
88 Chapter 7: Peripherals
To make the bits within the control register easier to read and write individually,
we might also define the following bitmasks:
#define TIMER_ENABLE 0xC000 // Enable the timer.
#define TIMER_DISABLE 0x4000 // Disable the timer.
#define TIMER_INTERRUPT 0x2000 // Enable timer interrupts.
#define TIMER_MAXCOUNT 0x0020 // Timer complete?
#define TIMER_PERIODIC 0x0001 // Periodic timer?
2. A set of variables to track the current state of the hardware and device
driver
The second step in the driver development process is to figure out what variables
you will need to track the state of the hardware and device driver. For example, in
the case of the timer/counter unit described earlier we’ll probably need to know if
the hardware has been initialized. And if it has been, we might also want to know
the length of the running countdown.
Some device drivers create more than one software device. This is a purely logical
device that is implemented over the top of the basic peripheral hardware. For
example, it is easy to imagine that more than one software timer could be created
from a single timer/counter unit. The timer/counter unit would be configured to
generate a periodic clock tick, and the device driver would then manage a set of
software timers of various lengths by maintaining state information for each.
3. A routine to initialize the hardware to a known state
Once you know how ...