Virtual Timers

A Virtual Timer consists of these parts:

* Memory variable T[i] representing a count down.
* Literal COUNT[i] to initialize T[i].
* Time-out routine.
* Enable flag.

There are two types of Virtual Timers:

* Free-Running:
  When T reaches zero, it is loaded again with COUNT so the count down restarts automatically.

* One-Time:
  When T reaches zero, the Enable flag is cleared automatically.

All Virtual Timers are initialized during the Initialization routine by copying COUNT[i] into T[i] and setting the enable flag to zero (disabled).

The interrupt service routine TMR_ISR of the on-chip real-timer decrements at once all Virtual Timers T's of those that happen to be enabled.

TMR_ISR also checks if T[i] equals zero, in which case it reloads the timer (T[i]=COUNT[i]), then call the TimeOut[i] routine. If it is of type One-Time, it clears the Enable bit of that Virtual Timer before calling TimeOut[i] so the Virtual Timer runs only once.

The TimeOut[i] routine implements the useful work. From the client code viewpoint, that routine takes the place that otherwise would occupy the Interrupt Service Routine of a real timer.

Client code activate or deactivate Virtual Timers at will by setting or clearing their Enable flags, respectively.