On FreeRTOS, the highest priority task is granted CPU time. If multiple tasks have equal priority, it uses round-robin scheduling among them. Lower priority tasks must wait.

It is important that high priority tasks don’t execute 100% of the time, because lower priority tasks would never get CPU time. It’s a fundamental problem of real-time programming.

Usually, you want to assign a high priority to a task that must react fast to some important event, perform quick action, and go to sleep, letting less important stuff to work in the meantime.

A generic example of such a system may be:

  1. highest priority - device drivers tasks (valve control, ADC, DAC, etc)
  2. medium priority - administrative subsystem (console task, telnet task)
  3. lower priority - several application tasks (www server, data processing, etc)

Lowest priority is given to general applications, that are scheduled using round-robin, which gives a more or less equal number of CPU time.

Medium priority - console tasks. The system operator cannot be cut off by a malfunctioning an http server that gets stuck in an infinite loop. Those tasks are not running 100% of the time. For example, it may execute command-line commands from the administrator.

Highest priority - device drivers, handling critical events, such as machinery control. You may be interested in opening a safety valve if boiler pressure gets too high and you really don’t want to wait until some stupid HTML rendering is finished in the webserver thread. Such tasks are run for a limited amount of time only.


FreeRTOS name convention:

  • Time Slicing Scheduling Policy: This is also known as a round-robin algorithm. In this algorithm, all equal priority tasks get CPU in equal portions of CPU time.
  • Fixed Priority Preemptive Scheduling: This scheduling algorithm selects tasks according to their priority. In other words, a high priority task always gets the CPU before a low priority task. A low priority task gets to execute only when there is no high priority task in the ready state.

The configUSE_PREEMPTION configuration constant is used to select fixed priority scheduling policy and configUSE_TIME_SLICING is used to select time slicing scheduler. But if you want to select both, you can set these configuration bit to one as shown in figure below:


🌱 Back to Garden