Entering Low power mode infinitely

Hi,

I’m a student and new to freeRTOS.
I’m developing an application in which I would like MCU running freeRTOS to enter sleep infinitely till an external wake-up interrupt is asserted (without getting woken-up by systick or Watchdog interrupt).

On researching, I found the following two ways of entering sleep in freeRTOS:

  1. Using vApplicationIdleHook() by setting configUSE_IDLE_HOOK = 1
  2. Using portSUPPRESS_TICKS_AND_SLEEP() by setting configUSE_TICKLESS_IDLE = 1

Option 1: vApplicationIdleHook()
If I enter sleep in this API, I feel that the systick would still be running and would wake-up the system at next systick interrupt.

Option 2: portSUPPRESS_TICKS_AND_SLEEP
If I use this then it seems I would have to specify params like configEXPECTED_IDLE_TIME_BEFORE_SLEEP, xExpectedIdleTime etc. which might not be applicable for my use-case.

Please suggest how should I go about implementing this.
Thanks.

Are you using a FreeRTOS port that provides a default implementation of tickless idle? The ARM Cortex M ports do, for example.

Hi Jeff
I’m using a RISCV based MCU and dont have the default implementation of tickless idle.
if possible, can you please share the implementation for riscv/cortex M for reference?

btw, should I go for tickless idle over vApplicationIdleHook() in this scenario?

Here’s the default implementation for Cortex M4F. https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/385e700953ad68680890cd9c4977dff384879a03/portable/GCC/ARM_CM4F/port.c#L516

And here’s where FreeRTOS calls the function. (Note that FreeRTOS determines on its own the expected idle time, based on delays, timers, and timeouts currently underway.) https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/385e700953ad68680890cd9c4977dff384879a03/tasks.c#L3504

1 Like

The answer is of course “it depends” :wink: My opinion is the best way is to implement the suppress-ticks-and-sleep method, even if at first your implementation is rudimentary. That allows you to enhance the implementation later as application evolves. I’m not a fan myself of the idle-hook approach because you’ll end up duplicating some of the structure already in the FreeRTOS side of the tickless interface.

1 Like

If you want to go to sleep for an extended time, then you really need some form of tickless idle, as otherwise the tick will keep waking you up. vApplicationIdleHood by itself can’t help with this, unless you put code like would be used in tickless idle into that hook.

1 Like