Bare Metal vs. RTOS to FreeRTOS Basics | FreeRTOS One

Table of contents

1. Bare metal and RTOS

1.1. Bare metal

1.2、RTOS

2. Introduction to FreeRTOS

2.1. Introduction

2.2. Features

2.3. How to find relevant information

3. FreeROTS Basics

3.1. Task scheduling

3.2. Task status


1. Bare metal and RTOS

1.1. Bare metal

        Without an operating system, it is also called a front-end and back-end system. The front-end system refers to the interrupt service function , and the background system refers to the large loop of the main program, that is, the application program .

Features:

1) Poor real-time performance (programs are executed in turns)

2) Empty wait (during delay, the CPU does not execute other code)

3) Poor structure (all implementation functions are placed in the main function loop)

1.2、RTOS

        Real-time OS, which is a real-time operating system.

Features:

1) Multi-tasking, each function can be divided into a task

2) Task scheduling. When high-priority tasks are delayed, the CPU trial period will be given to low-priority tasks.

3) Task preemption, high-priority tasks can preempt low-priority tasks

4) Task stack, each task has its own stack space to save relevant data

important point:

1) Interruption can interrupt tasks of any level

2) There can be different tasks with the same priority

2. Introduction to FreeRTOS

2.1. Introduction

Free, free, RTOS real-time operating system, FreeRTOS is a free embedded real-time operating system.

2.2. Features

1) Free and open source (reduces development costs)

2) Can be cut (the core code has only three .c files, 9000 lines)

3) Simple (good portability)

4) No limit on priority (there is no limit on task priority allocation, multiple tasks can have the same priority, hardware limit is 0-31)

5) No limit on tasks (there are no software restrictions on real-time tasks that can be created)

6) Support preemption/coroutine/time slice (task scheduling)

2.3. How to find relevant information

1) Official website: https://www.freertos.org/

2) Other sharing platforms on the Internet such as: Punctual Atomic Learning Materials, Wildfire Learning Materials

ARM Cortex-M knowledge reference: <Cortex M3 Authoritative Guide (Chinese)><Cortex M3, M4 Authoritative Guide>

3. FreeROTS Basics

3.1. Task scheduling

FreeROTS supports three task scheduling methods, as follows:

1) Preemptive scheduling: For tasks with different priorities, each task has a priority, and tasks with higher priority can preempt tasks with lower priority;

2) Time slice scheduling: A time slice is equal to the SysTick interrupt period (default 1ms), which can be set. For tasks with the same priority, when multiple tasks have the same priority, the task scheduler will follow the system clock beat. time to switch tasks;

3) Cable scheduling: The current execution task will always run, and high-priority tasks will not preempt lower-priority tasks. Although FreeROTS still supports it, the official has stated that it will not update Cable scheduling.

3.2. Task status

There are 4 statuses for tasks in FreeROTS, as follows:

1) Running state: The task being executed is in the running state. In STM32, only one task is in the running state at the same time;

2) Ready state: The task can be executed but has not yet been executed, then the task is in the ready state;

3) Blocked state: If a task is delayed or waiting for an external event to occur, then the task is in a blocked state;

4) Suspend state: Similar to pause, the function vTaskSuspend() is called to enter the suspended state, and the unsuspension function vTaskResume() needs to be called to enter the ready state.

Notice:

1) If the task is interrupted or blocked midway, the unused time slice will not be used twice. The next time it is the task’s turn to execute, a new time slice will be allocated;

2) Only the ready state can be converted into the running state;

3) If tasks in other states want to run, they must first be transformed into the ready state.

Four state transition diagrams, as shown in Figure 1 below:

figure 1

Among these four states, in addition to the running state, tasks in the other three task states have their corresponding task state lists, as follows:

Ready list: pxReadyTasksLists[x], where x represents the task priority value --> Commonly used hardware is relatively stable 0-31, larger numbers have higher priorities

Blocking list: pxDelayedTaskList

Suspended category: xSuspendedTaskList

So how do you know if there are tasks in the list?

Define a 32-bit variable. When a certain bit is set to 1, it means that there is a task in the corresponding priority ready list.

The scheduler always selects the task with the highest priority among all tasks in the ready list for execution.


 

Guess you like

Origin blog.csdn.net/qq_57663276/article/details/128726509