The role of real-time operating system and embedded real-time operating system

The role of real-time operating system and embedded real-time operating system

  1. Real-time operating system

1.1 Definition of RTOS

What is real time? Real-time means immediate and timely. If the operating system can enable the computer system to respond to the request of external events in time, and can control all real-time devices and real-time tasks in a timely manner, and can complete the processing of events within a specified time, then this kind of operating system is a real-time operation. System (real time operation system, RTOS.

From the perspective of time, real-time operating systems are divided into hard real-time operating systems and soft real-time operating systems. If the system must complete real-time tasks within a very strict time, then such a system is called a hard real-time operating system. For example, in order to prevent the ship from hitting the rocks during navigation, the head of the ship is equipped with a sonar to find the reef, the sonar signal is input into the embedded system, and the embedded system controls the action of the steering gear. Now suppose that there is a reef in front of the ship without taking any evasive action, the ship will collide with the reef after 10 minutes, and it takes 8 minutes for the steering gear to complete a reasonable evasive action. That is to say, from the discovery of the reef by the sonar to the start of the steering gear, the time left for the embedded system to calculate the data required to control the steering gear to make a reasonable action cannot exceed 2 minutes, and the calculation result should be correct: otherwise, the consequences will be catastrophic. For hard real-time systems, both correct results and incorrect results calculated beyond the deadline cannot be tolerated, because the accident has already occurred, and the results are no longer useful.

Relatively speaking, if the deadline for the system to complete the real-time task is not very strict, then this kind of system is called a soft real-time system. That is to say, the soft real-time system has a certain tolerance for calculation timeout, and the calculation result obtained beyond the allowable calculation time will not be completely useless, but the reliability of the result should be reduced to some extent.

As can be seen from the above description, the real-time performance of a system requires not only the guarantee of hardware, but also the guarantee of the operating system, that is, no matter under what circumstances, the time taken by the operating system to complete the task should be predictable when the application is designed. of.

1.2 Conditions to be met by a real-time operating system

Embedded systems mainly control equipment and devices. In these applications, whether the system can respond to external events in a timely and fast manner is usually the first requirement for the system. Therefore, most of the operating systems used by embedded systems are real-time. operating system. For a real-time operating system, it is required to calculate the output result as quickly as possible after receiving the input under the existing hardware conditions, and the application program designer can accurately determine in advance when designing the application program to complete the task. the maximum time required.

In order to meet the above requirements, the real-time operating system should meet three conditions: ① the real-time operating system must be a multi-tasking system; ② the task must use a unique priority to indicate the right to obtain the CPU; ③ the task switching time should be consistent with the number of tasks in the system. Irrelevant: ④ The time of interrupt delay is predictable and as short as possible 1.

1) Multitasking
When a computer executes an application program, it often uses I/O devices for data input and output, and I/O devices always take a while to work. During the operation of the I/O device, if the central processing unit (CPU) has no other tasks, it can only wait, so it will take a long time for the computer to run an application program. Poor sex.

If a large task is decomposed into multiple small tasks that can be run in parallel, the right to use the CPU can be handed over within the time that a task needs to wait, and the CPU can run other tasks, which can greatly improve the CPU utilization. Of course, the time taken by the system to complete the task will be greatly reduced, thus creating conditions for improving the real-time performance of the system. In addition, the multitasking system also brings another advantage, that is, it allows programmers to divide a large application program into relatively independent multiple tasks to complete, thus providing great advantages for the design and maintenance of the application program. Great convenience. Due to the many advantages of multitasking, today’s embedded real-time operating systems are multitasking systems.

2) The type of kernel
Since there is only one CPU in an embedded system, only one task among multiple tasks is allowed to use the CPU at a specific moment. According to the way in which the tasks in the system obtain the right to use the CPU, the kernels of multitasking real-time operating systems are divided into deprivable types. and inalienable types. But no matter what type of core, each task must have a unique priority level to denote its right to the CPU. Inalienable kernels are also called cooperative multitasking kernels. In this kind of kernel, the task with high priority always gets the right to use the CPU first.

In order to prevent a task from always occupying the right to use the CPU, this kernel requires that each task must be able to actively give up the right to use the CPU. In a deprivable kernel, the CPU always runs the task with the highest priority among multiple tasks, even if the CPU is running a low-priority task, when a high-priority task is ready, the high-priority task is ready. It will deprive the running task of the CPU usage rights, and make itself get the CPU usage rights. Due to the better real-time performance of the deprivable kernel, most of the embedded real-time operating systems at present are deprivable kernels.

3) Task switching time
Since it is a multitasking system, there is switching between tasks, and the scheduler of the operating system does this work. The scheduler needs a period of time when switching tasks, and the length of this period is also an important factor affecting the real-time performance of the system. In order for the designer of the application program to calculate the exact execution time for the system to complete a certain task, the running time of the scheduler required to perform task switching is fixed, that is, the time used by the scheduler to perform task switching cannot be affected by other factors in the application program. (such as the number of tasks).

4) Interrupt delay
The occurrence of an external event is often notified to the CPU in the form of an interrupt request signal, and then the interrupt service routine is run to process the event. The time from the CPU responding to the interrupt to the time the CPU turns to the interrupt service routine is called the interrupt latency. Obviously, the interrupt delay will affect the real-time performance of the system. Therefore, shortening the interrupt delay is also a problem that real-time operating systems need to solve.

  1. Embedded RTOS

Because the embedded system completes the control task of a device or equipment, the function of the task is relatively fixed, in general, the typical task supported by the embedded real-time operating system should be an infinite loop structure.

A task is essentially a function that returns void and does the user’s work in an infinite loop within the function. So, how does the application respond to some external asynchronous events from the user? Of course use interrupt technology and handle these asynchronous events in an interrupt service routine. A typical structure of an embedded system task is shown in Figure 1.

Figure 1 - Typical structure of an embedded system task
Figure 1 – Typical structure of an embedded system task

To sum up, the micro-system software that is used in embedded systems, manages system resources and multiple tasks, and has excellent performance such as high reliability and good tailorability, provides a running platform and real-time services for applications. Embedded real-time operating system.

At present, embedded operating systems mainly provide “micro-kernel”, and others such as window system interface, file management module, communication protocol, etc. have to be designed or purchased by developers themselves. Most embedded operating systems mainly provide the following three services to assist application designers.

(1) Memory management: Memory management is mainly dynamic memory management. When a certain part of an application needs to use memory, the memory allocation function provided by the operating system can be used to obtain enough memory space. Once used, the release memory function provided by the system can be called to return the used memory space to the system, so that the memory can be reused.

(2) Multitasking management: The embedded real-time operating system should provide a wealth of multitasking management functions to provide convenience for programmers to design multithreaded applications. Usually, embedded real-time operating systems will provide a good task scheduling mechanism to control tasks such as starting, running, suspending and ending states. Usually these scheduling algorithms meet the real-time requirements, that is, each action of the task can be executed within a strictly required time.

(3) Peripheral resource management: a complete embedded application system, in addition to the microprocessor and memory of the system itself, must also be supported by a variety of peripheral devices, such as keyboards, display devices, communication ports and external controllers Wait. These peripherals are resources that may be used by various tasks in the system. Due to the limited resources, the operating system must reasonably schedule and manage these resources to ensure that each task that uses resources can obtain sufficient resources at runtime. Faced with the huge application fields and attractive prospects of embedded systems, the world The major software development companies, manufacturers and even individuals have developed their own embedded operating systems. At present, the more common embedded operating systems are VxWorks from WindRiver, Windows CE from Microsoft, QNX Os from QNX, and Plam, WinCE, and EPOC, which are three-thirds of the embedded operating system for handheld devices. The system is expensive. Faced with this situation, some organizations and individuals have also developed some free and open source operating systems and released them on the Internet, the more famous ones are Linux and pC/oS-I1.

Read more: Definition and classification of new energy vehicles

Related Posts