Thursday, April 12, 2012

An efficient timer management module design

The timer is one of the basic elements of the normal operation of the communication protocol is mainly used for a variety of digital timer

and frame retransmission task. The communication protocol used in the SCM system timer, timing accuracy is not required, but the number of requirements. Hardware resources are limited, it is impossible for every single task is assigned a hardware timer, only through a single hardware timer simulate a number of software timers to meet the timing needs agreement.


These software timer data structure to organize themselves, and provides a uniform interface, called "Timer". Timer management are mainly two kinds of method:


(1) static array method. Timer node is stored in the array. The advantage is simple logic, occupy less ROM. However, this program has significant disadvantages: when the hardware timer interrupt occurs, the subtraction operation of all timer node, the time overhead and delay uncertainty (related to the timer number).


(2)delta linked list method. Ascending order to form a linked list in accordance with the timing value of the timer. A timer value of timer in front of all the timer value plus the value of the node. Thus, in each clock interrupt handler, only the subtraction operation on a timer node, greatly reducing the time overhead. However, the complex program logic, ROM, dosage, require frequent allocation of recovery of memory, easy to form the memory fragmentation.


The timer management module design is based on a static array method. Use a timer node array to hold all of the timing of the request, a representative of an available timer node of the array. Each timer node has a status indicates that the timer is in idle, or overflow state. Timing value of the timer and the timer expires, the message to be sent is also stored in the timer node, in order to achieve a hardware timer to provide users with a number of software timers.


In order to solve the problem of interrupt processing time overhead, the introduction of an auxiliary timer module, auxiliary timer value is always equal to the minimum timing value of all the timer node. In the hardware timer interrupt processing, only the auxiliary timer subtraction operation, which will greatly reduce interrupt processing time.


Start a timer, the main node to node array in an idle state is set to use. If the new timer is enabled, all timers from time to time to the minimum value, but also to update the auxiliary timer. Function pointer to point to the timer message and time value parameters, start the timer process shown in Figure 2. Successful start-up timer, return the node ID number of the timer.


Software timer is driven by the hardware digital timer. In the hardware timer interrupt, the first auxiliary timer value minus 1. If the auxiliary timer value is 0, then the timer value minimum timer has timed out, the corresponding message should be sent to the user task, the node set to the idle state, and re-calculate the timing values ??of the other nodes, and find the timing value the smallest node, update the auxiliary timer.

No comments:

Post a Comment