Application of embedded real-time operating system uC/OS in Control Engineering

Source: Internet
Author: User
In the field of embedded real-time applications, the entire software was generally designed as a front-and-back-end system. An application is an infinite loop. It calls the corresponding functions in a loop to complete the corresponding operations. This part is the background behavior. The interrupted service program processes asynchronous events, which is the foreground behavior. This is suitable for simple control. However, when the situation is complex, engineers are now inclined to apply an appropriate operating system to reduce the difficulty of system development and make the design and expansion of real-time applications easier, new functions can be added without major changes. UC/OS is an embedded real-time operating system suitable for developing small and medium-sized projects.

1. Features of uC/OS

UC/OS is a real-time, multi-task operating system with high portability and open source code. Its real-time kernel adopts a preemptive scheduling policy. This means that he always runs the task with the highest priority under the ready condition. When task a is running, for some reason, Task B with a higher priority enters the ready state, task a is immediately suspended and Task B is running. This may be because task a has sent a semaphore to activate Task B, or when task a is running, an interruption has arrived, the interrupted service subroutine enables Task B to enter the ready state. After the interruption is completed, Task B starts to run.

The uC/OS kernel uses a fixed-priority scheduling method. Therefore, each task must have a clear and different priority assigned to it by the program designer. If the designer wants the priority of a task to change based on time or condition changes, the designer must call the function ostaskchangeprio () to change the priority of the task. For example, if a minor fault does not affect system security in the system, a fault alarm task is triggered accordingly. At the beginning, the alarm task has a low priority and is always preemptible by a high-priority task, therefore, the task can only be executed once at intervals of a long period of time. Over time, if the fault cannot be handled, the priority can be gradually increased until the highest priority is reached.

If there is competition or deadlock between tasks due to shared resources, the system security will be seriously affected. Therefore, uC/OS provides a protection mechanism for shared resources. Generally, the semaphore method is used. Create a semaphore and initialize it. When a task needs to use a shared resource, it must first apply for the semaphore. In this process, even if a task with a higher priority enters the ready state, the resource cannot be used because the semaphore cannot be obtained. In uC/OS, priority is reversed. Simply put, a high-priority task must wait for the completion of a low-priority task. In the above circumstances, priority inversion between two tasks is unavoidable. Therefore, when using uC/OS, you must have a clear understanding of the developed system to choose whether to use semaphores for a shared resource.

For a complex real-time system, not all tasks are crucial, but most of them are integrated with both soft real-time and hard real-time requirements. A soft real-time system only requires that the system be executed as quickly as possible, and does not require completion within a specific time. In a hard real-time system, tasks must not only be executed correctly, but also be completed on time. Therefore, the given priority is a big problem related to system scheduling efficiency. It is also a task closely related to a specific system. 2 multi-task division in the software design of the elevator system

In a tall building, Multiple elevators often coexist to form a group control system. Therefore, the software system of each elevator not only controls the normal operation of the elevator, but also exchanges data with other elevators for optimal scheduling to reduce the waiting time of passengers and save energy.

In particular, each elevator is related to the safety of personnel and equipment, and its system reliability is very important. Although the final security guarantee is implemented by certain hardware devices, for example, when the elevator is completely out of control and falls down, the vehicle is stuck on the track by the Security clamp; however, these measures immediately stop the operation of the elevator, which brings great vibration and psychological discomfort to the passengers and may also cause damage to the equipment. Therefore, the software system should be the first security measure while completing normal functions.
Line of defense, so that the elevator can be easily changed in the case of a fault, reducing the impact on personnel and equipment.

2.1 Hardware System Structure

The hardware architecture 1 of the software system is shown in.

The M-elevator is connected by the CAN bus. Each master controller is equivalent, and each elevator is also a CAN bus.

2.2 Software Design

The software of each elevator is the same. The priority of the software system design is:

(1) Satisfying local security means the fastest response to signals involving security;
(2) meeting the normal control of the local machine, that is, normal control of the elevator operation status and motor operation;
(3) There are three deciding factors in responding to the call of a passenger as soon as possible: first, the timeliness of the communication response to the lower computer; and second, the timeliness of Inter-communication between multiple elevators; the third is the validity of the scheduling algorithm. The designed task level 2 is shown in.

This is a multi-chain multi-task system, and several tasks are common tasks. The priority is:

In a task chain, the most important task does not want to be interrupted by other tasks in the same task chain, so it should be set to the highest priority.

Except for public tasks, any task in task chain A has a higher priority than any other task in task chain B. The Setting principle of public tasks in different task chains is high or low. This setting ensures that tasks in the high-level task chain can be blocked at most once when the priority is reversed.

Each task of the system is independent. To increase system reliability, a super task is designed to monitor several important tasks. The working principle is to add the following code to important tasks, such as taskx,

Taskx ()
{Read the timer value to the global variable X;
...
Global variable X clear 0;
Latency;
}

UC/OS has a system clock (generally 10 ~ 100Hz), the code is executed every time the clock is interrupted. Ostimetickhook () is reserved for developers. We can use this function to do the following: ostimetickhook ()
{

If (the value of the current timer is a global variable X> = scheduled time ){
Processing,
Bytes ﹜
Bytes ﹜

This can effectively prevent the system from being fully crashed due to internal problems of individual tasks. Its essence is a time-out control.

3 knots

Using the system features provided by uC/OS, You can simplify multi-task Programming and meet the time requirements of multiple tasks, greatly reducing the development difficulty and easily completing tasks that are difficult to complete in front-end and back-end programming methods. At the same time, with the scheduled interruption of the system, a super task is designed to monitor other tasks, which improves the system reliability. Of course, we can also see that the readability and maintainability of the program are also improved.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.