Hi Pennels,
have you already downloaded the NI Measurement Hardware DDK (Driver Development Kit) from National instruments? In the DDK you will find some Examples for M seris boards. aiex2.cpp and aiex3.cpp should provide all you need.
The user has to provide a osiUserCode method in which the bars are set. Here is an example that was written for vxWorks
//******************************************************************************
// osiUserCode.cpp -- Generic Operating System Bus Interface
// osiUserCode.cpp includes the correct version of osiUserCode.cpp for the OS
//
// osiUserCode.cpp holds the two user defined functions
// needed to port iBus to a target platform.
//
// acquireBoard(); -- constructs and initializes the iBus
//
// releaseBoard(); -- deletes and cleans up the iBus
//
// There are also assorted helper functions which are also
// platform specific.
//
//******************************************************************************
/*
* osiUserCode.cpp (framework only)
*
*
* osiUserCode.cpp holds the two user defined functions
* needed to port iBus to a target platform.
*
* acquireBoard(); -- constructs and initializes the iBus
*
* releaseBoard(); -- deletes and cleans up the iBus
*
* There are also assorted helper functions which are also
* platform specific.
*
*
*/
// Platform independent headers
#ifndef ___osiBus_h___
#include "osiBus.h"
#endif
// System specific headers
#include <vxWorks.h>
#include <stdio.h>
#include <drv/pci/pciConfigLib.h>
struct pciResource
{
unsigned int bar[6];
unsigned int barsize[6];
int bus;
int device;
int func;
char irq;
int errcode;
};
typedef struct allUnitsPciRes
{
char deviceName[9];
int vendorId;
int deviceId;
int subVendorId;
int subSystemId;
int classCode;
int subClass;
int revisionId;
int nBARs;
int nMmuBARs;
int nUnits;
struct pciResource unitPciRes[PCI_MAX_DEV];
} ALLUNITS_PCIRES;
/* In this structure you should find all PCI resources of all PCI-6010 boards.
The code installs only the first one.
If you have another structure you can use it as well*/
extern ALLUNITS_PCIRES allPci6010Res;
/* Return iBus of first matching PCI/PXI card.
*/
iBus* acquireBoard(const uint32_t devicePCI_ID)
{
uint32_t devBAR0,devBAR1;
//uint32_t BAR0sz,BAR1sz;
void *mem0,*mem1;
iBus *bus;
//Find the PCI BAR memory ranges
switch (devicePCI_ID)
{
/* You have to look up the correct PCI devive Id of the PCI-6010 board using
* pciDeviceShow(...) from your vxWorks shell*/
case 0x0000ffff:
devBAR0 = allPci6010Res.unitPciRes[0].bar[0];
devBAR1 = allPci6010Res.unitPciRes[0].bar[1];
break;
default:
devBAR0 = (uint32_t)NULL;
devBAR1 = (uint32_t)NULL;
break;
}
mem0 = (void *) devBAR0;
mem1 = (void *) devBAR1;
printf("Base address devBAR0 = %10lx, Base address DAQ_STC = %10lx\n",
devBAR0, devBAR1);
//Memory map the BARs to get access to the PCI card's memory
//create a new iBus which uses the memory mapped addresses
bus = new iBus(0, 0, mem0, mem1);
bus->_physBar[0] = (uint32_t)devBAR0;
bus->_physBar[1] = (uint32_t)devBAR1;
bus->_physBar[2] = (uint32_t)NULL;
bus->_physBar[3] = (uint32_t)NULL;
bus->_physBar[4] = (uint32_t)NULL;
bus->_physBar[5] = (uint32_t)NULL;
return bus;
}
void releaseBoard(iBus *&bus)
{
//unmap the memory and close whatever system resources
//were used to create the iBus
delete bus;
}