📄 apci1710_inp_cpt.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 Dieselstraße 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 : API APCI1710 | Compiler : gcc | | Module name : Inp_CPT.C | Version : 2.96 | +-------------------------------+---------------------------------------+ | Project manager: Eric Stolz | Date : 02/12/2002 | +-----------------------------------------------------------------------+ | Description : APCI-1710 pulse encoder module | | | | | +-----------------------------------------------------------------------+ | UPDATES | +-----------------------------------------------------------------------+ | Date | Author | Description of updates | +----------+-----------+------------------------------------------------+ | | | | |----------|-----------|------------------------------------------------| | 08/05/00 | Guinot C | - 0400/0228 All Function in RING 0 | | | | available | +-----------------------------------------------------------------------+*//*+----------------------------------------------------------------------------+| Included files |+----------------------------------------------------------------------------+*/#include "APCI1710_Inp_cpt.h"/*+----------------------------------------------------------------------------+| Function Name : _INT_ i_APCI1710_InitPulseEncoder || (BYTE_ b_BoardHandle, || BYTE_ b_ModulNbr, || BYTE_ b_PulseEncoderNbr, || BYTE_ b_InputLevelSelection, || BYTE_ b_TriggerOutputAction, || ULONG_ ul_StartValue) |+----------------------------------------------------------------------------+| Task : Configure the pulse encoder operating mode selected via|| b_ModulNbr and b_PulseEncoderNbr. The pulse encoder || after each pulse decrement the counter value from 1. || || You must calling this function be for you call any || other function witch access of pulse encoders. |+----------------------------------------------------------------------------+| Input Parameters : BYTE_ b_BoardHandle : Handle of board APCI-1710|| BYTE_ b_ModulNbr : Module number to || configure (0 to 3) || BYTE_ b_PulseEncoderNbr : Pulse encoder selection || (0 to 3) || BYTE_ b_InputLevelSelection : Input level selection || (0 or 1) || 0 : Set pulse encoder|| count the the low|| level pulse. || 1 : Set pulse encoder|| count the the || high level pulse.|| BYTE_ b_TriggerOutputAction : Digital TRIGGER output || action || 0 : No action || 1 : Set the trigger || output to "1" || (high) after the || passage from 1 to|| 0 from pulse || encoder. || 2 : Set the trigger || output to "0" || (low) after the || passage from 1 to|| 0 from pulse || encoder || ULONG_ ul_StartValue : Pulse encoder start value|| (1 to 4294967295) b_ModulNbr =(BYTE) CR_AREF(insn->chanspec); b_PulseEncoderNbr =(BYTE) data[0]; b_InputLevelSelection =(BYTE) data[1]; b_TriggerOutputAction =(BYTE) data[2]; ul_StartValue =(ULONG) data[3]; |+----------------------------------------------------------------------------+| Output Parameters : - |+----------------------------------------------------------------------------+| Return Value : 0: No error || -1: The handle parameter of the board is wrong || -2: The module is not a pulse encoder module || -3: Pulse encoder selection is wrong || -4: Input level selection is wrong || -5: Digital TRIGGER output action selection is wrong || -6: Pulse encoder start value is wrong |+----------------------------------------------------------------------------+*/INT i_APCI1710_InsnConfigInitPulseEncoder(comedi_device *dev,comedi_subdevice *s, comedi_insn *insn,lsampl_t *data) { INT i_ReturnValue = 0; DWORD dw_IntRegister; BYTE b_ModulNbr; BYTE b_PulseEncoderNbr; BYTE b_InputLevelSelection; BYTE b_TriggerOutputAction; ULONG ul_StartValue; b_ModulNbr =(BYTE) CR_AREF(insn->chanspec); b_PulseEncoderNbr =(BYTE) data[0]; b_InputLevelSelection =(BYTE) data[1]; b_TriggerOutputAction =(BYTE) data[2]; ul_StartValue =(ULONG) data[3]; i_ReturnValue =insn->n; /***********************************/ /* Test the selected module number */ /***********************************/ if (b_ModulNbr <= 3) { /*************************/ /* Test if pulse encoder */ /*************************/ if ((devpriv->s_BoardInfos. dw_MolduleConfiguration [b_ModulNbr] & APCI1710_PULSE_ENCODER) == APCI1710_PULSE_ENCODER) { /******************************************/ /* Test the selected pulse encoder number */ /******************************************/ if (b_PulseEncoderNbr <= 3) { /************************/ /* Test the input level */ /************************/ if ((b_InputLevelSelection == 0) || (b_InputLevelSelection == 1)) { /*******************************************/ /* Test the ouput TRIGGER action selection */ /*******************************************/ if ((b_TriggerOutputAction <= 2) || (b_PulseEncoderNbr > 0)) { if (ul_StartValue > 1) { dw_IntRegister= inl(devpriv->s_BoardInfos.ui_Address + 20 + (64 * b_ModulNbr)); /***********************/ /* Set the start value */ /***********************/ outl(ul_StartValue,devpriv->s_BoardInfos.ui_Address + (b_PulseEncoderNbr * 4) + (64 * b_ModulNbr)); /***********************/ /* Set the input level */ /***********************/ devpriv->s_ModuleInfo [b_ModulNbr]. s_PulseEncoderModuleInfo. dw_SetRegister = (devpriv->s_ModuleInfo [b_ModulNbr]. s_PulseEncoderModuleInfo. dw_SetRegister & (0xFFFFFFFFUL - (1UL << (8 + b_PulseEncoderNbr)))) | ((1UL & (~b_InputLevelSelection)) << (8 + b_PulseEncoderNbr)); /*******************************/ /* Test if output trigger used */ /*******************************/ if ((b_TriggerOutputAction > 0) && (b_PulseEncoderNbr > 1)) { /****************************/ /* Enable the output action */ /****************************/ devpriv->s_ModuleInfo [b_ModulNbr]. s_PulseEncoderModuleInfo. dw_SetRegister = devpriv->s_ModuleInfo [b_ModulNbr]. s_PulseEncoderModuleInfo. dw_SetRegister | (1UL << (4 + b_PulseEncoderNbr)); /*********************************/ /* Set the output TRIGGER action */ /*********************************/ devpriv->s_ModuleInfo [b_ModulNbr]. s_PulseEncoderModuleInfo. dw_SetRegister = (devpriv->s_ModuleInfo [b_ModulNbr]. s_PulseEncoderModuleInfo. dw_SetRegister & (0xFFFFFFFFUL - (1UL << (12 + b_PulseEncoderNbr)))) | ((1UL & (b_TriggerOutputAction - 1)) << (12 + b_PulseEncoderNbr)); } else { /*****************************/ /* Disable the output action */ /*****************************/ devpriv->s_ModuleInfo [b_ModulNbr]. s_PulseEncoderModuleInfo. dw_SetRegister = devpriv->s_ModuleInfo [b_ModulNbr]. s_PulseEncoderModuleInfo. dw_SetRegister & (0xFFFFFFFFUL - (1UL << (4 + b_PulseEncoderNbr))); } /*************************/ /* Set the configuration */ /*************************/ outl(devpriv->s_ModuleInfo [b_ModulNbr]. s_PulseEncoderModuleInfo.dw_SetRegister,devpriv->s_BoardInfos. ui_Address + 20 + (64 * b_ModulNbr)); devpriv->s_ModuleInfo [b_ModulNbr]. s_PulseEncoderModuleInfo. s_PulseEncoderInfo [b_PulseEncoderNbr]. b_PulseEncoderInit = 1; } else { /**************************************/ /* Pulse encoder start value is wrong */ /**************************************/ DPRINTK("Pulse encoder start value is wrong\n"); i_ReturnValue = -6; } } else { /****************************************************/ /* Digital TRIGGER output action selection is wrong */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -