
A Simple Timer Driver 89
device works (and that it is indeed working) when you start looking for the source
of your interrupt problems. And there will almost certainly be some of those.
A Simple Timer Driver
The device driver example that we’re about to discuss is designed to control one
of the timer/counter units contained within the 80188EB processor. I have chosen
to implement this driver—and all of the remaining examples in the book—in C++.
Although C++ offers no additional assistance over C in accessing hardware regis-
ters, there are many good reasons to use it for this type of abstraction. Most nota-
bly, C++ classes allow us to hide the actual hardware interface more completely
than any C features or programming techniques. For example, a constructor can
be included to automatically configure the hardware each time a new timer object
is declared. This eliminates the need for an explicit call from the application soft-
ware to the driver initialization routine. In addition, it is possible to hide the data
structure that corresponds to the device registers within the private part of the
associated class. This helps to prevent the application programmer from acciden-
tally reading or writing the device registers from some other part of the program.
The definition of the Timer class is as follows:
enum TimerState { Idle, Active, Done };
enum TimerType { OneShot, Periodic };
class Timer
{
public: ...