📄 hwdrv_apci1500.c
字号:
/* Selects the data path polarity register of port B */ outb(APCI1500_RW_PORT_B_DATA_PCITCH_POLARITY,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); /* A high level of port B means 1 */ outb(0x7F,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); /* Selects the data direction register of port B */ outb(APCI1500_RW_PORT_B_DATA_DIRECTION,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); /* All bits used as inputs */ outb(0xFF,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); /* Selects the command and status register of port B */ outb(APCI1500_RW_PORT_B_COMMAND_AND_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); /* Deletes IP and IUS */ outb(0x20,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); /* Selects the command and status register of port B */ outb( APCI1500_RW_PORT_B_COMMAND_AND_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); /* Deactivates the interrupt management of port B: */ outb(0xE0,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); /* Selects the handshake specification register of port B */ outb(APCI1500_RW_PORT_B_HANDSHAKE_SPECIFICATION,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); /* Deletes the register */ outb(0,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); /*****************************************************/ /* Selects the data path polarity register of port C */ /*****************************************************/ outb( APCI1500_RW_PORT_C_DATA_PCITCH_POLARITY,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); /* High level of port C means 1 */ outb(0x9,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); /* Selects the data direction register of port C */ outb(APCI1500_RW_PORT_C_DATA_DIRECTION,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); /* All bits used as inputs except channel 1 */ outb(0x0E,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); /* Selects the special IO register of port C */ outb( APCI1500_RW_PORT_C_SPECIAL_IO_CONTROL,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); /* Deletes it */ outb(0,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); /******************************************************/ /* Selects the command and status register of timer 1 */ /******************************************************/ outb(APCI1500_RW_CPT_TMR1_CMD_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); /* Deletes IP and IUS */ outb(0x20,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); /* Selects the command and status register of timer 1 */ outb(APCI1500_RW_CPT_TMR1_CMD_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); /* Deactivates the interrupt management of timer 1 */ outb(0xE0,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); /******************************************************/ /* Selects the command and status register of timer 2 */ /******************************************************/ outb( APCI1500_RW_CPT_TMR2_CMD_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); /* Deletes IP and IUS */ outb(0x20,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); /* Selects the command and status register of timer 2 */ outb(APCI1500_RW_CPT_TMR2_CMD_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); /* Deactivates Timer 2 interrupt management: */ outb(0xE0,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); /******************************************************/ /* Selects the command and status register of timer 3 */ /******************************************************/ outb(APCI1500_RW_CPT_TMR3_CMD_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); /* Deletes IP and IUS */ outb(0x20,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); /* Selects the command and status register of Timer 3 */ outb(APCI1500_RW_CPT_TMR3_CMD_STATUS,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); /* Deactivates interrupt management of timer 3: */ outb(0xE0,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); /*************************************************/ /* Selects the master interrupt control register */ /*************************************************/ outb(APCI1500_RW_MASTER_INTERRUPT_CONTROL,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); /* Deletes all interrupts */ outb(0,devpriv->iobase+APCI1500_Z8536_CONTROL_REGISTER); return insn->n;}/*+----------------------------------------------------------------------------+| Function Name : int i_APCI1500_ReadMoreDigitalInput || (comedi_device *dev,comedi_subdevice *s, || comedi_insn *insn,lsampl_t *data) |+----------------------------------------------------------------------------+| Task : Return the status of the Requested digital inputs |+----------------------------------------------------------------------------+| Input Parameters : comedi_device *dev : Driver handle || UINT ui_NoOfChannels : No Of Channels To be Read || UINT *data : Data Pointer data[0] : 0 Read a single channel 1 read a port value data[1] : port value +----------------------------------------------------------------------------+| Output Parameters : -- data[0] :The read status value +----------------------------------------------------------------------------+| Return Value : TRUE : No error occur || : FALSE : Error occur. Return the error || |+----------------------------------------------------------------------------+*/INT i_APCI1500_ReadMoreDigitalInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data){ UINT ui_PortValue=data[1]; UINT ui_Mask=0; UINT ui_Channel; UINT ui_TmpValue=0; ui_Channel=CR_CHAN(insn->chanspec); switch(data[0]) { case 0: if (ui_Channel >= 0 && ui_Channel <=15) { ui_TmpValue=(UINT) inw(devpriv->i_IobaseAddon + APCI1500_DIGITAL_IP); *data = (ui_TmpValue >> ui_Channel)&0x1 ; }//if(ui_Channel >= 0 && ui_Channel <=15) else { printk("\nThe channel specification are in error\n"); return -EINVAL; // "sorry channel spec wrong " }//else if(ui_Channel >= 0 && ui_Channel <=15) break; case 1: *data=(UINT)inw(devpriv->i_IobaseAddon + APCI1500_DIGITAL_IP ); switch (ui_Channel) { case 2:ui_Mask=3; *data=(*data >>(2*ui_PortValue))&ui_Mask; break; case 4:ui_Mask=15; *data=(*data >>(4*ui_PortValue))&ui_Mask; break; case 8:ui_Mask=255; *data=(*data >>(8*ui_PortValue))&ui_Mask; break; case 15: break; default: printk("\nSpecified channel cannot be read \n"); return -EINVAL; // "sorry channel spec wrong " break; }//switch(ui_Channel) break; default: printk("\nThe specified functionality does not exist\n"); return -EINVAL; }//switch(data[0]) return insn->n;}/*+----------------------------------------------------------------------------+| Function Name : int i_APCI1500_ConfigDigitalOutputErrorInterrupt (comedi_device *dev,comedi_subdevice *s comedi_insn *insn,lsampl_t *data) || |+----------------------------------------------------------------------------+| Task : Configures the digital output memory and the digital output error interrupt |+----------------------------------------------------------------------------+| Input Parameters : comedi_device *dev : Driver handle || lsampl_t *data : Data Pointer contains || configuration parameters as below || comedi_subdevice *s, :pointer to subdevice structure comedi_insn *insn :pointer to insn structure | | data[0] :1:Memory on | | 0:Memory off | data[1] :1 Enable the voltage error interrupt | :0 Disable the voltage error interrupt | | |+----------------------------------------------------------------------------+| Output Parameters : -- |+----------------------------------------------------------------------------+| Return Value : TRUE : No error occur || : FALSE : Error occur. Return the error || |+----------------------------------------------------------------------------+*/int i_APCI1500_ConfigDigitalOutputErrorInterrupt(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data){devpriv->b_OutputMemoryStatus=data[0]; return insn->n;}/*+----------------------------------------------------------------------------+| Function Name : int i_APCI1500_WriteDigitalOutput || (comedi_device *dev,comedi_subdevice *s, | | comedi_insn *insn,lsampl_t *data) |+----------------------------------------------------------------------------+| Task : Writes port value To the selected port |+----------------------------------------------------------------------------+| Input Parameters : comedi_device *dev : Driver handle || UINT ui_NoOfChannels : No Of Channels To Write || UINT *data : Data Pointer to read status |+----------------------------------------------------------------------------+| Output Parameters : -- |+----------------------------------------------------------------------------+| Return Value : TRUE : No error occur || : FALSE : Error occur. Return the error || |+----------------------------------------------------------------------------+*/INT i_APCI1500_WriteDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) {static UINT ui_Temp=0;UINT ui_Temp1;UINT ui_NoOfChannel = CR_CHAN(insn->chanspec); // get the channel if(!devpriv->b_OutputMemoryStatus ) { ui_Temp=0; }//if(!devpriv->b_OutputMemoryStatus )if(data[3]==0) { if(data[1]==0) { data[0]=(data[0] << ui_NoOfChannel)|ui_Temp; outw(data[0],devpriv->i_IobaseAddon+APCI1500_DIGITAL_OP); }//if(data[1]==0) else { if(data[1]==1) { switch( ui_NoOfChannel) { case 2: data[0]=(data[0] << (2*data[2]))|ui_Temp; break; case 4:data[0]=(data[0] << (4*data[2]))|ui_Temp; break; case 8: data[0]=(data[0] <<(8*data[2]))|ui_Temp; break; case 15:data[0]=data[0]|ui_Temp; break; default: comedi_error(dev," chan spec wrong"); return -EINVAL; // "sorry channel spec wrong "
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -