?? apci1710_chrono.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 : CHRONO.C | Version : 2.96 | +-------------------------------+---------------------------------------+ | Project manager: Eric Stolz | Date : 02/12/2002 | +-----------------------------------------------------------------------+ | Description : APCI-1710 chronometer module | | | | | +-----------------------------------------------------------------------+ | UPDATES | +-----------------------------------------------------------------------+ | Date | Author | Description of updates | +----------+-----------+------------------------------------------------+ | 29/06/98 | S. Weber | Digital input / output implementation | |----------|-----------|------------------------------------------------| | 08/05/00 | Guinot C | - 0400/0228 All Function in RING 0 | | | | available | +-----------------------------------------------------------------------+ | | | | | | | | +-----------------------------------------------------------------------+*//*+----------------------------------------------------------------------------+| Included files |+----------------------------------------------------------------------------+*/#include "APCI1710_Chrono.h"/*+----------------------------------------------------------------------------+| Function Name : _INT_ i_APCI1710_InitChrono || (BYTE_ b_BoardHandle, || BYTE_ b_ModulNbr, || BYTE_ b_ChronoMode, || BYTE_ b_PCIInputClock, || BYTE_ b_TimingUnit, || ULONG_ ul_TimingInterval, || PULONG_ pul_RealTimingInterval) +----------------------------------------------------------------------------+| Task : Configure the chronometer operating mode (b_ChronoMode)|| from selected module (b_ModulNbr). || The ul_TimingInterval and ul_TimingUnit determine the || timing base for the measurement. || The pul_RealTimingInterval return the real timing || value. You must calling this function be for you call || any other function witch access of the chronometer. || || Witch this functionality from the APCI-1710 you have || the possibility to measure the timing witch two event. || || The mode 0 and 1 is appropriate for period measurement.|| The mode 2 and 3 is appropriate for frequent || measurement. || The mode 4 to 7 is appropriate for measuring the timing|| between two event. |+----------------------------------------------------------------------------+| Input Parameters : BYTE_ b_BoardHandle : Handle of board APCI-1710 || BYTE_ b_ModulNbr CR_AREF(insn->chanspec) : Module number to configure || (0 to 3) || BYTE_ b_ChronoMode data[0] : Chronometer action mode || (0 to 7). || BYTE_ b_PCIInputClock data[1] : Selection from PCI bus clock|| - APCI1710_30MHZ : || The PC have a PCI bus || clock from 30 MHz || - APCI1710_33MHZ : || The PC have a PCI bus || clock from 33 MHz || - APCI1710_40MHZ || The APCI-1710 have a || integrated 40Mhz || quartz. || BYTE_ b_TimingUnit data[2] : Base timing unity (0 to 4) || 0 : ns || 1 : μs || 2 : ms || 3 : s || 4 : mn || ULONG_ ul_TimingInterval : data[3] Base timing value. |+----------------------------------------------------------------------------+| Output Parameters : PULONG_ pul_RealTimingInterval : Real base timing || value. | data[0]+----------------------------------------------------------------------------+| Return Value : 0: No error || -1: The handle parameter of the board is wrong || -2: Module selection wrong || -3: The module is not a Chronometer module || -4: Chronometer mode selection is wrong || -5: The selected PCI input clock is wrong || -6: Timing unity selection is wrong || -7: Base timing selection is wrong || -8: You can not used the 40MHz clock selection wich || this board || -9: You can not used the 40MHz clock selection wich || this CHRONOS version |+----------------------------------------------------------------------------+*/INT i_APCI1710_InsnConfigInitChrono(comedi_device *dev,comedi_subdevice *s, comedi_insn *insn,lsampl_t *data) { INT i_ReturnValue = 0; ULONG ul_TimerValue = 0; ULONG ul_TimingInterval = 0; ULONG ul_RealTimingInterval = 0; double d_RealTimingInterval = 0; DWORD dw_ModeArray [8] = {0x01, 0x05, 0x00, 0x04, 0x02, 0x0E, 0x0A, 0x06}; BYTE b_ModulNbr,b_ChronoMode,b_PCIInputClock,b_TimingUnit; b_ModulNbr = CR_AREF(insn->chanspec); b_ChronoMode = (BYTE) data[0]; b_PCIInputClock = (BYTE) data[1]; b_TimingUnit = (BYTE) data[2]; ul_TimingInterval = (ULONG) data[3]; i_ReturnValue = insn->n; /**************************/ /* Test the module number */ /**************************/ if (b_ModulNbr < 4) { /***********************/ /* Test if chronometer */ /***********************/ if ((devpriv->s_BoardInfos. dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_CHRONOMETER) { /*****************************/ /* Test the chronometer mode */ /*****************************/ if (b_ChronoMode <= 7) { /**************************/ /* Test the PCI bus clock */ /**************************/ if ((b_PCIInputClock == APCI1710_30MHZ) || (b_PCIInputClock == APCI1710_33MHZ) || (b_PCIInputClock == APCI1710_40MHZ)) { /*************************/ /* Test the timing unity */ /*************************/ if (b_TimingUnit <= 4) { /**********************************/ /* Test the base timing selection */ /**********************************/ if (((b_PCIInputClock == APCI1710_30MHZ) && (b_TimingUnit == 0) && (ul_TimingInterval >= 66) && (ul_TimingInterval <= 0xFFFFFFFFUL)) || ((b_PCIInputClock == APCI1710_30MHZ) && (b_TimingUnit == 1) && (ul_TimingInterval >= 1) && (ul_TimingInterval <= 143165576UL)) || ((b_PCIInputClock == APCI1710_30MHZ) && (b_TimingUnit == 2) && (ul_TimingInterval >= 1) && (ul_TimingInterval <= 143165UL)) || ((b_PCIInputClock == APCI1710_30MHZ) && (b_TimingUnit == 3) && (ul_TimingInterval >= 1) && (ul_TimingInterval <= 143UL)) || ((b_PCIInputClock == APCI1710_30MHZ) && (b_TimingUnit == 4) && (ul_TimingInterval >= 1) && (ul_TimingInterval <= 2UL)) || ((b_PCIInputClock == APCI1710_33MHZ) && (b_TimingUnit == 0) && (ul_TimingInterval >= 60) && (ul_TimingInterval <= 0xFFFFFFFFUL)) || ((b_PCIInputClock == APCI1710_33MHZ) && (b_TimingUnit == 1) && (ul_TimingInterval >= 1) && (ul_TimingInterval <= 130150240UL)) || ((b_PCIInputClock == APCI1710_33MHZ) && (b_TimingUnit == 2) && (ul_TimingInterval >= 1) && (ul_TimingInterval <= 130150UL)) || ((b_PCIInputClock == APCI1710_33MHZ) && (b_TimingUnit == 3) && (ul_TimingInterval >= 1) && (ul_TimingInterval <= 130UL)) || ((b_PCIInputClock == APCI1710_33MHZ) && (b_TimingUnit == 4) && (ul_TimingInterval >= 1) && (ul_TimingInterval <= 2UL)) || ((b_PCIInputClock == APCI1710_40MHZ) && (b_TimingUnit == 0) && (ul_TimingInterval >= 50) && (ul_TimingInterval <= 0xFFFFFFFFUL)) || ((b_PCIInputClock == APCI1710_40MHZ) && (b_TimingUnit == 1) && (ul_TimingInterval >= 1) && (ul_TimingInterval <= 107374182UL)) || ((b_PCIInputClock == APCI1710_40MHZ) && (b_TimingUnit == 2) && (ul_TimingInterval >= 1) && (ul_TimingInterval <= 107374UL)) || ((b_PCIInputClock == APCI1710_40MHZ) && (b_TimingUnit == 3) && (ul_TimingInterval >= 1) && (ul_TimingInterval <= 107UL)) || ((b_PCIInputClock == APCI1710_40MHZ) && (b_TimingUnit == 4) && (ul_TimingInterval >= 1) && (ul_TimingInterval <= 1UL))) { /**************************/ /* Test the board version */ /**************************/ if (((b_PCIInputClock == APCI1710_40MHZ) && (devpriv->s_BoardInfos. b_BoardVersion > 0)) || (b_PCIInputClock != APCI1710_40MHZ)) { /************************/ /* Test the TOR version */ /************************/ if (((b_PCIInputClock == APCI1710_40MHZ) && ((devpriv->s_BoardInfos. dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) >= 0x3131)) || (b_PCIInputClock != APCI1710_40MHZ)) { fpu_begin (); /****************************************/ /* Calculate the timer 0 division fator */ /****************************************/ switch (b_TimingUnit) { /******/ /* ns */ /******/ case 0: /******************/ /* Timer 0 factor */ /******************/ ul_TimerValue = (ULONG) (ul_TimingInterval * (0.001 * b_PCIInputClock)); /*******************/ /* Round the value */ /*******************/ if ((double) ((double) ul_TimingInterval * (0.001 * (double) b_PCIInputClock)) >= ((double) ((double) ul_TimerValue + 0.5))) { ul_TimerValue = ul_TimerValue + 1; } /*****************************/ /* Calculate the real timing */ /*****************************/ ul_RealTimingInterval = (ULONG) (ul_TimerValue / (0.001 * (double) b_PCIInputClock)); d_RealTimingInterval = (double) ul_TimerValue / (0.001 * (double) b_PCIInputClock); if ((double) ((double) ul_TimerValue / (0.001 * (double) b_PCIInputClock)) >= (double) ((double) ul_RealTimingInterval + 0.5)) { ul_RealTimingInterval = ul_RealTimingInterval + 1; } ul_TimingInterval = ul_TimingInterval - 1; ul_TimerValue = ul_TimerValue - 2; if (b_PCIInputClock != APCI1710_40MHZ) { ul_TimerValue = (ULONG) ((double) (ul_TimerValue) * 0.99392); } break; /******/ /* ?s */ /******/ case 1: /******************/ /* Timer 0 factor */ /******************/ ul_TimerValue = (ULONG) (ul_TimingInterval * (1.0 * b_PCIInputClock)); /*******************/ /* Round the value */ /*******************/ if ((double) ((double) ul_TimingInterval * (1.0 * (double) b_PCIInputClock)) >= ((double) ((double) ul_TimerValue + 0.5))) { ul_TimerValue = ul_TimerValue + 1; } /*****************************/ /* Calculate the real timing */ /*****************************/ ul_RealTimingInterval = (ULONG) (ul_TimerValue / (1.0 * (double) b_PCIInputClock)); d_RealTimingInterval = (double) ul_TimerValue / ((double) 1.0 * (double) b_PCIInputClock); if ((double) ((double) ul_TimerValue / (1.0 * (double) b_PCIInputClock)) >= (double) ((double) ul_RealTimingInterval + 0.5)) { ul_RealTimingInterval = ul_RealTimingInterval + 1; } ul_TimingInterval = ul_TimingInterval - 1; ul_TimerValue = ul_TimerValue - 2; if (b_PCIInputClock != APCI1710_40MHZ) { ul_TimerValue = (ULONG) ((double) (ul_TimerValue) * 0.99392); } break; /******/ /* ms */ /******/ case 2: /******************/ /* Timer 0 factor */ /******************/ ul_TimerValue = ul_TimingInterval * (1000 * b_PCIInputClock); /*******************/ /* Round the value */ /*******************/ if ((double) ((double) ul_TimingInterval * (1000.0 * (double) b_PCIInputClock)) >= ((double) ((double) ul_TimerValue + 0.5))) { ul_TimerValue = ul_TimerValue + 1; } /*****************************/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -