Planning of multi-task scheduling mode for recorders

Publisher:少年不识愁滋味Latest update time:2011-08-23 Keywords:Recorder Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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.

Keywords:Recorder Reference address:Planning of multi-task scheduling mode for recorders

Previous article:Factors Affecting the Frequency Resolution of Spectrum Analyzers
Next article:Design of Cable Continuity Tester Based on PC104

Latest Test Measurement Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号