Real-time multitasking systems are extremely versatile, and they are almost infiltrated into all walks of life, and the system classification is complex. Although different applications are not exactly the same in the implementation mode, the core idea is the same. In embedded systems, the real-time multitasking mechanism is implemented by a background task manager running after startup. The application runs on top of the manager program. The background performs resource management, message management, task scheduling, and exception handling according to the requirements of each task. Its primary purpose is to schedule all available resources for real-time control tasks.
There are two main types of real-time systems: soft real-time systems and hard real-time systems. The purpose of the soft real-time system is to make each task run as fast as possible, and does not require limiting how long a task must be completed. In a hard real-time system, tasks are not only executed without errors but also on time. Most real-time systems are a combination of the two. For a complex task system, the choice of task scheduling mode is a key point of its system architecture. The paperless recorder has multi-level interface management and high real-time response requirements, so it is imperative to choose the system task scheduling mode that is suitable for it.
This paper comprehensively considers the real-time requirements of each task response, and makes creative adjustments to the task. Then the soft real-time system and the hard real-time system are organically combined to plan the most reasonable task scheduling mode.
1 Recorder real-time multitasking features
The usual real-time multitasking operating systems are relatively large, and are not applicable to real-time systems composed of single-chip microcomputers (80C320). Due to the limited computing power and memory of the microcontroller, the real-time operating system is required to have simple, practical, efficient and reliable features. As far as the recorder is concerned, its tasks and functions are foreseen, and the memory and file management system can be simplified or even cancelled [1]. Because the task's memory requirements are clear, fixed and independent storage area allocation schemes can be used without the need to control and distribute through the OS. Therefore, the real-time multitasking operating system can be simplified to a scheduling module based on task scheduling and clock interrupt management. There are four types of tasks in the recorder: run, ready, wait, suspend, and sleep states are merged into waits, no longer distinguishing them.
2 Division, organization and scheduling of tasks
2.1 Division of tasks
In the real-time multitasking system of the single-chip microcomputer, the key to realize the real-time multi-tasking mechanism is to reasonably decompose the system functions into individual task modules. The principle of dividing tasks: Programs that are relatively independent in function and can be executed simultaneously with other programs are divided into one task. However, the task division can not be too fine, otherwise it will increase the system overhead of task switching, reduce system efficiency and affect the real-time response of the system. Document [2] pointed out that it should try to merge closely related tasks and reduce communication between tasks. Taking into account the real-time nature of the task and the execution time, the ten tasks of the recorder can be divided into three categories:
(1) High-priority tasks: processing of uploading sample values ​​by the lower computer, virtual channel organization, and alarm processing. This kind of task has high real-time requirements, and the execution time is <0.1s. For example, the sample value processing task, the recorder should save the sample value as historical data, the time stamp should be added during the save process, the sample value is correct, and the time record error record is invalid. of.
(2) Low priority tasks: button response, display, PID control, flow accumulation. This type of task execution time <0.2s, the task real-time requirements are general. If the button responds to the task, a delay of 0.5s is tolerable.
(3) Background tasks: storage, printing, and communication with the management machine (PC). The execution time of such tasks is >1s, which requires the lowest real-time performance.
2.2 Organization of tasks
The system is powered on, initializes the fixed task stack of each task, and establishes a task queue status table and a task control table (TCB). These two tables are the basis for task scheduling. The task queue status table consists of three sub-tables: high priority, low priority, and background task. The task control table consists of three parts: task first address, status register, and task local variable. The data structure is shown in Figure 1.
2.3 Message-driven mechanism based task scheduling
Drawing on the idea of ​​object-oriented programming, the message concept is introduced in the recorder program, the execution condition of the task is converted into a message, the corresponding task is activated by the message, and the task scheduling module implements the scheduling. The message is defined as: When an event (such as an interrupt or a task is completed) occurs, the event handler sets the corresponding flag, and different flags represent different messages. The event handler can be an interrupt service routine or a task that needs to be set after execution. Therefore, the scheduling of tasks in the recorder is driven based on the message mechanism. The role of the message in the multitasking program is equivalent to the bridge, so that the tasks are independent and organically related to each other. The tasks cannot be directly called, and the message scheduling module is implemented by the task scheduling module.
Aluminum Extrusion Radiator,Led Heat Sink Aluminum,Heatsink Extrusion Profiles,Aluminium Heatsinks
Original Electronics Technology (Suzhou) Co., Ltd. , https://www.original-te.com