Real-time multitasking systems are widely used, almost penetrating into all walks of life, and the system classification is also very complex. In embedded systems, the real-time multitasking mechanism is implemented by a background task management program that runs after startup. The application runs on this manager program. The background performs resource management, message management, task scheduling, exception handling, etc. according to the requirements of each task. Its primary purpose is to schedule all available resources to achieve real-time control tasks.
There are two main categories of real-time systems: soft real-time systems and hard real-time systems. The purpose of a soft real-time system is to make each task run as fast as possible, without limiting the time within which a task must be completed. In a hard real-time system, each task must not only be executed correctly but also on time. Most real-time systems are a combination of the two. For a complex task system, the selection of task scheduling mode is a key point in its system architecture. Paperless recorders have multi-level interface management and high real-time response requirements, so it is imperative to choose a system task scheduling mode that is suitable for it.
This paper comprehensively considers the real-time requirements of each task response, makes creative adjustments to the tasks, and then organically combines the soft real-time system and the hard real-time system to plan the most reasonable task scheduling mode.
1. Features of real-time multi-tasking of recorders
Conventional real-time multitasking operating systems are relatively large and are not suitable for real-time systems composed of single-chip microcomputers (80C320). Since the computing power and memory of single-chip microcomputers are limited, real-time operating systems are required to be simple, practical, efficient and reliable. As for the recorder, its tasks and functions are predictable, so the memory and file management system can be simplified or even eliminated [1]. Because the task's requirements for memory are clear, a fixed and independent storage area allocation scheme can be used without the need for OS control and allocation. 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 task states in the recorder: running, ready, waiting, and suspended. The sleep state is merged into the waiting state and is no longer distinguished.
2 Task Division, Organization and Scheduling
2.1 Division of tasks
In a single-chip real-time multitasking system, the key to implementing a real-time multitasking mechanism is to reasonably decompose the system functions into various task modules. The principle of task division: programs that are relatively independent in function and can be executed simultaneously with other programs are divided into one task. However, the task division cannot be too detailed, otherwise it will increase the system overhead of task switching, reduce system efficiency and affect the real-time response of the system. Reference [2] points out that closely related tasks should be merged as much as possible to reduce communication between tasks. Taking into account the real-time nature and execution time of the tasks, the ten tasks of the recorder can be divided into three categories:
(1) High priority tasks: processing of sample values uploaded by the lower computer, virtual channel organization, and alarm processing. This type of task has high real-time requirements and an execution time of <0.1s. For example, in the sample value processing task, the recorder must save the sample values as historical data and add a time stamp during the saving process. Records with correct sample values but incorrect time stamps are invalid.
(2) Low-priority tasks: key response, display, PID control, flow totalizer. The execution time of this type of task is less than 0.2s, and the real-time requirements of the task are general. For example, for key response tasks, a delay of 0.5s is tolerable.
(3) Background tasks: storage, printing, and communication with the management computer (PC). The execution time of this type of task is > 1s, and the real-time requirement is the lowest.
2.2 Task Organization
When the system is powered on, the fixed task stack of each task is initialized, and the task queue status table and task control table (TCB) are established. 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 tasks; 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 Task Scheduling Based on Message-Driven Mechanism
Drawing on the idea of object-oriented programming, the concept of message is introduced into the recorder program, and the execution conditions of the task are converted into messages. The corresponding tasks are activated by the messages, and the scheduling is implemented by the task scheduling module. The message is defined as: when an event (such as an interrupt or the completion of a task) occurs, the event handler sets the corresponding flag, and different flags represent different messages. The event handler can be an interrupt service program or a task that needs to set a flag after execution. Therefore, the scheduling of tasks in the recorder is driven by the message mechanism. The role of the message in the multi-task program is equivalent to a bridge, which makes the tasks both independent and organically related. Tasks cannot be called directly, but need to be implemented by the task scheduling module with the help of messages.
The interrupt service program consists of two parts: the interrupt message (flag) handler and the interrupt task handler. The former only completes the message (flag) processing and then exits the interrupt, while the actual operation to be completed by the interrupt task handler is completed under the coordination of the task scheduling module. For example, if the display is pressed, the key interrupt message handler only generates a key message (flag) and then exits the interrupt, and the scheduling module calls the key interrupt task handler to obtain the key value and generate a display message based on the key message. The scheduling module calls the display task program based on the display message.
3 Real-time multi-task scheduling strategy
Multitasking systems usually use the kernel to manage each task, that is, the kernel allocates CPU time to each task and is responsible for communication between tasks. According to the task scheduling mechanism, it can be divided into non-preemptive kernel and preemptive kernel. The former requires each task to actively release CPU and other resources, while the latter supports the deprivation of the CPU usage right of the current task, so that the higher priority ready task can obtain CPU control and execute.
The scheduling strategy adopted by embedded systems usually takes into account three factors: the processing power of the system, the number of tasks, and the system's requirements for response time and execution efficiency. Preemptive scheduling can improve the real-time performance of high-priority tasks, but the system overhead is large; non-preemptive scheduling is just the opposite of preemptive scheduling. For the recorder, a preemptive and non-preemptive composite multi-task scheduling strategy is proposed. The normal working cycle of the recorder is 1s, and the working cycle of the scheduling module is also 1s. 1s is divided into three periods: 0s-0.5s, 0.5-0.8s, and 0.8s-1s. The real-time clock generates an interrupt at 0s, 0.5s, and 0.8s, respectively, and sets the Time-flag to 0, 5, and 8, respectively, and sets the Attemper-flag to 0. The task scheduling program flowchart is shown in Figure 2.
In one working cycle (1s) of the recorder, the composite scheduling strategy allows high-priority tasks to preempt low-priority and background tasks three times, while low-priority tasks have the right to preempt background tasks twice. Therefore, the response time of high-priority tasks is t≤0.5s, and the response time of low-priority tasks is t≤0.7s. Since the number of preemptions is limited, the task switching overhead is not large, which is conducive to improving system efficiency.
The preemptive and non-preemptive composite multi-task scheduling strategy has been successfully applied to a recorder and achieved the expected goal.
Previous article:Factors Affecting the Frequency Resolution of Spectrum Analyzers
Next article:Design of Cable Continuity Tester Based on PC104
- Keysight Technologies Helps Samsung Electronics Successfully Validate FiRa® 2.0 Safe Distance Measurement Test Case
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Seizing the Opportunities in the Chinese Application Market: NI's Challenges and Answers
- Tektronix Launches Breakthrough Power Measurement Tools to Accelerate Innovation as Global Electrification Accelerates
- Not all oscilloscopes are created equal: Why ADCs and low noise floor matter
- Enable TekHSI high-speed interface function to accelerate the remote transmission of waveform data
- How to measure the quality of soft start thyristor
- How to use a multimeter to judge whether a soft starter is good or bad
- What are the advantages and disadvantages of non-contact temperature sensors?
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Transplantation of webplayer audio player based on RVB2601
- The output voltage of the DCDC circuit is equal to the input voltage. What's going on?
- Square wave generates triangle wave
- Altium Designer 17,18,19 Export Coordinates Tutorial
- Line scan camera testing
- [RVB2601 Creative Application Development] RVB2601 Development Environment Part 2
- MCU serial communication program help
- When the TL5708 development board does not have a router, connect the PC and the development board with a network cable and place them in the same network segment to transfer files between them.
- [Mil MYC-JX8MPQ Review] + Improve the sht20 reading on the QT side
- What does DIN VDE V 0884-11:2017-01 mean for digital isolator certification?