Docsity

Embeded system rtos lecture, Summaries of Embedded Systems

Partial preview of the text

Download Embeded system rtos lecture and more Summaries Embedded Systems in PDF only on Docsity!

30 - Day FreeRTOS

Course for ESP

Using ESP-IDF

(Day 5 )

“Task States and

Priorities”

Table of Contents

1. Overview

On Day 5, you’ll learn:

  • The lifecycle of a FreeRTOS task
  • The different task states and what they mean
  • How priorities determine which task runs next
  • How to change task priority dynamically
  • Practical example of priority management By the end of this lesson, you’ll understand how the scheduler decides which task runs , and how to use priorities effectively for responsive systems.

1. Overview

In FreeRTOS, tasks can be in one of five main states:

2. Task Lifecycle in FreeRTOS

3. Task State

Transitions

4. How Priorities

Work

FreeRTOS uses preemptive scheduling :

  • Higher priority tasks always run before lower priority tasks.
  • Tasks with equal priority share CPU time via time slicing (if enabled).
  • Priority range in ESP-IDF defaults to: 0 (lowest) → configMAX_PRIORITIES - 1 (highest) In ESP-IDF, configMAX_PRIORITIES is 25 by default. Important: A low-priority task may never run if a high-priority task never blocks or yields.

4. How Priorities Work

Code Example

5. Example: Tasks with

Different Priorities

Expected Behavior

  • The high-priority task will run more often because the scheduler always picks the highest-priority ready task.
  • The low-priority task will run only when the high-priority task is delayed or blocked.

5. Example: Tasks with

Different Priorities

You can adjust a task’s priority during runtime using:

6. Changing Task Priority

Dynamically

Example: This can be useful for:

  • Temporarily boosting a task’s responsiveness
  • Reducing a task’s priority after a critical section is complete

7. Avoiding

Priority Pitfalls

8. Summary

Tasks have five main states in FreeRTOS. Priorities control who runs next — higher priority wins. Equal priorities share CPU time if time- slicing is enabled. Change priorities dynamically with vTaskPrioritySet() when needed. Avoid priority inversion and starvation by proper task design.

8. Summary