Chapter 17. how to write a driver, Arguments, How to write a driver – Comtrol eCos User Manual

Page 379

Advertising
background image

Chapter 17. How to Write a Driver

A device driver is nothing more than a named entity that supports the basic I/O functions - read, write, get config,
and set config. Typically a device driver also uses and manages interrupts from the device. While the interface
is generic and device driver independent, the actual driver implementation is completely up to the device driver
designer.

That said, the reason for using a device driver is to provide access to a device from application code in as general
purpose a fashion as reasonable. Most driver writers are also concerned with making this access as simple as
possible while being as efficient as possible.

Most device drivers are concerned with the movement of information, for example data bytes along a serial in-
terface, or packets in a network. In order to make the most efficient use of system resources, interrupts are used.
This will allow other application processing to take place while the data transfers are under way, with interrupts
used to indicate when various events have occurred. For example, a serial port typically generates an interrupt after
a character has been sent “down the wire” and the interface is ready for another. It makes sense to allow further
application processing while the data is being sent since this can take quite a long time. The interrupt can be used
to allow the driver to send a character as soon as the current one is complete, without any active participation by
the application code.

The main building blocks for device drivers are found in the include file:

<

cyg/io/devtab.h

>

All device drivers in eCos are described by a device table entry, using the cyg_devtab_entry_t type. The entry
should be created using the

DEVTAB_ENTRY()

macro, like this:

DEVTAB_ENTRY

(l, name, dep_name, handlers, init, lookup, priv)

Arguments

l

The "C" label for this device table entry.

name

The "C" string name for the device.

dep_name

For a layered device, the "C" string name of the device this device is built upon.

handlers

A pointer to the I/O function "handlers" (see below).

init

A function called when eCos is initialized. This function can query the device, setup hardware, etc.

275

Advertising