
94 Chapter 7: Peripherals
When a software timer is started, the data members state, type, and length are
initialized and the timer is inserted into a linked list of active timers called the
timerList. The timers in the timer list are ordered so that the first timer to expire is
at the top of the list. In addition, each timer has a count associated with it. This
value represents the number of ticks that will be remaining in the software timer once
all previous timers in the list have expired. Taken together, these design choices favor
quick updates to the timer list at the price of slower insertions and deletions. Speed is
important during updates because the timer list will be updated every time the hard-
ware generates a clock tick interrupt—that’s every one millisecond.
Figure 7-1 shows the timer list in action. Remember that each software timer has its
own unique length and starting time, but once it has been inserted into the list, only
the count field matters for ordering. In the example shown, the first and second
timers were both started (the second might actually have been restarted, because it
is periodic) at the same time. Since the second is 5 ms longer, it will expire 5 clock
ticks after the first. The second and third timers in the list both happen to expire at
the same time, though the third timer will have been running for 10 times longer.
The code for the interrupt service routine ...