📄 hwdrv_apci3xxx.c
字号:
}/*+----------------------------------------------------------------------------+| Function Name : INT i_APCI3XXX_InsnReadAnalogInput || (comedi_device *dev, || comedi_subdevice *s, || comedi_insn *insn, || lsampl_t *data) |+----------------------------------------------------------------------------+| Task Read 1 analog input |+----------------------------------------------------------------------------+| Input Parameters : b_Range = CR_RANGE(insn->chanspec); || b_Channel = CR_CHAN(insn->chanspec); || dw_NbrOfAcquisition = insn->n; |+----------------------------------------------------------------------------+| Output Parameters : - |+----------------------------------------------------------------------------+| Return Value :>0: No error || -3 : Channel selection error || -4 : Configuration selelection error || -10: Any conversion started || .... || -100 : Config command error || -101 : Data size error |+----------------------------------------------------------------------------+*/int i_APCI3XXX_InsnReadAnalogInput (comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data) { INT i_ReturnValue = insn->n; BYTE b_Configuration = (BYTE) CR_RANGE(insn->chanspec); BYTE b_Channel = (BYTE) CR_CHAN(insn->chanspec); DWORD dw_Temp = 0; DWORD dw_Configuration = 0; DWORD dw_AcquisitionCpt = 0; BYTE b_Interrupt = 0; /*************************************/ /* Test if operating mode configured */ /*************************************/ if (devpriv->b_AiInitialisation) { /***************************/ /* Test the channel number */ /***************************/ if (((b_Channel < devpriv->ps_BoardInfo->i_NbrAiChannel) && (devpriv->b_SingelDiff == APCI3XXX_SINGLE)) || ((b_Channel < devpriv->ps_BoardInfo->i_NbrAiChannelDiff) && (devpriv->b_SingelDiff == APCI3XXX_DIFF))) { /**********************************/ /* Test the channel configuration */ /**********************************/ if (b_Configuration > 7) { /***************************/ /* Channel not initialised */ /***************************/ i_ReturnValue = -4; printk ("Channel %d range %d selection error\n", b_Channel, b_Configuration); } } else { /***************************/ /* Channel selection error */ /***************************/ i_ReturnValue = -3; printk ("Channel %d selection error\n", b_Channel); } /**************************/ /* Test if no error occur */ /**************************/ if (i_ReturnValue >= 0) { /************************/ /* Test the buffer size */ /************************/ if ((b_Interrupt != 0) || ((b_Interrupt == 0) && (insn->n >= 1))) { /**********************************/ /* Test if conversion not started */ /**********************************/ if (i_APCI3XXX_TestConversionStarted (dev) == 0) { /******************/ /* Clear the FIFO */ /******************/ writel(0x10000UL, (void *) (devpriv->dw_AiBase + 12)); /*******************************/ /* Get and save the delay mode */ /*******************************/ dw_Temp = readl((void *) (devpriv->dw_AiBase + 4)); dw_Temp = dw_Temp & 0xFFFFFEF0UL; /***********************************/ /* Channel configuration selection */ /***********************************/ writel(dw_Temp, (void *) (devpriv->dw_AiBase + 4)); /**************************/ /* Make the configuration */ /**************************/ dw_Configuration = (b_Configuration & 3) | ((DWORD) (b_Configuration >> 2) << 6) | ((DWORD) devpriv->b_SingelDiff << 7); /***************************/ /* Write the configuration */ /***************************/ writel(dw_Configuration, (void *) (devpriv->dw_AiBase + 0)); /*********************/ /* Channel selection */ /*********************/ writel(dw_Temp | 0x100UL, (void *) (devpriv->dw_AiBase + 4)); writel((DWORD) b_Channel, (void *) (devpriv->dw_AiBase + 0)); /***********************/ /* Restaure delay mode */ /***********************/ writel(dw_Temp, (void *) (devpriv->dw_AiBase + 4)); /***********************************/ /* Set the number of sequence to 1 */ /***********************************/ writel(1, (void *) (devpriv->dw_AiBase + 48)); /***************************/ /* Save the interrupt flag */ /***************************/ devpriv->b_EocEosInterrupt = b_Interrupt; /*******************************/ /* Save the number of channels */ /*******************************/ devpriv->ui_AiNbrofChannels = 1; /******************************/ /* Test if interrupt not used */ /******************************/ if (b_Interrupt == 0) { for (dw_AcquisitionCpt = 0; dw_AcquisitionCpt < insn->n; dw_AcquisitionCpt ++) { /************************/ /* Start the conversion */ /************************/ writel(0x80000UL, (void *) (devpriv->dw_AiBase + 8)); /****************/ /* Wait the EOS */ /****************/ do { dw_Temp = readl((void *) (devpriv->dw_AiBase + 20)); dw_Temp = dw_Temp & 1; } while (dw_Temp != 1); /*************************/ /* Read the analog value */ /*************************/ data[dw_AcquisitionCpt] = (lsampl_t) readl((void *) (devpriv->dw_AiBase + 28)); } } else { /************************/ /* Start the conversion */ /************************/ writel(0x180000UL, (void *) (devpriv->dw_AiBase + 8)); } } else { /**************************/ /* Any conversion started */ /**************************/ printk("Any conversion started\n"); i_ReturnValue = -10; } } else { /*******************/ /* Data size error */ /*******************/ printk("Buffer size error\n"); i_ReturnValue = -101; } } } else { /***************************/ /* Channel selection error */ /***************************/ printk("Operating mode not configured\n"); i_ReturnValue = -1; } return (i_ReturnValue); }/*+----------------------------------------------------------------------------+| Function name : void v_APCI3XXX_Interrupt (int irq, || void *d, | | struct pt_regs *regs) |+----------------------------------------------------------------------------+| Task :Interrupt handler for APCI3XXX || When interrupt occurs this gets called. || First it finds which interrupt has been generated and | | handles corresponding interrupt |+----------------------------------------------------------------------------+| Input Parameters : - |+----------------------------------------------------------------------------+| Return Value : - |+----------------------------------------------------------------------------+*/void v_APCI3XXX_Interrupt(int irq, void *d, struct pt_regs *regs) { comedi_device *dev = d; BYTE b_CopyCpt = 0; DWORD dw_Status = 0; /***************************/ /* Test if interrupt occur */ /***************************/ if (((dw_Status = readl ((void *) (devpriv->dw_AiBase + 16))) & 0x2UL) == 0x2UL) { /***********************/ /* Reset the interrupt */ /***********************/ writel(dw_Status, (void *) (devpriv->dw_AiBase + 16)); /*****************************/ /* Test if interrupt enabled */ /*****************************/ if (devpriv->b_EocEosInterrupt == 1) { /********************************/ /* Read all analog inputs value */ /********************************/ for (b_CopyCpt = 0; b_CopyCpt < devpriv->ui_AiNbrofChannels; b_CopyCpt ++) { devpriv->ui_AiReadData[b_CopyCpt] = (UINT) readl((void *) (devpriv->dw_AiBase + 28)); } /**************************/ /* Set the interrupt flag */ /**************************/ devpriv->b_EocEosInterrupt = 2; /**********************************************/ /* Send a signal to from kernel to user space */ /**********************************************/ send_sig(SIGIO,devpriv->tsk_Current,0); } } }/*+----------------------------------------------------------------------------+| ANALOG OUTPUT SUBDEVICE |+----------------------------------------------------------------------------+*//*+----------------------------------------------------------------------------+| Function Name : INT i_APCI3XXX_InsnWriteAnalogOutput || (comedi_device *dev, || comedi_subdevice *s, || comedi_insn *insn, || lsampl_t *data) |+----------------------------------------------------------------------------+| Task Read 1 analog input |+----------------------------------------------------------------------------+| Input Parameters : b_Range = CR_RANGE(insn->chanspec); || b_Channel = CR_CHAN(insn->chanspec); || data[0] = analog value; |+----------------------------------------------------------------------------+| Output Parameters : - |+----------------------------------------------------------------------------+| Return Value :>0: No error || -3 : Channel selection error || -4 : Configuration selelection error || .... || -101 : Data size error |+----------------------------------------------------------------------------+*/int i_APCI3XXX_InsnWriteAnalogOutput (comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data) { BYTE b_Range = (BYTE) CR_RANGE(insn->chanspec); BYTE b_Channel = (BYTE) CR_CHAN (insn->chanspec); DWORD dw_Status = 0; INT i_ReturnValue = insn->n;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -