Portability, Sample code for a simple pci slot device – Rockwell Automation 6182 SDK User Manual
Page 65

RAC6182-Specific Extensions to the CE API
4–25
Publication 6182-UM002B-EN-P
Portability
The argument to this function is specific to the RAC6182 hardware.
This code assumes a simple device with one memory address space size
4K configured at PCI configuration offset 0x10 and one IO address space
size 16K configured at PCI configuration offset 0x14. It has a power
management register at offset 0x40 that must be set to bring the device
out of power down mode. The device periodically interrupts us to print
data or tell us it has died.
#include
#include
// values currently defined for RAC6182.
// these will be provided in a pcislot.h file
#define PCI_SLOT_BUS_NUMBER
1
#define PCI_SLOT_DEVICE_NUMBER
1
// bogus items for our simple card
#define CARD_VENDOR_ID
0x1234
#define CARD_DEVICE_ID
0x5678
#define CARD_POWER_MGMT_ON
0x00000001
#define CARD_MEMORY_SIZE
(4*1024)
#define CARD_IO_SIZE
(16*1024)
#define CARD_SIGNAL_DEAD
0xDEAD
int main(void)
{
PCI_COMMON_CONFIG PCIConfig;
HANDLE waitevent;
DWORD interrupt;
PHYSICAL_ADDRESS pa,pa2;
volatile UCHAR *IOSpace;
volatile UCHAR *MemSpace;
ULONG value;
NKDbgPrintfW(TEXT(“PCI card sample\n”));
if(HalGetBusDataByOffset(PCIConfiguration,PCI_SLOT_BUS_NUMBER,
PCI_SLOT_DEVICE_NUMBER,&PCIConfig,0,sizeof(PCIConfig)) !=
sizeof(PCIConfig)) {
NKDbgPrintfW(TEXT(“failed to get PCI slot config info\n”));
return(-1);
}
// check that our card is present
if(PCIConfig.VendorID!=CARD_VENDOR_ID ||
PCIConfig.DeviceID!=CARD_DEVICE_ID) {
NKDbgPrintfW(TEXT(“vendor %04x device %04x not our card\n”),
PCIConfig.VendorID,PCIConfig.DeviceID);
return(-1);
}
// power on to our bogus card to demonstrate a device-specific config
// space write
value=CARD_POWER_MGMT_ON;
if(HalSetBusDataByOffset(PCIConfiguration,PCI_SLOT_BUS_NUMBER,
PCI_SLOT_DEVICE_NUMBER,&value,0x40,sizeof(value))!=
sizeof(value)) {
Sample Code for a Simple
PCI Slot Device