Closed kwrtz closed 3 years ago
Your loop code will most likey optimized away bei GCC: Because a is never used, it does not need to be calculated. Even if you try to use a (e.g. printing it after the loop), the compiler will notice that it is essentially a constant expression (0*3.14) and will calculate this at the compile time and will essentially condense your loop to something like printf("%f\n",0)
Do ensure that your loop is not optimized away you should
volatile
To be sure that your code is not optimized away use the gnu objdump utility objdump -d <elffile>
and check the generated assembler code.
BTW: You tried to markup your code but to do it right you need three back ticks instead of one. Check with the preview function if your markup works as intended before posting. For longer code pieces you can also create a github gist (gist.github.com) and just store here
Ok, thank you very much. I didn't thought about the optimisation. Now it works :)
@kwrtz I will fix the Coop example Arduino sketch in this release. I don't want other's to get confused by the optimizations GCC is performing behind the scenes. I will fix the code as @ThomasHornschuh suggested. Thank you.
Sorry for re-opening again. I will fix the example Arduino sketch as shown below. Thanks.
void taskShortA(int id_) {
volatile float a = 0.0f, b = 0.0f;
for (int32_t i = 0; i < 10000; i++)
a += i;
b = a;
Serial.print("A");
}
I get follwowing result on UNO:
ACBACBACBL ACBACBACBL ACBACBACBL ACBACBACBL ACBACBACBL ACBACBACBL ACBACBACBL ACBACBACBL
while using following code:
`/*
/*
/*
include "HeliOS_Arduino.h"
/*
operations. */ void taskShortA(int id_) { float a = 0.0f;
for (int32_t i = 0; i < 1000; i++) a *= 3.14f;
Serial.print("A"); }
void taskShortB(int32t id) { float a = 0.0f;
for (int32_t i = 0; i < 10000; i++) a *= 3.14f;
Serial.print("B"); }
void taskShortC(int32t id) { float a = 0.0f;
for (int32_t i = 0; i < 40000; i++) a *= 3.14f;
Serial.print("C"); }
/*
operations. */ void taskLong(int32t id) { float a = 0.0f;
for (int32_t i = 0; i < 40000; i++) a *= 3.14f;
Serial.println("L"); }
void setup() { /*
task id. */ int id = 0;
Serial.begin(9600);
/*
called before any other HeliOS function call. */ xHeliOSSetup();
/*
as a callback pointer to the task function. */ id = xTaskAdd("TASKSHORTA", &taskShortA);
/*
xTaskStart() the id of the task to start. */ xTaskStart(id);
id = xTaskAdd("TASKSHORTB", &taskShortB); xTaskStart(id);
id = xTaskAdd("TASKSHORTA", &taskShortC); xTaskStart(id);
/*
as a callback pointer to the task function. */ id = xTaskAdd("TASKLONG", &taskLong);
/*
xTaskStart() the id of the task to start. */ xTaskStart(id);
Serial.println("START"); }
void loop() { /*