MCU Sleep mode from idle task hook and tickless idle mode

Hi,
I have gone through no. of threads on this topic but somehow not able to clearly understand the difference of sleep mode implementation from Idle task hook and using tickless idle mode.
My current implementation is in idle task hook, as below:

void vApplicationIdleHook( void )
{
     if(alltasksreadyforsleep())      //check if all other tasks set their flags indicating ready to sleep
    {
                   stopTickTimer();           //stop freeRTOS tick timer
                   setRTCAlarm();            //30s RTC alarm interrupt for wakeup
                   sleep_MCU();               //make MCU sleep
                   disableRTCAlarm();      //disable RTC from giving any other interrupt
                   startTickTimer();          //start freeRTOS tick timer
                   resetalltaskreadyflags();          //set all task ready to sleep flags to false
     }
}

In above implementation, my application hang-up during wakeup cycle randomly after functioning for few hours. I was reading about tickless idle mode and got into confusion if I am doing above things correct or I should use tickless idle mode and implement macro portSUPPRESS_TICKS_AND_SLEEP( xExpectedIdleTime ).

Please suggest.
Thanks,
Pradeep

One possible issue is you have a race condition in your code.

What if after alltasksreadyforsleep() returns true, something happens that makes the system not ready.

Note, Tickless idle first uses a quick check to see if it is possible, then enters a critical section and then confirms the state.

Hi @ppatel,

The difference between ideal task hook and tickles idle mode depends on how the low-power modes are managed. Idle task hook requires periodically exit and then re-enter the low power state to process tick interrupts, where as in tickles idle stops the periodic tick interrupt during idle periods allowing microcontroller to remain in a deep power saving state.

Can you please check this post - Low Power Support and let us know if it helps to clear the confusion.

We would appreciate feedbacks to update the page in case you find any information missing.