in Reliable timings using Threads, this example is given :
Code: Select all
msg_t my_thread(void *param) {
systime_t time = chTimeNow(); // T0
while (true) {
time += MS2ST(1000); // Next deadline
do_something();
chThdSleepUntil(time);
}
}
And includes a warning about do_something() execution time having to be shorter than the deadline which is great.
But, unless I'm mistaken, a warning about chTimeNow() restarting back from 0 would help too.
If the loop runs long enough for the current time to restart from 0, the delay time will be : (time - now) == (12345678 - 0) == 12345678 == very long.