[FreeRTOS (1)] Getting Started with FreeRTOS for Beginners - Getting to Know FreeRTOS for the First Time

1. Overview of real-time operating system

1. Concept

RTOS: According to the requirements of each task, perform resource (including memory, peripherals, etc.) management, message management, task scheduling, exception handling, etc. Each task has a priority, and the RTOS dynamically switches each task according to the priority of each task to ensure real-time requirements.

2. The necessity of RTOS

  • Embedded real-time operating system improves system reliability
  • Improve development efficiency and shorten development cycle
  • Embedded real-time operating system gives full play to the multitasking potential of 32-bit CPU

But the real-time operating system also requires additional ROM/RAM overhead, 2~5% additional CPU load, and the cost of the kernel.

3. The difference between RTOS and bare metal

① Bare metal development
is similar to the 51 MCU and STM32 we played in school. They all run in the main function, and there will be a super large while (1) loop, which contains almost all the business logic of the entire project, and then each logic There will be waiting functions such as delay in it, which will cause all business logic to work serially. Then poll one thing, one thing in order, and only one thing can be done at the same time. Similar to the picture below.
insert image description here
② How to improve it?
Each of these things corresponds to a task to reduce the degree of coupling. A task corresponds to a piece of hardware. By preempting the priority of tasks, tasks can be switched efficiently.insert image description here

4. Features of FreeRTOS

  • The FreeRTOS kernel supports preemptive and time slice scheduling
  • Provides a Tickless mode for low power consumption
  • The components of the system can choose dynamic or static RAM when they are created, such as tasks, message queues, semaphores, software timers, etc.
  • FreeRTOS-MPU supports MPU units in the Corex-M series, such as STM32F429.
  • The FreeRTOS system is simple, compact and easy to use. Usually, the kernel occupies 4k-9k bytes of space
  • High portability, the code is mainly written in C language.
  • Efficient software timer
  • Powerful trace execution function.
  • Stack overflow detection function.
  • There is no limit to the number of tasks.
  • Task priority (0~63) is not limited.

2. Architecture of FreeRTOS

insert image description here

  • One task manages one piece of hardware
  • Task-to-task or task-to-interrupt involving data transfer using message queues
  • Task shared resource access using mutex
  • Synchronization of tasks using semaphores
  • Flags are managed using the Event Flags Group
  • Write a task that specifically initializes the hardware, which can contain functions that create tasks.

3. The code structure of FreeRTOS

insert image description here

  • croutine.c/crooutine.h: Coroutine, which is more efficient on 8-bit/16-bit platforms, and it is recommended to use Task on 32-bit platforms.
  • event_group.c/event_group.h: This is the implementation of the event group.
  • heap_x.c: Kernel heap implementation, FreeRTOS provides heap_1.c~heap_5.c, 5 kinds of heap managers, each has advantages and disadvantages, you need to choose according to the application. I will explain this in detail in another blog post.
  • list.c/list.h: Linked list implementation, which mainly provides data structure algorithm support services for the scheduler. For example, task list.
  • port.c/portmacro.h: Hardware-related level portable abstraction, mainly including SysTick interrupt, context switching, interrupt management, the specific implementation depends largely on the platform (SCM system hardware core and compiler tool set). Usually implemented in assembly language.
  • queue.c/queue.h/semphr.h: semaphore, mutex implementation.
  • tasks.c/task.h: Task manager implementation.
  • timers.c/timers.h: Software timer implementation.
  • FreeRTOS.h: Compilation configuration file that aggregates compilation selection controls for all source files.
  • FreeRTOSConfig.h: FreeRTOS kernel configuration, Tick clock and irq interrupt configuration.

Guess you like

Origin blog.csdn.net/qq_43533553/article/details/129764092