I’m doing some time calculations that use the OS tick as base. This requires me to analyze my apps behaviour on tick wrap over. As I don’t want to wait until this happens, I now have to change FreeRTOS code to change xTickCount.
Sorry I don’t know anything about the implementation of the Linux
kernel. You can set the initial tick value to whatever you want - the
FreeRTOS code as delivered tries not to have any variables initialised
to anything other than 0 so as not to have variables outside the .bss
section.
If you have configUSE_TICKLESS_IDLE set to 1 you could also conceivable
use vTaskStepTick() to push the tick count forward too, but probably the
only safe way of doing that would be to create a single task, have that
task call vTaskStepTick() to step the tick count forward by however many
ticks you want, then create your other application tasks.
Thank you for your answer.
Using vTaskStepTick() works for me.
Starting the tick at some special value is not Linux specific. I just used Linux as an example.
/*
* Have the 32 bit jiffies value wrap 5 minutes after boot
* so jiffies wrap bugs show up earlier.
*/
#define INITIAL_JIFFIES ((unsigned long)(unsigned int) (-300*HZ))
This is done so that at 1 kHz the tick overflows for the first time after 5 minutes instead of ~50 days. The risk of having a hard-to-find error related to tick wrap over is thereby reduced a bit.
I would find it useful. Bugs related to wrapping may lurk in time delta calculations, so it’s good if such wrapping occurs regularly during testing (after a device has been running for a few minutes) rather than once something is running “in the wild” for ~50 days.
I’ve just been looking through the FreeRTOS 9.0.0 code to see if it looks safe in regard to wrapping. I came across this line in tasks.c which doesn’t look right:
I also see the code fragment if( xTickCount >= xNextTaskUnblockTime ) mentioned in comments a couple of times. The comment probably needs updating to match the code.
Looks right to me. The tick count must never be ahead of the time a task needs unblocking, and xNextTaskUnblockTime is set to ~-1 (max TickType_t value) to wait for the tick count to catch up before wrapping.