This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

what should I do in freertos function vApplicationIdleHook() to save power?

hi, in FreeRTOSConfig.h file, #define configUSE_TICKLESS_IDLE 1 #define configUSE_IDLE_HOOK 1

and the idlehook function void vApplicationIdleHook( void ) { __WFI; }

after implement the code above, i find it did not save power.

anybody can help me or give me a link to figure it out. thx~~

Parents
  • Hi,

    You do not need to have to use both.
    Idle hook run before the tickless idle sleep.

    You only need one in your case because you are telling the idle hook to sleep. The idle hook is intended to tell the idle task to make the application specific functionality when the system is idling within RTOS. It does not necessarily mean that it has to go sleep. Some applications might choose to do different tasks than sleep.

    You can try this experiment.

    Get power measurements for the below three scenarios Scenario 1

    #define configUSE_TICKLESS_IDLE 0
    #define configUSE_IDLE_HOOK 0
    

    Now you have will no power saving as the system is not going to power save mode at all.

    Scenario 2

    #define configUSE_TICKLESS_IDLE 1
    #define configUSE_IDLE_HOOK 0
    

    Now when the idle task is executed then it will suppress tick interrupts and sleep. That means no ticks will happen from the sleep until next expected tasks wakeup time or RTC overflow time. This will save considerable power.

    Scenario 3

    #define configUSE_TICKLESS_IDLE 0
    #define configUSE_IDLE_HOOK 1
    

    Now you are telling the idle task to run your hook in vApplicationIdleHook(). It does not care what you do in there. In your case it is WFI(); You will see power consumption less than scenario 1 but more than scenario 2. This is because your application is going to sleep by WFI which is better than scenario 1 where there was no sleep, but your application is waking up for every tick to update rtos time which is not the case in scenario 2.

    Your scenario

    This should not be used because your sleeping in your idle hook, two different types of sleeps.

    #define configUSE_TICKLESS_IDLE 1
    #define configUSE_IDLE_HOOK 1
    

    The idle function first runs your application hook which is WFI() and when it wakes up it supresses tick and sleep. It will repeat this in a cycle whenever the idle task is run. So in your case one wakeup from chip is from WFI (slept from idlehook) and the second wakeup will be from tickless idle sleep. So you are telling the idle task to sleep twice (different types of sleeps )in a loop when ever it gets a chance to run which gives you very unpredictable behavior.

Reply
  • Hi,

    You do not need to have to use both.
    Idle hook run before the tickless idle sleep.

    You only need one in your case because you are telling the idle hook to sleep. The idle hook is intended to tell the idle task to make the application specific functionality when the system is idling within RTOS. It does not necessarily mean that it has to go sleep. Some applications might choose to do different tasks than sleep.

    You can try this experiment.

    Get power measurements for the below three scenarios Scenario 1

    #define configUSE_TICKLESS_IDLE 0
    #define configUSE_IDLE_HOOK 0
    

    Now you have will no power saving as the system is not going to power save mode at all.

    Scenario 2

    #define configUSE_TICKLESS_IDLE 1
    #define configUSE_IDLE_HOOK 0
    

    Now when the idle task is executed then it will suppress tick interrupts and sleep. That means no ticks will happen from the sleep until next expected tasks wakeup time or RTC overflow time. This will save considerable power.

    Scenario 3

    #define configUSE_TICKLESS_IDLE 0
    #define configUSE_IDLE_HOOK 1
    

    Now you are telling the idle task to run your hook in vApplicationIdleHook(). It does not care what you do in there. In your case it is WFI(); You will see power consumption less than scenario 1 but more than scenario 2. This is because your application is going to sleep by WFI which is better than scenario 1 where there was no sleep, but your application is waking up for every tick to update rtos time which is not the case in scenario 2.

    Your scenario

    This should not be used because your sleeping in your idle hook, two different types of sleeps.

    #define configUSE_TICKLESS_IDLE 1
    #define configUSE_IDLE_HOOK 1
    

    The idle function first runs your application hook which is WFI() and when it wakes up it supresses tick and sleep. It will repeat this in a cycle whenever the idle task is run. So in your case one wakeup from chip is from WFI (slept from idlehook) and the second wakeup will be from tickless idle sleep. So you are telling the idle task to sleep twice (different types of sleeps )in a loop when ever it gets a chance to run which gives you very unpredictable behavior.

Children
Related