# configUSE\_TICKLESS\_IDLE

**URL:** <https://forums.freertos.org/t/configuse-tickless-idle/4177>\
**Category:** Kernel\
**Created:** [April 4, 2014, 2:20am UTC](https://forums.freertos.org/t/configuse-tickless-idle/4177 "2014-04-04T02:20:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [April 4, 2014, 2:20am UTC](https://forums.freertos.org/t/configuse-tickless-idle/4177/1 "2014-04-04T02:20:55Z")

</div>

**[l4n4](https://sourceforge.net/u/l4n4/)** wrote on [Friday, April 04, 2014](https://sourceforge.net/p/freertos/discussion/382005/thread/b86a64f0/#e25f):

If we enable the configUSE\_TICKLESS\_IDLE, it will go to ‘idle’ only when the xExpectedIdleTime \>= 2. Do you think , it’s worthwhile to call the \_\_WFI (wait for interrupt) even if the xExpectedIdleTime is \< 2 (in term of power saving)? I’m running a 180Mhz cortex M3.

if( xExpectedIdleTime \>= configEXPECTED\_IDLE\_TIME\_BEFORE\_SLEEP )  
{  
portSUPPRESS\_TICKS\_AND\_SLEEP( xExpectedIdleTime );  
}  
else{  
\_\_WFI(); //add wait for interrupt here  
}

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [April 4, 2014, 3:14am UTC](https://forums.freertos.org/t/configuse-tickless-idle/4177/2 "2014-04-04T03:14:51Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Friday, April 04, 2014](https://sourceforge.net/p/freertos/discussion/382005/thread/b86a64f0/#2d28):

It may be that, in your particular application, you get some benefit from doing that, but if so I would not recommend changing the source code in that way but instead define an idle hook function that just calls wfi.

Regards.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [April 4, 2014, 3:38am UTC](https://forums.freertos.org/t/configuse-tickless-idle/4177/3 "2014-04-04T03:38:55Z")

</div>

**[l4n4](https://sourceforge.net/u/l4n4/)** wrote on [Friday, April 04, 2014](https://sourceforge.net/p/freertos/discussion/382005/thread/b86a64f0/#3cf4):

The idle hook will be called all the time and before portSUPPRESS\_TICKS\_AND\_SLEEP, so it will always sleep for 1 tick time first before do any further checks. This means :

- if xExpectedIdleTime \< 2 : this is ok
- if xExpectedIdleTime == 2 : Idle hook will sleep for 1 tick and portSUPPRESS\_TICKS\_AND\_SLEEP will not be called. I would like the portSUPPRESS\_TICKS\_AND\_SLEEP to be called in this condition.
- xExpectedIdleTime \> 2 : this is ok

Thanks!

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [April 4, 2014, 3:01pm UTC](https://forums.freertos.org/t/configuse-tickless-idle/4177/4 "2014-04-04T15:01:39Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Friday, April 04, 2014](https://sourceforge.net/p/freertos/discussion/382005/thread/b86a64f0/#89c2):

How about setting configEXPECTED\_IDLE\_TIME\_BEFORE\_SLEEP to 0 (may cause a compiler warning where the \>= check is performed) then use the [configPRE\_SLEEP\_PROCESSING](http://www.freertos.org/low-power-ARM-cortex-rtos.html) to check the expected idle time and if the expected idle time is below a threshold set by yourself it can just call wfi and cancel the tickless entry (the macros parameter can be used for cancelling the tickless entry).

Regards.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [January 10, 2017, 4:31pm UTC](https://forums.freertos.org/t/configuse-tickless-idle/4177/5 "2017-01-10T16:31:12Z")

</div>

**[mplmht](https://sourceforge.net/u/mplmht/)** wrote on [Tuesday, January 10, 2017](https://sourceforge.net/p/freertos/discussion/382005/thread/b86a64f0/#c965):

I have the same concern here but I would like to keep usage of configEXPECTED\_IDLE\_TIME\_BEFORE\_SLEEP functionnality which is interesting I beleive.

I would like to get your advice on following code change proposal:

- when tickless idle feature is enabled, call to the idle hook  
when xExpectedIdleTime is below configEXPECTED\_IDLE\_TIME\_BEFORE\_SLEEP
- when tickless idle feature is not enabled, keep calling the idle hook the same way as now.

The code change could look like below in portTASK\_FUNCTION function of tasks.c (line 3177 of v9.0.0)?

```
#if ( configUSE_TICKLESS_IDLE == 0 )
    #if ( configUSE_IDLE_HOOK == 1 )
    {
        extern void vApplicationIdleHook( void );

        /* Call the user defined function from within the idle task. This
        allows the application designer to add background functionality
        without the overhead of a separate task.
        NOTE: vApplicationIdleHook() MUST NOT, UNDER ANY CIRCUMSTANCES,
        CALL A FUNCTION THAT MIGHT BLOCK. */
        vApplicationIdleHook();
    }
    #endif /* ( configUSE_IDLE_HOOK == 1 ) */

/* This conditional compilation should use inequality to 0, not equality
to 1. This is to ensure portSUPPRESS_TICKS_AND_SLEEP() is called when
user defined low power mode	implementations require
configUSE_TICKLESS_IDLE to be set to a value other than 1. */
#else /* configUSE_TICKLESS_IDLE != 0 */
{
TickType_t xExpectedIdleTime;

    /* It is not desirable to suspend then resume the scheduler on
    each iteration of the idle task. Therefore, a preliminary
    test of the expected idle time is performed without the
    scheduler suspended. The result here is not necessarily
    valid. */
    xExpectedIdleTime = prvGetExpectedIdleTime();

    if( xExpectedIdleTime >= configEXPECTED_IDLE_TIME_BEFORE_SLEEP )
    {
        vTaskSuspendAll();
        {
            /* Now the scheduler is suspended, the expected idle
            time can be sampled again, and this time its value can
            be used. */
            configASSERT( xNextTaskUnblockTime >= xTickCount );
            xExpectedIdleTime = prvGetExpectedIdleTime();

            if( xExpectedIdleTime >= configEXPECTED_IDLE_TIME_BEFORE_SLEEP )
            {
                traceLOW_POWER_IDLE_BEGIN();
                portSUPPRESS_TICKS_AND_SLEEP( xExpectedIdleTime );
                traceLOW_POWER_IDLE_END();
            }
            else
            {
                mtCOVERAGE_TEST_MARKER();
                #if ( configUSE_IDLE_HOOK == 1 )
                {
                    extern void vApplicationIdleHook( void );

                    /* Call the user defined function from within the idle task. This
                    allows the application designer to add background functionality
                    without the overhead of a separate task.
                    NOTE: vApplicationIdleHook() MUST NOT, UNDER ANY CIRCUMSTANCES,
                    CALL A FUNCTION THAT MIGHT BLOCK. */
                    vApplicationIdleHook();
                }
                #endif /* configUSE_IDLE_HOOK */
            }
        }
        ( void ) xTaskResumeAll();
    }
    else
    {
        mtCOVERAGE_TEST_MARKER();
    }
}
#endif /* configUSE_TICKLESS_IDLE */

```

Regards.

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [January 10, 2017, 5:12pm UTC](https://forums.freertos.org/t/configuse-tickless-idle/4177/6 "2017-01-10T17:12:03Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Tuesday, January 10, 2017](https://sourceforge.net/p/freertos/discussion/382005/thread/b86a64f0/#c965/1ca9):

Hi - thanks for your input, although I doubt this would be adopted  
because it would change the existing behaviour, which could cause issues  
for users that update the version of FreeRTOS they are using in existing  
applications.
