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

FreeRTOS tick count invalid when using tickless idle

I've encountered a problem getting the tick count from FreeRTOS when tickless idle is enabled. I'm not sure if this is a bug or just unexpected behavior. I am using the latest nRF5 SDK 11, and observed this with the nRF52. It looks like the same problem should also occur with the nRF51.

When calling xTaskGetTickCount() immediately after the system has woken from the idle state, but before the next tick interrupt after waking up has occurred, the tick count doesn't take into account the time spent idle. As soon as the first tick occurs after waking up, the tick count jumps ahead to the correct value.

The reason is that the vPortSuppressTicksAndSleep function in port_cmsis_systick.c doesn't call vTaskStepTick to account for the time spent idle. Instead it waits for xPortSysTickHandler to call it.

In the ARM_CM4F port of FreeRTOS, which uses SysTick as the tick source, the vPortSuppressTicksAndSleep function does call vTaskStepTick as soon as it wakes up when tickless idle is enabled.

Related