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:
- Using vApplicationIdleHook() by setting configUSE_IDLE_HOOK = 1
- 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.
Are you using a FreeRTOS port that provides a default implementation of tickless idle? The ARM Cortex M ports do, for example.
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?
The answer is of course “it depends” 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.
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.