Re-factor device specific code

r1292 | dcl | 2006-11-15 08:41:53 +1100 (Wed, 15 Nov 2006) | 2 lines
This commit is contained in:
Douglas Clowes
2006-11-15 08:41:53 +11:00
parent 2c1d9a0443
commit 6928921378
2 changed files with 350 additions and 273 deletions

View File

@@ -72,6 +72,8 @@ typedef struct device_private_t
#ifdef REGISTER_LEVEL_PROGRAMMING #ifdef REGISTER_LEVEL_PROGRAMMING
static void initMite(iBus *bus); static void initMite(iBus *bus);
static void initCard(pHWARE ptr);
static void initChan(pHWARE ptr);
static CARD* card[10]; static CARD* card[10];
#else #else
@@ -174,24 +176,7 @@ int hware_ctor(const char* device_name, pHWARE* ptr)
initMite(pci->bus); initMite(pci->bus);
pci->Bar1 = pci->bus->createAddressSpace(kPCI_BAR1); initCard(hware);
pci->board = new tstaticDIO(pci->Bar1);
//
//Configure All Digital lines as Input or Output
pci->board->IOSelect0.writeDirection(pci->board->IOSelect0.kDirectionInput);
pci->board->IOSelect1.writeDirection(pci->board->IOSelect1.kDirectionInput);
pci->board->IOSelect2.writeDirection(pci->board->IOSelect2.kDirectionInput);
pci->board->IOSelect3.writeDirection(pci->board->IOSelect3.kDirectionOutput);
pci->board->IOSelect4.writeDirection(pci->board->IOSelect4.kDirectionInput);
pci->board->IOSelect5.writeDirection(pci->board->IOSelect5.kDirectionInput);
pci->board->IOSelect6.writeDirection(pci->board->IOSelect6.kDirectionInput);
pci->board->IOSelect7.writeDirection(pci->board->IOSelect7.kDirectionOutput);
pci->board->IOSelect8.writeDirection(pci->board->IOSelect8.kDirectionInput);
pci->board->IOSelect9.writeDirection(pci->board->IOSelect9.kDirectionInput);
pci->board->IOSelect10.writeDirection(pci->board->IOSelect10.kDirectionInput);
pci->board->IOSelect11.writeDirection(pci->board->IOSelect11.kDirectionOutput);
} }
else else
{ {
@@ -206,42 +191,49 @@ int hware_ctor(const char* device_name, pHWARE* ptr)
} }
pci->dev_mask |= 1 << hware->channel_number; pci->dev_mask |= 1 << hware->channel_number;
initChan(hware);
#else #else
char local_name[40] = "dev2/port0"; do {
/*********************************************/ char local_name[40];
// Create a DAQmx task /*********************************************/
/*********************************************/ // Create a DAQmx task
DAQmxErrChk (DAQmxCreateTask("",&hware->taskHandle)); /*********************************************/
DAQmxErrChk (DAQmxCreateTask("",&hware->taskHandle_dout)); DAQmxErrChk (DAQmxCreateTask("",&hware->taskHandle));
DAQmxErrChk (DAQmxCreateTask("",&hware->taskHandle_dout));
/*********************************************/ /*********************************************/
// Create a DAQmx device within the task // Create a DAQmx device within the task
/*********************************************/ /*********************************************/
snprintf(local_name, sizeof(local_name), "dev%d/line%d:%d", snprintf(local_name, sizeof(local_name),
hware->card_number, "dev%d/line%d:%d",
hware->channel_number * 32, hware->card_number,
hware->channel_number * 32 + 23); hware->channel_number * 32,
DAQmxErrChk ( hware->channel_number * 32 + 23);
DAQmxCreateDIChan(hware->taskHandle, DAQmxErrChk (
local_name, DAQmxCreateDIChan(hware->taskHandle,
"", local_name,
DAQmx_Val_ChanForAllLines)); "",
fprintf(stderr, "Input %s\n", local_name); DAQmx_Val_ChanForAllLines));
snprintf(local_name, sizeof(local_name), "dev%d/line%d:%d",
hware->card_number, /*********************************************/
hware->channel_number * 32 + 24, // Create the digital output channel within the task
hware->channel_number * 32 + 31); /*********************************************/
DAQmxErrChk ( snprintf(local_name, sizeof(local_name),
DAQmxCreateDOChan(hware->taskHandle_dout, "dev%d/line%d:%d",
local_name, hware->card_number,
"", hware->channel_number * 32 + 24,
DAQmx_Val_ChanForAllLines)); hware->channel_number * 32 + 31);
fprintf(stderr, "Output %s\n", local_name); DAQmxErrChk (
/*********************************************/ DAQmxCreateDOChan(hware->taskHandle_dout,
// Start the DAQmx task local_name,
/*********************************************/ "",
DAQmxErrChk (DAQmxStartTask(hware->taskHandle)); DAQmx_Val_ChanForAllLines));
DAQmxErrChk (DAQmxStartTask(hware->taskHandle_dout)); /*********************************************/
// Start the DAQmx task
/*********************************************/
DAQmxErrChk (DAQmxStartTask(hware->taskHandle));
DAQmxErrChk (DAQmxStartTask(hware->taskHandle_dout));
} while (0);
#endif #endif
hware_write(hware, 0); hware_write(hware, 0);
@@ -492,10 +484,65 @@ void initMite(iBus *bus)
//Get the physical address of the DAQ board //Get the physical address of the DAQ board
physicalBar1 = bus->get(kBusAddressPhysical,kPCI_BAR1); physicalBar1 = bus->get(kBusAddressPhysical,kPCI_BAR1);
//Tell the MITE to enable BAR1, where the rest of the board's registers are
// ***** Generic MITE initialization *****
// Tell the MITE to enable BAR1, where the rest of the board's registers are
Bar0.write32(0xC0, (physicalBar1 & 0xffffff00L) | 0x80); Bar0.write32(0xC0, (physicalBar1 & 0xffffff00L) | 0x80);
bus->destroyAddressSpace(Bar0); bus->destroyAddressSpace(Bar0);
} }
void initCard(pHWARE hware)
{
CARD* pci = hware->card;
pci->Bar1 = pci->bus->createAddressSpace(kPCI_BAR1);
pci->board = new tstaticDIO(pci->Bar1);
//
// Set All Digital lines as Input so we don't accidentally double drive an IO pin
pci->board->IOSelect0.writeDirection(pci->board->IOSelect0.kDirectionInput);
pci->board->IOSelect1.writeDirection(pci->board->IOSelect1.kDirectionInput);
pci->board->IOSelect2.writeDirection(pci->board->IOSelect2.kDirectionInput);
pci->board->IOSelect3.writeDirection(pci->board->IOSelect3.kDirectionInput);
pci->board->IOSelect4.writeDirection(pci->board->IOSelect4.kDirectionInput);
pci->board->IOSelect5.writeDirection(pci->board->IOSelect5.kDirectionInput);
pci->board->IOSelect6.writeDirection(pci->board->IOSelect6.kDirectionInput);
pci->board->IOSelect7.writeDirection(pci->board->IOSelect7.kDirectionInput);
pci->board->IOSelect8.writeDirection(pci->board->IOSelect8.kDirectionInput);
pci->board->IOSelect9.writeDirection(pci->board->IOSelect9.kDirectionInput);
pci->board->IOSelect10.writeDirection(pci->board->IOSelect10.kDirectionInput);
pci->board->IOSelect11.writeDirection(pci->board->IOSelect11.kDirectionInput);
}
void initChan(pHWARE hware)
{
CARD* pci = hware->card;
/*
* Set up the channel object
*/
switch (hware->channel_number)
{
case 0:
pci->board->IOSelect0.writeDirection(pci->board->IOSelect0.kDirectionInput);
pci->board->IOSelect1.writeDirection(pci->board->IOSelect1.kDirectionInput);
pci->board->IOSelect2.writeDirection(pci->board->IOSelect2.kDirectionInput);
pci->board->IOSelect3.writeDirection(pci->board->IOSelect3.kDirectionOutput);
break;
case 1:
pci->board->IOSelect4.writeDirection(pci->board->IOSelect4.kDirectionInput);
pci->board->IOSelect5.writeDirection(pci->board->IOSelect5.kDirectionInput);
pci->board->IOSelect6.writeDirection(pci->board->IOSelect6.kDirectionInput);
pci->board->IOSelect7.writeDirection(pci->board->IOSelect7.kDirectionOutput);
break;
case 2:
pci->board->IOSelect8.writeDirection(pci->board->IOSelect8.kDirectionInput);
pci->board->IOSelect9.writeDirection(pci->board->IOSelect9.kDirectionInput);
pci->board->IOSelect10.writeDirection(pci->board->IOSelect10.kDirectionInput);
pci->board->IOSelect11.writeDirection(pci->board->IOSelect11.kDirectionOutput);
break;
}
}
#else #else
#endif #endif

View File

@@ -67,6 +67,13 @@ typedef struct device_private_t
#endif #endif
} DEVICE_PRIVATE; } DEVICE_PRIVATE;
#ifdef REGISTER_LEVEL_PROGRAMMING
static bool initPCI(pHWARE ptr, const char *name);
static void initCard(pHWARE ptr);
static void initChan(pHWARE ptr);
static CARD* card[10];
#else
typedef struct mapping_t { typedef struct mapping_t {
int cntr_num; int cntr_num;
int sync_num; int sync_num;
@@ -83,12 +90,6 @@ static MAPPING mapping[8] = {
{ 6, 13, 12 }, { 6, 13, 12 },
{ 7, 9, 8 } { 7, 9, 8 }
}; };
#ifdef REGISTER_LEVEL_PROGRAMMING
static void initMite(iBus *bus);
static CARD* card[10];
#else
#endif #endif
int hware_ctor(const char* device_name, pHWARE* ptr) int hware_ctor(const char* device_name, pHWARE* ptr)
@@ -100,7 +101,6 @@ int hware_ctor(const char* device_name, pHWARE* ptr)
int error = 0; int error = 0;
bool flag = false; bool flag = false;
char text_string[] = DEFAULT_DEVICE; char text_string[] = DEFAULT_DEVICE;
char port_range[40];
const char *name; const char *name;
const char *text; const char *text;
@@ -114,7 +114,7 @@ int hware_ctor(const char* device_name, pHWARE* ptr)
{ {
if (isspace(*name)) if (isspace(*name))
++name; ++name;
else if (*name >= '0' && *name <= '7') else if (*name >= '0' && *name <= '9')
{ {
if (flag) if (flag)
{ {
@@ -139,8 +139,6 @@ int hware_ctor(const char* device_name, pHWARE* ptr)
++text; ++text;
} }
hware->sync_line_number = mapping[hware->channel_number].sync_num;
hware->output_line_number = mapping[hware->channel_number].outp_num;
#ifdef REGISTER_LEVEL_PROGRAMMING #ifdef REGISTER_LEVEL_PROGRAMMING
if (card[hware->card_number] == NULL) if (card[hware->card_number] == NULL)
{ {
@@ -177,9 +175,7 @@ int hware_ctor(const char* device_name, pHWARE* ptr)
pci = card[hware->card_number]; pci = card[hware->card_number];
hware->card = pci; hware->card = pci;
pci->bus = acquireBoard((tChar*) local_name /* "PXI6::1::INSTR" */); if(!initPCI(hware, local_name))
if(pci->bus == NULL)
{ {
printf("Error accessing the PCI device \"%s\". Exiting.\n", printf("Error accessing the PCI device \"%s\". Exiting.\n",
local_name); local_name);
@@ -187,39 +183,7 @@ int hware_ctor(const char* device_name, pHWARE* ptr)
goto Error; goto Error;
} }
//Intitialise Mite Chip. initCard(hware);
initMite(pci->bus);
pci->Bar1 = pci->bus->createAddressSpace(kPCI_BAR1);
pci->Bar2 = pci->bus->createAddressSpace(kPCI_BAR1);
pci->tio_1 = new tTIO(pci->Bar1);
pci->tio_2 = new tTIO(pci->Bar2);
pci->tio_2->setAddressOffset(0x800);
//
//Set all counter outputs to 'input' so we don't accidentally double drive an IO pin
pci->tio_1->IO_Pin_8_9_Configuration_Register.writeIO_Pin_8_Select(0); //0='input'
pci->tio_1->IO_Pin_12_13_Configuration_Register.writeIO_Pin_12_Select(0); //0='input'
pci->tio_1->IO_Pin_16_17_Configuration_Register.writeIO_Pin_16_Select(0); //0='input'
pci->tio_1->IO_Pin_20_21_Configuration_Register.writeIO_Pin_20_Select(0); //0='input'
pci->tio_1->IO_Pin_24_25_Configuration_Register.writeIO_Pin_24_Select(0); //0='input'
pci->tio_1->IO_Pin_28_29_Configuration_Register.writeIO_Pin_28_Select(0); //0='input'
pci->tio_1->IO_Pin_32_33_Configuration_Register.writeIO_Pin_32_Select(0); //0='input'
pci->tio_1->IO_Pin_36_37_Configuration_Register.writeIO_Pin_36_Select(0); //0='input'
pci->tio_2->IO_Pin_8_9_Configuration_Register.writeIO_Pin_8_Select(0); //0='input'
pci->tio_2->IO_Pin_12_13_Configuration_Register.writeIO_Pin_12_Select(0); //0='input'
pci->tio_2->IO_Pin_16_17_Configuration_Register.writeIO_Pin_16_Select(0); //0='input'
pci->tio_2->IO_Pin_20_21_Configuration_Register.writeIO_Pin_20_Select(0); //0='input'
pci->tio_2->IO_Pin_24_25_Configuration_Register.writeIO_Pin_24_Select(0); //0='input'
pci->tio_2->IO_Pin_28_29_Configuration_Register.writeIO_Pin_28_Select(0); //0='input'
pci->tio_2->IO_Pin_32_33_Configuration_Register.writeIO_Pin_32_Select(0); //0='input'
pci->tio_2->IO_Pin_36_37_Configuration_Register.writeIO_Pin_36_Select(0); //0='input'
//Bind the first TIO to counters 0-3 on the IO connector, and
//bind the second TIO to counters 4-7
pci->tio_1->Clock_Configuration_Register.writeCntr_Swap(0);
pci->tio_2->Clock_Configuration_Register.writeCntr_Swap(1);
} }
else else
{ {
@@ -234,182 +198,48 @@ int hware_ctor(const char* device_name, pHWARE* ptr)
} }
pci->dev_mask |= 1 << hware->channel_number; pci->dev_mask |= 1 << hware->channel_number;
/* initChan(hware);
* Set up the counter object
*/
switch (hware->channel_number)
{
case 0:
//Disarm
pci->tio_1->G0_Command_Register.writeG0_Disarm(1);
//load initial value of zero
pci->tio_1->G0_Load_A_Registers.writeG0_Load_A(0x00000000);
pci->tio_1->G0_Command_Register.writeG0_Load(1);
//set source to external default source pin
pci->tio_1->G0_Input_Select_Register.writeG0_Source_Select(1);
//set gate to no gate
pci->tio_1->G0_Input_Select_Register.writeG0_Gate_Select(30);
pci->tio_1->G0_Mode_Register.writeG0_Gate_Polarity(1);
pci->tio_1->G0_Mode_Register.writeG0_Trigger_Mode_For_Edge_Gate(3);
//set counting direction to up
pci->tio_1->G0_Command_Register.writeG0_Up_Down(1);
//arm counter
pci->tio_1->G0_Command_Register.writeG0_Arm(1);
break;
case 1:
//Disarm
pci->tio_1->G1_Command_Register.writeG1_Disarm(1);
//load initial value of zero
pci->tio_1->G1_Load_A_Registers.writeG1_Load_A(0x00000000);
pci->tio_1->G1_Command_Register.writeG1_Load(1);
//set source to external default source pin
pci->tio_1->G1_Input_Select_Register.writeG1_Source_Select(1);
//set gate to no gate
pci->tio_1->G1_Input_Select_Register.writeG1_Gate_Select(30);
pci->tio_1->G1_Mode_Register.writeG1_Gate_Polarity(1);
pci->tio_1->G1_Mode_Register.writeG1_Trigger_Mode_For_Edge_Gate(3);
//set counting direction to up
pci->tio_1->G1_Command_Register.writeG1_Up_Down(1);
//arm counter
pci->tio_1->G1_Command_Register.writeG1_Arm(1);
break;
case 2:
//Disarm
pci->tio_1->G2_Command_Register.writeG2_Disarm(1);
//load initial value of zero
pci->tio_1->G2_Load_A_Registers.writeG2_Load_A(0x00000000);
pci->tio_1->G2_Command_Register.writeG2_Load(1);
//set source to external default source pin
pci->tio_1->G2_Input_Select_Register.writeG2_Source_Select(1);
//set gate to no gate
pci->tio_1->G2_Input_Select_Register.writeG2_Gate_Select(30);
pci->tio_1->G2_Mode_Register.writeG2_Gate_Polarity(1);
pci->tio_1->G2_Mode_Register.writeG2_Trigger_Mode_For_Edge_Gate(3);
//set counting direction to up
pci->tio_1->G2_Command_Register.writeG2_Up_Down(1);
//arm counter
pci->tio_1->G2_Command_Register.writeG2_Arm(1);
break;
case 3:
//Disarm
pci->tio_1->G3_Command_Register.writeG3_Disarm(1);
//load initial value of zero
pci->tio_1->G3_Load_A_Registers.writeG3_Load_A(0x00000000);
pci->tio_1->G3_Command_Register.writeG3_Load(1);
//set source to external default source pin
pci->tio_1->G3_Input_Select_Register.writeG3_Source_Select(1);
//set gate to no gate
pci->tio_1->G3_Input_Select_Register.writeG3_Gate_Select(30);
pci->tio_1->G3_Mode_Register.writeG3_Gate_Polarity(1);
pci->tio_1->G3_Mode_Register.writeG3_Trigger_Mode_For_Edge_Gate(3);
//set counting direction to up
pci->tio_1->G3_Command_Register.writeG3_Up_Down(1);
//arm counter
pci->tio_1->G3_Command_Register.writeG3_Arm(1);
break;
case 4:
//Disarm
pci->tio_2->G0_Command_Register.writeG0_Disarm(1);
//load initial value of zero
pci->tio_2->G0_Load_A_Registers.writeG0_Load_A(0x00000000);
pci->tio_2->G0_Command_Register.writeG0_Load(1);
//set source to external default source pin
pci->tio_2->G0_Input_Select_Register.writeG0_Source_Select(1);
//set gate to no gate
pci->tio_2->G0_Input_Select_Register.writeG0_Gate_Select(30);
pci->tio_2->G0_Mode_Register.writeG0_Gate_Polarity(1);
pci->tio_2->G0_Mode_Register.writeG0_Trigger_Mode_For_Edge_Gate(3);
//set counting direction to up
pci->tio_2->G0_Command_Register.writeG0_Up_Down(1);
//arm counter
pci->tio_2->G0_Command_Register.writeG0_Arm(1);
break;
case 5:
//Disarm
pci->tio_2->G1_Command_Register.writeG1_Disarm(1);
//load initial value of zero
pci->tio_2->G1_Load_A_Registers.writeG1_Load_A(0x00000000);
pci->tio_2->G1_Command_Register.writeG1_Load(1);
//set source to external default source pin
pci->tio_2->G1_Input_Select_Register.writeG1_Source_Select(1);
//set gate to no gate
pci->tio_2->G1_Input_Select_Register.writeG1_Gate_Select(30);
pci->tio_2->G1_Mode_Register.writeG1_Gate_Polarity(1);
pci->tio_2->G1_Mode_Register.writeG1_Trigger_Mode_For_Edge_Gate(3);
//set counting direction to up
pci->tio_2->G1_Command_Register.writeG1_Up_Down(1);
//arm counter
pci->tio_2->G1_Command_Register.writeG1_Arm(1);
break;
case 6:
//Disarm
pci->tio_2->G2_Command_Register.writeG2_Disarm(1);
//load initial value of zero
pci->tio_2->G2_Load_A_Registers.writeG2_Load_A(0x00000000);
pci->tio_2->G2_Command_Register.writeG2_Load(1);
//set source to external default source pin
pci->tio_2->G2_Input_Select_Register.writeG2_Source_Select(1);
//set gate to no gate
pci->tio_2->G2_Input_Select_Register.writeG2_Gate_Select(30);
pci->tio_2->G2_Mode_Register.writeG2_Gate_Polarity(1);
pci->tio_2->G2_Mode_Register.writeG2_Trigger_Mode_For_Edge_Gate(3);
//set counting direction to up
pci->tio_2->G2_Command_Register.writeG2_Up_Down(1);
//arm counter
pci->tio_2->G2_Command_Register.writeG2_Arm(1);
break;
case 7:
//Disarm
pci->tio_2->G3_Command_Register.writeG3_Disarm(1);
//load initial value of zero
pci->tio_2->G3_Load_A_Registers.writeG3_Load_A(0x00000000);
pci->tio_2->G3_Command_Register.writeG3_Load(1);
//set source to external default source pin
pci->tio_2->G3_Input_Select_Register.writeG3_Source_Select(1);
//set gate to no gate
pci->tio_2->G3_Input_Select_Register.writeG3_Gate_Select(30);
pci->tio_2->G3_Mode_Register.writeG3_Gate_Polarity(1);
pci->tio_2->G3_Mode_Register.writeG3_Trigger_Mode_For_Edge_Gate(3);
//set counting direction to up
pci->tio_2->G3_Command_Register.writeG3_Up_Down(1);
//arm counter
pci->tio_2->G3_Command_Register.writeG3_Arm(1);
break;
}
#else #else
/*********************************************/ do {
// Create a DAQmx task char local_name[40];
/*********************************************/ hware->sync_line_number = mapping[hware->channel_number].sync_num;
DAQmxErrChk (DAQmxCreateTask("",&hware->taskHandle)); hware->output_line_number = mapping[hware->channel_number].outp_num;
DAQmxErrChk (DAQmxCreateTask("",&hware->taskHandle_dout)); /*********************************************/
// Create a DAQmx task
/*********************************************/
DAQmxErrChk (DAQmxCreateTask("",&hware->taskHandle));
DAQmxErrChk (DAQmxCreateTask("",&hware->taskHandle_dout));
/*********************************************/ /*********************************************/
// Create a DAQmx device within the task // Create a DAQmx device within the task
/*********************************************/ /*********************************************/
DAQmxErrChk ( DAQmxErrChk (
DAQmxCreateCICountEdgesChan(hware->taskHandle, DAQmxCreateCICountEdgesChan(hware->taskHandle,
device_name, device_name,
"", "",
DAQmx_Val_Rising, DAQmx_Val_Rising,
hware->count32, hware->count32,
DAQmx_Val_CountUp)); DAQmx_Val_CountUp));
/*********************************************/ /*********************************************/
// Create the digital channel within the task // Create the digital output channel within the task
/*********************************************/ /*********************************************/
snprintf(port_range, sizeof(port_range), "DEV%d/LINE%d", snprintf(local_name, sizeof(local_name),
hware->card_number, hware->channel_number); "dev%d/line%d",
DAQmxErrChk (DAQmxCreateDOChan(hware->taskHandle_dout, hware->card_number,
port_range, hware->channel_number);
"", DAQmxErrChk (
DAQmx_Val_ChanPerLine)); DAQmxCreateDOChan(hware->taskHandle_dout,
local_name,
/*********************************************/ "",
// Start the DAQmx task DAQmx_Val_ChanPerLine));
/*********************************************/ /*********************************************/
DAQmxErrChk (DAQmxStartTask(hware->taskHandle)); // Start the DAQmx task
DAQmxErrChk (DAQmxStartTask(hware->taskHandle_dout)); /*********************************************/
hware_outp(hware, 0); DAQmxErrChk (DAQmxStartTask(hware->taskHandle));
DAQmxErrChk (DAQmxStartTask(hware->taskHandle_dout));
hware_outp(hware, 0);
} while (0);
#endif #endif
return 0; return 0;
@@ -745,7 +575,7 @@ int hware_dtor(pHWARE* ptr)
DAQmxClearTask(hware->taskHandle); DAQmxClearTask(hware->taskHandle);
hware->taskHandle = 0; hware->taskHandle = 0;
} }
if (hware->taskHandle_dout!=0) if (hware->taskHandle_dout != 0)
{ {
/*********************************************/ /*********************************************/
// DAQmx Stop Code // DAQmx Stop Code
@@ -809,5 +639,205 @@ void initMite(iBus *bus)
bus->destroyAddressSpace(Bar0); bus->destroyAddressSpace(Bar0);
} }
bool initPCI(pHWARE hware, const char* name)
{
CARD* pci = hware->card;
pci->bus = acquireBoard((tChar*) name);
if(pci->bus == NULL)
{
return false;
}
//Intitialise Mite Chip.
initMite(pci->bus);
return true;
}
void initCard(pHWARE hware)
{
CARD* pci = hware->card;
pci->Bar1 = pci->bus->createAddressSpace(kPCI_BAR1);
pci->Bar2 = pci->bus->createAddressSpace(kPCI_BAR1);
pci->tio_1 = new tTIO(pci->Bar1);
pci->tio_2 = new tTIO(pci->Bar2);
pci->tio_2->setAddressOffset(0x800);
//
// Set all counter outputs to 'input' so we don't accidentally double drive an IO pin
pci->tio_1->IO_Pin_8_9_Configuration_Register.writeIO_Pin_8_Select(0); //0='input'
pci->tio_1->IO_Pin_12_13_Configuration_Register.writeIO_Pin_12_Select(0); //0='input'
pci->tio_1->IO_Pin_16_17_Configuration_Register.writeIO_Pin_16_Select(0); //0='input'
pci->tio_1->IO_Pin_20_21_Configuration_Register.writeIO_Pin_20_Select(0); //0='input'
pci->tio_1->IO_Pin_24_25_Configuration_Register.writeIO_Pin_24_Select(0); //0='input'
pci->tio_1->IO_Pin_28_29_Configuration_Register.writeIO_Pin_28_Select(0); //0='input'
pci->tio_1->IO_Pin_32_33_Configuration_Register.writeIO_Pin_32_Select(0); //0='input'
pci->tio_1->IO_Pin_36_37_Configuration_Register.writeIO_Pin_36_Select(0); //0='input'
pci->tio_2->IO_Pin_8_9_Configuration_Register.writeIO_Pin_8_Select(0); //0='input'
pci->tio_2->IO_Pin_12_13_Configuration_Register.writeIO_Pin_12_Select(0); //0='input'
pci->tio_2->IO_Pin_16_17_Configuration_Register.writeIO_Pin_16_Select(0); //0='input'
pci->tio_2->IO_Pin_20_21_Configuration_Register.writeIO_Pin_20_Select(0); //0='input'
pci->tio_2->IO_Pin_24_25_Configuration_Register.writeIO_Pin_24_Select(0); //0='input'
pci->tio_2->IO_Pin_28_29_Configuration_Register.writeIO_Pin_28_Select(0); //0='input'
pci->tio_2->IO_Pin_32_33_Configuration_Register.writeIO_Pin_32_Select(0); //0='input'
pci->tio_2->IO_Pin_36_37_Configuration_Register.writeIO_Pin_36_Select(0); //0='input'
//Bind the first TIO to counters 0-3 on the IO connector, and
//bind the second TIO to counters 4-7
pci->tio_1->Clock_Configuration_Register.writeCntr_Swap(0);
pci->tio_2->Clock_Configuration_Register.writeCntr_Swap(1);
}
void initChan(pHWARE hware)
{
CARD* pci = hware->card;
/*
* Set up the channel object
*/
switch (hware->channel_number)
{
case 0:
//Disarm
pci->tio_1->G0_Command_Register.writeG0_Disarm(1);
//load initial value of zero
pci->tio_1->G0_Load_A_Registers.writeG0_Load_A(0x00000000);
pci->tio_1->G0_Command_Register.writeG0_Load(1);
//set source to external default source pin
pci->tio_1->G0_Input_Select_Register.writeG0_Source_Select(1);
//set gate to no gate
pci->tio_1->G0_Input_Select_Register.writeG0_Gate_Select(30);
pci->tio_1->G0_Mode_Register.writeG0_Gate_Polarity(1);
pci->tio_1->G0_Mode_Register.writeG0_Trigger_Mode_For_Edge_Gate(3);
//set counting direction to up
pci->tio_1->G0_Command_Register.writeG0_Up_Down(1);
//arm counter
pci->tio_1->G0_Command_Register.writeG0_Arm(1);
break;
case 1:
//Disarm
pci->tio_1->G1_Command_Register.writeG1_Disarm(1);
//load initial value of zero
pci->tio_1->G1_Load_A_Registers.writeG1_Load_A(0x00000000);
pci->tio_1->G1_Command_Register.writeG1_Load(1);
//set source to external default source pin
pci->tio_1->G1_Input_Select_Register.writeG1_Source_Select(1);
//set gate to no gate
pci->tio_1->G1_Input_Select_Register.writeG1_Gate_Select(30);
pci->tio_1->G1_Mode_Register.writeG1_Gate_Polarity(1);
pci->tio_1->G1_Mode_Register.writeG1_Trigger_Mode_For_Edge_Gate(3);
//set counting direction to up
pci->tio_1->G1_Command_Register.writeG1_Up_Down(1);
//arm counter
pci->tio_1->G1_Command_Register.writeG1_Arm(1);
break;
case 2:
//Disarm
pci->tio_1->G2_Command_Register.writeG2_Disarm(1);
//load initial value of zero
pci->tio_1->G2_Load_A_Registers.writeG2_Load_A(0x00000000);
pci->tio_1->G2_Command_Register.writeG2_Load(1);
//set source to external default source pin
pci->tio_1->G2_Input_Select_Register.writeG2_Source_Select(1);
//set gate to no gate
pci->tio_1->G2_Input_Select_Register.writeG2_Gate_Select(30);
pci->tio_1->G2_Mode_Register.writeG2_Gate_Polarity(1);
pci->tio_1->G2_Mode_Register.writeG2_Trigger_Mode_For_Edge_Gate(3);
//set counting direction to up
pci->tio_1->G2_Command_Register.writeG2_Up_Down(1);
//arm counter
pci->tio_1->G2_Command_Register.writeG2_Arm(1);
break;
case 3:
//Disarm
pci->tio_1->G3_Command_Register.writeG3_Disarm(1);
//load initial value of zero
pci->tio_1->G3_Load_A_Registers.writeG3_Load_A(0x00000000);
pci->tio_1->G3_Command_Register.writeG3_Load(1);
//set source to external default source pin
pci->tio_1->G3_Input_Select_Register.writeG3_Source_Select(1);
//set gate to no gate
pci->tio_1->G3_Input_Select_Register.writeG3_Gate_Select(30);
pci->tio_1->G3_Mode_Register.writeG3_Gate_Polarity(1);
pci->tio_1->G3_Mode_Register.writeG3_Trigger_Mode_For_Edge_Gate(3);
//set counting direction to up
pci->tio_1->G3_Command_Register.writeG3_Up_Down(1);
//arm counter
pci->tio_1->G3_Command_Register.writeG3_Arm(1);
break;
case 4:
//Disarm
pci->tio_2->G0_Command_Register.writeG0_Disarm(1);
//load initial value of zero
pci->tio_2->G0_Load_A_Registers.writeG0_Load_A(0x00000000);
pci->tio_2->G0_Command_Register.writeG0_Load(1);
//set source to external default source pin
pci->tio_2->G0_Input_Select_Register.writeG0_Source_Select(1);
//set gate to no gate
pci->tio_2->G0_Input_Select_Register.writeG0_Gate_Select(30);
pci->tio_2->G0_Mode_Register.writeG0_Gate_Polarity(1);
pci->tio_2->G0_Mode_Register.writeG0_Trigger_Mode_For_Edge_Gate(3);
//set counting direction to up
pci->tio_2->G0_Command_Register.writeG0_Up_Down(1);
//arm counter
pci->tio_2->G0_Command_Register.writeG0_Arm(1);
break;
case 5:
//Disarm
pci->tio_2->G1_Command_Register.writeG1_Disarm(1);
//load initial value of zero
pci->tio_2->G1_Load_A_Registers.writeG1_Load_A(0x00000000);
pci->tio_2->G1_Command_Register.writeG1_Load(1);
//set source to external default source pin
pci->tio_2->G1_Input_Select_Register.writeG1_Source_Select(1);
//set gate to no gate
pci->tio_2->G1_Input_Select_Register.writeG1_Gate_Select(30);
pci->tio_2->G1_Mode_Register.writeG1_Gate_Polarity(1);
pci->tio_2->G1_Mode_Register.writeG1_Trigger_Mode_For_Edge_Gate(3);
//set counting direction to up
pci->tio_2->G1_Command_Register.writeG1_Up_Down(1);
//arm counter
pci->tio_2->G1_Command_Register.writeG1_Arm(1);
break;
case 6:
//Disarm
pci->tio_2->G2_Command_Register.writeG2_Disarm(1);
//load initial value of zero
pci->tio_2->G2_Load_A_Registers.writeG2_Load_A(0x00000000);
pci->tio_2->G2_Command_Register.writeG2_Load(1);
//set source to external default source pin
pci->tio_2->G2_Input_Select_Register.writeG2_Source_Select(1);
//set gate to no gate
pci->tio_2->G2_Input_Select_Register.writeG2_Gate_Select(30);
pci->tio_2->G2_Mode_Register.writeG2_Gate_Polarity(1);
pci->tio_2->G2_Mode_Register.writeG2_Trigger_Mode_For_Edge_Gate(3);
//set counting direction to up
pci->tio_2->G2_Command_Register.writeG2_Up_Down(1);
//arm counter
pci->tio_2->G2_Command_Register.writeG2_Arm(1);
break;
case 7:
//Disarm
pci->tio_2->G3_Command_Register.writeG3_Disarm(1);
//load initial value of zero
pci->tio_2->G3_Load_A_Registers.writeG3_Load_A(0x00000000);
pci->tio_2->G3_Command_Register.writeG3_Load(1);
//set source to external default source pin
pci->tio_2->G3_Input_Select_Register.writeG3_Source_Select(1);
//set gate to no gate
pci->tio_2->G3_Input_Select_Register.writeG3_Gate_Select(30);
pci->tio_2->G3_Mode_Register.writeG3_Gate_Polarity(1);
pci->tio_2->G3_Mode_Register.writeG3_Trigger_Mode_For_Edge_Gate(3);
//set counting direction to up
pci->tio_2->G3_Command_Register.writeG3_Up_Down(1);
//arm counter
pci->tio_2->G3_Command_Register.writeG3_Arm(1);
break;
}
}
#else #else
#endif #endif