Tickless Mode with RTC wakeup SmartFusion2 (ARM Cortex M3)

Hi All, I’m trying to run FreeRTOS 10.0 in the lowest power mode possible. I have a few tasks at different priority levels, I’m not using time-slicing, or vApplicationIdleHook() callback. I have looked at lots of examples and scoured the FreeRTOS page on Tickless operation and ARM example. I even looked at “Example Configurations”. I think what I want to do is not covered by any of these. I want to have SysTick running from internal Timer1, which produces a tick IRQ every 1 ms. When prvIdleTask() runs, it is presumably because every other task is blocked and are waiting on a timeout, or an event to happen. My external RTC runs at 32768 hz. I have a 20-bit prescaler that can divide that signal to give me other clocks, but I can’t get a wakeup period that is exactly 1ms. I can get a wakeup at 125ms exactly. I thought what I should do is set the sleep threshold for 125ms, then when no tasks will be ready to run within 125ms, call WFI and wait for the RTC to wakeup the processor. When I call WFI, I’m pretty certain that TIMER1 stops. I can then call vTaskStepTick(125) and continue. Does that sound right?

Tickless Mode with RTC wakeup SmartFusion2 (ARM Cortex M3)

I want to have SysTick running from internal Timer1,
The SysTick timer on a Cortex-M is a hardware timer built into the MCU core. Timer1 is also a hardware timer, but a peripheral. You can’t have the SysTick running from Timer1, so I think this is just a mistype and I’m assuming you meant you want the RTOS tick interrupt generated from Timer1, instead of SysTick – SysTick being the default. This can be done by implementing your own version of vPortSetupTimerInterrupt(), which is a weak symbol in the port layer. Your version should configure timer 1 to generate the interrupt at whatever frequency you want, and ensure xPortSysTickHandler() is installed as the interrupt’s handler. When prvIdleTask() runs, it is presumably because
every other task is blocked and are waiting on a timeout, or an event to happen.
That is only true if there are no other tasks that run at the idle priority (0).
My external RTC runs at 32768 hz. I have a 20-bit prescaler that can divide that signal to give me other clocks, but I can’t get a wakeup period that is exactly 1ms. I can get a wakeup at 125ms exactly. I thought what I should do is set the sleep threshold for 125ms, then when no tasks will be ready to run within 125ms, call WFI and wait for the RTC to wakeup the processor. When I call WFI, I’m pretty certain that TIMER1 stops. I can then call vTaskStepTick(125) and continue. Does that sound right?
Hmm, not really, what if an interrupt brings you out of sleep mode before the 125 milliseconds have passed? It might work very roughly only, with lots of time slippage – ok unless it matters to your application.

Tickless Mode with RTC wakeup SmartFusion2 (ARM Cortex M3)

One thing to point out, there is normally no need for the system timer tick to be at 1ms intervals. The system timer tick rate determines how precise your time delays will be. If you have tasks that need to run at specified time intervales, then you need the system timer to be a suitable (greatest) common divisor of those periods. You can also use a hardware timer to periodically wake up one of your tasks if it has an odd interval. Most other uses of the system timer in my experiance are timeouts, which normally don’t have tight tolerances. I normally use a system tick rate of no more than 100 Hz. (If it is an odd value the only issue would be the define giving you its period would be a bit off so the example formulas are a bit inaccurate). If you are just looking for the power savings of WFI (which stops the processor but keeps everything else going) then you just need to enable the IdleHook, and let you IdleHook do the WFI, which will pause the processor until the next interrupt (possible the system tick timer). If you want more savings, you can enable tickless idle which turns off the tick interrupt (avoiding the needless wakeups) until the next timeout will expire (or some other interrupt occurs). This puts some inaccuracy into timeouts, but does save more power. For even more power reduction, you could implement even more power savings by turning off more clocks in the system, which is one point were the low frequeny RTC might come into play, letting that be the time base to wake you back up. This would assume that you know it is safe to turn all those devices off. You mentioned a SmartFusion FPGA, I presume you know that if you don’t need the services of it, you can also put the FPGA to sleep to save a lot of power too.