# Energy Saving Modes

**URL:** <https://forums.freertos.org/t/energy-saving-modes/20723>\
**Category:** Kernel\
**Created:** [June 15, 2024, 7:22pm UTC](https://forums.freertos.org/t/energy-saving-modes/20723 "2024-06-15T19:22:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![expl01t](https://avatars.discourse-cdn.com/v4/letter/e/9de053/32.png) [@expl01t](https://forums.freertos.org/u/expl01t)\
**Post date:** [June 15, 2024, 7:22pm UTC](https://forums.freertos.org/t/energy-saving-modes/20723/1 "2024-06-15T19:22:42Z")

</div>

Hello,

I am currently looking into FreeRTOS because I write my BA thesis about different IoT-OS. One of the topics that I want to compare those is energy management, especially energy saving modes (sleep mode, deep sleep mode etc.). Can someone maybe give me a short introduction on how this is done in FreeRTOS? If I understand it correctly, there aren´t sleep modes, instead this is done with the idle task hook.

Thank you for helping me out!

---

<div class="post-metadata">

**Author:** ![hs2](https://avatars.discourse-cdn.com/v4/letter/h/a4c791/32.png) [@hs2](https://forums.freertos.org/u/hs2)\
**Post date:** [June 15, 2024, 9:11pm UTC](https://forums.freertos.org/t/energy-saving-modes/20723/2 "2024-06-15T21:11:54Z")

</div>

> **[Tickless Low power features in FreeRTOS](https://www.freertos.org/low-power-tickless-rtos.html)**
>
> Low power tickless features in FreeRTOS

and

> **[Tickless Low power ARM RTOS Cortex-M Microcontrollers](https://www.freertos.org/low-power-ARM-cortex-rtos.html)**
>
> Low power tickless features in FreeRTOS for ARM Cortex-M microcontrollers

provide some more details.

---

<div class="post-metadata">

**Author:** ![kstribrn](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/kstribrn/32/6511_2.png) [@kstribrn](https://forums.freertos.org/u/kstribrn)\
**Post date:** [June 19, 2024, 4:31pm UTC](https://forums.freertos.org/t/energy-saving-modes/20723/3 "2024-06-19T16:31:06Z")

</div>

@hs2 linked you exactly what you should need!

In summary some MCUs have a lower power mode and can be placed into this mode when work isn’t being done. While the FreeRTOS tick isn’t much work to a chip, it is periodic work which has to happen. This periodic work can prevent a lower power mode. To help reduce power consumption FreeRTOS offers tickless idle. Tickless idle does not require a tick interrupt which in turn saves the work of running the interrupt, in turn allowing the MCU to be placed into it’s power saving state when the idle task would have ran instead.

---

<div class="post-metadata">

**Author:** ![LessIsMore](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/lessismore/32/4680_2.png) [@LessIsMore](https://forums.freertos.org/u/LessIsMore)\
**Post date:** [June 29, 2024, 4:08pm UTC](https://forums.freertos.org/t/energy-saving-modes/20723/4 "2024-06-29T16:08:00Z")

</div>

The page on tickless idle for the Cortex M0 says there are two macros that get called either side of a WFI instruction and there is talk of an “expected idle time”. In my application, I do no time calculations that span an idle time so I do not really care if the “ticks since boot” value is correct long term. Wakeup happens from a GPIO transition interrupt. It says that if I use ExpectedIdle=0 then the WFI is not executed. So in that case do I just call WFI myself at the end of my **configPRE\_SLEEP\_PROCESSING** macro?

---

<div class="post-metadata">

**Author:** ![aggarg](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/aggarg/32/4245_2.png) [@aggarg](https://forums.freertos.org/u/aggarg)\
**Post date:** [July 1, 2024, 6:14am UTC](https://forums.freertos.org/t/energy-saving-modes/20723/5 "2024-07-01T06:14:07Z")

</div>

> [@LessIsMore](#):
>
> It says that if I use ExpectedIdle=0 then the WFI is not executed. So in that case do I just call WFI myself at the end of my **configPRE\_SLEEP\_PROCESSING** macro?

You are likely taking about [this code block](https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/portable/GCC/ARM_CM4F/port.c#L671):

```auto
            configPRE_SLEEP_PROCESSING( xModifiableIdleTime );

            if( xModifiableIdleTime > 0 )
            {
                __asm volatile ( "dsb" ::: "memory" );
                __asm volatile ( "wfi" );
                __asm volatile ( "isb" );
            }

            configPOST_SLEEP_PROCESSING( xExpectedIdleTime );

```

If the implementation of `configPRE_SLEEP_PROCESSING` does not want to call WFI, it can set the parameter `xModifiableIdleTime` to zero:

```auto
/* ShouldSleep determines when to call WFI. */
#define configPRE_SLEEP_PROCESSING( xModifiableIdleTime ) \
    { \
        if( ShouldSleep( xModifiableIdleTime ) == pdFALSE ) \
        { \
            /* Do not call WFI. */ \
            xModifiableIdleTime = 0; \
        } \
    }

```

If you want to call WFI, you should not set `xModifiableIdleTime ` to 0.
