In this paper, the uC/OS-II operating system is transplanted to the LPC2132 kernel produced by PHILIPS. Based on the system's message mechanism and priority permissions, a task with the highest priority is set as a monitor to monitor all tasks running on the microcomputer. As long as a task fails, the monitoring task will delay feeding the dog, causing the timer to overflow and restart the system to ensure that the microcomputer and all tasks are in a long-term stable operating state.
1 System Overview
1.1 Introduction to hardware and development environment
The uC/OS-II operating system was ported to the LPC2132 development board. LPC2132 is a 32-bit ARM7TDMI-STM core microprocessor that supports real-time simulation and tracing, with 64kB high-speed FLASH memory, 4 communication interfaces, 2 32-bit timers, 1 10-bit 8-channel ADC, 2 hardware interfaces, 47 GPIOs and up to 9 edge or level-triggered external interrupts, which can fully meet the needs of general applications and expansion.
uC/OS-II is a preemptive multi-tasking real-time operating system. Its source code is open and highly portable. It is easy to use, easy to develop and popular. uC/OS-Ⅱ can manage up to 64 tasks, which are usually functions of an infinite loop. In the current version, tasks with priorities of 0, 1, 2, 3, OS_LOWEST_PRIO-3, OS_LOWEST_PRIO-2, OS_LOWEST_PRIO-1, and OS_LOWEST_PRIO are reserved, so users can have 5 to 6 tasks at the same time, which is enough to meet the various requirements of user design.
1.2 Functions implemented by the system
In a multi-task system, it is often hoped that when a task has a problem, the task will be restarted instead of the entire system, so as not to affect the operation of other critical tasks. When multiple restarts of the task are ineffective, the system will be restarted. The system will be restarted when an error occurs in the main program of the system or a problem occurs in the system hardware. The watchdog designed based on the above analysis mainly realizes the following functions.
(1) When a task fails, the software watchdog restarts the task.
(2) When multiple attempts to restart a task fail, restart the system.
(3) When an abnormality occurs in the operating system itself or in the system hardware, the microprocessor is restarted by the software watchdog or the hardware watchdog.
2 Multi-task watchdog monitoring principle
Combining the built-in hardware watchdog of LPC2132 and the uC/OS-Ⅱ operating system, a task with the highest priority is set as a monitor to monitor whether each application task is running normally. This monitor is called a software watchdog. This task sets a timer for each monitored task. The monitored task clears the corresponding timer regularly within the set time, which is called "feeding the soft dog". When the monitored tasks are all working normally, the software watchdog periodically clears the built-in hardware watchdog timer, which is called "feeding the dog". If a task in the monitored task group fails, the software watchdog cannot be "fed" within the set time, and the corresponding timer overflows. The system kernel sends an instruction to point the stack address of the task to its starting address and reset the task. If the task cannot be effectively started within the set number of times, the "feeding the dog" is delayed, the hardware watchdog counter overflows, and the system is restarted. In addition, when the monitor task itself fails, the hardware watchdog timer cannot be cleared in time to restart the system.
3 Software Implementation
3.1 Communication between application tasks and software watchdog
When information is transmitted between the multi-task software watchdog and each application task, each application task will send a running status message to the monitor, and the monitor task will also send a message to each task. In the case of a large number of application tasks, if mailboxes are used for communication, a large number of invalid operations will be caused, and programming will become cumbersome. Therefore, a message queue is used in the monitor task to realize message transmission with each application task, and two mailboxes are set in each application task, one for sending messages to the monitor message queue and the other for receiving messages sent by the monitor task message queue. When an application task fails in execution, the OSQPost() function is called to send a message to the monitor task message queue. The monitor task reads the message from the message queue by calling the OSQPend() function, and then calls the OSMboxPost() function to send messages representing different meanings to the message receiving mailbox of the application task. The task calls the OSMboxPend() function to read the message from the mailbox and then performs the corresponding operation.
3.2 Implementation of multi-task software watchdog
The multi-task watchdog monitors the running status of each task by checking whether each application task "feeds the soft dog" within the specified time. With the help of the timer interrupt mechanism of the microprocessor, a timing unit and a running flag are assigned to each task, and the timing interrupt performs independent timing according to the running flag status. When a task in the system is idle, it is periodically "fed" with a time interval less than the "feed the soft dog" setting as a period; when the task is executed, the longest execution time required is estimated, and the timer parameters in the monitor are set with a time interval slightly greater than the maximum time, and the periodic "feed the soft dog" module is interrupted at the same time, and the timer countdown in the monitor task is started. When the task is executed normally, the signal "feed the watchdog" is sent to clear the timer, reset the task, and restore the periodic "feed the watchdog" module; when the task execution is abnormal, the software watchdog cannot be cleared within the set time interval, causing the corresponding timer in the monitor to overflow. The monitor task sends instructions through the kernel service to point the stack address of the task to its starting address, restart the task, and accumulate the number of resets to clear the timer of the task.
4 Conclusion
Combining the built-in hardware watchdog of LPC2132 and the uC/OS-Ⅱ operating system, a software watchdog capable of multi-task management is designed. The watchdog can not only effectively monitor each application task, but also restart the task without affecting the normal operation of other tasks. The system will not be restarted until multiple restarts are invalid, thus achieving the goal of not overly restraining independent application tasks. In addition, the watchdog can also automatically restart when the main program and hardware have problems, ensuring long-term stable operation of the system.
Previous article:Improved design of Linux system software shell protection technology
Next article:Design and implementation of a high-performance queue manager for satellite switches
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- Wireless communication, 5G, RF, antenna and several concepts and indicators
- Happy Lantern Festival! Guess the lantern riddles and have fun
- How to make an automatic switch when there are 3 5V input ports on a circuit board?
- "Operational Amplifier Parameter Analysis and LTspice Application Simulation" Reading Notes Part 3 - Noise
- 280 million yuan in subsidies returned! A Russian supercomputer company's self-developed CPU failed to meet the standards and was sued by the Ministry of Industry and Trade
- I have a question about the drive circuit.
- Oh my god! My air conditioner has become a spirit!
- Analysis of the problem that the program cannot run after F28004x online debugging reset
- Ask for 88X3310PA1-BUS4I000 product manual
- The problem of BIN generated by STM32F051 being filled with 0