From 6928921378eb526523ec20b06d9bfae1790b303b Mon Sep 17 00:00:00 2001 From: Douglas Clowes Date: Wed, 15 Nov 2006 08:41:53 +1100 Subject: [PATCH] Re-factor device specific code r1292 | dcl | 2006-11-15 08:41:53 +1100 (Wed, 15 Nov 2006) | 2 lines --- site_ansto/hardsup/Digital/hware.c | 153 ++++++---- site_ansto/hardsup/Monitor/hware.c | 470 +++++++++++++++-------------- 2 files changed, 350 insertions(+), 273 deletions(-) diff --git a/site_ansto/hardsup/Digital/hware.c b/site_ansto/hardsup/Digital/hware.c index fb931252..e3aa7061 100644 --- a/site_ansto/hardsup/Digital/hware.c +++ b/site_ansto/hardsup/Digital/hware.c @@ -72,6 +72,8 @@ typedef struct device_private_t #ifdef REGISTER_LEVEL_PROGRAMMING static void initMite(iBus *bus); +static void initCard(pHWARE ptr); +static void initChan(pHWARE ptr); static CARD* card[10]; #else @@ -174,24 +176,7 @@ int hware_ctor(const char* device_name, pHWARE* ptr) initMite(pci->bus); - pci->Bar1 = pci->bus->createAddressSpace(kPCI_BAR1); - 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); + initCard(hware); } else { @@ -206,42 +191,49 @@ int hware_ctor(const char* device_name, pHWARE* ptr) } pci->dev_mask |= 1 << hware->channel_number; + initChan(hware); #else - char local_name[40] = "dev2/port0"; - /*********************************************/ - // Create a DAQmx task - /*********************************************/ - DAQmxErrChk (DAQmxCreateTask("",&hware->taskHandle)); - DAQmxErrChk (DAQmxCreateTask("",&hware->taskHandle_dout)); + do { + char local_name[40]; + /*********************************************/ + // Create a DAQmx task + /*********************************************/ + DAQmxErrChk (DAQmxCreateTask("",&hware->taskHandle)); + DAQmxErrChk (DAQmxCreateTask("",&hware->taskHandle_dout)); - /*********************************************/ - // Create a DAQmx device within the task - /*********************************************/ - snprintf(local_name, sizeof(local_name), "dev%d/line%d:%d", - hware->card_number, - hware->channel_number * 32, - hware->channel_number * 32 + 23); - DAQmxErrChk ( - DAQmxCreateDIChan(hware->taskHandle, - local_name, - "", - DAQmx_Val_ChanForAllLines)); - fprintf(stderr, "Input %s\n", local_name); - snprintf(local_name, sizeof(local_name), "dev%d/line%d:%d", - hware->card_number, - hware->channel_number * 32 + 24, - hware->channel_number * 32 + 31); - DAQmxErrChk ( - DAQmxCreateDOChan(hware->taskHandle_dout, - local_name, - "", - DAQmx_Val_ChanForAllLines)); - fprintf(stderr, "Output %s\n", local_name); - /*********************************************/ - // Start the DAQmx task - /*********************************************/ - DAQmxErrChk (DAQmxStartTask(hware->taskHandle)); - DAQmxErrChk (DAQmxStartTask(hware->taskHandle_dout)); + /*********************************************/ + // Create a DAQmx device within the task + /*********************************************/ + snprintf(local_name, sizeof(local_name), + "dev%d/line%d:%d", + hware->card_number, + hware->channel_number * 32, + hware->channel_number * 32 + 23); + DAQmxErrChk ( + DAQmxCreateDIChan(hware->taskHandle, + local_name, + "", + DAQmx_Val_ChanForAllLines)); + + /*********************************************/ + // Create the digital output channel within the task + /*********************************************/ + snprintf(local_name, sizeof(local_name), + "dev%d/line%d:%d", + hware->card_number, + hware->channel_number * 32 + 24, + hware->channel_number * 32 + 31); + DAQmxErrChk ( + DAQmxCreateDOChan(hware->taskHandle_dout, + local_name, + "", + DAQmx_Val_ChanForAllLines)); + /*********************************************/ + // Start the DAQmx task + /*********************************************/ + DAQmxErrChk (DAQmxStartTask(hware->taskHandle)); + DAQmxErrChk (DAQmxStartTask(hware->taskHandle_dout)); + } while (0); #endif hware_write(hware, 0); @@ -492,10 +484,65 @@ void initMite(iBus *bus) //Get the physical address of the DAQ board 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); 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 #endif diff --git a/site_ansto/hardsup/Monitor/hware.c b/site_ansto/hardsup/Monitor/hware.c index 32dc19e7..b79c34db 100644 --- a/site_ansto/hardsup/Monitor/hware.c +++ b/site_ansto/hardsup/Monitor/hware.c @@ -67,6 +67,13 @@ typedef struct device_private_t #endif } 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 { int cntr_num; int sync_num; @@ -83,12 +90,6 @@ static MAPPING mapping[8] = { { 6, 13, 12 }, { 7, 9, 8 } }; - -#ifdef REGISTER_LEVEL_PROGRAMMING -static void initMite(iBus *bus); - -static CARD* card[10]; -#else #endif 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; bool flag = false; char text_string[] = DEFAULT_DEVICE; - char port_range[40]; const char *name; const char *text; @@ -114,7 +114,7 @@ int hware_ctor(const char* device_name, pHWARE* ptr) { if (isspace(*name)) ++name; - else if (*name >= '0' && *name <= '7') + else if (*name >= '0' && *name <= '9') { if (flag) { @@ -139,8 +139,6 @@ int hware_ctor(const char* device_name, pHWARE* ptr) ++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 if (card[hware->card_number] == NULL) { @@ -177,9 +175,7 @@ int hware_ctor(const char* device_name, pHWARE* ptr) pci = card[hware->card_number]; hware->card = pci; - pci->bus = acquireBoard((tChar*) local_name /* "PXI6::1::INSTR" */); - - if(pci->bus == NULL) + if(!initPCI(hware, local_name)) { printf("Error accessing the PCI device \"%s\". Exiting.\n", local_name); @@ -187,39 +183,7 @@ int hware_ctor(const char* device_name, pHWARE* ptr) goto Error; } - //Intitialise Mite Chip. - - 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); + initCard(hware); } else { @@ -234,182 +198,48 @@ int hware_ctor(const char* device_name, pHWARE* ptr) } pci->dev_mask |= 1 << hware->channel_number; - /* - * 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; - } + initChan(hware); #else - /*********************************************/ - // Create a DAQmx task - /*********************************************/ - DAQmxErrChk (DAQmxCreateTask("",&hware->taskHandle)); - DAQmxErrChk (DAQmxCreateTask("",&hware->taskHandle_dout)); + do { + char local_name[40]; + hware->sync_line_number = mapping[hware->channel_number].sync_num; + hware->output_line_number = mapping[hware->channel_number].outp_num; + /*********************************************/ + // Create a DAQmx task + /*********************************************/ + DAQmxErrChk (DAQmxCreateTask("",&hware->taskHandle)); + DAQmxErrChk (DAQmxCreateTask("",&hware->taskHandle_dout)); - /*********************************************/ - // Create a DAQmx device within the task - /*********************************************/ - DAQmxErrChk ( - DAQmxCreateCICountEdgesChan(hware->taskHandle, - device_name, - "", - DAQmx_Val_Rising, - hware->count32, - DAQmx_Val_CountUp)); + /*********************************************/ + // Create a DAQmx device within the task + /*********************************************/ + DAQmxErrChk ( + DAQmxCreateCICountEdgesChan(hware->taskHandle, + device_name, + "", + DAQmx_Val_Rising, + hware->count32, + DAQmx_Val_CountUp)); - /*********************************************/ - // Create the digital channel within the task - /*********************************************/ - snprintf(port_range, sizeof(port_range), "DEV%d/LINE%d", - hware->card_number, hware->channel_number); - DAQmxErrChk (DAQmxCreateDOChan(hware->taskHandle_dout, - port_range, - "", - DAQmx_Val_ChanPerLine)); - - /*********************************************/ - // Start the DAQmx task - /*********************************************/ - DAQmxErrChk (DAQmxStartTask(hware->taskHandle)); - DAQmxErrChk (DAQmxStartTask(hware->taskHandle_dout)); - hware_outp(hware, 0); + /*********************************************/ + // Create the digital output channel within the task + /*********************************************/ + snprintf(local_name, sizeof(local_name), + "dev%d/line%d", + hware->card_number, + hware->channel_number); + DAQmxErrChk ( + DAQmxCreateDOChan(hware->taskHandle_dout, + local_name, + "", + DAQmx_Val_ChanPerLine)); + /*********************************************/ + // Start the DAQmx task + /*********************************************/ + DAQmxErrChk (DAQmxStartTask(hware->taskHandle)); + DAQmxErrChk (DAQmxStartTask(hware->taskHandle_dout)); + hware_outp(hware, 0); + } while (0); #endif return 0; @@ -745,7 +575,7 @@ int hware_dtor(pHWARE* ptr) DAQmxClearTask(hware->taskHandle); hware->taskHandle = 0; } - if (hware->taskHandle_dout!=0) + if (hware->taskHandle_dout != 0) { /*********************************************/ // DAQmx Stop Code @@ -809,5 +639,205 @@ void initMite(iBus *bus) 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 #endif