02.03.2014 Views

BSP Developer's Guide

BSP Developer's Guide

BSP Developer's Guide

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

5<br />

Driver <strong>Guide</strong>lines<br />

Per-Device Data Structure<br />

As part of an object-oriented design, each device should be represented in the<br />

system by a single structure with all the state information included. The object<br />

methods (subroutines) perform operations on objects using an object handle (a<br />

pointer to the data structure representing the object).<br />

New instances of a device object would be created by calling a device create<br />

function in the driver library (xxxDevCreate). During device creation time the<br />

driver should probe to verify that the device is actually present. If not present, the<br />

device creation operation should fail and return a null pointer.<br />

5<br />

Per-Driver Data Structure<br />

In keeping with an object oriented design methodology, there should be a structure<br />

to represent the driver itself. This structure would include all the driver state<br />

information (class variables). From a practical standpoint, having all the driver<br />

data in a single structure makes it easy to display from the CrossWind debugging<br />

tool.<br />

Driver Interrupt Service Routines<br />

Because there may be bus issues related to interrupts, drivers should not call<br />

intConnect( ) directly. The driver should define a macro that can be changed by the<br />

customer to call the correct interrupt connection routine, which may not be<br />

intConnect( ).<br />

#ifndef FOO_INT_CONNECT<br />

#define FOO_INT_CONNECT(vec, rtn, arg)<br />

#endif<br />

intConnect(vec, rtn, arg)<br />

Device driver ISRs must exit immediately if the device is not asserting interrupt.<br />

Do not assume that there is a one-to-one mapping between interrupt vectors and<br />

interrupt handlers. With PCI systems, it is quite likely that interrupt lines are used<br />

to service more then one device. Interrupt routines must examine the device and<br />

determine if it is actually generating an interrupt condition. If not, the interrupt<br />

handling code should exit as quickly as possible.<br />

97

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!