beautypg.com

Sample code – Rockwell Automation 2711P Software Development Kit User Manual User Manual

Page 85

background image

Publication 2711P-UM005A-EN-P - March 2007

Device Drivers 85

Sample Code

The code sample describes the preferred process for driver
initialization and provides a good starting point that can be used as a
model for actual production code. Though this code will compile,
none of the constant data is valid for any real device, they are just
placeholders for a developer to replace with proper values.
Additionally, this driver only implements the XXX_Init and
XXX_Deinit entry points.

The sample driver code illustrates several methods to obtain IRQ and
SYSINTR data from the platform. When all other sources are
exhausted this implementation will finally use pre-defined,
hard-coded values. A driver that uses this method is more easily
migrated to platforms that do not support specific features. For
example; if the platform does not have a PCI bus enumerator, but
does support the DDK Hal PCI functions, this driver implementation
would still be able to get the needed configuration data. Then when
the platform is changed and the PCI bus enumerator is supported, no
re-design of the driver is needed.

////////////////////////////////////////////////////////////////////

//

// File: driver.c

//

// Example of the preferred initialization processes used in

// CE platform stream based device driver development.

//

/////////////////////////////////////////////////////////////////////

#include

#include

#include

#include

#include

#include

////////////////////////////////////////////////////////////////////

//

// USAGE Build switches

//

// Defining DRV_USE_IO will use x86 port IO instructions when needed.

// Defining DRV_USE_PCI will invoke PCI DDK calls to assist initialization.

// Defining DEV_USE_ISR will cause the driver to attempt to

// initialize a Chained ISR handler.

//

/////////////////////////////////////////////////////////////////////