UART0 serial port programming (IV): The crisis of UART0 serial port programming in UC/OS-II

Publisher:ShimmeringStarLatest update time:2019-09-23 Source: eefocusKeywords:UART0 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. Potential Crisis

1. When designing serial port programming in uc/os operating system, the situation is complicated because ISR and multiple tasks are executed concurrently. Especially when the receiving state is passive, data can only be received by serial port interrupt.

2. During serial communication, both parties follow the same communication protocol. Since the baud rate remains unchanged, the interval between two consecutive serial port interruptions is basically fixed.

3. The receiving process will be wrong in the following two situations:

(1) The first case is that the maximum time the system turns off interrupts is greater than the interval between two adjacent serial receive interrupts. This may result in missing an interrupt and causing data loss.

(2) The maximum time that the real-time operating system kernel disables interrupts is known and is usually very short, so it is not the key to the problem.

(3) The longest time the system takes to disable interrupts is often caused by user software. For example, the interrupt service function we wrote is too complicated, causing the system to take too long to disable interrupts in order to process the interrupt service function.

(4) The second situation is that when the serial port program is running, an interrupt program with a higher priority interrupts the serial port program, resulting in data loss.

(5) Here is a concept: the period of time when the serial port reception interrupt cannot be responded is called "dead zone". Therefore, the key to solving the problem is that the dead zone time cannot be longer than the interval between two consecutive serial port interrupts.


2. How to resolve the crisis

l Do not disable interrupts (use mutex semaphores instead) when a task accesses a time-consuming shared resource.

l The ISR should be as brief as possible, and any work that can be separated should be delegated to related tasks.

(The design here is similar to the principle of dividing interrupts into the upper and lower parts in Linux)

Use the above method to shorten the dead time.

Another method is:

Increase the interval between two adjacent serial port receive interruptions.

l Method 1: Reduce the baud rate. This method is simple, but it also leads to a decrease in communication efficiency. Secondly, the baud rate is usually fixed when programming the serial port. Therefore, this method is generally not applicable.

l Method 2: Reduce the number of interrupts while keeping the baud rate unchanged, so as to lengthen the interval between two adjacent serial port receive interrupts.

The serial port of the ARM chip has a 16-byte buffer, and can be set to generate an interrupt after receiving 1, 4, 8, or 14 bytes. If it is set to interrupt after receiving 8 bytes, the interrupt interval will be extended by 8 times compared to a 1-byte interrupt.

Tiger-John Description:

After using the serial port programming with data buffer function, it is easier to meet the condition that the interval between two consecutive serial port receive interrupts is greater than the dead time, but there are still potential dangers.

To reliably avoid this crisis: the following conditions must be met

(1) The interval between two consecutive serial port receive interrupts must be greater than the system dead time

(2) The idle time of the receive buffer must be sufficient to store the new data received during the "dead zone" time.

 If the interrupt is set every time 8 bytes are received, the free space is also 8 bytes. Since the dead time is shorter than the interrupt interval, the new data received must be less than 8 bytes to avoid data loss.

That is, under the premise that the interrupt interval is greater than the "dead zone" time, the interrupt condition is set to 1/2 of the receiving buffer, then the dead zone time is close to the interrupt interval time, and the receiving process is reliable.


Keywords:UART0 Reference address:UART0 serial port programming (IV): The crisis of UART0 serial port programming in UC/OS-II

Previous article:UART0 serial port programming (I): Communication protocol design; RS232 standard
Next article:Various ARM emulator interface diagrams

Recommended ReadingLatest update time:2024-11-23 15:39

Protection issues of UC3842 circuit
The typical circuit of the switching power supply made of UC3842 is shown in Figure 1. Overload and short circuit protection is generally achieved by connecting a resistor (R4) in series with the source of the switch tube to send the current signal to the third foot of 3842. When the power supply
[Power Management]
Protection issues of UC3842 circuit
Design of intelligent window system based on μC/OS-II
0 Introduction With the development of computer technology, electronic technology and control technology, intelligent, automated and precise irrigation and fertilization technology is gradually replacing traditional irrigation methods. In the fertilization process, it is necessary to detect the pH and conductivity of
[Microcontroller]
Transplantation of μC/OS-II on S3C44BOX Processor
Abstract: This paper introduces the characteristics and kernel structure of the real-time operating system μC/OS-II, gives the steps and detailed related codes for porting μC/OS-II to Samsung embedded S3C44BOX ARM7 microprocessor, and explains the issues that should be paid attention to in the application of μC/OS-II.
[Microcontroller]
Transplantation of μC/OS-II on S3C44BOX Processor
Implementation of μC/OS-II Task Scheduling Hardware Instructions for Cortex-M3
1 Analysis of the task scheduling algorithm of μC/OS-II 1.1 Interpretation of the μC/OS-II task ready table The μC/OS operating system adopts the principle of task scheduling with priority first, so that the task with the highest priority among the tasks that enter the ready state can run immediately once it
[Microcontroller]
Implementation of μC/OS-II Task Scheduling Hardware Instructions for Cortex-M3
μC/OS-II real-time performance test and research
Real-time performance refers to the ability of a system to complete tasks within a limited time and respond to external asynchronous events in a timely manner. In most industrial controls, the requirements for real-time performance are very high. A real-time operating system is an operating system that can meet the
[Microcontroller]
Design and analysis of single-ended flyback switching power supply based on UC3842
  Power supply devices are an important field of power electronics technology application, among which high-frequency switching DC regulated power supplies have been widely used due to their outstanding advantages such as high efficiency, small size and light weight. The control circuit of the switching power supply ca
[Power Management]
Design and analysis of single-ended flyback switching power supply based on UC3842
Design of frequency converter structure control system based on uC/OS-II
This paper introduces the functional principle of variable structure control system of oil pumping motor inverter, how to use the multi-tasking function of uC/OS-II to realize the algorithm structure transformation of control system, the transplantation of operating system, the establishment of multi-tasking and the so
[Industrial Control]
Design of frequency converter structure control system based on uC/OS-II
Latest Microcontroller 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号