The above descriptions, while strictly useful as documentation, do not
really show how it all gets put together to make a device driver. The
following example of how to create the data structures for a device
driver, for a standard PC target, are derived from the eCosPro IDE disk
driver.
The first thing to do is to define the disk controllers:
A typical PC target has two IDE controllers, so we define two
controllers. The ide_controller_info_t structure is
defined by the driver and contains information needed to access the
controller. In this case this is the controller number, zero or one,
and the interrupt vector it uses. The
DISK_CONTROLLER() macro generates a system defined
controller structure and populates it with a pointer to the matching
controller info structure.
The next step is to define the disk functions that will be called to
perform data transfers on this driver. These functions the main part
of the driver, together with the init and lookup functions and any ISR
and DSR functions.
The first thing this macro does is generate an instance of the
ide_disk_info_t. This is a driver-defined structure to
contain any info that does not fit in the system defined
structures. In this case the important things are the number of the
device on the controller, zero or one mapping to master or slave, and
a pointer to the driver-defined controller structure. The
DISK_CHANNEL() macro creates a disk channel object
and populates it with the function list defined earlier, a pointer to the
matching local info structure just defined, and a pointer to the
controller it is attached to. Finally, a device table entry is
created. This uses linker features to install an entry into the device
table that allows the IO subsystem to locate this device.
Finally we need to instantiate all the channels that this driver will
support.