Search code examples
armembeddedfreertoscortex-m

Interrupt in TICKLESS_IDLE mode of FreeRTOS


I have some questions about tickless idle mode in FreeRTOS.

  • Does systick work in this mode, or systick just stop working when __WFI() has called and work again right after exiting __WFI() ?

  • Calling the __WFI() to make the MCU enter the low-power mode and using interrupts to wake up the MCU. But in FreeRTOS source code, port.c, as below. Before calling __WFI(), __disable_interrupt() is called. Hence, how can interrupt happen?

__weak void vPortSuppressTicksAndSleep( TickType_t xExpectedIdleTime )
{
      ...
   __disable_interrupt();

   if( eTaskConfirmSleepModeStatus() == eAbortSleep )
   {
      ...
   }
   else
   {
      ...
      if( xModifiableIdleTime > 0 )
      {
         __WFI();
      }
      ...
      __enable_interrupt();
      ...
}

Thanks for your help.


Solution

    • Whether systick runs in low power mode depends upon the clock source to systick. It is SOC specific. If the clock to systick is turned off in low power mode, then systick does not function.
    • The interaction between WFI and interrupts causes much confusion. It is important to remember WFI returns if an exception is made pending that is of higher priority. WFI ignores the value of PRIMASK. After WFI returns interrupts are still disabled until explicitly enabled. This is important behavior as it allows interrupts to be disabled and a final check to be made before going into low power mode and it allows other actions to be taken after WFI returns but before any IRQ is handled. Some SOC's need to perform housekeeping activities after coming out of low power mode.