CN-117149367-B - Timer management method based on embedded real-time operating system
Abstract
The invention relates to a timer management method based on an embedded real-time operating system. The method comprises the steps of firstly creating a list, adding timer services required by each thread in a system to a software timer management list in sequence, arranging the software timer timeout time management list in sequence according to the size of the software timer timeout time, calling a timer in the system to execute timing services according to the timeout time sequence in the software timer timeout time management list, loading corresponding software timer service functions to the software timer service function management list after the timer counts to the timeout time, and finally executing the software timer service functions in the list to realize the timer services required by each thread in the system. The invention can meet the timing service demands of numerous and various real-time embedded network devices even if the hardware high-precision timer is absent in the whole device system, and has wide application prospect.
Inventors
- GANG MINGXU
- LIU MINGZHE
- YAN BINGJUN
- WANG ZHIPING
- HU BO
- ZHANG BO
Assignees
- 中国科学院沈阳自动化研究所
Dates
- Publication Date
- 20260505
- Application Date
- 20220524
Claims (10)
- 1. The timer management method based on the embedded real-time operating system is characterized by comprising the following steps of: Step 1, creating a software timer management list, a software timer timeout time management list and a software timer service function management list; step 2, sequentially adding the timer services required by each thread in the embedded real-time operating system to a software timer management list; step 3, traversing the software timer management list, and inserting each software timer into the software timer timeout time management list according to the timeout time of each software timer in the software timer management list and the sequence from the smaller timeout time to the larger timeout time; step4, calling a timer in the embedded real-time operating system to execute timing service according to the overtime sequence in the overtime management list of the software timer; step 5, after the timer counts the overtime, loading the software timer service function corresponding to the overtime into a software timer service function management list, and executing the next overtime in the software timer overtime management list; and 6, executing the software timer service function in the software timer service function management list, and returning to the step 3.
- 2. The method for managing timers based on the embedded real-time operating system according to claim 1, wherein the software timer management list and the software timer service function management list are in a single-linked list structure, and the software timer timeout time management list is in a double-linked list structure.
- 3. The method of claim 1, wherein in step 2, the software timer management list is accessed by multiple threads in the support system, any thread is allowed to add the required timer service to the software timer management list, and the software timer management list is protected by calling a mutex in the embedded real-time operating system, so that only one thread can operate the software timer management list at any physical time.
- 4. The method of claim 1, wherein in step 2, the supported timer service operation mode includes a single operation mode and a loop operation mode.
- 5. The method for managing timers based on the embedded real-time operating system according to claim 1, wherein in step 4, the timer is the most accurate timer among all timers of the embedded real-time operating system.
- 6. The method of claim 1, wherein in step 5, when the timer counts to the timeout period, after the timer is started to time the interrupt service function, the software timer interrupt service function corresponding to the timeout period is added to the software timer service function management list, and the corresponding thread is notified to execute the software timer service function according to the execution mode of the software timer service function, then the next timeout period in the software timer timeout period management list is loaded and executed, and meanwhile, the software timer which has been executed in the software timer timeout period management list is deleted.
- 7. The method of claim 1, wherein in step 5, the supported software timer service function execution mode includes an interrupt callback trigger execution mode, a semaphore trigger execution mode, and a message queue trigger execution mode.
- 8. The method of claim 1, wherein in step 6, after the corresponding software timer service function is executed, different operations are executed according to the timing service operation mode of the software timer; If the software timer is in the single-time working mode, deleting the software timer from the software timer management list, and then executing the steps 3-6 in sequence again; if the software timer is in the loop mode of operation, the next timeout is calculated and added back to the software timer management list, and then steps 3-6 are reordered.
- 9. A timer management device based on an embedded real-time operating system, comprising a memory and a processor, wherein the memory is configured to store a computer program, and the processor is configured to implement a timer management method based on an embedded real-time operating system according to any one of claims 1-8 when the computer program is executed.
- 10. A computer readable storage medium, wherein a computer program is stored on the storage medium, which when executed by a processor, implements a timer management method based on an embedded real-time operating system according to any of claims 1-8.
Description
Timer management method based on embedded real-time operating system Technical Field The invention belongs to the field of network communication, and particularly relates to a timer management method based on an embedded real-time operating system. Background The method is characterized in that the method is used for solving the problems of real-time perception, real-time control and intelligent data analysis near the field end, and is a new development trend of a modern control system, so that the real-time embedded network equipment has an increasingly important position in the modern control system. In a real-time embedded network device, various communication protocols perform scheduling data transmission and receiving, starting and stopping of a communication protocol stack, delay, synchronization, switching and other activities of system tasks in a real-time operating system, accurate and high-speed timers are required to provide timing services, while a software timer provided by the embedded operating system can meet the requirement of actual functions on the number of timers, the timing accuracy is low and quick switching response cannot be realized, a hardware timer in the real-time embedded network device can provide high-accuracy timing services, the switching response speed of the timers can meet the actual function requirement, but the number of the hardware timers is rare and cannot meet the requirement on the number of timer services in the actual application process, so that a stable and high-efficiency timer management algorithm is realized in the real-time embedded network device, and the requirement of the real-time embedded network device on the timing services can be met. At present, the conventional timer management method has the limitations and disadvantages of the method, for example, the conventional timer management method is used for forming periodic interruption by running a hardware timer at a fixed frequency, then accumulating the periodic interruption by taking the periodic interruption as a timing reference source and realizing the accumulation of the periodic interruption in a software counting mode, and when the periodic interruption reaches a preset value, a preset task is executed, so that a plurality of high-precision timing services are provided. Disclosure of Invention Aiming at the defects in the prior art, the technical problem to be solved by the invention is to provide a timer management method based on an embedded real-time operating system, so that the timer management method can meet the requirement of real-time embedded network equipment on timing service. The technical scheme adopted by the invention for realizing the purpose is that the timer management method based on the embedded real-time operating system comprises the following steps: Step 1, creating a software timer management list, a software timer timeout time management list and a software timer service function management list; step 2, sequentially adding the timer services required by each thread in the embedded real-time operating system to a software timer management list; step 3, traversing the software timer management list, and inserting each software timer into the software timer timeout time management list according to the timeout time of each software timer in the software timer management list and the sequence from the smaller timeout time to the larger timeout time; step4, calling a timer in the embedded real-time operating system to execute timing service according to the overtime sequence in the overtime management list of the software timer; step 5, after the timer counts the overtime, loading the software timer service function corresponding to the overtime into a software timer service function management list, and executing the next overtime in the software timer overtime management list; and 6, executing the software timer service function in the software timer service function management list, and returning to the step 3. The software timer management list and the software timer service function management list adopt a single-linked list structure, and the software timer timeout time management list adopts a double-linked list structure. In step 2, the multithreading in the system is supported to access the software timer management list, any thread is allowed to add the needed timer service to the software timer management list, and meanwhile, the software timer management list is protected by calling the mutual exclusion semaphore in the embedded real-time operating system, so that only one thread at any physical moment is ensured to operate the software timer management list. In step 2, the supported timer service operation modes include a single operation mode and a loop operation mode. In step 4, the timer is the highest precision timer in all timers of the embedded real-time operating system. In step 5, when the timer counts to the timeout time, after entering the timer i