⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 apci1710_tor.c

📁 最新版comedi的源码
💻 C
📖 第 1 页 / 共 5 页
字号:
/**@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 : TOR.C           | Version  : 2.96                       |  +-------------------------------+---------------------------------------+  | Project manager: Eric Stolz   | Date     :  02/12/2002                |  +-----------------------------------------------------------------------+  | Description :   APCI-1710 tor counter module                          |  |                                                                       |  |                                                                       |  +-----------------------------------------------------------------------+  |                             UPDATES                                   |  +-----------------------------------------------------------------------+  |   Date   |   Author  |          Description of updates                |  +----------+-----------+------------------------------------------------+  | 27/01/99 | S. Weber  | 40 MHz implementation                          |  +-----------------------------------------------------------------------+  | 28/04/00 | S. Weber  | Simple,double and quadruple mode implementation|  |          |           | Extern clock implementation                    |  +-----------------------------------------------------------------------+  | 08/05/00 | Guinot C  | - 0400/0228 All Function in RING 0             |  |          |           |   available                                    |  +-----------------------------------------------------------------------+*//*+----------------------------------------------------------------------------+|                               Included files                               |+----------------------------------------------------------------------------+*/#include "APCI1710_Tor.h"/*+----------------------------------------------------------------------------+| Function Name     : _INT_     i_APCI1710_InitTorCounter                    ||                                       (BYTE_     b_BoardHandle,            ||                                        BYTE_     b_ModulNbr,               ||                                        BYTE_     b_TorCounter,             ||                                        BYTE_     b_PCIInputClock,          ||                                        BYTE_     b_TimingUnit,             ||                                        ULONG_   ul_TimingInterval,         ||                                        PULONG_ pul_RealTimingInterval)     |+----------------------------------------------------------------------------+| Task              : Configure the selected tor counter (b_TorCounter)      ||                     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 tor counter.    ||                                                                            |+----------------------------------------------------------------------------+| Input Parameters  :    ||                     		CR_AREF	BYTE_   b_ModulNbr       : Module number to configure  ||                                                (0 to 3)                    ||           data[0] BYTE_   b_TorCounter     : Tor counter selection       ||                                                (0 or 1).                   ||           data[1] BYTE_   b_PCIInputClock  : 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.                   ||                                                - APCI1710_GATE_INPUT       ||                                                  Used the gate input for   ||						   the base clock. If you    ||						   have selected this option,||						   than it is not possibl to ||						   used the gate input for   ||						   enabled the acquisition   ||           data[2] BYTE_   b_TimingUnit    : Base timing unit (0 to 4)    ||                                                 0 : ns                     ||                                                 1 : µs                     ||                                                 2 : ms                     ||                                                 3 : s                      ||                                                 4 : mn                     ||           data[3]          ULONG_ ul_TimingInterval : Base timing value.          |+----------------------------------------------------------------------------+| Output Parameters : PULONG_  pul_RealTimingInterval : Real  base timing    ||                     data[0]                                  value.               |+----------------------------------------------------------------------------+| Return Value      :  0: No error                                           ||                     -1: The handle parameter of the board is wrong         ||                     -2: Module selection wrong                             ||                     -3: The module is not a tor counter module             ||                     -4: Tor counter selection is wrong                     ||                     -5: The selected PCI input clock is wrong              ||                     -6: Timing unit 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 TOR version                                   |+----------------------------------------------------------------------------+*/INT   i_APCI1710_InsnConfigInitTorCounter(comedi_device *dev,comedi_subdevice *s,	comedi_insn *insn,lsampl_t *data)	{	INT    i_ReturnValue = 0;	ULONG ul_TimerValue  = 0;	DWORD dw_Command;	double d_RealTimingInterval = 0;	BYTE     b_ModulNbr;	BYTE     b_TorCounter;	BYTE     b_PCIInputClock;	BYTE     b_TimingUnit;	ULONG    ul_TimingInterval;	ULONG   ul_RealTimingInterval = 0;	i_ReturnValue			=   insn->n;	b_ModulNbr				=   (BYTE)  CR_AREF(insn->chanspec);	b_TorCounter			=	(BYTE)  data[0];	b_PCIInputClock			= 	(BYTE)  data[1];	b_TimingUnit			=	(BYTE)  data[2];	ul_TimingInterval		=	(ULONG) data[3];	printk("INPUT clock %d\n",b_PCIInputClock);			/**************************/		/* Test the module number */		/**************************/	if (b_ModulNbr < 4)	   {		/***********************/		/* Test if tor counter */		/***********************/	   if ((devpriv->s_BoardInfos.		dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_TOR_COUNTER)	      {	      /**********************************/	      /* Test the tor counter selection */	      /**********************************/	      if (b_TorCounter <= 1)		 {		 /**************************/		 /* Test the PCI bus clock */		 /**************************/		 if ((b_PCIInputClock == APCI1710_30MHZ) ||		     (b_PCIInputClock == APCI1710_33MHZ) ||		     (b_PCIInputClock == APCI1710_40MHZ) ||		     (b_PCIInputClock == APCI1710_GATE_INPUT))		    {		    /************************/		    /* Test the timing unit */		    /************************/		    if ((b_TimingUnit <= 4) || (b_PCIInputClock == APCI1710_GATE_INPUT))		       {		       /**********************************/		       /* Test the base timing selection */		       /**********************************/		       if(((b_PCIInputClock == APCI1710_30MHZ)   && (b_TimingUnit == 0) && (ul_TimingInterval >= 133) && (ul_TimingInterval <= 0xFFFFFFFFUL)) ||			   ((b_PCIInputClock == APCI1710_30MHZ)      && (b_TimingUnit == 1) && (ul_TimingInterval >= 1)   && (ul_TimingInterval <= 571230650UL))  ||			   ((b_PCIInputClock == APCI1710_30MHZ)      && (b_TimingUnit == 2) && (ul_TimingInterval >= 1)   && (ul_TimingInterval <= 571230UL))     ||			   ((b_PCIInputClock == APCI1710_30MHZ)      && (b_TimingUnit == 3) && (ul_TimingInterval >= 1)   && (ul_TimingInterval <= 571UL))        ||			   ((b_PCIInputClock == APCI1710_30MHZ)      && (b_TimingUnit == 4) && (ul_TimingInterval >= 1)   && (ul_TimingInterval <= 9UL))          ||			   ((b_PCIInputClock == APCI1710_33MHZ)      && (b_TimingUnit == 0) && (ul_TimingInterval >= 121) && (ul_TimingInterval <= 0xFFFFFFFFUL)) ||			   ((b_PCIInputClock == APCI1710_33MHZ)      && (b_TimingUnit == 1) && (ul_TimingInterval >= 1)   && (ul_TimingInterval <= 519691043UL))  ||			   ((b_PCIInputClock == APCI1710_33MHZ)      && (b_TimingUnit == 2) && (ul_TimingInterval >= 1)   && (ul_TimingInterval <= 519691UL))     ||			   ((b_PCIInputClock == APCI1710_33MHZ)      && (b_TimingUnit == 3) && (ul_TimingInterval >= 1)   && (ul_TimingInterval <= 520UL))        ||			   ((b_PCIInputClock == APCI1710_33MHZ)      && (b_TimingUnit == 4) && (ul_TimingInterval >= 1)   && (ul_TimingInterval <= 8UL))          ||			   ((b_PCIInputClock == APCI1710_40MHZ)      && (b_TimingUnit == 0) && (ul_TimingInterval >= 100) && (ul_TimingInterval <= 0xFFFFFFFFUL)) ||			   ((b_PCIInputClock == APCI1710_40MHZ)      && (b_TimingUnit == 1) && (ul_TimingInterval >= 1)   && (ul_TimingInterval <= 429496729UL))  ||			   ((b_PCIInputClock == APCI1710_40MHZ)      && (b_TimingUnit == 2) && (ul_TimingInterval >= 1)   && (ul_TimingInterval <= 429496UL))     ||			   ((b_PCIInputClock == APCI1710_40MHZ)      && (b_TimingUnit == 3) && (ul_TimingInterval >= 1)   && (ul_TimingInterval <= 429UL))        ||			   ((b_PCIInputClock == APCI1710_40MHZ)      && (b_TimingUnit == 4) && (ul_TimingInterval >= 1)   && (ul_TimingInterval <= 7UL))          ||			   ((b_PCIInputClock == APCI1710_GATE_INPUT) && (ul_TimingInterval >= 2)))			  {				/**************************/				/* 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_GATE_INPUT) && ((devpriv->s_BoardInfos.									       dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) >= 0x3132)) ||				 (b_PCIInputClock == APCI1710_30MHZ) ||				 (b_PCIInputClock == APCI1710_33MHZ))				{				/*********************************/				/* Test if not extern clock used */				/*********************************/				if (b_PCIInputClock != APCI1710_GATE_INPUT)				   {				   fpu_begin ();				   /****************************************/				   /* Calculate the timer 0 division fator */				   /****************************************/				   switch (b_TimingUnit)				      {				      /******/				      /* ns */				      /******/				      case 0:					   					      /******************/					      /* Timer 0 factor */					      /******************/					      ul_TimerValue = (ULONG) (ul_TimingInterval * (0.00025 * b_PCIInputClock));					      /*******************/					      /* Round the value */					      /*******************/					      if ((double) ((double) ul_TimingInterval * (0.00025 * (double) b_PCIInputClock)) >= ((double) ((double) ul_TimerValue + 0.5)))						 {						 ul_TimerValue = ul_TimerValue + 1;						 }					      /*****************************/					      /* Calculate the real timing */					      /*****************************/					      ul_RealTimingInterval = (ULONG) (ul_TimerValue / (0.00025 * (double) b_PCIInputClock));					      d_RealTimingInterval = (double) ul_TimerValue / (0.00025 * (double) b_PCIInputClock);					      if ((double) ((double) ul_TimerValue / (0.00025 * (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) * 1.007752288);						 }					   					   break;				      /******/				      /* æs */				      /******/				      case 1:					   					      /******************/					      /* Timer 0 factor */					      /******************/					      ul_TimerValue = (ULONG) (ul_TimingInterval * (0.25 * b_PCIInputClock));					      /*******************/					      /* Round the value */					      /*******************/					      if ((double) ((double) ul_TimingInterval * (0.25 * (double) b_PCIInputClock)) >= ((double) ((double) ul_TimerValue + 0.5)))						 {						 ul_TimerValue = ul_TimerValue + 1;						 }					      /*****************************/					      /* Calculate the real timing */					      /*****************************/					      ul_RealTimingInterval = (ULONG) (ul_TimerValue / (0.25 * (double) b_PCIInputClock));					      d_RealTimingInterval = (double) ul_TimerValue / ((double) 0.25 * (double) b_PCIInputClock);					     if ((double) ((double) ul_TimerValue / (0.25 * (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) * 1.007752288);						 }					   					   break;				      /******/				      /* ms */				      /******/				      case 2:					   					      /******************/					      /* Timer 0 factor */					      /******************/					      ul_TimerValue = ul_TimingInterval * (250.0 * b_PCIInputClock);					      /*******************/					      /* Round the value */					      /*******************/					      if ((double) ((double) ul_TimingInterval * (250.0 * (double) b_PCIInputClock)) >= ((double) ((double) ul_TimerValue + 0.5)))						 {						 ul_TimerValue = ul_TimerValue + 1;						 }					      /*****************************/					      /* Calculate the real timing */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -