This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

FreeRtos port xTickCount bug

Hello, I used latest port_cmsis_systick.c from SDK13.0. And there is still xTickCount bug. Function vPortSuppressTicksAndSleep() adds correct vTaskStepTick(diff); but the trouble is that you do not clear NRF_RTC_EVENT_COMPARE_0. This way the RTC ISR is called and 1 extra xTickCount is counted. Which effectively make system tick running faster and all xTickCount time operation have this error. The error is worst when you run sleep only for few tick. If you let CPU sleep just for 3 ticks then it really sleeps 3 ticks but counts 4 then you have 33% error!!! But I save you one loop and tell you error what I did when trying to fix it. I cleared RTC.Compare event flag. This way I got correct xTickCount. But I noticed that my task is one xTickCount delayed from execution. It is due to fact that FreeRtos is stupid and function vTaskStepTick(diff); does not move unblocked delayed task into ready tasks. This will happen next xTickCount. To fix that it is easiest to keep RTC.Compare event flag, but call vTaskStepTick(diff-1);

Parents Reply Children
No Data
Related