RTOS real-time operating system overview

The RTOS content learning part mainly includes "writing an RTOS operating system from 0" and "ROTS kernel application development". Common RTOSs include μC/OS-II, freetos, RT-Thread, and LiteOS. The main reasons for the introduction of ROTS are as follows:

RTOS kernel comparison

The system function of Freertos is more pure and can be used in various scenarios that require a real-time system. rtthread has various third-party components, especially related to network components, and has a strong advantage in the field of IoT products, which can help developers quickly complete the development of IoT products with components. LiteOS is widely integrated in Huawei's own IoT devices, including a large number of network cloud access interfaces.

I have been using rtos as the main development content, but I have not learned about the kernel implementation mechanism of rtos in detail. In the last month, I took some time to read the kernel code of freertos and rtthread, and understood the implementation mechanism and design ideas of the real-time system. To learn the code of freertos here, first read the detailed introduction of Zhu Dashen's freertos basic and advanced articles, and then read the source code; understand the basic design ideas and code implementation logic. The following is a brief list of the implementation differences between the two systems that I have learned.

1. Create tasks
Both systems support the creation of static system tasks and dynamic tasks. The difference is as follows:

The task created by freertos is added to the ready task list. After the creation is completed, if the scheduler is already running, it can directly participate in the scheduling.
The thread created by rtthread is added to the pending task list. After the thread is created, it is necessary to actively call start_up to move the thread to the ready task list to participate in scheduling.
Two, delay
Both systems support delay and delayutil. The difference is as follows:

The freertos system has a dedicated delay timeout count list. Delay tasks are arranged in the timeout counting list in sequence according to the timeout time, wait for the timeout time to arrive, and move them to the ready task list to participate in scheduling.
Each thread control block structure of the rtthread system defines a software timer structure. When the delay delay function is called, the software timer that comes with the thread will be started to complete the delay operation. When the delay timeout time is met, trigger The software timer timeout callback moves the task from the pending list to the ready list to participate in the scheduling.
Three, semaphore
Both systems support the use of semaphores. The difference is as follows:

The semaphore of the freertos system is also a queue, but the length of the queue is 0. Freertos encapsulates counting semaphores and binary semaphores using macro definitions.
The rtthread system semaphore only supports counting semaphores, and the initial value of the semaphore is passed in when the semaphore is created. There is no interface for binary semaphores in the system. It can be used as a binary semaphore by setting the initial value to 1.
4. Mailboxes
Mailboxes are different from message queues. Mailboxes are often used to transmit an address, and can directly refer to data for data transmission. However, the implementation mechanism of the message queue is to allocate the memory of the maximum length of the queue in advance. When transmitting data, copy the data to be sent to the requested queue memory to realize the copy of the data.

The freertos system does not support mailboxes.
The rtthread system supports mailboxes. The size of data transmitted by mailboxes is only 4 bytes. It is generally used to transmit an address, and this address is used for data transmission.


Five, time slice

Both systems support the mechanism of time slice rotation. Time slice rotation means that there are at least two highest tasks with the same priority in the ready task list. Task scheduling needs to be performed at a fixed time tick in turn. Share CPU resources. The differences between the two systems are as follows:

The freertos system needs to actively enable the macro definition of time slice rotation to enable this function. When task scheduling is switched, each task can only execute 1 tick.
The rtthread system can directly pass in the time slice parameter when creating a thread. When thread scheduling is switched, it will occupy CPU resources according to the time slice passed in when creating a thread, and schedule threads with the same priority.
Sixth, priority
The priority of the freertos system is defined as, the greater the value of the priority, the higher the priority of the task.
The priority of the rtthread system is defined as, the smaller the value of the priority, the higher the priority of the thread. A thread with a priority of 0 has the highest priority.

RTOS Kernel Use Cases Supported by ES32 SDK

ES32 SDK provides users with kernel use cases of FreeRTOS, RT-Thread-Nano and Huawei LiteOS, as shown in the figure below. Users can learn the use of RTOS through these use cases.

RTOS details

FreeRTOS

FreeRTOS FreeRTOS was released by Richard Barry of the United States in 2003. It cooperates closely with many semiconductor manufacturers and is currently the RTOS with the highest market share. Follow the GPLv2+ license agreement.

FreeRTOS is just an operating system kernel, and it needs to expand third-party GUI (graphical user interface), TCP/IP protocol stack, FS (file system) and other components to realize a more complex system. Unlike RT-Thread, which has a rich ecosystem of components and software packages, it can quickly implement a variety of  IoT  systems.

RT-Thread The copyright of RT-Thread belongs to Shanghai Ruiside Electronic Technology Co., Ltd. It was first released in January 2006. The initial version number is 0.1.0. After 10 years of development, the main version number has now been upgraded to 4.0.3, accumulative The number of developers has reached millions, and the installed capacity of products in various industries has reached an astonishing hundreds of millions, occupying the top spot among domestic RTOSs. It follows the Apache-2.0 open source licensing model.

The overall structure of RT-Thread is as follows:

The RT-Thread operating system process management algorithm is the same as the RR scheduling in the RT scheduler in Linux, and time slice rotation training is added on the basis of strict priority.

It specifically includes the following parts:

  • Kernel layer: RT-Thread kernel is the core part of RT-Thread, including the implementation of objects in the kernel system, such as multi-threading and its scheduling, semaphores, mailboxes, message queues, memory management, timers , etc .; lib cpu / BSP ( Chip Migration Related Documents/Board Support Package) is closely related to hardware and consists of peripheral drivers and CPU migration.
  • Component and service layer: Components are upper-layer software based on the RT-Thread kernel, such as virtual file system, FinSH command line interface, network framework, device framework, etc. Modular design is adopted to achieve high cohesion inside components and low coupling between components .
  • RT-Thread software package: running on the RT-Thread  Internet of Things operating system platform, it is a general software component for different application fields, consisting of description information, source code or library files. RT-Thread provides an open software package platform, where official or developer-provided software packages are stored. This platform provides developers with a choice of many reusable software packages, which is also an important part of the RT-Thread ecosystem. The software package ecology is very important for the selection of an operating system, because these software packages are highly reusable and highly modular, which greatly facilitates application developers to create the system they want in the shortest possible time. . The number of software packages supported by RT-Thread has reached 300+.
  • IDE:RT-Thread Studio

The RT-Thread kernel structure is as follows:

The kernel is above the hardware layer, and the kernel part includes the kernel library and real-time kernel implementation.

The kernel library is a small set of C library-like function implementation subsets to ensure that the kernel can run independently. This part will be different depending on the compiler's own C library. When using the GNU GCC compiler, it will carry more standard C library implementations.

Huawei LiteOS

Huawei LiteOS is an "open source and free" real-time operating system. It is a lightweight IoT operating system for the IoT field. It is widely used in smart home , personal wearables, Internet of Vehicles, urban public services, manufacturing and other fields. and maintenance costs, effectively lowering the development threshold and shortening the development cycle. Follow the BSD-3 open source license agreement.

The overall structure of LiteOS is as follows:

It mainly includes the following components:

  • Basic kernel: including the non-cuttable minimal kernel and other modules that can be cut. Tiny Kernel contains task management, memory management, interrupt management, exception management and system clock . Tailorable modules include semaphores, mutexes, queue management, event management, software timers, etc.
  • Kernel enhancement: In addition to the basic kernel functions, further enhanced functions are provided, including C++ support, debugging components, etc. The commissioning component provides powerful problem location and commissioning capabilities, including shell commands, Trace event tracking, obtaining CPU usage, and LMS.
  • File system: Provide a set of lightweight file system interfaces to support the basic functions of the file system, including vfs, ram fs, fatfs, etc.
  • System library interface: Provide a series of system library interfaces to improve the portability and compatibility of the operating system, including Libc/Libm/POSIX and CMSIS adaptation layer interfaces.
  • Network protocol stack: Provide a rich network protocol stack to support a variety of network functions, including CoAP/Lw M2M , MQTT, etc.
  • Business components: A series of business components or frameworks built on the above components to support richer user scenarios, including OTA, GUI, AI, sensing frameworks, etc.
  • IDE:Huawei LiteOS Studio。

The Huawei LiteOS kernel structure is as follows:

Since the release of Huawei LiteOS in the open source community,   it has built an open source IoT ecosystem around the NB-IoT IoT market from multiple dimensions such as technology, ecology, solutions, and commercial support. Currently, it has aggregated 50+ MCUs and solutions Partners jointly launch a batch of open source development kits and industry solutions to help customers in many industries quickly launch IoT terminals and services. Customers cover many industries and provide developers with a "one-stop" complete software platform, effectively reducing the development threshold , Shorten the development cycle.

The basic kernel of Huawei LiteOS includes a very small kernel that cannot be tailored and other modules that can be tailored. Tiny Kernel contains task management, memory management, interrupt management, exception management and system clock. Tailorable modules include semaphores, mutexes, queue management, event management, software timers, etc. Huawei LiteOS supports UP (single-core) and SMP (multi-core) modes, that is, it supports running in a single-core or multi-core environment.

Guess you like

Origin blog.csdn.net/u012294613/article/details/130881855