📄 hwdrv_apci3xxx.c
字号:
/**@verbatimCopyright (C) 2004,2005 ADDI-DATA GmbH for the source code of this module. ADDI-DATA GmbH Dieselstrasse 3 D-77833 Ottersweier Tel: +19(0)7223/9493-0 Fax: +49(0)7223/9493-92 http://www.addi-data-com info@addi-data.com This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USAYou shoud also find the complete GPL in the COPYING file accompanying this source code.@endverbatim*//* +-----------------------------------------------------------------------+ | (C) ADDI-DATA GmbH Dieselstrasse 3 D-77833 Ottersweier | +-----------------------------------------------------------------------+ | Tel : +49 (0) 7223/9493-0 | email : info@addi-data.com | | Fax : +49 (0) 7223/9493-92 | Internet : http://www.addi-data.com | +-----------------------------------------------------------------------+ | Project : APCI-3XXX | Compiler : GCC | | Module name : hwdrv_apci3xxx.c| Version : 2.96 | +-------------------------------+---------------------------------------+ | Project manager: S. Weber | Date : 15/09/2005 | +-----------------------------------------------------------------------+ | Description :APCI3XXX Module. Hardware abstraction Layer for APCI3XXX| +-----------------------------------------------------------------------+ | UPDATE'S | +-----------------------------------------------------------------------+ | Date | Author | Description of updates | +----------+-----------+------------------------------------------------+ | | | | | | | | +----------+-----------+------------------------------------------------+*/#include "hwdrv_apci3xxx.h"/*+----------------------------------------------------------------------------+| ANALOG INPUT FUNCTIONS |+----------------------------------------------------------------------------+*//*+----------------------------------------------------------------------------+| Function Name : INT i_APCI3XXX_TestConversionStarted || (comedi_device *dev) |+----------------------------------------------------------------------------+| Task Test if any conversion started |+----------------------------------------------------------------------------+| Input Parameters : - |+----------------------------------------------------------------------------+| Output Parameters : - |+----------------------------------------------------------------------------+| Return Value : 0 : Conversion not started || 1 : Conversion started |+----------------------------------------------------------------------------+*/int i_APCI3XXX_TestConversionStarted (comedi_device *dev) { if ((readl ((void *) (devpriv->dw_AiBase + 8)) & 0x80000UL) == 0x80000UL) { return (1); } else { return (0); } }/*+----------------------------------------------------------------------------+| Function Name : INT i_APCI3XXX_AnalogInputConfigOperatingMode || (comedi_device *dev, || comedi_subdevice *s, || comedi_insn *insn, || lsampl_t *data) |+----------------------------------------------------------------------------+| Task Converting mode and convert time selection |+----------------------------------------------------------------------------+| Input Parameters : b_SingleDiff = (BYTE) data[1]; || b_TimeBase = (BYTE) data[2]; (0: ns, 1:micros 2:ms)|| dw_ReloadValue = (DWORD) data[3]; || ........ |+----------------------------------------------------------------------------+| Output Parameters : - |+----------------------------------------------------------------------------+| Return Value :>0 : No error || -1 : Single/Diff selection error || -2 : Convert time base unity selection error || -3 : Convert time value selection error || -10: Any conversion started || .... || -100 : Config command error || -101 : Data size error |+----------------------------------------------------------------------------+*/int i_APCI3XXX_AnalogInputConfigOperatingMode (comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data) { INT i_ReturnValue = insn->n; BYTE b_TimeBase = 0; BYTE b_SingleDiff = 0; DWORD dw_ReloadValue = 0; DWORD dw_TestReloadValue = 0; /************************/ /* Test the buffer size */ /************************/ if (insn->n == 4) { /****************************/ /* Get the Singel/Diff flag */ /****************************/ b_SingleDiff = (BYTE) data[1]; /****************************/ /* Get the time base unitiy */ /****************************/ b_TimeBase = (BYTE) data[2]; /*************************************/ /* Get the convert time reload value */ /*************************************/ dw_ReloadValue = (DWORD) data[3]; /**********************/ /* Test the time base */ /**********************/ if ((devpriv->ps_BoardInfo->b_AvailableConvertUnit & (1 << b_TimeBase)) != 0) { /*******************************/ /* Test the convert time value */ /*******************************/ if ((dw_ReloadValue >= 0) && (dw_ReloadValue <= 65535)) { dw_TestReloadValue = dw_ReloadValue; if (b_TimeBase == 1) { dw_TestReloadValue = dw_TestReloadValue * 1000UL; } if (b_TimeBase == 2) { dw_TestReloadValue = dw_TestReloadValue * 1000000UL; } /*******************************/ /* Test the convert time value */ /*******************************/ if (dw_TestReloadValue >= devpriv->ps_BoardInfo->ui_MinAcquisitiontimeNs) { if ((b_SingleDiff == APCI3XXX_SINGLE) || (b_SingleDiff == APCI3XXX_DIFF)) { if (((b_SingleDiff == APCI3XXX_SINGLE) && (devpriv->ps_BoardInfo->i_NbrAiChannel == 0)) || ((b_SingleDiff == APCI3XXX_DIFF) && (devpriv->ps_BoardInfo->i_NbrAiChannelDiff == 0))) { /*******************************/ /* Single/Diff selection error */ /*******************************/ printk("Single/Diff selection error\n"); i_ReturnValue = -1; } else { /**********************************/ /* Test if conversion not started */ /**********************************/ if (i_APCI3XXX_TestConversionStarted (dev) == 0) { devpriv->ui_EocEosConversionTime = (UINT) dw_ReloadValue; devpriv->b_EocEosConversionTimeBase = b_TimeBase; devpriv->b_SingelDiff = b_SingleDiff; devpriv->b_AiInitialisation = 1; /*******************************/ /* Set the convert timing unit */ /*******************************/ writel((DWORD) b_TimeBase, (void *) (devpriv->dw_AiBase + 36)); /**************************/ /* Set the convert timing */ /*************************/ writel(dw_ReloadValue, (void *) (devpriv->dw_AiBase + 32)); } else { /**************************/ /* Any conversion started */ /**************************/ printk("Any conversion started\n"); i_ReturnValue = -10; } } } else { /*******************************/ /* Single/Diff selection error */ /*******************************/ printk("Single/Diff selection error\n"); i_ReturnValue = -1; } } else { /************************/ /* Time selection error */ /************************/ printk("Convert time value selection error\n"); i_ReturnValue = -3; } } else { /************************/ /* Time selection error */ /************************/ printk("Convert time value selection error\n"); i_ReturnValue = -3; } } else { /*****************************/ /* Time base selection error */ /*****************************/ printk("Convert time base unity selection error\n"); i_ReturnValue = -2; } } else { /*******************/ /* Data size error */ /*******************/ printk("Buffer size error\n"); i_ReturnValue = -101; } return (i_ReturnValue); }/*+----------------------------------------------------------------------------+| Function Name : INT i_APCI3XXX_InsnConfigAnalogInput || (comedi_device *dev, || comedi_subdevice *s, || comedi_insn *insn, || lsampl_t *data) |+----------------------------------------------------------------------------+| Task Converting mode and convert time selection |+----------------------------------------------------------------------------+| Input Parameters : b_ConvertMode = (BYTE) data[0]; || b_TimeBase = (BYTE) data[1]; (0: ns, 1:micros 2:ms)|| dw_ReloadValue = (DWORD) data[2]; || ........ |+----------------------------------------------------------------------------+| Output Parameters : - |+----------------------------------------------------------------------------+| Return Value :>0: No error || .... || -100 : Config command error || -101 : Data size error |+----------------------------------------------------------------------------+*/int i_APCI3XXX_InsnConfigAnalogInput(comedi_device *dev, comedi_subdevice *s, comedi_insn *insn, lsampl_t *data) { INT i_ReturnValue = insn->n; /************************/ /* Test the buffer size */ /************************/ if (insn->n >= 1) { switch ((BYTE) data[0]) { case APCI3XXX_CONFIGURATION: i_ReturnValue = i_APCI3XXX_AnalogInputConfigOperatingMode (dev, s, insn, data) ; break; default: i_ReturnValue = -100; printk("Config command error %d\n", data[0]); break; } } else { /*******************/ /* Data size error */ /*******************/ printk("Buffer size error\n"); i_ReturnValue = -101; } return (i_ReturnValue);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -