The Idle Task

The idle task is the default task that the FreeRTOS scheduler will enter into if their are no tasks waiting for execution time. It is created automatically by the FreeRTOS core, and cannot be disabled. There are two ways of getting access to the idle function (so you can write you own code inside it).

Monitoring the idle task is a good way to measure the utilization of an embedded CPU, and see how much free time it has left to do other things.

FreeRTOS always requires at least one task that is ready to run, and because of this, you must not use FreeRTOS API functions in the idle task which may wait of block on things.

The idle task is responsible for freeing memory of tasks which have been recently deleted. So if your application deletes tasks, you must make sure that the idle task is not starved continuously of processor time, otherwise the memory will never be freed. This is the only thing the idle task has to do however, so if you don’t delete any tasks (which is a common scenario), the idle task can be starved of processor time.

Creating An Idle Hook

To create an idle hook,  configUSE_IDLE_HOOK must be set to 1 in FreeRTOSConfig.h, and then define a function with the following prototype:

 

  • GS

    How to monitor the Idle Task running time in CPU? I use vTaskGetRunTimeStats( ). I created just single Task (Task1) in main(). When using this API, I receive Task1 100% and Idle Task <1%. But the real percentage is 70% utilized by Idle and 30% by Task1. Seeking suggestions to solve this error. I maintain 10Hz of CPU tick rate and counter to use Runtimestats as 1kHz.

    • How are you sure about the real percentages being 70% and 30%? Also, try creating another task (Task2) of equal priority as Task1 and see what runtime stats you get back from that, this might indicate whether the problem is specifically to do with the idle task…

  • How are you sure about the real percentages being 70% and 30%? Also, try creating another task (Task2) of equal priority as Task1 and see what runtime stats you get back from that, this might indicate whether the problem is specifically to do with the idle task.