Convert from DOS to unix. Convert to UTF-8. Minor warning fixes.
authorDavid Schleef <ds@schleef.org>
Fri, 7 Oct 2005 05:06:33 +0000 (05:06 +0000)
committerDavid Schleef <ds@schleef.org>
Fri, 7 Oct 2005 05:06:33 +0000 (05:06 +0000)
42 files changed:
comedi/drivers/addi-data/APCI1710_82x54.c
comedi/drivers/addi-data/APCI1710_Chrono.c
comedi/drivers/addi-data/APCI1710_Chrono.h
comedi/drivers/addi-data/APCI1710_Dig_io.c
comedi/drivers/addi-data/APCI1710_Dig_io.h
comedi/drivers/addi-data/APCI1710_INCCPT.c
comedi/drivers/addi-data/APCI1710_INCCPT.h
comedi/drivers/addi-data/APCI1710_Inp_cpt.c
comedi/drivers/addi-data/APCI1710_Inp_cpt.h
comedi/drivers/addi-data/APCI1710_Pwm.c
comedi/drivers/addi-data/APCI1710_Pwm.h
comedi/drivers/addi-data/APCI1710_Ssi.c
comedi/drivers/addi-data/APCI1710_Ssi.h
comedi/drivers/addi-data/APCI1710_Tor.c
comedi/drivers/addi-data/APCI1710_Tor.h
comedi/drivers/addi-data/APCI1710_Ttl.c
comedi/drivers/addi-data/APCI1710_Ttl.h
comedi/drivers/addi-data/addi_amcc_S5920.c
comedi/drivers/addi-data/addi_amcc_S5920.h
comedi/drivers/addi-data/addi_common.c
comedi/drivers/addi-data/addi_eeprom.c
comedi/drivers/addi-data/hwdrv_APCI1710.c
comedi/drivers/addi-data/hwdrv_APCI1710.h
comedi/drivers/addi-data/hwdrv_apci035.c
comedi/drivers/addi-data/hwdrv_apci035.h
comedi/drivers/addi-data/hwdrv_apci1032.c
comedi/drivers/addi-data/hwdrv_apci1500.c
comedi/drivers/addi-data/hwdrv_apci1516.c
comedi/drivers/addi-data/hwdrv_apci1516.h
comedi/drivers/addi-data/hwdrv_apci1564.c
comedi/drivers/addi-data/hwdrv_apci1564.h
comedi/drivers/addi-data/hwdrv_apci16xx.c
comedi/drivers/addi-data/hwdrv_apci16xx.h
comedi/drivers/addi-data/hwdrv_apci2016.c
comedi/drivers/addi-data/hwdrv_apci2016.h
comedi/drivers/addi-data/hwdrv_apci2032.c
comedi/drivers/addi-data/hwdrv_apci2032.h
comedi/drivers/addi-data/hwdrv_apci2200.c
comedi/drivers/addi-data/hwdrv_apci3200.c
comedi/drivers/addi-data/hwdrv_apci3200.h
comedi/drivers/addi-data/hwdrv_apci3501.c
comedi/drivers/addi-data/hwdrv_apci3xxx.h

index bf0137833e055df0dbbd0a82af6ed9c3d76667a6..7d1f04dae348d1de2d2041b7b2c22d9633bc19ac 100644 (file)
@@ -24,7 +24,7 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc
 /*
     
   +-----------------------------------------------------------------------+
-  | (C) ADDI-DATA GmbH          Dieselstraße 3       D-77833 Ottersweier  |
+  | (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   |
index da805ae8819ca712673df099a73bef6811d94260..89916fad28207cf34110ec30ee32c2c4bcba2fc0 100644 (file)
-/**\r
-@verbatim\r
-\r
-Copyright (C) 2004,2005  ADDI-DATA GmbH for the source code of this module. \r
-        \r
-        ADDI-DATA GmbH \r
-        Dieselstrasse 3 \r
-        D-77833 Ottersweier \r
-        Tel: +19(0)7223/9493-0 \r
-        Fax: +49(0)7223/9493-92 \r
-        http://www.addi-data-com \r
-        info@addi-data.com \r
-\r
-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.\r
-\r
-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.\r
-\r
-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 USA\r
-\r
-You shoud also find the complete GPL in the COPYING file accompanying this source code.\r
-\r
-@endverbatim\r
-*/\r
-/*\r
-    \r
-  +-----------------------------------------------------------------------+\r
-  | (C) ADDI-DATA GmbH          Dieselstraße 3       D-77833 Ottersweier  |\r
-  +-----------------------------------------------------------------------+\r
-  | Tel : +49 (0) 7223/9493-0     | email    : info@addi-data.com         |\r
-  | Fax : +49 (0) 7223/9493-92    | Internet : http://www.addi-data.com   |\r
-  +-----------------------------------------------------------------------+\r
-  | Project     : API APCI1710    | Compiler : gcc                        |\r
-  | Module name : CHRONO.C        | Version  : 2.96                       |\r
-  +-------------------------------+---------------------------------------+\r
-  | Project manager: Eric Stolz   | Date     :  02/12/2002                |\r
-  +-----------------------------------------------------------------------+\r
-  | Description :   APCI-1710 chronometer module                          |\r
-  |                                                                       |\r
-  |                                                                       |\r
-  +-----------------------------------------------------------------------+\r
-  |                             UPDATES                                   |\r
-  +-----------------------------------------------------------------------+\r
-  |   Date   |   Author  |          Description of updates                |\r
-  +----------+-----------+------------------------------------------------+\r
-  | 29/06/98 | S. Weber  | Digital input / output implementation          |\r
-  |----------|-----------|------------------------------------------------|\r
-  | 08/05/00 | Guinot C  | - 0400/0228 All Function in RING 0             |\r
-  |          |           |   available                                    |\r
-  +-----------------------------------------------------------------------+\r
-  |          |           |                                                |\r
-  |          |           |                                                |\r
-  +-----------------------------------------------------------------------+\r
-*/\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-|                               Included files                               |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-#include "APCI1710_Chrono.h"\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : _INT_     i_APCI1710_InitChrono                        |\r
-|                                       (BYTE_     b_BoardHandle,            |\r
-|                                        BYTE_     b_ModulNbr,               |\r
-|                                        BYTE_     b_ChronoMode,             |\r
-|                                        BYTE_     b_PCIInputClock,          |\r
-|                                        BYTE_     b_TimingUnit,             |\r
-|                                        ULONG_   ul_TimingInterval,         |\r
-|                                        PULONG_ pul_RealTimingInterval) \r
-\r
-+----------------------------------------------------------------------------+\r
-| Task              : Configure the chronometer operating mode (b_ChronoMode)|\r
-|                     from selected module (b_ModulNbr).                     |\r
-|                     The ul_TimingInterval and ul_TimingUnit determine the  |\r
-|                     timing base for the measurement.                       |\r
-|                     The pul_RealTimingInterval return the real timing      |\r
-|                     value. You must calling this function be for you call  |\r
-|                     any other function witch access of the chronometer.    |\r
-|                                                                            |\r
-|                     Witch this functionality from the APCI-1710 you have   |\r
-|                     the possibility to measure the timing witch two event. |\r
-|                                                                            |\r
-|                     The mode 0 and 1 is appropriate for period measurement.|\r
-|                     The mode 2 and 3 is appropriate for frequent           |\r
-|                     measurement.                                           |\r
-|                     The mode 4 to 7 is appropriate for measuring the timing|\r
-|                     between  two event.                                    |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : BYTE_   b_BoardHandle    : Handle of board APCI-1710   |\r
-| BYTE_   b_ModulNbr  CR_AREF(insn->chanspec)  : Module number to configure  |\r
-|                                                (0 to 3)                    |\r
-| BYTE_   b_ChronoMode                         data[0]    : Chronometer action mode     |\r
-|                                                (0 to 7).                   |\r
-| BYTE_   b_PCIInputClock                      data[1] : Selection from PCI bus clock|\r
-|                                                - APCI1710_30MHZ :          |\r
-|                                                  The PC have a PCI bus     |\r
-|                                                  clock from 30 MHz         |\r
-|                                                - APCI1710_33MHZ :          |\r
-|                                                  The PC have a PCI bus     |\r
-|                                                  clock from 33 MHz         |\r
-|                                                - APCI1710_40MHZ            |\r
-|                                                  The APCI-1710 have a      |\r
-|                                                  integrated 40Mhz          |\r
-|                                                  quartz.                   |\r
-|               BYTE_   b_TimingUnit   data[2]    : Base timing unity (0 to 4) |\r
-|                                                 0 : ns                     |\r
-|                                                 1 : µs                     |\r
-|                                                 2 : ms                     |\r
-|                                                 3 : s                      |\r
-|                                                 4 : mn                     |\r
-|         ULONG_ ul_TimingInterval : data[3]    Base timing value.          |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : PULONG_  pul_RealTimingInterval : Real  base timing    |\r
-|                                                       value.               \r
-|                     data[0]\r
-+----------------------------------------------------------------------------+\r
-| Return Value      :  0: No error                                           |\r
-|                     -1: The handle parameter of the board is wrong         |\r
-|                     -2: Module selection wrong                             |\r
-|                     -3: The module is not a Chronometer module             |\r
-|                     -4: Chronometer mode selection is wrong                |\r
-|                     -5: The selected PCI input clock is wrong              |\r
-|                     -6: Timing unity selection is wrong                    |\r
-|                     -7: Base timing selection is wrong                     |\r
-|                     -8: You can not used the 40MHz clock selection wich    |\r
-|                         this board                                         |\r
-|                     -9: You can not used the 40MHz clock selection wich    |\r
-|                         this CHRONOS version                               |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-\r
-\r
-INT i_APCI1710_InsnConfigInitChrono(comedi_device *dev,comedi_subdevice *s,\r
-       comedi_insn *insn,lsampl_t *data)\r
-       {\r
-       INT    i_ReturnValue        = 0;\r
-       ULONG ul_TimerValue         = 0;\r
-       ULONG ul_TimingInterval     = 0;\r
-       ULONG ul_RealTimingInterval = 0;\r
-       double d_RealTimingInterval = 0;\r
-       DWORD dw_ModeArray [8] = {0x01, 0x05, 0x00, 0x04, 0x02, 0x0E, 0x0A, 0x06};\r
-       BYTE   b_ModulNbr,b_ChronoMode,b_PCIInputClock,b_TimingUnit;\r
-\r
-       b_ModulNbr        = CR_AREF(insn->chanspec);\r
-       b_ChronoMode      = (BYTE)  data[0];\r
-       b_PCIInputClock   = (BYTE)  data[1];\r
-       b_TimingUnit      = (BYTE)  data[2];\r
-       ul_TimingInterval =     (ULONG) data[3];  \r
-       i_ReturnValue     =  insn->n;\r
-\r
-       /**************************/\r
-       /* Test the module number */\r
-       /**************************/\r
-\r
-       if (b_ModulNbr < 4)\r
-          {\r
-          /***********************/\r
-          /* Test if chronometer */\r
-          /***********************/\r
-\r
-          if ((devpriv->s_BoardInfos.\r
-               dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_CHRONOMETER)\r
-             {\r
-             /*****************************/\r
-             /* Test the chronometer mode */\r
-             /*****************************/\r
-\r
-             if (b_ChronoMode <= 7)\r
-                {\r
-                /**************************/\r
-                /* Test the PCI bus clock */\r
-                /**************************/\r
-\r
-                if ((b_PCIInputClock == APCI1710_30MHZ) ||\r
-                    (b_PCIInputClock == APCI1710_33MHZ) ||\r
-                    (b_PCIInputClock == APCI1710_40MHZ))\r
-                   {\r
-                   /*************************/\r
-                   /* Test the timing unity */\r
-                   /*************************/\r
-\r
-                   if (b_TimingUnit <= 4)\r
-                      {\r
-                      /**********************************/\r
-                      /* Test the base timing selection */\r
-                      /**********************************/\r
-\r
-                      if (((b_PCIInputClock == APCI1710_30MHZ) && (b_TimingUnit == 0) && (ul_TimingInterval >= 66) && (ul_TimingInterval <= 0xFFFFFFFFUL)) ||\r
-                          ((b_PCIInputClock == APCI1710_30MHZ) && (b_TimingUnit == 1) && (ul_TimingInterval >= 1)  && (ul_TimingInterval <= 143165576UL))  ||\r
-                          ((b_PCIInputClock == APCI1710_30MHZ) && (b_TimingUnit == 2) && (ul_TimingInterval >= 1)  && (ul_TimingInterval <= 143165UL))     ||\r
-                          ((b_PCIInputClock == APCI1710_30MHZ) && (b_TimingUnit == 3) && (ul_TimingInterval >= 1)  && (ul_TimingInterval <= 143UL))        ||\r
-                          ((b_PCIInputClock == APCI1710_30MHZ) && (b_TimingUnit == 4) && (ul_TimingInterval >= 1)  && (ul_TimingInterval <= 2UL))          ||\r
-                          ((b_PCIInputClock == APCI1710_33MHZ) && (b_TimingUnit == 0) && (ul_TimingInterval >= 60) && (ul_TimingInterval <= 0xFFFFFFFFUL)) ||\r
-                          ((b_PCIInputClock == APCI1710_33MHZ) && (b_TimingUnit == 1) && (ul_TimingInterval >= 1)  && (ul_TimingInterval <= 130150240UL))  ||\r
-                          ((b_PCIInputClock == APCI1710_33MHZ) && (b_TimingUnit == 2) && (ul_TimingInterval >= 1)  && (ul_TimingInterval <= 130150UL))     ||\r
-                          ((b_PCIInputClock == APCI1710_33MHZ) && (b_TimingUnit == 3) && (ul_TimingInterval >= 1)  && (ul_TimingInterval <= 130UL))        ||\r
-                          ((b_PCIInputClock == APCI1710_33MHZ) && (b_TimingUnit == 4) && (ul_TimingInterval >= 1)  && (ul_TimingInterval <= 2UL))          ||\r
-                          ((b_PCIInputClock == APCI1710_40MHZ) && (b_TimingUnit == 0) && (ul_TimingInterval >= 50) && (ul_TimingInterval <= 0xFFFFFFFFUL)) ||\r
-                          ((b_PCIInputClock == APCI1710_40MHZ) && (b_TimingUnit == 1) && (ul_TimingInterval >= 1)  && (ul_TimingInterval <= 107374182UL))  ||\r
-                          ((b_PCIInputClock == APCI1710_40MHZ) && (b_TimingUnit == 2) && (ul_TimingInterval >= 1)  && (ul_TimingInterval <= 107374UL))     ||\r
-                          ((b_PCIInputClock == APCI1710_40MHZ) && (b_TimingUnit == 3) && (ul_TimingInterval >= 1)  && (ul_TimingInterval <= 107UL))        ||\r
-                          ((b_PCIInputClock == APCI1710_40MHZ) && (b_TimingUnit == 4) && (ul_TimingInterval >= 1)  && (ul_TimingInterval <= 1UL)))\r
-                         {\r
-                         /**************************/\r
-                         /* Test the board version */\r
-                         /**************************/\r
-\r
-                         if (((b_PCIInputClock == APCI1710_40MHZ) && (devpriv->s_BoardInfos.\r
-                                                                     b_BoardVersion > 0)) ||\r
-                             (b_PCIInputClock != APCI1710_40MHZ))\r
-                            {\r
-                            /************************/\r
-                            /* Test the TOR version */\r
-                            /************************/\r
-\r
-                            if (((b_PCIInputClock == APCI1710_40MHZ) && ((devpriv->s_BoardInfos.\r
-                                                                         dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) >= 0x3131)) ||\r
-                                (b_PCIInputClock != APCI1710_40MHZ))\r
-                               {\r
-                               fpu_begin ();\r
-                               \r
-                               /****************************************/\r
-                               /* Calculate the timer 0 division fator */\r
-                               /****************************************/\r
-\r
-                               switch (b_TimingUnit)\r
-                                  {\r
-                                  /******/\r
-                                  /* ns */\r
-                                  /******/\r
-\r
-                                  case 0:\r
-                                       \r
-                                          /******************/\r
-                                          /* Timer 0 factor */\r
-                                          /******************/\r
-\r
-                                          ul_TimerValue = (ULONG) (ul_TimingInterval * (0.001 * b_PCIInputClock));\r
-\r
-                                          /*******************/\r
-                                          /* Round the value */\r
-                                          /*******************/\r
-\r
-                                          if ((double) ((double) ul_TimingInterval * (0.001 * (double) b_PCIInputClock)) >= ((double) ((double) ul_TimerValue + 0.5)))\r
-                                             {\r
-                                             ul_TimerValue = ul_TimerValue + 1;\r
-                                             }\r
-\r
-                                          /*****************************/\r
-                                          /* Calculate the real timing */\r
-                                          /*****************************/\r
-\r
-                                          ul_RealTimingInterval = (ULONG) (ul_TimerValue / (0.001 * (double) b_PCIInputClock));\r
-                                          d_RealTimingInterval = (double) ul_TimerValue / (0.001 * (double) b_PCIInputClock);\r
-\r
-                                          if ((double) ((double) ul_TimerValue / (0.001 * (double) b_PCIInputClock)) >= (double) ((double) ul_RealTimingInterval + 0.5))\r
-                                             {\r
-                                             ul_RealTimingInterval = ul_RealTimingInterval + 1;\r
-                                             }\r
-\r
-                                          ul_TimingInterval = ul_TimingInterval - 1;\r
-                                          ul_TimerValue     = ul_TimerValue - 2;\r
-                                          if (b_PCIInputClock != APCI1710_40MHZ)\r
-                                             {\r
-                                             ul_TimerValue     = (ULONG) ((double) (ul_TimerValue) * 0.99392);\r
-                                             }\r
-                               \r
-                                       break;\r
-\r
-                                  /******/\r
-                                  /* æs */\r
-                                  /******/\r
-\r
-                                  case 1:\r
-                                       \r
-                                          /******************/\r
-                                          /* Timer 0 factor */\r
-                                          /******************/\r
-\r
-                                          ul_TimerValue = (ULONG) (ul_TimingInterval * (1.0 * b_PCIInputClock));\r
-\r
-                                          /*******************/\r
-                                          /* Round the value */\r
-                                          /*******************/\r
-\r
-                                          if ((double) ((double) ul_TimingInterval * (1.0 * (double) b_PCIInputClock)) >= ((double) ((double) ul_TimerValue + 0.5)))\r
-                                             {\r
-                                             ul_TimerValue = ul_TimerValue + 1;\r
-                                             }\r
-\r
-                                          /*****************************/\r
-                                          /* Calculate the real timing */\r
-                                          /*****************************/\r
-\r
-                                          ul_RealTimingInterval = (ULONG) (ul_TimerValue / (1.0 * (double) b_PCIInputClock));\r
-                                          d_RealTimingInterval = (double) ul_TimerValue / ((double) 1.0 * (double) b_PCIInputClock);\r
-\r
-                                          if ((double) ((double) ul_TimerValue / (1.0 * (double) b_PCIInputClock)) >= (double) ((double) ul_RealTimingInterval + 0.5))\r
-                                             {\r
-                                             ul_RealTimingInterval = ul_RealTimingInterval + 1;\r
-                                             }\r
-\r
-                                          ul_TimingInterval = ul_TimingInterval - 1;\r
-                                          ul_TimerValue     = ul_TimerValue - 2;\r
-                                          if (b_PCIInputClock != APCI1710_40MHZ)\r
-                                             {\r
-                                             ul_TimerValue     = (ULONG) ((double) (ul_TimerValue) * 0.99392);\r
-                                             }\r
-                                       \r
-\r
-                                       break;\r
-\r
-                                  /******/\r
-                                  /* ms */\r
-                                  /******/\r
-\r
-                                  case 2:\r
-                                       \r
-                                          /******************/\r
-                                          /* Timer 0 factor */\r
-                                          /******************/\r
-\r
-                                          ul_TimerValue = ul_TimingInterval * (1000 * b_PCIInputClock);\r
-\r
-                                          /*******************/\r
-                                          /* Round the value */\r
-                                          /*******************/\r
-\r
-                                          if ((double) ((double) ul_TimingInterval * (1000.0 * (double) b_PCIInputClock)) >= ((double) ((double) ul_TimerValue + 0.5)))\r
-                                             {\r
-                                             ul_TimerValue = ul_TimerValue + 1;\r
-                                             }\r
-\r
-                                          /*****************************/\r
-                                          /* Calculate the real timing */\r
-                                          /*****************************/\r
-\r
-                                          ul_RealTimingInterval = (ULONG) (ul_TimerValue / (1000.0 * (double) b_PCIInputClock));\r
-                                          d_RealTimingInterval = (double) ul_TimerValue / (1000.0 * (double) b_PCIInputClock);\r
-\r
-                                          if ((double) ((double) ul_TimerValue / (1000.0 * (double) b_PCIInputClock)) >= (double) ((double) ul_RealTimingInterval + 0.5))\r
-                                             {\r
-                                             ul_RealTimingInterval = ul_RealTimingInterval + 1;\r
-                                             }\r
-\r
-                                          ul_TimingInterval = ul_TimingInterval - 1;\r
-                                          ul_TimerValue     = ul_TimerValue - 2;\r
-                                          if (b_PCIInputClock != APCI1710_40MHZ)\r
-                                             {\r
-                                             ul_TimerValue     = (ULONG) ((double) (ul_TimerValue) * 0.99392);\r
-                                             }\r
-                                       \r
-                                       break;\r
-\r
-                                  /*****/\r
-                                  /* s */\r
-                                  /*****/\r
-\r
-                                  case 3:\r
-                                       \r
-                                          /******************/\r
-                                          /* Timer 0 factor */\r
-                                          /******************/\r
-\r
-                                          ul_TimerValue = (ULONG) (ul_TimingInterval * (1000000.0 * b_PCIInputClock));\r
-\r
-                                          /*******************/\r
-                                          /* Round the value */\r
-                                          /*******************/\r
-\r
-                                          if ((double) ((double) ul_TimingInterval * (1000000.0 * (double) b_PCIInputClock)) >= ((double) ((double) ul_TimerValue + 0.5)))\r
-                                             {\r
-                                             ul_TimerValue = ul_TimerValue + 1;\r
-                                             }\r
-\r
-                                          /*****************************/\r
-                                          /* Calculate the real timing */\r
-                                          /*****************************/\r
-\r
-                                          ul_RealTimingInterval = (ULONG) (ul_TimerValue / (1000000.0 * (double) b_PCIInputClock));\r
-                                          d_RealTimingInterval = (double) ul_TimerValue / (1000000.0 * (double) b_PCIInputClock);\r
-\r
-                                          if ((double) ((double) ul_TimerValue / (1000000.0 * (double) b_PCIInputClock)) >= (double) ((double) ul_RealTimingInterval + 0.5))\r
-                                             {\r
-                                             ul_RealTimingInterval = ul_RealTimingInterval + 1;\r
-                                             }\r
-\r
-                                          ul_TimingInterval = ul_TimingInterval - 1;\r
-                                          ul_TimerValue     = ul_TimerValue - 2;\r
-                                          if (b_PCIInputClock != APCI1710_40MHZ)\r
-                                             {\r
-                                             ul_TimerValue     = (ULONG) ((double) (ul_TimerValue) * 0.99392);\r
-                                             }\r
-                                       \r
-\r
-                                       break;\r
-\r
-                                  /******/\r
-                                  /* mn */\r
-                                  /******/\r
-\r
-                                  case 4:\r
-                                       \r
-                                          /******************/\r
-                                          /* Timer 0 factor */\r
-                                          /******************/\r
-\r
-                                          ul_TimerValue = (ULONG) ((ul_TimingInterval * 60) * (1000000.0 * b_PCIInputClock));\r
-\r
-                                          /*******************/\r
-                                          /* Round the value */\r
-                                          /*******************/\r
-\r
-                                          if ((double) ((double) (ul_TimingInterval * 60.0) * (1000000.0 * (double) b_PCIInputClock)) >= ((double) ((double) ul_TimerValue + 0.5)))\r
-                                             {\r
-                                             ul_TimerValue = ul_TimerValue + 1;\r
-                                             }\r
-\r
-                                          /*****************************/\r
-                                          /* Calculate the real timing */\r
-                                          /*****************************/\r
-\r
-                                          ul_RealTimingInterval = (ULONG) (ul_TimerValue / (1000000.0 * (double) b_PCIInputClock)) / 60;\r
-                                          d_RealTimingInterval = ((double) ul_TimerValue / (0.001 * (double) b_PCIInputClock)) / 60.0;\r
-\r
-                                          if ((double) (((double) ul_TimerValue / (1000000.0 * (double) b_PCIInputClock)) / 60.0) >= (double) ((double) ul_RealTimingInterval + 0.5))\r
-                                             {\r
-                                             ul_RealTimingInterval = ul_RealTimingInterval + 1;\r
-                                             }\r
-\r
-                                          ul_TimingInterval = ul_TimingInterval - 1;\r
-                                          ul_TimerValue     = ul_TimerValue - 2;\r
-                                          if (b_PCIInputClock != APCI1710_40MHZ)\r
-                                             {\r
-                                             ul_TimerValue     = (ULONG) ((double) (ul_TimerValue) * 0.99392);\r
-                                             }\r
-                                       \r
-\r
-                                       break;\r
-                                  }\r
-\r
-                               fpu_end ();\r
-                               \r
-                               /****************************/\r
-                               /* Save the PCI input clock */\r
-                               /****************************/\r
-\r
-                               devpriv->s_ModuleInfo [b_ModulNbr].\r
-                               s_ChronoModuleInfo.\r
-                               b_PCIInputClock = b_PCIInputClock;\r
-\r
-                               /*************************/\r
-                               /* Save the timing unity */\r
-                               /*************************/\r
-\r
-                               devpriv->s_ModuleInfo [b_ModulNbr].\r
-                               s_ChronoModuleInfo.\r
-                               b_TimingUnit = b_TimingUnit;\r
-\r
-                               /************************/\r
-                               /* Save the base timing */\r
-                               /************************/\r
-\r
-                               devpriv->s_ModuleInfo [b_ModulNbr].\r
-                               s_ChronoModuleInfo.\r
-                               d_TimingInterval = d_RealTimingInterval;\r
-\r
-                               /****************************/\r
-                               /* Set the chronometer mode */\r
-                               /****************************/\r
-\r
-                               devpriv->s_ModuleInfo [b_ModulNbr].\r
-                               s_ChronoModuleInfo.\r
-                               dw_ConfigReg = dw_ModeArray [b_ChronoMode];\r
-\r
-                               /***********************/\r
-                               /* Test if 40 MHz used */\r
-                               /***********************/\r
-\r
-                               if (b_PCIInputClock == APCI1710_40MHZ)\r
-                                  {\r
-                                  devpriv->s_ModuleInfo [b_ModulNbr].\r
-                                  s_ChronoModuleInfo.\r
-                                  dw_ConfigReg = devpriv->s_ModuleInfo [b_ModulNbr].\r
-                                                 s_ChronoModuleInfo.\r
-                                                 dw_ConfigReg | 0x80;\r
-                                  }\r
-\r
-                               outl(devpriv->s_ModuleInfo [b_ModulNbr].s_ChronoModuleInfo.\r
-                                       dw_ConfigReg,devpriv->s_BoardInfos.\r
-                                       ui_Address + 16 + (64 * b_ModulNbr));\r
-\r
-                               /***********************/\r
-                               /* Write timer 0 value */\r
-                               /***********************/\r
-\r
-                               \r
-                               outl(ul_TimerValue,devpriv->s_BoardInfos.\r
-                                       ui_Address + (64 * b_ModulNbr));\r
-\r
-                               /*********************/\r
-                               /* Chronometer init. */\r
-                               /*********************/\r
-\r
-                               devpriv->s_ModuleInfo [b_ModulNbr].\r
-                               s_ChronoModuleInfo.\r
-                               b_ChronoInit = 1;\r
-                               }\r
-                            else\r
-                               {\r
-                               /***********************************************/\r
-                               /* TOR version error for 40MHz clock selection */\r
-                               /***********************************************/\r
-\r
-                       DPRINTK("TOR version error for 40MHz clock selection\n");\r
-                               i_ReturnValue = -9;\r
-                               }\r
-                            }\r
-                         else\r
-                            {\r
-                            /**************************************************************/\r
-                            /* You can not used the 40MHz clock selection wich this board */\r
-                            /**************************************************************/\r
-\r
-                                DPRINTK("You can not used the 40MHz clock selection wich this board\n");\r
-                            i_ReturnValue = -8;\r
-                            }\r
-                         }\r
-                      else\r
-                         {\r
-                         /**********************************/\r
-                         /* Base timing selection is wrong */\r
-                         /**********************************/\r
-\r
-                         DPRINTK("Base timing selection is wrong\n");\r
-                         i_ReturnValue = -7;\r
-                         }\r
-                      } // if ((b_TimingUnit >= 0) && (b_TimingUnit <= 4))\r
-                   else\r
-                      {\r
-                      /***********************************/\r
-                      /* Timing unity selection is wrong */\r
-                      /***********************************/\r
-\r
-                          DPRINTK("Timing unity selection is wrong\n");\r
-                      i_ReturnValue = -6;\r
-                      } // if ((b_TimingUnit >= 0) && (b_TimingUnit <= 4))\r
-                   } // if ((b_PCIInputClock == APCI1710_30MHZ) || (b_PCIInputClock == APCI1710_33MHZ))\r
-                else\r
-                   {\r
-                   /*****************************************/\r
-                   /* The selected PCI input clock is wrong */\r
-                   /*****************************************/\r
-\r
-                       DPRINTK("The selected PCI input clock is wrong\n");\r
-                   i_ReturnValue = -5;\r
-                   } // if ((b_PCIInputClock == APCI1710_30MHZ) || (b_PCIInputClock == APCI1710_33MHZ))\r
-                } // if (b_ChronoMode >= 0 && b_ChronoMode <= 7)\r
-             else\r
-                {\r
-                /***************************************/\r
-                /* Chronometer mode selection is wrong */\r
-                /***************************************/\r
-               \r
-DPRINTK("Chronometer mode selection is wrong\n");\r
-                i_ReturnValue = -4;\r
-                } // if (b_ChronoMode >= 0 && b_ChronoMode <= 7)\r
-             }\r
-          else\r
-             {\r
-             /******************************************/\r
-             /* The module is not a Chronometer module */\r
-             /******************************************/\r
-\r
-             DPRINTK("The module is not a Chronometer module\n");\r
-             i_ReturnValue = -3;\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /***********************/\r
-          /* Module number error */\r
-          /***********************/\r
-\r
-          DPRINTK("Module number error\n");\r
-          i_ReturnValue = -2;\r
-          }\r
-       data[0] = ul_RealTimingInterval;\r
-       return (i_ReturnValue);\r
-       }\r
-\r
-\r
-\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : _INT_ i_APCI1710_EnableChrono                          |\r
-|                                               (BYTE_ b_BoardHandle,        |\r
-|                                                BYTE_ b_ModulNbr,           |\r
-|                                                BYTE_ b_CycleMode,          |\r
-|                                                BYTE_ b_InterruptEnable)\r
-INT i_APCI1710_InsnWriteEnableDisableChrono(comedi_device *dev,\r
-comedi_subdevice *s,comedi_insn *insn,lsampl_t *data)                                           |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Enable the chronometer from selected module            |\r
-|                     (b_ModulNbr). You must calling the                     |\r
-|                     "i_APCI1710_InitChrono" function be for you call this  |\r
-|                     function.                                              |\r
-|                     If you enable the chronometer interrupt, the           |\r
-|                     chronometer generate a interrupt after the stop signal.|\r
-|                     See function "i_APCI1710_SetBoardIntRoutineX" and the  |\r
-|                     Interrupt mask description chapter from this manual.   |\r
-|                     The b_CycleMode parameter determine if you will        |\r
-|                     measured a single or more cycle. \r
-\r
-|                                        Disable the chronometer from selected module           |\r
-|                     (b_ModulNbr). If you disable the chronometer after a   |\r
-|                     start signal occur and you restart the chronometer     |\r
-|                     witch the " i_APCI1710_EnableChrono" function, if no   |\r
-|                     stop signal occur this start signal is ignored.   \r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : BYTE_ b_BoardHandle  : Handle of board APCI-1710       |\r
-|                     BYTE_ b_ModulNbr   CR_AREF(chanspec)  : Selected module number (0 to 3) |\r
-                                  data[0]  ENABle/Disable chrono\r
-|                     BYTE_ b_CycleMode    : Selected the chronometer        |\r
-|                                  data[1]           acquisition mode                |\r
-|                     BYTE_ b_InterruptEnable : Enable or disable the        |\r
-|                                   data[2]            chronometer interrupt.       |\r
-|                                               APCI1710_ENABLE:             |\r
-|                                               Enable the chronometer       |\r
-|                                               interrupt                    |\r
-|                                               APCI1710_DISABLE:            |\r
-|                                               Disable the chronometer      |\r
-|                                               interrupt                    |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : -                                                      |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      :  0: No error                                           |\r
-|                     -1: The handle parameter of the board is wrong         |\r
-|                     -2: Module selection wrong                             |\r
-|                     -3: The module is not a Chronometer module             |\r
-|                     -4: Chronometer not initialised see function           |\r
-|                         "i_APCI1710_InitChrono"                            |\r
-|                     -5: Chronometer acquisition mode cycle is wrong        |\r
-|                     -6: Interrupt parameter is wrong                       |\r
-|                     -7: Interrupt function not initialised.                |\r
-|                         See function "i_APCI1710_SetBoardIntRoutineX"  \r
-                      -8: data[0] wrong input    |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-\r
-INT i_APCI1710_InsnWriteEnableDisableChrono(comedi_device *dev,comedi_subdevice *s,\r
-       comedi_insn *insn,lsampl_t *data)\r
-       {\r
-       INT i_ReturnValue = 0;\r
-       BYTE b_ModulNbr,b_CycleMode,b_InterruptEnable,b_Action;\r
-       b_ModulNbr                      =       CR_AREF(insn->chanspec);\r
-        b_Action            =(BYTE) data[0];\r
-       b_CycleMode                     =(BYTE) data[1];\r
-       b_InterruptEnable       =(BYTE) data[2];\r
-       i_ReturnValue           =   insn->n;\r
-       \r
-\r
-       \r
-       /**************************/\r
-       /* Test the module number */\r
-       /**************************/\r
-\r
-       if (b_ModulNbr < 4)\r
-          {\r
-          /***********************/\r
-          /* Test if chronometer */\r
-          /***********************/\r
-\r
-          if ((devpriv->s_BoardInfos.\r
-               dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_CHRONOMETER)\r
-             {\r
-             /***********************************/\r
-             /* Test if chronometer initialised */\r
-             /***********************************/\r
-\r
-             if (devpriv->s_ModuleInfo [b_ModulNbr].\r
-                 s_ChronoModuleInfo.\r
-                 b_ChronoInit == 1)\r
-                {\r
-\r
-\r
-         switch(b_Action)\r
-         {\r
\r
-                case APCI1710_ENABLE :\r
-                            \r
-                /*********************************/\r
-                /* Test the cycle mode parameter */\r
-                /*********************************/\r
-\r
-                if ((b_CycleMode == APCI1710_SINGLE) || (b_CycleMode == APCI1710_CONTINUOUS))\r
-                   {\r
-                   /***************************/\r
-                   /* Test the interrupt flag */\r
-                   /***************************/\r
-\r
-                   if ((b_InterruptEnable == APCI1710_ENABLE) || (b_InterruptEnable == APCI1710_DISABLE))\r
-                      {\r
-                   \r
-       \r
-                         /***************************/\r
-                         /* Save the interrupt flag */\r
-                         /***************************/\r
-\r
-                         devpriv->s_ModuleInfo [b_ModulNbr].\r
-                         s_ChronoModuleInfo.\r
-                         b_InterruptMask = b_InterruptEnable;\r
-\r
-                         /***********************/\r
-                         /* Save the cycle mode */\r
-                         /***********************/\r
-\r
-                         devpriv->s_ModuleInfo [b_ModulNbr].\r
-                         s_ChronoModuleInfo.\r
-                         b_CycleMode = b_CycleMode;\r
-\r
-                         devpriv->s_ModuleInfo [b_ModulNbr].\r
-                         s_ChronoModuleInfo.\r
-                         dw_ConfigReg = (devpriv->s_ModuleInfo [b_ModulNbr].\r
-                                         s_ChronoModuleInfo.\r
-                                         dw_ConfigReg & 0x8F)           |\r
-                                         ((1 & b_InterruptEnable) << 5) |\r
-                                         ((1 & b_CycleMode) << 6)       |\r
-                                         0x10 ;\r
-\r
-                         /*****************************/\r
-                         /* Test if interrupt enabled */\r
-                         /*****************************/\r
-\r
-                         if (b_InterruptEnable == APCI1710_ENABLE)\r
-                            {\r
-                            /****************************/\r
-                            /* Clear the interrupt flag */\r
-                            /****************************/\r
-\r
-                           \r
-                                outl(devpriv->s_ModuleInfo [b_ModulNbr].\r
-                                    s_ChronoModuleInfo.dw_ConfigReg, devpriv->s_BoardInfos.\r
-                                    ui_Address + 32 + (64 * b_ModulNbr));\r
-                         devpriv->tsk_Current=current; // Save the current process task structure\r
-                            }\r
-\r
-                         /***********************************/\r
-                         /* Enable or disable the interrupt */\r
-                         /* Enable the chronometer          */\r
-                         /***********************************/\r
-           \r
-                         outl(devpriv->s_ModuleInfo [b_ModulNbr].\r
-                                 s_ChronoModuleInfo.dw_ConfigReg,devpriv->s_BoardInfos.\r
-                                 ui_Address + 16 + (64 * b_ModulNbr));\r
-\r
-                         /*************************/\r
-                         /* Clear status register */\r
-                         /*************************/\r
-\r
-                        \r
-                         outl(0,devpriv->s_BoardInfos.ui_Address + 36 + (64 * b_ModulNbr));\r
-                         \r
-                   } // if ((b_InterruptEnable == APCI1710_ENABLE) || (b_InterruptEnable == APCI1710_DISABLE))\r
-                   else\r
-                      {\r
-                      /********************************/\r
-                      /* Interrupt parameter is wrong */\r
-                      /********************************/\r
-\r
-                          DPRINTK("Interrupt parameter is wrong\n");\r
-                      i_ReturnValue = -6;\r
-                      } // if ((b_InterruptEnable == APCI1710_ENABLE) || (b_InterruptEnable == APCI1710_DISABLE))\r
-                   } // if ((b_CycleMode == APCI1710_SINGLE) || (b_CycleMode == APCI1710_CONTINUOUS))\r
-                else\r
-                   {\r
-                   /***********************************************/\r
-                   /* Chronometer acquisition mode cycle is wrong */\r
-                   /***********************************************/\r
-\r
-                       DPRINTK("Chronometer acquisition mode cycle is wrong\n");\r
-                   i_ReturnValue = -5;\r
-                   } // if ((b_CycleMode == APCI1710_SINGLE) || (b_CycleMode == APCI1710_CONTINUOUS))\r
-                break;\r
-\r
-                case APCI1710_DISABLE :\r
-\r
-                devpriv->s_ModuleInfo [b_ModulNbr].\r
-                s_ChronoModuleInfo.\r
-                b_InterruptMask = 0;\r
-\r
-                devpriv->s_ModuleInfo [b_ModulNbr].\r
-                s_ChronoModuleInfo.\r
-                dw_ConfigReg = devpriv->s_ModuleInfo [b_ModulNbr].\r
-                               s_ChronoModuleInfo.\r
-                               dw_ConfigReg & 0x2F;\r
-\r
-                /***************************/\r
-                /* Disable the interrupt   */\r
-                /* Disable the chronometer */\r
-                /***************************/\r
-\r
-                \r
-                outl(devpriv->s_ModuleInfo [b_ModulNbr].\r
-                        s_ChronoModuleInfo.dw_ConfigReg, devpriv->s_BoardInfos.\r
-                        ui_Address + 16 + (64 * b_ModulNbr));\r
-\r
-                /***************************/\r
-                /* Test if continuous mode */\r
-                /***************************/\r
-\r
-                if (devpriv->s_ModuleInfo [b_ModulNbr].\r
-                    s_ChronoModuleInfo.b_CycleMode == APCI1710_CONTINUOUS)\r
-                   {\r
-                   /*************************/\r
-                   /* Clear status register */\r
-                   /*************************/\r
-\r
-                  \r
-                       outl(0,devpriv->s_BoardInfos.ui_Address + 36 + (64 * b_ModulNbr));\r
-                   }\r
-                   break;\r
-\r
-                default:\r
-                         DPRINTK("Inputs wrong! Enable or Disable chrono\n");\r
-                         i_ReturnValue = -8;\r
-                 } // switch ENABLE/DISABLE\r
-                }\r
-             else\r
-                {\r
-                /*******************************/\r
-                /* Chronometer not initialised */\r
-                /*******************************/\r
-\r
-                DPRINTK("Chronometer not initialised\n");\r
-                i_ReturnValue = -4;\r
-                }\r
-             }\r
-          else\r
-             {\r
-             /******************************************/\r
-             /* The module is not a Chronometer module */\r
-             /******************************************/\r
-\r
-             DPRINTK("The module is not a Chronometer module\n");      \r
-             i_ReturnValue = -3;\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /***********************/\r
-          /* Module number error */\r
-          /***********************/\r
-\r
-          DPRINTK("Module number error\n");\r
-          i_ReturnValue = -2;\r
-          }\r
-\r
-      \r
-       return (i_ReturnValue);\r
-       }\r
-\r
-\r
-\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     :INT       i_APCI1710_InsnReadChrono(comedi_device *dev,comedi_subdevice *s,\r
-comedi_insn *insn,lsampl_t *data)                   |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Read  functions for Timer                                     |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : \r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : -                                                      |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      : \r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-INT    i_APCI1710_InsnReadChrono(comedi_device *dev,comedi_subdevice *s,\r
-comedi_insn *insn,lsampl_t *data)\r
-{\r
-       BYTE b_ReadType;\r
-       INT  i_ReturnValue=insn->n;\r
-        \r
-       b_ReadType=CR_CHAN(insn->chanspec);\r
-\r
-       switch(b_ReadType)\r
-       {\r
-       case APCI1710_CHRONO_PROGRESS_STATUS:\r
-               i_ReturnValue=i_APCI1710_GetChronoProgressStatus  (dev,\r
-                                                (BYTE)    CR_AREF(insn->chanspec),\r
-                                                (PBYTE)  &data[0]);\r
-       break;\r
-\r
-       case APCI1710_CHRONO_READVALUE:\r
-               i_ReturnValue=i_APCI1710_ReadChronoValue      (dev,\r
-                                        (BYTE)    CR_AREF(insn->chanspec),\r
-                                        (UINT)    insn->unused[0],\r
-                                        (PBYTE)   &data[0],\r
-                                        (PULONG) &data[1]);\r
-       break;\r
-\r
-       case APCI1710_CHRONO_CONVERTVALUE:\r
-               i_ReturnValue=i_APCI1710_ConvertChronoValue     (dev,\r
-                                        (BYTE)    CR_AREF(insn->chanspec),\r
-                                        (ULONG)   insn->unused[0],\r
-                                        (PULONG)  &data[0],\r
-                                        (PBYTE)   &data[1],\r
-                                        (PBYTE)   &data[2],\r
-                                        (PUINT)  &data[3],\r
-                                        (PUINT)  &data[4],\r
-                                        (PUINT)  &data[5]);\r
-       break;\r
-        \r
-        case APCI1710_CHRONO_READINTERRUPT:\r
-                         printk("In Chrono Read Interrupt\n");\r
-\r
-                         data[0]=devpriv->s_InterruptParameters.\r
-                                                     s_FIFOInterruptParameters [devpriv->\r
-                                                                                s_InterruptParameters.\r
-                                                                                ui_Read].b_OldModuleMask;\r
-                         data[1]=devpriv->s_InterruptParameters.\r
-                                                     s_FIFOInterruptParameters [devpriv->\r
-                                                                                s_InterruptParameters.\r
-                                                                                ui_Read].ul_OldInterruptMask;\r
-                         data[2]=devpriv->s_InterruptParameters.\r
-                                                     s_FIFOInterruptParameters [devpriv->\r
-                                                                                s_InterruptParameters.\r
-                                                                                ui_Read].ul_OldCounterLatchValue;\r
-\r
-                            \r
-                            /**************************/\r
-                            /* Increment the read FIFO */\r
-                            /***************************/\r
-\r
-                            devpriv->\r
-                            s_InterruptParameters.\r
-                            ui_Read = (devpriv->\r
-                                       s_InterruptParameters.\r
-                                       ui_Read + 1) % APCI1710_SAVE_INTERRUPT;\r
-        break;\r
-    \r
-       default:\r
-               printk("ReadType Parameter wrong\n");\r
-       }\r
-\r
-       if(i_ReturnValue>=0) i_ReturnValue =insn->n;\r
-       return (i_ReturnValue); \r
-\r
-}\r
-\r
-\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : _INT_ i_APCI1710_GetChronoProgressStatus               |\r
-|                               (BYTE_    b_BoardHandle,                     |\r
-|                                BYTE_    b_ModulNbr,                        |\r
-|                                PBYTE_  pb_ChronoStatus)                    |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Return the chronometer status (pb_ChronoStatus) from   |\r
-|                     selected chronometer module (b_ModulNbr).              |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : BYTE_ b_BoardHandle  : Handle of board APCI-1710       |\r
-|                     BYTE_ b_ModulNbr     : Selected module number (0 to 3) |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : PULONG_  pb_ChronoStatus : Return the chronometer      |\r
-|                                                status.                     |\r
-|                                                0 : Measurement not started.|\r
-|                                                    No start signal occur.  |\r
-|                                                1 : Measurement started.    |\r
-|                                                    A start signal occur.   |\r
-|                                                2 : Measurement stopped.    |\r
-|                                                    A stop signal occur.    |\r
-|                                                    The measurement is      |\r
-|                                                    terminate.              |\r
-|                                                3: A overflow occur. You    |\r
-|                                                   must change the base     |\r
-|                                                   timing witch the         |\r
-|                                                   function                 |\r
-|                                                   "i_APCI1710_InitChrono"  |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      :  0: No error                                           |\r
-|                     -1: The handle parameter of the board is wrong         |\r
-|                     -2: Module selection wrong                             |\r
-|                     -3: The module is not a Chronometer module             |\r
-|                     -4: Chronometer not initialised see function           |\r
-|                         "i_APCI1710_InitChrono"                            |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-INT   i_APCI1710_GetChronoProgressStatus      (comedi_device *dev,\r
-                                                BYTE    b_ModulNbr,\r
-                                                PBYTE  pb_ChronoStatus)\r
-       {\r
-       INT    i_ReturnValue = 0;\r
-       DWORD dw_Status;\r
-       \r
-       /**************************/\r
-       /* Test the module number */\r
-       /**************************/\r
-\r
-       if (b_ModulNbr < 4)\r
-          {\r
-          /***********************/\r
-          /* Test if chronometer */\r
-          /***********************/\r
-\r
-          if ((devpriv->\r
-               s_BoardInfos.\r
-               dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_CHRONOMETER)\r
-             {\r
-             /***********************************/\r
-             /* Test if chronometer initialised */\r
-             /***********************************/\r
-\r
-             if (devpriv->\r
-                 s_ModuleInfo [b_ModulNbr].\r
-                 s_ChronoModuleInfo.\r
-                 b_ChronoInit == 1)\r
-                {\r
-               \r
-               dw_Status=inl(devpriv->s_BoardInfos.\r
-                       ui_Address + 8 + (64 * b_ModulNbr));\r
-\r
-                /********************/\r
-                /* Test if overflow */\r
-                /********************/\r
-\r
-                if ((dw_Status & 8) == 8)\r
-                   {\r
-                   /******************/\r
-                   /* Overflow occur */\r
-                   /******************/\r
-\r
-                   *pb_ChronoStatus = 3;\r
-                   } // if ((dw_Status & 8) == 8)\r
-                else\r
-                   {\r
-                   /*******************************/\r
-                   /* Test if measurement stopped */\r
-                   /*******************************/\r
-\r
-                   if ((dw_Status & 2) == 2)\r
-                      {\r
-                      /***********************/\r
-                      /* A stop signal occur */\r
-                      /***********************/\r
-\r
-                      *pb_ChronoStatus = 2;\r
-                      } // if ((dw_Status & 2) == 2)\r
-                   else\r
-                      {\r
-                      /*******************************/\r
-                      /* Test if measurement started */\r
-                      /*******************************/\r
-\r
-                      if ((dw_Status & 1) == 1)\r
-                         {\r
-                         /************************/\r
-                         /* A start signal occur */\r
-                         /************************/\r
-\r
-                         *pb_ChronoStatus = 1;\r
-                         } // if ((dw_Status & 1) == 1)\r
-                      else\r
-                         {\r
-                         /***************************/\r
-                         /* Measurement not started */\r
-                         /***************************/\r
-\r
-                         *pb_ChronoStatus = 0;\r
-                         } // if ((dw_Status & 1) == 1)\r
-                      } // if ((dw_Status & 2) == 2)\r
-                   } // if ((dw_Status & 8) == 8)\r
-                }\r
-             else\r
-                {\r
-                /*******************************/\r
-                /* Chronometer not initialised */\r
-                /*******************************/\r
-                DPRINTK("Chronometer not initialised\n");\r
-                i_ReturnValue = -4;\r
-                }\r
-             }\r
-          else\r
-             {\r
-             /******************************************/\r
-             /* The module is not a Chronometer module */\r
-             /******************************************/\r
-              DPRINTK("The module is not a Chronometer module\n");\r
-             i_ReturnValue = -3;\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /***********************/\r
-          /* Module number error */\r
-          /***********************/\r
-          DPRINTK("Module number error\n");\r
-          i_ReturnValue = -2;\r
-          }\r
-\r
-       return (i_ReturnValue);\r
-       }\r
-\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : _INT_ i_APCI1710_ReadChronoValue                       |\r
-|                               (BYTE_     b_BoardHandle,                    |\r
-|                                BYTE_     b_ModulNbr,                       |\r
-|                                UINT_    ui_TimeOut,                        |\r
-|                                PBYTE_   pb_ChronoStatus,                   |\r
-|                                PULONG_ pul_ChronoValue)                    |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Return the chronometer status (pb_ChronoStatus) and the|\r
-|                     timing value (pul_ChronoValue) after a stop signal     |\r
-|                     occur from selected chronometer module (b_ModulNbr).   |\r
-|                     This function are only avaible if you have disabled    |\r
-|                     the interrupt functionality. See function              |\r
-|                     "i_APCI1710_EnableChrono" and the Interrupt mask       |\r
-|                     description chapter.                                   |\r
-|                     You can test the chronometer status witch the          |\r
-|                     "i_APCI1710_GetChronoProgressStatus" function.         |\r
-|                                                                            |\r
-|                     The returned value from pul_ChronoValue parameter is   |\r
-|                     not real measured timing.                              |\r
-|                     You must used the "i_APCI1710_ConvertChronoValue"      |\r
-|                     function or make this operation for calculate the      |\r
-|                     timing:                                                |\r
-|                                                                            |\r
-|                     Timing = pul_ChronoValue * pul_RealTimingInterval.     |\r
-|                                                                            |\r
-|                     pul_RealTimingInterval is the returned parameter from  |\r
-|                     "i_APCI1710_InitChrono" function and the time unity is |\r
-|                     the b_TimingUnit from "i_APCI1710_InitChrono" function|\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : BYTE_ b_BoardHandle  : Handle of board APCI-1710       |\r
-|                     BYTE_ b_ModulNbr     : Selected module number (0 to 3) |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : PULONG_  pb_ChronoStatus : Return the chronometer      |\r
-|                                                status.                     |\r
-|                                                0 : Measurement not started.|\r
-|                                                    No start signal occur.  |\r
-|                                                1 : Measurement started.    |\r
-|                                                    A start signal occur.   |\r
-|                                                2 : Measurement stopped.    |\r
-|                                                    A stop signal occur.    |\r
-|                                                    The measurement is      |\r
-|                                                    terminate.              |\r
-|                                                3: A overflow occur. You    |\r
-|                                                   must change the base     |\r
-|                                                   timing witch the         |\r
-|                                                   function                 |\r
-|                                                   "i_APCI1710_InitChrono"  |\r
-|                     PULONG  pul_ChronoValue  : Chronometer timing value.   |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      :  0: No error                                           |\r
-|                     -1: The handle parameter of the board is wrong         |\r
-|                     -2: Module selection wrong                             |\r
-|                     -3: The module is not a Chronometer module             |\r
-|                     -4: Chronometer not initialised see function           |\r
-|                         "i_APCI1710_InitChrono"                            |\r
-|                     -5: Timeout parameter is wrong (0 to 65535)            |\r
-|                     -6: Interrupt routine installed. You can not read      |\r
-|                         directly the chronometer measured timing.          |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-INT   i_APCI1710_ReadChronoValue      (comedi_device *dev,\r
-                                        BYTE     b_ModulNbr,\r
-                                        UINT    ui_TimeOut,\r
-                                        PBYTE   pb_ChronoStatus,\r
-                                        PULONG pul_ChronoValue)\r
-       {\r
-       INT    i_ReturnValue = 0;\r
-       DWORD dw_Status;\r
-       DWORD dw_TimeOut = 0;\r
-       \r
-\r
-       /**************************/\r
-       /* Test the module number */\r
-       /**************************/\r
-\r
-       if (b_ModulNbr < 4)\r
-          {\r
-          /***********************/\r
-          /* Test if chronometer */\r
-          /***********************/\r
-\r
-          if ((devpriv->\r
-               s_BoardInfos.\r
-               dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_CHRONOMETER)\r
-             {\r
-             /***********************************/\r
-             /* Test if chronometer initialised */\r
-             /***********************************/\r
-\r
-             if (devpriv->\r
-                 s_ModuleInfo [b_ModulNbr].\r
-                 s_ChronoModuleInfo.\r
-                 b_ChronoInit == 1)\r
-                {\r
-                /*****************************/\r
-                /* Test the timout parameter */\r
-                /*****************************/\r
-\r
-                if ((ui_TimeOut >= 0) && (ui_TimeOut <= 65535UL))\r
-                   {\r
-                  \r
-                      for (;;)\r
-                         {\r
-                         /*******************/\r
-                         /* Read the status */\r
-                         /*******************/\r
-\r
-                        \r
-                               dw_Status=inl(devpriv->s_BoardInfos.\r
-                                ui_Address + 8 + (64 * b_ModulNbr));\r
-\r
-\r
-                         /********************/\r
-                         /* Test if overflow */\r
-                         /********************/\r
-\r
-                         if ((dw_Status & 8) == 8)\r
-                            {\r
-                            /******************/\r
-                            /* Overflow occur */\r
-                            /******************/\r
-\r
-                            *pb_ChronoStatus = 3;\r
-\r
-                            /***************************/\r
-                            /* Test if continuous mode */\r
-                            /***************************/\r
-\r
-                            if (devpriv->s_ModuleInfo [b_ModulNbr].\r
-                                s_ChronoModuleInfo.\r
-                                b_CycleMode == APCI1710_CONTINUOUS)\r
-                               {\r
-                               /*************************/\r
-                               /* Clear status register */\r
-                               /*************************/\r
-\r
-                               \r
-                                        outl(0,devpriv->s_BoardInfos.\r
-                                       ui_Address + 36 + (64 * b_ModulNbr));\r
-                               }\r
-\r
-                            break;\r
-                            } // if ((dw_Status & 8) == 8)\r
-                         else\r
-                            {\r
-                            /*******************************/\r
-                            /* Test if measurement stopped */\r
-                            /*******************************/\r
-\r
-                            if ((dw_Status & 2) == 2)\r
-                               {\r
-                               /***********************/\r
-                               /* A stop signal occur */\r
-                               /***********************/\r
-\r
-                               *pb_ChronoStatus = 2;\r
-\r
-                               /***************************/\r
-                               /* Test if continnous mode */\r
-                               /***************************/\r
-\r
-                               if (devpriv->\r
-                                   s_ModuleInfo [b_ModulNbr].\r
-                                   s_ChronoModuleInfo.\r
-                                   b_CycleMode == APCI1710_CONTINUOUS)\r
-                                  {\r
-                                  /*************************/\r
-                                  /* Clear status register */\r
-                                  /*************************/\r
-\r
-                                  \r
-                                       outl(0,devpriv->s_BoardInfos.\r
-                                          ui_Address + 36 + (64 * b_ModulNbr));\r
-                                  }\r
-                               break;\r
-                               } // if ((dw_Status & 2) == 2)\r
-                            else\r
-                               {\r
-                               /*******************************/\r
-                               /* Test if measurement started */\r
-                               /*******************************/\r
-\r
-                               if ((dw_Status & 1) == 1)\r
-                                  {\r
-                                  /************************/\r
-                                  /* A start signal occur */\r
-                                  /************************/\r
-\r
-                                  *pb_ChronoStatus = 1;\r
-                                  } // if ((dw_Status & 1) == 1)\r
-                               else\r
-                                  {\r
-                                  /***************************/\r
-                                  /* Measurement not started */\r
-                                  /***************************/\r
-\r
-                                  *pb_ChronoStatus = 0;\r
-                                  } // if ((dw_Status & 1) == 1)\r
-                               } // if ((dw_Status & 2) == 2)\r
-                            } // if ((dw_Status & 8) == 8)\r
-\r
-                         if (dw_TimeOut == ui_TimeOut)\r
-                            {\r
-                            /*****************/\r
-                            /* Timeout occur */\r
-                            /*****************/\r
-\r
-                            break;\r
-                            }\r
-                         else\r
-                            {\r
-                            /*************************/\r
-                            /* Increment the timeout */\r
-                            /*************************/\r
-\r
-                            dw_TimeOut = dw_TimeOut + 1;\r
-                                mdelay(1000);\r
-                           \r
-                               }\r
-                         } // for (;;)\r
-\r
-                      /*****************************/\r
-                      /* Test if stop signal occur */\r
-                      /*****************************/\r
-\r
-                      if (*pb_ChronoStatus == 2)\r
-                         {\r
-                         /**********************************/\r
-                         /* Read the measured timing value */\r
-                         /**********************************/\r
-\r
-                         \r
-                               *pul_ChronoValue= inl(devpriv->s_BoardInfos.\r
-                                ui_Address + 4 + (64 * b_ModulNbr));\r
-\r
-                         if (*pul_ChronoValue != 0)\r
-                            {\r
-                            *pul_ChronoValue = *pul_ChronoValue - 1;\r
-                            }\r
-                         }\r
-                      else\r
-                         {\r
-                         /*************************/\r
-                         /* Test if timeout occur */\r
-                         /*************************/\r
-\r
-                         if ((*pb_ChronoStatus != 3) && (dw_TimeOut == ui_TimeOut) && (ui_TimeOut != 0))\r
-                            {\r
-                            /*****************/\r
-                            /* Timeout occur */\r
-                            /*****************/\r
-\r
-                            *pb_ChronoStatus = 4;\r
-                            }\r
-                         }\r
-                    \r
-                   }\r
-                else\r
-                   {\r
-                   /******************************/\r
-                   /* Timeout parameter is wrong */\r
-                   /******************************/\r
-                    DPRINTK("Timeout parameter is wrong\n");\r
-                   i_ReturnValue = -5;\r
-                   }\r
-                }\r
-             else\r
-                {\r
-                /*******************************/\r
-                /* Chronometer not initialised */\r
-                /*******************************/\r
-                DPRINTK("Chronometer not initialised\n");\r
-                i_ReturnValue = -4;\r
-                }\r
-             }\r
-          else\r
-             {\r
-             /******************************************/\r
-             /* The module is not a Chronometer module */\r
-             /******************************************/\r
-             DPRINTK("The module is not a Chronometer module\n");      \r
-             i_ReturnValue = -3;\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /***********************/\r
-          /* Module number error */\r
-          /***********************/\r
-          DPRINTK("Module number error\n");\r
-          i_ReturnValue = -2;\r
-          }\r
-\r
-       return (i_ReturnValue);\r
-       }\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : _INT_ i_APCI1710_ConvertChronoValue                    |\r
-|                               (BYTE_     b_BoardHandle,                    |\r
-|                                BYTE_     b_ModulNbr,                       |\r
-|                                ULONG_   ul_ChronoValue,                    |\r
-|                                PULONG_ pul_Hour,                           |\r
-|                                PBYTE_   pb_Minute,                         |\r
-|                                PBYTE_   pb_Second,                         |\r
-|                                PUINT_  pui_MilliSecond,                    |\r
-|                                PUINT_  pui_MicroSecond,                    |\r
-|                                PUINT_  pui_NanoSecond)                     |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Convert the chronometer measured timing                |\r
-|                     (ul_ChronoValue) in to h, mn, s, ms, µs, ns.           |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : BYTE_   b_BoardHandle : Handle of board APCI-1710      |\r
-|                     BYTE_   b_ModulNbr    : Selected module number (0 to 3)|\r
-|                     ULONG_ ul_ChronoValue : Measured chronometer timing    |\r
-|                                             value.                         |\r
-|                                             See"i_APCI1710_ReadChronoValue"|\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : PULONG_   pul_Hour        : Chronometer timing hour    |\r
-|                     PBYTE_     pb_Minute      : Chronometer timing minute  |\r
-|                     PBYTE_     pb_Second      : Chronometer timing second  |\r
-|                     PUINT_    pui_MilliSecond  : Chronometer timing mini   |\r
-|                                                 second                     |\r
-|                     PUINT_    pui_MicroSecond : Chronometer timing micro   |\r
-|                                                 second                     |\r
-|                     PUINT_    pui_NanoSecond  : Chronometer timing nano    |\r
-|                                                 second                     |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      :  0: No error                                           |\r
-|                     -1: The handle parameter of the board is wrong         |\r
-|                     -2: Module selection wrong                             |\r
-|                     -3: The module is not a Chronometer module             |\r
-|                     -4: Chronometer not initialised see function           |\r
-|                         "i_APCI1710_InitChrono"                            |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-INT i_APCI1710_ConvertChronoValue     (comedi_device *dev,\r
-                                        BYTE     b_ModulNbr,\r
-                                        ULONG   ul_ChronoValue,\r
-                                        PULONG pul_Hour,\r
-                                        PBYTE   pb_Minute,\r
-                                        PBYTE   pb_Second,\r
-                                        PUINT  pui_MilliSecond,\r
-                                        PUINT  pui_MicroSecond,\r
-                                        PUINT  pui_NanoSecond)\r
-       {\r
-       INT    i_ReturnValue = 0;\r
-       double d_Hour;\r
-       double d_Minute;\r
-       double d_Second;\r
-       double d_MilliSecond;\r
-       double d_MicroSecond;\r
-       double d_NanoSecond;\r
-       \r
-       /**************************/\r
-       /* Test the module number */\r
-       /**************************/\r
-\r
-       if (b_ModulNbr < 4)\r
-          {\r
-          /***********************/\r
-          /* Test if chronometer */\r
-          /***********************/\r
-\r
-          if ((devpriv->\r
-               s_BoardInfos.\r
-               dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_CHRONOMETER)\r
-             {\r
-             /***********************************/\r
-             /* Test if chronometer initialised */\r
-             /***********************************/\r
-\r
-             if (devpriv->\r
-                 s_ModuleInfo [b_ModulNbr].\r
-                 s_ChronoModuleInfo.\r
-                 b_ChronoInit == 1)\r
-                {\r
-                fpu_begin ();\r
-                \r
-                   d_Hour = (double) ul_ChronoValue * (double) devpriv->\r
-                                                               s_ModuleInfo [b_ModulNbr].\r
-                                                               s_ChronoModuleInfo.\r
-                                                               d_TimingInterval;\r
-\r
-                   switch (devpriv->\r
-                           s_ModuleInfo [b_ModulNbr].\r
-                           s_ChronoModuleInfo.\r
-                           b_TimingUnit)\r
-                      {\r
-                      case 0:\r
-                           d_Hour = d_Hour / (double) 1000.0;\r
-\r
-                      case 1:\r
-                           d_Hour = d_Hour / (double) 1000.0;\r
-\r
-                      case 2:\r
-                           d_Hour = d_Hour / (double) 1000.0;\r
-\r
-                      case 3:\r
-                           d_Hour = d_Hour / (double) 60.0;\r
-\r
-                      case 4:\r
-                           /**********************/\r
-                           /* Calculate the hour */\r
-                           /**********************/\r
-\r
-                           d_Hour    = d_Hour / (double) 60.0;\r
-                           *pul_Hour = (ULONG) d_Hour;\r
-\r
-                           /************************/\r
-                           /* Calculate the minute */\r
-                           /************************/\r
-\r
-                           d_Minute   = d_Hour - *pul_Hour;\r
-                           d_Minute   = d_Minute * 60;\r
-                           *pb_Minute = (BYTE) d_Minute;\r
-\r
-                           /************************/\r
-                           /* Calculate the second */\r
-                           /************************/\r
-\r
-                           d_Second   = d_Minute - *pb_Minute;\r
-                           d_Second   = d_Second * 60;\r
-                           *pb_Second = (BYTE) d_Second;\r
-\r
-                           /*****************************/\r
-                           /* Calculate the mini second */\r
-                           /*****************************/\r
-\r
-                           d_MilliSecond    = d_Second - *pb_Second;\r
-                           d_MilliSecond    = d_MilliSecond * 1000;\r
-                           *pui_MilliSecond = (UINT) d_MilliSecond;\r
-\r
-                           /******************************/\r
-                           /* Calculate the micro second */\r
-                           /******************************/\r
-\r
-                           d_MicroSecond    = d_MilliSecond - *pui_MilliSecond;\r
-                           d_MicroSecond    = d_MicroSecond * 1000;\r
-                           *pui_MicroSecond = (UINT) d_MicroSecond;\r
-\r
-                           /******************************/\r
-                           /* Calculate the micro second */\r
-                           /******************************/\r
-\r
-                           d_NanoSecond    = d_MicroSecond - *pui_MicroSecond;\r
-                           d_NanoSecond    = d_NanoSecond * 1000;\r
-                           *pui_NanoSecond = (UINT) d_NanoSecond;\r
-                           break;\r
-                      }\r
-                   \r
-                fpu_end ();\r
-                }\r
-             else\r
-                {\r
-                /*******************************/\r
-                /* Chronometer not initialised */\r
-                /*******************************/\r
-                DPRINTK("Chronometer not initialised\n");\r
-                i_ReturnValue = -4;\r
-                }\r
-             }\r
-          else\r
-             {\r
-             /******************************************/\r
-             /* The module is not a Chronometer module */\r
-             /******************************************/\r
-             DPRINTK("The module is not a Chronometer module\n");      \r
-             i_ReturnValue = -3;\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /***********************/\r
-          /* Module number error */\r
-          /***********************/\r
-          DPRINTK("Module number error\n");    \r
-          i_ReturnValue = -2;\r
-          }\r
-\r
-       return (i_ReturnValue);\r
-       }\r
-\r
-\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : INT i_APCI1710_InsnBitsChronoDigitalIO(comedi_device *dev,comedi_subdevice *s,\r
-       comedi_insn *insn,lsampl_t *data)                    |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Sets the output witch has been passed with the         |\r
-|                     parameter b_Channel. Setting an output means setting an|\r
-|                     output high.                                           |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : BYTE_ b_BoardHandle   : Handle of board APCI-1710      |\r
-|                     BYTE_ b_ModulNbr      : Selected module number (0 to 3)|\r
-|                     BYTE_ b_OutputChannel : Selection from digital output  |\r
-|                           CR_CHAN()                  channel (0 to 2)               |\r
-|                                              0 : Channel H                 |\r
-|                                              1 : Channel A                 |\r
-|                                              2 : Channel B                 |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : -                                                      |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      :  0: No error                                           |\r
-|                     -1: The handle parameter of the board is wrong         |\r
-|                     -2: Module selection wrong                             |\r
-|                     -3: The module is not a Chronometer module             |\r
-|                     -4: The selected digital output is wrong               |\r
-|                     -5: Chronometer not initialised see function           |\r
-|                         "i_APCI1710_InitChrono"                            |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : _INT_ i_APCI1710_SetChronoChlOff                       |\r
-|                               (BYTE_  b_BoardHandle,                       |\r
-|                                BYTE_  b_ModulNbr,                          |\r
-|                                BYTE_  b_OutputChannel)                     |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Resets the output witch has been passed with the       |\r
-|                     parameter b_Channel. Resetting an output means setting |\r
-|                     an output low.                                         |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : BYTE_ b_BoardHandle   : Handle of board APCI-1710 \r
-                        data[0] : Chl ON, Chl OFF , Chl Read , Port Read \r
-                                                        \r
-|                     BYTE_ b_ModulNbr  CR_AREF    : Selected module number (0 to 3)|\r
-|                     BYTE_ b_OutputChannel CR_CHAN : Selection from digital output  |\r
-|                                             channel (0 to 2)               |\r
-|                                              0 : Channel H                 |\r
-|                                              1 : Channel A                 |\r
-|                                              2 : Channel B                 |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : -                                                      |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      :  0: No error                                           |\r
-|                     -1: The handle parameter of the board is wrong         |\r
-|                     -2: Module selection wrong                             |\r
-|                     -3: The module is not a Chronometer module             |\r
-|                     -4: The selected digital output is wrong               |\r
-|                     -5: Chronometer not initialised see function           |\r
-|                         "i_APCI1710_InitChrono"                            |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : _INT_ i_APCI1710_ReadChronoChlValue                    |\r
-|                               (BYTE_   b_BoardHandle,                      |\r
-|                                BYTE_   b_ModulNbr,                         |\r
-|                                BYTE_   b_InputChannel,                     |\r
-|                                PBYTE_ pb_ChannelStatus)                    |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Return the status from selected digital input          |\r
-|                     (b_InputChannel) from selected chronometer             |\r
-|                     module (b_ModulNbr).                                   |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : BYTE_ b_BoardHandle   : Handle of board APCI-1710      |\r
-|                     BYTE_ b_ModulNbr      : Selected module number (0 to 3)|\r
-|                     BYTE_ b_InputChannel  : Selection from digital input   |\r
-|                                             channel (0 to 2)               |\r
-|                                   CR_CHAN()             0 : Channel E               |\r
-|                                                1 : Channel F               |\r
-|                                                2 : Channel G               |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : PBYTE_ pb_ChannelStatus : Digital input channel status.|\r
-|                                data[0]                0 : Channel is not active   |\r
-|                                                1 : Channel is active       |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      :  0: No error                                           |\r
-|                     -1: The handle parameter of the board is wrong         |\r
-|                     -2: Module selection wrong                             |\r
-|                     -3: The module is not a Chronometer module             |\r
-|                     -4: The selected digital input is wrong                |\r
-|                     -5: Chronometer not initialised see function           |\r
-|                         "i_APCI1710_InitChrono"                            |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : _INT_ i_APCI1710_ReadChronoPortValue                   |\r
-|                               (BYTE_   b_BoardHandle,                      |\r
-|                                BYTE_   b_ModulNbr,                         |\r
-|                                PBYTE_ pb_PortValue)                        |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Return the status from digital inputs port from        |\r
-|                     selected  (b_ModulNbr) chronometer module.             |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : BYTE_ b_BoardHandle   : Handle of board APCI-1710      |\r
-|                     BYTE_ b_ModulNbr      : Selected module number (0 to 3)|\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : PBYTE_ pb_PortValue   : Digital inputs port status.    \r
-|                     data[0]\r
-+----------------------------------------------------------------------------+\r
-| Return Value      :  0: No error                                           |\r
-|                     -1: The handle parameter of the board is wrong         |\r
-|                     -2: Module selection wrong                             |\r
-|                     -3: The module is not a Chronometer module             |\r
-|                     -4: Chronometer not initialised see function           |\r
-|                         "i_APCI1710_InitChrono"                            |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-\r
-INT i_APCI1710_InsnBitsChronoDigitalIO(comedi_device *dev,comedi_subdevice *s,\r
-       comedi_insn *insn,lsampl_t *data)\r
-       {\r
-       INT    i_ReturnValue = 0;\r
-       BYTE  b_ModulNbr,b_OutputChannel,b_InputChannel,b_IOType;\r
-       DWORD dw_Status;\r
-       PBYTE pb_ChannelStatus;\r
-       PBYTE pb_PortValue;\r
-       \r
-       b_ModulNbr      = CR_AREF(insn->chanspec);\r
-       i_ReturnValue = insn->n;\r
-       b_IOType   = (BYTE) data[0];\r
-          \r
-\r
-       \r
-\r
-       /**************************/\r
-       /* Test the module number */\r
-       /**************************/\r
-\r
-       if (b_ModulNbr < 4)\r
-          {\r
-          /***********************/\r
-          /* Test if chronometer */\r
-          /***********************/\r
-\r
-          if ((devpriv->s_BoardInfos.\r
-               dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_CHRONOMETER)\r
-             {\r
-             /***********************************/\r
-             /* Test if chronometer initialised */\r
-             /***********************************/\r
-\r
-             if (devpriv->s_ModuleInfo [b_ModulNbr].\r
-                 s_ChronoModuleInfo.\r
-                 b_ChronoInit == 1)\r
-                {\r
-                /***********************************/\r
-                /* Test the digital output channel */\r
-                /***********************************/\r
-          switch(b_IOType)\r
-          {\r
-\r
-                case APCI1710_CHRONO_SET_CHANNELOFF:\r
-\r
-               b_OutputChannel = (BYTE) CR_CHAN(insn->chanspec);\r
-                         if (b_OutputChannel <= 2)\r
-                   {\r
-                   \r
-             outl(0,devpriv->s_BoardInfos.ui_Address + 20 + (b_OutputChannel * 4) + (64 * b_ModulNbr));\r
-                   } // if ((b_OutputChannel >= 0) && (b_OutputChannel <= 2))\r
-                else\r
-                   {\r
-                   /****************************************/\r
-                   /* The selected digital output is wrong */\r
-                   /****************************************/\r
-\r
-                   DPRINTK("The selected digital output is wrong\n"); \r
-                   i_ReturnValue = -4;\r
-\r
-                   } // if ((b_OutputChannel >= 0) && (b_OutputChannel <= 2))\r
-\r
-                 break;\r
-\r
-                 case APCI1710_CHRONO_SET_CHANNELON:\r
-\r
-                b_OutputChannel = (BYTE) CR_CHAN(insn->chanspec);\r
-                if (b_OutputChannel <= 2)\r
-                   {\r
-                   \r
-                        outl(1,devpriv->s_BoardInfos.ui_Address + 20 + (b_OutputChannel * 4) + (64 * b_ModulNbr));\r
-                   } // if ((b_OutputChannel >= 0) && (b_OutputChannel <= 2))\r
-                else\r
-                   {\r
-                   /****************************************/\r
-                   /* The selected digital output is wrong */\r
-                   /****************************************/\r
-\r
-                       DPRINTK("The selected digital output is wrong\n");\r
-                   i_ReturnValue = -4;\r
-\r
-                   } // if ((b_OutputChannel >= 0) && (b_OutputChannel <= 2))\r
-\r
-                       break;\r
-                 \r
-                 case APCI1710_CHRONO_READ_CHANNEL :\r
-                /**********************************/\r
-                /* Test the digital input channel */\r
-                /**********************************/\r
-                pb_ChannelStatus = (PBYTE) &data[0];\r
-                b_InputChannel = (BYTE) CR_CHAN(insn->chanspec);\r
-                \r
-                if (b_InputChannel <= 2)\r
-                   {\r
-                   \r
-                        dw_Status = inl(devpriv->s_BoardInfos.ui_Address + 12 + (64 * b_ModulNbr));\r
-\r
-                   *pb_ChannelStatus = (BYTE) (((dw_Status >> b_InputChannel) & 1) ^ 1);\r
-                   } // if ((b_InputChannel >= 0) && (b_InputChannel <= 2))\r
-                else\r
-                   {\r
-                   /***************************************/\r
-                   /* The selected digital input is wrong */\r
-                   /***************************************/\r
-\r
-                       DPRINTK("The selected digital input is wrong\n");\r
-                   i_ReturnValue = -4;\r
-                   } // if ((b_InputChannel >= 0) && (b_InputChannel <= 2))\r
-\r
-                 break;\r
-\r
-                 case APCI1710_CHRONO_READ_PORT :\r
-\r
-                       pb_PortValue = (PBYTE) &data[0];\r
-\r
-                       \r
-                       dw_Status = inl(devpriv->s_BoardInfos.ui_Address + 12 + (64 * b_ModulNbr));\r
-\r
-                   *pb_PortValue = (BYTE) ((dw_Status & 0x7) ^ 7);\r
-                         break;\r
-                 }\r
-                }\r
-             else\r
-                {\r
-                /*******************************/\r
-                /* Chronometer not initialised */\r
-                /*******************************/\r
-\r
-                DPRINTK("Chronometer not initialised\n");      \r
-                i_ReturnValue = -5;\r
-                }\r
-             }\r
-          else\r
-             {\r
-             /******************************************/\r
-             /* The module is not a Chronometer module */\r
-             /******************************************/\r
-\r
-             DPRINTK("The module is not a Chronometer module\n");\r
-             i_ReturnValue = -3;\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /***********************/\r
-          /* Module number error */\r
-          /***********************/\r
-\r
-          DPRINTK("Module number error\n");\r
-          i_ReturnValue = -2;\r
-          }\r
-\r
-       return (i_ReturnValue);\r
-}\r
-\r
+/**
+@verbatim
+
+Copyright (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 USA
+
+You 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;
+                                             }
+
+                                          /*****************************/
+                                          /* Calculate the real timing */
+                                          /*****************************/
+
+                                          ul_RealTimingInterval = (ULONG) (ul_TimerValue / (1000.0 * (double) b_PCIInputClock));
+                                          d_RealTimingInterval = (double) ul_TimerValue / (1000.0 * (double) b_PCIInputClock);
+
+                                          if ((double) ((double) ul_TimerValue / (1000.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;
+
+                                  /*****/
+                                  /* s */
+                                  /*****/
+
+                                  case 3:
+                                       
+                                          /******************/
+                                          /* Timer 0 factor */
+                                          /******************/
+
+                                          ul_TimerValue = (ULONG) (ul_TimingInterval * (1000000.0 * b_PCIInputClock));
+
+                                          /*******************/
+                                          /* Round the value */
+                                          /*******************/
+
+                                          if ((double) ((double) ul_TimingInterval * (1000000.0 * (double) b_PCIInputClock)) >= ((double) ((double) ul_TimerValue + 0.5)))
+                                             {
+                                             ul_TimerValue = ul_TimerValue + 1;
+                                             }
+
+                                          /*****************************/
+                                          /* Calculate the real timing */
+                                          /*****************************/
+
+                                          ul_RealTimingInterval = (ULONG) (ul_TimerValue / (1000000.0 * (double) b_PCIInputClock));
+                                          d_RealTimingInterval = (double) ul_TimerValue / (1000000.0 * (double) b_PCIInputClock);
+
+                                          if ((double) ((double) ul_TimerValue / (1000000.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;
+
+                                  /******/
+                                  /* mn */
+                                  /******/
+
+                                  case 4:
+                                       
+                                          /******************/
+                                          /* Timer 0 factor */
+                                          /******************/
+
+                                          ul_TimerValue = (ULONG) ((ul_TimingInterval * 60) * (1000000.0 * b_PCIInputClock));
+
+                                          /*******************/
+                                          /* Round the value */
+                                          /*******************/
+
+                                          if ((double) ((double) (ul_TimingInterval * 60.0) * (1000000.0 * (double) b_PCIInputClock)) >= ((double) ((double) ul_TimerValue + 0.5)))
+                                             {
+                                             ul_TimerValue = ul_TimerValue + 1;
+                                             }
+
+                                          /*****************************/
+                                          /* Calculate the real timing */
+                                          /*****************************/
+
+                                          ul_RealTimingInterval = (ULONG) (ul_TimerValue / (1000000.0 * (double) b_PCIInputClock)) / 60;
+                                          d_RealTimingInterval = ((double) ul_TimerValue / (0.001 * (double) b_PCIInputClock)) / 60.0;
+
+                                          if ((double) (((double) ul_TimerValue / (1000000.0 * (double) b_PCIInputClock)) / 60.0) >= (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;
+                                  }
+
+                               fpu_end ();
+                               
+                               /****************************/
+                               /* Save the PCI input clock */
+                               /****************************/
+
+                               devpriv->s_ModuleInfo [b_ModulNbr].
+                               s_ChronoModuleInfo.
+                               b_PCIInputClock = b_PCIInputClock;
+
+                               /*************************/
+                               /* Save the timing unity */
+                               /*************************/
+
+                               devpriv->s_ModuleInfo [b_ModulNbr].
+                               s_ChronoModuleInfo.
+                               b_TimingUnit = b_TimingUnit;
+
+                               /************************/
+                               /* Save the base timing */
+                               /************************/
+
+                               devpriv->s_ModuleInfo [b_ModulNbr].
+                               s_ChronoModuleInfo.
+                               d_TimingInterval = d_RealTimingInterval;
+
+                               /****************************/
+                               /* Set the chronometer mode */
+                               /****************************/
+
+                               devpriv->s_ModuleInfo [b_ModulNbr].
+                               s_ChronoModuleInfo.
+                               dw_ConfigReg = dw_ModeArray [b_ChronoMode];
+
+                               /***********************/
+                               /* Test if 40 MHz used */
+                               /***********************/
+
+                               if (b_PCIInputClock == APCI1710_40MHZ)
+                                  {
+                                  devpriv->s_ModuleInfo [b_ModulNbr].
+                                  s_ChronoModuleInfo.
+                                  dw_ConfigReg = devpriv->s_ModuleInfo [b_ModulNbr].
+                                                 s_ChronoModuleInfo.
+                                                 dw_ConfigReg | 0x80;
+                                  }
+
+                               outl(devpriv->s_ModuleInfo [b_ModulNbr].s_ChronoModuleInfo.
+                                       dw_ConfigReg,devpriv->s_BoardInfos.
+                                       ui_Address + 16 + (64 * b_ModulNbr));
+
+                               /***********************/
+                               /* Write timer 0 value */
+                               /***********************/
+
+                               
+                               outl(ul_TimerValue,devpriv->s_BoardInfos.
+                                       ui_Address + (64 * b_ModulNbr));
+
+                               /*********************/
+                               /* Chronometer init. */
+                               /*********************/
+
+                               devpriv->s_ModuleInfo [b_ModulNbr].
+                               s_ChronoModuleInfo.
+                               b_ChronoInit = 1;
+                               }
+                            else
+                               {
+                               /***********************************************/
+                               /* TOR version error for 40MHz clock selection */
+                               /***********************************************/
+
+                       DPRINTK("TOR version error for 40MHz clock selection\n");
+                               i_ReturnValue = -9;
+                               }
+                            }
+                         else
+                            {
+                            /**************************************************************/
+                            /* You can not used the 40MHz clock selection wich this board */
+                            /**************************************************************/
+
+                                DPRINTK("You can not used the 40MHz clock selection wich this board\n");
+                            i_ReturnValue = -8;
+                            }
+                         }
+                      else
+                         {
+                         /**********************************/
+                         /* Base timing selection is wrong */
+                         /**********************************/
+
+                         DPRINTK("Base timing selection is wrong\n");
+                         i_ReturnValue = -7;
+                         }
+                      } // if ((b_TimingUnit >= 0) && (b_TimingUnit <= 4))
+                   else
+                      {
+                      /***********************************/
+                      /* Timing unity selection is wrong */
+                      /***********************************/
+
+                          DPRINTK("Timing unity selection is wrong\n");
+                      i_ReturnValue = -6;
+                      } // if ((b_TimingUnit >= 0) && (b_TimingUnit <= 4))
+                   } // if ((b_PCIInputClock == APCI1710_30MHZ) || (b_PCIInputClock == APCI1710_33MHZ))
+                else
+                   {
+                   /*****************************************/
+                   /* The selected PCI input clock is wrong */
+                   /*****************************************/
+
+                       DPRINTK("The selected PCI input clock is wrong\n");
+                   i_ReturnValue = -5;
+                   } // if ((b_PCIInputClock == APCI1710_30MHZ) || (b_PCIInputClock == APCI1710_33MHZ))
+                } // if (b_ChronoMode >= 0 && b_ChronoMode <= 7)
+             else
+                {
+                /***************************************/
+                /* Chronometer mode selection is wrong */
+                /***************************************/
+               
+DPRINTK("Chronometer mode selection is wrong\n");
+                i_ReturnValue = -4;
+                } // if (b_ChronoMode >= 0 && b_ChronoMode <= 7)
+             }
+          else
+             {
+             /******************************************/
+             /* The module is not a Chronometer module */
+             /******************************************/
+
+             DPRINTK("The module is not a Chronometer module\n");
+             i_ReturnValue = -3;
+             }
+          }
+       else
+          {
+          /***********************/
+          /* Module number error */
+          /***********************/
+
+          DPRINTK("Module number error\n");
+          i_ReturnValue = -2;
+          }
+       data[0] = ul_RealTimingInterval;
+       return (i_ReturnValue);
+       }
+
+
+
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     : _INT_ i_APCI1710_EnableChrono                          |
+|                                               (BYTE_ b_BoardHandle,        |
+|                                                BYTE_ b_ModulNbr,           |
+|                                                BYTE_ b_CycleMode,          |
+|                                                BYTE_ b_InterruptEnable)
+INT i_APCI1710_InsnWriteEnableDisableChrono(comedi_device *dev,
+comedi_subdevice *s,comedi_insn *insn,lsampl_t *data)                                           |
++----------------------------------------------------------------------------+
+| Task              : Enable the chronometer from selected module            |
+|                     (b_ModulNbr). You must calling the                     |
+|                     "i_APCI1710_InitChrono" function be for you call this  |
+|                     function.                                              |
+|                     If you enable the chronometer interrupt, the           |
+|                     chronometer generate a interrupt after the stop signal.|
+|                     See function "i_APCI1710_SetBoardIntRoutineX" and the  |
+|                     Interrupt mask description chapter from this manual.   |
+|                     The b_CycleMode parameter determine if you will        |
+|                     measured a single or more cycle. 
+
+|                                        Disable the chronometer from selected module           |
+|                     (b_ModulNbr). If you disable the chronometer after a   |
+|                     start signal occur and you restart the chronometer     |
+|                     witch the " i_APCI1710_EnableChrono" function, if no   |
+|                     stop signal occur this start signal is ignored.   
++----------------------------------------------------------------------------+
+| Input Parameters  : BYTE_ b_BoardHandle  : Handle of board APCI-1710       |
+|                     BYTE_ b_ModulNbr   CR_AREF(chanspec)  : Selected module number (0 to 3) |
+                                  data[0]  ENABle/Disable chrono
+|                     BYTE_ b_CycleMode    : Selected the chronometer        |
+|                                  data[1]           acquisition mode                |
+|                     BYTE_ b_InterruptEnable : Enable or disable the        |
+|                                   data[2]            chronometer interrupt.       |
+|                                               APCI1710_ENABLE:             |
+|                                               Enable the chronometer       |
+|                                               interrupt                    |
+|                                               APCI1710_DISABLE:            |
+|                                               Disable the chronometer      |
+|                                               interrupt                    |
++----------------------------------------------------------------------------+
+| Output Parameters : -                                                      |
++----------------------------------------------------------------------------+
+| 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 not initialised see function           |
+|                         "i_APCI1710_InitChrono"                            |
+|                     -5: Chronometer acquisition mode cycle is wrong        |
+|                     -6: Interrupt parameter is wrong                       |
+|                     -7: Interrupt function not initialised.                |
+|                         See function "i_APCI1710_SetBoardIntRoutineX"  
+                      -8: data[0] wrong input    |
++----------------------------------------------------------------------------+
+*/
+
+
+INT i_APCI1710_InsnWriteEnableDisableChrono(comedi_device *dev,comedi_subdevice *s,
+       comedi_insn *insn,lsampl_t *data)
+       {
+       INT i_ReturnValue = 0;
+       BYTE b_ModulNbr,b_CycleMode,b_InterruptEnable,b_Action;
+       b_ModulNbr                      =       CR_AREF(insn->chanspec);
+        b_Action            =(BYTE) data[0];
+       b_CycleMode                     =(BYTE) data[1];
+       b_InterruptEnable       =(BYTE) data[2];
+       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 if chronometer initialised */
+             /***********************************/
+
+             if (devpriv->s_ModuleInfo [b_ModulNbr].
+                 s_ChronoModuleInfo.
+                 b_ChronoInit == 1)
+                {
+
+
+         switch(b_Action)
+         {
+                case APCI1710_ENABLE :
+                            
+                /*********************************/
+                /* Test the cycle mode parameter */
+                /*********************************/
+
+                if ((b_CycleMode == APCI1710_SINGLE) || (b_CycleMode == APCI1710_CONTINUOUS))
+                   {
+                   /***************************/
+                   /* Test the interrupt flag */
+                   /***************************/
+
+                   if ((b_InterruptEnable == APCI1710_ENABLE) || (b_InterruptEnable == APCI1710_DISABLE))
+                      {
+                   
+       
+                         /***************************/
+                         /* Save the interrupt flag */
+                         /***************************/
+
+                         devpriv->s_ModuleInfo [b_ModulNbr].
+                         s_ChronoModuleInfo.
+                         b_InterruptMask = b_InterruptEnable;
+
+                         /***********************/
+                         /* Save the cycle mode */
+                         /***********************/
+
+                         devpriv->s_ModuleInfo [b_ModulNbr].
+                         s_ChronoModuleInfo.
+                         b_CycleMode = b_CycleMode;
+
+                         devpriv->s_ModuleInfo [b_ModulNbr].
+                         s_ChronoModuleInfo.
+                         dw_ConfigReg = (devpriv->s_ModuleInfo [b_ModulNbr].
+                                         s_ChronoModuleInfo.
+                                         dw_ConfigReg & 0x8F)           |
+                                         ((1 & b_InterruptEnable) << 5) |
+                                         ((1 & b_CycleMode) << 6)       |
+                                         0x10 ;
+
+                         /*****************************/
+                         /* Test if interrupt enabled */
+                         /*****************************/
+
+                         if (b_InterruptEnable == APCI1710_ENABLE)
+                            {
+                            /****************************/
+                            /* Clear the interrupt flag */
+                            /****************************/
+
+                           
+                                outl(devpriv->s_ModuleInfo [b_ModulNbr].
+                                    s_ChronoModuleInfo.dw_ConfigReg, devpriv->s_BoardInfos.
+                                    ui_Address + 32 + (64 * b_ModulNbr));
+                         devpriv->tsk_Current=current; // Save the current process task structure
+                            }
+
+                         /***********************************/
+                         /* Enable or disable the interrupt */
+                         /* Enable the chronometer          */
+                         /***********************************/
+           
+                         outl(devpriv->s_ModuleInfo [b_ModulNbr].
+                                 s_ChronoModuleInfo.dw_ConfigReg,devpriv->s_BoardInfos.
+                                 ui_Address + 16 + (64 * b_ModulNbr));
+
+                         /*************************/
+                         /* Clear status register */
+                         /*************************/
+
+                        
+                         outl(0,devpriv->s_BoardInfos.ui_Address + 36 + (64 * b_ModulNbr));
+                         
+                   } // if ((b_InterruptEnable == APCI1710_ENABLE) || (b_InterruptEnable == APCI1710_DISABLE))
+                   else
+                      {
+                      /********************************/
+                      /* Interrupt parameter is wrong */
+                      /********************************/
+
+                          DPRINTK("Interrupt parameter is wrong\n");
+                      i_ReturnValue = -6;
+                      } // if ((b_InterruptEnable == APCI1710_ENABLE) || (b_InterruptEnable == APCI1710_DISABLE))
+                   } // if ((b_CycleMode == APCI1710_SINGLE) || (b_CycleMode == APCI1710_CONTINUOUS))
+                else
+                   {
+                   /***********************************************/
+                   /* Chronometer acquisition mode cycle is wrong */
+                   /***********************************************/
+
+                       DPRINTK("Chronometer acquisition mode cycle is wrong\n");
+                   i_ReturnValue = -5;
+                   } // if ((b_CycleMode == APCI1710_SINGLE) || (b_CycleMode == APCI1710_CONTINUOUS))
+                break;
+
+                case APCI1710_DISABLE :
+
+                devpriv->s_ModuleInfo [b_ModulNbr].
+                s_ChronoModuleInfo.
+                b_InterruptMask = 0;
+
+                devpriv->s_ModuleInfo [b_ModulNbr].
+                s_ChronoModuleInfo.
+                dw_ConfigReg = devpriv->s_ModuleInfo [b_ModulNbr].
+                               s_ChronoModuleInfo.
+                               dw_ConfigReg & 0x2F;
+
+                /***************************/
+                /* Disable the interrupt   */
+                /* Disable the chronometer */
+                /***************************/
+
+                
+                outl(devpriv->s_ModuleInfo [b_ModulNbr].
+                        s_ChronoModuleInfo.dw_ConfigReg, devpriv->s_BoardInfos.
+                        ui_Address + 16 + (64 * b_ModulNbr));
+
+                /***************************/
+                /* Test if continuous mode */
+                /***************************/
+
+                if (devpriv->s_ModuleInfo [b_ModulNbr].
+                    s_ChronoModuleInfo.b_CycleMode == APCI1710_CONTINUOUS)
+                   {
+                   /*************************/
+                   /* Clear status register */
+                   /*************************/
+
+                  
+                       outl(0,devpriv->s_BoardInfos.ui_Address + 36 + (64 * b_ModulNbr));
+                   }
+                   break;
+
+                default:
+                         DPRINTK("Inputs wrong! Enable or Disable chrono\n");
+                         i_ReturnValue = -8;
+                 } // switch ENABLE/DISABLE
+                }
+             else
+                {
+                /*******************************/
+                /* Chronometer not initialised */
+                /*******************************/
+
+                DPRINTK("Chronometer not initialised\n");
+                i_ReturnValue = -4;
+                }
+             }
+          else
+             {
+             /******************************************/
+             /* The module is not a Chronometer module */
+             /******************************************/
+
+             DPRINTK("The module is not a Chronometer module\n");      
+             i_ReturnValue = -3;
+             }
+          }
+       else
+          {
+          /***********************/
+          /* Module number error */
+          /***********************/
+
+          DPRINTK("Module number error\n");
+          i_ReturnValue = -2;
+          }
+
+      
+       return (i_ReturnValue);
+       }
+
+
+
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     :INT       i_APCI1710_InsnReadChrono(comedi_device *dev,comedi_subdevice *s,
+comedi_insn *insn,lsampl_t *data)                   |
++----------------------------------------------------------------------------+
+| Task              : Read  functions for Timer                                     |
++----------------------------------------------------------------------------+
+| Input Parameters  : 
++----------------------------------------------------------------------------+
+| Output Parameters : -                                                      |
++----------------------------------------------------------------------------+
+| Return Value      : 
++----------------------------------------------------------------------------+
+*/
+
+INT    i_APCI1710_InsnReadChrono(comedi_device *dev,comedi_subdevice *s,
+comedi_insn *insn,lsampl_t *data)
+{
+       BYTE b_ReadType;
+       INT  i_ReturnValue=insn->n;
+        
+       b_ReadType=CR_CHAN(insn->chanspec);
+
+       switch(b_ReadType)
+       {
+       case APCI1710_CHRONO_PROGRESS_STATUS:
+               i_ReturnValue=i_APCI1710_GetChronoProgressStatus  (dev,
+                                                (BYTE)    CR_AREF(insn->chanspec),
+                                                (PBYTE)  &data[0]);
+       break;
+
+       case APCI1710_CHRONO_READVALUE:
+               i_ReturnValue=i_APCI1710_ReadChronoValue      (dev,
+                                        (BYTE)    CR_AREF(insn->chanspec),
+                                        (UINT)    insn->unused[0],
+                                        (PBYTE)   &data[0],
+                                        (PULONG) &data[1]);
+       break;
+
+       case APCI1710_CHRONO_CONVERTVALUE:
+               i_ReturnValue=i_APCI1710_ConvertChronoValue     (dev,
+                                        (BYTE)    CR_AREF(insn->chanspec),
+                                        (ULONG)   insn->unused[0],
+                                        (PULONG)  &data[0],
+                                        (PBYTE)   &data[1],
+                                        (PBYTE)   &data[2],
+                                        (PUINT)  &data[3],
+                                        (PUINT)  &data[4],
+                                        (PUINT)  &data[5]);
+       break;
+        
+        case APCI1710_CHRONO_READINTERRUPT:
+                         printk("In Chrono Read Interrupt\n");
+
+                         data[0]=devpriv->s_InterruptParameters.
+                                                     s_FIFOInterruptParameters [devpriv->
+                                                                                s_InterruptParameters.
+                                                                                ui_Read].b_OldModuleMask;
+                         data[1]=devpriv->s_InterruptParameters.
+                                                     s_FIFOInterruptParameters [devpriv->
+                                                                                s_InterruptParameters.
+                                                                                ui_Read].ul_OldInterruptMask;
+                         data[2]=devpriv->s_InterruptParameters.
+                                                     s_FIFOInterruptParameters [devpriv->
+                                                                                s_InterruptParameters.
+                                                                                ui_Read].ul_OldCounterLatchValue;
+
+                            
+                            /**************************/
+                            /* Increment the read FIFO */
+                            /***************************/
+
+                            devpriv->
+                            s_InterruptParameters.
+                            ui_Read = (devpriv->
+                                       s_InterruptParameters.
+                                       ui_Read + 1) % APCI1710_SAVE_INTERRUPT;
+        break;
+    
+       default:
+               printk("ReadType Parameter wrong\n");
+       }
+
+       if(i_ReturnValue>=0) i_ReturnValue =insn->n;
+       return (i_ReturnValue); 
+
+}
+
+
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     : _INT_ i_APCI1710_GetChronoProgressStatus               |
+|                               (BYTE_    b_BoardHandle,                     |
+|                                BYTE_    b_ModulNbr,                        |
+|                                PBYTE_  pb_ChronoStatus)                    |
++----------------------------------------------------------------------------+
+| Task              : Return the chronometer status (pb_ChronoStatus) from   |
+|                     selected chronometer module (b_ModulNbr).              |
++----------------------------------------------------------------------------+
+| Input Parameters  : BYTE_ b_BoardHandle  : Handle of board APCI-1710       |
+|                     BYTE_ b_ModulNbr     : Selected module number (0 to 3) |
++----------------------------------------------------------------------------+
+| Output Parameters : PULONG_  pb_ChronoStatus : Return the chronometer      |
+|                                                status.                     |
+|                                                0 : Measurement not started.|
+|                                                    No start signal occur.  |
+|                                                1 : Measurement started.    |
+|                                                    A start signal occur.   |
+|                                                2 : Measurement stopped.    |
+|                                                    A stop signal occur.    |
+|                                                    The measurement is      |
+|                                                    terminate.              |
+|                                                3: A overflow occur. You    |
+|                                                   must change the base     |
+|                                                   timing witch the         |
+|                                                   function                 |
+|                                                   "i_APCI1710_InitChrono"  |
++----------------------------------------------------------------------------+
+| 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 not initialised see function           |
+|                         "i_APCI1710_InitChrono"                            |
++----------------------------------------------------------------------------+
+*/
+
+INT   i_APCI1710_GetChronoProgressStatus      (comedi_device *dev,
+                                                BYTE    b_ModulNbr,
+                                                PBYTE  pb_ChronoStatus)
+       {
+       INT    i_ReturnValue = 0;
+       DWORD dw_Status;
+       
+       /**************************/
+       /* Test the module number */
+       /**************************/
+
+       if (b_ModulNbr < 4)
+          {
+          /***********************/
+          /* Test if chronometer */
+          /***********************/
+
+          if ((devpriv->
+               s_BoardInfos.
+               dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_CHRONOMETER)
+             {
+             /***********************************/
+             /* Test if chronometer initialised */
+             /***********************************/
+
+             if (devpriv->
+                 s_ModuleInfo [b_ModulNbr].
+                 s_ChronoModuleInfo.
+                 b_ChronoInit == 1)
+                {
+               
+               dw_Status=inl(devpriv->s_BoardInfos.
+                       ui_Address + 8 + (64 * b_ModulNbr));
+
+                /********************/
+                /* Test if overflow */
+                /********************/
+
+                if ((dw_Status & 8) == 8)
+                   {
+                   /******************/
+                   /* Overflow occur */
+                   /******************/
+
+                   *pb_ChronoStatus = 3;
+                   } // if ((dw_Status & 8) == 8)
+                else
+                   {
+                   /*******************************/
+                   /* Test if measurement stopped */
+                   /*******************************/
+
+                   if ((dw_Status & 2) == 2)
+                      {
+                      /***********************/
+                      /* A stop signal occur */
+                      /***********************/
+
+                      *pb_ChronoStatus = 2;
+                      } // if ((dw_Status & 2) == 2)
+                   else
+                      {
+                      /*******************************/
+                      /* Test if measurement started */
+                      /*******************************/
+
+                      if ((dw_Status & 1) == 1)
+                         {
+                         /************************/
+                         /* A start signal occur */
+                         /************************/
+
+                         *pb_ChronoStatus = 1;
+                         } // if ((dw_Status & 1) == 1)
+                      else
+                         {
+                         /***************************/
+                         /* Measurement not started */
+                         /***************************/
+
+                         *pb_ChronoStatus = 0;
+                         } // if ((dw_Status & 1) == 1)
+                      } // if ((dw_Status & 2) == 2)
+                   } // if ((dw_Status & 8) == 8)
+                }
+             else
+                {
+                /*******************************/
+                /* Chronometer not initialised */
+                /*******************************/
+                DPRINTK("Chronometer not initialised\n");
+                i_ReturnValue = -4;
+                }
+             }
+          else
+             {
+             /******************************************/
+             /* The module is not a Chronometer module */
+             /******************************************/
+              DPRINTK("The module is not a Chronometer module\n");
+             i_ReturnValue = -3;
+             }
+          }
+       else
+          {
+          /***********************/
+          /* Module number error */
+          /***********************/
+          DPRINTK("Module number error\n");
+          i_ReturnValue = -2;
+          }
+
+       return (i_ReturnValue);
+       }
+
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     : _INT_ i_APCI1710_ReadChronoValue                       |
+|                               (BYTE_     b_BoardHandle,                    |
+|                                BYTE_     b_ModulNbr,                       |
+|                                UINT_    ui_TimeOut,                        |
+|                                PBYTE_   pb_ChronoStatus,                   |
+|                                PULONG_ pul_ChronoValue)                    |
++----------------------------------------------------------------------------+
+| Task              : Return the chronometer status (pb_ChronoStatus) and the|
+|                     timing value (pul_ChronoValue) after a stop signal     |
+|                     occur from selected chronometer module (b_ModulNbr).   |
+|                     This function are only avaible if you have disabled    |
+|                     the interrupt functionality. See function              |
+|                     "i_APCI1710_EnableChrono" and the Interrupt mask       |
+|                     description chapter.                                   |
+|                     You can test the chronometer status witch the          |
+|                     "i_APCI1710_GetChronoProgressStatus" function.         |
+|                                                                            |
+|                     The returned value from pul_ChronoValue parameter is   |
+|                     not real measured timing.                              |
+|                     You must used the "i_APCI1710_ConvertChronoValue"      |
+|                     function or make this operation for calculate the      |
+|                     timing:                                                |
+|                                                                            |
+|                     Timing = pul_ChronoValue * pul_RealTimingInterval.     |
+|                                                                            |
+|                     pul_RealTimingInterval is the returned parameter from  |
+|                     "i_APCI1710_InitChrono" function and the time unity is |
+|                     the b_TimingUnit from "i_APCI1710_InitChrono" function|
++----------------------------------------------------------------------------+
+| Input Parameters  : BYTE_ b_BoardHandle  : Handle of board APCI-1710       |
+|                     BYTE_ b_ModulNbr     : Selected module number (0 to 3) |
++----------------------------------------------------------------------------+
+| Output Parameters : PULONG_  pb_ChronoStatus : Return the chronometer      |
+|                                                status.                     |
+|                                                0 : Measurement not started.|
+|                                                    No start signal occur.  |
+|                                                1 : Measurement started.    |
+|                                                    A start signal occur.   |
+|                                                2 : Measurement stopped.    |
+|                                                    A stop signal occur.    |
+|                                                    The measurement is      |
+|                                                    terminate.              |
+|                                                3: A overflow occur. You    |
+|                                                   must change the base     |
+|                                                   timing witch the         |
+|                                                   function                 |
+|                                                   "i_APCI1710_InitChrono"  |
+|                     PULONG  pul_ChronoValue  : Chronometer timing 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 Chronometer module             |
+|                     -4: Chronometer not initialised see function           |
+|                         "i_APCI1710_InitChrono"                            |
+|                     -5: Timeout parameter is wrong (0 to 65535)            |
+|                     -6: Interrupt routine installed. You can not read      |
+|                         directly the chronometer measured timing.          |
++----------------------------------------------------------------------------+
+*/
+
+INT   i_APCI1710_ReadChronoValue      (comedi_device *dev,
+                                        BYTE     b_ModulNbr,
+                                        UINT    ui_TimeOut,
+                                        PBYTE   pb_ChronoStatus,
+                                        PULONG pul_ChronoValue)
+       {
+       INT    i_ReturnValue = 0;
+       DWORD dw_Status;
+       DWORD dw_TimeOut = 0;
+       
+
+       /**************************/
+       /* Test the module number */
+       /**************************/
+
+       if (b_ModulNbr < 4)
+          {
+          /***********************/
+          /* Test if chronometer */
+          /***********************/
+
+          if ((devpriv->
+               s_BoardInfos.
+               dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_CHRONOMETER)
+             {
+             /***********************************/
+             /* Test if chronometer initialised */
+             /***********************************/
+
+             if (devpriv->
+                 s_ModuleInfo [b_ModulNbr].
+                 s_ChronoModuleInfo.
+                 b_ChronoInit == 1)
+                {
+                /*****************************/
+                /* Test the timout parameter */
+                /*****************************/
+
+                if ((ui_TimeOut >= 0) && (ui_TimeOut <= 65535UL))
+                   {
+                  
+                      for (;;)
+                         {
+                         /*******************/
+                         /* Read the status */
+                         /*******************/
+
+                        
+                               dw_Status=inl(devpriv->s_BoardInfos.
+                                ui_Address + 8 + (64 * b_ModulNbr));
+
+
+                         /********************/
+                         /* Test if overflow */
+                         /********************/
+
+                         if ((dw_Status & 8) == 8)
+                            {
+                            /******************/
+                            /* Overflow occur */
+                            /******************/
+
+                            *pb_ChronoStatus = 3;
+
+                            /***************************/
+                            /* Test if continuous mode */
+                            /***************************/
+
+                            if (devpriv->s_ModuleInfo [b_ModulNbr].
+                                s_ChronoModuleInfo.
+                                b_CycleMode == APCI1710_CONTINUOUS)
+                               {
+                               /*************************/
+                               /* Clear status register */
+                               /*************************/
+
+                               
+                                        outl(0,devpriv->s_BoardInfos.
+                                       ui_Address + 36 + (64 * b_ModulNbr));
+                               }
+
+                            break;
+                            } // if ((dw_Status & 8) == 8)
+                         else
+                            {
+                            /*******************************/
+                            /* Test if measurement stopped */
+                            /*******************************/
+
+                            if ((dw_Status & 2) == 2)
+                               {
+                               /***********************/
+                               /* A stop signal occur */
+                               /***********************/
+
+                               *pb_ChronoStatus = 2;
+
+                               /***************************/
+                               /* Test if continnous mode */
+                               /***************************/
+
+                               if (devpriv->
+                                   s_ModuleInfo [b_ModulNbr].
+                                   s_ChronoModuleInfo.
+                                   b_CycleMode == APCI1710_CONTINUOUS)
+                                  {
+                                  /*************************/
+                                  /* Clear status register */
+                                  /*************************/
+
+                                  
+                                       outl(0,devpriv->s_BoardInfos.
+                                          ui_Address + 36 + (64 * b_ModulNbr));
+                                  }
+                               break;
+                               } // if ((dw_Status & 2) == 2)
+                            else
+                               {
+                               /*******************************/
+                               /* Test if measurement started */
+                               /*******************************/
+
+                               if ((dw_Status & 1) == 1)
+                                  {
+                                  /************************/
+                                  /* A start signal occur */
+                                  /************************/
+
+                                  *pb_ChronoStatus = 1;
+                                  } // if ((dw_Status & 1) == 1)
+                               else
+                                  {
+                                  /***************************/
+                                  /* Measurement not started */
+                                  /***************************/
+
+                                  *pb_ChronoStatus = 0;
+                                  } // if ((dw_Status & 1) == 1)
+                               } // if ((dw_Status & 2) == 2)
+                            } // if ((dw_Status & 8) == 8)
+
+                         if (dw_TimeOut == ui_TimeOut)
+                            {
+                            /*****************/
+                            /* Timeout occur */
+                            /*****************/
+
+                            break;
+                            }
+                         else
+                            {
+                            /*************************/
+                            /* Increment the timeout */
+                            /*************************/
+
+                            dw_TimeOut = dw_TimeOut + 1;
+                                mdelay(1000);
+                           
+                               }
+                         } // for (;;)
+
+                      /*****************************/
+                      /* Test if stop signal occur */
+                      /*****************************/
+
+                      if (*pb_ChronoStatus == 2)
+                         {
+                         /**********************************/
+                         /* Read the measured timing value */
+                         /**********************************/
+
+                         
+                               *pul_ChronoValue= inl(devpriv->s_BoardInfos.
+                                ui_Address + 4 + (64 * b_ModulNbr));
+
+                         if (*pul_ChronoValue != 0)
+                            {
+                            *pul_ChronoValue = *pul_ChronoValue - 1;
+                            }
+                         }
+                      else
+                         {
+                         /*************************/
+                         /* Test if timeout occur */
+                         /*************************/
+
+                         if ((*pb_ChronoStatus != 3) && (dw_TimeOut == ui_TimeOut) && (ui_TimeOut != 0))
+                            {
+                            /*****************/
+                            /* Timeout occur */
+                            /*****************/
+
+                            *pb_ChronoStatus = 4;
+                            }
+                         }
+                    
+                   }
+                else
+                   {
+                   /******************************/
+                   /* Timeout parameter is wrong */
+                   /******************************/
+                    DPRINTK("Timeout parameter is wrong\n");
+                   i_ReturnValue = -5;
+                   }
+                }
+             else
+                {
+                /*******************************/
+                /* Chronometer not initialised */
+                /*******************************/
+                DPRINTK("Chronometer not initialised\n");
+                i_ReturnValue = -4;
+                }
+             }
+          else
+             {
+             /******************************************/
+             /* The module is not a Chronometer module */
+             /******************************************/
+             DPRINTK("The module is not a Chronometer module\n");      
+             i_ReturnValue = -3;
+             }
+          }
+       else
+          {
+          /***********************/
+          /* Module number error */
+          /***********************/
+          DPRINTK("Module number error\n");
+          i_ReturnValue = -2;
+          }
+
+       return (i_ReturnValue);
+       }
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     : _INT_ i_APCI1710_ConvertChronoValue                    |
+|                               (BYTE_     b_BoardHandle,                    |
+|                                BYTE_     b_ModulNbr,                       |
+|                                ULONG_   ul_ChronoValue,                    |
+|                                PULONG_ pul_Hour,                           |
+|                                PBYTE_   pb_Minute,                         |
+|                                PBYTE_   pb_Second,                         |
+|                                PUINT_  pui_MilliSecond,                    |
+|                                PUINT_  pui_MicroSecond,                    |
+|                                PUINT_  pui_NanoSecond)                     |
++----------------------------------------------------------------------------+
+| Task              : Convert the chronometer measured timing                |
+|                     (ul_ChronoValue) in to h, mn, s, ms, µs, ns.           |
++----------------------------------------------------------------------------+
+| Input Parameters  : BYTE_   b_BoardHandle : Handle of board APCI-1710      |
+|                     BYTE_   b_ModulNbr    : Selected module number (0 to 3)|
+|                     ULONG_ ul_ChronoValue : Measured chronometer timing    |
+|                                             value.                         |
+|                                             See"i_APCI1710_ReadChronoValue"|
++----------------------------------------------------------------------------+
+| Output Parameters : PULONG_   pul_Hour        : Chronometer timing hour    |
+|                     PBYTE_     pb_Minute      : Chronometer timing minute  |
+|                     PBYTE_     pb_Second      : Chronometer timing second  |
+|                     PUINT_    pui_MilliSecond  : Chronometer timing mini   |
+|                                                 second                     |
+|                     PUINT_    pui_MicroSecond : Chronometer timing micro   |
+|                                                 second                     |
+|                     PUINT_    pui_NanoSecond  : Chronometer timing nano    |
+|                                                 second                     |
++----------------------------------------------------------------------------+
+| 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 not initialised see function           |
+|                         "i_APCI1710_InitChrono"                            |
++----------------------------------------------------------------------------+
+*/
+
+INT i_APCI1710_ConvertChronoValue     (comedi_device *dev,
+                                        BYTE     b_ModulNbr,
+                                        ULONG   ul_ChronoValue,
+                                        PULONG pul_Hour,
+                                        PBYTE   pb_Minute,
+                                        PBYTE   pb_Second,
+                                        PUINT  pui_MilliSecond,
+                                        PUINT  pui_MicroSecond,
+                                        PUINT  pui_NanoSecond)
+       {
+       INT    i_ReturnValue = 0;
+       double d_Hour;
+       double d_Minute;
+       double d_Second;
+       double d_MilliSecond;
+       double d_MicroSecond;
+       double d_NanoSecond;
+       
+       /**************************/
+       /* Test the module number */
+       /**************************/
+
+       if (b_ModulNbr < 4)
+          {
+          /***********************/
+          /* Test if chronometer */
+          /***********************/
+
+          if ((devpriv->
+               s_BoardInfos.
+               dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_CHRONOMETER)
+             {
+             /***********************************/
+             /* Test if chronometer initialised */
+             /***********************************/
+
+             if (devpriv->
+                 s_ModuleInfo [b_ModulNbr].
+                 s_ChronoModuleInfo.
+                 b_ChronoInit == 1)
+                {
+                fpu_begin ();
+                
+                   d_Hour = (double) ul_ChronoValue * (double) devpriv->
+                                                               s_ModuleInfo [b_ModulNbr].
+                                                               s_ChronoModuleInfo.
+                                                               d_TimingInterval;
+
+                   switch (devpriv->
+                           s_ModuleInfo [b_ModulNbr].
+                           s_ChronoModuleInfo.
+                           b_TimingUnit)
+                      {
+                      case 0:
+                           d_Hour = d_Hour / (double) 1000.0;
+
+                      case 1:
+                           d_Hour = d_Hour / (double) 1000.0;
+
+                      case 2:
+                           d_Hour = d_Hour / (double) 1000.0;
+
+                      case 3:
+                           d_Hour = d_Hour / (double) 60.0;
+
+                      case 4:
+                           /**********************/
+                           /* Calculate the hour */
+                           /**********************/
+
+                           d_Hour    = d_Hour / (double) 60.0;
+                           *pul_Hour = (ULONG) d_Hour;
+
+                           /************************/
+                           /* Calculate the minute */
+                           /************************/
+
+                           d_Minute   = d_Hour - *pul_Hour;
+                           d_Minute   = d_Minute * 60;
+                           *pb_Minute = (BYTE) d_Minute;
+
+                           /************************/
+                           /* Calculate the second */
+                           /************************/
+
+                           d_Second   = d_Minute - *pb_Minute;
+                           d_Second   = d_Second * 60;
+                           *pb_Second = (BYTE) d_Second;
+
+                           /*****************************/
+                           /* Calculate the mini second */
+                           /*****************************/
+
+                           d_MilliSecond    = d_Second - *pb_Second;
+                           d_MilliSecond    = d_MilliSecond * 1000;
+                           *pui_MilliSecond = (UINT) d_MilliSecond;
+
+                           /******************************/
+                           /* Calculate the micro second */
+                           /******************************/
+
+                           d_MicroSecond    = d_MilliSecond - *pui_MilliSecond;
+                           d_MicroSecond    = d_MicroSecond * 1000;
+                           *pui_MicroSecond = (UINT) d_MicroSecond;
+
+                           /******************************/
+                           /* Calculate the micro second */
+                           /******************************/
+
+                           d_NanoSecond    = d_MicroSecond - *pui_MicroSecond;
+                           d_NanoSecond    = d_NanoSecond * 1000;
+                           *pui_NanoSecond = (UINT) d_NanoSecond;
+                           break;
+                      }
+                   
+                fpu_end ();
+                }
+             else
+                {
+                /*******************************/
+                /* Chronometer not initialised */
+                /*******************************/
+                DPRINTK("Chronometer not initialised\n");
+                i_ReturnValue = -4;
+                }
+             }
+          else
+             {
+             /******************************************/
+             /* The module is not a Chronometer module */
+             /******************************************/
+             DPRINTK("The module is not a Chronometer module\n");      
+             i_ReturnValue = -3;
+             }
+          }
+       else
+          {
+          /***********************/
+          /* Module number error */
+          /***********************/
+          DPRINTK("Module number error\n");    
+          i_ReturnValue = -2;
+          }
+
+       return (i_ReturnValue);
+       }
+
+
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     : INT i_APCI1710_InsnBitsChronoDigitalIO(comedi_device *dev,comedi_subdevice *s,
+       comedi_insn *insn,lsampl_t *data)                    |
++----------------------------------------------------------------------------+
+| Task              : Sets the output witch has been passed with the         |
+|                     parameter b_Channel. Setting an output means setting an|
+|                     output high.                                           |
++----------------------------------------------------------------------------+
+| Input Parameters  : BYTE_ b_BoardHandle   : Handle of board APCI-1710      |
+|                     BYTE_ b_ModulNbr      : Selected module number (0 to 3)|
+|                     BYTE_ b_OutputChannel : Selection from digital output  |
+|                           CR_CHAN()                  channel (0 to 2)               |
+|                                              0 : Channel H                 |
+|                                              1 : Channel A                 |
+|                                              2 : Channel B                 |
++----------------------------------------------------------------------------+
+| Output Parameters : -                                                      |
++----------------------------------------------------------------------------+
+| 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: The selected digital output is wrong               |
+|                     -5: Chronometer not initialised see function           |
+|                         "i_APCI1710_InitChrono"                            |
++----------------------------------------------------------------------------+
+*/
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     : _INT_ i_APCI1710_SetChronoChlOff                       |
+|                               (BYTE_  b_BoardHandle,                       |
+|                                BYTE_  b_ModulNbr,                          |
+|                                BYTE_  b_OutputChannel)                     |
++----------------------------------------------------------------------------+
+| Task              : Resets the output witch has been passed with the       |
+|                     parameter b_Channel. Resetting an output means setting |
+|                     an output low.                                         |
++----------------------------------------------------------------------------+
+| Input Parameters  : BYTE_ b_BoardHandle   : Handle of board APCI-1710 
+                        data[0] : Chl ON, Chl OFF , Chl Read , Port Read 
+                                                        
+|                     BYTE_ b_ModulNbr  CR_AREF    : Selected module number (0 to 3)|
+|                     BYTE_ b_OutputChannel CR_CHAN : Selection from digital output  |
+|                                             channel (0 to 2)               |
+|                                              0 : Channel H                 |
+|                                              1 : Channel A                 |
+|                                              2 : Channel B                 |
++----------------------------------------------------------------------------+
+| Output Parameters : -                                                      |
++----------------------------------------------------------------------------+
+| 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: The selected digital output is wrong               |
+|                     -5: Chronometer not initialised see function           |
+|                         "i_APCI1710_InitChrono"                            |
++----------------------------------------------------------------------------+
+*/
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     : _INT_ i_APCI1710_ReadChronoChlValue                    |
+|                               (BYTE_   b_BoardHandle,                      |
+|                                BYTE_   b_ModulNbr,                         |
+|                                BYTE_   b_InputChannel,                     |
+|                                PBYTE_ pb_ChannelStatus)                    |
++----------------------------------------------------------------------------+
+| Task              : Return the status from selected digital input          |
+|                     (b_InputChannel) from selected chronometer             |
+|                     module (b_ModulNbr).                                   |
++----------------------------------------------------------------------------+
+| Input Parameters  : BYTE_ b_BoardHandle   : Handle of board APCI-1710      |
+|                     BYTE_ b_ModulNbr      : Selected module number (0 to 3)|
+|                     BYTE_ b_InputChannel  : Selection from digital input   |
+|                                             channel (0 to 2)               |
+|                                   CR_CHAN()             0 : Channel E               |
+|                                                1 : Channel F               |
+|                                                2 : Channel G               |
++----------------------------------------------------------------------------+
+| Output Parameters : PBYTE_ pb_ChannelStatus : Digital input channel status.|
+|                                data[0]                0 : Channel is not active   |
+|                                                1 : Channel is active       |
++----------------------------------------------------------------------------+
+| 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: The selected digital input is wrong                |
+|                     -5: Chronometer not initialised see function           |
+|                         "i_APCI1710_InitChrono"                            |
++----------------------------------------------------------------------------+
+*/
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     : _INT_ i_APCI1710_ReadChronoPortValue                   |
+|                               (BYTE_   b_BoardHandle,                      |
+|                                BYTE_   b_ModulNbr,                         |
+|                                PBYTE_ pb_PortValue)                        |
++----------------------------------------------------------------------------+
+| Task              : Return the status from digital inputs port from        |
+|                     selected  (b_ModulNbr) chronometer module.             |
++----------------------------------------------------------------------------+
+| Input Parameters  : BYTE_ b_BoardHandle   : Handle of board APCI-1710      |
+|                     BYTE_ b_ModulNbr      : Selected module number (0 to 3)|
++----------------------------------------------------------------------------+
+| Output Parameters : PBYTE_ pb_PortValue   : Digital inputs port status.    
+|                     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 not initialised see function           |
+|                         "i_APCI1710_InitChrono"                            |
++----------------------------------------------------------------------------+
+*/
+
+
+INT i_APCI1710_InsnBitsChronoDigitalIO(comedi_device *dev,comedi_subdevice *s,
+       comedi_insn *insn,lsampl_t *data)
+       {
+       INT    i_ReturnValue = 0;
+       BYTE  b_ModulNbr,b_OutputChannel,b_InputChannel,b_IOType;
+       DWORD dw_Status;
+       PBYTE pb_ChannelStatus;
+       PBYTE pb_PortValue;
+       
+       b_ModulNbr      = CR_AREF(insn->chanspec);
+       i_ReturnValue = insn->n;
+       b_IOType   = (BYTE) data[0];
+          
+
+       
+
+       /**************************/
+       /* Test the module number */
+       /**************************/
+
+       if (b_ModulNbr < 4)
+          {
+          /***********************/
+          /* Test if chronometer */
+          /***********************/
+
+          if ((devpriv->s_BoardInfos.
+               dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_CHRONOMETER)
+             {
+             /***********************************/
+             /* Test if chronometer initialised */
+             /***********************************/
+
+             if (devpriv->s_ModuleInfo [b_ModulNbr].
+                 s_ChronoModuleInfo.
+                 b_ChronoInit == 1)
+                {
+                /***********************************/
+                /* Test the digital output channel */
+                /***********************************/
+          switch(b_IOType)
+          {
+
+                case APCI1710_CHRONO_SET_CHANNELOFF:
+
+               b_OutputChannel = (BYTE) CR_CHAN(insn->chanspec);
+                         if (b_OutputChannel <= 2)
+                   {
+                   
+             outl(0,devpriv->s_BoardInfos.ui_Address + 20 + (b_OutputChannel * 4) + (64 * b_ModulNbr));
+                   } // if ((b_OutputChannel >= 0) && (b_OutputChannel <= 2))
+                else
+                   {
+                   /****************************************/
+                   /* The selected digital output is wrong */
+                   /****************************************/
+
+                   DPRINTK("The selected digital output is wrong\n"); 
+                   i_ReturnValue = -4;
+
+                   } // if ((b_OutputChannel >= 0) && (b_OutputChannel <= 2))
+
+                 break;
+
+                 case APCI1710_CHRONO_SET_CHANNELON:
+
+                b_OutputChannel = (BYTE) CR_CHAN(insn->chanspec);
+                if (b_OutputChannel <= 2)
+                   {
+                   
+                        outl(1,devpriv->s_BoardInfos.ui_Address + 20 + (b_OutputChannel * 4) + (64 * b_ModulNbr));
+                   } // if ((b_OutputChannel >= 0) && (b_OutputChannel <= 2))
+                else
+                   {
+                   /****************************************/
+                   /* The selected digital output is wrong */
+                   /****************************************/
+
+                       DPRINTK("The selected digital output is wrong\n");
+                   i_ReturnValue = -4;
+
+                   } // if ((b_OutputChannel >= 0) && (b_OutputChannel <= 2))
+
+                       break;
+                 
+                 case APCI1710_CHRONO_READ_CHANNEL :
+                /**********************************/
+                /* Test the digital input channel */
+                /**********************************/
+                pb_ChannelStatus = (PBYTE) &data[0];
+                b_InputChannel = (BYTE) CR_CHAN(insn->chanspec);
+                
+                if (b_InputChannel <= 2)
+                   {
+                   
+                        dw_Status = inl(devpriv->s_BoardInfos.ui_Address + 12 + (64 * b_ModulNbr));
+
+                   *pb_ChannelStatus = (BYTE) (((dw_Status >> b_InputChannel) & 1) ^ 1);
+                   } // if ((b_InputChannel >= 0) && (b_InputChannel <= 2))
+                else
+                   {
+                   /***************************************/
+                   /* The selected digital input is wrong */
+                   /***************************************/
+
+                       DPRINTK("The selected digital input is wrong\n");
+                   i_ReturnValue = -4;
+                   } // if ((b_InputChannel >= 0) && (b_InputChannel <= 2))
+
+                 break;
+
+                 case APCI1710_CHRONO_READ_PORT :
+
+                       pb_PortValue = (PBYTE) &data[0];
+
+                       
+                       dw_Status = inl(devpriv->s_BoardInfos.ui_Address + 12 + (64 * b_ModulNbr));
+
+                   *pb_PortValue = (BYTE) ((dw_Status & 0x7) ^ 7);
+                         break;
+                 }
+                }
+             else
+                {
+                /*******************************/
+                /* Chronometer not initialised */
+                /*******************************/
+
+                DPRINTK("Chronometer not initialised\n");      
+                i_ReturnValue = -5;
+                }
+             }
+          else
+             {
+             /******************************************/
+             /* The module is not a Chronometer module */
+             /******************************************/
+
+             DPRINTK("The module is not a Chronometer module\n");
+             i_ReturnValue = -3;
+             }
+          }
+       else
+          {
+          /***********************/
+          /* Module number error */
+          /***********************/
+
+          DPRINTK("Module number error\n");
+          i_ReturnValue = -2;
+          }
+
+       return (i_ReturnValue);
+}
+
index e284114d51fb9150689a9b20f0a0de3e62441148..9ea0570192944d12724cdbd52b78b1ff3db9c3a0 100644 (file)
@@ -1 +1,102 @@
-/**\r@verbatim\r\rCopyright (C) 2004,2005  ADDI-DATA GmbH for the source code of this module. \r        \r        ADDI-DATA GmbH \r        Dieselstrasse 3 \r        D-77833 Ottersweier \r        Tel: +19(0)7223/9493-0 \r        Fax: +49(0)7223/9493-92 \r        http://www.addi-data-com \r        info@addi-data.com \r\rThis 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.\r\rThis 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.\r\rYou 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 USA\r\rYou shoud also find the complete GPL in the COPYING file accompanying this source code.\r\r@endverbatim\r*/\r\r\r\r#define APCI1710_30MHZ           30\r#define APCI1710_33MHZ           33\r#define APCI1710_40MHZ           40\r\r\r#define APCI1710_SINGLE     0\r#define APCI1710_CONTINUOUS 1\r\r\r#define APCI1710_CHRONO_PROGRESS_STATUS           0\r#define APCI1710_CHRONO_READVALUE                     1\r#define APCI1710_CHRONO_CONVERTVALUE          2\r#define APCI1710_CHRONO_READINTERRUPT       3\r\r#define APCI1710_CHRONO_SET_CHANNELON                  0\r#define APCI1710_CHRONO_SET_CHANNELOFF                1\r#define APCI1710_CHRONO_READ_CHANNEL          2\r#define APCI1710_CHRONO_READ_PORT                     3\r\r/*\r+----------------------------------------------------------------------------+\r|                  CHRONOMETER INISIALISATION FUNCTION   |\r+----------------------------------------------------------------------------+\r */\r\rINT i_APCI1710_InsnConfigInitChrono(comedi_device *dev,comedi_subdevice *s,\r        comedi_insn *insn,lsampl_t *data);\r\rINT i_APCI1710_InsnWriteEnableDisableChrono(comedi_device *dev,comedi_subdevice *s,\r        comedi_insn *insn,lsampl_t *data);\r\r\r/*\r+----------------------------------------------------------------------------+\r|                       CHRONOMETER READ FUNCTION                            |\r+----------------------------------------------------------------------------+\r*/\r\rINT    i_APCI1710_InsnReadChrono(comedi_device *dev,comedi_subdevice *s,\rcomedi_insn *insn,lsampl_t *data);\r\r\rINT   i_APCI1710_GetChronoProgressStatus      (comedi_device *dev,\r                                               BYTE    b_ModulNbr,\r                                            PBYTE  pb_ChronoStatus);\r\rINT   i_APCI1710_ReadChronoValue      (comedi_device *dev,\r                                   BYTE     b_ModulNbr,\r                                   UINT    ui_TimeOut,\r                                    PBYTE   pb_ChronoStatus,\r                                       PULONG pul_ChronoValue);\r\rINT i_APCI1710_ConvertChronoValue     (comedi_device *dev,\r                                   BYTE     b_ModulNbr,\r                                   ULONG   ul_ChronoValue,\r                                        PULONG pul_Hour,\r                                       PBYTE   pb_Minute,\r                                     PBYTE   pb_Second,\r                                     PUINT  pui_MilliSecond,\r                                        PUINT  pui_MicroSecond,\r                                        PUINT  pui_NanoSecond);\r\r\r\r\r\r/*\r+----------------------------------------------------------------------------+\r|                       CHRONOMETER DIGITAL INPUT OUTPUT FUNCTION                  |\r+----------------------------------------------------------------------------+\r*/\r\rINT i_APCI1710_InsnBitsChronoDigitalIO(comedi_device *dev,comedi_subdevice *s,\r comedi_insn *insn,lsampl_t *data);\r\r\r
\ No newline at end of file
+/**
+@verbatim
+
+Copyright (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 USA
+
+You shoud also find the complete GPL in the COPYING file accompanying this source code.
+
+@endverbatim
+*/
+
+
+
+#define APCI1710_30MHZ           30
+#define APCI1710_33MHZ           33
+#define APCI1710_40MHZ           40
+
+
+#define APCI1710_SINGLE     0
+#define APCI1710_CONTINUOUS 1
+
+
+#define APCI1710_CHRONO_PROGRESS_STATUS                0
+#define APCI1710_CHRONO_READVALUE                      1
+#define APCI1710_CHRONO_CONVERTVALUE           2
+#define APCI1710_CHRONO_READINTERRUPT       3
+
+#define APCI1710_CHRONO_SET_CHANNELON                  0
+#define APCI1710_CHRONO_SET_CHANNELOFF         1
+#define APCI1710_CHRONO_READ_CHANNEL           2
+#define APCI1710_CHRONO_READ_PORT                      3
+
+/*
++----------------------------------------------------------------------------+
+|                  CHRONOMETER INISIALISATION FUNCTION   |
++----------------------------------------------------------------------------+
+ */
+
+INT i_APCI1710_InsnConfigInitChrono(comedi_device *dev,comedi_subdevice *s,
+       comedi_insn *insn,lsampl_t *data);
+
+INT i_APCI1710_InsnWriteEnableDisableChrono(comedi_device *dev,comedi_subdevice *s,
+       comedi_insn *insn,lsampl_t *data);
+
+
+/*
++----------------------------------------------------------------------------+
+|                       CHRONOMETER READ FUNCTION                            |
++----------------------------------------------------------------------------+
+*/
+
+INT    i_APCI1710_InsnReadChrono(comedi_device *dev,comedi_subdevice *s,
+comedi_insn *insn,lsampl_t *data);
+
+
+INT   i_APCI1710_GetChronoProgressStatus      (comedi_device *dev,
+                                                BYTE    b_ModulNbr,
+                                                PBYTE  pb_ChronoStatus);
+
+INT   i_APCI1710_ReadChronoValue      (comedi_device *dev,
+                                        BYTE     b_ModulNbr,
+                                        UINT    ui_TimeOut,
+                                        PBYTE   pb_ChronoStatus,
+                                        PULONG pul_ChronoValue);
+
+INT i_APCI1710_ConvertChronoValue     (comedi_device *dev,
+                                        BYTE     b_ModulNbr,
+                                        ULONG   ul_ChronoValue,
+                                        PULONG pul_Hour,
+                                        PBYTE   pb_Minute,
+                                        PBYTE   pb_Second,
+                                        PUINT  pui_MilliSecond,
+                                        PUINT  pui_MicroSecond,
+                                        PUINT  pui_NanoSecond);
+
+
+
+
+
+/*
++----------------------------------------------------------------------------+
+|                       CHRONOMETER DIGITAL INPUT OUTPUT FUNCTION                  |
++----------------------------------------------------------------------------+
+*/
+
+INT i_APCI1710_InsnBitsChronoDigitalIO(comedi_device *dev,comedi_subdevice *s,
+       comedi_insn *insn,lsampl_t *data);
+
+
index e7d1aac9cd79d822d3345e322410190a38ada759..141eb5754cf84e5312924747369b0296dc441000 100644 (file)
-/**\r
-@verbatim\r
-\r
-Copyright (C) 2004,2005  ADDI-DATA GmbH for the source code of this module. \r
-        \r
-        ADDI-DATA GmbH \r
-        Dieselstrasse 3 \r
-        D-77833 Ottersweier \r
-        Tel: +19(0)7223/9493-0 \r
-        Fax: +49(0)7223/9493-92 \r
-        http://www.addi-data-com \r
-        info@addi-data.com \r
-\r
-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.\r
-\r
-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.\r
-\r
-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 USA\r
-\r
-You shoud also find the complete GPL in the COPYING file accompanying this source code.\r
-\r
-@endverbatim\r
-*/\r
-/*\r
-    \r
-  +-----------------------------------------------------------------------+\r
-  | (C) ADDI-DATA GmbH          Dieselstraße 3       D-77833 Ottersweier  |\r
-  +-----------------------------------------------------------------------+\r
-  | Tel : +49 (0) 7223/9493-0     | email    : info@addi-data.com         |\r
-  | Fax : +49 (0) 7223/9493-92    | Internet : http://www.addi-data.com   |\r
-  +-----------------------------------------------------------------------+\r
-  | Project     : API APCI1710    | Compiler : gcc                        |\r
-  | Module name : DIG_IO.C        | Version  : 2.96                       |\r
-  +-------------------------------+---------------------------------------+\r
-  | Project manager: Eric Stolz   | Date     :  02/12/2002                |\r
-  +-----------------------------------------------------------------------+\r
-  | Description :   APCI-1710 digital I/O module                          |\r
-  |                                                                       |\r
-  |                                                                       |\r
-  +-----------------------------------------------------------------------+\r
-  |                             UPDATES                                   |\r
-  +-----------------------------------------------------------------------+\r
-  |   Date   |   Author  |          Description of updates                |\r
-  +----------+-----------+------------------------------------------------+\r
-  | 16/06/98 | S. Weber  | Digital input / output implementation          |\r
-  |----------|-----------|------------------------------------------------|\r
-  | 08/05/00 | Guinot C  | - 0400/0228 All Function in RING 0             |\r
-  |          |           |   available                                    |\r
-  +-----------------------------------------------------------------------+\r
-  |          |           |                                                |\r
-  |          |           |                                                |\r
-  +-----------------------------------------------------------------------+\r
-*/\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-|                               Included files                               |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-#include "APCI1710_Dig_io.h"\r
-\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : INT i_APCI1710_InsnConfigDigitalIO(comedi_device *dev, |\r
-|                                              comedi_subdevice *s,comedi_insn *insn,lsampl_t *data)|\r
-+----------------------------------------------------------------------------+\r
-| Task              : Configure the digital I/O operating mode from selected |\r
-|                     module  (b_ModulNbr). You must calling this function be|\r
-|                     for you call any other function witch access of digital|\r
-|                     I/O.                                                   |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  :                                                                                                       |\r
-|                  BYTE_ b_ModulNbr      data[0]: Module number to               |\r
-|                                             configure (0 to 3)             |\r
-|                     BYTE_ b_ChannelAMode data[1]  : Channel A mode selection       |\r
-|                                             0 : Channel used for digital   |\r
-|                                                 input                      |\r
-|                                             1 : Channel used for digital   |\r
-|                                                 output                     |\r
-|                     BYTE_ b_ChannelBMode data[2] : Channel B mode selection       |\r
-|                                             0 : Channel used for digital   |\r
-|                                                 input                      |\r
-|                                             1 : Channel used for digital   |\r
-|                                                 output                                        |                                          \r
-                                               data[0]   memory on/off\r
-Activates and deactivates the digital output memory. \r
-                                               After having      |\r
-|                 called up this function with memory on,the output you have previously|\r
-|                     activated with the function are not reset\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : -                                                      |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      : 0: No error                                            |\r
-|                    -1: The handle parameter of the board is wrong          |\r
-|                    -2: The module parameter is wrong                       |\r
-|                    -3: The module is not a digital I/O module              |\r
-|                    -4: Bi-directional channel A configuration error        |\r
-|                    -5: Bi-directional channel B configuration error        |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-INT i_APCI1710_InsnConfigDigitalIO(comedi_device *dev,comedi_subdevice *s,\r
-       comedi_insn *insn,lsampl_t *data)\r
-    {\r
-       BYTE   b_ModulNbr,b_ChannelAMode,b_ChannelBMode ;\r
-        BYTE   b_MemoryOnOff,b_ConfigType;\r
-       INT    i_ReturnValue = 0;\r
-       DWORD  dw_WriteConfig = 0;\r
-       \r
-       b_ModulNbr              =       (BYTE) CR_AREF(insn->chanspec);\r
-        b_ConfigType\r
-   =   (BYTE) data[0];// Memory or  Init\r
-       b_ChannelAMode  =       (BYTE) data[1];\r
-       b_ChannelBMode  =       (BYTE) data[2];\r
-        b_MemoryOnOff   =      (BYTE) data[1]; // if memory operation \r
-       i_ReturnValue   =   insn->n;\r
-\r
-  \r
-               /**************************/\r
-               /* Test the module number */\r
-               /**************************/\r
-\r
-               if (b_ModulNbr >= 4)\r
-               {\r
-                       DPRINTK("Module Number invalid\n");\r
-                       i_ReturnValue = -2;\r
-                    return i_ReturnValue;   \r
-               }       \r
-            switch(b_ConfigType)\r
-              {\r
-               case APCI1710_DIGIO_MEMORYONOFF:        \r
-\r
-               if(b_MemoryOnOff) // If Memory ON\r
-               {\r
-                /****************************/\r
-                /* Set the output memory on */\r
-                /****************************/\r
-\r
-                devpriv->s_ModuleInfo [b_ModulNbr].\r
-                s_DigitalIOInfo.\r
-                b_OutputMemoryEnabled = 1;\r
-\r
-                /***************************/\r
-                /* Clear the output memory */\r
-                /***************************/\r
-                devpriv->s_ModuleInfo [b_ModulNbr].\r
-                s_DigitalIOInfo.\r
-                dw_OutputMemory = 0;\r
-               }\r
-               else   // If memory off\r
-               {\r
-                /*****************************/\r
-                /* Set the output memory off */\r
-                /*****************************/\r
-\r
-                devpriv->s_ModuleInfo [b_ModulNbr].\r
-                s_DigitalIOInfo.\r
-                b_OutputMemoryEnabled = 0;     \r
-               }\r
-               break;\r
-\r
-        case APCI1710_DIGIO_INIT:\r
-            \r
-       /*******************************/\r
-       /* Test if digital I/O counter */\r
-       /*******************************/\r
-\r
-        if((devpriv->s_BoardInfos.dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_DIGITAL_IO)\r
-       {\r
-\r
-       /***************************************************/\r
-       /* Test the bi-directional channel A configuration */\r
-       /***************************************************/\r
-          \r
-                       if ((b_ChannelAMode == 0) || (b_ChannelAMode == 1))\r
-                       {\r
-       /***************************************************/\r
-       /* Test the bi-directional channel B configuration */\r
-       /***************************************************/\r
-\r
-                               if ((b_ChannelBMode == 0) || (b_ChannelBMode == 1))\r
-                               {\r
-                                        devpriv->s_ModuleInfo [b_ModulNbr].\r
-                                               s_DigitalIOInfo.\r
-                                               b_DigitalInit = 1;\r
-\r
-       /********************************/\r
-       /* Save channel A configuration */\r
-       /********************************/\r
-\r
-                                       devpriv->s_ModuleInfo [b_ModulNbr].\r
-                                               s_DigitalIOInfo.\r
-                                               b_ChannelAMode = b_ChannelAMode;\r
-\r
-       /********************************/\r
-       /* Save channel B configuration */\r
-       /********************************/\r
-\r
-                                       devpriv->s_ModuleInfo [b_ModulNbr].\r
-                                               s_DigitalIOInfo.\r
-                                               b_ChannelBMode = b_ChannelBMode;\r
-\r
-       /*****************************************/\r
-       /* Set the channel A and B configuration */\r
-       /*****************************************/\r
-\r
-\r
-                   dw_WriteConfig = (DWORD) (b_ChannelAMode | (b_ChannelBMode * 2));\r
-\r
-       /***************************/\r
-       /* Write the configuration */\r
-       /***************************/\r
-\r
-                        outl(dw_WriteConfig,devpriv->s_BoardInfos.ui_Address + 4 + (64 * b_ModulNbr));\r
-\r
-                       }\r
-            else\r
-                       {\r
-       /************************************************/\r
-       /* Bi-directional channel B configuration error */\r
-       /************************************************/      \r
-                        DPRINTK("Bi-directional channel B configuration error\n");     \r
-                        i_ReturnValue = -5;  \r
-                       }               \r
-\r
-               }\r
-        else\r
-                {\r
-       /************************************************/\r
-       /* Bi-directional channel A configuration error */\r
-       /************************************************/\r
-                       DPRINTK("Bi-directional channel A configuration error\n");      \r
-                       i_ReturnValue = -4; \r
-                \r
-                } \r
-\r
-       }\r
-       else\r
-        {\r
-       /******************************************/\r
-       /* The module is not a digital I/O module */\r
-       /******************************************/\r
-                       DPRINTK("The module is not a digital I/O module\n");    \r
-                       i_ReturnValue = -3;\r
-     }\r
-    } // end of Switch \r
-     printk("Return Value %d\n",i_ReturnValue);  \r
-     return i_ReturnValue;\r
-}\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-|                            INPUT FUNCTIONS                                 |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-\r
-|INT i_APCI1710_InsnReadDigitalIOChlValue(comedi_device *dev,comedi_subdevice \r
-*s,    comedi_insn *insn,lsampl_t *data)\r
-\r
-+----------------------------------------------------------------------------+\r
-| Task              : Read the status from selected digital I/O digital input|\r
-|                     (b_InputChannel)                                       |\r
-+----------------------------------------------------------------------------|\r
-\r
-  \r
-|\r
-|  BYTE_ b_ModulNbr  CR_AREF(chanspec)          : Selected module number   |\r
-|                                                   (0 to 3)                 |\r
-|  BYTE_ b_InputChannel CR_CHAN(chanspec)        : Selection from digital   |\r
-|                                                   input ( 0 to 6)          |\r
-|                                                      0 : Channel C         |\r
-|                                                      1 : Channel D         |\r
-|                                                      2 : Channel E         |\r
-|                                                      3 : Channel F         |\r
-|                                                      4 : Channel G         |\r
-|                                                      5 : Channel A         |\r
-|                                                      6 : Channel B   \r
-\r
-  \r
-       |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters :                                   data[0]   : Digital input channel    |\r
-|                                                   status                   |\r
-|                                                   0 : Channle is not active|\r
-|                                                   1 : Channle is active    |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      : 0: No error                                            |\r
-|                    -1: The handle parameter of the board is wrong          |\r
-|                    -2: The module parameter is wrong                       |\r
-|                    -3: The module is not a digital I/O module              |\r
-|                    -4: The selected digital I/O digital input is wrong     |\r
-|                    -5: Digital I/O not initialised                         |\r
-|                    -6: The digital channel A is used for output            |\r
-|                    -7: The digital channel B is used for output            |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-//_INT_   i_APCI1710_ReadDigitalIOChlValue      (BYTE_    b_BoardHandle,\r
-//                                            BYTE_    b_ModulNbr,\r
-//                                            BYTE_    b_InputChannel,\r
-//\r
-//                                            PBYTE_  pb_ChannelStatus)\r
-INT i_APCI1710_InsnReadDigitalIOChlValue(comedi_device *dev,comedi_subdevice *s,\r
-       comedi_insn *insn,lsampl_t *data)\r
-{\r
-       INT    i_ReturnValue = 0;\r
-       DWORD dw_StatusReg;\r
-       BYTE    b_ModulNbr,b_InputChannel;\r
-        PBYTE  pb_ChannelStatus;\r
-       b_ModulNbr              = (BYTE) CR_AREF(insn->chanspec);\r
-        b_InputChannel = (BYTE) CR_CHAN(insn->chanspec);\r
-        data[0]=0;\r
-        pb_ChannelStatus= (PBYTE) &data[0];\r
-        i_ReturnValue = insn->n;\r
-\r
-\r
-       /**************************/\r
-       /* Test the module number */\r
-       /**************************/\r
-\r
-       if (b_ModulNbr < 4)\r
-          {\r
-          /*******************************/\r
-          /* Test if digital I/O counter */\r
-          /*******************************/\r
-\r
-          if ((devpriv->s_BoardInfos.dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_DIGITAL_IO)\r
-             {\r
-             /******************************************/\r
-             /* Test the digital imnput channel number */\r
-             /******************************************/\r
-\r
-             if (b_InputChannel <= 6)\r
-                {\r
-                /**********************************************/\r
-                /* Test if the digital I/O module initialised */\r
-                /**********************************************/\r
-\r
-                if (devpriv->s_ModuleInfo[b_ModulNbr].s_DigitalIOInfo.b_DigitalInit == 1)\r
-                   {\r
-                   /**********************************/\r
-                   /* Test if channel A or channel B */\r
-                   /**********************************/\r
-\r
-                   if (b_InputChannel > 4)\r
-                      {\r
-                      /*********************/\r
-                      /* Test if channel A */\r
-                      /*********************/\r
-\r
-                      if (b_InputChannel == 5)\r
-                         {\r
-                         /***************************/\r
-                         /* Test the channel A mode */\r
-                         /***************************/\r
-\r
-                         if (devpriv->s_ModuleInfo [b_ModulNbr].s_DigitalIOInfo.b_ChannelAMode != 0)\r
-                            {\r
-                            /********************************************/\r
-                            /* The digital channel A is used for output */\r
-                            /********************************************/\r
-\r
-                            i_ReturnValue = -6;\r
-                            }\r
-                         } // if (b_InputChannel == 5)\r
-                      else\r
-                         {\r
-                         /***************************/\r
-                         /* Test the channel B mode */\r
-                         /***************************/\r
-\r
-                         if (devpriv->s_ModuleInfo [b_ModulNbr].s_DigitalIOInfo.b_ChannelBMode != 0)\r
-                            {\r
-                            /********************************************/\r
-                            /* The digital channel B is used for output */\r
-                            /********************************************/\r
-\r
-                            i_ReturnValue = -7;\r
-                            }\r
-                         } // if (b_InputChannel == 5)\r
-                      } // if (b_InputChannel > 4)\r
-\r
-                   /***********************/\r
-                   /* Test if error occur */\r
-                   /***********************/\r
-\r
-                   if (i_ReturnValue >= 0)\r
-                      {\r
-                      /**************************/\r
-                      /* Read all digital input */\r
-                      /**************************/\r
-\r
-                      //INPDW (ps_APCI1710Variable->\r
-                          //   s_Board [b_BoardHandle].\r
-                          //   s_BoardInfos.\r
-                           //  ui_Address + (64 * b_ModulNbr),\r
-                            // &dw_StatusReg);\r
-\r
-                           dw_StatusReg = inl(devpriv->s_BoardInfos.ui_Address + (64 * b_ModulNbr));\r
-\r
-                      *pb_ChannelStatus = (BYTE) ((dw_StatusReg ^ 0x1C) >> b_InputChannel) & 1;\r
-                        \r
-                      } // if (i_ReturnValue == 0)\r
-                   }\r
-                else\r
-                   {\r
-                   /*******************************/\r
-                   /* Digital I/O not initialised */\r
-                   /*******************************/\r
-                       DPRINTK("Digital I/O not initialised\n");\r
-                   i_ReturnValue = -5;\r
-                   }\r
-                }\r
-             else\r
-                {\r
-                /********************************/\r
-                /* Selected digital input error */\r
-                /********************************/\r
-                DPRINTK("Selected digital input error\n"); \r
-                i_ReturnValue = -4;\r
-                }\r
-             }\r
-          else\r
-             {\r
-             /******************************************/\r
-             /* The module is not a digital I/O module */\r
-             /******************************************/\r
-                 DPRINTK("The module is not a digital I/O module\n"); \r
-             i_ReturnValue = -3;\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /***********************/\r
-          /* Module number error */\r
-          /***********************/\r
-               DPRINTK("Module number error\n"); \r
-          i_ReturnValue = -2;\r
-          }\r
-\r
-       return (i_ReturnValue);\r
-       }\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-|                            OUTPUT FUNCTIONS                                |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : INT i_APCI1710_InsnWriteDigitalIOChlOnOff(comedi_device \r
-|*dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data)\r
-\r
-+----------------------------------------------------------------------------+\r
-| Task              : Sets or resets the output witch has been passed with the         |\r
-|                     parameter b_Channel. Setting an output means setting   |\r
-|                     an ouput high.                                         |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : BYTE_ b_BoardHandle   : Handle of board APCI-1710      |\r
-|                     BYTE_ b_ModulNbr (aref )    : Selected module number (0 to 3)|\r
-|                     BYTE_ b_OutputChannel (CR_CHAN) : Selection from digital output  |\r
-|                                             channel (0 to 2)               |\r
-|                                                0 : Channel H               |\r
-|                                                1 : Channel A               |\r
-|                                                2 : Channel B               |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : -                                                      |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      : 0: No error                                            |\r
-|                    -1: The handle parameter of the board is wrong          |\r
-|                    -2: The module parameter is wrong                       |\r
-|                    -3: The module is not a digital I/O module              |\r
-|                    -4: The selected digital output is wrong                |\r
-|                    -5: digital I/O not initialised see function            |\r
-|                        " i_APCI1710_InitDigitalIO"                         |\r
-|                    -6: The digital channel A is used for input             |\r
-|                    -7: The digital channel B is used for input \r
-                                        -8: Digital Output Memory OFF.                          |\r
-|                        Use previously the function                         |\r
-|                        "i_APCI1710_SetDigitalIOMemoryOn".            |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-//_INT_   i_APCI1710_SetDigitalIOChlOn    (BYTE_ b_BoardHandle,\r
-//                                      BYTE_ b_ModulNbr,\r
-//                                      BYTE_ b_OutputChannel)\r
-INT i_APCI1710_InsnWriteDigitalIOChlOnOff(comedi_device *dev,comedi_subdevice *s,\r
-       comedi_insn *insn,lsampl_t *data)\r
-       {\r
-       INT    i_ReturnValue = 0;\r
-       DWORD dw_WriteValue  = 0;\r
-       BYTE b_ModulNbr,b_OutputChannel;\r
-       i_ReturnValue   =       insn->n; \r
-       b_ModulNbr              =   CR_AREF(insn->chanspec);  \r
-       b_OutputChannel =   CR_CHAN(insn->chanspec);  \r
-       \r
-       \r
-\r
-       /**************************/\r
-       /* Test the module number */\r
-       /**************************/\r
-\r
-       if (b_ModulNbr < 4)\r
-          {\r
-          /*******************************/\r
-          /* Test if digital I/O counter */\r
-          /*******************************/\r
-\r
-          if ((devpriv->s_BoardInfos.\r
-               dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_DIGITAL_IO)\r
-             {\r
-             /**********************************************/\r
-             /* Test if the digital I/O module initialised */\r
-             /**********************************************/\r
-\r
-             if (devpriv->s_ModuleInfo [b_ModulNbr].\r
-                 s_DigitalIOInfo.\r
-                 b_DigitalInit == 1)\r
-                {\r
-                /******************************************/\r
-                /* Test the digital output channel number */\r
-                /******************************************/\r
-\r
-                switch (b_OutputChannel)\r
-                   {\r
-                   /*************/\r
-                   /* Channel H */\r
-                   /*************/\r
-\r
-                   case 0:\r
-                        break;\r
-\r
-                   /*************/\r
-                   /* Channel A */\r
-                   /*************/\r
-\r
-                   case 1:\r
-                        if (devpriv->s_ModuleInfo [b_ModulNbr].\r
-                            s_DigitalIOInfo.\r
-                            b_ChannelAMode != 1)\r
-                           {\r
-                           /*******************************************/\r
-                           /* The digital channel A is used for input */\r
-                           /*******************************************/\r
-\r
-                           i_ReturnValue = -6;\r
-                           }\r
-                        break;\r
-\r
-                   /*************/\r
-                   /* Channel B */\r
-                   /*************/\r
-\r
-                   case 2:\r
-                        if (devpriv->s_ModuleInfo [b_ModulNbr].\r
-                            s_DigitalIOInfo.\r
-                            b_ChannelBMode != 1)\r
-                           {\r
-                           /*******************************************/\r
-                           /* The digital channel B is used for input */\r
-                           /*******************************************/\r
-\r
-                           i_ReturnValue = -7;\r
-                           }\r
-                        break;\r
-\r
-                   default :\r
-                        /****************************************/\r
-                        /* The selected digital output is wrong */\r
-                        /****************************************/\r
-\r
-                        i_ReturnValue = -4;\r
-                        break;\r
-                   }\r
-\r
-                /***********************/\r
-                /* Test if error occur */\r
-                /***********************/\r
-\r
-                if (i_ReturnValue >= 0)\r
-                   {\r
-            \r
-                        \r
-                       /*********************************/\r
-                   /* Test if set channel ON        */\r
-                   /*********************************/ \r
-                        if(data[0])\r
-                        {               \r
-                   /*********************************/\r
-                   /* Test if output memory enabled */\r
-                   /*********************************/\r
-\r
-                   if (devpriv->s_ModuleInfo [b_ModulNbr].\r
-                       s_DigitalIOInfo.\r
-                       b_OutputMemoryEnabled == 1)\r
-                      {\r
-                      dw_WriteValue = devpriv->s_ModuleInfo [b_ModulNbr].\r
-                                      s_DigitalIOInfo.\r
-                                      dw_OutputMemory | (1 << b_OutputChannel);\r
-\r
-                      devpriv->s_ModuleInfo [b_ModulNbr].\r
-                      s_DigitalIOInfo.\r
-                      dw_OutputMemory = dw_WriteValue;\r
-                      }\r
-                   else\r
-                      {\r
-                      dw_WriteValue = 1 << b_OutputChannel;\r
-                      }\r
-                        } // set channel off\r
-             else\r
-                        {\r
-                               if (devpriv->s_ModuleInfo [b_ModulNbr].\r
-                       s_DigitalIOInfo.\r
-                       b_OutputMemoryEnabled == 1)\r
-                      {\r
-                      dw_WriteValue = devpriv->s_ModuleInfo [b_ModulNbr].\r
-                                      s_DigitalIOInfo.\r
-                                      dw_OutputMemory & (0xFFFFFFFFUL - (1 << b_OutputChannel));\r
-\r
-                      devpriv->s_ModuleInfo [b_ModulNbr].s_DigitalIOInfo.dw_OutputMemory = dw_WriteValue;\r
-                      }\r
-                   else\r
-                      {\r
-                      /*****************************/\r
-                      /* Digital Output Memory OFF */\r
-                      /*****************************/\r
-                          // +Use previously the function "i_APCI1710_SetDigitalIOMemoryOn"\r
-                      i_ReturnValue = -8;\r
-                      }\r
-\r
-             }\r
-                   /*******************/\r
-                   /* Write the value */\r
-                   /*******************/\r
-\r
-                   //OUTPDW (ps_APCI1710Variable->\r
-                       //    s_Board [b_BoardHandle].\r
-                        //   s_BoardInfos.\r
-                        //   ui_Address + (64 * b_ModulNbr),\r
-                        //   dw_WriteValue);\r
-                       outl(dw_WriteValue,devpriv->s_BoardInfos.ui_Address + (64 * b_ModulNbr));\r
-                   }\r
-                }\r
-             else\r
-                {\r
-                /*******************************/\r
-                /* Digital I/O not initialised */\r
-                /*******************************/\r
-\r
-                i_ReturnValue = -5;\r
-                }\r
-             }\r
-          else\r
-             {\r
-             /******************************************/\r
-             /* The module is not a digital I/O module */\r
-             /******************************************/\r
-\r
-             i_ReturnValue = -3;\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /***********************/\r
-          /* Module number error */\r
-          /***********************/\r
-\r
-          i_ReturnValue = -2;\r
-          }\r
-\r
-       return (i_ReturnValue);\r
-       }\r
-\r
-\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-    \r
-|INT i_APCI1710_InsnBitsDigitalIOPortOnOff(comedi_device *dev,comedi_subdevice \r
-       *s,     comedi_insn *insn,lsampl_t *data)\r
-+----------------------------------------------------------------------------+\r
-| Task              : write:\r
-                                         Sets or resets one or several outputs from port.                 |\r
-|                     Setting an output means setting an output high.        |\r
-|                     If you have switched OFF the digital output memory     |\r
-|                     (OFF), all the other output are set to "0".            \r
-\r
-|                      read:\r
-                                         Read the status from digital input port                |\r
-|                     from selected digital I/O module (b_ModulNbr)   \r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : \r
-       BYTE_ b_BoardHandle   : Handle of board APCI-1710      |\r
-|   BYTE_ b_ModulNbr  CR_AREF(aref)    : Selected module number (0 to 3)|\r
-|   BYTE_ b_PortValue CR_CHAN(chanspec) : Output Value ( 0 To 7 )        \r
-|                       data[0]           read or write port\r
-                        data[1]            if write then indicate ON or OFF\r
-\r
-                        if read : data[1] will return port status.\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : -                                                      |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      :\r
-\r
-                INPUT :\r
-   \r
-                                         0: No error                                            |\r
-|                    -1: The handle parameter of the board is wrong          |\r
-|                    -2: The module parameter is wrong                       |\r
-|                    -3: The module is not a digital I/O module              |\r
-|                    -4: Digital I/O not initialised                           \r
-\r
-                               OUTPUT:   0: No error                                            |\r
-|                    -1: The handle parameter of the board is wrong          |\r
-|                    -2: The module parameter is wrong                       |\r
-|                    -3: The module is not a digital I/O module              |\r
-|                    -4: Output value wrong                                  |\r
-|                    -5: digital I/O not initialised see function            |\r
-|                        " i_APCI1710_InitDigitalIO"                         |\r
-|                    -6: The digital channel A is used for input             |\r
-|                    -7: The digital channel B is used for input \r
-                                       -8: Digital Output Memory OFF.                          |\r
-|                        Use previously the function                         |\r
-|                        "i_APCI1710_SetDigitalIOMemoryOn".               |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-//_INT_   i_APCI1710_SetDigitalIOPortOn   (BYTE_ b_BoardHandle,\r
-//                                      BYTE_ b_ModulNbr,\r
-//                                      BYTE_ b_PortValue)\r
-INT i_APCI1710_InsnBitsDigitalIOPortOnOff(comedi_device *dev,comedi_subdevice *s,\r
-       comedi_insn *insn,lsampl_t *data)\r
-       {\r
-       INT    i_ReturnValue = 0;\r
-       DWORD dw_WriteValue = 0;\r
-       DWORD dw_StatusReg;\r
-       BYTE b_ModulNbr,b_PortValue;\r
-        BYTE b_PortOperation,b_PortOnOFF;\r
-\r
-       PBYTE pb_PortValue;\r
-          \r
-       b_ModulNbr              = (BYTE) CR_AREF(insn->chanspec);\r
-       b_PortOperation = (BYTE) data[0];// Input or output \r
-       b_PortOnOFF             = (BYTE) data[1];// if output then On or Off\r
-       b_PortValue             = (BYTE) data[2];// if out put then Value\r
-       i_ReturnValue   = insn->n;\r
-        pb_PortValue    = (PBYTE) &data[0];\r
-// if input then read value\r
-       \r
-\r
-\r
-    switch(b_PortOperation)\r
-       {\r
-    case APCI1710_INPUT  :\r
-       /**************************/\r
-       /* Test the module number */\r
-       /**************************/\r
-\r
-       if (b_ModulNbr < 4)\r
-          {\r
-          /*******************************/\r
-          /* Test if digital I/O counter */\r
-          /*******************************/\r
-\r
-          if ((devpriv->s_BoardInfos.\r
-               dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_DIGITAL_IO)\r
-             {\r
-             /**********************************************/\r
-             /* Test if the digital I/O module initialised */\r
-             /**********************************************/\r
-\r
-             if (devpriv->s_ModuleInfo [b_ModulNbr].\r
-                 s_DigitalIOInfo.b_DigitalInit == 1)\r
-                {\r
-                /**************************/\r
-                /* Read all digital input */\r
-                /**************************/\r
-\r
-                //INPDW (ps_APCI1710Variable->\r
-               //      s_Board [b_BoardHandle].\r
-               //      s_BoardInfos.\r
-               //      ui_Address + (64 * b_ModulNbr),\r
-               //      &dw_StatusReg);\r
-\r
-          dw_StatusReg=inl(devpriv->s_BoardInfos.ui_Address + (64 * b_ModulNbr));\r
-                *pb_PortValue = (BYTE) (dw_StatusReg ^ 0x1C);\r
-               \r
-                }\r
-             else\r
-                {\r
-                /*******************************/\r
-                /* Digital I/O not initialised */\r
-                /*******************************/\r
-\r
-                i_ReturnValue = -4;\r
-                }\r
-             }\r
-          else\r
-             {\r
-             /******************************************/\r
-             /* The module is not a digital I/O module */\r
-             /******************************************/\r
-\r
-             i_ReturnValue = -3;\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /***********************/\r
-          /* Module number error */\r
-          /***********************/\r
-\r
-          i_ReturnValue = -2;\r
-          }\r
-       \r
-         break;\r
-\r
-       case APCI1710_OUTPUT :\r
-       /**************************/\r
-       /* Test the module number */\r
-       /**************************/\r
-\r
-       if (b_ModulNbr < 4)\r
-          {\r
-          /*******************************/\r
-          /* Test if digital I/O counter */\r
-          /*******************************/\r
-\r
-          if ((devpriv->s_BoardInfos.\r
-               dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_DIGITAL_IO)\r
-             {\r
-             /**********************************************/\r
-             /* Test if the digital I/O module initialised */\r
-             /**********************************************/\r
-\r
-             if (devpriv->s_ModuleInfo [b_ModulNbr].\r
-                 s_DigitalIOInfo.\r
-                 b_DigitalInit == 1)\r
-                {\r
-                /***********************/\r
-                /* Test the port value */\r
-                /***********************/\r
-\r
-                if (b_PortValue <= 7)\r
-                   {\r
-                   /***********************************/\r
-                   /* Test the digital output channel */\r
-                   /***********************************/\r
-\r
-                   /**************************/\r
-                   /* Test if channel A used */\r
-                   /**************************/\r
-\r
-                   if ((b_PortValue & 2) == 2)\r
-                      {\r
-                      if (devpriv->s_ModuleInfo [b_ModulNbr].\r
-                          s_DigitalIOInfo.\r
-                          b_ChannelAMode != 1)\r
-                         {\r
-                         /*******************************************/\r
-                         /* The digital channel A is used for input */\r
-                         /*******************************************/\r
-\r
-                         i_ReturnValue = -6;\r
-                         }\r
-                      } // if ((b_PortValue & 2) == 2)\r
-\r
-                   /**************************/\r
-                   /* Test if channel B used */\r
-                   /**************************/\r
-\r
-                   if ((b_PortValue & 4) == 4)\r
-                      {\r
-                      if (devpriv->s_ModuleInfo [b_ModulNbr].\r
-                          s_DigitalIOInfo.\r
-                          b_ChannelBMode != 1)\r
-                         {\r
-                         /*******************************************/\r
-                         /* The digital channel B is used for input */\r
-                         /*******************************************/\r
-\r
-                         i_ReturnValue = -7;\r
-                         }\r
-                      } // if ((b_PortValue & 4) == 4)\r
-\r
-                   /***********************/\r
-                   /* Test if error occur */\r
-                   /***********************/\r
-\r
-                   if (i_ReturnValue >= 0)\r
-                      {\r
-                          \r
-                         //if(data[1])\r
-                         //{\r
-               switch(b_PortOnOFF)\r
-               { \r
-                          /*********************************/\r
-                      /* Test if set Port ON                   */\r
-                      /*********************************/\r
-\r
-                          case APCI1710_ON :\r
-\r
-                      /*********************************/\r
-                      /* Test if output memory enabled */\r
-                      /*********************************/\r
-\r
-                      if (devpriv->s_ModuleInfo [b_ModulNbr].\r
-                          s_DigitalIOInfo.\r
-                          b_OutputMemoryEnabled == 1)\r
-                         {\r
-                         dw_WriteValue = devpriv->s_ModuleInfo [b_ModulNbr].\r
-                                         s_DigitalIOInfo.\r
-                                         dw_OutputMemory | b_PortValue;\r
-\r
-                         devpriv->s_ModuleInfo [b_ModulNbr].\r
-                         s_DigitalIOInfo.dw_OutputMemory = dw_WriteValue;\r
-                         }\r
-                      else\r
-                         {\r
-                         dw_WriteValue = b_PortValue;\r
-                         }\r
-              break;\r
-\r
-                       // If Set PORT  OFF  \r
-                       case APCI1710_OFF:\r
-                       \r
-                          /*********************************/\r
-                      /* Test if output memory enabled */\r
-                      /*********************************/\r
-\r
-                      if (devpriv->s_ModuleInfo [b_ModulNbr].\r
-                          s_DigitalIOInfo.b_OutputMemoryEnabled == 1)\r
-                         {\r
-                         dw_WriteValue = devpriv->s_ModuleInfo [b_ModulNbr].\r
-                                         s_DigitalIOInfo.\r
-                                         dw_OutputMemory & (0xFFFFFFFFUL - b_PortValue);\r
-\r
-                         devpriv->s_ModuleInfo [b_ModulNbr].\r
-                         s_DigitalIOInfo.\r
-                         dw_OutputMemory = dw_WriteValue;\r
-                         }\r
-                      else\r
-                         {\r
-                         /*****************************/\r
-                         /* Digital Output Memory OFF */\r
-                         /*****************************/\r
-\r
-                         i_ReturnValue = -8;\r
-                         }\r
-                       } // switch\r
-\r
-                      /*******************/\r
-                      /* Write the value */\r
-                      /*******************/\r
-\r
-                    //  OUTPDW (ps_APCI1710Variable->\r
-                        //      s_Board [b_BoardHandle].\r
-                        //      s_BoardInfos.\r
-                        //      ui_Address + (64 * b_ModulNbr),\r
-                        //      dw_WriteValue);\r
-                               outl(dw_WriteValue,devpriv->s_BoardInfos.ui_Address + (64 * b_ModulNbr));\r
-                      }\r
-                   }\r
-                else\r
-                   {\r
-                   /**********************/\r
-                   /* Output value wrong */\r
-                   /**********************/\r
-\r
-                   i_ReturnValue = -4;\r
-                   }\r
-                }\r
-             else\r
-                {\r
-                /*******************************/\r
-                /* Digital I/O not initialised */\r
-                /*******************************/\r
-\r
-                i_ReturnValue = -5;\r
-                }\r
-             }\r
-          else\r
-             {\r
-             /******************************************/\r
-             /* The module is not a digital I/O module */\r
-             /******************************************/\r
-\r
-             i_ReturnValue = -3;\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /***********************/\r
-          /* Module number error */\r
-          /***********************/\r
-\r
-          i_ReturnValue = -2;\r
-          }\r
-       break;\r
-\r
-       default:\r
-               i_ReturnValue = -9;\r
-               DPRINTK("NO INPUT/OUTPUT specified\n");\r
-  } //switch INPUT / OUTPUT\r
-       return (i_ReturnValue);\r
-}\r
-\r
-\r
-\r
+/**
+@verbatim
+
+Copyright (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 USA
+
+You 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 : DIG_IO.C        | Version  : 2.96                       |
+  +-------------------------------+---------------------------------------+
+  | Project manager: Eric Stolz   | Date     :  02/12/2002                |
+  +-----------------------------------------------------------------------+
+  | Description :   APCI-1710 digital I/O module                          |
+  |                                                                       |
+  |                                                                       |
+  +-----------------------------------------------------------------------+
+  |                             UPDATES                                   |
+  +-----------------------------------------------------------------------+
+  |   Date   |   Author  |          Description of updates                |
+  +----------+-----------+------------------------------------------------+
+  | 16/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_Dig_io.h"
+
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     : INT i_APCI1710_InsnConfigDigitalIO(comedi_device *dev, |
+|                                              comedi_subdevice *s,comedi_insn *insn,lsampl_t *data)|
++----------------------------------------------------------------------------+
+| Task              : Configure the digital I/O operating mode from selected |
+|                     module  (b_ModulNbr). You must calling this function be|
+|                     for you call any other function witch access of digital|
+|                     I/O.                                                   |
++----------------------------------------------------------------------------+
+| Input Parameters  :                                                                                                       |
+|                  BYTE_ b_ModulNbr      data[0]: Module number to               |
+|                                             configure (0 to 3)             |
+|                     BYTE_ b_ChannelAMode data[1]  : Channel A mode selection       |
+|                                             0 : Channel used for digital   |
+|                                                 input                      |
+|                                             1 : Channel used for digital   |
+|                                                 output                     |
+|                     BYTE_ b_ChannelBMode data[2] : Channel B mode selection       |
+|                                             0 : Channel used for digital   |
+|                                                 input                      |
+|                                             1 : Channel used for digital   |
+|                                                 output                                        |                                          
+                                               data[0]   memory on/off
+Activates and deactivates the digital output memory. 
+                                               After having      |
+|                 called up this function with memory on,the output you have previously|
+|                     activated with the function are not reset
++----------------------------------------------------------------------------+
+| Output Parameters : -                                                      |
++----------------------------------------------------------------------------+
+| Return Value      : 0: No error                                            |
+|                    -1: The handle parameter of the board is wrong          |
+|                    -2: The module parameter is wrong                       |
+|                    -3: The module is not a digital I/O module              |
+|                    -4: Bi-directional channel A configuration error        |
+|                    -5: Bi-directional channel B configuration error        |
++----------------------------------------------------------------------------+
+*/
+
+INT i_APCI1710_InsnConfigDigitalIO(comedi_device *dev,comedi_subdevice *s,
+       comedi_insn *insn,lsampl_t *data)
+    {
+       BYTE   b_ModulNbr,b_ChannelAMode,b_ChannelBMode ;
+        BYTE   b_MemoryOnOff,b_ConfigType;
+       INT    i_ReturnValue = 0;
+       DWORD  dw_WriteConfig = 0;
+       
+       b_ModulNbr              =       (BYTE) CR_AREF(insn->chanspec);
+        b_ConfigType
+   =   (BYTE) data[0];// Memory or  Init
+       b_ChannelAMode  =       (BYTE) data[1];
+       b_ChannelBMode  =       (BYTE) data[2];
+        b_MemoryOnOff   =      (BYTE) data[1]; // if memory operation 
+       i_ReturnValue   =   insn->n;
+
+  
+               /**************************/
+               /* Test the module number */
+               /**************************/
+
+               if (b_ModulNbr >= 4)
+               {
+                       DPRINTK("Module Number invalid\n");
+                       i_ReturnValue = -2;
+                    return i_ReturnValue;   
+               }       
+            switch(b_ConfigType)
+              {
+               case APCI1710_DIGIO_MEMORYONOFF:        
+
+               if(b_MemoryOnOff) // If Memory ON
+               {
+                /****************************/
+                /* Set the output memory on */
+                /****************************/
+
+                devpriv->s_ModuleInfo [b_ModulNbr].
+                s_DigitalIOInfo.
+                b_OutputMemoryEnabled = 1;
+
+                /***************************/
+                /* Clear the output memory */
+                /***************************/
+                devpriv->s_ModuleInfo [b_ModulNbr].
+                s_DigitalIOInfo.
+                dw_OutputMemory = 0;
+               }
+               else   // If memory off
+               {
+                /*****************************/
+                /* Set the output memory off */
+                /*****************************/
+
+                devpriv->s_ModuleInfo [b_ModulNbr].
+                s_DigitalIOInfo.
+                b_OutputMemoryEnabled = 0;     
+               }
+               break;
+
+        case APCI1710_DIGIO_INIT:
+            
+       /*******************************/
+       /* Test if digital I/O counter */
+       /*******************************/
+
+        if((devpriv->s_BoardInfos.dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_DIGITAL_IO)
+       {
+
+       /***************************************************/
+       /* Test the bi-directional channel A configuration */
+       /***************************************************/
+          
+                       if ((b_ChannelAMode == 0) || (b_ChannelAMode == 1))
+                       {
+       /***************************************************/
+       /* Test the bi-directional channel B configuration */
+       /***************************************************/
+
+                               if ((b_ChannelBMode == 0) || (b_ChannelBMode == 1))
+                               {
+                                        devpriv->s_ModuleInfo [b_ModulNbr].
+                                               s_DigitalIOInfo.
+                                               b_DigitalInit = 1;
+
+       /********************************/
+       /* Save channel A configuration */
+       /********************************/
+
+                                       devpriv->s_ModuleInfo [b_ModulNbr].
+                                               s_DigitalIOInfo.
+                                               b_ChannelAMode = b_ChannelAMode;
+
+       /********************************/
+       /* Save channel B configuration */
+       /********************************/
+
+                                       devpriv->s_ModuleInfo [b_ModulNbr].
+                                               s_DigitalIOInfo.
+                                               b_ChannelBMode = b_ChannelBMode;
+
+       /*****************************************/
+       /* Set the channel A and B configuration */
+       /*****************************************/
+
+
+                   dw_WriteConfig = (DWORD) (b_ChannelAMode | (b_ChannelBMode * 2));
+
+       /***************************/
+       /* Write the configuration */
+       /***************************/
+
+                        outl(dw_WriteConfig,devpriv->s_BoardInfos.ui_Address + 4 + (64 * b_ModulNbr));
+
+                       }
+            else
+                       {
+       /************************************************/
+       /* Bi-directional channel B configuration error */
+       /************************************************/      
+                        DPRINTK("Bi-directional channel B configuration error\n");     
+                        i_ReturnValue = -5;  
+                       }               
+
+               }
+        else
+                {
+       /************************************************/
+       /* Bi-directional channel A configuration error */
+       /************************************************/
+                       DPRINTK("Bi-directional channel A configuration error\n");      
+                       i_ReturnValue = -4; 
+                
+                } 
+
+       }
+       else
+        {
+       /******************************************/
+       /* The module is not a digital I/O module */
+       /******************************************/
+                       DPRINTK("The module is not a digital I/O module\n");    
+                       i_ReturnValue = -3;
+     }
+    } // end of Switch 
+     printk("Return Value %d\n",i_ReturnValue);  
+     return i_ReturnValue;
+}
+
+/*
++----------------------------------------------------------------------------+
+|                            INPUT FUNCTIONS                                 |
++----------------------------------------------------------------------------+
+*/
+
+/*
++----------------------------------------------------------------------------+
+
+|INT i_APCI1710_InsnReadDigitalIOChlValue(comedi_device *dev,comedi_subdevice 
+*s,    comedi_insn *insn,lsampl_t *data)
+
++----------------------------------------------------------------------------+
+| Task              : Read the status from selected digital I/O digital input|
+|                     (b_InputChannel)                                       |
++----------------------------------------------------------------------------|
+
+  
+|
+|  BYTE_ b_ModulNbr  CR_AREF(chanspec)          : Selected module number   |
+|                                                   (0 to 3)                 |
+|  BYTE_ b_InputChannel CR_CHAN(chanspec)        : Selection from digital   |
+|                                                   input ( 0 to 6)          |
+|                                                      0 : Channel C         |
+|                                                      1 : Channel D         |
+|                                                      2 : Channel E         |
+|                                                      3 : Channel F         |
+|                                                      4 : Channel G         |
+|                                                      5 : Channel A         |
+|                                                      6 : Channel B   
+
+  
+       |
++----------------------------------------------------------------------------+
+| Output Parameters :                                   data[0]   : Digital input channel    |
+|                                                   status                   |
+|                                                   0 : Channle is not active|
+|                                                   1 : Channle is active    |
++----------------------------------------------------------------------------+
+| Return Value      : 0: No error                                            |
+|                    -1: The handle parameter of the board is wrong          |
+|                    -2: The module parameter is wrong                       |
+|                    -3: The module is not a digital I/O module              |
+|                    -4: The selected digital I/O digital input is wrong     |
+|                    -5: Digital I/O not initialised                         |
+|                    -6: The digital channel A is used for output            |
+|                    -7: The digital channel B is used for output            |
++----------------------------------------------------------------------------+
+*/
+
+//_INT_   i_APCI1710_ReadDigitalIOChlValue      (BYTE_    b_BoardHandle,
+//                                            BYTE_    b_ModulNbr,
+//                                            BYTE_    b_InputChannel,
+//
+//                                            PBYTE_  pb_ChannelStatus)
+INT i_APCI1710_InsnReadDigitalIOChlValue(comedi_device *dev,comedi_subdevice *s,
+       comedi_insn *insn,lsampl_t *data)
+{
+       INT    i_ReturnValue = 0;
+       DWORD dw_StatusReg;
+       BYTE    b_ModulNbr,b_InputChannel;
+        PBYTE  pb_ChannelStatus;
+       b_ModulNbr              = (BYTE) CR_AREF(insn->chanspec);
+        b_InputChannel = (BYTE) CR_CHAN(insn->chanspec);
+        data[0]=0;
+        pb_ChannelStatus= (PBYTE) &data[0];
+        i_ReturnValue = insn->n;
+
+
+       /**************************/
+       /* Test the module number */
+       /**************************/
+
+       if (b_ModulNbr < 4)
+          {
+          /*******************************/
+          /* Test if digital I/O counter */
+          /*******************************/
+
+          if ((devpriv->s_BoardInfos.dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_DIGITAL_IO)
+             {
+             /******************************************/
+             /* Test the digital imnput channel number */
+             /******************************************/
+
+             if (b_InputChannel <= 6)
+                {
+                /**********************************************/
+                /* Test if the digital I/O module initialised */
+                /**********************************************/
+
+                if (devpriv->s_ModuleInfo[b_ModulNbr].s_DigitalIOInfo.b_DigitalInit == 1)
+                   {
+                   /**********************************/
+                   /* Test if channel A or channel B */
+                   /**********************************/
+
+                   if (b_InputChannel > 4)
+                      {
+                      /*********************/
+                      /* Test if channel A */
+                      /*********************/
+
+                      if (b_InputChannel == 5)
+                         {
+                         /***************************/
+                         /* Test the channel A mode */
+                         /***************************/
+
+                         if (devpriv->s_ModuleInfo [b_ModulNbr].s_DigitalIOInfo.b_ChannelAMode != 0)
+                            {
+                            /********************************************/
+                            /* The digital channel A is used for output */
+                            /********************************************/
+
+                            i_ReturnValue = -6;
+                            }
+                         } // if (b_InputChannel == 5)
+                      else
+                         {
+                         /***************************/
+                         /* Test the channel B mode */
+                         /***************************/
+
+                         if (devpriv->s_ModuleInfo [b_ModulNbr].s_DigitalIOInfo.b_ChannelBMode != 0)
+                            {
+                            /********************************************/
+                            /* The digital channel B is used for output */
+                            /********************************************/
+
+                            i_ReturnValue = -7;
+                            }
+                         } // if (b_InputChannel == 5)
+                      } // if (b_InputChannel > 4)
+
+                   /***********************/
+                   /* Test if error occur */
+                   /***********************/
+
+                   if (i_ReturnValue >= 0)
+                      {
+                      /**************************/
+                      /* Read all digital input */
+                      /**************************/
+
+                      //INPDW (ps_APCI1710Variable->
+                          //   s_Board [b_BoardHandle].
+                          //   s_BoardInfos.
+                           //  ui_Address + (64 * b_ModulNbr),
+                            // &dw_StatusReg);
+
+                           dw_StatusReg = inl(devpriv->s_BoardInfos.ui_Address + (64 * b_ModulNbr));
+
+                      *pb_ChannelStatus = (BYTE) ((dw_StatusReg ^ 0x1C) >> b_InputChannel) & 1;
+                        
+                      } // if (i_ReturnValue == 0)
+                   }
+                else
+                   {
+                   /*******************************/
+                   /* Digital I/O not initialised */
+                   /*******************************/
+                       DPRINTK("Digital I/O not initialised\n");
+                   i_ReturnValue = -5;
+                   }
+                }
+             else
+                {
+                /********************************/
+                /* Selected digital input error */
+                /********************************/
+                DPRINTK("Selected digital input error\n"); 
+                i_ReturnValue = -4;
+                }
+             }
+          else
+             {
+             /******************************************/
+             /* The module is not a digital I/O module */
+             /******************************************/
+                 DPRINTK("The module is not a digital I/O module\n"); 
+             i_ReturnValue = -3;
+             }
+          }
+       else
+          {
+          /***********************/
+          /* Module number error */
+          /***********************/
+               DPRINTK("Module number error\n"); 
+          i_ReturnValue = -2;
+          }
+
+       return (i_ReturnValue);
+       }
+
+/*
++----------------------------------------------------------------------------+
+|                            OUTPUT FUNCTIONS                                |
++----------------------------------------------------------------------------+
+*/
+
+
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     : INT i_APCI1710_InsnWriteDigitalIOChlOnOff(comedi_device 
+|*dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data)
+
++----------------------------------------------------------------------------+
+| Task              : Sets or resets the output witch has been passed with the         |
+|                     parameter b_Channel. Setting an output means setting   |
+|                     an ouput high.                                         |
++----------------------------------------------------------------------------+
+| Input Parameters  : BYTE_ b_BoardHandle   : Handle of board APCI-1710      |
+|                     BYTE_ b_ModulNbr (aref )    : Selected module number (0 to 3)|
+|                     BYTE_ b_OutputChannel (CR_CHAN) : Selection from digital output  |
+|                                             channel (0 to 2)               |
+|                                                0 : Channel H               |
+|                                                1 : Channel A               |
+|                                                2 : Channel B               |
++----------------------------------------------------------------------------+
+| Output Parameters : -                                                      |
++----------------------------------------------------------------------------+
+| Return Value      : 0: No error                                            |
+|                    -1: The handle parameter of the board is wrong          |
+|                    -2: The module parameter is wrong                       |
+|                    -3: The module is not a digital I/O module              |
+|                    -4: The selected digital output is wrong                |
+|                    -5: digital I/O not initialised see function            |
+|                        " i_APCI1710_InitDigitalIO"                         |
+|                    -6: The digital channel A is used for input             |
+|                    -7: The digital channel B is used for input 
+                                        -8: Digital Output Memory OFF.                          |
+|                        Use previously the function                         |
+|                        "i_APCI1710_SetDigitalIOMemoryOn".            |
++----------------------------------------------------------------------------+
+*/
+
+//_INT_   i_APCI1710_SetDigitalIOChlOn    (BYTE_ b_BoardHandle,
+//                                      BYTE_ b_ModulNbr,
+//                                      BYTE_ b_OutputChannel)
+INT i_APCI1710_InsnWriteDigitalIOChlOnOff(comedi_device *dev,comedi_subdevice *s,
+       comedi_insn *insn,lsampl_t *data)
+       {
+       INT    i_ReturnValue = 0;
+       DWORD dw_WriteValue  = 0;
+       BYTE b_ModulNbr,b_OutputChannel;
+       i_ReturnValue   =       insn->n; 
+       b_ModulNbr              =   CR_AREF(insn->chanspec);  
+       b_OutputChannel =   CR_CHAN(insn->chanspec);  
+       
+       
+
+       /**************************/
+       /* Test the module number */
+       /**************************/
+
+       if (b_ModulNbr < 4)
+          {
+          /*******************************/
+          /* Test if digital I/O counter */
+          /*******************************/
+
+          if ((devpriv->s_BoardInfos.
+               dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_DIGITAL_IO)
+             {
+             /**********************************************/
+             /* Test if the digital I/O module initialised */
+             /**********************************************/
+
+             if (devpriv->s_ModuleInfo [b_ModulNbr].
+                 s_DigitalIOInfo.
+                 b_DigitalInit == 1)
+                {
+                /******************************************/
+                /* Test the digital output channel number */
+                /******************************************/
+
+                switch (b_OutputChannel)
+                   {
+                   /*************/
+                   /* Channel H */
+                   /*************/
+
+                   case 0:
+                        break;
+
+                   /*************/
+                   /* Channel A */
+                   /*************/
+
+                   case 1:
+                        if (devpriv->s_ModuleInfo [b_ModulNbr].
+                            s_DigitalIOInfo.
+                            b_ChannelAMode != 1)
+                           {
+                           /*******************************************/
+                           /* The digital channel A is used for input */
+                           /*******************************************/
+
+                           i_ReturnValue = -6;
+                           }
+                        break;
+
+                   /*************/
+                   /* Channel B */
+                   /*************/
+
+                   case 2:
+                        if (devpriv->s_ModuleInfo [b_ModulNbr].
+                            s_DigitalIOInfo.
+                            b_ChannelBMode != 1)
+                           {
+                           /*******************************************/
+                           /* The digital channel B is used for input */
+                           /*******************************************/
+
+                           i_ReturnValue = -7;
+                           }
+                        break;
+
+                   default :
+                        /****************************************/
+                        /* The selected digital output is wrong */
+                        /****************************************/
+
+                        i_ReturnValue = -4;
+                        break;
+                   }
+
+                /***********************/
+                /* Test if error occur */
+                /***********************/
+
+                if (i_ReturnValue >= 0)
+                   {
+            
+                        
+                       /*********************************/
+                   /* Test if set channel ON        */
+                   /*********************************/ 
+                        if(data[0])
+                        {               
+                   /*********************************/
+                   /* Test if output memory enabled */
+                   /*********************************/
+
+                   if (devpriv->s_ModuleInfo [b_ModulNbr].
+                       s_DigitalIOInfo.
+                       b_OutputMemoryEnabled == 1)
+                      {
+                      dw_WriteValue = devpriv->s_ModuleInfo [b_ModulNbr].
+                                      s_DigitalIOInfo.
+                                      dw_OutputMemory | (1 << b_OutputChannel);
+
+                      devpriv->s_ModuleInfo [b_ModulNbr].
+                      s_DigitalIOInfo.
+                      dw_OutputMemory = dw_WriteValue;
+                      }
+                   else
+                      {
+                      dw_WriteValue = 1 << b_OutputChannel;
+                      }
+                        } // set channel off
+             else
+                        {
+                               if (devpriv->s_ModuleInfo [b_ModulNbr].
+                       s_DigitalIOInfo.
+                       b_OutputMemoryEnabled == 1)
+                      {
+                      dw_WriteValue = devpriv->s_ModuleInfo [b_ModulNbr].
+                                      s_DigitalIOInfo.
+                                      dw_OutputMemory & (0xFFFFFFFFUL - (1 << b_OutputChannel));
+
+                      devpriv->s_ModuleInfo [b_ModulNbr].s_DigitalIOInfo.dw_OutputMemory = dw_WriteValue;
+                      }
+                   else
+                      {
+                      /*****************************/
+                      /* Digital Output Memory OFF */
+                      /*****************************/
+                          // +Use previously the function "i_APCI1710_SetDigitalIOMemoryOn"
+                      i_ReturnValue = -8;
+                      }
+
+             }
+                   /*******************/
+                   /* Write the value */
+                   /*******************/
+
+                   //OUTPDW (ps_APCI1710Variable->
+                       //    s_Board [b_BoardHandle].
+                        //   s_BoardInfos.
+                        //   ui_Address + (64 * b_ModulNbr),
+                        //   dw_WriteValue);
+                       outl(dw_WriteValue,devpriv->s_BoardInfos.ui_Address + (64 * b_ModulNbr));
+                   }
+                }
+             else
+                {
+                /*******************************/
+                /* Digital I/O not initialised */
+                /*******************************/
+
+                i_ReturnValue = -5;
+                }
+             }
+          else
+             {
+             /******************************************/
+             /* The module is not a digital I/O module */
+             /******************************************/
+
+             i_ReturnValue = -3;
+             }
+          }
+       else
+          {
+          /***********************/
+          /* Module number error */
+          /***********************/
+
+          i_ReturnValue = -2;
+          }
+
+       return (i_ReturnValue);
+       }
+
+
+
+/*
++----------------------------------------------------------------------------+
+    
+|INT i_APCI1710_InsnBitsDigitalIOPortOnOff(comedi_device *dev,comedi_subdevice 
+       *s,     comedi_insn *insn,lsampl_t *data)
++----------------------------------------------------------------------------+
+| Task              : write:
+                                         Sets or resets one or several outputs from port.                 |
+|                     Setting an output means setting an output high.        |
+|                     If you have switched OFF the digital output memory     |
+|                     (OFF), all the other output are set to "0".            
+
+|                      read:
+                                         Read the status from digital input port                |
+|                     from selected digital I/O module (b_ModulNbr)   
++----------------------------------------------------------------------------+
+| Input Parameters  : 
+       BYTE_ b_BoardHandle   : Handle of board APCI-1710      |
+|   BYTE_ b_ModulNbr  CR_AREF(aref)    : Selected module number (0 to 3)|
+|   BYTE_ b_PortValue CR_CHAN(chanspec) : Output Value ( 0 To 7 )        
+|                       data[0]           read or write port
+                        data[1]            if write then indicate ON or OFF
+
+                        if read : data[1] will return port status.
++----------------------------------------------------------------------------+
+| Output Parameters : -                                                      |
++----------------------------------------------------------------------------+
+| Return Value      :
+
+                INPUT :
+   
+                                         0: No error                                            |
+|                    -1: The handle parameter of the board is wrong          |
+|                    -2: The module parameter is wrong                       |
+|                    -3: The module is not a digital I/O module              |
+|                    -4: Digital I/O not initialised                           
+
+                               OUTPUT:   0: No error                                            |
+|                    -1: The handle parameter of the board is wrong          |
+|                    -2: The module parameter is wrong                       |
+|                    -3: The module is not a digital I/O module              |
+|                    -4: Output value wrong                                  |
+|                    -5: digital I/O not initialised see function            |
+|                        " i_APCI1710_InitDigitalIO"                         |
+|                    -6: The digital channel A is used for input             |
+|                    -7: The digital channel B is used for input 
+                                       -8: Digital Output Memory OFF.                          |
+|                        Use previously the function                         |
+|                        "i_APCI1710_SetDigitalIOMemoryOn".               |
++----------------------------------------------------------------------------+
+*/
+
+//_INT_   i_APCI1710_SetDigitalIOPortOn   (BYTE_ b_BoardHandle,
+//                                      BYTE_ b_ModulNbr,
+//                                      BYTE_ b_PortValue)
+INT i_APCI1710_InsnBitsDigitalIOPortOnOff(comedi_device *dev,comedi_subdevice *s,
+       comedi_insn *insn,lsampl_t *data)
+       {
+       INT    i_ReturnValue = 0;
+       DWORD dw_WriteValue = 0;
+       DWORD dw_StatusReg;
+       BYTE b_ModulNbr,b_PortValue;
+        BYTE b_PortOperation,b_PortOnOFF;
+
+       PBYTE pb_PortValue;
+          
+       b_ModulNbr              = (BYTE) CR_AREF(insn->chanspec);
+       b_PortOperation = (BYTE) data[0];// Input or output 
+       b_PortOnOFF             = (BYTE) data[1];// if output then On or Off
+       b_PortValue             = (BYTE) data[2];// if out put then Value
+       i_ReturnValue   = insn->n;
+        pb_PortValue    = (PBYTE) &data[0];
+// if input then read value
+       
+
+
+    switch(b_PortOperation)
+       {
+    case APCI1710_INPUT  :
+       /**************************/
+       /* Test the module number */
+       /**************************/
+
+       if (b_ModulNbr < 4)
+          {
+          /*******************************/
+          /* Test if digital I/O counter */
+          /*******************************/
+
+          if ((devpriv->s_BoardInfos.
+               dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_DIGITAL_IO)
+             {
+             /**********************************************/
+             /* Test if the digital I/O module initialised */
+             /**********************************************/
+
+             if (devpriv->s_ModuleInfo [b_ModulNbr].
+                 s_DigitalIOInfo.b_DigitalInit == 1)
+                {
+                /**************************/
+                /* Read all digital input */
+                /**************************/
+
+                //INPDW (ps_APCI1710Variable->
+               //      s_Board [b_BoardHandle].
+               //      s_BoardInfos.
+               //      ui_Address + (64 * b_ModulNbr),
+               //      &dw_StatusReg);
+
+          dw_StatusReg=inl(devpriv->s_BoardInfos.ui_Address + (64 * b_ModulNbr));
+                *pb_PortValue = (BYTE) (dw_StatusReg ^ 0x1C);
+               
+                }
+             else
+                {
+                /*******************************/
+                /* Digital I/O not initialised */
+                /*******************************/
+
+                i_ReturnValue = -4;
+                }
+             }
+          else
+             {
+             /******************************************/
+             /* The module is not a digital I/O module */
+             /******************************************/
+
+             i_ReturnValue = -3;
+             }
+          }
+       else
+          {
+          /***********************/
+          /* Module number error */
+          /***********************/
+
+          i_ReturnValue = -2;
+          }
+       
+         break;
+
+       case APCI1710_OUTPUT :
+       /**************************/
+       /* Test the module number */
+       /**************************/
+
+       if (b_ModulNbr < 4)
+          {
+          /*******************************/
+          /* Test if digital I/O counter */
+          /*******************************/
+
+          if ((devpriv->s_BoardInfos.
+               dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_DIGITAL_IO)
+             {
+             /**********************************************/
+             /* Test if the digital I/O module initialised */
+             /**********************************************/
+
+             if (devpriv->s_ModuleInfo [b_ModulNbr].
+                 s_DigitalIOInfo.
+                 b_DigitalInit == 1)
+                {
+                /***********************/
+                /* Test the port value */
+                /***********************/
+
+                if (b_PortValue <= 7)
+                   {
+                   /***********************************/
+                   /* Test the digital output channel */
+                   /***********************************/
+
+                   /**************************/
+                   /* Test if channel A used */
+                   /**************************/
+
+                   if ((b_PortValue & 2) == 2)
+                      {
+                      if (devpriv->s_ModuleInfo [b_ModulNbr].
+                          s_DigitalIOInfo.
+                          b_ChannelAMode != 1)
+                         {
+                         /*******************************************/
+                         /* The digital channel A is used for input */
+                         /*******************************************/
+
+                         i_ReturnValue = -6;
+                         }
+                      } // if ((b_PortValue & 2) == 2)
+
+                   /**************************/
+                   /* Test if channel B used */
+                   /**************************/
+
+                   if ((b_PortValue & 4) == 4)
+                      {
+                      if (devpriv->s_ModuleInfo [b_ModulNbr].
+                          s_DigitalIOInfo.
+                          b_ChannelBMode != 1)
+                         {
+                         /*******************************************/
+                         /* The digital channel B is used for input */
+                         /*******************************************/
+
+                         i_ReturnValue = -7;
+                         }
+                      } // if ((b_PortValue & 4) == 4)
+
+                   /***********************/
+                   /* Test if error occur */
+                   /***********************/
+
+                   if (i_ReturnValue >= 0)
+                      {
+                          
+                         //if(data[1])
+                         //{
+               switch(b_PortOnOFF)
+               { 
+                          /*********************************/
+                      /* Test if set Port ON                   */
+                      /*********************************/
+
+                          case APCI1710_ON :
+
+                      /*********************************/
+                      /* Test if output memory enabled */
+                      /*********************************/
+
+                      if (devpriv->s_ModuleInfo [b_ModulNbr].
+                          s_DigitalIOInfo.
+                          b_OutputMemoryEnabled == 1)
+                         {
+                         dw_WriteValue = devpriv->s_ModuleInfo [b_ModulNbr].
+                                         s_DigitalIOInfo.
+                                         dw_OutputMemory | b_PortValue;
+
+                         devpriv->s_ModuleInfo [b_ModulNbr].
+                         s_DigitalIOInfo.dw_OutputMemory = dw_WriteValue;
+                         }
+                      else
+                         {
+                         dw_WriteValue = b_PortValue;
+                         }
+              break;
+
+                       // If Set PORT  OFF  
+                       case APCI1710_OFF:
+                       
+                          /*********************************/
+                      /* Test if output memory enabled */
+                      /*********************************/
+
+                      if (devpriv->s_ModuleInfo [b_ModulNbr].
+                          s_DigitalIOInfo.b_OutputMemoryEnabled == 1)
+                         {
+                         dw_WriteValue = devpriv->s_ModuleInfo [b_ModulNbr].
+                                         s_DigitalIOInfo.
+                                         dw_OutputMemory & (0xFFFFFFFFUL - b_PortValue);
+
+                         devpriv->s_ModuleInfo [b_ModulNbr].
+                         s_DigitalIOInfo.
+                         dw_OutputMemory = dw_WriteValue;
+                         }
+                      else
+                         {
+                         /*****************************/
+                         /* Digital Output Memory OFF */
+                         /*****************************/
+
+                         i_ReturnValue = -8;
+                         }
+                       } // switch
+
+                      /*******************/
+                      /* Write the value */
+                      /*******************/
+
+                    //  OUTPDW (ps_APCI1710Variable->
+                        //      s_Board [b_BoardHandle].
+                        //      s_BoardInfos.
+                        //      ui_Address + (64 * b_ModulNbr),
+                        //      dw_WriteValue);
+                               outl(dw_WriteValue,devpriv->s_BoardInfos.ui_Address + (64 * b_ModulNbr));
+                      }
+                   }
+                else
+                   {
+                   /**********************/
+                   /* Output value wrong */
+                   /**********************/
+
+                   i_ReturnValue = -4;
+                   }
+                }
+             else
+                {
+                /*******************************/
+                /* Digital I/O not initialised */
+                /*******************************/
+
+                i_ReturnValue = -5;
+                }
+             }
+          else
+             {
+             /******************************************/
+             /* The module is not a digital I/O module */
+             /******************************************/
+
+             i_ReturnValue = -3;
+             }
+          }
+       else
+          {
+          /***********************/
+          /* Module number error */
+          /***********************/
+
+          i_ReturnValue = -2;
+          }
+       break;
+
+       default:
+               i_ReturnValue = -9;
+               DPRINTK("NO INPUT/OUTPUT specified\n");
+  } //switch INPUT / OUTPUT
+       return (i_ReturnValue);
+}
+
+
+
index 78eef9b253bdc15acc3b90f55dbb7d9da4fcc54b..9aed57398b94736f417d931e975c37f823602fa5 100644 (file)
@@ -1,60 +1,60 @@
-/**\r
-@verbatim\r
-\r
-Copyright (C) 2004,2005  ADDI-DATA GmbH for the source code of this module. \r
-        \r
-        ADDI-DATA GmbH \r
-        Dieselstrasse 3 \r
-        D-77833 Ottersweier \r
-        Tel: +19(0)7223/9493-0 \r
-        Fax: +49(0)7223/9493-92 \r
-        http://www.addi-data-com \r
-        info@addi-data.com \r
-\r
-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.\r
-\r
-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.\r
-\r
-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 USA\r
-\r
-You shoud also find the complete GPL in the COPYING file accompanying this source code.\r
-\r
-@endverbatim\r
-*/\r
-\r
-\r
-#define                APCI1710_ON                             1                       // Digital  Output ON or OFF\r
-#define                APCI1710_OFF                    0\r
-\r
-\r
-#define                APCI1710_INPUT                  0               // Digital I/O\r
-#define                APCI1710_OUTPUT                 1\r
-\r
-#define         APCI1710_DIGIO_MEMORYONOFF  0x10       //      \r
-#define         APCI1710_DIGIO_INIT         0x11\r
-\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-|                       DIGITAL I/O INISIALISATION FUNCTION                  |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-\r
-       INT i_APCI1710_InsnConfigDigitalIO(comedi_device *dev,comedi_subdevice *s,\r
-       comedi_insn *insn,lsampl_t *data);\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-|                            INPUT OUTPUT  FUNCTIONS                         |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-INT i_APCI1710_InsnReadDigitalIOChlValue(comedi_device *dev,comedi_subdevice *s,\r
-       comedi_insn *insn,lsampl_t *data);\r
-\r
-INT i_APCI1710_InsnWriteDigitalIOChlOnOff(comedi_device *dev,comedi_subdevice *s,\r
-       comedi_insn *insn,lsampl_t *data);\r
-\r
-INT i_APCI1710_InsnBitsDigitalIOPortOnOff(comedi_device *dev,comedi_subdevice *s,\r
-       comedi_insn *insn,lsampl_t *data);\r
-\r
+/**
+@verbatim
+
+Copyright (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 USA
+
+You shoud also find the complete GPL in the COPYING file accompanying this source code.
+
+@endverbatim
+*/
+
+
+#define                APCI1710_ON                             1                       // Digital  Output ON or OFF
+#define                APCI1710_OFF                    0
+
+
+#define                APCI1710_INPUT                  0               // Digital I/O
+#define                APCI1710_OUTPUT                 1
+
+#define         APCI1710_DIGIO_MEMORYONOFF  0x10       //      
+#define         APCI1710_DIGIO_INIT         0x11
+
+
+/*
++----------------------------------------------------------------------------+
+|                       DIGITAL I/O INISIALISATION FUNCTION                  |
++----------------------------------------------------------------------------+
+*/
+
+
+       INT i_APCI1710_InsnConfigDigitalIO(comedi_device *dev,comedi_subdevice *s,
+       comedi_insn *insn,lsampl_t *data);
+
+/*
++----------------------------------------------------------------------------+
+|                            INPUT OUTPUT  FUNCTIONS                         |
++----------------------------------------------------------------------------+
+*/
+INT i_APCI1710_InsnReadDigitalIOChlValue(comedi_device *dev,comedi_subdevice *s,
+       comedi_insn *insn,lsampl_t *data);
+
+INT i_APCI1710_InsnWriteDigitalIOChlOnOff(comedi_device *dev,comedi_subdevice *s,
+       comedi_insn *insn,lsampl_t *data);
+
+INT i_APCI1710_InsnBitsDigitalIOPortOnOff(comedi_device *dev,comedi_subdevice *s,
+       comedi_insn *insn,lsampl_t *data);
+
index 03211f0ef9b43f7e0c64e84655bb47f588a56c13..9136f51e42a73bd84d6e18a7c8dd026b4b9f4206 100644 (file)
-/**\r
-@verbatim\r
-\r
-Copyright (C) 2004,2005  ADDI-DATA GmbH for the source code of this module. \r
-        \r
-        ADDI-DATA GmbH \r
-        Dieselstrasse 3 \r
-        D-77833 Ottersweier \r
-        Tel: +19(0)7223/9493-0 \r
-        Fax: +49(0)7223/9493-92 \r
-        http://www.addi-data-com \r
-        info@addi-data.com \r
-\r
-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.\r
-\r
-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.\r
-\r
-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 USA\r
-\r
-You shoud also find the complete GPL in the COPYING file accompanying this source code.\r
-\r
-@endverbatim\r
-*/\r
-/*    \r
-  +-----------------------------------------------------------------------+\r
-  | (C) ADDI-DATA GmbH          Dieselstraße 3       D-77833 Ottersweier  |\r
-  +-----------------------------------------------------------------------+\r
-  | Tel : +49 (0) 7223/9493-0     | email    : info@addi-data.com         |\r
-  | Fax : +49 (0) 7223/9493-92    | Internet : http://www.addi-data.com   |\r
-  +-----------------------------------------------------------------------+\r
-  | Project     : API APCI1710    | Compiler : gcc                        |\r
-  | Module name : INC_CPT.C       | Version  : 2.96                       |\r
-  +-------------------------------+---------------------------------------+\r
-  | Project manager: Eric Stolz   | Date     :  02/12/2002                |\r
-  +-----------------------------------------------------------------------+\r
-  | Description :   APCI-1710 incremental counter module                  |\r
-  |                                                                       |\r
-  |                                                                       |\r
-  +-----------------------------------------------------------------------+\r
-  |                             UPDATES                                   |\r
-  +-----------------------------------------------------------------------+\r
-  |   Date   |   Author  |          Description of updates                |\r
-  +----------+-----------+------------------------------------------------+\r
-  |          |           |                                                |\r
-  |----------|-----------|------------------------------------------------|\r
-  | 08/05/00 | Guinot C  | - 0400/0228 All Function in RING 0             |\r
-  |          |           |   available                                    |\r
-  +-----------------------------------------------------------------------+\r
-  | 29/06/01 | Guinot C. | - 1100/0231 -> 0701/0232                       |\r
-  |          |           | See i_APCI1710_DisableFrequencyMeasurement     |\r
-  +-----------------------------------------------------------------------+\r
-*/\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-|                               Included files                               |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-\r
-#include "APCI1710_INCCPT.h"\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| INT  i_APCI1710_InsnConfigINCCPT(comedi_device *dev,comedi_subdevice *s,\r
-comedi_insn *insn,lsampl_t *data)\r
-\r
-+----------------------------------------------------------------------------+\r
-| Task              : Configuration function for INC_CPT                             |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  :                                                                                                           |      \r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : *data\r
-+----------------------------------------------------------------------------+\r
-| Return Value      :                 |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-\r
-INT    i_APCI1710_InsnConfigINCCPT(comedi_device *dev,comedi_subdevice *s,\r
-comedi_insn *insn,lsampl_t *data)\r
-{ \r
-       UINT  ui_ConfigType; \r
-       INT    i_ReturnValue = 0;\r
-       ui_ConfigType=CR_CHAN(insn->chanspec);\r
-       \r
-       printk ("\nINC_CPT");\r
-\r
-       devpriv->tsk_Current=current; // Save the current process task structure\r
-       switch(ui_ConfigType)\r
-       {\r
-       case    APCI1710_INCCPT_INITCOUNTER     :                               \r
-                       i_ReturnValue =i_APCI1710_InitCounter (dev,\r
-                                       CR_AREF(insn->chanspec),\r
-                                       (BYTE) data[0],\r
-                                       (BYTE) data[1],\r
-                                       (BYTE) data[2],\r
-                                       (BYTE) data[3],\r
-                                       (BYTE) data[4]);\r
-                       break;\r
-\r
-       case    APCI1710_INCCPT_COUNTERAUTOTEST:\r
-                       i_ReturnValue =i_APCI1710_CounterAutoTest (dev,\r
-                                       (PBYTE)   &data[0]);\r
-                       break;\r
-\r
-       case    APCI1710_INCCPT_INITINDEX:\r
-                       i_ReturnValue =i_APCI1710_InitIndex    (dev,\r
-                                       CR_AREF(insn->chanspec),\r
-                                       (BYTE) data[0],\r
-                                       (BYTE) data[1],\r
-                                       (BYTE) data[2],\r
-                                       (BYTE) data[3]);\r
-                       break;\r
-\r
-       case    APCI1710_INCCPT_INITREFERENCE:\r
-                       i_ReturnValue =i_APCI1710_InitReference  (dev,\r
-                                       CR_AREF(insn->chanspec),\r
-                                       (BYTE) data[0]);\r
-                       break;\r
-\r
-       case    APCI1710_INCCPT_INITEXTERNALSTROBE:             \r
-                       i_ReturnValue =i_APCI1710_InitExternalStrobe    (dev,\r
-                                       CR_AREF(insn->chanspec),\r
-                                       (BYTE) data[0],\r
-                                       (BYTE) data[1]);\r
-                       break;\r
-\r
-       case    APCI1710_INCCPT_INITCOMPARELOGIC:\r
-                       i_ReturnValue =i_APCI1710_InitCompareLogic     (dev,\r
-                                       CR_AREF(insn->chanspec),\r
-                                       (UINT) data[0]);\r
-                       break;\r
-\r
-       case    APCI1710_INCCPT_INITFREQUENCYMEASUREMENT:\r
-                       i_ReturnValue =i_APCI1710_InitFrequencyMeasurement      (dev,\r
-                                       CR_AREF(insn->chanspec),\r
-                                       (BYTE) data[0],\r
-                                       (BYTE) data[1],\r
-                                       (ULONG) data[2],\r
-                                       (PULONG) &data[0]);\r
-                       break;\r
-\r
-    default: \r
-                   printk("Insn Config : Config Parameter Wrong\n");\r
-\r
-       }\r
-\r
-    if(i_ReturnValue>=0) i_ReturnValue =insn->n;\r
-       return (i_ReturnValue);\r
-}\r
-\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : _INT_ i_APCI1710_InitCounter                           |\r
-|                               (BYTE_          b_BoardHandle,               |\r
-|                                BYTE_          b_ModulNbr,                  |\r
-|                                BYTE_          b_CounterRange,              |\r
-|                                BYTE_          b_FirstCounterModus,         |\r
-|                                BYTE_          b_FirstCounterOption,        |\r
-|                                BYTE_          b_SecondCounterModus,        |\r
-|                                BYTE_          b_SecondCounterOption)       |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Configure the counter operating mode from selected     |\r
-|                     module (b_ModulNbr). You must calling this function be |\r
-|                     for you call any other function witch access of        |\r
-|                     counters.                                              |\r
-|                                                                            |\r
-|                          Counter range                                     |\r
-|                          -------------                                     |\r
-| +------------------------------------+-----------------------------------+ |\r
-| | Parameter       Passed value       |        Description                | |\r
-| |------------------------------------+-----------------------------------| |\r
-| |b_ModulNbr   APCI1710_16BIT_COUNTER |  The module is configured for     | |\r
-| |                                    |  two 16-bit counter.              | |\r
-| |                                    |  - b_FirstCounterModus and        | |\r
-| |                                    |    b_FirstCounterOption           | |\r
-| |                                    |    configure the first 16 bit     | |\r
-| |                                    |    counter.                       | |\r
-| |                                    |  - b_SecondCounterModus and       | |\r
-| |                                    |    b_SecondCounterOption          | |\r
-| |                                    |    configure the second 16 bit    | |\r
-| |                                    |    counter.                       | |\r
-| |------------------------------------+-----------------------------------| |\r
-| |b_ModulNbr   APCI1710_32BIT_COUNTER |  The module is configured for one | |\r
-| |                                    |  32-bit counter.                  | |\r
-| |                                    |  - b_FirstCounterModus and        | |\r
-| |                                    |    b_FirstCounterOption           | |\r
-| |                                    |    configure the 32 bit counter.  | |\r
-| |                                    |  - b_SecondCounterModus and       | |\r
-| |                                    |    b_SecondCounterOption          | |\r
-| |                                    |    are not used and have no       | |\r
-| |                                    |    importance.                    | |\r
-| +------------------------------------+-----------------------------------+ |\r
-|                                                                            |\r
-|                      Counter operating mode                                |\r
-|                      ----------------------                                |\r
-|                                                                            |\r
-| +--------------------+-------------------------+-------------------------+ |\r
-| |    Parameter       |     Passed value        |    Description          | |\r
-| |--------------------+-------------------------+-------------------------| |\r
-| |b_FirstCounterModus | APCI1710_QUADRUPLE_MODE | In the quadruple mode,  | |\r
-| |       or           |                         | the edge analysis       | |\r
-| |b_SecondCounterModus|                         | circuit generates a     | |\r
-| |                    |                         | counting pulse from     | |\r
-| |                    |                         | each edge of 2 signals  | |\r
-| |                    |                         | which are phase shifted | |\r
-| |                    |                         | in relation to each     | |\r
-| |                    |                         | other.                  | |\r
-| |--------------------+-------------------------+-------------------------| |\r
-| |b_FirstCounterModus |   APCI1710_DOUBLE_MODE  | Functions in the same   | |\r
-| |       or           |                         | way as the quadruple    | |\r
-| |b_SecondCounterModus|                         | mode, except that only  | |\r
-| |                    |                         | two of the four edges   | |\r
-| |                    |                         | are analysed per        | |\r
-| |                    |                         | period                  | |\r
-| |--------------------+-------------------------+-------------------------| |\r
-| |b_FirstCounterModus |   APCI1710_SIMPLE_MODE  | Functions in the same   | |\r
-| |       or           |                         | way as the quadruple    | |\r
-| |b_SecondCounterModus|                         | mode, except that only  | |\r
-| |                    |                         | one of the four edges   | |\r
-| |                    |                         | is analysed per         | |\r
-| |                    |                         | period.                 | |\r
-| |--------------------+-------------------------+-------------------------| |\r
-| |b_FirstCounterModus |   APCI1710_DIRECT_MODE  | In the direct mode the  | |\r
-| |       or           |                         | both edge analysis      | |\r
-| |b_SecondCounterModus|                         | circuits are inactive.  | |\r
-| |                    |                         | The inputs A, B in the  | |\r
-| |                    |                         | 32-bit mode or A, B and | |\r
-| |                    |                         | C, D in the 16-bit mode | |\r
-| |                    |                         | represent, each, one    | |\r
-| |                    |                         | clock pulse gate circuit| |\r
-| |                    |                         | There by frequency and  | |\r
-| |                    |                         | pulse duration          | |\r
-| |                    |                         | measurements can be     | |\r
-| |                    |                         | performed.              | |\r
-| +--------------------+-------------------------+-------------------------+ |\r
-|                                                                            |\r
-|                                                                            |\r
-|       IMPORTANT!                                                           |\r
-|       If you have configured the module for two 16-bit counter, a mixed    |\r
-|       mode with a counter in quadruple/double/single mode                  |\r
-|       and the other counter in direct mode is not possible!                |\r
-|                                                                            |\r
-|                                                                            |\r
-|         Counter operating option for quadruple/double/simple mode          |\r
-|         ---------------------------------------------------------          |\r
-|                                                                            |\r
-| +----------------------+-------------------------+------------------------+|\r
-| |       Parameter      |     Passed value        |  Description           ||\r
-| |----------------------+-------------------------+------------------------||\r
-| |b_FirstCounterOption  | APCI1710_HYSTERESIS_ON  | In both edge analysis  ||\r
-| |        or            |                         | circuits is available  ||\r
-| |b_SecondCounterOption |                         | one hysteresis circuit.||\r
-| |                      |                         | It suppresses each     ||\r
-| |                      |                         | time the first counting||\r
-| |                      |                         | pulse after a change   ||\r
-| |                      |                         | of rotation.           ||\r
-| |----------------------+-------------------------+------------------------||\r
-| |b_FirstCounterOption  | APCI1710_HYSTERESIS_OFF | The first counting     ||\r
-| |       or             |                         | pulse is not suppress  ||\r
-| |b_SecondCounterOption |                         | after a change of      ||\r
-| |                      |                         | rotation.              ||\r
-| +----------------------+-------------------------+------------------------+|\r
-|                                                                            |\r
-|                                                                            |\r
-|       IMPORTANT!                                                           |\r
-|       This option are only avaible if you have selected the direct mode.   |\r
-|                                                                            |\r
-|                                                                            |\r
-|               Counter operating option for direct mode                     |\r
-|               ----------------------------------------                     |\r
-|                                                                            |\r
-| +----------------------+--------------------+----------------------------+ |\r
-| |      Parameter       |     Passed value   |       Description          | |\r
-| |----------------------+--------------------+----------------------------| |\r
-| |b_FirstCounterOption  | APCI1710_INCREMENT | The counter increment for  | |\r
-| |       or             |                    | each counting pulse        | |\r
-| |b_SecondCounterOption |                    |                            | |\r
-| |----------------------+--------------------+----------------------------| |\r
-| |b_FirstCounterOption  | APCI1710_DECREMENT | The counter decrement for  | |\r
-| |       or             |                    | each counting pulse        | |\r
-| |b_SecondCounterOption |                    |                            | |\r
-| +----------------------+--------------------+----------------------------+ |\r
-|                                                                            |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : BYTE_ b_BoardHandle         : Handle of board APCI-1710|\r
-|                     BYTE_ b_ModulNbr            : Module number to         |\r
-|                                                   configure (0 to 3)       |\r
-|                     BYTE_ b_CounterRange        : Selection form counter   |\r
-|                                                   range.                   |\r
-|                     BYTE_ b_FirstCounterModus   : First counter operating  |\r
-|                                                   mode.                    |\r
-|                     BYTE_ b_FirstCounterOption  : First counter  option.   |\r
-|                     BYTE_ b_SecondCounterModus  : Second counter operating |\r
-|                                                   mode.                    |\r
-|                     BYTE_ b_SecondCounterOption : Second counter  option.  |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : -                                                      |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      : 0: No error                                            |\r
-|                    -1: The handle parameter of the board is wrong          |\r
-|                    -2: The module is not a counter module                  |\r
-|                    -3: The selected counter range is wrong.                |\r
-|                    -4: The selected first counter operating mode is wrong. |\r
-|                    -5: The selected first counter operating option is wrong|\r
-|                    -6: The selected second counter operating mode is wrong.|\r
-|                    -7: The selected second counter operating option is     |\r
-|                        wrong.                                              |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-\r
-\r
-\r
-\r
-INT   i_APCI1710_InitCounter (comedi_device *dev,\r
-                               BYTE          b_ModulNbr,\r
-                               BYTE          b_CounterRange,\r
-                               BYTE          b_FirstCounterModus,\r
-                               BYTE          b_FirstCounterOption,\r
-                               BYTE          b_SecondCounterModus,\r
-                               BYTE          b_SecondCounterOption)\r
-       {\r
-       INT    i_ReturnValue = 0;\r
-               \r
-       /*******************************/\r
-       /* Test if incremental counter */\r
-       /*******************************/\r
-\r
-       if ((devpriv->s_BoardInfos.\r
-            dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_INCREMENTAL_COUNTER)\r
-          {\r
-          /**************************/\r
-          /* Test the counter range */\r
-          /**************************/\r
-\r
-          if (b_CounterRange == APCI1710_16BIT_COUNTER || b_CounterRange == APCI1710_32BIT_COUNTER)\r
-             {\r
-             /********************************/\r
-             /* Test the first counter modus */\r
-             /********************************/\r
-\r
-             if (b_FirstCounterModus == APCI1710_QUADRUPLE_MODE ||\r
-                 b_FirstCounterModus == APCI1710_DOUBLE_MODE    ||\r
-                 b_FirstCounterModus == APCI1710_SIMPLE_MODE    ||\r
-                 b_FirstCounterModus == APCI1710_DIRECT_MODE)\r
-                {\r
-                /*********************************/\r
-                /* Test the first counter option */\r
-                /*********************************/\r
-\r
-                if ((b_FirstCounterModus   == APCI1710_DIRECT_MODE   &&\r
-                     (b_FirstCounterOption == APCI1710_INCREMENT     ||\r
-                      b_FirstCounterOption == APCI1710_DECREMENT))   ||\r
-                    (b_FirstCounterModus   != APCI1710_DIRECT_MODE   &&\r
-                     (b_FirstCounterOption == APCI1710_HYSTERESIS_ON ||\r
-                      b_FirstCounterOption == APCI1710_HYSTERESIS_OFF)))\r
-                   {\r
-                   /**************************/\r
-                   /* Test if 16-bit counter */\r
-                   /**************************/\r
-\r
-                   if (b_CounterRange == APCI1710_16BIT_COUNTER)\r
-                      {\r
-                      /*********************************/\r
-                      /* Test the second counter modus */\r
-                      /*********************************/\r
-\r
-                      if ((b_FirstCounterModus != APCI1710_DIRECT_MODE      &&\r
-                           (b_SecondCounterModus == APCI1710_QUADRUPLE_MODE ||\r
-                            b_SecondCounterModus == APCI1710_DOUBLE_MODE    ||\r
-                            b_SecondCounterModus == APCI1710_SIMPLE_MODE))  ||\r
-                          (b_FirstCounterModus == APCI1710_DIRECT_MODE &&\r
-                           b_SecondCounterModus == APCI1710_DIRECT_MODE))\r
-                         {\r
-                         /**********************************/\r
-                         /* Test the second counter option */\r
-                         /**********************************/\r
-\r
-                         if ((b_SecondCounterModus   == APCI1710_DIRECT_MODE   &&\r
-                              (b_SecondCounterOption == APCI1710_INCREMENT     ||\r
-                               b_SecondCounterOption == APCI1710_DECREMENT))   ||\r
-                             (b_SecondCounterModus   != APCI1710_DIRECT_MODE   &&\r
-                              (b_SecondCounterOption == APCI1710_HYSTERESIS_ON ||\r
-                               b_SecondCounterOption == APCI1710_HYSTERESIS_OFF)))\r
-                            {\r
-                            i_ReturnValue = 0;\r
-                            }\r
-                         else\r
-                            {\r
-                            /*********************************************************/\r
-                            /* The selected second counter operating option is wrong */\r
-                            /*********************************************************/\r
-\r
-                        DPRINTK("The selected second counter operating option is wrong\n");\r
-                            i_ReturnValue = -7;\r
-                            }\r
-                         }\r
-                      else\r
-                         {\r
-                         /*******************************************************/\r
-                         /* The selected second counter operating mode is wrong */\r
-                         /*******************************************************/\r
-\r
-                         DPRINTK("The selected second counter operating mode is wrong\n");\r
-                         i_ReturnValue = -6;\r
-                         }\r
-                      }\r
-                   }\r
-                else\r
-                   {\r
-                   /********************************************************/\r
-                   /* The selected first counter operating option is wrong */\r
-                   /********************************************************/\r
-\r
-                   DPRINTK("The selected first counter operating option is wrong\n");\r
-                   i_ReturnValue = -5;\r
-                   }\r
-                }\r
-             else\r
-                {\r
-                /******************************************************/\r
-                /* The selected first counter operating mode is wrong */\r
-                /******************************************************/\r
-                 DPRINTK("The selected first counter operating mode is wrong\n");\r
-                i_ReturnValue = -4;\r
-                }\r
-             }\r
-          else\r
-             {\r
-             /***************************************/\r
-             /* The selected counter range is wrong */\r
-             /***************************************/\r
-\r
-             DPRINTK("The selected counter range is wrong\n");\r
-             i_ReturnValue = -3;\r
-             }\r
-\r
-          /*************************/\r
-          /* Test if a error occur */\r
-          /*************************/\r
-\r
-          if (i_ReturnValue == 0)\r
-             {\r
-             /**************************/\r
-             /* Test if 16-Bit counter */\r
-             /**************************/\r
-\r
-             if (b_CounterRange == APCI1710_32BIT_COUNTER)\r
-                {\r
-                devpriv->\r
-                s_ModuleInfo [b_ModulNbr].\r
-                s_SiemensCounterInfo.\r
-                s_ModeRegister.\r
-                s_ByteModeRegister.\r
-                b_ModeRegister1 = b_CounterRange      |\r
-                                  b_FirstCounterModus |\r
-                                  b_FirstCounterOption;\r
-                }\r
-             else\r
-                {\r
-                devpriv->\r
-                s_ModuleInfo [b_ModulNbr].\r
-                s_SiemensCounterInfo.\r
-                s_ModeRegister.\r
-                s_ByteModeRegister.\r
-                b_ModeRegister1 = b_CounterRange                 |\r
-                                  (b_FirstCounterModus   & 0x5)  |\r
-                                  (b_FirstCounterOption  & 0x20) |\r
-                                  (b_SecondCounterModus  & 0xA)  |\r
-                                  (b_SecondCounterOption & 0x40);\r
-\r
-                /***********************/\r
-                /* Test if direct mode */\r
-                /***********************/\r
-\r
-                if (b_FirstCounterModus == APCI1710_DIRECT_MODE)\r
-                   {\r
-                   devpriv->\r
-                   s_ModuleInfo [b_ModulNbr].\r
-                   s_SiemensCounterInfo.\r
-                   s_ModeRegister.\r
-                   s_ByteModeRegister.\r
-                   b_ModeRegister1 = devpriv->\r
-                                     s_ModuleInfo [b_ModulNbr].\r
-                                     s_SiemensCounterInfo.\r
-                                     s_ModeRegister.\r
-                                     s_ByteModeRegister.\r
-                                     b_ModeRegister1 | APCI1710_DIRECT_MODE;\r
-                   }\r
-                }\r
-\r
-             /***************************/\r
-             /* Write the configuration */\r
-             /***************************/\r
-\r
-          \r
-                 outl(devpriv->s_ModuleInfo [b_ModulNbr].\r
-                     s_SiemensCounterInfo.\r
-                     s_ModeRegister.\r
-                     dw_ModeRegister1_2_3_4,\r
-                         devpriv->s_BoardInfos.\r
-                     ui_Address + 20 + (64 * b_ModulNbr));\r
-\r
-\r
-             devpriv->\r
-             s_ModuleInfo [b_ModulNbr].\r
-             s_SiemensCounterInfo.\r
-             s_InitFlag.\r
-             b_CounterInit = 1;\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /**************************************/\r
-          /* The module is not a counter module */\r
-          /**************************************/\r
-\r
-          DPRINTK("The module is not a counter module\n");\r
-          i_ReturnValue = -2;\r
-          }\r
-\r
-       return (i_ReturnValue);\r
-       }\r
-\r
-\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : _INT_ i_APCI1710_CounterAutoTest                       |\r
-|                                               (BYTE_     b_BoardHandle,    |\r
-|                                                PBYTE_   pb_TestStatus)     |\r
-+----------------------------------------------------------------------------+\r
-| Task              : A test mode is intended for testing the component and  |\r
-|                     the connected periphery. All the 8-bit counter chains  |\r
-|                     are operated internally as down counters.              |\r
-|                     Independently from the external signals,               |\r
-|                     all the four 8-bit counter chains are decremented in   |\r
-|                     parallel by each negative clock pulse edge of CLKX.    |\r
-|                                                                            |\r
-|                       Counter auto test conclusion                         |\r
-|                       ----------------------------                         |\r
-|              +-----------------+-----------------------------+             |\r
-|              | pb_TestStatus   |    Error description        |             |\r
-|              |     mask        |                             |             |\r
-|              |-----------------+-----------------------------|             |\r
-|              |    0000         |     No error detected       |             |\r
-|              |-----------------|-----------------------------|             |\r
-|              |    0001         | Error detected of counter 0 |             |\r
-|              |-----------------|-----------------------------|             |\r
-|              |    0010         | Error detected of counter 1 |             |\r
-|              |-----------------|-----------------------------|             |\r
-|              |    0100         | Error detected of counter 2 |             |\r
-|              |-----------------|-----------------------------|             |\r
-|              |    1000         | Error detected of counter 3 |             |\r
-|              +-----------------+-----------------------------+             |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : BYTE_   b_BoardHandle : Handle of board APCI-1710      |  |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : PBYTE_ pb_TestStatus  : Auto test conclusion. See table|\r
-+----------------------------------------------------------------------------+\r
-| Return Value      :  0: No error                                           |\r
-|                     -1: The handle parameter of the board is wrong         |\r
-|                     -2: No counter module found                            |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-INT  i_APCI1710_CounterAutoTest  (comedi_device *dev,PBYTE   pb_TestStatus)\r
-       {\r
-       BYTE   b_ModulCpt    = 0;\r
-       INT    i_ReturnValue = 0;\r
-       DWORD dw_LathchValue;\r
-       \r
-       \r
-       *pb_TestStatus = 0;\r
-\r
-       /********************************/\r
-       /* Test if counter module found */\r
-       /********************************/\r
-\r
-       if ((devpriv->\r
-            s_BoardInfos.\r
-            dw_MolduleConfiguration [0] & 0xFFFF0000UL) == APCI1710_INCREMENTAL_COUNTER ||\r
-           (devpriv->\r
-            s_BoardInfos.\r
-            dw_MolduleConfiguration [1] & 0xFFFF0000UL) == APCI1710_INCREMENTAL_COUNTER ||\r
-           (devpriv->\r
-            s_BoardInfos.\r
-            dw_MolduleConfiguration [2] & 0xFFFF0000UL) == APCI1710_INCREMENTAL_COUNTER||\r
-           (devpriv->\r
-            s_BoardInfos.\r
-            dw_MolduleConfiguration [3] & 0xFFFF0000UL) == APCI1710_INCREMENTAL_COUNTER)\r
-          {\r
-          for (b_ModulCpt = 0; b_ModulCpt < 4 ; b_ModulCpt ++)\r
-             {\r
-             /*******************************/\r
-             /* Test if incremental counter */\r
-             /*******************************/\r
-\r
-             if ((devpriv->\r
-                  s_BoardInfos.\r
-                  dw_MolduleConfiguration [b_ModulCpt] & 0xFFFF0000UL) == APCI1710_INCREMENTAL_COUNTER)\r
-                {\r
-                /******************/\r
-                /* Start the test */\r
-                /******************/\r
-\r
-                \r
-                       outl(3,devpriv->s_BoardInfos.\r
-                        ui_Address + 16 + (64 * b_ModulCpt));\r
-\r
-                /*********************/\r
-                /* Tatch the counter */\r
-                /*********************/\r
-\r
-                \r
-                       outl(1,devpriv->s_BoardInfos.\r
-                        ui_Address + (64 * b_ModulCpt));\r
-\r
-                /************************/\r
-                /* Read the latch value */\r
-                /************************/\r
-\r
-               \r
-                       dw_LathchValue=inl(devpriv->s_BoardInfos.\r
-                       ui_Address + 4 + (64 * b_ModulCpt));\r
-\r
-                if ((dw_LathchValue & 0xFF) != ((dw_LathchValue >> 8)  & 0xFF) &&\r
-                    (dw_LathchValue & 0xFF) != ((dw_LathchValue >> 16) & 0xFF) &&\r
-                    (dw_LathchValue & 0xFF) != ((dw_LathchValue >> 24) & 0xFF))\r
-                   {\r
-                   *pb_TestStatus = *pb_TestStatus | (1 << b_ModulCpt);\r
-                   }\r
-\r
-                /*****************/\r
-                /* Stop the test */\r
-                /*****************/\r
-\r
-                \r
-                outl(0,devpriv->s_BoardInfos.\r
-                        ui_Address + 16 + (64 * b_ModulCpt));\r
-                }\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /***************************/\r
-          /* No counter module found */\r
-          /***************************/\r
-\r
-          DPRINTK("No counter module found\n");\r
-          i_ReturnValue = -2;\r
-          }\r
-\r
-       return (i_ReturnValue);\r
-       }\r
-\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : _INT_ i_APCI1710_InitIndex (BYTE_ b_BoardHandle,       |\r
-|                                                 BYTE_ b_ModulNbr,          |\r
-|                                                 BYTE_ b_ReferenceAction,   |\r
-|                                                 BYTE_ b_IndexOperation,    |\r
-|                                                 BYTE_ b_AutoMode,          |\r
-|                                                 BYTE_ b_InterruptEnable)   |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Initialise the index corresponding to the selected     |\r
-|                     module (b_ModulNbr). If a INDEX flag occur, you have   |\r
-|                     the possibility to clear the 32-Bit counter or to latch|\r
-|                     the current 32-Bit value in to the first latch         |\r
-|                     register. The b_IndexOperation parameter give the      |\r
-|                     possibility to choice the INDEX action.                |\r
-|                     If you have enabled the automatic mode, each INDEX     |\r
-|                     action is cleared automatically, else you must read    |\r
-|                     the index status ("i_APCI1710_ReadIndexStatus")        |\r
-|                     after each INDEX action.                               |\r
-|                                                                            |\r
-|                                                                            |\r
-|                               Index action                                 |\r
-|                               ------------                                 |\r
-|                                                                            |\r
-|           +------------------------+------------------------------------+  |\r
-|           |   b_IndexOperation     |         Operation                  |  |\r
-|           |------------------------+------------------------------------|  |\r
-|           |APCI1710_LATCH_COUNTER  | After a index signal, the counter  |  |\r
-|           |                        | value (32-Bit) is latched in to    |  |\r
-|           |                        | the first latch register           |  |\r
-|           |------------------------|------------------------------------|  |\r
-|           |APCI1710_CLEAR_COUNTER  | After a index signal, the counter  |  |\r
-|           |                        | value is cleared (32-Bit)          |  |\r
-|           +------------------------+------------------------------------+  |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : BYTE_ b_BoardHandle     : Handle of board APCI-1710    |\r
-|                     BYTE_ b_ModulNbr        : Module number to configure   |\r
-|                                               (0 to 3)                     |\r
-|                     BYTE_ b_ReferenceAction : Determine if the reference   |\r
-|                                               must set or no for the       |\r
-|                                               acceptance from index        |\r
-|                                               APCI1710_ENABLE :            |\r
-|                                                  Reference must be set for |\r
-|                                                  accepted the index        |\r
-|                                               APCI1710_DISABLE :           |\r
-|                                                  Reference have not        |\r
-|                                                  importance                |\r
-|                     BYTE_ b_IndexOperation  : Index operating mode.        |\r
-|                                               See table.                   |\r
-|                     BYTE_ b_AutoMode        : Enable or disable the        |\r
-|                                               automatic index reset.       |\r
-|                                               APCI1710_ENABLE :            |\r
-|                                                 Enable the automatic mode  |\r
-|                                               APCI1710_DISABLE :           |\r
-|                                                 Disable the automatic mode |\r
-|                     BYTE_ b_InterruptEnable : Enable or disable the        |\r
-|                                               interrupt.                   |\r
-|                                               APCI1710_ENABLE :            |\r
-|                                               Enable the interrupt         |\r
-|                                               APCI1710_DISABLE :           |\r
-|                                               Disable the interrupt        |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : -                                                      |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      :  0: No error                                           |\r
-|                     -1: The handle parameter of the board is wrong         |\r
-|                     -2: No counter module found                            |\r
-|                     -3: Counter not initialised see function               |\r
-|                         "i_APCI1710_InitCounter"                           |\r
-|                     -4  The reference action parameter is wrong            |\r
-|                     -5: The index operating mode parameter is wrong        |\r
-|                     -6: The auto mode parameter is wrong                   |\r
-|                     -7: Interrupt parameter is wrong                       |\r
-|                     -8: Interrupt function not initialised.                |\r
-|                         See function "i_APCI1710_SetBoardIntRoutineX"      |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-INT   i_APCI1710_InitIndex    (comedi_device *dev,\r
-                                BYTE b_ModulNbr,\r
-                                BYTE b_ReferenceAction,\r
-                                BYTE b_IndexOperation,\r
-                                BYTE b_AutoMode,\r
-                                BYTE b_InterruptEnable)\r
-       {\r
-       INT  i_ReturnValue = 0;\r
-       \r
-\r
-       /**************************/\r
-       /* Test the module number */\r
-       /**************************/\r
-\r
-       if (b_ModulNbr < 4)\r
-          {\r
-          /*******************************/\r
-          /* Test if counter initialised */\r
-          /*******************************/\r
-\r
-          if (devpriv->\r
-              s_ModuleInfo [b_ModulNbr].\r
-              s_SiemensCounterInfo.\r
-              s_InitFlag.\r
-              b_CounterInit == 1)\r
-             {\r
-             /********************************/\r
-             /* Test the reference parameter */\r
-             /********************************/\r
-\r
-             if (b_ReferenceAction == APCI1710_ENABLE ||\r
-                 b_ReferenceAction == APCI1710_DISABLE)\r
-                {\r
-                /****************************/\r
-                /* Test the index parameter */\r
-                /****************************/\r
-\r
-                if (b_IndexOperation == APCI1710_HIGH_EDGE_LATCH_COUNTER           ||\r
-                    b_IndexOperation == APCI1710_LOW_EDGE_LATCH_COUNTER            ||\r
-                    b_IndexOperation == APCI1710_HIGH_EDGE_CLEAR_COUNTER           ||\r
-                    b_IndexOperation == APCI1710_LOW_EDGE_CLEAR_COUNTER            ||\r
-                    b_IndexOperation == APCI1710_HIGH_EDGE_LATCH_AND_CLEAR_COUNTER ||\r
-                    b_IndexOperation == APCI1710_LOW_EDGE_LATCH_AND_CLEAR_COUNTER)\r
-                   {\r
-                   /********************************/\r
-                   /* Test the auto mode parameter */\r
-                   /********************************/\r
-\r
-                   if (b_AutoMode == APCI1710_ENABLE ||\r
-                       b_AutoMode == APCI1710_DISABLE)\r
-                      {\r
-                      /***************************/\r
-                      /* Test the interrupt mode */\r
-                      /***************************/\r
-\r
-                      if (b_InterruptEnable == APCI1710_ENABLE ||\r
-                          b_InterruptEnable == APCI1710_DISABLE)\r
-                         {\r
-                        \r
-                            /************************************/\r
-                            /* Makte the configuration commando */\r
-                            /************************************/\r
-\r
-                            if (b_ReferenceAction == APCI1710_ENABLE)\r
-                               {\r
-                               devpriv->\r
-                               s_ModuleInfo [b_ModulNbr].\r
-                               s_SiemensCounterInfo.\r
-                               s_ModeRegister.\r
-                               s_ByteModeRegister.\r
-                               b_ModeRegister2 = devpriv->\r
-                                                 s_ModuleInfo [b_ModulNbr].\r
-                                                 s_SiemensCounterInfo.\r
-                                                 s_ModeRegister.\r
-                                                 s_ByteModeRegister.\r
-                                                 b_ModeRegister2 | APCI1710_ENABLE_INDEX_ACTION;\r
-                               }\r
-                            else\r
-                               {\r
-                               devpriv->\r
-                               s_ModuleInfo [b_ModulNbr].\r
-                               s_SiemensCounterInfo.\r
-                               s_ModeRegister.\r
-                               s_ByteModeRegister.\r
-                               b_ModeRegister2 = devpriv->\r
-                                                 s_ModuleInfo [b_ModulNbr].\r
-                                                 s_SiemensCounterInfo.\r
-                                                 s_ModeRegister.\r
-                                                 s_ByteModeRegister.\r
-                                                 b_ModeRegister2 & APCI1710_DISABLE_INDEX_ACTION;\r
-                               }\r
-\r
-                            /****************************************/\r
-                            /* Test if low level latch or/and clear */\r
-                            /****************************************/\r
-\r
-                            if (b_IndexOperation == APCI1710_LOW_EDGE_LATCH_COUNTER ||\r
-                                b_IndexOperation == APCI1710_LOW_EDGE_CLEAR_COUNTER ||\r
-                                b_IndexOperation == APCI1710_LOW_EDGE_LATCH_AND_CLEAR_COUNTER)\r
-                               {\r
-                               /*************************************/\r
-                               /* Set the index level to low (DQ26) */\r
-                               /*************************************/\r
-\r
-                               devpriv->\r
-                               s_ModuleInfo [b_ModulNbr].\r
-                               s_SiemensCounterInfo.\r
-                               s_ModeRegister.\r
-                               s_ByteModeRegister.\r
-                               b_ModeRegister4 = devpriv->\r
-                                                 s_ModuleInfo [b_ModulNbr].\r
-                                                 s_SiemensCounterInfo.\r
-                                                 s_ModeRegister.\r
-                                                 s_ByteModeRegister.\r
-                                                 b_ModeRegister4 | APCI1710_SET_LOW_INDEX_LEVEL;\r
-                               }\r
-                            else\r
-                               {\r
-                               /**************************************/\r
-                               /* Set the index level to high (DQ26) */\r
-                               /**************************************/\r
-\r
-                               devpriv->\r
-                               s_ModuleInfo [b_ModulNbr].\r
-                               s_SiemensCounterInfo.\r
-                               s_ModeRegister.\r
-                               s_ByteModeRegister.\r
-                               b_ModeRegister4 = devpriv->\r
-                                                 s_ModuleInfo [b_ModulNbr].\r
-                                                 s_SiemensCounterInfo.\r
-                                                 s_ModeRegister.\r
-                                                 s_ByteModeRegister.\r
-                                                 b_ModeRegister4 & APCI1710_SET_HIGH_INDEX_LEVEL;\r
-                               }\r
-\r
-                            /***********************************/\r
-                            /* Test if latch and clear counter */\r
-                            /***********************************/\r
-\r
-                            if (b_IndexOperation == APCI1710_HIGH_EDGE_LATCH_AND_CLEAR_COUNTER ||\r
-                                b_IndexOperation == APCI1710_LOW_EDGE_LATCH_AND_CLEAR_COUNTER)\r
-                               {\r
-                               /***************************************/\r
-                               /* Set the latch and clear flag (DQ27) */\r
-                               /***************************************/\r
-\r
-                               devpriv->\r
-                               s_ModuleInfo [b_ModulNbr].\r
-                               s_SiemensCounterInfo.\r
-                               s_ModeRegister.\r
-                               s_ByteModeRegister.\r
-                               b_ModeRegister4 = devpriv->\r
-                                                 s_ModuleInfo [b_ModulNbr].\r
-                                                 s_SiemensCounterInfo.\r
-                                                 s_ModeRegister.\r
-                                                 s_ByteModeRegister.\r
-                                                 b_ModeRegister4 | APCI1710_ENABLE_LATCH_AND_CLEAR;\r
-                               } // if (b_IndexOperation == APCI1710_HIGH_EDGE_LATCH_AND_CLEAR_COUNTER || b_IndexOperation == APCI1710_LOW_EDGE_LATCH_AND_CLEAR_COUNTER)\r
-                            else\r
-                               {\r
-                               /*****************************************/\r
-                               /* Clear the latch and clear flag (DQ27) */\r
-                               /*****************************************/\r
-\r
-                               devpriv->\r
-                               s_ModuleInfo [b_ModulNbr].\r
-                               s_SiemensCounterInfo.\r
-                               s_ModeRegister.\r
-                               s_ByteModeRegister.\r
-                               b_ModeRegister4 = devpriv->\r
-                                                 s_ModuleInfo [b_ModulNbr].\r
-                                                 s_SiemensCounterInfo.\r
-                                                 s_ModeRegister.\r
-                                                 s_ByteModeRegister.\r
-                                                 b_ModeRegister4 & APCI1710_DISABLE_LATCH_AND_CLEAR;\r
-\r
-                               /*************************/\r
-                               /* Test if latch counter */\r
-                               /*************************/\r
-\r
-                               if (b_IndexOperation == APCI1710_HIGH_EDGE_LATCH_COUNTER ||\r
-                                   b_IndexOperation == APCI1710_LOW_EDGE_LATCH_COUNTER)\r
-                                  {\r
-                                  /*********************************/\r
-                                  /* Enable the latch from counter */\r
-                                  /*********************************/\r
-\r
-                                  devpriv->\r
-                                  s_ModuleInfo [b_ModulNbr].\r
-                                  s_SiemensCounterInfo.\r
-                                  s_ModeRegister.\r
-                                  s_ByteModeRegister.\r
-                                  b_ModeRegister2 = devpriv->\r
-                                                    s_ModuleInfo [b_ModulNbr].\r
-                                                    s_SiemensCounterInfo.\r
-                                                    s_ModeRegister.\r
-                                                    s_ByteModeRegister.\r
-                                                    b_ModeRegister2 | APCI1710_INDEX_LATCH_COUNTER;\r
-                                  }\r
-                               else\r
-                                  {\r
-                                  /*********************************/\r
-                                  /* Enable the clear from counter */\r
-                                  /*********************************/\r
-\r
-                                  devpriv->\r
-                                  s_ModuleInfo [b_ModulNbr].\r
-                                  s_SiemensCounterInfo.\r
-                                  s_ModeRegister.\r
-                                  s_ByteModeRegister.\r
-                                  b_ModeRegister2 = devpriv->\r
-                                                    s_ModuleInfo [b_ModulNbr].\r
-                                                    s_SiemensCounterInfo.\r
-                                                    s_ModeRegister.\r
-                                                    s_ByteModeRegister.\r
-                                                    b_ModeRegister2 & (~APCI1710_INDEX_LATCH_COUNTER);\r
-                                  }\r
-                               } // // if (b_IndexOperation == APCI1710_HIGH_EDGE_LATCH_AND_CLEAR_COUNTER || b_IndexOperation == APCI1710_LOW_EDGE_LATCH_AND_CLEAR_COUNTER)\r
-\r
-\r
-                            if (b_AutoMode == APCI1710_DISABLE)\r
-                               {\r
-                               devpriv->\r
-                               s_ModuleInfo [b_ModulNbr].\r
-                               s_SiemensCounterInfo.\r
-                               s_ModeRegister.\r
-                               s_ByteModeRegister.\r
-                               b_ModeRegister2 = devpriv->\r
-                                                 s_ModuleInfo [b_ModulNbr].\r
-                                                 s_SiemensCounterInfo.\r
-                                                 s_ModeRegister.\r
-                                                 s_ByteModeRegister.\r
-                                                 b_ModeRegister2 | APCI1710_INDEX_AUTO_MODE;\r
-                               }\r
-                            else\r
-                               {\r
-                               devpriv->\r
-                               s_ModuleInfo [b_ModulNbr].\r
-                               s_SiemensCounterInfo.\r
-                               s_ModeRegister.\r
-                               s_ByteModeRegister.\r
-                               b_ModeRegister2 = devpriv->\r
-                                                 s_ModuleInfo [b_ModulNbr].\r
-                                                 s_SiemensCounterInfo.\r
-                                                 s_ModeRegister.\r
-                                                 s_ByteModeRegister.\r
-                                                 b_ModeRegister2 & (~APCI1710_INDEX_AUTO_MODE);\r
-                               }\r
-\r
-                            if (b_InterruptEnable == APCI1710_ENABLE)\r
-                               {\r
-                               devpriv->\r
-                               s_ModuleInfo [b_ModulNbr].\r
-                               s_SiemensCounterInfo.\r
-                               s_ModeRegister.\r
-                               s_ByteModeRegister.\r
-                               b_ModeRegister3 = devpriv->\r
-                                                 s_ModuleInfo [b_ModulNbr].\r
-                                                 s_SiemensCounterInfo.\r
-                                                 s_ModeRegister.\r
-                                                 s_ByteModeRegister.\r
-                                                 b_ModeRegister3 | APCI1710_ENABLE_INDEX_INT;\r
-                               }\r
-                            else\r
-                               {\r
-                               devpriv->\r
-                               s_ModuleInfo [b_ModulNbr].\r
-                               s_SiemensCounterInfo.\r
-                               s_ModeRegister.\r
-                               s_ByteModeRegister.\r
-                               b_ModeRegister3 = devpriv->\r
-                                                 s_ModuleInfo [b_ModulNbr].\r
-                                                 s_SiemensCounterInfo.\r
-                                                 s_ModeRegister.\r
-                                                 s_ByteModeRegister.\r
-                                                 b_ModeRegister3 & APCI1710_DISABLE_INDEX_INT;\r
-                               }\r
-\r
-                            devpriv->\r
-                            s_ModuleInfo [b_ModulNbr].\r
-                            s_SiemensCounterInfo.\r
-                            s_InitFlag.\r
-                            b_IndexInit = 1;\r
-                           \r
-                         }\r
-                      else\r
-                         {\r
-                         /********************************/\r
-                         /* Interrupt parameter is wrong */\r
-                         /********************************/\r
-                         DPRINTK("Interrupt parameter is wrong\n");    \r
-                         i_ReturnValue = -7;\r
-                         }\r
-                      }\r
-                   else\r
-                      {\r
-                      /************************************/\r
-                      /* The auto mode parameter is wrong */\r
-                      /************************************/\r
-\r
-                          DPRINTK("The auto mode parameter is wrong\n");\r
-                      i_ReturnValue = -6;\r
-                      }\r
-                   }\r
-                else\r
-                   {\r
-                   /***********************************************/\r
-                   /* The index operating mode parameter is wrong */\r
-                   /***********************************************/\r
-\r
-                   DPRINTK("The index operating mode parameter is wrong\n");\r
-                   i_ReturnValue = -5;\r
-                   }\r
-                }\r
-             else\r
-                {\r
-                /*******************************************/\r
-                /* The reference action parameter is wrong */\r
-                /*******************************************/\r
-\r
-                DPRINTK("The reference action parameter is wrong\n");\r
-                i_ReturnValue = -4;\r
-                }\r
-             }\r
-          else\r
-             {\r
-             /****************************************/\r
-             /* Counter not initialised see function */\r
-             /* "i_APCI1710_InitCounter"             */\r
-             /****************************************/\r
-\r
-             DPRINTK("Counter not initialised\n");     \r
-             i_ReturnValue = -3;\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /*************************************************/\r
-          /* The selected module number parameter is wrong */\r
-          /*************************************************/\r
-\r
-          DPRINTK("The selected module number parameter is wrong\n");\r
-          i_ReturnValue = -2;\r
-          }\r
-\r
-       return (i_ReturnValue);\r
-       }\r
-\r
-\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : _INT_ i_APCI1710_InitReference                         |\r
-|                                                (BYTE_ b_BoardHandle,       |\r
-|                                                 BYTE_ b_ModulNbr,          |\r
-|                                                 BYTE_ b_ReferenceLevel)    |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Initialise the reference corresponding to the selected |\r
-|                     module (b_ModulNbr).                                   |\r
-|                                                                            |\r
-|                               Reference level                              |\r
-|                               ---------------                              |\r
-|             +--------------------+-------------------------+               |\r
-|             | b_ReferenceLevel   |         Operation       |               |\r
-|             +--------------------+-------------------------+               |\r
-|             |   APCI1710_LOW     |  Reference occur if "0" |               |\r
-|             |--------------------|-------------------------|               |\r
-|             |   APCI1710_HIGH    |  Reference occur if "1" |               |\r
-|             +--------------------+-------------------------+               |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : BYTE_ b_BoardHandle     : Handle of board APCI-1710    |\r
-|                     BYTE_ b_ModulNbr        : Module number to configure   |\r
-|                                               (0 to 3)                     |\r
-|                     BYTE_ b_ReferenceLevel  : Reference level.             |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : -                                                      |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      :  0: No error                                           |\r
-|                     -1: The handle parameter of the board is wrong         |\r
-|                     -2: The selected module number parameter is wrong      |\r
-|                     -3: Counter not initialised see function               |\r
-|                         "i_APCI1710_InitCounter"                           |\r
-|                     -4: Reference level parameter is wrong                 |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-INT   i_APCI1710_InitReference        (comedi_device *dev,\r
-                                        BYTE b_ModulNbr,\r
-                                        BYTE b_ReferenceLevel)\r
-       {\r
-       INT i_ReturnValue = 0;\r
-       \r
-       /**************************/\r
-       /* Test the module number */\r
-       /**************************/\r
-\r
-       if (b_ModulNbr < 4)\r
-          {\r
-          /*******************************/\r
-          /* Test if counter initialised */\r
-          /*******************************/\r
-\r
-          if (devpriv->\r
-              s_ModuleInfo [b_ModulNbr].\r
-              s_SiemensCounterInfo.\r
-              s_InitFlag.\r
-              b_CounterInit == 1)\r
-             {\r
-             /**************************************/\r
-             /* Test the reference level parameter */\r
-             /**************************************/\r
-\r
-             if (b_ReferenceLevel == 0 ||\r
-                 b_ReferenceLevel == 1)\r
-                {\r
-                if (b_ReferenceLevel == 1)\r
-                   {\r
-                   devpriv->\r
-                   s_ModuleInfo [b_ModulNbr].\r
-                   s_SiemensCounterInfo.\r
-                   s_ModeRegister.\r
-                   s_ByteModeRegister.\r
-                   b_ModeRegister2 = devpriv->\r
-                                     s_ModuleInfo [b_ModulNbr].\r
-                                     s_SiemensCounterInfo.\r
-                                     s_ModeRegister.\r
-                                     s_ByteModeRegister.\r
-                                     b_ModeRegister2 | APCI1710_REFERENCE_HIGH;\r
-                   }\r
-                else\r
-                   {\r
-                   devpriv->\r
-                   s_ModuleInfo [b_ModulNbr].\r
-                   s_SiemensCounterInfo.\r
-                   s_ModeRegister.\r
-                   s_ByteModeRegister.\r
-                   b_ModeRegister2 = devpriv->\r
-                                     s_ModuleInfo [b_ModulNbr].\r
-                                     s_SiemensCounterInfo.\r
-                                     s_ModeRegister.\r
-                                     s_ByteModeRegister.\r
-                                     b_ModeRegister2 & APCI1710_REFERENCE_LOW;\r
-                   }\r
-\r
-                \r
-                outl(devpriv->s_ModuleInfo [b_ModulNbr].\r
-                        s_SiemensCounterInfo.\r
-                        s_ModeRegister.\r
-                        dw_ModeRegister1_2_3_4,devpriv->s_BoardInfos.\r
-                        ui_Address + 20 + (64 * b_ModulNbr));\r
-\r
-\r
-                devpriv->\r
-                s_ModuleInfo [b_ModulNbr].\r
-                s_SiemensCounterInfo.\r
-                s_InitFlag.\r
-                b_ReferenceInit = 1;\r
-                }\r
-             else\r
-                {\r
-                /**************************************/\r
-                /* Reference level parameter is wrong */\r
-                /**************************************/\r
-\r
-                DPRINTK("Reference level parameter is wrong\n");\r
-                i_ReturnValue = -4;\r
-                }\r
-             }\r
-          else\r
-             {\r
-             /****************************************/\r
-             /* Counter not initialised see function */\r
-             /* "i_APCI1710_InitCounter"             */\r
-             /****************************************/\r
-\r
-             DPRINTK("Counter not initialised\n");     \r
-             i_ReturnValue = -3;\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /*************************************************/\r
-          /* The selected module number parameter is wrong */\r
-          /*************************************************/\r
-\r
-          DPRINTK("The selected module number parameter is wrong\n");  \r
-          i_ReturnValue = -2;\r
-          }\r
-\r
-       return (i_ReturnValue);\r
-       }\r
-\r
-\r
-\r
-       \r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : _INT_    i_APCI1710_InitExternalStrobe                |\r
-|                                      (BYTE_ b_BoardHandle,                |\r
-|                                       BYTE_ b_ModulNbr,                   |\r
-|                                       BYTE_ b_ExternalStrobe,             |\r
-|                                       BYTE_ b_ExternalStrobeLevel)        |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Initialises the external strobe level corresponding to |\r
-|                    the selected module (b_ModulNbr).                      |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : BYTE_ b_BoardHandle     : Handle of board APCI-1710    |\r
-|                     BYTE_ b_ModulNbr        : Module number to configure   |\r
-|                                               (0 to 3)                     |\r
-|                    BYTE_ b_ExternalStrobe  : External strobe selection    |\r
-|                                              0 : External strobe A        |\r
-|                                              1 : External strobe B        |\r
-|                    BYTE_ b_ExternalStrobeLevel : External strobe level    |\r
-|                                              APCI1710_LOW :               |\r
-|                                              External latch occurs if "0" |\r
-|                                              APCI1710_HIGH :              |\r
-|                                              External latch occurs if "1" |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : -                                                      |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      :  0: No error                                           |\r
-|                     -1: The handle parameter of the board is wrong         |\r
-|                     -2: The selected module number is wrong                |\r
-|                     -3: Counter not initialised.                           |\r
-|                        See function "i_APCI1710_InitCounter"              |\r
-|                     -4: External strobe selection is wrong                 |\r
-|                     -5: External strobe level parameter is wrong           |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-INT    i_APCI1710_InitExternalStrobe   (comedi_device *dev,\r
-                                        BYTE b_ModulNbr,\r
-                                        BYTE b_ExternalStrobe,\r
-                                        BYTE b_ExternalStrobeLevel)\r
-       {\r
-       INT    i_ReturnValue = 0;\r
-       \r
-       \r
-       /**************************/\r
-       /* Test the module number */\r
-       /**************************/\r
-\r
-       if (b_ModulNbr < 4)\r
-          {\r
-          /*******************************/\r
-          /* Test if counter initialised */\r
-          /*******************************/\r
-\r
-          if (devpriv->\r
-              s_ModuleInfo [b_ModulNbr].\r
-              s_SiemensCounterInfo.\r
-              s_InitFlag.\r
-              b_CounterInit == 1)\r
-             {\r
-             /**************************************/\r
-             /* Test the external strobe selection */\r
-              /**************************************/\r
-\r
-             if (b_ExternalStrobe == 0 || b_ExternalStrobe == 1)\r
-                {\r
-                /******************/\r
-                /* Test the level */\r
-                /******************/\r
-\r
-                if ((b_ExternalStrobeLevel == APCI1710_HIGH) ||\r
-                    ((b_ExternalStrobeLevel == APCI1710_LOW && (devpriv->\r
-                                                                s_BoardInfos.\r
-                                                                dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) >= 0x3135)))\r
-                   {\r
-                   /*****************/\r
-                   /* Set the level */\r
-                   /*****************/\r
-\r
-                   devpriv->\r
-                   s_ModuleInfo [b_ModulNbr].\r
-                   s_SiemensCounterInfo.\r
-                   s_ModeRegister.\r
-                   s_ByteModeRegister.\r
-                   b_ModeRegister4 = (devpriv->\r
-                                      s_ModuleInfo [b_ModulNbr].\r
-                                      s_SiemensCounterInfo.\r
-                                      s_ModeRegister.\r
-                                      s_ByteModeRegister.\r
-                                      b_ModeRegister4 & (0xFF - (0x10 << b_ExternalStrobe))) |\r
-                                      ((b_ExternalStrobeLevel^1) << (4 + b_ExternalStrobe));\r
-                   }\r
-                else\r
-                   {\r
-                   /********************************************/\r
-                   /* External strobe level parameter is wrong */\r
-                   /********************************************/\r
-\r
-                       DPRINTK("External strobe level parameter is wrong\n");\r
-                   i_ReturnValue = -5;\r
-                   }\r
-                } // if (b_ExternalStrobe == 0 || b_ExternalStrobe == 1)\r
-             else\r
-                {\r
-                /**************************************/\r
-                /* External strobe selection is wrong */\r
-                /**************************************/\r
-\r
-                DPRINTK("External strobe selection is wrong\n");\r
-                i_ReturnValue = -4;\r
-                } // if (b_ExternalStrobe == 0 || b_ExternalStrobe == 1)\r
-             }\r
-          else\r
-             {\r
-             /****************************************/\r
-             /* Counter not initialised see function */\r
-             /* "i_APCI1710_InitCounter"             */\r
-             /****************************************/\r
-\r
-             DPRINTK("Counter not initialised\n");     \r
-             i_ReturnValue = -3;\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /*************************************************/\r
-          /* The selected module number parameter is wrong */\r
-          /*************************************************/\r
-\r
-          DPRINTK("The selected module number parameter is wrong\n");  \r
-          i_ReturnValue = -2;\r
-          }\r
-\r
-       return (i_ReturnValue);\r
-       }\r
-\r
-\r
-       /*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : _INT_ i_APCI1710_InitCompareLogic                      |\r
-|                               (BYTE_   b_BoardHandle,                      |\r
-|                                BYTE_   b_ModulNbr,                         |\r
-|                                UINT_  ui_CompareValue)                     |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Set the 32-Bit compare value. At that moment that the  |\r
-|                     incremental counter arrive to the compare value        |\r
-|                     (ui_CompareValue) a interrupt is generated.            |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : BYTE_  b_BoardHandle    : Handle of board APCI-1710    |\r
-|                     BYTE_  b_ModulNbr       : Module number to configure   |\r
-|                                               (0 to 3)                     |\r
-|                     UINT_ ui_CompareValue   : 32-Bit compare value         |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : -\r
-+----------------------------------------------------------------------------+\r
-| Return Value      :  0: No error                                           |\r
-|                     -1: The handle parameter of the board is wrong         |\r
-|                     -2: No counter module found                            |\r
-|                     -3: Counter not initialised see function               |\r
-|                         "i_APCI1710_InitCounter"                           |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-INT   i_APCI1710_InitCompareLogic     (comedi_device *dev,\r
-                                        BYTE   b_ModulNbr,\r
-                                        UINT  ui_CompareValue)\r
-       {\r
-       INT    i_ReturnValue = 0;\r
-       \r
-\r
-       /**************************/\r
-       /* Test the module number */\r
-       /**************************/\r
-\r
-       if (b_ModulNbr < 4)\r
-          {\r
-          /*******************************/\r
-          /* Test if counter initialised */\r
-          /*******************************/\r
-\r
-          if (devpriv->\r
-              s_ModuleInfo [b_ModulNbr].\r
-              s_SiemensCounterInfo.\r
-              s_InitFlag.\r
-              b_CounterInit == 1)\r
-             {\r
-             \r
-                  outl(ui_CompareValue,devpriv->s_BoardInfos.\r
-                     ui_Address + 28 + (64 * b_ModulNbr));\r
-\r
-             devpriv->\r
-             s_ModuleInfo [b_ModulNbr].\r
-             s_SiemensCounterInfo.\r
-             s_InitFlag.\r
-             b_CompareLogicInit = 1;\r
-             }\r
-          else\r
-             {\r
-             /****************************************/\r
-             /* Counter not initialised see function */\r
-             /* "i_APCI1710_InitCounter"             */\r
-             /****************************************/\r
-\r
-             DPRINTK("Counter not initialised\n");     \r
-             i_ReturnValue = -3;\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /*************************************************/\r
-          /* The selected module number parameter is wrong */\r
-          /*************************************************/\r
-\r
-          DPRINTK("The selected module number parameter is wrong\n");  \r
-          i_ReturnValue = -2;\r
-          }\r
-\r
-       return (i_ReturnValue);\r
-       }\r
-\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : _INT_ i_APCI1710_InitFrequencyMeasurement              |\r
-|                              (BYTE_           b_BoardHandle,              |\r
-|                               BYTE_           b_ModulNbr,                 |\r
-|                               BYTE_           b_PCIInputClock,            |\r
-|                               BYTE_           b_TimingUnity,              |\r
-|                               ULONG_         ul_TimingInterval,           |\r
-|                               PULONG_       pul_RealTimingInterval)       |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Sets the time for the frequency measurement.           |\r
-|                    Configures the selected TOR incremental counter of the |\r
-|                    selected module (b_ModulNbr). The ul_TimingInterval and|\r
-|                    ul_TimingUnity determine the time base for the         |\r
-|                    measurement. The pul_RealTimingInterval returns the    |\r
-|                    real time value. You must call up this function before |\r
-|                    you call up any other function which gives access to   |\r
-|                    the frequency measurement.                             |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : BYTE_  b_BoardHandle    : Handle of board APCI-1710    |\r
-|                    BYTE_  b_ModulNbr       : Number of the module to be   |\r
-|                                              configured (0 to 3)          |\r
-|                    BYTE_  b_PCIInputClock  : Selection of the PCI bus     |\r
-|                                              clock                        |\r
-|                                              - APCI1710_30MHZ :           |\r
-|                                                The PC has a PCI bus clock |\r
-|                                                of 30 MHz                  |\r
-|                                              - APCI1710_33MHZ :           |\r
-|                                                The PC has a PCI bus clock |\r
-|                                                of 33 MHz                  |\r
-|                    BYTE_  b_TimingUnity    : Base time unit (0 to 2)      |\r
-|                                                0 : ns                     |\r
-|                                                1 : æs                     |\r
-|                                                2 : ms                     |\r
-|                    ULONG_ ul_TimingInterval: Base time value.             |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : PULONG_ pul_RealTimingInterval : Real base time value. |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      :  0: No error                                           |\r
-|                     -1: The handle parameter of the board is wrong         |\r
-|                     -2: The selected module number is wrong                |\r
-|                     -3: Counter not initialised see function               |\r
-|                        "i_APCI1710_InitCounter"                           |\r
-|                     -4: The selected PCI input clock is wrong              |\r
-|                     -5: Timing unity selection is wrong                    |\r
-|                     -6: Base timing selection is wrong                     |\r
-|                    -7: 40MHz quartz not on board                          |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-INT    i_APCI1710_InitFrequencyMeasurement     (comedi_device *dev,\r
-                                                BYTE            b_ModulNbr,\r
-                                                BYTE            b_PCIInputClock,\r
-                                                BYTE            b_TimingUnity,\r
-                                                ULONG           ul_TimingInterval,\r
-                                                PULONG      pul_RealTimingInterval)\r
-       {\r
-       INT    i_ReturnValue = 0;\r
-       ULONG ul_TimerValue  = 0;\r
-       double d_RealTimingInterval;\r
-       DWORD dw_Status      = 0;\r
-       \r
-       /**************************/\r
-       /* Test the module number */\r
-       /**************************/\r
-\r
-       if (b_ModulNbr < 4)\r
-          {\r
-          /*******************************/\r
-          /* Test if counter initialised */\r
-          /*******************************/\r
-\r
-          if (devpriv->\r
-              s_ModuleInfo [b_ModulNbr].\r
-              s_SiemensCounterInfo.\r
-              s_InitFlag.\r
-              b_CounterInit == 1)\r
-             {\r
-             /**************************/\r
-             /* Test the PCI bus clock */\r
-             /**************************/\r
-\r
-             if ((b_PCIInputClock == APCI1710_30MHZ) ||\r
-                 (b_PCIInputClock == APCI1710_33MHZ) ||\r
-                 (b_PCIInputClock == APCI1710_40MHZ))\r
-                {\r
-                /************************/\r
-                /* Test the timing unit */\r
-                /************************/\r
-\r
-                if (b_TimingUnity <= 2)\r
-                   {\r
-                   /**********************************/\r
-                   /* Test the base timing selection */\r
-                   /**********************************/\r
-\r
-                   if (((b_PCIInputClock == APCI1710_30MHZ) && (b_TimingUnity == 0) && (ul_TimingInterval >= 266) && (ul_TimingInterval <= 8738133UL)) ||\r
-                       ((b_PCIInputClock == APCI1710_30MHZ) && (b_TimingUnity == 1) && (ul_TimingInterval >= 1)   && (ul_TimingInterval <= 8738UL))    ||\r
-                       ((b_PCIInputClock == APCI1710_30MHZ) && (b_TimingUnity == 2) && (ul_TimingInterval >= 1)   && (ul_TimingInterval <= 8UL))       ||\r
-                       ((b_PCIInputClock == APCI1710_33MHZ) && (b_TimingUnity == 0) && (ul_TimingInterval >= 242) && (ul_TimingInterval <= 7943757UL)) ||\r
-                       ((b_PCIInputClock == APCI1710_33MHZ) && (b_TimingUnity == 1) && (ul_TimingInterval >= 1)   && (ul_TimingInterval <= 7943UL))    ||\r
-                       ((b_PCIInputClock == APCI1710_33MHZ) && (b_TimingUnity == 2) && (ul_TimingInterval >= 1)   && (ul_TimingInterval <= 7UL))       ||\r
-                       ((b_PCIInputClock == APCI1710_40MHZ) && (b_TimingUnity == 0) && (ul_TimingInterval >= 200) && (ul_TimingInterval <= 6553500UL)) ||\r
-                       ((b_PCIInputClock == APCI1710_40MHZ) && (b_TimingUnity == 1) && (ul_TimingInterval >= 1)   && (ul_TimingInterval <= 6553UL))    ||\r
-                       ((b_PCIInputClock == APCI1710_40MHZ) && (b_TimingUnity == 2) && (ul_TimingInterval >= 1)   && (ul_TimingInterval <= 6UL)))\r
-                      {\r
-                      /**********************/\r
-                      /* Test if 40MHz used */\r
-                      /**********************/\r
-\r
-                      if (b_PCIInputClock == APCI1710_40MHZ)\r
-                         {\r
-                         /******************************/\r
-                         /* Test if firmware >= Rev1.5 */\r
-                         /******************************/\r
-\r
-                         if ((devpriv->\r
-                              s_BoardInfos.\r
-                              dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) >= 0x3135)\r
-                            {\r
-                            /*********************************/\r
-                            /* Test if 40MHz quartz on board */\r
-                            /*********************************/\r
-\r
-                            /*INPDW (ps_APCI1710Variable->\r
-                                   s_Board [b_BoardHandle].\r
-                                   s_BoardInfos.\r
-                                   ui_Address + 36 + (64 * b_ModulNbr), &dw_Status);*/\r
-                                 dw_Status=inl(devpriv->s_BoardInfos.\r
-                                   ui_Address + 36 + (64 * b_ModulNbr));\r
-\r
-                            /******************************/\r
-                            /* Test the quartz flag (DQ0) */\r
-                            /******************************/\r
-\r
-                            if ((dw_Status & 1) != 1)\r
-                               {\r
-                               /*****************************/\r
-                               /* 40MHz quartz not on board */\r
-                               /*****************************/\r
-\r
-                               DPRINTK("40MHz quartz not on board\n");\r
-                               i_ReturnValue = -7;\r
-                               }\r
-                            }\r
-                         else\r
-                            {\r
-                            /*****************************/\r
-                            /* 40MHz quartz not on board */\r
-                            /*****************************/\r
-                                DPRINTK("40MHz quartz not on board\n");\r
-                            i_ReturnValue = -7;\r
-                            }\r
-                         } // if (b_PCIInputClock == APCI1710_40MHZ)\r
-\r
-                      /***************************/\r
-                      /* Test if not error occur */\r
-                      /***************************/\r
-\r
-                      if (i_ReturnValue == 0)\r
-                         {\r
-                         /****************************/\r
-                         /* Test the INC_CPT version */\r
-                         /****************************/\r
-\r
-                         if ((devpriv->s_BoardInfos.\r
-                              dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) >= 0x3131)\r
-                            {\r
-                           \r
-                               /**********************/\r
-                               /* Test if 40MHz used */\r
-                               /**********************/\r
-\r
-                               if (b_PCIInputClock == APCI1710_40MHZ)\r
-                                  {\r
-                                  /*********************************/\r
-                                  /* Enable the 40MHz quarz (DQ30) */\r
-                                  /*********************************/\r
-\r
-                                  devpriv->\r
-                                  s_ModuleInfo [b_ModulNbr].\r
-                                  s_SiemensCounterInfo.\r
-                                  s_ModeRegister.\r
-                                  s_ByteModeRegister.\r
-                                  b_ModeRegister4 = devpriv->\r
-                                                    s_ModuleInfo [b_ModulNbr].\r
-                                                    s_SiemensCounterInfo.\r
-                                                    s_ModeRegister.\r
-                                                    s_ByteModeRegister.\r
-                                                    b_ModeRegister4 | APCI1710_ENABLE_40MHZ_FREQUENCY;\r
-                                  } // if (b_PCIInputClock == APCI1710_40MHZ)\r
-                               else\r
-                                  {\r
-                                  /**********************************/\r
-                                  /* Disable the 40MHz quarz (DQ30) */\r
-                                  /**********************************/\r
-\r
-                                  devpriv->\r
-                                  s_ModuleInfo [b_ModulNbr].\r
-                                  s_SiemensCounterInfo.\r
-                                  s_ModeRegister.\r
-                                  s_ByteModeRegister.\r
-                                  b_ModeRegister4 = devpriv->\r
-                                                    s_ModuleInfo [b_ModulNbr].\r
-                                                    s_SiemensCounterInfo.\r
-                                                    s_ModeRegister.\r
-                                                    s_ByteModeRegister.\r
-                                                    b_ModeRegister4 & APCI1710_DISABLE_40MHZ_FREQUENCY;\r
-\r
-                                  } // if (b_PCIInputClock == APCI1710_40MHZ)\r
-                           \r
-\r
-                            /********************************/\r
-                            /* Calculate the division fator */\r
-                            /********************************/\r
-\r
-                            fpu_begin ();\r
-                            switch (b_TimingUnity)\r
-                               {\r
-                               /******/\r
-                               /* ns */\r
-                               /******/\r
-\r
-                               case 0:\r
-                                    \r
-                                       /******************/\r
-                                       /* Timer 0 factor */\r
-                                       /******************/\r
-\r
-                                       ul_TimerValue = (ULONG) (ul_TimingInterval * (0.00025 * b_PCIInputClock));\r
-\r
-                                       /*******************/\r
-                                       /* Round the value */\r
-                                       /*******************/\r
-\r
-                                       if ((double) ((double) ul_TimingInterval * (0.00025 * (double) b_PCIInputClock)) >= ((double) ((double) ul_TimerValue + 0.5)))\r
-                                          {\r
-                                          ul_TimerValue = ul_TimerValue + 1;\r
-                                          }\r
-\r
-                                       /*****************************/\r
-                                       /* Calculate the real timing */\r
-                                       /*****************************/\r
-\r
-                                       *pul_RealTimingInterval = (ULONG) (ul_TimerValue / (0.00025 * (double) b_PCIInputClock));\r
-                                       d_RealTimingInterval = (double) ul_TimerValue / (0.00025 * (double) b_PCIInputClock);\r
-\r
-                                       if ((double) ((double) ul_TimerValue / (0.00025 * (double) b_PCIInputClock)) >= (double) ((double) *pul_RealTimingInterval + 0.5))\r
-                                          {\r
-                                          *pul_RealTimingInterval = *pul_RealTimingInterval + 1;\r
-                                          }\r
-\r
-                                       ul_TimingInterval     = ul_TimingInterval - 1;\r
-                                       ul_TimerValue = ul_TimerValue - 2;\r
-                                    \r
-                                    break;\r
-\r
-                               /******/\r
-                               /* æs */\r
-                               /******/\r
-\r
-                               case 1:\r
-                               \r
-                                    \r
-                                       /******************/\r
-                                       /* Timer 0 factor */\r
-                                       /******************/\r
-\r
-                                       ul_TimerValue = (ULONG) (ul_TimingInterval * (0.25 * b_PCIInputClock));\r
-\r
-                                       /*******************/\r
-                                       /* Round the value */\r
-                                       /*******************/\r
-\r
-                                       if ((double) ((double) ul_TimingInterval * (0.25 * (double) b_PCIInputClock)) >= ((double) ((double) ul_TimerValue + 0.5)))\r
-                                          {\r
-                                          ul_TimerValue = ul_TimerValue + 1;\r
-                                          }\r
-\r
-                                       /*****************************/\r
-                                       /* Calculate the real timing */\r
-                                       /*****************************/\r
-\r
-                                       *pul_RealTimingInterval = (ULONG) (ul_TimerValue / (0.25 * (double) b_PCIInputClock));\r
-                                       d_RealTimingInterval    = (double) ul_TimerValue / ((double) 0.25 * (double) b_PCIInputClock);\r
-\r
-                                       if ((double) ((double) ul_TimerValue / (0.25 * (double) b_PCIInputClock)) >= (double) ((double) *pul_RealTimingInterval + 0.5))\r
-                                          {\r
-                                          *pul_RealTimingInterval = *pul_RealTimingInterval + 1;\r
-                                          }\r
-\r
-                                       ul_TimingInterval     = ul_TimingInterval - 1;\r
-                                       ul_TimerValue = ul_TimerValue - 2;\r
-                                    \r
-\r
-                                    break;\r
-\r
-                               /******/\r
-                               /* ms */\r
-                               /******/\r
-\r
-                               case 2:\r
-                               \r
-                                    \r
-                                       /******************/\r
-                                       /* Timer 0 factor */\r
-                                       /******************/\r
-\r
-                                       ul_TimerValue = ul_TimingInterval * (250.0 * b_PCIInputClock);\r
-\r
-                                       /*******************/\r
-                                       /* Round the value */\r
-                                       /*******************/\r
-\r
-                                       if ((double) ((double) ul_TimingInterval * (250.0 * (double) b_PCIInputClock)) >= ((double) ((double) ul_TimerValue + 0.5)))\r
-                                          {\r
-                                          ul_TimerValue = ul_TimerValue + 1;\r
-                                          }\r
-\r
-                                       /*****************************/\r
-                                       /* Calculate the real timing */\r
-                                       /*****************************/\r
-\r
-                                       *pul_RealTimingInterval = (ULONG) (ul_TimerValue / (250.0 * (double) b_PCIInputClock));\r
-                                       d_RealTimingInterval    = (double) ul_TimerValue / (250.0 * (double) b_PCIInputClock);\r
-\r
-                                       if ((double) ((double) ul_TimerValue / (250.0 * (double) b_PCIInputClock)) >= (double) ((double) *pul_RealTimingInterval + 0.5))\r
-                                          {\r
-                                          *pul_RealTimingInterval = *pul_RealTimingInterval + 1;\r
-                                          }\r
-\r
-                                       ul_TimingInterval     = ul_TimingInterval - 1;\r
-                                       ul_TimerValue = ul_TimerValue - 2;\r
-                                    \r
-                                    break;\r
-                               }\r
-\r
-                            fpu_end ();\r
-                            /*************************/\r
-                            /* Write the timer value */\r
-                            /*************************/\r
-\r
-                           \r
-                                        outl(ul_TimerValue,devpriv->s_BoardInfos.\r
-                                    ui_Address + 32 + (64 * b_ModulNbr));\r
-\r
-                            /*******************************/\r
-                            /* Set the initialisation flag */\r
-                            /*******************************/\r
-\r
-                            devpriv->\r
-                            s_ModuleInfo [b_ModulNbr].\r
-                            s_SiemensCounterInfo.\r
-                            s_InitFlag.\r
-                            b_FrequencyMeasurementInit  = 1;\r
-                            }\r
-                         else\r
-                            {\r
-                            /***************************/\r
-                            /* Counter not initialised */\r
-                            /***************************/\r
-\r
-                        DPRINTK("Counter not initialised\n");  \r
-                            i_ReturnValue = -3;\r
-                            }\r
-                         } // if (i_ReturnValue == 0)\r
-                      }\r
-                   else\r
-                      {\r
-                      /**********************************/\r
-                      /* Base timing selection is wrong */\r
-                      /**********************************/\r
-\r
-                          DPRINTK("Base timing selection is wrong\n");  \r
-                      i_ReturnValue = -6;\r
-                      }\r
-                   }\r
-                else\r
-                   {\r
-                   /***********************************/\r
-                   /* Timing unity selection is wrong */\r
-                   /***********************************/\r
-\r
-                       DPRINTK("Timing unity selection is wrong\n");\r
-                   i_ReturnValue = -5;\r
-                   }\r
-                }\r
-             else\r
-                {\r
-                /*****************************************/\r
-                /* The selected PCI input clock is wrong */\r
-                /*****************************************/\r
-\r
-                DPRINTK("The selected PCI input clock is wrong\n");    \r
-                i_ReturnValue = -4;\r
-                }\r
-             }\r
-          else\r
-             {\r
-             /****************************************/\r
-             /* Counter not initialised see function */\r
-             /* "i_APCI1710_InitCounter"             */\r
-             /****************************************/\r
-\r
-             DPRINTK("Counter not initialised\n");     \r
-             i_ReturnValue = -3;\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /*************************************************/\r
-          /* The selected module number parameter is wrong */\r
-          /*************************************************/\r
-\r
-          DPRINTK("The selected module number parameter is wrong\n");  \r
-          i_ReturnValue = -2;\r
-          }\r
-\r
-       return (i_ReturnValue);\r
-       }\r
-\r
-/*########################################################################### */\r
-\r
-                                                       //INSN BITS\r
-/*########################################################################### */\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     :INT       i_APCI1710_InsnBitsINCCPT(comedi_device *dev,comedi_subdevice *s,\r
-comedi_insn *insn,lsampl_t *data)                   |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Set & Clear Functions for INC_CPT                                          |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : \r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : -                                                      |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      : \r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-\r
-INT    i_APCI1710_InsnBitsINCCPT(comedi_device *dev,comedi_subdevice *s,\r
-comedi_insn *insn,lsampl_t *data)\r
-{\r
-       UINT ui_BitsType;\r
-       INT i_ReturnValue=0;\r
-       ui_BitsType=CR_CHAN(insn->chanspec);\r
-       devpriv->tsk_Current=current; // Save the current process task structure\r
-\r
-       switch(ui_BitsType)\r
-       {\r
-       case APCI1710_INCCPT_CLEARCOUNTERVALUE:\r
-               i_ReturnValue=i_APCI1710_ClearCounterValue    (dev,\r
-                                        (BYTE) CR_AREF(insn->chanspec));\r
-               break;\r
-\r
-       case APCI1710_INCCPT_CLEARALLCOUNTERVALUE:\r
-               i_ReturnValue=i_APCI1710_ClearAllCounterValue (dev);\r
-               break;\r
-\r
-       case APCI1710_INCCPT_SETINPUTFILTER:\r
-               i_ReturnValue=i_APCI1710_SetInputFilter (dev,\r
-                                                                       (BYTE) CR_AREF(insn->chanspec),\r
-                                    (BYTE) data[0],\r
-                                                                       (BYTE) data[1]);\r
-               break;\r
-\r
-       case APCI1710_INCCPT_LATCHCOUNTER:\r
-               i_ReturnValue=i_APCI1710_LatchCounter (dev,\r
-                                (BYTE) CR_AREF(insn->chanspec),\r
-                                (BYTE) data[0]);\r
-               break;\r
-\r
-       case APCI1710_INCCPT_SETINDEXANDREFERENCESOURCE:\r
-               i_ReturnValue=i_APCI1710_SetIndexAndReferenceSource     (dev,\r
-                                                (BYTE) CR_AREF(insn->chanspec),\r
-                                                (BYTE) data[0]);\r
-               break;\r
-\r
-       case APCI1710_INCCPT_SETDIGITALCHLON:\r
-               i_ReturnValue=i_APCI1710_SetDigitalChlOn (dev,\r
-                                    (BYTE) CR_AREF(insn->chanspec));\r
-               break;\r
-\r
-       case APCI1710_INCCPT_SETDIGITALCHLOFF:\r
-               i_ReturnValue=i_APCI1710_SetDigitalChlOff (dev,\r
-                                    (BYTE) CR_AREF(insn->chanspec));\r
-               break;\r
-\r
-       default:\r
-               printk("Bits Config Parameter Wrong\n");\r
-       }\r
-\r
-       if(i_ReturnValue>=0) i_ReturnValue =insn->n;\r
-       return (i_ReturnValue);\r
-}\r
-\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : _INT_ i_APCI1710_ClearCounterValue                     |\r
-|                               (BYTE_      b_BoardHandle,                   |\r
-|                                BYTE_       b_ModulNbr)                     |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Clear the counter value from selected module           |\r
-|                     (b_ModulNbr).                                          |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : BYTE_ b_BoardHandle : Handle of board APCI-1710        |\r
-|                     BYTE_ b_ModulNbr    : Module number to configure       |\r
-|                                           (0 to 3)                         |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : -                                                      |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      :  0: No error                                           |\r
-|                     -1: The handle parameter of the board is wrong         |\r
-|                     -2: The selected module number parameter is wrong      |\r
-|                     -3: Counter not initialised see function               |\r
-|                         "i_APCI1710_InitCounter"                           |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-INT   i_APCI1710_ClearCounterValue    (comedi_device *dev,\r
-                                        BYTE b_ModulNbr)\r
-       {\r
-       INT i_ReturnValue = 0;\r
-       \r
-       /**************************/\r
-       /* Test the module number */\r
-       /**************************/\r
-\r
-       if (b_ModulNbr < 4)\r
-          {\r
-          /*******************************/\r
-          /* Test if counter initialised */\r
-          /*******************************/\r
-\r
-          if (devpriv->\r
-              s_ModuleInfo [b_ModulNbr].\r
-              s_SiemensCounterInfo.\r
-              s_InitFlag.\r
-              b_CounterInit == 1)\r
-             {\r
-             /*********************/\r
-             /* Clear the counter */\r
-             /*********************/\r
-\r
-             \r
-                  outl(1,devpriv->s_BoardInfos.\r
-                     ui_Address + 16 + (64 * b_ModulNbr));\r
-             }\r
-          else\r
-             {\r
-             /****************************************/\r
-             /* Counter not initialised see function */\r
-             /* "i_APCI1710_InitCounter"             */\r
-             /****************************************/\r
-\r
-             DPRINTK("Counter not initialised\n");             \r
-             i_ReturnValue = -3;\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /*************************************************/\r
-          /* The selected module number parameter is wrong */\r
-          /*************************************************/\r
-\r
-          DPRINTK("The selected module number parameter is wrong\n");                  \r
-          i_ReturnValue = -2;\r
-          }\r
-\r
-       return (i_ReturnValue);\r
-       }\r
-\r
-\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : _INT_ i_APCI1710_ClearAllCounterValue                  |\r
-|                               (BYTE_      b_BoardHandle)                   |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Clear all counter value.                               |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : BYTE_ b_BoardHandle : Handle of board APCI-1710        |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : -                                                      |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      :  0: No error                                           |\r
-|                     -1: The handle parameter of the board is wrong         |\r
-|                     -2: No counter module found                            |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-INT   i_APCI1710_ClearAllCounterValue (comedi_device *dev)\r
-       {\r
-       BYTE   b_ModulCpt    = 0;\r
-       INT    i_ReturnValue = 0;\r
-       \r
-\r
-       /********************************/\r
-       /* Test if counter module found */\r
-       /********************************/\r
-\r
-       if ((devpriv->s_BoardInfos.\r
-            dw_MolduleConfiguration [0] & 0xFFFF0000UL) == APCI1710_INCREMENTAL_COUNTER ||\r
-           (devpriv->s_BoardInfos.\r
-            dw_MolduleConfiguration [1] & 0xFFFF0000UL) == APCI1710_INCREMENTAL_COUNTER ||\r
-           (devpriv->s_BoardInfos.\r
-            dw_MolduleConfiguration [2] & 0xFFFF0000UL) == APCI1710_INCREMENTAL_COUNTER ||\r
-           (devpriv->s_BoardInfos.\r
-            dw_MolduleConfiguration [3] & 0xFFFF0000UL) == APCI1710_INCREMENTAL_COUNTER)\r
-          {\r
-          for (b_ModulCpt = 0; b_ModulCpt < 4 ; b_ModulCpt ++)\r
-             {\r
-             /*******************************/\r
-             /* Test if incremental counter */\r
-             /*******************************/\r
-\r
-             if ((devpriv->s_BoardInfos.\r
-                  dw_MolduleConfiguration [b_ModulCpt] & 0xFFFF0000UL) == APCI1710_INCREMENTAL_COUNTER)\r
-                {\r
-                /*********************/\r
-                /* Clear the counter */\r
-                /*********************/\r
-\r
-                \r
-               outl(1,devpriv->s_BoardInfos.\r
-                        ui_Address + 16 + (64 * b_ModulCpt));\r
-                }\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /***************************/\r
-          /* No counter module found */\r
-          /***************************/\r
-\r
-          DPRINTK("No counter module found\n");        \r
-          i_ReturnValue = -2;\r
-          }\r
-\r
-       return (i_ReturnValue);\r
-       }\r
-\r
-\r
-\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : _INT_ i_APCI1710_SetInputFilter                        |\r
-|                                      (BYTE_ b_BoardHandle,                |\r
-|                                       BYTE_ b_Module,                     |\r
-|                                       BYTE_ b_PCIInputClock,              |\r
-|                                       BYTE_ b_Filter)                     |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Disable or enable the software filter from selected    |\r
-|                    module (b_ModulNbr). b_Filter determine the filter time|\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : BYTE_  b_BoardHandle    : Handle of board APCI-1710    |\r
-|                    BYTE_  b_ModulNbr       : Number of the module to be   |\r
-|                                              configured (0 to 3)          |\r
-|                    BYTE_  b_PCIInputClock  : Selection of the PCI bus     |\r
-|                                              clock                        |\r
-|                                              - APCI1710_30MHZ :           |\r
-|                                                The PC has a PCI bus clock |\r
-|                                                of 30 MHz                  |\r
-|                                              - APCI1710_33MHZ :           |\r
-|                                                The PC has a PCI bus clock |\r
-|                                                of 33 MHz                  |\r
-|                                              - APCI1710_40MHZ :           |\r
-|                                                The APCI1710 has a 40MHz    |\r
-|                                                quartz                     |\r
-|                    BYTE_  b_Filter         : Filter selection             |\r
-|                                                                            |\r
-|                              30 MHz                                       |\r
-|                              ------                                       |\r
-|                                      0:  Software filter not used         |\r
-|                                      1:  Filter from 266ns  (3.750000MHz) |\r
-|                                      2:  Filter from 400ns  (2.500000MHz) |\r
-|                                      3:  Filter from 533ns  (1.876170MHz) |\r
-|                                      4:  Filter from 666ns  (1.501501MHz) |\r
-|                                      5:  Filter from 800ns  (1.250000MHz) |\r
-|                                      6:  Filter from 933ns  (1.071800MHz) |\r
-|                                      7:  Filter from 1066ns (0.938080MHz) |\r
-|                                      8:  Filter from 1200ns (0.833333MHz) |\r
-|                                      9:  Filter from 1333ns (0.750000MHz) |\r
-|                                      10: Filter from 1466ns (0.682100MHz) |\r
-|                                      11: Filter from 1600ns (0.625000MHz) |\r
-|                                      12: Filter from 1733ns (0.577777MHz) |\r
-|                                      13: Filter from 1866ns (0.535900MHz) |\r
-|                                      14: Filter from 2000ns (0.500000MHz) |\r
-|                                      15: Filter from 2133ns (0.468800MHz) |\r
-|                                                                           |\r
-|                              33 MHz                                       |\r
-|                              ------                                       |\r
-|                                      0:  Software filter not used         |\r
-|                                      1:  Filter from 242ns  (4.125000MHz) |\r
-|                                      2:  Filter from 363ns  (2.754820MHz) |\r
-|                                      3:  Filter from 484ns  (2.066115MHz) |\r
-|                                      4:  Filter from 605ns  (1.652892MHz) |\r
-|                                      5:  Filter from 726ns  (1.357741MHz) |\r
-|                                      6:  Filter from 847ns  (1.180637MHz) |\r
-|                                      7:  Filter from 968ns  (1.033055MHz) |\r
-|                                      8:  Filter from 1089ns (0.918273MHz) |\r
-|                                      9:  Filter from 1210ns (0.826446MHz) |\r
-|                                      10: Filter from 1331ns (0.751314MHz) |\r
-|                                      11: Filter from 1452ns (0.688705MHz) |\r
-|                                      12: Filter from 1573ns (0.635727MHz) |\r
-|                                      13: Filter from 1694ns (0.590318MHz) |\r
-|                                      14: Filter from 1815ns (0.550964MHz) |\r
-|                                      15: Filter from 1936ns (0.516528MHz) |\r
-|                                                                           |\r
-|                              40 MHz                                       |\r
-|                              ------                                       |\r
-|                                      0:  Software filter not used         |\r
-|                                      1:  Filter from 200ns  (5.000000MHz) |\r
-|                                      2:  Filter from 300ns  (3.333333MHz) |\r
-|                                      3:  Filter from 400ns  (2.500000MHz) |\r
-|                                      4:  Filter from 500ns  (2.000000MHz) |\r
-|                                      5:  Filter from 600ns  (1.666666MHz) |\r
-|                                      6:  Filter from 700ns  (1.428500MHz) |\r
-|                                      7:  Filter from 800ns  (1.250000MHz) |\r
-|                                      8:  Filter from 900ns  (1.111111MHz) |\r
-|                                      9:  Filter from 1000ns (1.000000MHz) |\r
-|                                      10: Filter from 1100ns (0.909090MHz) |\r
-|                                      11: Filter from 1200ns (0.833333MHz) |\r
-|                                      12: Filter from 1300ns (0.769200MHz) |\r
-|                                      13: Filter from 1400ns (0.714200MHz) |\r
-|                                      14: Filter from 1500ns (0.666666MHz) |\r
-|                                      15: Filter from 1600ns (0.625000MHz) |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : -                                                      |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      :  0: No error                                           |\r
-|                     -1: The handle parameter of the board is wrong         |\r
-|                     -2: The selected module number is wrong                |\r
-|                     -3: The module is not a counter module                 |\r
-|                                        -4: The selected PCI input clock is wrong              |\r
-|                                        -5: The selected filter value is wrong                 |\r
-|                                        -6: 40MHz quartz not on board                          |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-INT    i_APCI1710_SetInputFilter       (comedi_device *dev,\r
-                                                                       BYTE b_ModulNbr,\r
-                                    BYTE b_PCIInputClock,\r
-                                                                       BYTE b_Filter)\r
-       {\r
-       INT    i_ReturnValue = 0;\r
-       DWORD dw_Status      = 0;\r
-       \r
-       /**************************/\r
-       /* Test the module number */\r
-       /**************************/\r
-\r
-       if (b_ModulNbr < 4)\r
-          {\r
-          /*******************************/\r
-          /* Test if incremental counter */\r
-          /*******************************/\r
-\r
-          if ((devpriv->s_BoardInfos.\r
-               dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_INCREMENTAL_COUNTER)\r
-             {\r
-             /******************************/\r
-             /* Test if firmware >= Rev1.5 */\r
-             /******************************/\r
-\r
-             if ((devpriv->s_BoardInfos.\r
-                  dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) >= 0x3135)\r
-                {\r
-                /**************************/\r
-                /* Test the PCI bus clock */\r
-                /**************************/\r
-\r
-                if ((b_PCIInputClock == APCI1710_30MHZ) ||\r
-                    (b_PCIInputClock == APCI1710_33MHZ) ||\r
-                    (b_PCIInputClock == APCI1710_40MHZ))\r
-                   {\r
-                   /*************************/\r
-                   /* Test the filter value */\r
-                   /*************************/\r
-\r
-                   if (b_Filter < 16)\r
-                      {\r
-                      /**********************/\r
-                      /* Test if 40MHz used */\r
-                      /**********************/\r
-\r
-                      if (b_PCIInputClock == APCI1710_40MHZ)\r
-                         {\r
-                         /*********************************/\r
-                         /* Test if 40MHz quartz on board */\r
-                         /*********************************/\r
-\r
-                        \r
-                       dw_Status=      inl(devpriv->s_BoardInfos.\r
-                                ui_Address + 36 + (64 * b_ModulNbr));\r
-\r
-                         /******************************/\r
-                         /* Test the quartz flag (DQ0) */\r
-                         /******************************/\r
-\r
-                         if ((dw_Status & 1) != 1)\r
-                            {\r
-                            /*****************************/\r
-                            /* 40MHz quartz not on board */\r
-                            /*****************************/\r
-\r
-                        DPRINTK("40MHz quartz not on board\n"); \r
-                            i_ReturnValue = -6;\r
-                            }\r
-                         } // if (b_PCIInputClock == APCI1710_40MHZ)\r
-\r
-                      /***************************/\r
-                      /* Test if error not occur */\r
-                      /***************************/\r
-\r
-                      if (i_ReturnValue == 0)\r
-                         {\r
-                         /**********************/\r
-                         /* Test if 40MHz used */\r
-                         /**********************/\r
-\r
-                         if (b_PCIInputClock == APCI1710_40MHZ)\r
-                            {\r
-                            /*********************************/\r
-                            /* Enable the 40MHz quarz (DQ31) */\r
-                            /*********************************/\r
-\r
-                            devpriv->\r
-                            s_ModuleInfo [b_ModulNbr].\r
-                            s_SiemensCounterInfo.\r
-                            s_ModeRegister.\r
-                            s_ByteModeRegister.\r
-                            b_ModeRegister4 = devpriv->\r
-                                              s_ModuleInfo [b_ModulNbr].\r
-                                              s_SiemensCounterInfo.\r
-                                              s_ModeRegister.\r
-                                              s_ByteModeRegister.\r
-                                              b_ModeRegister4 | APCI1710_ENABLE_40MHZ_FILTER;\r
-\r
-                            } // if (b_PCIInputClock == APCI1710_40MHZ)\r
-                         else\r
-                            {\r
-                            /**********************************/\r
-                            /* Disable the 40MHz quarz (DQ31) */\r
-                            /**********************************/\r
-\r
-                            devpriv->\r
-                            s_ModuleInfo [b_ModulNbr].\r
-                            s_SiemensCounterInfo.\r
-                            s_ModeRegister.\r
-                            s_ByteModeRegister.\r
-                            b_ModeRegister4 = devpriv->\r
-                                              s_ModuleInfo [b_ModulNbr].\r
-                                              s_SiemensCounterInfo.\r
-                                              s_ModeRegister.\r
-                                              s_ByteModeRegister.\r
-                                              b_ModeRegister4 & APCI1710_DISABLE_40MHZ_FILTER;\r
-\r
-                            } // if (b_PCIInputClock == APCI1710_40MHZ)\r
-\r
-                         /************************/\r
-                         /* Set the filter value */\r
-                         /************************/\r
-\r
-                         devpriv->\r
-                         s_ModuleInfo [b_ModulNbr].\r
-                         s_SiemensCounterInfo.\r
-                         s_ModeRegister.\r
-                         s_ByteModeRegister.\r
-                         b_ModeRegister3 = (devpriv->s_ModuleInfo [b_ModulNbr].\r
-                                            s_SiemensCounterInfo.\r
-                                            s_ModeRegister.\r
-                                            s_ByteModeRegister.\r
-                                            b_ModeRegister3 & 0x1F) | ((b_Filter & 0x7) << 5);\r
-\r
-                         devpriv->s_ModuleInfo [b_ModulNbr].\r
-                         s_SiemensCounterInfo.\r
-                         s_ModeRegister.\r
-                         s_ByteModeRegister.\r
-                         b_ModeRegister4 = (devpriv->\r
-                                            s_ModuleInfo [b_ModulNbr].\r
-                                            s_SiemensCounterInfo.\r
-                                            s_ModeRegister.\r
-                                            s_ByteModeRegister.\r
-                                            b_ModeRegister4 & 0xFE) | ((b_Filter & 0x8) >> 3);\r
-\r
-                         /***************************/\r
-                         /* Write the configuration */\r
-                         /***************************/\r
-\r
-                         \r
-                         outl(devpriv->s_ModuleInfo [b_ModulNbr].\r
-                                 s_SiemensCounterInfo.\r
-                                 s_ModeRegister.\r
-                                 dw_ModeRegister1_2_3_4,devpriv->s_BoardInfos.\r
-                                 ui_Address + 20 + (64 * b_ModulNbr));\r
-                         } // if (i_ReturnValue == 0)\r
-                      } // if (b_Filter < 16)\r
-                   else\r
-                      {\r
-                      /**************************************/\r
-                      /* The selected filter value is wrong */\r
-                      /**************************************/\r
-\r
-                          DPRINTK("The selected filter value is wrong\n");      \r
-                      i_ReturnValue = -5;\r
-                      } // if (b_Filter < 16)\r
-                   } // if ((b_PCIInputClock == APCI1710_30MHZ) || (b_PCIInputClock == APCI1710_33MHZ) || (b_PCIInputClock == APCI1710_40MHZ))\r
-                else\r
-                   {\r
-                   /*****************************************/\r
-                   /* The selected PCI input clock is wrong */\r
-                   /*****************************************/\r
-\r
-                       DPRINTK("The selected PCI input clock is wrong\n");\r
-                   i_ReturnValue = 4;\r
-                   } // if ((b_PCIInputClock == APCI1710_30MHZ) || (b_PCIInputClock == APCI1710_33MHZ) || (b_PCIInputClock == APCI1710_40MHZ))\r
-                }\r
-             else\r
-                {\r
-                /**************************************/\r
-                /* The module is not a counter module */\r
-                /**************************************/\r
-\r
-                DPRINTK("The module is not a counter module\n");\r
-                i_ReturnValue = -3;\r
-                }\r
-             }\r
-          else\r
-             {\r
-             /**************************************/\r
-             /* The module is not a counter module */\r
-             /**************************************/\r
-\r
-             DPRINTK("The module is not a counter module\n");  \r
-             i_ReturnValue = -3;\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /*************************************************/\r
-          /* The selected module number parameter is wrong */\r
-          /*************************************************/\r
-\r
-          DPRINTK("The selected module number parameter is wrong\n");  \r
-          i_ReturnValue = -2;\r
-          }\r
-\r
-       return (i_ReturnValue);\r
-       }\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : _INT_ i_APCI1710_LatchCounter (BYTE_ b_BoardHandle,    |\r
-|                                                    BYTE_ b_ModulNbr,       |\r
-|                                                    BYTE_ b_LatchReg)       |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Latch the courant value from selected module           |\r
-|                     (b_ModulNbr) in to the selected latch register         |\r
-|                     (b_LatchReg).                                          |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : BYTE_ b_BoardHandle : Handle of board APCI-1710        |\r
-|                     BYTE_ b_ModulNbr    : Module number to configure       |\r
-|                                           (0 to 3)                         |\r
-|                     BYTE_ b_LatchReg    : Selected latch register          |\r
-|                               0 : for the first latch register             |\r
-|                               1 : for the second latch register            |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : -                                                      |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      :  0: No error                                           |\r
-|                     -1: The handle parameter of the board is wrong         |\r
-|                     -2: No counter module found                            |\r
-|                     -3: Counter not initialised see function               |\r
-|                         "i_APCI1710_InitCounter"                           |\r
-|                     -4: The selected latch register parameter is wrong     |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-INT   i_APCI1710_LatchCounter (comedi_device *dev,\r
-                                BYTE b_ModulNbr,\r
-                                BYTE b_LatchReg)\r
-       {\r
-       INT i_ReturnValue = 0;\r
-       \r
-\r
-       /**************************/\r
-       /* Test the module number */\r
-       /**************************/\r
-\r
-       if (b_ModulNbr < 4)\r
-          {\r
-          /*******************************/\r
-          /* Test if counter initialised */\r
-          /*******************************/\r
-\r
-          if (devpriv->\r
-              s_ModuleInfo [b_ModulNbr].\r
-              s_SiemensCounterInfo.\r
-              s_InitFlag.\r
-              b_CounterInit == 1)\r
-             {\r
-             /*************************************/\r
-             /* Test the latch register parameter */\r
-             /*************************************/\r
-\r
-             if (b_LatchReg < 2)\r
-                {\r
-                /*********************/\r
-                /* Tatch the counter */\r
-                /*********************/\r
-\r
-                       outl(1 << (b_LatchReg * 4),devpriv->s_BoardInfos.\r
-                        ui_Address + (64 * b_ModulNbr));\r
-                }\r
-             else\r
-                {\r
-                /**************************************************/\r
-                /* The selected latch register parameter is wrong */\r
-                /**************************************************/\r
-\r
-                DPRINTK("The selected latch register parameter is wrong\n");\r
-                i_ReturnValue = -4;\r
-                }\r
-             }\r
-          else\r
-             {\r
-             /****************************************/\r
-             /* Counter not initialised see function */\r
-             /* "i_APCI1710_InitCounter"             */\r
-             /****************************************/\r
-\r
-             DPRINTK("Counter not initialised\n");     \r
-             i_ReturnValue = -3;\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /*************************************************/\r
-          /* The selected module number parameter is wrong */\r
-          /*************************************************/\r
-\r
-          DPRINTK("The selected module number parameter is wrong\n");  \r
-          i_ReturnValue = -2;\r
-          }\r
-\r
-       return (i_ReturnValue);\r
-       }\r
-\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : _INT_    i_APCI1710_SetIndexAndReferenceSource        |\r
-|                                      (BYTE_ b_BoardHandle,                |\r
-|                                       BYTE_ b_ModulNbr,                   |\r
-|                                       BYTE_ b_SourceSelection)            |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Determine the hardware source for the index and the    |\r
-|                    reference logic. Per default the index logic is        |\r
-|                    connected to the difference input C and the reference  |\r
-|                    logic is connected to the 24V input E                  |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : BYTE_ b_BoardHandle     : Handle of board APCI-1710    |\r
-|                     BYTE_ b_ModulNbr        : Module number to configure   |\r
-|                                               (0 to 3)                     |\r
-|                    BYTE_ b_SourceSelection : APCI1710_SOURCE_0 :          |\r
-|                                              The index logic is connected |\r
-|                                              to the difference input C and|\r
-|                                              the reference logic is       |\r
-|                                              connected to the 24V input E.|\r
-|                                              This is the default          |\r
-|                                              configuration.               |\r
-|                                              APCI1710_SOURCE_1 :          |\r
-|                                              The reference logic is       |\r
-|                                              connected to the difference  |\r
-|                                              input C and the index logic  |\r
-|                                              is connected to the 24V      |\r
-|                                              input E                      |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : -                                                      |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      :  0: No error                                           |\r
-|                     -1: The handle parameter of the board is wrong         |\r
-|                    -2: The selected module number is wrong                |\r
-|                    -3: The module is not a counter module.                |\r
-|                    -4: The source selection is wrong                      |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-INT    i_APCI1710_SetIndexAndReferenceSource   (comedi_device *dev,\r
-                                                BYTE b_ModulNbr,\r
-                                                BYTE b_SourceSelection)\r
-       {\r
-       INT    i_ReturnValue = 0;\r
-       \r
-       \r
-       /**************************/\r
-       /* Test the module number */\r
-       /**************************/\r
-\r
-       if (b_ModulNbr < 4)\r
-          {\r
-          /*******************************/\r
-          /* Test if incremental counter */\r
-          /*******************************/\r
-\r
-          if ((devpriv->s_BoardInfos.\r
-               dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_INCREMENTAL_COUNTER)\r
-             {\r
-             /******************************/\r
-             /* Test if firmware >= Rev1.5 */\r
-             /******************************/\r
-\r
-             if ((devpriv->s_BoardInfos.\r
-                  dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) >= 0x3135)\r
-                {\r
-                /*****************************/\r
-                /* Test the source selection */\r
-                /*****************************/\r
-\r
-                if (b_SourceSelection == APCI1710_SOURCE_0 ||\r
-                    b_SourceSelection == APCI1710_SOURCE_1)\r
-                   {\r
-                   /******************************************/\r
-                   /* Test if invert the index and reference */\r
-                   /******************************************/\r
-\r
-                   if (b_SourceSelection == APCI1710_SOURCE_1)\r
-                      {\r
-                      /********************************************/\r
-                      /* Invert index and reference source (DQ25) */\r
-                      /********************************************/\r
-\r
-                      devpriv->s_ModuleInfo [b_ModulNbr].\r
-                      s_SiemensCounterInfo.\r
-                      s_ModeRegister.\r
-                      s_ByteModeRegister.\r
-                      b_ModeRegister4 = devpriv->\r
-                                        s_ModuleInfo [b_ModulNbr].\r
-                                        s_SiemensCounterInfo.\r
-                                        s_ModeRegister.\r
-                                        s_ByteModeRegister.\r
-                                        b_ModeRegister4 | APCI1710_INVERT_INDEX_RFERENCE;\r
-                      }\r
-                   else\r
-                      {\r
-                      /****************************************/\r
-                      /* Set the default configuration (DQ25) */\r
-                      /****************************************/\r
-\r
-                      devpriv->s_ModuleInfo [b_ModulNbr].\r
-                      s_SiemensCounterInfo.\r
-                      s_ModeRegister.\r
-                      s_ByteModeRegister.\r
-                      b_ModeRegister4 = devpriv->\r
-                                        s_ModuleInfo [b_ModulNbr].\r
-                                        s_SiemensCounterInfo.\r
-                                        s_ModeRegister.\r
-                                        s_ByteModeRegister.\r
-                                        b_ModeRegister4 & APCI1710_DEFAULT_INDEX_RFERENCE;\r
-                      }\r
-                   } // if (b_SourceSelection == APCI1710_SOURCE_0 ||b_SourceSelection == APCI1710_SOURCE_1)\r
-                else\r
-                   {\r
-                   /*********************************/\r
-                   /* The source selection is wrong */\r
-                    /*********************************/\r
-\r
-                   DPRINTK("The source selection is wrong\n");\r
-                   i_ReturnValue = -4;\r
-                   } // if (b_SourceSelection == APCI1710_SOURCE_0 ||b_SourceSelection == APCI1710_SOURCE_1)\r
-                }\r
-             else\r
-                {\r
-                /**************************************/\r
-                /* The module is not a counter module */\r
-                /**************************************/\r
-\r
-                DPRINTK("The module is not a counter module\n");       \r
-                i_ReturnValue = -3;\r
-                }\r
-             }\r
-          else\r
-             {\r
-             /**************************************/\r
-             /* The module is not a counter module */\r
-             /**************************************/\r
-\r
-             DPRINTK("The module is not a counter module\n");  \r
-             i_ReturnValue = -3;\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /***************************************/\r
-          /* The selected module number is wrong */\r
-          /***************************************/\r
-\r
-          DPRINTK("The selected module number is wrong\n");    \r
-          i_ReturnValue = -2;\r
-          }\r
-\r
-       return (i_ReturnValue);\r
-       }\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : _INT_    i_APCI1710_SetDigitalChlOn                   |\r
-|                                 (BYTE_  b_BoardHandle,                    |\r
-|                                  BYTE_  b_ModulNbr)                       |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Sets the digital output H Setting an output means      |\r
-|                    setting an ouput high.                                 |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : BYTE_  b_BoardHandle    : Handle of board APCI-1710    |\r
-|                    BYTE_  b_ModulNbr       : Number of the module to be   |\r
-|                                              configured (0 to 3)          |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : -                                                      |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      :  0: No error                                           |\r
-|                     -1: The handle parameter of the board is wrong         |\r
-|                     -2: The selected module number is wrong                |\r
-|                     -3: Counter not initialised see function               |\r
-|                        "i_APCI1710_InitCounter"                           |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-INT    i_APCI1710_SetDigitalChlOn (comedi_device *dev,\r
-                                   BYTE  b_ModulNbr)\r
-       {\r
-       INT    i_ReturnValue = 0;\r
-       \r
-       /**************************/\r
-       /* Test the module number */\r
-       /**************************/\r
-\r
-       if (b_ModulNbr < 4)\r
-          {\r
-          /*******************************/\r
-          /* Test if counter initialised */\r
-          /*******************************/\r
-\r
-          if (devpriv->\r
-              s_ModuleInfo [b_ModulNbr].\r
-              s_SiemensCounterInfo.\r
-              s_InitFlag.\r
-              b_CounterInit == 1)\r
-             {\r
-             devpriv->\r
-             s_ModuleInfo [b_ModulNbr].\r
-             s_SiemensCounterInfo.\r
-             s_ModeRegister.\r
-             s_ByteModeRegister.\r
-             b_ModeRegister3 = devpriv->\r
-                               s_ModuleInfo [b_ModulNbr].\r
-                               s_SiemensCounterInfo.\r
-                               s_ModeRegister.\r
-                               s_ByteModeRegister.\r
-                               b_ModeRegister3 | 0x10;\r
-\r
-             /*********************/\r
-             /* Set the output On */\r
-             /*********************/\r
-\r
-                 outl(devpriv->s_ModuleInfo [b_ModulNbr].\r
-                     s_SiemensCounterInfo.\r
-                     s_ModeRegister.\r
-                     dw_ModeRegister1_2_3_4,devpriv->s_BoardInfos.\r
-                     ui_Address + 20 + (64 * b_ModulNbr));\r
-             }\r
-          else\r
-             {\r
-             /****************************************/\r
-             /* Counter not initialised see function */\r
-             /* "i_APCI1710_InitCounter"             */\r
-             /****************************************/\r
-\r
-             DPRINTK("Counter not initialised\n");\r
-             i_ReturnValue = -3;\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /*************************************************/\r
-          /* The selected module number parameter is wrong */\r
-          /*************************************************/\r
-\r
-          DPRINTK("The selected module number parameter is wrong\n");  \r
-          i_ReturnValue = -2;\r
-          }\r
-\r
-       return (i_ReturnValue);\r
-       }\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : _INT_    i_APCI1710_SetDigitalChlOff                  |\r
-|                                 (BYTE_  b_BoardHandle,                    |\r
-|                                  BYTE_  b_ModulNbr)                       |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Resets the digital output H. Resetting an output means |\r
-|                    setting an ouput low.                                  |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : BYTE_  b_BoardHandle    : Handle of board APCI-1710    |\r
-|                    BYTE_  b_ModulNbr       : Number of the module to be   |\r
-|                                              configured (0 to 3)          |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : -                                                      |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      :  0: No error                                           |\r
-|                     -1: The handle parameter of the board is wrong         |\r
-|                     -2: The selected module number is wrong                |\r
-|                     -3: Counter not initialised see function               |\r
-|                        "i_APCI1710_InitCounter"                           |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-INT    i_APCI1710_SetDigitalChlOff (comedi_device *dev,\r
-                                    BYTE  b_ModulNbr)\r
-       {\r
-       INT    i_ReturnValue = 0;\r
-       \r
-       /**************************/\r
-       /* Test the module number */\r
-       /**************************/\r
-\r
-       if (b_ModulNbr < 4)\r
-          {\r
-          /*******************************/\r
-          /* Test if counter initialised */\r
-          /*******************************/\r
-\r
-          if (devpriv->\r
-              s_ModuleInfo [b_ModulNbr].\r
-              s_SiemensCounterInfo.\r
-              s_InitFlag.\r
-              b_CounterInit == 1)\r
-             {\r
-             devpriv->\r
-             s_ModuleInfo [b_ModulNbr].\r
-             s_SiemensCounterInfo.\r
-             s_ModeRegister.\r
-             s_ByteModeRegister.\r
-             b_ModeRegister3 = devpriv->\r
-                               s_ModuleInfo [b_ModulNbr].\r
-                               s_SiemensCounterInfo.\r
-                               s_ModeRegister.\r
-                               s_ByteModeRegister.\r
-                               b_ModeRegister3 & 0xEF;\r
-\r
-             /**********************/\r
-             /* Set the output Off */\r
-             /**********************/\r
-\r
-                 outl(devpriv->s_ModuleInfo [b_ModulNbr].\r
-                     s_SiemensCounterInfo.\r
-                     s_ModeRegister.\r
-                     dw_ModeRegister1_2_3_4,devpriv->s_BoardInfos.\r
-                     ui_Address + 20 + (64 * b_ModulNbr));\r
-             }\r
-          else\r
-             {\r
-             /****************************************/\r
-             /* Counter not initialised see function */\r
-             /* "i_APCI1710_InitCounter"             */\r
-             /****************************************/\r
-\r
-             DPRINTK("Counter not initialised\n");     \r
-             i_ReturnValue = -3;\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /*************************************************/\r
-          /* The selected module number parameter is wrong */\r
-          /*************************************************/\r
-\r
-          DPRINTK("The selected module number parameter is wrong\n");  \r
-          i_ReturnValue = -2;\r
-          }\r
-\r
-       return (i_ReturnValue);\r
-       }\r
-\r
-\r
-/*########################################################################### */\r
-\r
-                                                       // INSN WRITE\r
-/*########################################################################### */\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     :INT       i_APCI1710_InsnWriteINCCPT(comedi_device *dev,comedi_subdevice *s,\r
-comedi_insn *insn,lsampl_t *data)                   |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Enable Disable functions for INC_CPT                                       |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : \r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : -                                                      |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      : \r
-+----------------------------------------------------------------------------+\r
-*/\r
-INT    i_APCI1710_InsnWriteINCCPT(comedi_device *dev,comedi_subdevice *s,\r
-comedi_insn *insn,lsampl_t *data)\r
-{\r
-       UINT ui_WriteType;\r
-       INT i_ReturnValue=0;\r
-        \r
-       ui_WriteType=CR_CHAN(insn->chanspec);\r
-       devpriv->tsk_Current=current; // Save the current process task structure\r
-\r
-       switch(ui_WriteType)\r
-       {\r
-               case APCI1710_INCCPT_ENABLELATCHINTERRUPT:\r
-                       i_ReturnValue = i_APCI1710_EnableLatchInterrupt (dev,\r
-                                        (BYTE) CR_AREF(insn->chanspec));\r
-               break;\r
-\r
-               case APCI1710_INCCPT_DISABLELATCHINTERRUPT:\r
-                       i_ReturnValue = i_APCI1710_DisableLatchInterrupt (dev,\r
-                                                (BYTE) CR_AREF(insn->chanspec));\r
-               break;\r
-\r
-               case APCI1710_INCCPT_WRITE16BITCOUNTERVALUE:\r
-                       i_ReturnValue = i_APCI1710_Write16BitCounterValue       (dev,\r
-                                                (BYTE) CR_AREF(insn->chanspec),\r
-                                                (BYTE)  data[0],\r
-                                                (UINT)  data[1]);\r
-               break;\r
-\r
-               case APCI1710_INCCPT_WRITE32BITCOUNTERVALUE:\r
-                        i_ReturnValue = i_APCI1710_Write32BitCounterValue       (dev,\r
-                                                (BYTE) CR_AREF(insn->chanspec),\r
-                                                (ULONG) data[0]);\r
-\r
-               break;\r
-\r
-               case APCI1710_INCCPT_ENABLEINDEX:\r
-                       i_APCI1710_EnableIndex  (dev,\r
-                                (BYTE) CR_AREF(insn->chanspec));\r
-               break;\r
-\r
-               case APCI1710_INCCPT_DISABLEINDEX:                                              \r
-                       i_ReturnValue = i_APCI1710_DisableIndex  (dev,\r
-                                (BYTE) CR_AREF(insn->chanspec));\r
-               break;\r
-\r
-               case APCI1710_INCCPT_ENABLECOMPARELOGIC:                                        \r
-                       i_ReturnValue = i_APCI1710_EnableCompareLogic   (dev,\r
-                                        (BYTE) CR_AREF(insn->chanspec));\r
-               break;\r
-\r
-               case APCI1710_INCCPT_DISABLECOMPARELOGIC:       \r
-                       i_ReturnValue = i_APCI1710_DisableCompareLogic  (dev,\r
-                                        (BYTE) CR_AREF(insn->chanspec));\r
-               break;\r
-\r
-               case APCI1710_INCCPT_ENABLEFREQUENCYMEASUREMENT:                        \r
-                       i_ReturnValue = i_APCI1710_EnableFrequencyMeasurement   (dev,\r
-                                                (BYTE) CR_AREF(insn->chanspec),\r
-                                                (BYTE)          data[0]);\r
-               break;\r
-\r
-               case APCI1710_INCCPT_DISABLEFREQUENCYMEASUREMENT:                                       \r
-                       i_ReturnValue = i_APCI1710_DisableFrequencyMeasurement  (dev,\r
-                                                (BYTE) CR_AREF(insn->chanspec));\r
-               break;\r
-\r
-               default:\r
-                       printk("Write Config Parameter Wrong\n");\r
-       }\r
-\r
-       if(i_ReturnValue>=0) i_ReturnValue =insn->n;\r
-       return (i_ReturnValue);\r
-}\r
-\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : _INT_ i_APCI1710_EnableLatchInterrupt                  |\r
-|                               (BYTE_ b_BoardHandle,                        |\r
-|                                BYTE_ b_ModulNbr)                           |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Enable the latch interrupt from selected module        |\r
-|                     (b_ModulNbr). Each software or hardware latch occur a  |\r
-|                     interrupt.                                             |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : BYTE_ b_BoardHandle : Handle of board APCI-1710        |\r
-|                     BYTE_ b_ModulNbr    : Module number to configure       |\r
-|                                           (0 to 3)                         |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : -                                                      |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      :  0: No error                                           |\r
-|                     -1: The handle parameter of the board is wrong         |\r
-|                     -2: No counter module found                            |\r
-|                     -3: Counter not initialised see function               |\r
-|                         "i_APCI1710_InitCounter"                           |\r
-|                     -4: Interrupt routine not installed see function       |\r
-|                         "i_APCI1710_SetBoardIntRoutine"                    |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-INT  i_APCI1710_EnableLatchInterrupt (comedi_device *dev,\r
-                                        BYTE b_ModulNbr)\r
-       {\r
-       INT i_ReturnValue = 0;\r
-       \r
-       /**************************/\r
-       /* Test the module number */\r
-       /**************************/\r
-\r
-       if (b_ModulNbr < 4)\r
-          {\r
-          /*******************************/\r
-          /* Test if counter initialised */\r
-          /*******************************/\r
-\r
-          if (devpriv->s_ModuleInfo [b_ModulNbr].\r
-              s_SiemensCounterInfo.\r
-              s_InitFlag.\r
-              b_CounterInit == 1)\r
-             {\r
-\r
-                /********************/\r
-                /* Enable interrupt */\r
-                /********************/\r
-\r
-                devpriv->s_ModuleInfo [b_ModulNbr].\r
-                s_SiemensCounterInfo.\r
-                s_ModeRegister.\r
-                s_ByteModeRegister.\r
-                b_ModeRegister2 = devpriv->\r
-                                  s_ModuleInfo [b_ModulNbr].\r
-                                  s_SiemensCounterInfo.\r
-                                  s_ModeRegister.\r
-                                  s_ByteModeRegister.\r
-                                  b_ModeRegister2 | APCI1710_ENABLE_LATCH_INT;\r
-\r
-                /***************************/\r
-                /* Write the configuration */\r
-                /***************************/\r
-\r
-                outl(devpriv->s_ModuleInfo [b_ModulNbr].\r
-                        s_SiemensCounterInfo.\r
-                        s_ModeRegister.\r
-                        dw_ModeRegister1_2_3_4,devpriv->s_BoardInfos.\r
-                        ui_Address + 20 + (64 * b_ModulNbr));\r
-             }\r
-          else\r
-             {\r
-             /****************************************/\r
-             /* Counter not initialised see function */\r
-             /* "i_APCI1710_InitCounter"             */\r
-             /****************************************/\r
-\r
-             DPRINTK("Counter not initialised\n");     \r
-             i_ReturnValue = -3;\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /*************************************************/\r
-          /* The selected module number parameter is wrong */\r
-          /*************************************************/\r
-\r
-          DPRINTK("The selected module number parameter is wrong\n");\r
-          i_ReturnValue = -2;\r
-          }\r
-\r
-       return (i_ReturnValue);\r
-       }\r
-\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : _INT_ i_APCI1710_DisableLatchInterrupt                 |\r
-|                               (BYTE_ b_BoardHandle,                        |\r
-|                                BYTE_ b_ModulNbr)                           |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Disable the latch interrupt from selected module       |\r
-|                     (b_ModulNbr).                                          |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : BYTE_ b_BoardHandle : Handle of board APCI-1710        |\r
-|                     BYTE_ b_ModulNbr    : Module number to configure       |\r
-|                                           (0 to 3)                         |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : -                                                      |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      :  0: No error                                           |\r
-|                     -1: The handle parameter of the board is wrong         |\r
-|                     -2: No counter module found                            |\r
-|                     -3: Counter not initialised see function               |\r
-|                         "i_APCI1710_InitCounter"                           |\r
-|                     -4: Interrupt routine not installed see function       |\r
-|                         "i_APCI1710_SetBoardIntRoutine"                    |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-INT   i_APCI1710_DisableLatchInterrupt        (comedi_device *dev,\r
-                                                BYTE b_ModulNbr)\r
-       {\r
-       INT i_ReturnValue = 0;\r
-       \r
-       /**************************/\r
-       /* Test the module number */\r
-       /**************************/\r
-\r
-       if (b_ModulNbr < 4)\r
-          {\r
-          /*******************************/\r
-          /* Test if counter initialised */\r
-          /*******************************/\r
-\r
-          if (devpriv->\r
-              s_ModuleInfo [b_ModulNbr].\r
-              s_SiemensCounterInfo.\r
-              s_InitFlag.\r
-              b_CounterInit == 1)\r
-             {\r
-\r
-                /***************************/\r
-                /* Write the configuration */\r
-                /***************************/\r
-\r
-                  outl(devpriv->s_ModuleInfo [b_ModulNbr].\r
-                        s_SiemensCounterInfo.\r
-                        s_ModeRegister.\r
-                        dw_ModeRegister1_2_3_4 & ((APCI1710_DISABLE_LATCH_INT << 8) | 0xFF),devpriv->s_BoardInfos.\r
-                        ui_Address + 20 + (64 * b_ModulNbr));\r
-\r
-                  mdelay(1000);\r
-\r
-                /*********************/\r
-                /* Disable interrupt */\r
-                /*********************/\r
-\r
-                devpriv->\r
-                s_ModuleInfo [b_ModulNbr].\r
-                s_SiemensCounterInfo.\r
-                s_ModeRegister.\r
-                s_ByteModeRegister.\r
-                b_ModeRegister2 = devpriv->\r
-                                  s_ModuleInfo [b_ModulNbr].\r
-                                  s_SiemensCounterInfo.\r
-                                  s_ModeRegister.\r
-                                  s_ByteModeRegister.\r
-                                  b_ModeRegister2 & APCI1710_DISABLE_LATCH_INT;\r
-\r
-             }\r
-          else\r
-             {\r
-             /****************************************/\r
-             /* Counter not initialised see function */\r
-             /* "i_APCI1710_InitCounter"             */\r
-             /****************************************/\r
-\r
-             DPRINTK("Counter not initialised\n");     \r
-             i_ReturnValue = -3;\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /*************************************************/\r
-          /* The selected module number parameter is wrong */\r
-          /*************************************************/\r
-\r
-          DPRINTK("The selected module number parameter is wrong\n");  \r
-          i_ReturnValue = -2;\r
-          }\r
-\r
-       return (i_ReturnValue);\r
-       }\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : _INT_ i_APCI1710_Write16BitCounterValue                |\r
-|                                               (BYTE_  b_BoardHandle        |\r
-|                                                BYTE_  b_ModulNbr,          |\r
-|                                                BYTE_  b_SelectedCounter,   |\r
-|                                                UINT_ ui_WriteValue)        |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Write a 16-Bit value (ui_WriteValue) in to the selected|\r
-|                     16-Bit counter (b_SelectedCounter) from selected module|\r
-|                     (b_ModulNbr).                                          |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : BYTE_ b_BoardHandle     : Handle of board APCI-1710    |\r
-|                     BYTE_ b_ModulNbr        : Module number to configure   |\r
-|                                              (0 to 3)                      |\r
-|                     BYTE_ b_SelectedCounter : Selected 16-Bit counter      |\r
-|                                               (0 or 1)                     |\r
-|                     UINT_ ui_WriteValue     : 16-Bit write value           |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : -                                                      |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      :  0: No error                                           |\r
-|                     -1: The handle parameter of the board is wrong         |\r
-|                     -2: No counter module found                            |\r
-|                     -3: Counter not initialised see function               |\r
-|                         "i_APCI1710_InitCounter"                           |\r
-|                     -4: The selected 16-Bit counter parameter is wrong     |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-INT   i_APCI1710_Write16BitCounterValue       (comedi_device *dev,\r
-                                                BYTE  b_ModulNbr,\r
-                                                BYTE  b_SelectedCounter,\r
-                                                UINT  ui_WriteValue)\r
-       {\r
-       INT i_ReturnValue = 0;\r
-       \r
-       \r
-       /**************************/\r
-       /* Test the module number */\r
-       /**************************/\r
-\r
-       if (b_ModulNbr < 4)\r
-          {\r
-          /*******************************/\r
-          /* Test if counter initialised */\r
-          /*******************************/\r
-\r
-          if (devpriv->\r
-              s_ModuleInfo [b_ModulNbr].\r
-              s_SiemensCounterInfo.\r
-              s_InitFlag.\r
-              b_CounterInit == 1)\r
-             {\r
-             /******************************/\r
-             /* Test the counter selection */\r
-             /******************************/\r
-\r
-             if (b_SelectedCounter < 2)\r
-                {\r
-                /*******************/\r
-                /* Write the value */\r
-                /*******************/\r
-\r
-               outl((ULONG) ((ULONG) (ui_WriteValue) << (16 * b_SelectedCounter)),devpriv->s_BoardInfos.\r
-                        ui_Address + 8 + (b_SelectedCounter * 4) + (64 * b_ModulNbr));\r
-                }\r
-             else\r
-                {\r
-                /**************************************************/\r
-                /* The selected 16-Bit counter parameter is wrong */\r
-                /**************************************************/\r
-\r
-                DPRINTK("The selected 16-Bit counter parameter is wrong\n");\r
-                i_ReturnValue = -4;\r
-                }\r
-             }\r
-          else\r
-             {\r
-             /****************************************/\r
-             /* Counter not initialised see function */\r
-             /* "i_APCI1710_InitCounter"             */\r
-             /****************************************/\r
-\r
-             DPRINTK("Counter not initialised\n");     \r
-             i_ReturnValue = -3;\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /*************************************************/\r
-          /* The selected module number parameter is wrong */\r
-          /*************************************************/\r
-\r
-          DPRINTK("The selected module number parameter is wrong\n");\r
-          i_ReturnValue = -2;\r
-          }\r
-\r
-       return (i_ReturnValue);\r
-       }\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : _INT_ i_APCI1710_Write32BitCounterValue                |\r
-|                                               (BYTE_   b_BoardHandle       |\r
-|                                                BYTE_   b_ModulNbr,         |\r
-|                                                ULONG_ ul_WriteValue)       |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Write a 32-Bit value (ui_WriteValue) in to the selected|\r
-|                     module (b_ModulNbr).                                   |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : BYTE_ b_BoardHandle     : Handle of board APCI-1710    |\r
-|                     BYTE_ b_ModulNbr        : Module number to configure   |\r
-|                                              (0 to 3)                      |\r
-|                     ULONG_ ul_WriteValue    : 32-Bit write value           |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : -                                                      |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      :  0: No error                                           |\r
-|                     -1: The handle parameter of the board is wrong         |\r
-|                     -2: No counter module found                            |\r
-|                     -3: Counter not initialised see function               |\r
-|                         "i_APCI1710_InitCounter"                           |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-INT   i_APCI1710_Write32BitCounterValue       (comedi_device *dev,\r
-                                                BYTE   b_ModulNbr,\r
-                                                ULONG ul_WriteValue)\r
-       {\r
-       INT i_ReturnValue = 0;\r
-       \r
-       \r
-       /**************************/\r
-       /* Test the module number */\r
-       /**************************/\r
-\r
-       if (b_ModulNbr < 4)\r
-          {\r
-          /*******************************/\r
-          /* Test if counter initialised */\r
-          /*******************************/\r
-\r
-          if (devpriv->\r
-              s_ModuleInfo [b_ModulNbr].\r
-              s_SiemensCounterInfo.\r
-              s_InitFlag.\r
-              b_CounterInit == 1)\r
-             {\r
-             /*******************/\r
-             /* Write the value */\r
-             /*******************/\r
-\r
-                  outl(ul_WriteValue,devpriv->s_BoardInfos.\r
-                     ui_Address + 4 + (64 * b_ModulNbr));\r
-             }\r
-          else\r
-             {\r
-             /****************************************/\r
-             /* Counter not initialised see function */\r
-             /* "i_APCI1710_InitCounter"             */\r
-             /****************************************/\r
-\r
-             DPRINTK("Counter not initialised\n");     \r
-             i_ReturnValue = -3;\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /*************************************************/\r
-          /* The selected module number parameter is wrong */\r
-          /*************************************************/\r
-\r
-          DPRINTK("The selected module number parameter is wrong\n");  \r
-          i_ReturnValue = -2;\r
-          }\r
-\r
-       return (i_ReturnValue);\r
-       }\r
-\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : _INT_ i_APCI1710_EnableIndex (BYTE_  b_BoardHandle,    |\r
-|                                                   BYTE_  b_ModulNbr)       |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Enable the INDEX actions                               |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : BYTE_ b_BoardHandle     : Handle of board APCI-1710    |\r
-|                     BYTE_ b_ModulNbr        : Module number to configure   |\r
-|                                               (0 to 3)                     |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : -                                                      |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      :  0: No error                                           |\r
-|                     -1: The handle parameter of the board is wrong         |\r
-|                     -2: No counter module found                            |\r
-|                     -3: Counter not initialised see function               |\r
-|                         "i_APCI1710_InitCounter"                           |\r
-|                     -4: Index not initialised see function                 |\r
-|                         "i_APCI1710_InitIndex"                             |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-INT   i_APCI1710_EnableIndex  (comedi_device *dev,\r
-                                BYTE b_ModulNbr)\r
-       {\r
-       INT    i_ReturnValue = 0;\r
-       ULONG ul_InterruptLatchReg;\r
-       \r
-       \r
-       /**************************/\r
-       /* Test the module number */\r
-       /**************************/\r
-\r
-       if (b_ModulNbr < 4)\r
-          {\r
-          /*******************************/\r
-          /* Test if counter initialised */\r
-          /*******************************/\r
-\r
-          if (devpriv->\r
-              s_ModuleInfo [b_ModulNbr].\r
-              s_SiemensCounterInfo.\r
-              s_InitFlag.\r
-              b_CounterInit == 1)\r
-             {\r
-             /*****************************/\r
-             /* Test if index initialised */\r
-             /*****************************/\r
-\r
-             if (devpriv->\r
-                 s_ModuleInfo [b_ModulNbr].\r
-                 s_SiemensCounterInfo.\r
-                 s_InitFlag.\r
-                 b_IndexInit)\r
-                {\r
-                devpriv->\r
-                s_ModuleInfo [b_ModulNbr].\r
-                s_SiemensCounterInfo.\r
-                s_ModeRegister.\r
-                s_ByteModeRegister.\r
-                b_ModeRegister2 = devpriv->\r
-                                  s_ModuleInfo [b_ModulNbr].\r
-                                  s_SiemensCounterInfo.\r
-                                  s_ModeRegister.\r
-                                  s_ByteModeRegister.\r
-                                  b_ModeRegister2 | APCI1710_ENABLE_INDEX;\r
-\r
-                 ul_InterruptLatchReg=inl(devpriv->s_BoardInfos.\r
-                       ui_Address + 24 + (64 * b_ModulNbr));\r
-\r
-\r
-                 outl(devpriv->s_ModuleInfo [b_ModulNbr].\r
-                        s_SiemensCounterInfo.\r
-                        s_ModeRegister.\r
-                        dw_ModeRegister1_2_3_4,devpriv->s_BoardInfos.\r
-                        ui_Address + 20 + (64 * b_ModulNbr));\r
-                }\r
-             else\r
-                {\r
-                /*************************************************************/\r
-                /* Index not initialised see function "i_APCI1710_InitIndex" */\r
-                /*************************************************************/\r
-\r
-                DPRINTK("Index not initialised \n");\r
-                i_ReturnValue = -4;\r
-                }\r
-             }\r
-          else\r
-             {\r
-             /****************************************/\r
-             /* Counter not initialised see function */\r
-             /* "i_APCI1710_InitCounter"             */\r
-             /****************************************/\r
-\r
-             DPRINTK("Counter not initialised\n");     \r
-             i_ReturnValue = -3;\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /*************************************************/\r
-          /* The selected module number parameter is wrong */\r
-          /*************************************************/\r
-\r
-          DPRINTK("The selected module number parameter is wrong\n");\r
-          i_ReturnValue = -2;\r
-          }\r
-\r
-       return (i_ReturnValue);\r
-       }\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : _INT_ i_APCI1710_DisableIndex (BYTE_  b_BoardHandle,   |\r
-|                                                    BYTE_  b_ModulNbr)      |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Disable the INDEX actions                              |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : BYTE_ b_BoardHandle     : Handle of board APCI-1710    |\r
-|                     BYTE_ b_ModulNbr        : Module number to configure   |\r
-|                                               (0 to 3)                     |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : -                                                      |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      :  0: No error                                           |\r
-|                     -1: The handle parameter of the board is wrong         |\r
-|                     -2: No counter module found                            |\r
-|                     -3: Counter not initialised see function               |\r
-|                         "i_APCI1710_InitCounter"                           |\r
-|                     -4: Index not initialised see function                 |\r
-|                         "i_APCI1710_InitIndex"                             |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-INT  i_APCI1710_DisableIndex (comedi_device *dev,\r
-                                BYTE b_ModulNbr)\r
-       {\r
-       INT i_ReturnValue = 0;\r
-       \r
-       \r
-       /**************************/\r
-       /* Test the module number */\r
-       /**************************/\r
-\r
-       if (b_ModulNbr < 4)\r
-          {\r
-          /*******************************/\r
-          /* Test if counter initialised */\r
-          /*******************************/\r
-\r
-          if (devpriv->\r
-              s_ModuleInfo [b_ModulNbr].\r
-              s_SiemensCounterInfo.\r
-              s_InitFlag.\r
-              b_CounterInit == 1)\r
-             {\r
-             /*****************************/\r
-             /* Test if index initialised */\r
-             /*****************************/\r
-\r
-             if (devpriv->\r
-                 s_ModuleInfo [b_ModulNbr].\r
-                 s_SiemensCounterInfo.\r
-                 s_InitFlag.\r
-                 b_IndexInit)\r
-                {\r
-                devpriv->\r
-                s_ModuleInfo [b_ModulNbr].\r
-                s_SiemensCounterInfo.\r
-                s_ModeRegister.\r
-                s_ByteModeRegister.\r
-                b_ModeRegister2 = devpriv->\r
-                                  s_ModuleInfo [b_ModulNbr].\r
-                                  s_SiemensCounterInfo.\r
-                                  s_ModeRegister.\r
-                                  s_ByteModeRegister.\r
-                                  b_ModeRegister2 & APCI1710_DISABLE_INDEX;\r
-\r
-                outl(devpriv->s_ModuleInfo [b_ModulNbr].\r
-                        s_SiemensCounterInfo.\r
-                        s_ModeRegister.\r
-                        dw_ModeRegister1_2_3_4,devpriv->s_BoardInfos.\r
-                        ui_Address + 20 + (64 * b_ModulNbr));\r
-                }\r
-             else\r
-                {\r
-                /*************************************************************/\r
-                /* Index not initialised see function "i_APCI1710_InitIndex" */\r
-                /*************************************************************/\r
-\r
-                DPRINTK("Index not initialised  \n");\r
-                i_ReturnValue = -4;\r
-                }\r
-             }\r
-          else\r
-             {\r
-             /****************************************/\r
-             /* Counter not initialised see function */\r
-             /* "i_APCI1710_InitCounter"             */\r
-             /****************************************/\r
-\r
-             DPRINTK("Counter not initialised\n");     \r
-             i_ReturnValue = -3;\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /*************************************************/\r
-          /* The selected module number parameter is wrong */\r
-          /*************************************************/\r
-\r
-          DPRINTK("The selected module number parameter is wrong\n");  \r
-          i_ReturnValue = -2;\r
-          }\r
-\r
-       return (i_ReturnValue);\r
-       }\r
-\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : _INT_ i_APCI1710_EnableCompareLogic                    |\r
-|                               (BYTE_   b_BoardHandle,                      |\r
-|                                BYTE_   b_ModulNbr)                         |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Enable the 32-Bit compare logic. At that moment that   |\r
-|                     the incremental counter arrive to the compare value a  |\r
-|                     interrupt is generated.                                |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : BYTE_  b_BoardHandle    : Handle of board APCI-1710    |\r
-|                     BYTE_  b_ModulNbr       : Module number to configure   |\r
-|                                               (0 to 3)                     |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : -\r
-+----------------------------------------------------------------------------+\r
-| Return Value      :  0: No error                                           |\r
-|                     -1: The handle parameter of the board is wrong         |\r
-|                     -2: No counter module found                            |\r
-|                     -3: Counter not initialised see function               |\r
-|                         "i_APCI1710_InitCounter"                           |\r
-|                     -4: Compare logic not initialised.                     |\r
-|                         See function "i_APCI1710_InitCompareLogic"         |\r
-|                     -5: Interrupt function not initialised.                |\r
-|                         See function "i_APCI1710_SetBoardIntRoutineX"      |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-INT   i_APCI1710_EnableCompareLogic   (comedi_device *dev,\r
-                                        BYTE   b_ModulNbr)\r
-       {\r
-       INT    i_ReturnValue = 0;\r
-       \r
-       \r
-       /**************************/\r
-       /* Test the module number */\r
-       /**************************/\r
-\r
-       if (b_ModulNbr < 4)\r
-          {\r
-          /*******************************/\r
-          /* Test if counter initialised */\r
-          /*******************************/\r
-\r
-          if (devpriv->\r
-              s_ModuleInfo [b_ModulNbr].\r
-              s_SiemensCounterInfo.\r
-              s_InitFlag.\r
-              b_CounterInit == 1)\r
-             {\r
-             /*************************************/\r
-             /* Test if compare logic initialised */\r
-             /*************************************/\r
-\r
-             if (devpriv->\r
-                 s_ModuleInfo [b_ModulNbr].\r
-                 s_SiemensCounterInfo.\r
-                 s_InitFlag.\r
-                 b_CompareLogicInit == 1)\r
-                {\r
-                   devpriv->\r
-                   s_ModuleInfo [b_ModulNbr].\r
-                   s_SiemensCounterInfo.\r
-                   s_ModeRegister.\r
-                   s_ByteModeRegister.\r
-                   b_ModeRegister3 = devpriv->\r
-                                     s_ModuleInfo [b_ModulNbr].\r
-                                     s_SiemensCounterInfo.\r
-                                     s_ModeRegister.\r
-                                     s_ByteModeRegister.\r
-                                     b_ModeRegister3 | APCI1710_ENABLE_COMPARE_INT;\r
-\r
-                   /***************************/\r
-                   /* Write the configuration */\r
-                   /***************************/\r
-\r
-                       outl(devpriv->s_ModuleInfo [b_ModulNbr].\r
-                           s_SiemensCounterInfo.\r
-                           s_ModeRegister.\r
-                           dw_ModeRegister1_2_3_4,devpriv->s_BoardInfos.\r
-                           ui_Address + 20 + (64 * b_ModulNbr));\r
-                }\r
-             else\r
-                {\r
-                /*********************************/\r
-                /* Compare logic not initialised */\r
-                /*********************************/\r
-\r
-                DPRINTK("Compare logic not initialised\n");\r
-                i_ReturnValue = -4;\r
-                }\r
-             }\r
-          else\r
-             {\r
-             /****************************************/\r
-             /* Counter not initialised see function */\r
-             /* "i_APCI1710_InitCounter"             */\r
-             /****************************************/\r
-\r
-             DPRINTK("Counter not initialised\n");     \r
-             i_ReturnValue = -3;\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /*************************************************/\r
-          /* The selected module number parameter is wrong */\r
-          /*************************************************/\r
-\r
-          DPRINTK("The selected module number parameter is wrong\n");\r
-          i_ReturnValue = -2;\r
-          }\r
-\r
-       return (i_ReturnValue);\r
-       }\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : _INT_ i_APCI1710_DisableCompareLogic                   |\r
-|                               (BYTE_   b_BoardHandle,                      |\r
-|                                BYTE_   b_ModulNbr)                         |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Disable the 32-Bit compare logic.\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : BYTE_  b_BoardHandle    : Handle of board APCI-1710    |\r
-|                     BYTE_  b_ModulNbr       : Module number to configure   |\r
-|                                               (0 to 3)                     |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : -\r
-+----------------------------------------------------------------------------+\r
-| Return Value      :  0: No error                                           |\r
-|                     -1: The handle parameter of the board is wrong         |\r
-|                     -2: No counter module found                            |\r
-|                     -3: Counter not initialised see function               |\r
-|                         "i_APCI1710_InitCounter"                           |\r
-|                     -4: Compare logic not initialised.                     |\r
-|                         See function "i_APCI1710_InitCompareLogic"         |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-INT   i_APCI1710_DisableCompareLogic  (comedi_device *dev,\r
-                                        BYTE   b_ModulNbr)\r
-       {\r
-       INT    i_ReturnValue = 0;\r
-       \r
-       /**************************/\r
-       /* Test the module number */\r
-       /**************************/\r
-\r
-       if (b_ModulNbr < 4)\r
-          {\r
-          /*******************************/\r
-          /* Test if counter initialised */\r
-          /*******************************/\r
-\r
-          if (devpriv->\r
-              s_ModuleInfo [b_ModulNbr].\r
-              s_SiemensCounterInfo.\r
-              s_InitFlag.\r
-              b_CounterInit == 1)\r
-             {\r
-             /*************************************/\r
-             /* Test if compare logic initialised */\r
-             /*************************************/\r
-\r
-             if (devpriv->\r
-                 s_ModuleInfo [b_ModulNbr].\r
-                 s_SiemensCounterInfo.\r
-                 s_InitFlag.\r
-                 b_CompareLogicInit == 1)\r
-                {\r
-                devpriv->\r
-                s_ModuleInfo [b_ModulNbr].\r
-                s_SiemensCounterInfo.\r
-                s_ModeRegister.\r
-                s_ByteModeRegister.\r
-                b_ModeRegister3 = devpriv->\r
-                                  s_ModuleInfo [b_ModulNbr].\r
-                                  s_SiemensCounterInfo.\r
-                                  s_ModeRegister.\r
-                                  s_ByteModeRegister.\r
-                                  b_ModeRegister3 & APCI1710_DISABLE_COMPARE_INT;\r
-\r
-                /***************************/\r
-                /* Write the configuration */\r
-                /***************************/\r
-\r
-                outl(devpriv->s_ModuleInfo [b_ModulNbr].\r
-                        s_SiemensCounterInfo.\r
-                        s_ModeRegister.\r
-                        dw_ModeRegister1_2_3_4,devpriv->s_BoardInfos.\r
-                        ui_Address + 20 + (64 * b_ModulNbr));\r
-                }\r
-             else\r
-                {\r
-                /*********************************/\r
-                /* Compare logic not initialised */\r
-                /*********************************/\r
-\r
-                DPRINTK("Compare logic not initialised\n");\r
-                i_ReturnValue = -4;\r
-                }\r
-             }\r
-          else\r
-             {\r
-             /****************************************/\r
-             /* Counter not initialised see function */\r
-             /* "i_APCI1710_InitCounter"             */\r
-             /****************************************/\r
-\r
-             DPRINTK("Counter not initialised\n");     \r
-             i_ReturnValue = -3;\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /*************************************************/\r
-          /* The selected module number parameter is wrong */\r
-          /*************************************************/\r
-\r
-          DPRINTK("The selected module number parameter is wrong\n");\r
-          i_ReturnValue = -2;\r
-          }\r
-\r
-       return (i_ReturnValue);\r
-       }\r
-\r
-\r
-       /*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : _INT_ i_APCI1710_EnableFrequencyMeasurement            |\r
-|                              (BYTE_   b_BoardHandle,                      |\r
-|                               BYTE_   b_ModulNbr,                         |\r
-|                               BYTE_   b_InterruptEnable)                  |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Enables the frequency measurement function             |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : BYTE_  b_BoardHandle    : Handle of board APCI-1710    |\r
-|                    BYTE_  b_ModulNbr       : Number of the module to be   |\r
-|                                              configured (0 to 3)          |\r
-|                    BYTE_  b_InterruptEnable: Enable or disable the        |\r
-|                                              interrupt.                   |\r
-|                                              APCI1710_ENABLE:             |\r
-|                                              Enable the interrupt         |\r
-|                                              APCI1710_DISABLE:            |\r
-|                                              Disable the interrupt        |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : -                                                      |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      :  0: No error                                           |\r
-|                     -1: The handle parameter of the board is wrong         |\r
-|                     -2: The selected module number is wrong                |\r
-|                     -3: Counter not initialised see function               |\r
-|                        "i_APCI1710_InitCounter"                           |\r
-|                     -4: Frequency measurement logic not initialised.       |\r
-|                        See function "i_APCI1710_InitFrequencyMeasurement" |\r
-|                     -5: Interrupt parameter is wrong                       |\r
-|                     -6: Interrupt function not initialised.                |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-INT    i_APCI1710_EnableFrequencyMeasurement   (comedi_device *dev,\r
-                                                BYTE    b_ModulNbr,\r
-                                                BYTE    b_InterruptEnable)\r
-       {\r
-       INT    i_ReturnValue = 0;\r
-       \r
-       \r
-       /**************************/\r
-       /* Test the module number */\r
-       /**************************/\r
-\r
-       if (b_ModulNbr < 4)\r
-          {\r
-          /*******************************/\r
-          /* Test if counter initialised */\r
-          /*******************************/\r
-\r
-          if (devpriv->\r
-              s_ModuleInfo [b_ModulNbr].\r
-              s_SiemensCounterInfo.\r
-              s_InitFlag.\r
-              b_CounterInit == 1)\r
-             {\r
-             /********************************************/\r
-             /* Test if frequency mesurement initialised */\r
-             /********************************************/\r
-\r
-             if (devpriv->\r
-                 s_ModuleInfo [b_ModulNbr].\r
-                 s_SiemensCounterInfo.\r
-                 s_InitFlag.\r
-                 b_FrequencyMeasurementInit == 1)\r
-                {\r
-                /***************************/\r
-                /* Test the interrupt mode */\r
-                /***************************/\r
-\r
-                if ((b_InterruptEnable == APCI1710_DISABLE) ||\r
-                    (b_InterruptEnable == APCI1710_ENABLE))\r
-                   {\r
-\r
-                      /************************************/\r
-                      /* Enable the frequency measurement */\r
-                      /************************************/\r
-\r
-                      devpriv->\r
-                      s_ModuleInfo [b_ModulNbr].\r
-                      s_SiemensCounterInfo.\r
-                      s_ModeRegister.\r
-                      s_ByteModeRegister.\r
-                      b_ModeRegister3 = devpriv->\r
-                                        s_ModuleInfo [b_ModulNbr].\r
-                                        s_SiemensCounterInfo.\r
-                                        s_ModeRegister.\r
-                                        s_ByteModeRegister.\r
-                                        b_ModeRegister3 | APCI1710_ENABLE_FREQUENCY;\r
-\r
-                      /*********************************************/\r
-                      /* Disable or enable the frequency interrupt */\r
-                      /*********************************************/\r
-\r
-                      devpriv->\r
-                      s_ModuleInfo [b_ModulNbr].\r
-                      s_SiemensCounterInfo.\r
-                      s_ModeRegister.\r
-                      s_ByteModeRegister.\r
-                      b_ModeRegister3 = (devpriv->\r
-                                         s_ModuleInfo [b_ModulNbr].\r
-                                         s_SiemensCounterInfo.\r
-                                         s_ModeRegister.\r
-                                         s_ByteModeRegister.\r
-                                         b_ModeRegister3 & APCI1710_DISABLE_FREQUENCY_INT) | (b_InterruptEnable << 3);\r
-\r
-                      /***************************/\r
-                      /* Write the configuration */\r
-                      /***************************/\r
-\r
-                          outl(devpriv->s_ModuleInfo [b_ModulNbr].\r
-                              s_SiemensCounterInfo.\r
-                              s_ModeRegister.\r
-                              dw_ModeRegister1_2_3_4,devpriv->s_BoardInfos.\r
-                              ui_Address + 20 + (64 * b_ModulNbr));\r
-\r
-                      devpriv->\r
-                      s_ModuleInfo [b_ModulNbr].\r
-                      s_SiemensCounterInfo.\r
-                      s_InitFlag.\r
-                      b_FrequencyMeasurementEnable = 1;\r
-                   }\r
-                else\r
-                   {\r
-                   /********************************/\r
-                   /* Interrupt parameter is wrong */\r
-                   /********************************/\r
-\r
-                   DPRINTK("Interrupt parameter is wrong\n");\r
-                   i_ReturnValue = -5;\r
-                   }\r
-                }\r
-             else\r
-                {\r
-                /***********************************************/\r
-                /* Frequency measurement logic not initialised */\r
-                /***********************************************/\r
-\r
-                DPRINTK("Frequency measurement logic not initialised\n");\r
-                i_ReturnValue = -4;\r
-                }\r
-             }\r
-          else\r
-             {\r
-             /****************************************/\r
-             /* Counter not initialised see function */\r
-             /* "i_APCI1710_InitCounter"             */\r
-             /****************************************/\r
-\r
-             DPRINTK("Counter not initialised\n");     \r
-             i_ReturnValue = -3;\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /*************************************************/\r
-          /* The selected module number parameter is wrong */\r
-          /*************************************************/\r
-\r
-          DPRINTK("The selected module number parameter is wrong\n"); \r
-          i_ReturnValue = -2;\r
-          }\r
-\r
-       return (i_ReturnValue);\r
-       }\r
-\r
-       /*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : _INT_ i_APCI1710_DisableFrequencyMeasurement           |\r
-|                              (BYTE_   b_BoardHandle,                      |\r
-|                               BYTE_   b_ModulNbr)                         |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Disables the frequency measurement function             |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : BYTE_  b_BoardHandle    : Handle of board APCI-1710    |\r
-|                    BYTE_  b_ModulNbr       : Number of the module to be   |\r
-|                                              configured (0 to 3)          |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : -                                                      |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      :  0: No error                                           |\r
-|                     -1: The handle parameter of the board is wrong         |\r
-|                     -2: The selected module number is wrong                |\r
-|                     -3: Counter not initialised see function               |\r
-|                        "i_APCI1710_InitCounter"                           |\r
-|                     -4: Frequency measurement logic not initialised.       |\r
-|                        See function "i_APCI1710_InitFrequencyMeasurement" |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-INT    i_APCI1710_DisableFrequencyMeasurement  (comedi_device *dev,\r
-                                                BYTE    b_ModulNbr)\r
-       {\r
-       INT    i_ReturnValue = 0;\r
-       \r
-       /**************************/\r
-       /* Test the module number */\r
-       /**************************/\r
-\r
-       if (b_ModulNbr < 4)\r
-          {\r
-          /*******************************/\r
-          /* Test if counter initialised */\r
-          /*******************************/\r
-\r
-          if (devpriv->\r
-              s_ModuleInfo [b_ModulNbr].\r
-              s_SiemensCounterInfo.\r
-              s_InitFlag.\r
-              b_CounterInit == 1)\r
-             {\r
-             /********************************************/\r
-             /* Test if frequency mesurement initialised */\r
-             /********************************************/\r
-\r
-             if (devpriv->\r
-                 s_ModuleInfo [b_ModulNbr].\r
-                 s_SiemensCounterInfo.\r
-                 s_InitFlag.\r
-                 b_FrequencyMeasurementInit == 1)\r
-                {\r
-                /*************************************/\r
-                /* Disable the frequency measurement */\r
-                /*************************************/\r
-\r
-                devpriv->\r
-                s_ModuleInfo [b_ModulNbr].\r
-                s_SiemensCounterInfo.\r
-                s_ModeRegister.\r
-                s_ByteModeRegister.\r
-                b_ModeRegister3 = devpriv->\r
-                                  s_ModuleInfo [b_ModulNbr].\r
-                                  s_SiemensCounterInfo.\r
-                                  s_ModeRegister.\r
-                                  s_ByteModeRegister.\r
-                                  b_ModeRegister3 & APCI1710_DISABLE_FREQUENCY\r
-                                  // Begin CG 29/06/01 CG 1100/0231 -> 0701/0232 Frequence measure IRQ must be cleared\r
-                                  & APCI1710_DISABLE_FREQUENCY_INT;\r
-                                  // End CG 29/06/01 CG 1100/0231 -> 0701/0232 Frequence measure IRQ must be cleared\r
-\r
-                /***************************/\r
-                /* Write the configuration */\r
-                /***************************/\r
-\r
-                outl(devpriv->s_ModuleInfo [b_ModulNbr].\r
-                        s_SiemensCounterInfo.\r
-                        s_ModeRegister.\r
-                        dw_ModeRegister1_2_3_4,devpriv->s_BoardInfos.\r
-                        ui_Address + 20 + (64 * b_ModulNbr));\r
-\r
-                /*************************************/\r
-                /* Disable the frequency measurement */\r
-                /*************************************/\r
-\r
-                devpriv->\r
-                s_ModuleInfo [b_ModulNbr].\r
-                s_SiemensCounterInfo.\r
-                s_InitFlag.\r
-                b_FrequencyMeasurementEnable = 0;\r
-                }\r
-             else\r
-                {\r
-                /***********************************************/\r
-                /* Frequency measurement logic not initialised */\r
-                /***********************************************/\r
-\r
-                DPRINTK("Frequency measurement logic not initialised\n");\r
-                i_ReturnValue = -4;\r
-                }\r
-             }\r
-          else\r
-             {\r
-             /****************************************/\r
-             /* Counter not initialised see function */\r
-             /* "i_APCI1710_InitCounter"             */\r
-             /****************************************/\r
-\r
-             DPRINTK("Counter not initialised\n");     \r
-             i_ReturnValue = -3;\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /*************************************************/\r
-          /* The selected module number parameter is wrong */\r
-          /*************************************************/\r
-\r
-          DPRINTK("The selected module number parameter is wrong\n");  \r
-          i_ReturnValue = -2;\r
-          }\r
-\r
-       return (i_ReturnValue);\r
-       }\r
-\r
-/*########################################################################### */\r
-\r
-                                                       // INSN READ\r
-\r
-/*########################################################################### */\r
-\r
-                                        \r
-\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     :INT       i_APCI1710_InsnWriteINCCPT(comedi_device *dev,comedi_subdevice *s,\r
-comedi_insn *insn,lsampl_t *data)                   |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Read and Get functions for INC_CPT                                       |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : \r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : -                                                      |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      : \r
-+----------------------------------------------------------------------------+\r
-*/\r
-INT    i_APCI1710_InsnReadINCCPT(comedi_device *dev,comedi_subdevice *s,\r
-comedi_insn *insn,lsampl_t *data)\r
-{\r
-       UINT ui_ReadType;\r
-       INT  i_ReturnValue=0;\r
-        \r
-       ui_ReadType=CR_CHAN(insn->chanspec);\r
-\r
-       devpriv->tsk_Current=current; // Save the current process task structure\r
-       switch(ui_ReadType)\r
-       {\r
-       case APCI1710_INCCPT_READLATCHREGISTERSTATUS:\r
-               i_ReturnValue=i_APCI1710_ReadLatchRegisterStatus      (dev,\r
-                                                (BYTE)   CR_AREF(insn->chanspec),\r
-                                                (BYTE)   CR_RANGE(insn->chanspec),\r
-                                                (PBYTE)  &data[0]);\r
-       break;\r
-\r
-       case APCI1710_INCCPT_READLATCHREGISTERVALUE:\r
-               i_ReturnValue=i_APCI1710_ReadLatchRegisterValue       (dev,\r
-                                                (BYTE)   CR_AREF(insn->chanspec),\r
-                                                (BYTE)   CR_RANGE(insn->chanspec),\r
-                                                (PULONG) &data[0]);\r
-                printk("Latch Register Value %d\n",data[0]);\r
-       break;\r
-\r
-       case APCI1710_INCCPT_READ16BITCOUNTERVALUE:\r
-               i_ReturnValue=i_APCI1710_Read16BitCounterValue        (dev,\r
-                                                (BYTE)   CR_AREF(insn->chanspec),\r
-                                                (BYTE)   CR_RANGE(insn->chanspec),\r
-                                                (PUINT) &data[0]);\r
-       break;\r
-    \r
-       case APCI1710_INCCPT_READ32BITCOUNTERVALUE:\r
-               i_ReturnValue=i_APCI1710_Read32BitCounterValue        (dev,\r
-                                                (BYTE)   CR_AREF(insn->chanspec),\r
-                                                (PULONG)  &data[0]);\r
-       break;\r
-    \r
-       case APCI1710_INCCPT_GETINDEXSTATUS:\r
-                i_ReturnValue=i_APCI1710_GetIndexStatus      (dev,\r
-                                       (BYTE)   CR_AREF(insn->chanspec),\r
-                                       (PBYTE) &data[0]);\r
-       break;\r
-    \r
-       case APCI1710_INCCPT_GETREFERENCESTATUS:\r
-                i_ReturnValue=i_APCI1710_GetReferenceStatus      (dev,\r
-                                           (BYTE)   CR_AREF(insn->chanspec),\r
-                                           (PBYTE)  &data[0]);\r
-       break;\r
-    \r
-       case APCI1710_INCCPT_GETUASSTATUS:\r
-               i_ReturnValue=i_APCI1710_GetUASStatus (dev,\r
-                                (BYTE)   CR_AREF(insn->chanspec),\r
-                                (PBYTE) &data[0]);\r
-       break;\r
-    \r
-       case APCI1710_INCCPT_GETCBSTATUS:\r
-               i_ReturnValue=i_APCI1710_GetCBStatus  (dev,\r
-                                (BYTE)   CR_AREF(insn->chanspec),\r
-                                (PBYTE) &data[0]);\r
-       break;\r
-    \r
-       case APCI1710_INCCPT_GET16BITCBSTATUS:\r
-               i_ReturnValue=i_APCI1710_Get16BitCBStatus       (dev,\r
-                                (BYTE)   CR_AREF(insn->chanspec),\r
-                                (PBYTE) &data[0],\r
-                                (PBYTE) &data[1]);\r
-       break;\r
-    \r
-       case APCI1710_INCCPT_GETUDSTATUS:\r
-               i_ReturnValue=i_APCI1710_GetUDStatus  (dev,\r
-                                (BYTE)   CR_AREF(insn->chanspec),\r
-                                (PBYTE) &data[0]);\r
-       \r
-       break;\r
-    \r
-       case APCI1710_INCCPT_GETINTERRUPTUDLATCHEDSTATUS:\r
-               i_ReturnValue=i_APCI1710_GetInterruptUDLatchedStatus  (dev,\r
-                                (BYTE)   CR_AREF(insn->chanspec),\r
-                                (PBYTE) &data[0]);\r
-       break;\r
-    \r
-       case APCI1710_INCCPT_READFREQUENCYMEASUREMENT:\r
-               i_ReturnValue=i_APCI1710_ReadFrequencyMeasurement (dev,\r
-                                (BYTE)   CR_AREF(insn->chanspec),\r
-                                (PBYTE)  &data[0],\r
-                                (PBYTE)  &data[1],\r
-                                (PULONG) &data[2]);\r
-       break;\r
-         \r
-        case APCI1710_INCCPT_READINTERRUPT:\r
-               data[0]=devpriv->s_InterruptParameters.\r
-                                                     s_FIFOInterruptParameters [devpriv->\r
-                                                                                s_InterruptParameters.\r
-                                                                                ui_Read].b_OldModuleMask;\r
-               data[1]=devpriv->s_InterruptParameters.\r
-                                                     s_FIFOInterruptParameters [devpriv->\r
-                                                                                s_InterruptParameters.\r
-                                                                                ui_Read].ul_OldInterruptMask;\r
-               data[2]=devpriv->s_InterruptParameters.\r
-                                                     s_FIFOInterruptParameters [devpriv->\r
-                                                                                s_InterruptParameters.\r
-                                                                                ui_Read].ul_OldCounterLatchValue;\r
-\r
-                            \r
-               /**************************/\r
-               /* Increment the read FIFO */\r
-               /***************************/\r
-\r
-               devpriv->\r
-               s_InterruptParameters.\r
-               ui_Read = (devpriv->s_InterruptParameters.\r
-                                       ui_Read + 1) % APCI1710_SAVE_INTERRUPT;\r
\r
-         \r
-               break;                      \r
-    \r
-       default:\r
-               printk("ReadType Parameter wrong\n");\r
-       }\r
-\r
-       if(i_ReturnValue>=0) i_ReturnValue =insn->n;\r
-       return (i_ReturnValue); \r
-\r
-}\r
-\r
-\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : _INT_ i_APCI1710_ReadLatchRegisterStatus               |\r
-|                                                   (BYTE_   b_BoardHandle,  |\r
-|                                                    BYTE_   b_ModulNbr,     |\r
-|                                                    BYTE_   b_LatchReg,     |\r
-|                                                    PBYTE_ pb_LatchStatus)  |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Read the latch register status from selected module    |\r
-|                     (b_ModulNbr) and selected latch register (b_LatchReg). |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : BYTE_ b_BoardHandle : Handle of board APCI-1710        |\r
-|                     BYTE_ b_ModulNbr    : Module number to configure       |\r
-|                                           (0 to 3)                         |\r
-|                     BYTE_ b_LatchReg    : Selected latch register          |\r
-|                               0 : for the first latch register             |\r
-|                               1 : for the second latch register            |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : PBYTE_ pb_LatchStatus :   Latch register status.       |\r
-|                                               0 : No latch occur           |\r
-|                                               1 : A software latch occur   |\r
-|                                               2 : A hardware latch occur   |\r
-|                                               3 : A software and hardware  |\r
-|                                                   latch occur              |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      :  0: No error                                           |\r
-|                     -1: The handle parameter of the board is wrong         |\r
-|                     -2: No counter module found                            |\r
-|                     -3: Counter not initialised see function               |\r
-|                         "i_APCI1710_InitCounter"                           |\r
-|                     -4: The selected latch register parameter is wrong     |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-INT   i_APCI1710_ReadLatchRegisterStatus      (comedi_device *dev,\r
-                                                BYTE   b_ModulNbr,\r
-                                                BYTE   b_LatchReg,\r
-                                                PBYTE pb_LatchStatus)\r
-       {\r
-       INT    i_ReturnValue = 0;\r
-       DWORD dw_LatchReg;\r
-       \r
-       /**************************/\r
-       /* Test the module number */\r
-       /**************************/\r
-\r
-       if (b_ModulNbr < 4)\r
-          {\r
-          /*******************************/\r
-          /* Test if counter initialised */\r
-          /*******************************/\r
-\r
-          if (devpriv->\r
-              s_ModuleInfo [b_ModulNbr].\r
-              s_SiemensCounterInfo.\r
-              s_InitFlag.\r
-              b_CounterInit == 1)\r
-             {\r
-             /*************************************/\r
-             /* Test the latch register parameter */\r
-             /*************************************/\r
-\r
-             if (b_LatchReg < 2)\r
-                {\r
-                       dw_LatchReg=inl(devpriv->s_BoardInfos.\r
-                                                       ui_Address + (64 * b_ModulNbr));\r
-\r
-                *pb_LatchStatus = (BYTE) ((dw_LatchReg >> (b_LatchReg * 4)) & 0x3);\r
-                }\r
-             else\r
-                {\r
-                /**************************************************/\r
-                /* The selected latch register parameter is wrong */\r
-                /**************************************************/\r
-\r
-                DPRINTK("The selected latch register parameter is wrong\n");\r
-                i_ReturnValue = -4;\r
-                }\r
-             }\r
-          else\r
-             {\r
-             /****************************************/\r
-             /* Counter not initialised see function */\r
-             /* "i_APCI1710_InitCounter"             */\r
-             /****************************************/\r
-\r
-             DPRINTK("Counter not initialised\n");\r
-             i_ReturnValue = -3;\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /*************************************************/\r
-          /* The selected module number parameter is wrong */\r
-          /*************************************************/\r
-\r
-          DPRINTK("The selected module number parameter is wrong\n");  \r
-          i_ReturnValue = -2;\r
-          }\r
-\r
-\r
-       return (i_ReturnValue);\r
-       }\r
-\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : _INT_ i_APCI1710_ReadLatchRegisterValue                |\r
-|                                                   (BYTE_     b_BoardHandle,|\r
-|                                                    BYTE_     b_ModulNbr,   |\r
-|                                                    BYTE_     b_LatchReg,   |\r
-|                                                    PULONG_ pul_LatchValue) |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Read the latch register value from selected module     |\r
-|                     (b_ModulNbr) and selected latch register (b_LatchReg). |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : BYTE_ b_BoardHandle : Handle of board APCI-1710        |\r
-|                     BYTE_ b_ModulNbr    : Module number to configure       |\r
-|                                           (0 to 3)                         |\r
-|                     BYTE_ b_LatchReg    : Selected latch register          |\r
-|                               0 : for the first latch register             |\r
-|                               1 : for the second latch register            |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : PULONG_ pul_LatchValue : Latch register value          |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      :  0: No error                                           |\r
-|                     -1: The handle parameter of the board is wrong         |\r
-|                     -2: No counter module found                            |\r
-|                     -3: Counter not initialised see function               |\r
-|                         "i_APCI1710_InitCounter"                           |\r
-|                     -4: The selected latch register parameter is wrong     |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-INT   i_APCI1710_ReadLatchRegisterValue       (comedi_device *dev,\r
-                                                BYTE     b_ModulNbr,\r
-                                                BYTE     b_LatchReg,\r
-                                                PULONG pul_LatchValue)\r
-       {\r
-       INT i_ReturnValue = 0;\r
-       \r
-       /**************************/\r
-       /* Test the module number */\r
-       /**************************/\r
-\r
-       if (b_ModulNbr < 4)\r
-          {\r
-          /*******************************/\r
-          /* Test if counter initialised */\r
-          /*******************************/\r
-\r
-          if (devpriv->\r
-              s_ModuleInfo [b_ModulNbr].\r
-              s_SiemensCounterInfo.\r
-              s_InitFlag.\r
-              b_CounterInit == 1)\r
-             {\r
-             /*************************************/\r
-             /* Test the latch register parameter */\r
-             /*************************************/\r
-\r
-             if (b_LatchReg < 2)\r
-                {\r
-                       *pul_LatchValue=inl(devpriv->s_BoardInfos.\r
-                       ui_Address + ((b_LatchReg + 1) * 4) + (64 * b_ModulNbr));\r
-                    \r
-                }\r
-             else\r
-                {\r
-                /**************************************************/\r
-                /* The selected latch register parameter is wrong */\r
-                /**************************************************/\r
-\r
-                DPRINTK("The selected latch register parameter is wrong\n");\r
-                i_ReturnValue = -4;\r
-                }\r
-             }\r
-          else\r
-             {\r
-             /****************************************/\r
-             /* Counter not initialised see function */\r
-             /* "i_APCI1710_InitCounter"             */\r
-             /****************************************/\r
-\r
-             DPRINTK("Counter not initialised\n");     \r
-             i_ReturnValue = -3;\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /*************************************************/\r
-          /* The selected module number parameter is wrong */\r
-          /*************************************************/\r
-\r
-          DPRINTK("The selected module number parameter is wrong\n");  \r
-          i_ReturnValue = -2;\r
-          }\r
-\r
-       return (i_ReturnValue);\r
-       }\r
-\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : _INT_ i_APCI1710_Read16BitCounterValue                 |\r
-|                                       (BYTE_     b_BoardHandle,            |\r
-|                                        BYTE_     b_ModulNbr,               |\r
-|                                        BYTE_     b_SelectedCounter,        |\r
-|                                        PUINT_   pui_CounterValue)          |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Latch the selected 16-Bit counter (b_SelectedCounter)  |\r
-|                     from selected module (b_ModulNbr) in to the first      |\r
-|                     latch register and return the latched value.           |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : BYTE_ b_BoardHandle     : Handle of board APCI-1710    |\r
-|                     BYTE_ b_ModulNbr        : Module number to configure   |\r
-|                                              (0 to 3)                      |\r
-|                     BYTE_ b_SelectedCounter : Selected 16-Bit counter      |\r
-|                                               (0 or 1)                     |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : PUINT_ pui_CounterValue : 16-Bit counter value         |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      :  0: No error                                           |\r
-|                     -1: The handle parameter of the board is wrong         |\r
-|                     -2: No counter module found                            |\r
-|                     -3: Counter not initialised see function               |\r
-|                         "i_APCI1710_InitCounter"                           |\r
-|                     -4: The selected 16-Bit counter parameter is wrong     |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-INT   i_APCI1710_Read16BitCounterValue        (comedi_device *dev,\r
-                                                BYTE    b_ModulNbr,\r
-                                                BYTE    b_SelectedCounter,\r
-                                                PUINT pui_CounterValue)\r
-       {\r
-       INT    i_ReturnValue = 0;\r
-       DWORD dw_LathchValue = 0;\r
-       \r
-       /**************************/\r
-       /* Test the module number */\r
-       /**************************/\r
-\r
-       if (b_ModulNbr < 4)\r
-          {\r
-          /*******************************/\r
-          /* Test if counter initialised */\r
-          /*******************************/\r
-\r
-          if (devpriv->\r
-              s_ModuleInfo [b_ModulNbr].\r
-              s_SiemensCounterInfo.\r
-              s_InitFlag.\r
-              b_CounterInit == 1)\r
-             {\r
-             /******************************/\r
-             /* Test the counter selection */\r
-             /******************************/\r
-\r
-             if (b_SelectedCounter < 2)\r
-                {\r
-                /*********************/\r
-                /* Latch the counter */\r
-                /*********************/\r
-\r
-                         outl(1,devpriv->s_BoardInfos.\r
-                        ui_Address + (64 * b_ModulNbr));\r
-\r
-                /************************/\r
-                /* Read the latch value */\r
-                /************************/\r
-\r
-                       dw_LathchValue=inl(devpriv->s_BoardInfos.\r
-                       ui_Address + 4 + (64 * b_ModulNbr));\r
-\r
-                *pui_CounterValue = (UINT) ((dw_LathchValue >> (16 * b_SelectedCounter)) & 0xFFFFU);\r
-                }\r
-             else\r
-                {\r
-                /**************************************************/\r
-                /* The selected 16-Bit counter parameter is wrong */\r
-                /**************************************************/\r
-\r
-                DPRINTK("The selected 16-Bit counter parameter is wrong\n");\r
-                i_ReturnValue = -4;\r
-                }\r
-             }\r
-          else\r
-             {\r
-             /****************************************/\r
-             /* Counter not initialised see function */\r
-             /* "i_APCI1710_InitCounter"             */\r
-             /****************************************/\r
-\r
-             DPRINTK("Counter not initialised\n");     \r
-             i_ReturnValue = -3;\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /*************************************************/\r
-          /* The selected module number parameter is wrong */\r
-          /*************************************************/\r
-\r
-          DPRINTK("The selected module number parameter is wrong\n");\r
-          i_ReturnValue = -2;\r
-          }\r
-\r
-       return (i_ReturnValue);\r
-       }\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : _INT_ i_APCI1710_Read32BitCounterValue                 |\r
-|                                       (BYTE_     b_BoardHandle,            |\r
-|                                        BYTE_     b_ModulNbr,               |\r
-|                                        PULONG_ pul_CounterValue)           |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Latch the 32-Bit counter from selected module          |\r
-|                     (b_ModulNbr) in to the first latch register and return |\r
-|                     the latched value.                                     |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : BYTE_ b_BoardHandle     : Handle of board APCI-1710    |\r
-|                     BYTE_ b_ModulNbr        : Module number to configure   |\r
-|                                              (0 to 3)                      |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : PULONG_  pul_CounterValue : 32-Bit counter value       |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      :  0: No error                                           |\r
-|                     -1: The handle parameter of the board is wrong         |\r
-|                     -2: No counter module found                            |\r
-|                     -3: Counter not initialised see function               |\r
-|                         "i_APCI1710_InitCounter"                           |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-INT   i_APCI1710_Read32BitCounterValue        (comedi_device *dev,\r
-                                                BYTE      b_ModulNbr,\r
-                                                PULONG  pul_CounterValue)\r
-       {\r
-       INT    i_ReturnValue = 0;\r
-       \r
-       \r
-       /**************************/\r
-       /* Test the module number */\r
-       /**************************/\r
-\r
-       if (b_ModulNbr < 4)\r
-          {\r
-          /*******************************/\r
-          /* Test if counter initialised */\r
-          /*******************************/\r
-\r
-          if (devpriv->\r
-              s_ModuleInfo [b_ModulNbr].\r
-              s_SiemensCounterInfo.\r
-              s_InitFlag.\r
-              b_CounterInit == 1)\r
-             {\r
-             /*********************/\r
-             /* Tatch the counter */\r
-             /*********************/\r
-\r
-                  outl(1,devpriv->s_BoardInfos.\r
-                     ui_Address + (64 * b_ModulNbr));\r
-\r
-             /************************/\r
-             /* Read the latch value */\r
-             /************************/\r
-\r
-                  *pul_CounterValue=inl(devpriv->s_BoardInfos.\r
-                    ui_Address + 4 + (64 * b_ModulNbr));\r
-             }\r
-          else\r
-             {\r
-             /****************************************/\r
-             /* Counter not initialised see function */\r
-             /* "i_APCI1710_InitCounter"             */\r
-             /****************************************/\r
-\r
-             DPRINTK("Counter not initialised\n");\r
-             i_ReturnValue = -3;\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /*************************************************/\r
-          /* The selected module number parameter is wrong */\r
-          /*************************************************/\r
-\r
-          DPRINTK("The selected module number parameter is wrong\n");  \r
-          i_ReturnValue = -2;\r
-          }\r
-\r
-       return (i_ReturnValue);\r
-       }\r
-\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : _INT_ i_APCI1710_GetIndexStatus (BYTE_   b_BoardHandle,|\r
-|                                                      BYTE_   b_ModulNbr,   |\r
-|                                                      PBYTE_ pb_IndexStatus)|\r
-+----------------------------------------------------------------------------+\r
-| Task              : Return the index status                                |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : BYTE_ b_BoardHandle     : Handle of board APCI-1710    |\r
-|                     BYTE_ b_ModulNbr        : Module number to configure   |\r
-|                                               (0 to 3)                     |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : PBYTE_ pb_IndexStatus   : 0 : No INDEX occur           |\r
-|                                               1 : A INDEX occur            |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      :  0: No error                                           |\r
-|                     -1: The handle parameter of the board is wrong         |\r
-|                     -2: No counter module found                            |\r
-|                     -3: Counter not initialised see function               |\r
-|                         "i_APCI1710_InitCounter"                           |\r
-|                     -4: Index not initialised see function                 |\r
-|                         "i_APCI1710_InitIndex"                             |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-INT   i_APCI1710_GetIndexStatus      (comedi_device *dev,\r
-                                       BYTE   b_ModulNbr,\r
-                                       PBYTE pb_IndexStatus)\r
-       {\r
-       INT    i_ReturnValue = 0;\r
-       DWORD dw_StatusReg   = 0;\r
-       \r
-       /**************************/\r
-       /* Test the module number */\r
-       /**************************/\r
-\r
-       if (b_ModulNbr < 4)\r
-          {\r
-          /*******************************/\r
-          /* Test if counter initialised */\r
-          /*******************************/\r
-\r
-          if (devpriv->\r
-              s_ModuleInfo [b_ModulNbr].\r
-              s_SiemensCounterInfo.\r
-              s_InitFlag.\r
-              b_CounterInit == 1)\r
-             {\r
-             /*****************************/\r
-             /* Test if index initialised */\r
-             /*****************************/\r
-\r
-             if (devpriv->\r
-                 s_ModuleInfo [b_ModulNbr].\r
-                 s_SiemensCounterInfo.\r
-                 s_InitFlag.\r
-                 b_IndexInit)\r
-                {\r
-                        dw_StatusReg= inl(devpriv->s_BoardInfos.\r
-                        ui_Address + 12 + (64 * b_ModulNbr));\r
-\r
-                *pb_IndexStatus = (BYTE) (dw_StatusReg & 1);\r
-                }\r
-             else\r
-                {\r
-                /*************************************************************/\r
-                /* Index not initialised see function "i_APCI1710_InitIndex" */\r
-                /*************************************************************/\r
-\r
-                DPRINTK("Index not initialised\n");\r
-                i_ReturnValue = -4;\r
-                }\r
-             }\r
-          else\r
-             {\r
-             /****************************************/\r
-             /* Counter not initialised see function */\r
-             /* "i_APCI1710_InitCounter"             */\r
-             /****************************************/\r
-\r
-             DPRINTK("Counter not initialised\n");     \r
-             i_ReturnValue = -3;\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /*************************************************/\r
-          /* The selected module number parameter is wrong */\r
-          /*************************************************/\r
-\r
-          DPRINTK("The selected module number parameter is wrong\n");  \r
-          i_ReturnValue = -2;\r
-          }\r
-\r
-       return (i_ReturnValue);\r
-       }\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : _INT_ i_APCI1710_GetReferenceStatus                    |\r
-|                                                (BYTE_   b_BoardHandle,     |\r
-|                                                 BYTE_   b_ModulNbr,        |\r
-|                                                 PBYTE_ pb_ReferenceStatus) |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Return the reference status                            |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : BYTE_ b_BoardHandle     : Handle of board APCI-1710    |\r
-|                     BYTE_ b_ModulNbr        : Module number to configure   |\r
-|                                               (0 to 3)                     |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : PBYTE_ pb_ReferenceStatus   : 0 : No REFERENCE occur   |\r
-|                                                   1 : A REFERENCE occur    |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      :  0: No error                                           |\r
-|                     -1: The handle parameter of the board is wrong         |\r
-|                     -2: No counter module found                            |\r
-|                     -3: Counter not initialised see function               |\r
-|                         "i_APCI1710_InitCounter"                           |\r
-|                     -4: Reference not initialised see function             |\r
-|                         "i_APCI1710_InitReference"                         |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-INT   i_APCI1710_GetReferenceStatus      (comedi_device *dev,\r
-                                           BYTE   b_ModulNbr,\r
-                                           PBYTE  pb_ReferenceStatus)\r
-       {\r
-       INT    i_ReturnValue = 0;\r
-       DWORD dw_StatusReg   = 0;\r
-       \r
-       /**************************/\r
-       /* Test the module number */\r
-       /**************************/\r
-\r
-       if (b_ModulNbr < 4)\r
-          {\r
-          /*******************************/\r
-          /* Test if counter initialised */\r
-          /*******************************/\r
-\r
-          if (devpriv->\r
-              s_ModuleInfo [b_ModulNbr].\r
-              s_SiemensCounterInfo.\r
-              s_InitFlag.\r
-              b_CounterInit == 1)\r
-             {\r
-             /*********************************/\r
-             /* Test if reference initialised */\r
-             /*********************************/\r
-\r
-             if (devpriv->\r
-                 s_ModuleInfo [b_ModulNbr].\r
-                 s_SiemensCounterInfo.\r
-                 s_InitFlag.\r
-                 b_ReferenceInit)\r
-                {\r
-                       dw_StatusReg=inl(devpriv->s_BoardInfos.\r
-                        ui_Address + 24 + (64 * b_ModulNbr));\r
-\r
-                *pb_ReferenceStatus = (BYTE) (~dw_StatusReg & 1);\r
-                }\r
-             else\r
-                {\r
-                /*********************************************************************/\r
-                /* Reference not initialised see function "i_APCI1710_InitReference" */\r
-                /*********************************************************************/\r
-\r
-                DPRINTK("Reference not initialised\n");\r
-                i_ReturnValue = -4;\r
-                }\r
-             }\r
-          else\r
-             {\r
-             /****************************************/\r
-             /* Counter not initialised see function */\r
-             /* "i_APCI1710_InitCounter"             */\r
-             /****************************************/\r
-\r
-             DPRINTK("Counter not initialised\n");     \r
-             i_ReturnValue = -3;\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /*************************************************/\r
-          /* The selected module number parameter is wrong */\r
-          /*************************************************/\r
-\r
-          DPRINTK("The selected module number parameter is wrong\n");\r
-          i_ReturnValue = -2;\r
-          }\r
-\r
-       return (i_ReturnValue);\r
-       }\r
-\r
-\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : _INT_ i_APCI1710_GetUASStatus                          |\r
-|                               (BYTE_   b_BoardHandle,                      |\r
-|                                BYTE_   b_ModulNbr,                         |\r
-|                                PBYTE_ pb_UASStatus)                        |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Return the error signal (UAS) status                   |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : BYTE_ b_BoardHandle     : Handle of board APCI-1710    |\r
-|                     BYTE_ b_ModulNbr        : Module number to configure   |\r
-|                                               (0 to 3)                     |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : PBYTE_ pb_UASStatus      : 0 : UAS is low "0"          |\r
-|                                                1 : UAS is high "1"         |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      :  0: No error                                           |\r
-|                     -1: The handle parameter of the board is wrong         |\r
-|                     -2: No counter module found                            |\r
-|                     -3: Counter not initialised see function               |\r
-|                         "i_APCI1710_InitCounter"                           |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-INT   i_APCI1710_GetUASStatus (comedi_device *dev,\r
-                                BYTE   b_ModulNbr,\r
-                                PBYTE pb_UASStatus)\r
-       {\r
-       INT    i_ReturnValue = 0;\r
-       DWORD dw_StatusReg   = 0;\r
-       \r
-       \r
-       /**************************/\r
-       /* Test the module number */\r
-       /**************************/\r
-\r
-       if (b_ModulNbr < 4)\r
-          {\r
-          /*******************************/\r
-          /* Test if counter initialised */\r
-          /*******************************/\r
-\r
-          if (devpriv->\r
-              s_ModuleInfo [b_ModulNbr].\r
-              s_SiemensCounterInfo.\r
-              s_InitFlag.\r
-              b_CounterInit == 1)\r
-             {\r
-                  dw_StatusReg=inl(devpriv->s_BoardInfos.\r
-                     ui_Address + 24 + (64 * b_ModulNbr));\r
-\r
-             *pb_UASStatus = (BYTE) ((dw_StatusReg >> 1) & 1);\r
-             }\r
-          else\r
-             {\r
-             /****************************************/\r
-             /* Counter not initialised see function */\r
-             /* "i_APCI1710_InitCounter"             */\r
-             /****************************************/\r
-\r
-             DPRINTK("Counter not initialised\n");     \r
-             i_ReturnValue = -3;\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /*************************************************/\r
-          /* The selected module number parameter is wrong */\r
-          /*************************************************/\r
-\r
-          DPRINTK("The selected module number parameter is wrong\n");  \r
-          i_ReturnValue = -2;\r
-       \r
-          }\r
-\r
-       return (i_ReturnValue);\r
-       }\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : _INT_ i_APCI1710_GetCBStatus                           |\r
-|                               (BYTE_   b_BoardHandle,                      |\r
-|                                BYTE_   b_ModulNbr,                         |\r
-|                                PBYTE_ pb_CBStatus)                         |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Return the counter overflow status                     |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : BYTE_ b_BoardHandle     : Handle of board APCI-1710    |\r
-|                     BYTE_ b_ModulNbr        : Module number to configure   |\r
-|                                               (0 to 3)                     |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : PBYTE_ pb_CBStatus      : 0 : Counter no overflow      |\r
-|                                               1 : Counter overflow         |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      :  0: No error                                           |\r
-|                     -1: The handle parameter of the board is wrong         |\r
-|                     -2: No counter module found                            |\r
-|                     -3: Counter not initialised see function               |\r
-|                         "i_APCI1710_InitCounter"                           |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-INT   i_APCI1710_GetCBStatus  (comedi_device *dev,\r
-                                BYTE   b_ModulNbr,\r
-                                PBYTE pb_CBStatus)\r
-       {\r
-       INT    i_ReturnValue = 0;\r
-       DWORD dw_StatusReg   = 0;\r
-       \r
-\r
-       \r
-       /**************************/\r
-       /* Test the module number */\r
-       /**************************/\r
-\r
-       if (b_ModulNbr < 4)\r
-          {\r
-          /*******************************/\r
-          /* Test if counter initialised */\r
-          /*******************************/\r
-\r
-          if (devpriv->\r
-              s_ModuleInfo [b_ModulNbr].\r
-              s_SiemensCounterInfo.\r
-              s_InitFlag.\r
-              b_CounterInit == 1)\r
-             {\r
-                       dw_StatusReg=inl(devpriv->s_BoardInfos.\r
-                     ui_Address + 16 + (64 * b_ModulNbr));\r
-\r
-             *pb_CBStatus = (BYTE) (dw_StatusReg & 1);\r
-                             \r
-             }\r
-          else\r
-             {\r
-             /****************************************/\r
-             /* Counter not initialised see function */\r
-             /* "i_APCI1710_InitCounter"             */\r
-             /****************************************/\r
-\r
-             DPRINTK("Counter not initialised\n");     \r
-             i_ReturnValue = -3;\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /*************************************************/\r
-          /* The selected module number parameter is wrong */\r
-          /*************************************************/\r
-\r
-          DPRINTK("The selected module number parameter is wrong\n");  \r
-          i_ReturnValue = -2;\r
-          }\r
-\r
-       return (i_ReturnValue);\r
-       }\r
-\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : _INT_ i_APCI1710_Get16BitCBStatus                      |\r
-|                                      (BYTE_     b_BoardHandle,            |\r
-|                                       BYTE_     b_ModulNbr,               |\r
-|                                       PBYTE_ pb_CBStatusCounter0,         |\r
-|                                       PBYTE_ pb_CBStatusCounter1)         |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Returns the counter overflow (counter initialised to   |\r
-|                    2*16-bit) status from selected incremental counter     |\r
-|                    module                                                 |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : BYTE_ b_BoardHandle     : Handle of board APCI-1710    |\r
-|                     BYTE_ b_ModulNbr        : Module number to configure   |\r
-|                                               (0 to 3)                     |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : PBYTE_ pb_CBStatusCounter0 : 0 : No overflow occur for |\r
-|                                                     the first 16-bit      |\r
-|                                                     counter               |\r
-|                                                 1 : Overflow occur for the|\r
-|                                                     first 16-bit counter  |\r
-|                    PBYTE_ pb_CBStatusCounter1 : 0 : No overflow occur for |\r
-|                                                     the second 16-bit     |\r
-|                                                     counter               |\r
-|                                                 1 : Overflow occur for the|\r
-|                                                     second 16-bit counter |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      :  0: No error                                           |\r
-|                     -1: The handle parameter of the board is wrong         |\r
-|                     -2: No counter module found                            |\r
-|                     -3: Counter not initialised see function               |\r
-|                         "i_APCI1710_InitCounter"                           |\r
-|                     -4: Counter not initialised to 2*16-bit mode.          |\r
-|                        See function "i_APCI1710_InitCounter"              |\r
-|                     -5: Firmware revision error                            |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-INT    i_APCI1710_Get16BitCBStatus     (comedi_device *dev,\r
-                                        BYTE     b_ModulNbr,\r
-                                        PBYTE pb_CBStatusCounter0,\r
-                                        PBYTE pb_CBStatusCounter1)\r
-       {\r
-       INT    i_ReturnValue = 0;\r
-       DWORD dw_StatusReg   = 0;\r
-       \r
-\r
-       \r
-       /**************************/\r
-       /* Test the module number */\r
-       /**************************/\r
-\r
-       if (b_ModulNbr < 4)\r
-          {\r
-          /*******************************/\r
-          /* Test if counter initialised */\r
-          /*******************************/\r
-\r
-          if (devpriv->\r
-              s_ModuleInfo [b_ModulNbr].\r
-              s_SiemensCounterInfo.\r
-              s_InitFlag.\r
-              b_CounterInit == 1)\r
-             {\r
-             /*************************/\r
-             /* Test if 2*16-Bit mode */\r
-             /*************************/\r
-\r
-             if ((devpriv->\r
-                  s_ModuleInfo [b_ModulNbr].\r
-                  s_SiemensCounterInfo.\r
-                  s_ModeRegister.\r
-                  s_ByteModeRegister.\r
-                  b_ModeRegister1 & 0x10) == 0x10)\r
-                {\r
-                /*****************************/\r
-                /* Test the Firmware version */\r
-                /*****************************/\r
-\r
-                if ((devpriv->\r
-                     s_BoardInfos.\r
-                     dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) >= 0x3136)\r
-                   {\r
-                        dw_StatusReg=inl(devpriv->s_BoardInfos.\r
-                           ui_Address + 16 + (64 * b_ModulNbr));\r
-\r
-                   *pb_CBStatusCounter1 = (BYTE) ((dw_StatusReg >> 0) & 1);\r
-                   *pb_CBStatusCounter0 = (BYTE) ((dw_StatusReg >> 1) & 1);\r
-                   } // if ((ps_APCI1710Variable->s_Board [b_BoardHandle].s_BoardInfos.dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) >= 0x3136)\r
-                else\r
-                   {\r
-                   /****************************/\r
-                   /* Firmware revision error  */\r
-                   /****************************/\r
-\r
-                   i_ReturnValue = -5;\r
-                   } // if ((ps_APCI1710Variable->s_Board [b_BoardHandle].s_BoardInfos.dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) >= 0x3136)\r
-                } // if ((ps_APCI1710Variable->s_Board [b_BoardHandle].s_ModuleInfo [b_ModulNbr].s_SiemensCounterInfo.s_ModeRegister.s_ByteModeRegister.b_ModeRegister1 & 0x10) == 0x10)\r
-             else\r
-                {\r
-                /********************************************/\r
-                /* Counter not initialised to 2*16-bit mode */\r
-                /* "i_APCI1710_InitCounter"                 */\r
-                /********************************************/\r
-\r
-                DPRINTK("Counter not initialised\n");\r
-                i_ReturnValue = -4;\r
-                } // if ((ps_APCI1710Variable->s_Board [b_BoardHandle].s_ModuleInfo [b_ModulNbr].s_SiemensCounterInfo.s_ModeRegister.s_ByteModeRegister.b_ModeRegister1 & 0x10) == 0x10)\r
-             } // if (ps_APCI1710Variable->s_Board [b_BoardHandle].s_ModuleInfo [b_ModulNbr].s_SiemensCounterInfo.s_InitFlag.b_CounterInit == 1)\r
-          else\r
-             {\r
-             /****************************************/\r
-             /* Counter not initialised see function */\r
-             /* "i_APCI1710_InitCounter"             */\r
-             /****************************************/\r
-\r
-             DPRINTK("Counter not initialised\n");             \r
-             i_ReturnValue = -3;\r
-             } // if (ps_APCI1710Variable->s_Board [b_BoardHandle].s_ModuleInfo [b_ModulNbr].s_SiemensCounterInfo.s_InitFlag.b_CounterInit == 1)\r
-          } // if (b_ModulNbr < 4)\r
-       else\r
-          {\r
-          /*************************************************/\r
-          /* The selected module number parameter is wrong */\r
-          /*************************************************/\r
-\r
-          DPRINTK("The selected module number parameter is wrong\n");\r
-          i_ReturnValue = -2;\r
-          } // if (b_ModulNbr < 4)\r
-\r
-       return (i_ReturnValue);\r
-       }\r
-\r
-\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : _INT_ i_APCI1710_GetUDStatus                           |\r
-|                               (BYTE_   b_BoardHandle,                      |\r
-|                                BYTE_   b_ModulNbr,                         |\r
-|                                PBYTE_ pb_UDStatus)                         |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Return the counter progress status                     |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : BYTE_ b_BoardHandle     : Handle of board APCI-1710    |\r
-|                     BYTE_ b_ModulNbr        : Module number to configure   |\r
-|                                               (0 to 3)                     |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : PBYTE_ pb_UDStatus      : 0 : Counter progress in the  |\r
-|                                                   selected mode down       |\r
-|                                               1 : Counter progress in the  |\r
-|                                                   selected mode up         |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      :  0: No error                                           |\r
-|                     -1: The handle parameter of the board is wrong         |\r
-|                     -2: No counter module found                            |\r
-|                     -3: Counter not initialised see function               |\r
-|                         "i_APCI1710_InitCounter"                           |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-INT   i_APCI1710_GetUDStatus  (comedi_device *dev,\r
-                                BYTE   b_ModulNbr,\r
-                                PBYTE pb_UDStatus)\r
-       {\r
-       INT    i_ReturnValue = 0;\r
-       DWORD dw_StatusReg   = 0;\r
-       \r
-       \r
-       /**************************/\r
-       /* Test the module number */\r
-       /**************************/\r
-\r
-       if (b_ModulNbr < 4)\r
-          {\r
-          /*******************************/\r
-          /* Test if counter initialised */\r
-          /*******************************/\r
-\r
-          if (devpriv->\r
-              s_ModuleInfo [b_ModulNbr].\r
-              s_SiemensCounterInfo.\r
-              s_InitFlag.\r
-              b_CounterInit == 1)\r
-             {\r
-                  dw_StatusReg=inl(devpriv->s_BoardInfos.\r
-                     ui_Address + 24 + (64 * b_ModulNbr));\r
-\r
-             *pb_UDStatus = (BYTE) ((dw_StatusReg >> 2) & 1);\r
-               \r
-             }\r
-          else\r
-             {\r
-             /****************************************/\r
-             /* Counter not initialised see function */\r
-             /* "i_APCI1710_InitCounter"             */\r
-             /****************************************/\r
-\r
-             DPRINTK("Counter not initialised\n");     \r
-             i_ReturnValue = -3;\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /*************************************************/\r
-          /* The selected module number parameter is wrong */\r
-          /*************************************************/\r
-\r
-          DPRINTK("The selected module number parameter is wrong\n");  \r
-          i_ReturnValue = -2;\r
-          }\r
-\r
-       return (i_ReturnValue);\r
-       }\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : _INT_ i_APCI1710_GetInterruptUDLatchedStatus           |\r
-|                               (BYTE_   b_BoardHandle,                      |\r
-|                                BYTE_   b_ModulNbr,                         |\r
-|                                PBYTE_ pb_UDStatus)                         |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Return the counter progress latched status after a     |\r
-|                     index interrupt occur.                                 |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : BYTE_ b_BoardHandle     : Handle of board APCI-1710    |\r
-|                     BYTE_ b_ModulNbr        : Module number to configure   |\r
-|                                               (0 to 3)                     |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : PBYTE_ pb_UDStatus      : 0 : Counter progress in the  |\r
-|                                                   selected mode down       |\r
-|                                               1 : Counter progress in the  |\r
-|                                                   selected mode up         |\r
-|                                               2 : No index interrupt occur |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      :  0: No error                                           |\r
-|                     -1: The handle parameter of the board is wrong         |\r
-|                     -2: No counter module found                            |\r
-|                     -3: Counter not initialised see function               |\r
-|                         "i_APCI1710_InitCounter"                           |\r
-|                     -4: Interrupt function not initialised.                |\r
-|                         See function "i_APCI1710_SetBoardIntRoutineX"      |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-INT   i_APCI1710_GetInterruptUDLatchedStatus  (comedi_device *dev,\r
-                                                BYTE   b_ModulNbr,\r
-                                                PBYTE pb_UDStatus)\r
-       {\r
-       INT    i_ReturnValue = 0;\r
-       DWORD dw_StatusReg   = 0;\r
-       \r
-\r
-       /**************************/\r
-       /* Test the module number */\r
-       /**************************/\r
-\r
-       if (b_ModulNbr < 4)\r
-          {\r
-          /*******************************/\r
-          /* Test if counter initialised */\r
-          /*******************************/\r
-\r
-          if (devpriv->\r
-              s_ModuleInfo [b_ModulNbr].\r
-              s_SiemensCounterInfo.\r
-              s_InitFlag.\r
-              b_CounterInit == 1)\r
-             {\r
-                /*********************************/\r
-                /* Test if index interrupt occur */\r
-                /*********************************/\r
-\r
-                if (devpriv->\r
-                    s_ModuleInfo [b_ModulNbr].\r
-                    s_SiemensCounterInfo.\r
-                    s_InitFlag.\r
-                    b_IndexInterruptOccur == 1)\r
-                   {\r
-                   devpriv->\r
-                   s_ModuleInfo [b_ModulNbr].\r
-                   s_SiemensCounterInfo.\r
-                   s_InitFlag.\r
-                   b_IndexInterruptOccur = 0;\r
-\r
-                       dw_StatusReg=inl(devpriv->s_BoardInfos.\r
-                           ui_Address + 12 + (64 * b_ModulNbr));\r
-\r
-                   *pb_UDStatus = (BYTE) ((dw_StatusReg >> 1) & 1);\r
-                   }\r
-                else\r
-                   {\r
-                   /****************************/\r
-                   /* No index interrupt occur */\r
-                   /****************************/\r
-\r
-                   *pb_UDStatus = 2;\r
-                   }\r
-             }\r
-          else\r
-             {\r
-             /****************************************/\r
-             /* Counter not initialised see function */\r
-             /* "i_APCI1710_InitCounter"             */\r
-             /****************************************/\r
-\r
-             DPRINTK("Counter not initialised\n");     \r
-             i_ReturnValue = -3;\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /*************************************************/\r
-          /* The selected module number parameter is wrong */\r
-          /*************************************************/\r
-\r
-          DPRINTK("The selected module number parameter is wrong\n");  \r
-          i_ReturnValue = -2;\r
-          }\r
-\r
-       return (i_ReturnValue);\r
-       }\r
-\r
-\r
-       /*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : _INT_ i_APCI1710_ReadFrequencyMeasurement              |\r
-|                              (BYTE_            b_BoardHandle,             |\r
-|                               BYTE_            b_ModulNbr,                |\r
-|                               PBYTE_          pb_Status,                  |\r
-|                               PULONG_        pul_ReadValue)               |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Returns the status (pb_Status) and the number of       |\r
-|                    increments in the set time.                            |\r
-|                    See function " i_APCI1710_InitFrequencyMeasurement "   |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : BYTE_  b_BoardHandle    : Handle of board APCI-1710    |\r
-|                    BYTE_  b_ModulNbr       : Number of the module to be   |\r
-|                                              configured (0 to 3)          |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : PBYTE_   pb_Status     : Returns the frequency        |\r
-|                                              measurement status           |\r
-|                                              0 : Counting cycle not       |\r
-|                                                  started.                 |\r
-|                                              1 : Counting cycle started.  |\r
-|                                              2 : Counting cycle stopped.  |\r
-|                                                  The measurement cycle is |\r
-|                                                  completed.               |\r
-|                    PBYTE_ pb_UDStatus      : 0 : Counter progress in the  |\r
-|                                                   selected mode down       |\r
-|                                               1 : Counter progress in the  |\r
-|                                                   selected mode up         |\r
-|                    PULONG_ pul_ReadValue   : Return the number of         |\r
-|                                              increments in the defined    |\r
-|                                              time base.                   |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      :  0: No error                                           |\r
-|                     -1: The handle parameter of the board is wrong         |\r
-|                     -2: The selected module number is wrong                |\r
-|                     -3: Counter not initialised see function               |\r
-|                        "i_APCI1710_InitCounter"                           |\r
-|                     -4: Frequency measurement logic not initialised.       |\r
-|                        See function "i_APCI1710_InitFrequencyMeasurement" |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-INT    i_APCI1710_ReadFrequencyMeasurement (comedi_device *dev,\r
-                                            BYTE        b_ModulNbr,\r
-                                            PBYTE       pb_Status,\r
-                                            PBYTE       pb_UDStatus,\r
-                                            PULONG      pul_ReadValue)\r
-       {\r
-       INT    i_ReturnValue = 0;\r
-       UINT  ui_16BitValue;\r
-       DWORD dw_StatusReg;\r
-       \r
-\r
-\r
-       /**************************/\r
-       /* Test the module number */\r
-       /**************************/\r
-\r
-       if (b_ModulNbr < 4)\r
-          {\r
-          /*******************************/\r
-          /* Test if counter initialised */\r
-          /*******************************/\r
-\r
-          if (devpriv->\r
-              s_ModuleInfo [b_ModulNbr].\r
-              s_SiemensCounterInfo.\r
-              s_InitFlag.\r
-              b_CounterInit == 1)\r
-             {\r
-             /********************************************/\r
-             /* Test if frequency mesurement initialised */\r
-             /********************************************/\r
-\r
-             if (devpriv->\r
-                 s_ModuleInfo [b_ModulNbr].\r
-                 s_SiemensCounterInfo.\r
-                 s_InitFlag.\r
-                 b_FrequencyMeasurementInit == 1)\r
-                {\r
-                /******************/\r
-                /* Test if enable */\r
-                /******************/\r
-\r
-                if (devpriv->\r
-                    s_ModuleInfo [b_ModulNbr].\r
-                    s_SiemensCounterInfo.\r
-                    s_InitFlag.\r
-                    b_FrequencyMeasurementEnable == 1)\r
-                   {\r
-                   /*******************/\r
-                   /* Read the status */\r
-                   /*******************/\r
-\r
-                        dw_StatusReg=inl(devpriv->s_BoardInfos.\r
-                          ui_Address + 32 + (64 * b_ModulNbr));\r
-\r
-                   /**************************/\r
-                   /* Test if frequency stop */\r
-                   /**************************/\r
-\r
-                   if (dw_StatusReg & 1)\r
-                      {\r
-                      *pb_Status   = 2;\r
-                      *pb_UDStatus = (BYTE) ((dw_StatusReg >> 1) & 3);\r
-\r
-                      /******************/\r
-                      /* Read the value */\r
-                      /******************/\r
-\r
-                          *pul_ReadValue=inl(devpriv->s_BoardInfos.\r
-                             ui_Address + 28 + (64 * b_ModulNbr));\r
-                                                    \r
-\r
-                      if (*pb_UDStatus == 0)\r
-                         {\r
-                         /*************************/\r
-                         /* Test the counter mode */\r
-                         /*************************/\r
-\r
-                         if ((devpriv->\r
-                              s_ModuleInfo [b_ModulNbr].\r
-                              s_SiemensCounterInfo.\r
-                              s_ModeRegister.\r
-                              s_ByteModeRegister.\r
-                              b_ModeRegister1 & APCI1710_16BIT_COUNTER) == APCI1710_16BIT_COUNTER)\r
-                            {\r
-                            /****************************************/\r
-                            /* Test if 16-bit counter 1 pulse occur */\r
-                            /****************************************/\r
-\r
-                            if ((*pul_ReadValue & 0xFFFFU) != 0)\r
-                               {\r
-                               ui_16BitValue  = (UINT) *pul_ReadValue & 0xFFFFU;\r
-                               *pul_ReadValue = (*pul_ReadValue & 0xFFFF0000UL) | (0xFFFFU - ui_16BitValue);\r
-                               }\r
-\r
-                            /****************************************/\r
-                            /* Test if 16-bit counter 2 pulse occur */\r
-                            /****************************************/\r
-\r
-                            if ((*pul_ReadValue & 0xFFFF0000UL) != 0)\r
-                               {\r
-                               ui_16BitValue  = (UINT) ((*pul_ReadValue >> 16) & 0xFFFFU);\r
-                               *pul_ReadValue = (*pul_ReadValue & 0xFFFFUL) | ((0xFFFFU - ui_16BitValue) << 16);\r
-                               }\r
-                            }\r
-                         else\r
-                            {\r
-                            if (*pul_ReadValue != 0)\r
-                               {\r
-                               *pul_ReadValue = 0xFFFFFFFFUL - *pul_ReadValue;\r
-                               }\r
-                            }\r
-                         }\r
-                      else\r
-                         {\r
-                         if (*pb_UDStatus == 1)\r
-                            {\r
-                            /****************************************/\r
-                            /* Test if 16-bit counter 2 pulse occur */\r
-                            /****************************************/\r
-\r
-                            if ((*pul_ReadValue & 0xFFFF0000UL) != 0)\r
-                               {\r
-                               ui_16BitValue  = (UINT) ((*pul_ReadValue >> 16) & 0xFFFFU);\r
-                               *pul_ReadValue = (*pul_ReadValue & 0xFFFFUL) | ((0xFFFFU - ui_16BitValue) << 16);\r
-                               }\r
-                            }\r
-                         else\r
-                            {\r
-                            if (*pb_UDStatus == 2)\r
-                               {\r
-                               /****************************************/\r
-                               /* Test if 16-bit counter 1 pulse occur */\r
-                               /****************************************/\r
-\r
-                               if ((*pul_ReadValue & 0xFFFFU) != 0)\r
-                                  {\r
-                                  ui_16BitValue  = (UINT) *pul_ReadValue & 0xFFFFU;\r
-                                  *pul_ReadValue = (*pul_ReadValue & 0xFFFF0000UL) | (0xFFFFU - ui_16BitValue);\r
-                                  }\r
-                               }\r
-                            }\r
-                         }\r
-                      }\r
-                   else\r
-                      {\r
-                      *pb_Status   = 1;\r
-                      *pb_UDStatus = 0;\r
-                      }\r
-                   }\r
-                else\r
-                   {\r
-                   *pb_Status   = 0;\r
-                   *pb_UDStatus = 0;\r
-                   }\r
-                }\r
-             else\r
-                {\r
-                /***********************************************/\r
-                /* Frequency measurement logic not initialised */\r
-                /***********************************************/\r
-\r
-                DPRINTK("Frequency measurement logic not initialised\n");\r
-                i_ReturnValue = -4;\r
-                }\r
-             }\r
-          else\r
-             {\r
-             /****************************************/\r
-             /* Counter not initialised see function */\r
-             /* "i_APCI1710_InitCounter"             */\r
-             /****************************************/\r
-\r
-             DPRINTK("Counter not initialised\n");     \r
-             i_ReturnValue = -3;\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /*************************************************/\r
-          /* The selected module number parameter is wrong */\r
-          /*************************************************/\r
-\r
-          DPRINTK("The selected module number parameter is wrong\n");\r
-          i_ReturnValue = -2;\r
-          }\r
-\r
-       return (i_ReturnValue);\r
-       }\r
+/**
+@verbatim
+
+Copyright (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 USA
+
+You 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 : INC_CPT.C       | Version  : 2.96                       |
+  +-------------------------------+---------------------------------------+
+  | Project manager: Eric Stolz   | Date     :  02/12/2002                |
+  +-----------------------------------------------------------------------+
+  | Description :   APCI-1710 incremental counter module                  |
+  |                                                                       |
+  |                                                                       |
+  +-----------------------------------------------------------------------+
+  |                             UPDATES                                   |
+  +-----------------------------------------------------------------------+
+  |   Date   |   Author  |          Description of updates                |
+  +----------+-----------+------------------------------------------------+
+  |          |           |                                                |
+  |----------|-----------|------------------------------------------------|
+  | 08/05/00 | Guinot C  | - 0400/0228 All Function in RING 0             |
+  |          |           |   available                                    |
+  +-----------------------------------------------------------------------+
+  | 29/06/01 | Guinot C. | - 1100/0231 -> 0701/0232                       |
+  |          |           | See i_APCI1710_DisableFrequencyMeasurement     |
+  +-----------------------------------------------------------------------+
+*/
+
+/*
++----------------------------------------------------------------------------+
+|                               Included files                               |
++----------------------------------------------------------------------------+
+*/
+
+
+#include "APCI1710_INCCPT.h"
+
+/*
++----------------------------------------------------------------------------+
+| INT  i_APCI1710_InsnConfigINCCPT(comedi_device *dev,comedi_subdevice *s,
+comedi_insn *insn,lsampl_t *data)
+
++----------------------------------------------------------------------------+
+| Task              : Configuration function for INC_CPT                             |
++----------------------------------------------------------------------------+
+| Input Parameters  :                                                                                                           |      
++----------------------------------------------------------------------------+
+| Output Parameters : *data
++----------------------------------------------------------------------------+
+| Return Value      :                 |
++----------------------------------------------------------------------------+
+*/
+
+
+INT    i_APCI1710_InsnConfigINCCPT(comedi_device *dev,comedi_subdevice *s,
+comedi_insn *insn,lsampl_t *data)
+{ 
+       UINT  ui_ConfigType; 
+       INT    i_ReturnValue = 0;
+       ui_ConfigType=CR_CHAN(insn->chanspec);
+       
+       printk ("\nINC_CPT");
+
+       devpriv->tsk_Current=current; // Save the current process task structure
+       switch(ui_ConfigType)
+       {
+       case    APCI1710_INCCPT_INITCOUNTER     :                               
+                       i_ReturnValue =i_APCI1710_InitCounter (dev,
+                                       CR_AREF(insn->chanspec),
+                                       (BYTE) data[0],
+                                       (BYTE) data[1],
+                                       (BYTE) data[2],
+                                       (BYTE) data[3],
+                                       (BYTE) data[4]);
+                       break;
+
+       case    APCI1710_INCCPT_COUNTERAUTOTEST:
+                       i_ReturnValue =i_APCI1710_CounterAutoTest (dev,
+                                       (PBYTE)   &data[0]);
+                       break;
+
+       case    APCI1710_INCCPT_INITINDEX:
+                       i_ReturnValue =i_APCI1710_InitIndex    (dev,
+                                       CR_AREF(insn->chanspec),
+                                       (BYTE) data[0],
+                                       (BYTE) data[1],
+                                       (BYTE) data[2],
+                                       (BYTE) data[3]);
+                       break;
+
+       case    APCI1710_INCCPT_INITREFERENCE:
+                       i_ReturnValue =i_APCI1710_InitReference  (dev,
+                                       CR_AREF(insn->chanspec),
+                                       (BYTE) data[0]);
+                       break;
+
+       case    APCI1710_INCCPT_INITEXTERNALSTROBE:             
+                       i_ReturnValue =i_APCI1710_InitExternalStrobe    (dev,
+                                       CR_AREF(insn->chanspec),
+                                       (BYTE) data[0],
+                                       (BYTE) data[1]);
+                       break;
+
+       case    APCI1710_INCCPT_INITCOMPARELOGIC:
+                       i_ReturnValue =i_APCI1710_InitCompareLogic     (dev,
+                                       CR_AREF(insn->chanspec),
+                                       (UINT) data[0]);
+                       break;
+
+       case    APCI1710_INCCPT_INITFREQUENCYMEASUREMENT:
+                       i_ReturnValue =i_APCI1710_InitFrequencyMeasurement      (dev,
+                                       CR_AREF(insn->chanspec),
+                                       (BYTE) data[0],
+                                       (BYTE) data[1],
+                                       (ULONG) data[2],
+                                       (PULONG) &data[0]);
+                       break;
+
+    default: 
+                   printk("Insn Config : Config Parameter Wrong\n");
+
+       }
+
+    if(i_ReturnValue>=0) i_ReturnValue =insn->n;
+       return (i_ReturnValue);
+}
+
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     : _INT_ i_APCI1710_InitCounter                           |
+|                               (BYTE_          b_BoardHandle,               |
+|                                BYTE_          b_ModulNbr,                  |
+|                                BYTE_          b_CounterRange,              |
+|                                BYTE_          b_FirstCounterModus,         |
+|                                BYTE_          b_FirstCounterOption,        |
+|                                BYTE_          b_SecondCounterModus,        |
+|                                BYTE_          b_SecondCounterOption)       |
++----------------------------------------------------------------------------+
+| Task              : Configure the counter operating mode from selected     |
+|                     module (b_ModulNbr). You must calling this function be |
+|                     for you call any other function witch access of        |
+|                     counters.                                              |
+|                                                                            |
+|                          Counter range                                     |
+|                          -------------                                     |
+| +------------------------------------+-----------------------------------+ |
+| | Parameter       Passed value       |        Description                | |
+| |------------------------------------+-----------------------------------| |
+| |b_ModulNbr   APCI1710_16BIT_COUNTER |  The module is configured for     | |
+| |                                    |  two 16-bit counter.              | |
+| |                                    |  - b_FirstCounterModus and        | |
+| |                                    |    b_FirstCounterOption           | |
+| |                                    |    configure the first 16 bit     | |
+| |                                    |    counter.                       | |
+| |                                    |  - b_SecondCounterModus and       | |
+| |                                    |    b_SecondCounterOption          | |
+| |                                    |    configure the second 16 bit    | |
+| |                                    |    counter.                       | |
+| |------------------------------------+-----------------------------------| |
+| |b_ModulNbr   APCI1710_32BIT_COUNTER |  The module is configured for one | |
+| |                                    |  32-bit counter.                  | |
+| |                                    |  - b_FirstCounterModus and        | |
+| |                                    |    b_FirstCounterOption           | |
+| |                                    |    configure the 32 bit counter.  | |
+| |                                    |  - b_SecondCounterModus and       | |
+| |                                    |    b_SecondCounterOption          | |
+| |                                    |    are not used and have no       | |
+| |                                    |    importance.                    | |
+| +------------------------------------+-----------------------------------+ |
+|                                                                            |
+|                      Counter operating mode                                |
+|                      ----------------------                                |
+|                                                                            |
+| +--------------------+-------------------------+-------------------------+ |
+| |    Parameter       |     Passed value        |    Description          | |
+| |--------------------+-------------------------+-------------------------| |
+| |b_FirstCounterModus | APCI1710_QUADRUPLE_MODE | In the quadruple mode,  | |
+| |       or           |                         | the edge analysis       | |
+| |b_SecondCounterModus|                         | circuit generates a     | |
+| |                    |                         | counting pulse from     | |
+| |                    |                         | each edge of 2 signals  | |
+| |                    |                         | which are phase shifted | |
+| |                    |                         | in relation to each     | |
+| |                    |                         | other.                  | |
+| |--------------------+-------------------------+-------------------------| |
+| |b_FirstCounterModus |   APCI1710_DOUBLE_MODE  | Functions in the same   | |
+| |       or           |                         | way as the quadruple    | |
+| |b_SecondCounterModus|                         | mode, except that only  | |
+| |                    |                         | two of the four edges   | |
+| |                    |                         | are analysed per        | |
+| |                    |                         | period                  | |
+| |--------------------+-------------------------+-------------------------| |
+| |b_FirstCounterModus |   APCI1710_SIMPLE_MODE  | Functions in the same   | |
+| |       or           |                         | way as the quadruple    | |
+| |b_SecondCounterModus|                         | mode, except that only  | |
+| |                    |                         | one of the four edges   | |
+| |                    |                         | is analysed per         | |
+| |                    |                         | period.                 | |
+| |--------------------+-------------------------+-------------------------| |
+| |b_FirstCounterModus |   APCI1710_DIRECT_MODE  | In the direct mode the  | |
+| |       or           |                         | both edge analysis      | |
+| |b_SecondCounterModus|                         | circuits are inactive.  | |
+| |                    |                         | The inputs A, B in the  | |
+| |                    |                         | 32-bit mode or A, B and | |
+| |                    |                         | C, D in the 16-bit mode | |
+| |                    |                         | represent, each, one    | |
+| |                    |                         | clock pulse gate circuit| |
+| |                    |                         | There by frequency and  | |
+| |                    |                         | pulse duration          | |
+| |                    |                         | measurements can be     | |
+| |                    |                         | performed.              | |
+| +--------------------+-------------------------+-------------------------+ |
+|                                                                            |
+|                                                                            |
+|       IMPORTANT!                                                           |
+|       If you have configured the module for two 16-bit counter, a mixed    |
+|       mode with a counter in quadruple/double/single mode                  |
+|       and the other counter in direct mode is not possible!                |
+|                                                                            |
+|                                                                            |
+|         Counter operating option for quadruple/double/simple mode          |
+|         ---------------------------------------------------------          |
+|                                                                            |
+| +----------------------+-------------------------+------------------------+|
+| |       Parameter      |     Passed value        |  Description           ||
+| |----------------------+-------------------------+------------------------||
+| |b_FirstCounterOption  | APCI1710_HYSTERESIS_ON  | In both edge analysis  ||
+| |        or            |                         | circuits is available  ||
+| |b_SecondCounterOption |                         | one hysteresis circuit.||
+| |                      |                         | It suppresses each     ||
+| |                      |                         | time the first counting||
+| |                      |                         | pulse after a change   ||
+| |                      |                         | of rotation.           ||
+| |----------------------+-------------------------+------------------------||
+| |b_FirstCounterOption  | APCI1710_HYSTERESIS_OFF | The first counting     ||
+| |       or             |                         | pulse is not suppress  ||
+| |b_SecondCounterOption |                         | after a change of      ||
+| |                      |                         | rotation.              ||
+| +----------------------+-------------------------+------------------------+|
+|                                                                            |
+|                                                                            |
+|       IMPORTANT!                                                           |
+|       This option are only avaible if you have selected the direct mode.   |
+|                                                                            |
+|                                                                            |
+|               Counter operating option for direct mode                     |
+|               ----------------------------------------                     |
+|                                                                            |
+| +----------------------+--------------------+----------------------------+ |
+| |      Parameter       |     Passed value   |       Description          | |
+| |----------------------+--------------------+----------------------------| |
+| |b_FirstCounterOption  | APCI1710_INCREMENT | The counter increment for  | |
+| |       or             |                    | each counting pulse        | |
+| |b_SecondCounterOption |                    |                            | |
+| |----------------------+--------------------+----------------------------| |
+| |b_FirstCounterOption  | APCI1710_DECREMENT | The counter decrement for  | |
+| |       or             |                    | each counting pulse        | |
+| |b_SecondCounterOption |                    |                            | |
+| +----------------------+--------------------+----------------------------+ |
+|                                                                            |
++----------------------------------------------------------------------------+
+| Input Parameters  : BYTE_ b_BoardHandle         : Handle of board APCI-1710|
+|                     BYTE_ b_ModulNbr            : Module number to         |
+|                                                   configure (0 to 3)       |
+|                     BYTE_ b_CounterRange        : Selection form counter   |
+|                                                   range.                   |
+|                     BYTE_ b_FirstCounterModus   : First counter operating  |
+|                                                   mode.                    |
+|                     BYTE_ b_FirstCounterOption  : First counter  option.   |
+|                     BYTE_ b_SecondCounterModus  : Second counter operating |
+|                                                   mode.                    |
+|                     BYTE_ b_SecondCounterOption : Second counter  option.  |
++----------------------------------------------------------------------------+
+| Output Parameters : -                                                      |
++----------------------------------------------------------------------------+
+| Return Value      : 0: No error                                            |
+|                    -1: The handle parameter of the board is wrong          |
+|                    -2: The module is not a counter module                  |
+|                    -3: The selected counter range is wrong.                |
+|                    -4: The selected first counter operating mode is wrong. |
+|                    -5: The selected first counter operating option is wrong|
+|                    -6: The selected second counter operating mode is wrong.|
+|                    -7: The selected second counter operating option is     |
+|                        wrong.                                              |
++----------------------------------------------------------------------------+
+*/
+
+
+
+
+
+INT   i_APCI1710_InitCounter (comedi_device *dev,
+                               BYTE          b_ModulNbr,
+                               BYTE          b_CounterRange,
+                               BYTE          b_FirstCounterModus,
+                               BYTE          b_FirstCounterOption,
+                               BYTE          b_SecondCounterModus,
+                               BYTE          b_SecondCounterOption)
+       {
+       INT    i_ReturnValue = 0;
+               
+       /*******************************/
+       /* Test if incremental counter */
+       /*******************************/
+
+       if ((devpriv->s_BoardInfos.
+            dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_INCREMENTAL_COUNTER)
+          {
+          /**************************/
+          /* Test the counter range */
+          /**************************/
+
+          if (b_CounterRange == APCI1710_16BIT_COUNTER || b_CounterRange == APCI1710_32BIT_COUNTER)
+             {
+             /********************************/
+             /* Test the first counter modus */
+             /********************************/
+
+             if (b_FirstCounterModus == APCI1710_QUADRUPLE_MODE ||
+                 b_FirstCounterModus == APCI1710_DOUBLE_MODE    ||
+                 b_FirstCounterModus == APCI1710_SIMPLE_MODE    ||
+                 b_FirstCounterModus == APCI1710_DIRECT_MODE)
+                {
+                /*********************************/
+                /* Test the first counter option */
+                /*********************************/
+
+                if ((b_FirstCounterModus   == APCI1710_DIRECT_MODE   &&
+                     (b_FirstCounterOption == APCI1710_INCREMENT     ||
+                      b_FirstCounterOption == APCI1710_DECREMENT))   ||
+                    (b_FirstCounterModus   != APCI1710_DIRECT_MODE   &&
+                     (b_FirstCounterOption == APCI1710_HYSTERESIS_ON ||
+                      b_FirstCounterOption == APCI1710_HYSTERESIS_OFF)))
+                   {
+                   /**************************/
+                   /* Test if 16-bit counter */
+                   /**************************/
+
+                   if (b_CounterRange == APCI1710_16BIT_COUNTER)
+                      {
+                      /*********************************/
+                      /* Test the second counter modus */
+                      /*********************************/
+
+                      if ((b_FirstCounterModus != APCI1710_DIRECT_MODE      &&
+                           (b_SecondCounterModus == APCI1710_QUADRUPLE_MODE ||
+                            b_SecondCounterModus == APCI1710_DOUBLE_MODE    ||
+                            b_SecondCounterModus == APCI1710_SIMPLE_MODE))  ||
+                          (b_FirstCounterModus == APCI1710_DIRECT_MODE &&
+                           b_SecondCounterModus == APCI1710_DIRECT_MODE))
+                         {
+                         /**********************************/
+                         /* Test the second counter option */
+                         /**********************************/
+
+                         if ((b_SecondCounterModus   == APCI1710_DIRECT_MODE   &&
+                              (b_SecondCounterOption == APCI1710_INCREMENT     ||
+                               b_SecondCounterOption == APCI1710_DECREMENT))   ||
+                             (b_SecondCounterModus   != APCI1710_DIRECT_MODE   &&
+                              (b_SecondCounterOption == APCI1710_HYSTERESIS_ON ||
+                               b_SecondCounterOption == APCI1710_HYSTERESIS_OFF)))
+                            {
+                            i_ReturnValue = 0;
+                            }
+                         else
+                            {
+                            /*********************************************************/
+                            /* The selected second counter operating option is wrong */
+                            /*********************************************************/
+
+                        DPRINTK("The selected second counter operating option is wrong\n");
+                            i_ReturnValue = -7;
+                            }
+                         }
+                      else
+                         {
+                         /*******************************************************/
+                         /* The selected second counter operating mode is wrong */
+                         /*******************************************************/
+
+                         DPRINTK("The selected second counter operating mode is wrong\n");
+                         i_ReturnValue = -6;
+                         }
+                      }
+                   }
+                else
+                   {
+                   /********************************************************/
+                   /* The selected first counter operating option is wrong */
+                   /********************************************************/
+
+                   DPRINTK("The selected first counter operating option is wrong\n");
+                   i_ReturnValue = -5;
+                   }
+                }
+             else
+                {
+                /******************************************************/
+                /* The selected first counter operating mode is wrong */
+                /******************************************************/
+                 DPRINTK("The selected first counter operating mode is wrong\n");
+                i_ReturnValue = -4;
+                }
+             }
+          else
+             {
+             /***************************************/
+             /* The selected counter range is wrong */
+             /***************************************/
+
+             DPRINTK("The selected counter range is wrong\n");
+             i_ReturnValue = -3;
+             }
+
+          /*************************/
+          /* Test if a error occur */
+          /*************************/
+
+          if (i_ReturnValue == 0)
+             {
+             /**************************/
+             /* Test if 16-Bit counter */
+             /**************************/
+
+             if (b_CounterRange == APCI1710_32BIT_COUNTER)
+                {
+                devpriv->
+                s_ModuleInfo [b_ModulNbr].
+                s_SiemensCounterInfo.
+                s_ModeRegister.
+                s_ByteModeRegister.
+                b_ModeRegister1 = b_CounterRange      |
+                                  b_FirstCounterModus |
+                                  b_FirstCounterOption;
+                }
+             else
+                {
+                devpriv->
+                s_ModuleInfo [b_ModulNbr].
+                s_SiemensCounterInfo.
+                s_ModeRegister.
+                s_ByteModeRegister.
+                b_ModeRegister1 = b_CounterRange                 |
+                                  (b_FirstCounterModus   & 0x5)  |
+                                  (b_FirstCounterOption  & 0x20) |
+                                  (b_SecondCounterModus  & 0xA)  |
+                                  (b_SecondCounterOption & 0x40);
+
+                /***********************/
+                /* Test if direct mode */
+                /***********************/
+
+                if (b_FirstCounterModus == APCI1710_DIRECT_MODE)
+                   {
+                   devpriv->
+                   s_ModuleInfo [b_ModulNbr].
+                   s_SiemensCounterInfo.
+                   s_ModeRegister.
+                   s_ByteModeRegister.
+                   b_ModeRegister1 = devpriv->
+                                     s_ModuleInfo [b_ModulNbr].
+                                     s_SiemensCounterInfo.
+                                     s_ModeRegister.
+                                     s_ByteModeRegister.
+                                     b_ModeRegister1 | APCI1710_DIRECT_MODE;
+                   }
+                }
+
+             /***************************/
+             /* Write the configuration */
+             /***************************/
+
+          
+                 outl(devpriv->s_ModuleInfo [b_ModulNbr].
+                     s_SiemensCounterInfo.
+                     s_ModeRegister.
+                     dw_ModeRegister1_2_3_4,
+                         devpriv->s_BoardInfos.
+                     ui_Address + 20 + (64 * b_ModulNbr));
+
+
+             devpriv->
+             s_ModuleInfo [b_ModulNbr].
+             s_SiemensCounterInfo.
+             s_InitFlag.
+             b_CounterInit = 1;
+             }
+          }
+       else
+          {
+          /**************************************/
+          /* The module is not a counter module */
+          /**************************************/
+
+          DPRINTK("The module is not a counter module\n");
+          i_ReturnValue = -2;
+          }
+
+       return (i_ReturnValue);
+       }
+
+
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     : _INT_ i_APCI1710_CounterAutoTest                       |
+|                                               (BYTE_     b_BoardHandle,    |
+|                                                PBYTE_   pb_TestStatus)     |
++----------------------------------------------------------------------------+
+| Task              : A test mode is intended for testing the component and  |
+|                     the connected periphery. All the 8-bit counter chains  |
+|                     are operated internally as down counters.              |
+|                     Independently from the external signals,               |
+|                     all the four 8-bit counter chains are decremented in   |
+|                     parallel by each negative clock pulse edge of CLKX.    |
+|                                                                            |
+|                       Counter auto test conclusion                         |
+|                       ----------------------------                         |
+|              +-----------------+-----------------------------+             |
+|              | pb_TestStatus   |    Error description        |             |
+|              |     mask        |                             |             |
+|              |-----------------+-----------------------------|             |
+|              |    0000         |     No error detected       |             |
+|              |-----------------|-----------------------------|             |
+|              |    0001         | Error detected of counter 0 |             |
+|              |-----------------|-----------------------------|             |
+|              |    0010         | Error detected of counter 1 |             |
+|              |-----------------|-----------------------------|             |
+|              |    0100         | Error detected of counter 2 |             |
+|              |-----------------|-----------------------------|             |
+|              |    1000         | Error detected of counter 3 |             |
+|              +-----------------+-----------------------------+             |
++----------------------------------------------------------------------------+
+| Input Parameters  : BYTE_   b_BoardHandle : Handle of board APCI-1710      |  |
++----------------------------------------------------------------------------+
+| Output Parameters : PBYTE_ pb_TestStatus  : Auto test conclusion. See table|
++----------------------------------------------------------------------------+
+| Return Value      :  0: No error                                           |
+|                     -1: The handle parameter of the board is wrong         |
+|                     -2: No counter module found                            |
++----------------------------------------------------------------------------+
+*/
+
+INT  i_APCI1710_CounterAutoTest  (comedi_device *dev,PBYTE   pb_TestStatus)
+       {
+       BYTE   b_ModulCpt    = 0;
+       INT    i_ReturnValue = 0;
+       DWORD dw_LathchValue;
+       
+       
+       *pb_TestStatus = 0;
+
+       /********************************/
+       /* Test if counter module found */
+       /********************************/
+
+       if ((devpriv->
+            s_BoardInfos.
+            dw_MolduleConfiguration [0] & 0xFFFF0000UL) == APCI1710_INCREMENTAL_COUNTER ||
+           (devpriv->
+            s_BoardInfos.
+            dw_MolduleConfiguration [1] & 0xFFFF0000UL) == APCI1710_INCREMENTAL_COUNTER ||
+           (devpriv->
+            s_BoardInfos.
+            dw_MolduleConfiguration [2] & 0xFFFF0000UL) == APCI1710_INCREMENTAL_COUNTER||
+           (devpriv->
+            s_BoardInfos.
+            dw_MolduleConfiguration [3] & 0xFFFF0000UL) == APCI1710_INCREMENTAL_COUNTER)
+          {
+          for (b_ModulCpt = 0; b_ModulCpt < 4 ; b_ModulCpt ++)
+             {
+             /*******************************/
+             /* Test if incremental counter */
+             /*******************************/
+
+             if ((devpriv->
+                  s_BoardInfos.
+                  dw_MolduleConfiguration [b_ModulCpt] & 0xFFFF0000UL) == APCI1710_INCREMENTAL_COUNTER)
+                {
+                /******************/
+                /* Start the test */
+                /******************/
+
+                
+                       outl(3,devpriv->s_BoardInfos.
+                        ui_Address + 16 + (64 * b_ModulCpt));
+
+                /*********************/
+                /* Tatch the counter */
+                /*********************/
+
+                
+                       outl(1,devpriv->s_BoardInfos.
+                        ui_Address + (64 * b_ModulCpt));
+
+                /************************/
+                /* Read the latch value */
+                /************************/
+
+               
+                       dw_LathchValue=inl(devpriv->s_BoardInfos.
+                       ui_Address + 4 + (64 * b_ModulCpt));
+
+                if ((dw_LathchValue & 0xFF) != ((dw_LathchValue >> 8)  & 0xFF) &&
+                    (dw_LathchValue & 0xFF) != ((dw_LathchValue >> 16) & 0xFF) &&
+                    (dw_LathchValue & 0xFF) != ((dw_LathchValue >> 24) & 0xFF))
+                   {
+                   *pb_TestStatus = *pb_TestStatus | (1 << b_ModulCpt);
+                   }
+
+                /*****************/
+                /* Stop the test */
+                /*****************/
+
+                
+                outl(0,devpriv->s_BoardInfos.
+                        ui_Address + 16 + (64 * b_ModulCpt));
+                }
+             }
+          }
+       else
+          {
+          /***************************/
+          /* No counter module found */
+          /***************************/
+
+          DPRINTK("No counter module found\n");
+          i_ReturnValue = -2;
+          }
+
+       return (i_ReturnValue);
+       }
+
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     : _INT_ i_APCI1710_InitIndex (BYTE_ b_BoardHandle,       |
+|                                                 BYTE_ b_ModulNbr,          |
+|                                                 BYTE_ b_ReferenceAction,   |
+|                                                 BYTE_ b_IndexOperation,    |
+|                                                 BYTE_ b_AutoMode,          |
+|                                                 BYTE_ b_InterruptEnable)   |
++----------------------------------------------------------------------------+
+| Task              : Initialise the index corresponding to the selected     |
+|                     module (b_ModulNbr). If a INDEX flag occur, you have   |
+|                     the possibility to clear the 32-Bit counter or to latch|
+|                     the current 32-Bit value in to the first latch         |
+|                     register. The b_IndexOperation parameter give the      |
+|                     possibility to choice the INDEX action.                |
+|                     If you have enabled the automatic mode, each INDEX     |
+|                     action is cleared automatically, else you must read    |
+|                     the index status ("i_APCI1710_ReadIndexStatus")        |
+|                     after each INDEX action.                               |
+|                                                                            |
+|                                                                            |
+|                               Index action                                 |
+|                               ------------                                 |
+|                                                                            |
+|           +------------------------+------------------------------------+  |
+|           |   b_IndexOperation     |         Operation                  |  |
+|           |------------------------+------------------------------------|  |
+|           |APCI1710_LATCH_COUNTER  | After a index signal, the counter  |  |
+|           |                        | value (32-Bit) is latched in to    |  |
+|           |                        | the first latch register           |  |
+|           |------------------------|------------------------------------|  |
+|           |APCI1710_CLEAR_COUNTER  | After a index signal, the counter  |  |
+|           |                        | value is cleared (32-Bit)          |  |
+|           +------------------------+------------------------------------+  |
++----------------------------------------------------------------------------+
+| Input Parameters  : BYTE_ b_BoardHandle     : Handle of board APCI-1710    |
+|                     BYTE_ b_ModulNbr        : Module number to configure   |
+|                                               (0 to 3)                     |
+|                     BYTE_ b_ReferenceAction : Determine if the reference   |
+|                                               must set or no for the       |
+|                                               acceptance from index        |
+|                                               APCI1710_ENABLE :            |
+|                                                  Reference must be set for |
+|                                                  accepted the index        |
+|                                               APCI1710_DISABLE :           |
+|                                                  Reference have not        |
+|                                                  importance                |
+|                     BYTE_ b_IndexOperation  : Index operating mode.        |
+|                                               See table.                   |
+|                     BYTE_ b_AutoMode        : Enable or disable the        |
+|                                               automatic index reset.       |
+|                                               APCI1710_ENABLE :            |
+|                                                 Enable the automatic mode  |
+|                                               APCI1710_DISABLE :           |
+|                                                 Disable the automatic mode |
+|                     BYTE_ b_InterruptEnable : Enable or disable the        |
+|                                               interrupt.                   |
+|                                               APCI1710_ENABLE :            |
+|                                               Enable the interrupt         |
+|                                               APCI1710_DISABLE :           |
+|                                               Disable the interrupt        |
++----------------------------------------------------------------------------+
+| Output Parameters : -                                                      |
++----------------------------------------------------------------------------+
+| Return Value      :  0: No error                                           |
+|                     -1: The handle parameter of the board is wrong         |
+|                     -2: No counter module found                            |
+|                     -3: Counter not initialised see function               |
+|                         "i_APCI1710_InitCounter"                           |
+|                     -4  The reference action parameter is wrong            |
+|                     -5: The index operating mode parameter is wrong        |
+|                     -6: The auto mode parameter is wrong                   |
+|                     -7: Interrupt parameter is wrong                       |
+|                     -8: Interrupt function not initialised.                |
+|                         See function "i_APCI1710_SetBoardIntRoutineX"      |
++----------------------------------------------------------------------------+
+*/
+
+INT   i_APCI1710_InitIndex    (comedi_device *dev,
+                                BYTE b_ModulNbr,
+                                BYTE b_ReferenceAction,
+                                BYTE b_IndexOperation,
+                                BYTE b_AutoMode,
+                                BYTE b_InterruptEnable)
+       {
+       INT  i_ReturnValue = 0;
+       
+
+       /**************************/
+       /* Test the module number */
+       /**************************/
+
+       if (b_ModulNbr < 4)
+          {
+          /*******************************/
+          /* Test if counter initialised */
+          /*******************************/
+
+          if (devpriv->
+              s_ModuleInfo [b_ModulNbr].
+              s_SiemensCounterInfo.
+              s_InitFlag.
+              b_CounterInit == 1)
+             {
+             /********************************/
+             /* Test the reference parameter */
+             /********************************/
+
+             if (b_ReferenceAction == APCI1710_ENABLE ||
+                 b_ReferenceAction == APCI1710_DISABLE)
+                {
+                /****************************/
+                /* Test the index parameter */
+                /****************************/
+
+                if (b_IndexOperation == APCI1710_HIGH_EDGE_LATCH_COUNTER           ||
+                    b_IndexOperation == APCI1710_LOW_EDGE_LATCH_COUNTER            ||
+                    b_IndexOperation == APCI1710_HIGH_EDGE_CLEAR_COUNTER           ||
+                    b_IndexOperation == APCI1710_LOW_EDGE_CLEAR_COUNTER            ||
+                    b_IndexOperation == APCI1710_HIGH_EDGE_LATCH_AND_CLEAR_COUNTER ||
+                    b_IndexOperation == APCI1710_LOW_EDGE_LATCH_AND_CLEAR_COUNTER)
+                   {
+                   /********************************/
+                   /* Test the auto mode parameter */
+                   /********************************/
+
+                   if (b_AutoMode == APCI1710_ENABLE ||
+                       b_AutoMode == APCI1710_DISABLE)
+                      {
+                      /***************************/
+                      /* Test the interrupt mode */
+                      /***************************/
+
+                      if (b_InterruptEnable == APCI1710_ENABLE ||
+                          b_InterruptEnable == APCI1710_DISABLE)
+                         {
+                        
+                            /************************************/
+                            /* Makte the configuration commando */
+                            /************************************/
+
+                            if (b_ReferenceAction == APCI1710_ENABLE)
+                               {
+                               devpriv->
+                               s_ModuleInfo [b_ModulNbr].
+                               s_SiemensCounterInfo.
+                               s_ModeRegister.
+                               s_ByteModeRegister.
+                               b_ModeRegister2 = devpriv->
+                                                 s_ModuleInfo [b_ModulNbr].
+                                                 s_SiemensCounterInfo.
+                                                 s_ModeRegister.
+                                                 s_ByteModeRegister.
+                                                 b_ModeRegister2 | APCI1710_ENABLE_INDEX_ACTION;
+                               }
+                            else
+                               {
+                               devpriv->
+                               s_ModuleInfo [b_ModulNbr].
+                               s_SiemensCounterInfo.
+                               s_ModeRegister.
+                               s_ByteModeRegister.
+                               b_ModeRegister2 = devpriv->
+                                                 s_ModuleInfo [b_ModulNbr].
+                                                 s_SiemensCounterInfo.
+                                                 s_ModeRegister.
+                                                 s_ByteModeRegister.
+                                                 b_ModeRegister2 & APCI1710_DISABLE_INDEX_ACTION;
+                               }
+
+                            /****************************************/
+                            /* Test if low level latch or/and clear */
+                            /****************************************/
+
+                            if (b_IndexOperation == APCI1710_LOW_EDGE_LATCH_COUNTER ||
+                                b_IndexOperation == APCI1710_LOW_EDGE_CLEAR_COUNTER ||
+                                b_IndexOperation == APCI1710_LOW_EDGE_LATCH_AND_CLEAR_COUNTER)
+                               {
+                               /*************************************/
+                               /* Set the index level to low (DQ26) */
+                               /*************************************/
+
+                               devpriv->
+                               s_ModuleInfo [b_ModulNbr].
+                               s_SiemensCounterInfo.
+                               s_ModeRegister.
+                               s_ByteModeRegister.
+                               b_ModeRegister4 = devpriv->
+                                                 s_ModuleInfo [b_ModulNbr].
+                                                 s_SiemensCounterInfo.
+                                                 s_ModeRegister.
+                                                 s_ByteModeRegister.
+                                                 b_ModeRegister4 | APCI1710_SET_LOW_INDEX_LEVEL;
+                               }
+                            else
+                               {
+                               /**************************************/
+                               /* Set the index level to high (DQ26) */
+                               /**************************************/
+
+                               devpriv->
+                               s_ModuleInfo [b_ModulNbr].
+                               s_SiemensCounterInfo.
+                               s_ModeRegister.
+                               s_ByteModeRegister.
+                               b_ModeRegister4 = devpriv->
+                                                 s_ModuleInfo [b_ModulNbr].
+                                                 s_SiemensCounterInfo.
+                                                 s_ModeRegister.
+                                                 s_ByteModeRegister.
+                                                 b_ModeRegister4 & APCI1710_SET_HIGH_INDEX_LEVEL;
+                               }
+
+                            /***********************************/
+                            /* Test if latch and clear counter */
+                            /***********************************/
+
+                            if (b_IndexOperation == APCI1710_HIGH_EDGE_LATCH_AND_CLEAR_COUNTER ||
+                                b_IndexOperation == APCI1710_LOW_EDGE_LATCH_AND_CLEAR_COUNTER)
+                               {
+                               /***************************************/
+                               /* Set the latch and clear flag (DQ27) */
+                               /***************************************/
+
+                               devpriv->
+                               s_ModuleInfo [b_ModulNbr].
+                               s_SiemensCounterInfo.
+                               s_ModeRegister.
+                               s_ByteModeRegister.
+                               b_ModeRegister4 = devpriv->
+                                                 s_ModuleInfo [b_ModulNbr].
+                                                 s_SiemensCounterInfo.
+                                                 s_ModeRegister.
+                                                 s_ByteModeRegister.
+                                                 b_ModeRegister4 | APCI1710_ENABLE_LATCH_AND_CLEAR;
+                               } // if (b_IndexOperation == APCI1710_HIGH_EDGE_LATCH_AND_CLEAR_COUNTER || b_IndexOperation == APCI1710_LOW_EDGE_LATCH_AND_CLEAR_COUNTER)
+                            else
+                               {
+                               /*****************************************/
+                               /* Clear the latch and clear flag (DQ27) */
+                               /*****************************************/
+
+                               devpriv->
+                               s_ModuleInfo [b_ModulNbr].
+                               s_SiemensCounterInfo.
+                               s_ModeRegister.
+                               s_ByteModeRegister.
+                               b_ModeRegister4 = devpriv->
+                                                 s_ModuleInfo [b_ModulNbr].
+                                                 s_SiemensCounterInfo.
+                                                 s_ModeRegister.
+                                                 s_ByteModeRegister.
+                                                 b_ModeRegister4 & APCI1710_DISABLE_LATCH_AND_CLEAR;
+
+                               /*************************/
+                               /* Test if latch counter */
+                               /*************************/
+
+                               if (b_IndexOperation == APCI1710_HIGH_EDGE_LATCH_COUNTER ||
+                                   b_IndexOperation == APCI1710_LOW_EDGE_LATCH_COUNTER)
+                                  {
+                                  /*********************************/
+                                  /* Enable the latch from counter */
+                                  /*********************************/
+
+                                  devpriv->
+                                  s_ModuleInfo [b_ModulNbr].
+                                  s_SiemensCounterInfo.
+                                  s_ModeRegister.
+                                  s_ByteModeRegister.
+                                  b_ModeRegister2 = devpriv->
+                                                    s_ModuleInfo [b_ModulNbr].
+                                                    s_SiemensCounterInfo.
+                                                    s_ModeRegister.
+                                                    s_ByteModeRegister.
+                                                    b_ModeRegister2 | APCI1710_INDEX_LATCH_COUNTER;
+                                  }
+                               else
+                                  {
+                                  /*********************************/
+                                  /* Enable the clear from counter */
+                                  /*********************************/
+
+                                  devpriv->
+                                  s_ModuleInfo [b_ModulNbr].
+                                  s_SiemensCounterInfo.
+                                  s_ModeRegister.
+                                  s_ByteModeRegister.
+                                  b_ModeRegister2 = devpriv->
+                                                    s_ModuleInfo [b_ModulNbr].
+                                                    s_SiemensCounterInfo.
+                                                    s_ModeRegister.
+                                                    s_ByteModeRegister.
+                                                    b_ModeRegister2 & (~APCI1710_INDEX_LATCH_COUNTER);
+                                  }
+                               } // // if (b_IndexOperation == APCI1710_HIGH_EDGE_LATCH_AND_CLEAR_COUNTER || b_IndexOperation == APCI1710_LOW_EDGE_LATCH_AND_CLEAR_COUNTER)
+
+
+                            if (b_AutoMode == APCI1710_DISABLE)
+                               {
+                               devpriv->
+                               s_ModuleInfo [b_ModulNbr].
+                               s_SiemensCounterInfo.
+                               s_ModeRegister.
+                               s_ByteModeRegister.
+                               b_ModeRegister2 = devpriv->
+                                                 s_ModuleInfo [b_ModulNbr].
+                                                 s_SiemensCounterInfo.
+                                                 s_ModeRegister.
+                                                 s_ByteModeRegister.
+                                                 b_ModeRegister2 | APCI1710_INDEX_AUTO_MODE;
+                               }
+                            else
+                               {
+                               devpriv->
+                               s_ModuleInfo [b_ModulNbr].
+                               s_SiemensCounterInfo.
+                               s_ModeRegister.
+                               s_ByteModeRegister.
+                               b_ModeRegister2 = devpriv->
+                                                 s_ModuleInfo [b_ModulNbr].
+                                                 s_SiemensCounterInfo.
+                                                 s_ModeRegister.
+                                                 s_ByteModeRegister.
+                                                 b_ModeRegister2 & (~APCI1710_INDEX_AUTO_MODE);
+                               }
+
+                            if (b_InterruptEnable == APCI1710_ENABLE)
+                               {
+                               devpriv->
+                               s_ModuleInfo [b_ModulNbr].
+                               s_SiemensCounterInfo.
+                               s_ModeRegister.
+                               s_ByteModeRegister.
+                               b_ModeRegister3 = devpriv->
+                                                 s_ModuleInfo [b_ModulNbr].
+                                                 s_SiemensCounterInfo.
+                                                 s_ModeRegister.
+                                                 s_ByteModeRegister.
+                                                 b_ModeRegister3 | APCI1710_ENABLE_INDEX_INT;
+                               }
+                            else
+                               {
+                               devpriv->
+                               s_ModuleInfo [b_ModulNbr].
+                               s_SiemensCounterInfo.
+                               s_ModeRegister.
+                               s_ByteModeRegister.
+                               b_ModeRegister3 = devpriv->
+                                                 s_ModuleInfo [b_ModulNbr].
+                                                 s_SiemensCounterInfo.
+                                                 s_ModeRegister.
+                                                 s_ByteModeRegister.
+                                                 b_ModeRegister3 & APCI1710_DISABLE_INDEX_INT;
+                               }
+
+                            devpriv->
+                            s_ModuleInfo [b_ModulNbr].
+                            s_SiemensCounterInfo.
+                            s_InitFlag.
+                            b_IndexInit = 1;
+                           
+                         }
+                      else
+                         {
+                         /********************************/
+                         /* Interrupt parameter is wrong */
+                         /********************************/
+                         DPRINTK("Interrupt parameter is wrong\n");    
+                         i_ReturnValue = -7;
+                         }
+                      }
+                   else
+                      {
+                      /************************************/
+                      /* The auto mode parameter is wrong */
+                      /************************************/
+
+                          DPRINTK("The auto mode parameter is wrong\n");
+                      i_ReturnValue = -6;
+                      }
+                   }
+                else
+                   {
+                   /***********************************************/
+                   /* The index operating mode parameter is wrong */
+                   /***********************************************/
+
+                   DPRINTK("The index operating mode parameter is wrong\n");
+                   i_ReturnValue = -5;
+                   }
+                }
+             else
+                {
+                /*******************************************/
+                /* The reference action parameter is wrong */
+                /*******************************************/
+
+                DPRINTK("The reference action parameter is wrong\n");
+                i_ReturnValue = -4;
+                }
+             }
+          else
+             {
+             /****************************************/
+             /* Counter not initialised see function */
+             /* "i_APCI1710_InitCounter"             */
+             /****************************************/
+
+             DPRINTK("Counter not initialised\n");     
+             i_ReturnValue = -3;
+             }
+          }
+       else
+          {
+          /*************************************************/
+          /* The selected module number parameter is wrong */
+          /*************************************************/
+
+          DPRINTK("The selected module number parameter is wrong\n");
+          i_ReturnValue = -2;
+          }
+
+       return (i_ReturnValue);
+       }
+
+
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     : _INT_ i_APCI1710_InitReference                         |
+|                                                (BYTE_ b_BoardHandle,       |
+|                                                 BYTE_ b_ModulNbr,          |
+|                                                 BYTE_ b_ReferenceLevel)    |
++----------------------------------------------------------------------------+
+| Task              : Initialise the reference corresponding to the selected |
+|                     module (b_ModulNbr).                                   |
+|                                                                            |
+|                               Reference level                              |
+|                               ---------------                              |
+|             +--------------------+-------------------------+               |
+|             | b_ReferenceLevel   |         Operation       |               |
+|             +--------------------+-------------------------+               |
+|             |   APCI1710_LOW     |  Reference occur if "0" |               |
+|             |--------------------|-------------------------|               |
+|             |   APCI1710_HIGH    |  Reference occur if "1" |               |
+|             +--------------------+-------------------------+               |
++----------------------------------------------------------------------------+
+| Input Parameters  : BYTE_ b_BoardHandle     : Handle of board APCI-1710    |
+|                     BYTE_ b_ModulNbr        : Module number to configure   |
+|                                               (0 to 3)                     |
+|                     BYTE_ b_ReferenceLevel  : Reference level.             |
++----------------------------------------------------------------------------+
+| Output Parameters : -                                                      |
++----------------------------------------------------------------------------+
+| Return Value      :  0: No error                                           |
+|                     -1: The handle parameter of the board is wrong         |
+|                     -2: The selected module number parameter is wrong      |
+|                     -3: Counter not initialised see function               |
+|                         "i_APCI1710_InitCounter"                           |
+|                     -4: Reference level parameter is wrong                 |
++----------------------------------------------------------------------------+
+*/
+
+INT   i_APCI1710_InitReference        (comedi_device *dev,
+                                        BYTE b_ModulNbr,
+                                        BYTE b_ReferenceLevel)
+       {
+       INT i_ReturnValue = 0;
+       
+       /**************************/
+       /* Test the module number */
+       /**************************/
+
+       if (b_ModulNbr < 4)
+          {
+          /*******************************/
+          /* Test if counter initialised */
+          /*******************************/
+
+          if (devpriv->
+              s_ModuleInfo [b_ModulNbr].
+              s_SiemensCounterInfo.
+              s_InitFlag.
+              b_CounterInit == 1)
+             {
+             /**************************************/
+             /* Test the reference level parameter */
+             /**************************************/
+
+             if (b_ReferenceLevel == 0 ||
+                 b_ReferenceLevel == 1)
+                {
+                if (b_ReferenceLevel == 1)
+                   {
+                   devpriv->
+                   s_ModuleInfo [b_ModulNbr].
+                   s_SiemensCounterInfo.
+                   s_ModeRegister.
+                   s_ByteModeRegister.
+                   b_ModeRegister2 = devpriv->
+                                     s_ModuleInfo [b_ModulNbr].
+                                     s_SiemensCounterInfo.
+                                     s_ModeRegister.
+                                     s_ByteModeRegister.
+                                     b_ModeRegister2 | APCI1710_REFERENCE_HIGH;
+                   }
+                else
+                   {
+                   devpriv->
+                   s_ModuleInfo [b_ModulNbr].
+                   s_SiemensCounterInfo.
+                   s_ModeRegister.
+                   s_ByteModeRegister.
+                   b_ModeRegister2 = devpriv->
+                                     s_ModuleInfo [b_ModulNbr].
+                                     s_SiemensCounterInfo.
+                                     s_ModeRegister.
+                                     s_ByteModeRegister.
+                                     b_ModeRegister2 & APCI1710_REFERENCE_LOW;
+                   }
+
+                
+                outl(devpriv->s_ModuleInfo [b_ModulNbr].
+                        s_SiemensCounterInfo.
+                        s_ModeRegister.
+                        dw_ModeRegister1_2_3_4,devpriv->s_BoardInfos.
+                        ui_Address + 20 + (64 * b_ModulNbr));
+
+
+                devpriv->
+                s_ModuleInfo [b_ModulNbr].
+                s_SiemensCounterInfo.
+                s_InitFlag.
+                b_ReferenceInit = 1;
+                }
+             else
+                {
+                /**************************************/
+                /* Reference level parameter is wrong */
+                /**************************************/
+
+                DPRINTK("Reference level parameter is wrong\n");
+                i_ReturnValue = -4;
+                }
+             }
+          else
+             {
+             /****************************************/
+             /* Counter not initialised see function */
+             /* "i_APCI1710_InitCounter"             */
+             /****************************************/
+
+             DPRINTK("Counter not initialised\n");     
+             i_ReturnValue = -3;
+             }
+          }
+       else
+          {
+          /*************************************************/
+          /* The selected module number parameter is wrong */
+          /*************************************************/
+
+          DPRINTK("The selected module number parameter is wrong\n");  
+          i_ReturnValue = -2;
+          }
+
+       return (i_ReturnValue);
+       }
+
+
+
+       
+/*
++----------------------------------------------------------------------------+
+| Function Name     : _INT_    i_APCI1710_InitExternalStrobe                |
+|                                      (BYTE_ b_BoardHandle,                |
+|                                       BYTE_ b_ModulNbr,                   |
+|                                       BYTE_ b_ExternalStrobe,             |
+|                                       BYTE_ b_ExternalStrobeLevel)        |
++----------------------------------------------------------------------------+
+| Task              : Initialises the external strobe level corresponding to |
+|                    the selected module (b_ModulNbr).                      |
++----------------------------------------------------------------------------+
+| Input Parameters  : BYTE_ b_BoardHandle     : Handle of board APCI-1710    |
+|                     BYTE_ b_ModulNbr        : Module number to configure   |
+|                                               (0 to 3)                     |
+|                    BYTE_ b_ExternalStrobe  : External strobe selection    |
+|                                              0 : External strobe A        |
+|                                              1 : External strobe B        |
+|                    BYTE_ b_ExternalStrobeLevel : External strobe level    |
+|                                              APCI1710_LOW :               |
+|                                              External latch occurs if "0" |
+|                                              APCI1710_HIGH :              |
+|                                              External latch occurs if "1" |
++----------------------------------------------------------------------------+
+| Output Parameters : -                                                      |
++----------------------------------------------------------------------------+
+| Return Value      :  0: No error                                           |
+|                     -1: The handle parameter of the board is wrong         |
+|                     -2: The selected module number is wrong                |
+|                     -3: Counter not initialised.                           |
+|                        See function "i_APCI1710_InitCounter"              |
+|                     -4: External strobe selection is wrong                 |
+|                     -5: External strobe level parameter is wrong           |
++----------------------------------------------------------------------------+
+*/
+
+INT    i_APCI1710_InitExternalStrobe   (comedi_device *dev,
+                                        BYTE b_ModulNbr,
+                                        BYTE b_ExternalStrobe,
+                                        BYTE b_ExternalStrobeLevel)
+       {
+       INT    i_ReturnValue = 0;
+       
+       
+       /**************************/
+       /* Test the module number */
+       /**************************/
+
+       if (b_ModulNbr < 4)
+          {
+          /*******************************/
+          /* Test if counter initialised */
+          /*******************************/
+
+          if (devpriv->
+              s_ModuleInfo [b_ModulNbr].
+              s_SiemensCounterInfo.
+              s_InitFlag.
+              b_CounterInit == 1)
+             {
+             /**************************************/
+             /* Test the external strobe selection */
+              /**************************************/
+
+             if (b_ExternalStrobe == 0 || b_ExternalStrobe == 1)
+                {
+                /******************/
+                /* Test the level */
+                /******************/
+
+                if ((b_ExternalStrobeLevel == APCI1710_HIGH) ||
+                    ((b_ExternalStrobeLevel == APCI1710_LOW && (devpriv->
+                                                                s_BoardInfos.
+                                                                dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) >= 0x3135)))
+                   {
+                   /*****************/
+                   /* Set the level */
+                   /*****************/
+
+                   devpriv->
+                   s_ModuleInfo [b_ModulNbr].
+                   s_SiemensCounterInfo.
+                   s_ModeRegister.
+                   s_ByteModeRegister.
+                   b_ModeRegister4 = (devpriv->
+                                      s_ModuleInfo [b_ModulNbr].
+                                      s_SiemensCounterInfo.
+                                      s_ModeRegister.
+                                      s_ByteModeRegister.
+                                      b_ModeRegister4 & (0xFF - (0x10 << b_ExternalStrobe))) |
+                                      ((b_ExternalStrobeLevel^1) << (4 + b_ExternalStrobe));
+                   }
+                else
+                   {
+                   /********************************************/
+                   /* External strobe level parameter is wrong */
+                   /********************************************/
+
+                       DPRINTK("External strobe level parameter is wrong\n");
+                   i_ReturnValue = -5;
+                   }
+                } // if (b_ExternalStrobe == 0 || b_ExternalStrobe == 1)
+             else
+                {
+                /**************************************/
+                /* External strobe selection is wrong */
+                /**************************************/
+
+                DPRINTK("External strobe selection is wrong\n");
+                i_ReturnValue = -4;
+                } // if (b_ExternalStrobe == 0 || b_ExternalStrobe == 1)
+             }
+          else
+             {
+             /****************************************/
+             /* Counter not initialised see function */
+             /* "i_APCI1710_InitCounter"             */
+             /****************************************/
+
+             DPRINTK("Counter not initialised\n");     
+             i_ReturnValue = -3;
+             }
+          }
+       else
+          {
+          /*************************************************/
+          /* The selected module number parameter is wrong */
+          /*************************************************/
+
+          DPRINTK("The selected module number parameter is wrong\n");  
+          i_ReturnValue = -2;
+          }
+
+       return (i_ReturnValue);
+       }
+
+
+       /*
++----------------------------------------------------------------------------+
+| Function Name     : _INT_ i_APCI1710_InitCompareLogic                      |
+|                               (BYTE_   b_BoardHandle,                      |
+|                                BYTE_   b_ModulNbr,                         |
+|                                UINT_  ui_CompareValue)                     |
++----------------------------------------------------------------------------+
+| Task              : Set the 32-Bit compare value. At that moment that the  |
+|                     incremental counter arrive to the compare value        |
+|                     (ui_CompareValue) a interrupt is generated.            |
++----------------------------------------------------------------------------+
+| Input Parameters  : BYTE_  b_BoardHandle    : Handle of board APCI-1710    |
+|                     BYTE_  b_ModulNbr       : Module number to configure   |
+|                                               (0 to 3)                     |
+|                     UINT_ ui_CompareValue   : 32-Bit compare value         |
++----------------------------------------------------------------------------+
+| Output Parameters : -
++----------------------------------------------------------------------------+
+| Return Value      :  0: No error                                           |
+|                     -1: The handle parameter of the board is wrong         |
+|                     -2: No counter module found                            |
+|                     -3: Counter not initialised see function               |
+|                         "i_APCI1710_InitCounter"                           |
++----------------------------------------------------------------------------+
+*/
+
+INT   i_APCI1710_InitCompareLogic     (comedi_device *dev,
+                                        BYTE   b_ModulNbr,
+                                        UINT  ui_CompareValue)
+       {
+       INT    i_ReturnValue = 0;
+       
+
+       /**************************/
+       /* Test the module number */
+       /**************************/
+
+       if (b_ModulNbr < 4)
+          {
+          /*******************************/
+          /* Test if counter initialised */
+          /*******************************/
+
+          if (devpriv->
+              s_ModuleInfo [b_ModulNbr].
+              s_SiemensCounterInfo.
+              s_InitFlag.
+              b_CounterInit == 1)
+             {
+             
+                  outl(ui_CompareValue,devpriv->s_BoardInfos.
+                     ui_Address + 28 + (64 * b_ModulNbr));
+
+             devpriv->
+             s_ModuleInfo [b_ModulNbr].
+             s_SiemensCounterInfo.
+             s_InitFlag.
+             b_CompareLogicInit = 1;
+             }
+          else
+             {
+             /****************************************/
+             /* Counter not initialised see function */
+             /* "i_APCI1710_InitCounter"             */
+             /****************************************/
+
+             DPRINTK("Counter not initialised\n");     
+             i_ReturnValue = -3;
+             }
+          }
+       else
+          {
+          /*************************************************/
+          /* The selected module number parameter is wrong */
+          /*************************************************/
+
+          DPRINTK("The selected module number parameter is wrong\n");  
+          i_ReturnValue = -2;
+          }
+
+       return (i_ReturnValue);
+       }
+
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     : _INT_ i_APCI1710_InitFrequencyMeasurement              |
+|                              (BYTE_           b_BoardHandle,              |
+|                               BYTE_           b_ModulNbr,                 |
+|                               BYTE_           b_PCIInputClock,            |
+|                               BYTE_           b_TimingUnity,              |
+|                               ULONG_         ul_TimingInterval,           |
+|                               PULONG_       pul_RealTimingInterval)       |
++----------------------------------------------------------------------------+
+| Task              : Sets the time for the frequency measurement.           |
+|                    Configures the selected TOR incremental counter of the |
+|                    selected module (b_ModulNbr). The ul_TimingInterval and|
+|                    ul_TimingUnity determine the time base for the         |
+|                    measurement. The pul_RealTimingInterval returns the    |
+|                    real time value. You must call up this function before |
+|                    you call up any other function which gives access to   |
+|                    the frequency measurement.                             |
++----------------------------------------------------------------------------+
+| Input Parameters  : BYTE_  b_BoardHandle    : Handle of board APCI-1710    |
+|                    BYTE_  b_ModulNbr       : Number of the module to be   |
+|                                              configured (0 to 3)          |
+|                    BYTE_  b_PCIInputClock  : Selection of the PCI bus     |
+|                                              clock                        |
+|                                              - APCI1710_30MHZ :           |
+|                                                The PC has a PCI bus clock |
+|                                                of 30 MHz                  |
+|                                              - APCI1710_33MHZ :           |
+|                                                The PC has a PCI bus clock |
+|                                                of 33 MHz                  |
+|                    BYTE_  b_TimingUnity    : Base time unit (0 to 2)      |
+|                                                0 : ns                     |
+|                                                1 : æs                     |
+|                                                2 : ms                     |
+|                    ULONG_ ul_TimingInterval: Base time value.             |
++----------------------------------------------------------------------------+
+| Output Parameters : PULONG_ pul_RealTimingInterval : Real base time value. |
++----------------------------------------------------------------------------+
+| Return Value      :  0: No error                                           |
+|                     -1: The handle parameter of the board is wrong         |
+|                     -2: The selected module number is wrong                |
+|                     -3: Counter not initialised see function               |
+|                        "i_APCI1710_InitCounter"                           |
+|                     -4: The selected PCI input clock is wrong              |
+|                     -5: Timing unity selection is wrong                    |
+|                     -6: Base timing selection is wrong                     |
+|                    -7: 40MHz quartz not on board                          |
++----------------------------------------------------------------------------+
+*/
+
+INT    i_APCI1710_InitFrequencyMeasurement     (comedi_device *dev,
+                                                BYTE            b_ModulNbr,
+                                                BYTE            b_PCIInputClock,
+                                                BYTE            b_TimingUnity,
+                                                ULONG           ul_TimingInterval,
+                                                PULONG      pul_RealTimingInterval)
+       {
+       INT    i_ReturnValue = 0;
+       ULONG ul_TimerValue  = 0;
+       double d_RealTimingInterval;
+       DWORD dw_Status      = 0;
+       
+       /**************************/
+       /* Test the module number */
+       /**************************/
+
+       if (b_ModulNbr < 4)
+          {
+          /*******************************/
+          /* Test if counter initialised */
+          /*******************************/
+
+          if (devpriv->
+              s_ModuleInfo [b_ModulNbr].
+              s_SiemensCounterInfo.
+              s_InitFlag.
+              b_CounterInit == 1)
+             {
+             /**************************/
+             /* Test the PCI bus clock */
+             /**************************/
+
+             if ((b_PCIInputClock == APCI1710_30MHZ) ||
+                 (b_PCIInputClock == APCI1710_33MHZ) ||
+                 (b_PCIInputClock == APCI1710_40MHZ))
+                {
+                /************************/
+                /* Test the timing unit */
+                /************************/
+
+                if (b_TimingUnity <= 2)
+                   {
+                   /**********************************/
+                   /* Test the base timing selection */
+                   /**********************************/
+
+                   if (((b_PCIInputClock == APCI1710_30MHZ) && (b_TimingUnity == 0) && (ul_TimingInterval >= 266) && (ul_TimingInterval <= 8738133UL)) ||
+                       ((b_PCIInputClock == APCI1710_30MHZ) && (b_TimingUnity == 1) && (ul_TimingInterval >= 1)   && (ul_TimingInterval <= 8738UL))    ||
+                       ((b_PCIInputClock == APCI1710_30MHZ) && (b_TimingUnity == 2) && (ul_TimingInterval >= 1)   && (ul_TimingInterval <= 8UL))       ||
+                       ((b_PCIInputClock == APCI1710_33MHZ) && (b_TimingUnity == 0) && (ul_TimingInterval >= 242) && (ul_TimingInterval <= 7943757UL)) ||
+                       ((b_PCIInputClock == APCI1710_33MHZ) && (b_TimingUnity == 1) && (ul_TimingInterval >= 1)   && (ul_TimingInterval <= 7943UL))    ||
+                       ((b_PCIInputClock == APCI1710_33MHZ) && (b_TimingUnity == 2) && (ul_TimingInterval >= 1)   && (ul_TimingInterval <= 7UL))       ||
+                       ((b_PCIInputClock == APCI1710_40MHZ) && (b_TimingUnity == 0) && (ul_TimingInterval >= 200) && (ul_TimingInterval <= 6553500UL)) ||
+                       ((b_PCIInputClock == APCI1710_40MHZ) && (b_TimingUnity == 1) && (ul_TimingInterval >= 1)   && (ul_TimingInterval <= 6553UL))    ||
+                       ((b_PCIInputClock == APCI1710_40MHZ) && (b_TimingUnity == 2) && (ul_TimingInterval >= 1)   && (ul_TimingInterval <= 6UL)))
+                      {
+                      /**********************/
+                      /* Test if 40MHz used */
+                      /**********************/
+
+                      if (b_PCIInputClock == APCI1710_40MHZ)
+                         {
+                         /******************************/
+                         /* Test if firmware >= Rev1.5 */
+                         /******************************/
+
+                         if ((devpriv->
+                              s_BoardInfos.
+                              dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) >= 0x3135)
+                            {
+                            /*********************************/
+                            /* Test if 40MHz quartz on board */
+                            /*********************************/
+
+                            /*INPDW (ps_APCI1710Variable->
+                                   s_Board [b_BoardHandle].
+                                   s_BoardInfos.
+                                   ui_Address + 36 + (64 * b_ModulNbr), &dw_Status);*/
+                                 dw_Status=inl(devpriv->s_BoardInfos.
+                                   ui_Address + 36 + (64 * b_ModulNbr));
+
+                            /******************************/
+                            /* Test the quartz flag (DQ0) */
+                            /******************************/
+
+                            if ((dw_Status & 1) != 1)
+                               {
+                               /*****************************/
+                               /* 40MHz quartz not on board */
+                               /*****************************/
+
+                               DPRINTK("40MHz quartz not on board\n");
+                               i_ReturnValue = -7;
+                               }
+                            }
+                         else
+                            {
+                            /*****************************/
+                            /* 40MHz quartz not on board */
+                            /*****************************/
+                                DPRINTK("40MHz quartz not on board\n");
+                            i_ReturnValue = -7;
+                            }
+                         } // if (b_PCIInputClock == APCI1710_40MHZ)
+
+                      /***************************/
+                      /* Test if not error occur */
+                      /***************************/
+
+                      if (i_ReturnValue == 0)
+                         {
+                         /****************************/
+                         /* Test the INC_CPT version */
+                         /****************************/
+
+                         if ((devpriv->s_BoardInfos.
+                              dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) >= 0x3131)
+                            {
+                           
+                               /**********************/
+                               /* Test if 40MHz used */
+                               /**********************/
+
+                               if (b_PCIInputClock == APCI1710_40MHZ)
+                                  {
+                                  /*********************************/
+                                  /* Enable the 40MHz quarz (DQ30) */
+                                  /*********************************/
+
+                                  devpriv->
+                                  s_ModuleInfo [b_ModulNbr].
+                                  s_SiemensCounterInfo.
+                                  s_ModeRegister.
+                                  s_ByteModeRegister.
+                                  b_ModeRegister4 = devpriv->
+                                                    s_ModuleInfo [b_ModulNbr].
+                                                    s_SiemensCounterInfo.
+                                                    s_ModeRegister.
+                                                    s_ByteModeRegister.
+                                                    b_ModeRegister4 | APCI1710_ENABLE_40MHZ_FREQUENCY;
+                                  } // if (b_PCIInputClock == APCI1710_40MHZ)
+                               else
+                                  {
+                                  /**********************************/
+                                  /* Disable the 40MHz quarz (DQ30) */
+                                  /**********************************/
+
+                                  devpriv->
+                                  s_ModuleInfo [b_ModulNbr].
+                                  s_SiemensCounterInfo.
+                                  s_ModeRegister.
+                                  s_ByteModeRegister.
+                                  b_ModeRegister4 = devpriv->
+                                                    s_ModuleInfo [b_ModulNbr].
+                                                    s_SiemensCounterInfo.
+                                                    s_ModeRegister.
+                                                    s_ByteModeRegister.
+                                                    b_ModeRegister4 & APCI1710_DISABLE_40MHZ_FREQUENCY;
+
+                                  } // if (b_PCIInputClock == APCI1710_40MHZ)
+                           
+
+                            /********************************/
+                            /* Calculate the division fator */
+                            /********************************/
+
+                            fpu_begin ();
+                            switch (b_TimingUnity)
+                               {
+                               /******/
+                               /* 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 */
+                                       /*****************************/
+
+                                       *pul_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) *pul_RealTimingInterval + 0.5))
+                                          {
+                                          *pul_RealTimingInterval = *pul_RealTimingInterval + 1;
+                                          }
+
+                                       ul_TimingInterval     = ul_TimingInterval - 1;
+                                       ul_TimerValue = ul_TimerValue - 2;
+                                    
+                                    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 */
+                                       /*****************************/
+
+                                       *pul_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) *pul_RealTimingInterval + 0.5))
+                                          {
+                                          *pul_RealTimingInterval = *pul_RealTimingInterval + 1;
+                                          }
+
+                                       ul_TimingInterval     = ul_TimingInterval - 1;
+                                       ul_TimerValue = ul_TimerValue - 2;
+                                    
+
+                                    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 */
+                                       /*****************************/
+
+                                       *pul_RealTimingInterval = (ULONG) (ul_TimerValue / (250.0 * (double) b_PCIInputClock));
+                                       d_RealTimingInterval    = (double) ul_TimerValue / (250.0 * (double) b_PCIInputClock);
+
+                                       if ((double) ((double) ul_TimerValue / (250.0 * (double) b_PCIInputClock)) >= (double) ((double) *pul_RealTimingInterval + 0.5))
+                                          {
+                                          *pul_RealTimingInterval = *pul_RealTimingInterval + 1;
+                                          }
+
+                                       ul_TimingInterval     = ul_TimingInterval - 1;
+                                       ul_TimerValue = ul_TimerValue - 2;
+                                    
+                                    break;
+                               }
+
+                            fpu_end ();
+                            /*************************/
+                            /* Write the timer value */
+                            /*************************/
+
+                           
+                                        outl(ul_TimerValue,devpriv->s_BoardInfos.
+                                    ui_Address + 32 + (64 * b_ModulNbr));
+
+                            /*******************************/
+                            /* Set the initialisation flag */
+                            /*******************************/
+
+                            devpriv->
+                            s_ModuleInfo [b_ModulNbr].
+                            s_SiemensCounterInfo.
+                            s_InitFlag.
+                            b_FrequencyMeasurementInit  = 1;
+                            }
+                         else
+                            {
+                            /***************************/
+                            /* Counter not initialised */
+                            /***************************/
+
+                        DPRINTK("Counter not initialised\n");  
+                            i_ReturnValue = -3;
+                            }
+                         } // if (i_ReturnValue == 0)
+                      }
+                   else
+                      {
+                      /**********************************/
+                      /* Base timing selection is wrong */
+                      /**********************************/
+
+                          DPRINTK("Base timing selection is wrong\n");  
+                      i_ReturnValue = -6;
+                      }
+                   }
+                else
+                   {
+                   /***********************************/
+                   /* Timing unity selection is wrong */
+                   /***********************************/
+
+                       DPRINTK("Timing unity selection is wrong\n");
+                   i_ReturnValue = -5;
+                   }
+                }
+             else
+                {
+                /*****************************************/
+                /* The selected PCI input clock is wrong */
+                /*****************************************/
+
+                DPRINTK("The selected PCI input clock is wrong\n");    
+                i_ReturnValue = -4;
+                }
+             }
+          else
+             {
+             /****************************************/
+             /* Counter not initialised see function */
+             /* "i_APCI1710_InitCounter"             */
+             /****************************************/
+
+             DPRINTK("Counter not initialised\n");     
+             i_ReturnValue = -3;
+             }
+          }
+       else
+          {
+          /*************************************************/
+          /* The selected module number parameter is wrong */
+          /*************************************************/
+
+          DPRINTK("The selected module number parameter is wrong\n");  
+          i_ReturnValue = -2;
+          }
+
+       return (i_ReturnValue);
+       }
+
+/*########################################################################### */
+
+                                                       //INSN BITS
+/*########################################################################### */
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     :INT       i_APCI1710_InsnBitsINCCPT(comedi_device *dev,comedi_subdevice *s,
+comedi_insn *insn,lsampl_t *data)                   |
++----------------------------------------------------------------------------+
+| Task              : Set & Clear Functions for INC_CPT                                          |
++----------------------------------------------------------------------------+
+| Input Parameters  : 
++----------------------------------------------------------------------------+
+| Output Parameters : -                                                      |
++----------------------------------------------------------------------------+
+| Return Value      : 
++----------------------------------------------------------------------------+
+*/
+
+
+INT    i_APCI1710_InsnBitsINCCPT(comedi_device *dev,comedi_subdevice *s,
+comedi_insn *insn,lsampl_t *data)
+{
+       UINT ui_BitsType;
+       INT i_ReturnValue=0;
+       ui_BitsType=CR_CHAN(insn->chanspec);
+       devpriv->tsk_Current=current; // Save the current process task structure
+
+       switch(ui_BitsType)
+       {
+       case APCI1710_INCCPT_CLEARCOUNTERVALUE:
+               i_ReturnValue=i_APCI1710_ClearCounterValue    (dev,
+                                        (BYTE) CR_AREF(insn->chanspec));
+               break;
+
+       case APCI1710_INCCPT_CLEARALLCOUNTERVALUE:
+               i_ReturnValue=i_APCI1710_ClearAllCounterValue (dev);
+               break;
+
+       case APCI1710_INCCPT_SETINPUTFILTER:
+               i_ReturnValue=i_APCI1710_SetInputFilter (dev,
+                                                                       (BYTE) CR_AREF(insn->chanspec),
+                                    (BYTE) data[0],
+                                                                       (BYTE) data[1]);
+               break;
+
+       case APCI1710_INCCPT_LATCHCOUNTER:
+               i_ReturnValue=i_APCI1710_LatchCounter (dev,
+                                (BYTE) CR_AREF(insn->chanspec),
+                                (BYTE) data[0]);
+               break;
+
+       case APCI1710_INCCPT_SETINDEXANDREFERENCESOURCE:
+               i_ReturnValue=i_APCI1710_SetIndexAndReferenceSource     (dev,
+                                                (BYTE) CR_AREF(insn->chanspec),
+                                                (BYTE) data[0]);
+               break;
+
+       case APCI1710_INCCPT_SETDIGITALCHLON:
+               i_ReturnValue=i_APCI1710_SetDigitalChlOn (dev,
+                                    (BYTE) CR_AREF(insn->chanspec));
+               break;
+
+       case APCI1710_INCCPT_SETDIGITALCHLOFF:
+               i_ReturnValue=i_APCI1710_SetDigitalChlOff (dev,
+                                    (BYTE) CR_AREF(insn->chanspec));
+               break;
+
+       default:
+               printk("Bits Config Parameter Wrong\n");
+       }
+
+       if(i_ReturnValue>=0) i_ReturnValue =insn->n;
+       return (i_ReturnValue);
+}
+
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     : _INT_ i_APCI1710_ClearCounterValue                     |
+|                               (BYTE_      b_BoardHandle,                   |
+|                                BYTE_       b_ModulNbr)                     |
++----------------------------------------------------------------------------+
+| Task              : Clear the counter value from selected module           |
+|                     (b_ModulNbr).                                          |
++----------------------------------------------------------------------------+
+| Input Parameters  : BYTE_ b_BoardHandle : Handle of board APCI-1710        |
+|                     BYTE_ b_ModulNbr    : Module number to configure       |
+|                                           (0 to 3)                         |
++----------------------------------------------------------------------------+
+| Output Parameters : -                                                      |
++----------------------------------------------------------------------------+
+| Return Value      :  0: No error                                           |
+|                     -1: The handle parameter of the board is wrong         |
+|                     -2: The selected module number parameter is wrong      |
+|                     -3: Counter not initialised see function               |
+|                         "i_APCI1710_InitCounter"                           |
++----------------------------------------------------------------------------+
+*/
+
+INT   i_APCI1710_ClearCounterValue    (comedi_device *dev,
+                                        BYTE b_ModulNbr)
+       {
+       INT i_ReturnValue = 0;
+       
+       /**************************/
+       /* Test the module number */
+       /**************************/
+
+       if (b_ModulNbr < 4)
+          {
+          /*******************************/
+          /* Test if counter initialised */
+          /*******************************/
+
+          if (devpriv->
+              s_ModuleInfo [b_ModulNbr].
+              s_SiemensCounterInfo.
+              s_InitFlag.
+              b_CounterInit == 1)
+             {
+             /*********************/
+             /* Clear the counter */
+             /*********************/
+
+             
+                  outl(1,devpriv->s_BoardInfos.
+                     ui_Address + 16 + (64 * b_ModulNbr));
+             }
+          else
+             {
+             /****************************************/
+             /* Counter not initialised see function */
+             /* "i_APCI1710_InitCounter"             */
+             /****************************************/
+
+             DPRINTK("Counter not initialised\n");             
+             i_ReturnValue = -3;
+             }
+          }
+       else
+          {
+          /*************************************************/
+          /* The selected module number parameter is wrong */
+          /*************************************************/
+
+          DPRINTK("The selected module number parameter is wrong\n");                  
+          i_ReturnValue = -2;
+          }
+
+       return (i_ReturnValue);
+       }
+
+
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     : _INT_ i_APCI1710_ClearAllCounterValue                  |
+|                               (BYTE_      b_BoardHandle)                   |
++----------------------------------------------------------------------------+
+| Task              : Clear all counter value.                               |
++----------------------------------------------------------------------------+
+| Input Parameters  : BYTE_ b_BoardHandle : Handle of board APCI-1710        |
++----------------------------------------------------------------------------+
+| Output Parameters : -                                                      |
++----------------------------------------------------------------------------+
+| Return Value      :  0: No error                                           |
+|                     -1: The handle parameter of the board is wrong         |
+|                     -2: No counter module found                            |
++----------------------------------------------------------------------------+
+*/
+
+INT   i_APCI1710_ClearAllCounterValue (comedi_device *dev)
+       {
+       BYTE   b_ModulCpt    = 0;
+       INT    i_ReturnValue = 0;
+       
+
+       /********************************/
+       /* Test if counter module found */
+       /********************************/
+
+       if ((devpriv->s_BoardInfos.
+            dw_MolduleConfiguration [0] & 0xFFFF0000UL) == APCI1710_INCREMENTAL_COUNTER ||
+           (devpriv->s_BoardInfos.
+            dw_MolduleConfiguration [1] & 0xFFFF0000UL) == APCI1710_INCREMENTAL_COUNTER ||
+           (devpriv->s_BoardInfos.
+            dw_MolduleConfiguration [2] & 0xFFFF0000UL) == APCI1710_INCREMENTAL_COUNTER ||
+           (devpriv->s_BoardInfos.
+            dw_MolduleConfiguration [3] & 0xFFFF0000UL) == APCI1710_INCREMENTAL_COUNTER)
+          {
+          for (b_ModulCpt = 0; b_ModulCpt < 4 ; b_ModulCpt ++)
+             {
+             /*******************************/
+             /* Test if incremental counter */
+             /*******************************/
+
+             if ((devpriv->s_BoardInfos.
+                  dw_MolduleConfiguration [b_ModulCpt] & 0xFFFF0000UL) == APCI1710_INCREMENTAL_COUNTER)
+                {
+                /*********************/
+                /* Clear the counter */
+                /*********************/
+
+                
+               outl(1,devpriv->s_BoardInfos.
+                        ui_Address + 16 + (64 * b_ModulCpt));
+                }
+             }
+          }
+       else
+          {
+          /***************************/
+          /* No counter module found */
+          /***************************/
+
+          DPRINTK("No counter module found\n");        
+          i_ReturnValue = -2;
+          }
+
+       return (i_ReturnValue);
+       }
+
+
+
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     : _INT_ i_APCI1710_SetInputFilter                        |
+|                                      (BYTE_ b_BoardHandle,                |
+|                                       BYTE_ b_Module,                     |
+|                                       BYTE_ b_PCIInputClock,              |
+|                                       BYTE_ b_Filter)                     |
++----------------------------------------------------------------------------+
+| Task              : Disable or enable the software filter from selected    |
+|                    module (b_ModulNbr). b_Filter determine the filter time|
++----------------------------------------------------------------------------+
+| Input Parameters  : BYTE_  b_BoardHandle    : Handle of board APCI-1710    |
+|                    BYTE_  b_ModulNbr       : Number of the module to be   |
+|                                              configured (0 to 3)          |
+|                    BYTE_  b_PCIInputClock  : Selection of the PCI bus     |
+|                                              clock                        |
+|                                              - APCI1710_30MHZ :           |
+|                                                The PC has a PCI bus clock |
+|                                                of 30 MHz                  |
+|                                              - APCI1710_33MHZ :           |
+|                                                The PC has a PCI bus clock |
+|                                                of 33 MHz                  |
+|                                              - APCI1710_40MHZ :           |
+|                                                The APCI1710 has a 40MHz    |
+|                                                quartz                     |
+|                    BYTE_  b_Filter         : Filter selection             |
+|                                                                            |
+|                              30 MHz                                       |
+|                              ------                                       |
+|                                      0:  Software filter not used         |
+|                                      1:  Filter from 266ns  (3.750000MHz) |
+|                                      2:  Filter from 400ns  (2.500000MHz) |
+|                                      3:  Filter from 533ns  (1.876170MHz) |
+|                                      4:  Filter from 666ns  (1.501501MHz) |
+|                                      5:  Filter from 800ns  (1.250000MHz) |
+|                                      6:  Filter from 933ns  (1.071800MHz) |
+|                                      7:  Filter from 1066ns (0.938080MHz) |
+|                                      8:  Filter from 1200ns (0.833333MHz) |
+|                                      9:  Filter from 1333ns (0.750000MHz) |
+|                                      10: Filter from 1466ns (0.682100MHz) |
+|                                      11: Filter from 1600ns (0.625000MHz) |
+|                                      12: Filter from 1733ns (0.577777MHz) |
+|                                      13: Filter from 1866ns (0.535900MHz) |
+|                                      14: Filter from 2000ns (0.500000MHz) |
+|                                      15: Filter from 2133ns (0.468800MHz) |
+|                                                                           |
+|                              33 MHz                                       |
+|                              ------                                       |
+|                                      0:  Software filter not used         |
+|                                      1:  Filter from 242ns  (4.125000MHz) |
+|                                      2:  Filter from 363ns  (2.754820MHz) |
+|                                      3:  Filter from 484ns  (2.066115MHz) |
+|                                      4:  Filter from 605ns  (1.652892MHz) |
+|                                      5:  Filter from 726ns  (1.357741MHz) |
+|                                      6:  Filter from 847ns  (1.180637MHz) |
+|                                      7:  Filter from 968ns  (1.033055MHz) |
+|                                      8:  Filter from 1089ns (0.918273MHz) |
+|                                      9:  Filter from 1210ns (0.826446MHz) |
+|                                      10: Filter from 1331ns (0.751314MHz) |
+|                                      11: Filter from 1452ns (0.688705MHz) |
+|                                      12: Filter from 1573ns (0.635727MHz) |
+|                                      13: Filter from 1694ns (0.590318MHz) |
+|                                      14: Filter from 1815ns (0.550964MHz) |
+|                                      15: Filter from 1936ns (0.516528MHz) |
+|                                                                           |
+|                              40 MHz                                       |
+|                              ------                                       |
+|                                      0:  Software filter not used         |
+|                                      1:  Filter from 200ns  (5.000000MHz) |
+|                                      2:  Filter from 300ns  (3.333333MHz) |
+|                                      3:  Filter from 400ns  (2.500000MHz) |
+|                                      4:  Filter from 500ns  (2.000000MHz) |
+|                                      5:  Filter from 600ns  (1.666666MHz) |
+|                                      6:  Filter from 700ns  (1.428500MHz) |
+|                                      7:  Filter from 800ns  (1.250000MHz) |
+|                                      8:  Filter from 900ns  (1.111111MHz) |
+|                                      9:  Filter from 1000ns (1.000000MHz) |
+|                                      10: Filter from 1100ns (0.909090MHz) |
+|                                      11: Filter from 1200ns (0.833333MHz) |
+|                                      12: Filter from 1300ns (0.769200MHz) |
+|                                      13: Filter from 1400ns (0.714200MHz) |
+|                                      14: Filter from 1500ns (0.666666MHz) |
+|                                      15: Filter from 1600ns (0.625000MHz) |
++----------------------------------------------------------------------------+
+| Output Parameters : -                                                      |
++----------------------------------------------------------------------------+
+| Return Value      :  0: No error                                           |
+|                     -1: The handle parameter of the board is wrong         |
+|                     -2: The selected module number is wrong                |
+|                     -3: The module is not a counter module                 |
+|                                        -4: The selected PCI input clock is wrong              |
+|                                        -5: The selected filter value is wrong                 |
+|                                        -6: 40MHz quartz not on board                          |
++----------------------------------------------------------------------------+
+*/
+
+INT    i_APCI1710_SetInputFilter       (comedi_device *dev,
+                                                                       BYTE b_ModulNbr,
+                                    BYTE b_PCIInputClock,
+                                                                       BYTE b_Filter)
+       {
+       INT    i_ReturnValue = 0;
+       DWORD dw_Status      = 0;
+       
+       /**************************/
+       /* Test the module number */
+       /**************************/
+
+       if (b_ModulNbr < 4)
+          {
+          /*******************************/
+          /* Test if incremental counter */
+          /*******************************/
+
+          if ((devpriv->s_BoardInfos.
+               dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_INCREMENTAL_COUNTER)
+             {
+             /******************************/
+             /* Test if firmware >= Rev1.5 */
+             /******************************/
+
+             if ((devpriv->s_BoardInfos.
+                  dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) >= 0x3135)
+                {
+                /**************************/
+                /* Test the PCI bus clock */
+                /**************************/
+
+                if ((b_PCIInputClock == APCI1710_30MHZ) ||
+                    (b_PCIInputClock == APCI1710_33MHZ) ||
+                    (b_PCIInputClock == APCI1710_40MHZ))
+                   {
+                   /*************************/
+                   /* Test the filter value */
+                   /*************************/
+
+                   if (b_Filter < 16)
+                      {
+                      /**********************/
+                      /* Test if 40MHz used */
+                      /**********************/
+
+                      if (b_PCIInputClock == APCI1710_40MHZ)
+                         {
+                         /*********************************/
+                         /* Test if 40MHz quartz on board */
+                         /*********************************/
+
+                        
+                       dw_Status=      inl(devpriv->s_BoardInfos.
+                                ui_Address + 36 + (64 * b_ModulNbr));
+
+                         /******************************/
+                         /* Test the quartz flag (DQ0) */
+                         /******************************/
+
+                         if ((dw_Status & 1) != 1)
+                            {
+                            /*****************************/
+                            /* 40MHz quartz not on board */
+                            /*****************************/
+
+                        DPRINTK("40MHz quartz not on board\n"); 
+                            i_ReturnValue = -6;
+                            }
+                         } // if (b_PCIInputClock == APCI1710_40MHZ)
+
+                      /***************************/
+                      /* Test if error not occur */
+                      /***************************/
+
+                      if (i_ReturnValue == 0)
+                         {
+                         /**********************/
+                         /* Test if 40MHz used */
+                         /**********************/
+
+                         if (b_PCIInputClock == APCI1710_40MHZ)
+                            {
+                            /*********************************/
+                            /* Enable the 40MHz quarz (DQ31) */
+                            /*********************************/
+
+                            devpriv->
+                            s_ModuleInfo [b_ModulNbr].
+                            s_SiemensCounterInfo.
+                            s_ModeRegister.
+                            s_ByteModeRegister.
+                            b_ModeRegister4 = devpriv->
+                                              s_ModuleInfo [b_ModulNbr].
+                                              s_SiemensCounterInfo.
+                                              s_ModeRegister.
+                                              s_ByteModeRegister.
+                                              b_ModeRegister4 | APCI1710_ENABLE_40MHZ_FILTER;
+
+                            } // if (b_PCIInputClock == APCI1710_40MHZ)
+                         else
+                            {
+                            /**********************************/
+                            /* Disable the 40MHz quarz (DQ31) */
+                            /**********************************/
+
+                            devpriv->
+                            s_ModuleInfo [b_ModulNbr].
+                            s_SiemensCounterInfo.
+                            s_ModeRegister.
+                            s_ByteModeRegister.
+                            b_ModeRegister4 = devpriv->
+                                              s_ModuleInfo [b_ModulNbr].
+                                              s_SiemensCounterInfo.
+                                              s_ModeRegister.
+                                              s_ByteModeRegister.
+                                              b_ModeRegister4 & APCI1710_DISABLE_40MHZ_FILTER;
+
+                            } // if (b_PCIInputClock == APCI1710_40MHZ)
+
+                         /************************/
+                         /* Set the filter value */
+                         /************************/
+
+                         devpriv->
+                         s_ModuleInfo [b_ModulNbr].
+                         s_SiemensCounterInfo.
+                         s_ModeRegister.
+                         s_ByteModeRegister.
+                         b_ModeRegister3 = (devpriv->s_ModuleInfo [b_ModulNbr].
+                                            s_SiemensCounterInfo.
+                                            s_ModeRegister.
+                                            s_ByteModeRegister.
+                                            b_ModeRegister3 & 0x1F) | ((b_Filter & 0x7) << 5);
+
+                         devpriv->s_ModuleInfo [b_ModulNbr].
+                         s_SiemensCounterInfo.
+                         s_ModeRegister.
+                         s_ByteModeRegister.
+                         b_ModeRegister4 = (devpriv->
+                                            s_ModuleInfo [b_ModulNbr].
+                                            s_SiemensCounterInfo.
+                                            s_ModeRegister.
+                                            s_ByteModeRegister.
+                                            b_ModeRegister4 & 0xFE) | ((b_Filter & 0x8) >> 3);
+
+                         /***************************/
+                         /* Write the configuration */
+                         /***************************/
+
+                         
+                         outl(devpriv->s_ModuleInfo [b_ModulNbr].
+                                 s_SiemensCounterInfo.
+                                 s_ModeRegister.
+                                 dw_ModeRegister1_2_3_4,devpriv->s_BoardInfos.
+                                 ui_Address + 20 + (64 * b_ModulNbr));
+                         } // if (i_ReturnValue == 0)
+                      } // if (b_Filter < 16)
+                   else
+                      {
+                      /**************************************/
+                      /* The selected filter value is wrong */
+                      /**************************************/
+
+                          DPRINTK("The selected filter value is wrong\n");      
+                      i_ReturnValue = -5;
+                      } // if (b_Filter < 16)
+                   } // if ((b_PCIInputClock == APCI1710_30MHZ) || (b_PCIInputClock == APCI1710_33MHZ) || (b_PCIInputClock == APCI1710_40MHZ))
+                else
+                   {
+                   /*****************************************/
+                   /* The selected PCI input clock is wrong */
+                   /*****************************************/
+
+                       DPRINTK("The selected PCI input clock is wrong\n");
+                   i_ReturnValue = 4;
+                   } // if ((b_PCIInputClock == APCI1710_30MHZ) || (b_PCIInputClock == APCI1710_33MHZ) || (b_PCIInputClock == APCI1710_40MHZ))
+                }
+             else
+                {
+                /**************************************/
+                /* The module is not a counter module */
+                /**************************************/
+
+                DPRINTK("The module is not a counter module\n");
+                i_ReturnValue = -3;
+                }
+             }
+          else
+             {
+             /**************************************/
+             /* The module is not a counter module */
+             /**************************************/
+
+             DPRINTK("The module is not a counter module\n");  
+             i_ReturnValue = -3;
+             }
+          }
+       else
+          {
+          /*************************************************/
+          /* The selected module number parameter is wrong */
+          /*************************************************/
+
+          DPRINTK("The selected module number parameter is wrong\n");  
+          i_ReturnValue = -2;
+          }
+
+       return (i_ReturnValue);
+       }
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     : _INT_ i_APCI1710_LatchCounter (BYTE_ b_BoardHandle,    |
+|                                                    BYTE_ b_ModulNbr,       |
+|                                                    BYTE_ b_LatchReg)       |
++----------------------------------------------------------------------------+
+| Task              : Latch the courant value from selected module           |
+|                     (b_ModulNbr) in to the selected latch register         |
+|                     (b_LatchReg).                                          |
++----------------------------------------------------------------------------+
+| Input Parameters  : BYTE_ b_BoardHandle : Handle of board APCI-1710        |
+|                     BYTE_ b_ModulNbr    : Module number to configure       |
+|                                           (0 to 3)                         |
+|                     BYTE_ b_LatchReg    : Selected latch register          |
+|                               0 : for the first latch register             |
+|                               1 : for the second latch register            |
++----------------------------------------------------------------------------+
+| Output Parameters : -                                                      |
++----------------------------------------------------------------------------+
+| Return Value      :  0: No error                                           |
+|                     -1: The handle parameter of the board is wrong         |
+|                     -2: No counter module found                            |
+|                     -3: Counter not initialised see function               |
+|                         "i_APCI1710_InitCounter"                           |
+|                     -4: The selected latch register parameter is wrong     |
++----------------------------------------------------------------------------+
+*/
+
+INT   i_APCI1710_LatchCounter (comedi_device *dev,
+                                BYTE b_ModulNbr,
+                                BYTE b_LatchReg)
+       {
+       INT i_ReturnValue = 0;
+       
+
+       /**************************/
+       /* Test the module number */
+       /**************************/
+
+       if (b_ModulNbr < 4)
+          {
+          /*******************************/
+          /* Test if counter initialised */
+          /*******************************/
+
+          if (devpriv->
+              s_ModuleInfo [b_ModulNbr].
+              s_SiemensCounterInfo.
+              s_InitFlag.
+              b_CounterInit == 1)
+             {
+             /*************************************/
+             /* Test the latch register parameter */
+             /*************************************/
+
+             if (b_LatchReg < 2)
+                {
+                /*********************/
+                /* Tatch the counter */
+                /*********************/
+
+                       outl(1 << (b_LatchReg * 4),devpriv->s_BoardInfos.
+                        ui_Address + (64 * b_ModulNbr));
+                }
+             else
+                {
+                /**************************************************/
+                /* The selected latch register parameter is wrong */
+                /**************************************************/
+
+                DPRINTK("The selected latch register parameter is wrong\n");
+                i_ReturnValue = -4;
+                }
+             }
+          else
+             {
+             /****************************************/
+             /* Counter not initialised see function */
+             /* "i_APCI1710_InitCounter"             */
+             /****************************************/
+
+             DPRINTK("Counter not initialised\n");     
+             i_ReturnValue = -3;
+             }
+          }
+       else
+          {
+          /*************************************************/
+          /* The selected module number parameter is wrong */
+          /*************************************************/
+
+          DPRINTK("The selected module number parameter is wrong\n");  
+          i_ReturnValue = -2;
+          }
+
+       return (i_ReturnValue);
+       }
+
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     : _INT_    i_APCI1710_SetIndexAndReferenceSource        |
+|                                      (BYTE_ b_BoardHandle,                |
+|                                       BYTE_ b_ModulNbr,                   |
+|                                       BYTE_ b_SourceSelection)            |
++----------------------------------------------------------------------------+
+| Task              : Determine the hardware source for the index and the    |
+|                    reference logic. Per default the index logic is        |
+|                    connected to the difference input C and the reference  |
+|                    logic is connected to the 24V input E                  |
++----------------------------------------------------------------------------+
+| Input Parameters  : BYTE_ b_BoardHandle     : Handle of board APCI-1710    |
+|                     BYTE_ b_ModulNbr        : Module number to configure   |
+|                                               (0 to 3)                     |
+|                    BYTE_ b_SourceSelection : APCI1710_SOURCE_0 :          |
+|                                              The index logic is connected |
+|                                              to the difference input C and|
+|                                              the reference logic is       |
+|                                              connected to the 24V input E.|
+|                                              This is the default          |
+|                                              configuration.               |
+|                                              APCI1710_SOURCE_1 :          |
+|                                              The reference logic is       |
+|                                              connected to the difference  |
+|                                              input C and the index logic  |
+|                                              is connected to the 24V      |
+|                                              input E                      |
++----------------------------------------------------------------------------+
+| Output Parameters : -                                                      |
++----------------------------------------------------------------------------+
+| Return Value      :  0: No error                                           |
+|                     -1: The handle parameter of the board is wrong         |
+|                    -2: The selected module number is wrong                |
+|                    -3: The module is not a counter module.                |
+|                    -4: The source selection is wrong                      |
++----------------------------------------------------------------------------+
+*/
+
+INT    i_APCI1710_SetIndexAndReferenceSource   (comedi_device *dev,
+                                                BYTE b_ModulNbr,
+                                                BYTE b_SourceSelection)
+       {
+       INT    i_ReturnValue = 0;
+       
+       
+       /**************************/
+       /* Test the module number */
+       /**************************/
+
+       if (b_ModulNbr < 4)
+          {
+          /*******************************/
+          /* Test if incremental counter */
+          /*******************************/
+
+          if ((devpriv->s_BoardInfos.
+               dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_INCREMENTAL_COUNTER)
+             {
+             /******************************/
+             /* Test if firmware >= Rev1.5 */
+             /******************************/
+
+             if ((devpriv->s_BoardInfos.
+                  dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) >= 0x3135)
+                {
+                /*****************************/
+                /* Test the source selection */
+                /*****************************/
+
+                if (b_SourceSelection == APCI1710_SOURCE_0 ||
+                    b_SourceSelection == APCI1710_SOURCE_1)
+                   {
+                   /******************************************/
+                   /* Test if invert the index and reference */
+                   /******************************************/
+
+                   if (b_SourceSelection == APCI1710_SOURCE_1)
+                      {
+                      /********************************************/
+                      /* Invert index and reference source (DQ25) */
+                      /********************************************/
+
+                      devpriv->s_ModuleInfo [b_ModulNbr].
+                      s_SiemensCounterInfo.
+                      s_ModeRegister.
+                      s_ByteModeRegister.
+                      b_ModeRegister4 = devpriv->
+                                        s_ModuleInfo [b_ModulNbr].
+                                        s_SiemensCounterInfo.
+                                        s_ModeRegister.
+                                        s_ByteModeRegister.
+                                        b_ModeRegister4 | APCI1710_INVERT_INDEX_RFERENCE;
+                      }
+                   else
+                      {
+                      /****************************************/
+                      /* Set the default configuration (DQ25) */
+                      /****************************************/
+
+                      devpriv->s_ModuleInfo [b_ModulNbr].
+                      s_SiemensCounterInfo.
+                      s_ModeRegister.
+                      s_ByteModeRegister.
+                      b_ModeRegister4 = devpriv->
+                                        s_ModuleInfo [b_ModulNbr].
+                                        s_SiemensCounterInfo.
+                                        s_ModeRegister.
+                                        s_ByteModeRegister.
+                                        b_ModeRegister4 & APCI1710_DEFAULT_INDEX_RFERENCE;
+                      }
+                   } // if (b_SourceSelection == APCI1710_SOURCE_0 ||b_SourceSelection == APCI1710_SOURCE_1)
+                else
+                   {
+                   /*********************************/
+                   /* The source selection is wrong */
+                    /*********************************/
+
+                   DPRINTK("The source selection is wrong\n");
+                   i_ReturnValue = -4;
+                   } // if (b_SourceSelection == APCI1710_SOURCE_0 ||b_SourceSelection == APCI1710_SOURCE_1)
+                }
+             else
+                {
+                /**************************************/
+                /* The module is not a counter module */
+                /**************************************/
+
+                DPRINTK("The module is not a counter module\n");       
+                i_ReturnValue = -3;
+                }
+             }
+          else
+             {
+             /**************************************/
+             /* The module is not a counter module */
+             /**************************************/
+
+             DPRINTK("The module is not a counter module\n");  
+             i_ReturnValue = -3;
+             }
+          }
+       else
+          {
+          /***************************************/
+          /* The selected module number is wrong */
+          /***************************************/
+
+          DPRINTK("The selected module number is wrong\n");    
+          i_ReturnValue = -2;
+          }
+
+       return (i_ReturnValue);
+       }
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     : _INT_    i_APCI1710_SetDigitalChlOn                   |
+|                                 (BYTE_  b_BoardHandle,                    |
+|                                  BYTE_  b_ModulNbr)                       |
++----------------------------------------------------------------------------+
+| Task              : Sets the digital output H Setting an output means      |
+|                    setting an ouput high.                                 |
++----------------------------------------------------------------------------+
+| Input Parameters  : BYTE_  b_BoardHandle    : Handle of board APCI-1710    |
+|                    BYTE_  b_ModulNbr       : Number of the module to be   |
+|                                              configured (0 to 3)          |
++----------------------------------------------------------------------------+
+| Output Parameters : -                                                      |
++----------------------------------------------------------------------------+
+| Return Value      :  0: No error                                           |
+|                     -1: The handle parameter of the board is wrong         |
+|                     -2: The selected module number is wrong                |
+|                     -3: Counter not initialised see function               |
+|                        "i_APCI1710_InitCounter"                           |
++----------------------------------------------------------------------------+
+*/
+
+INT    i_APCI1710_SetDigitalChlOn (comedi_device *dev,
+                                   BYTE  b_ModulNbr)
+       {
+       INT    i_ReturnValue = 0;
+       
+       /**************************/
+       /* Test the module number */
+       /**************************/
+
+       if (b_ModulNbr < 4)
+          {
+          /*******************************/
+          /* Test if counter initialised */
+          /*******************************/
+
+          if (devpriv->
+              s_ModuleInfo [b_ModulNbr].
+              s_SiemensCounterInfo.
+              s_InitFlag.
+              b_CounterInit == 1)
+             {
+             devpriv->
+             s_ModuleInfo [b_ModulNbr].
+             s_SiemensCounterInfo.
+             s_ModeRegister.
+             s_ByteModeRegister.
+             b_ModeRegister3 = devpriv->
+                               s_ModuleInfo [b_ModulNbr].
+                               s_SiemensCounterInfo.
+                               s_ModeRegister.
+                               s_ByteModeRegister.
+                               b_ModeRegister3 | 0x10;
+
+             /*********************/
+             /* Set the output On */
+             /*********************/
+
+                 outl(devpriv->s_ModuleInfo [b_ModulNbr].
+                     s_SiemensCounterInfo.
+                     s_ModeRegister.
+                     dw_ModeRegister1_2_3_4,devpriv->s_BoardInfos.
+                     ui_Address + 20 + (64 * b_ModulNbr));
+             }
+          else
+             {
+             /****************************************/
+             /* Counter not initialised see function */
+             /* "i_APCI1710_InitCounter"             */
+             /****************************************/
+
+             DPRINTK("Counter not initialised\n");
+             i_ReturnValue = -3;
+             }
+          }
+       else
+          {
+          /*************************************************/
+          /* The selected module number parameter is wrong */
+          /*************************************************/
+
+          DPRINTK("The selected module number parameter is wrong\n");  
+          i_ReturnValue = -2;
+          }
+
+       return (i_ReturnValue);
+       }
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     : _INT_    i_APCI1710_SetDigitalChlOff                  |
+|                                 (BYTE_  b_BoardHandle,                    |
+|                                  BYTE_  b_ModulNbr)                       |
++----------------------------------------------------------------------------+
+| Task              : Resets the digital output H. Resetting an output means |
+|                    setting an ouput low.                                  |
++----------------------------------------------------------------------------+
+| Input Parameters  : BYTE_  b_BoardHandle    : Handle of board APCI-1710    |
+|                    BYTE_  b_ModulNbr       : Number of the module to be   |
+|                                              configured (0 to 3)          |
++----------------------------------------------------------------------------+
+| Output Parameters : -                                                      |
++----------------------------------------------------------------------------+
+| Return Value      :  0: No error                                           |
+|                     -1: The handle parameter of the board is wrong         |
+|                     -2: The selected module number is wrong                |
+|                     -3: Counter not initialised see function               |
+|                        "i_APCI1710_InitCounter"                           |
++----------------------------------------------------------------------------+
+*/
+
+INT    i_APCI1710_SetDigitalChlOff (comedi_device *dev,
+                                    BYTE  b_ModulNbr)
+       {
+       INT    i_ReturnValue = 0;
+       
+       /**************************/
+       /* Test the module number */
+       /**************************/
+
+       if (b_ModulNbr < 4)
+          {
+          /*******************************/
+          /* Test if counter initialised */
+          /*******************************/
+
+          if (devpriv->
+              s_ModuleInfo [b_ModulNbr].
+              s_SiemensCounterInfo.
+              s_InitFlag.
+              b_CounterInit == 1)
+             {
+             devpriv->
+             s_ModuleInfo [b_ModulNbr].
+             s_SiemensCounterInfo.
+             s_ModeRegister.
+             s_ByteModeRegister.
+             b_ModeRegister3 = devpriv->
+                               s_ModuleInfo [b_ModulNbr].
+                               s_SiemensCounterInfo.
+                               s_ModeRegister.
+                               s_ByteModeRegister.
+                               b_ModeRegister3 & 0xEF;
+
+             /**********************/
+             /* Set the output Off */
+             /**********************/
+
+                 outl(devpriv->s_ModuleInfo [b_ModulNbr].
+                     s_SiemensCounterInfo.
+                     s_ModeRegister.
+                     dw_ModeRegister1_2_3_4,devpriv->s_BoardInfos.
+                     ui_Address + 20 + (64 * b_ModulNbr));
+             }
+          else
+             {
+             /****************************************/
+             /* Counter not initialised see function */
+             /* "i_APCI1710_InitCounter"             */
+             /****************************************/
+
+             DPRINTK("Counter not initialised\n");     
+             i_ReturnValue = -3;
+             }
+          }
+       else
+          {
+          /*************************************************/
+          /* The selected module number parameter is wrong */
+          /*************************************************/
+
+          DPRINTK("The selected module number parameter is wrong\n");  
+          i_ReturnValue = -2;
+          }
+
+       return (i_ReturnValue);
+       }
+
+
+/*########################################################################### */
+
+                                                       // INSN WRITE
+/*########################################################################### */
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     :INT       i_APCI1710_InsnWriteINCCPT(comedi_device *dev,comedi_subdevice *s,
+comedi_insn *insn,lsampl_t *data)                   |
++----------------------------------------------------------------------------+
+| Task              : Enable Disable functions for INC_CPT                                       |
++----------------------------------------------------------------------------+
+| Input Parameters  : 
++----------------------------------------------------------------------------+
+| Output Parameters : -                                                      |
++----------------------------------------------------------------------------+
+| Return Value      : 
++----------------------------------------------------------------------------+
+*/
+INT    i_APCI1710_InsnWriteINCCPT(comedi_device *dev,comedi_subdevice *s,
+comedi_insn *insn,lsampl_t *data)
+{
+       UINT ui_WriteType;
+       INT i_ReturnValue=0;
+        
+       ui_WriteType=CR_CHAN(insn->chanspec);
+       devpriv->tsk_Current=current; // Save the current process task structure
+
+       switch(ui_WriteType)
+       {
+               case APCI1710_INCCPT_ENABLELATCHINTERRUPT:
+                       i_ReturnValue = i_APCI1710_EnableLatchInterrupt (dev,
+                                        (BYTE) CR_AREF(insn->chanspec));
+               break;
+
+               case APCI1710_INCCPT_DISABLELATCHINTERRUPT:
+                       i_ReturnValue = i_APCI1710_DisableLatchInterrupt (dev,
+                                                (BYTE) CR_AREF(insn->chanspec));
+               break;
+
+               case APCI1710_INCCPT_WRITE16BITCOUNTERVALUE:
+                       i_ReturnValue = i_APCI1710_Write16BitCounterValue       (dev,
+                                                (BYTE) CR_AREF(insn->chanspec),
+                                                (BYTE)  data[0],
+                                                (UINT)  data[1]);
+               break;
+
+               case APCI1710_INCCPT_WRITE32BITCOUNTERVALUE:
+                        i_ReturnValue = i_APCI1710_Write32BitCounterValue       (dev,
+                                                (BYTE) CR_AREF(insn->chanspec),
+                                                (ULONG) data[0]);
+
+               break;
+
+               case APCI1710_INCCPT_ENABLEINDEX:
+                       i_APCI1710_EnableIndex  (dev,
+                                (BYTE) CR_AREF(insn->chanspec));
+               break;
+
+               case APCI1710_INCCPT_DISABLEINDEX:                                              
+                       i_ReturnValue = i_APCI1710_DisableIndex  (dev,
+                                (BYTE) CR_AREF(insn->chanspec));
+               break;
+
+               case APCI1710_INCCPT_ENABLECOMPARELOGIC:                                        
+                       i_ReturnValue = i_APCI1710_EnableCompareLogic   (dev,
+                                        (BYTE) CR_AREF(insn->chanspec));
+               break;
+
+               case APCI1710_INCCPT_DISABLECOMPARELOGIC:       
+                       i_ReturnValue = i_APCI1710_DisableCompareLogic  (dev,
+                                        (BYTE) CR_AREF(insn->chanspec));
+               break;
+
+               case APCI1710_INCCPT_ENABLEFREQUENCYMEASUREMENT:                        
+                       i_ReturnValue = i_APCI1710_EnableFrequencyMeasurement   (dev,
+                                                (BYTE) CR_AREF(insn->chanspec),
+                                                (BYTE)          data[0]);
+               break;
+
+               case APCI1710_INCCPT_DISABLEFREQUENCYMEASUREMENT:                                       
+                       i_ReturnValue = i_APCI1710_DisableFrequencyMeasurement  (dev,
+                                                (BYTE) CR_AREF(insn->chanspec));
+               break;
+
+               default:
+                       printk("Write Config Parameter Wrong\n");
+       }
+
+       if(i_ReturnValue>=0) i_ReturnValue =insn->n;
+       return (i_ReturnValue);
+}
+
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     : _INT_ i_APCI1710_EnableLatchInterrupt                  |
+|                               (BYTE_ b_BoardHandle,                        |
+|                                BYTE_ b_ModulNbr)                           |
++----------------------------------------------------------------------------+
+| Task              : Enable the latch interrupt from selected module        |
+|                     (b_ModulNbr). Each software or hardware latch occur a  |
+|                     interrupt.                                             |
++----------------------------------------------------------------------------+
+| Input Parameters  : BYTE_ b_BoardHandle : Handle of board APCI-1710        |
+|                     BYTE_ b_ModulNbr    : Module number to configure       |
+|                                           (0 to 3)                         |
++----------------------------------------------------------------------------+
+| Output Parameters : -                                                      |
++----------------------------------------------------------------------------+
+| Return Value      :  0: No error                                           |
+|                     -1: The handle parameter of the board is wrong         |
+|                     -2: No counter module found                            |
+|                     -3: Counter not initialised see function               |
+|                         "i_APCI1710_InitCounter"                           |
+|                     -4: Interrupt routine not installed see function       |
+|                         "i_APCI1710_SetBoardIntRoutine"                    |
++----------------------------------------------------------------------------+
+*/
+
+INT  i_APCI1710_EnableLatchInterrupt (comedi_device *dev,
+                                        BYTE b_ModulNbr)
+       {
+       INT i_ReturnValue = 0;
+       
+       /**************************/
+       /* Test the module number */
+       /**************************/
+
+       if (b_ModulNbr < 4)
+          {
+          /*******************************/
+          /* Test if counter initialised */
+          /*******************************/
+
+          if (devpriv->s_ModuleInfo [b_ModulNbr].
+              s_SiemensCounterInfo.
+              s_InitFlag.
+              b_CounterInit == 1)
+             {
+
+                /********************/
+                /* Enable interrupt */
+                /********************/
+
+                devpriv->s_ModuleInfo [b_ModulNbr].
+                s_SiemensCounterInfo.
+                s_ModeRegister.
+                s_ByteModeRegister.
+                b_ModeRegister2 = devpriv->
+                                  s_ModuleInfo [b_ModulNbr].
+                                  s_SiemensCounterInfo.
+                                  s_ModeRegister.
+                                  s_ByteModeRegister.
+                                  b_ModeRegister2 | APCI1710_ENABLE_LATCH_INT;
+
+                /***************************/
+                /* Write the configuration */
+                /***************************/
+
+                outl(devpriv->s_ModuleInfo [b_ModulNbr].
+                        s_SiemensCounterInfo.
+                        s_ModeRegister.
+                        dw_ModeRegister1_2_3_4,devpriv->s_BoardInfos.
+                        ui_Address + 20 + (64 * b_ModulNbr));
+             }
+          else
+             {
+             /****************************************/
+             /* Counter not initialised see function */
+             /* "i_APCI1710_InitCounter"             */
+             /****************************************/
+
+             DPRINTK("Counter not initialised\n");     
+             i_ReturnValue = -3;
+             }
+          }
+       else
+          {
+          /*************************************************/
+          /* The selected module number parameter is wrong */
+          /*************************************************/
+
+          DPRINTK("The selected module number parameter is wrong\n");
+          i_ReturnValue = -2;
+          }
+
+       return (i_ReturnValue);
+       }
+
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     : _INT_ i_APCI1710_DisableLatchInterrupt                 |
+|                               (BYTE_ b_BoardHandle,                        |
+|                                BYTE_ b_ModulNbr)                           |
++----------------------------------------------------------------------------+
+| Task              : Disable the latch interrupt from selected module       |
+|                     (b_ModulNbr).                                          |
++----------------------------------------------------------------------------+
+| Input Parameters  : BYTE_ b_BoardHandle : Handle of board APCI-1710        |
+|                     BYTE_ b_ModulNbr    : Module number to configure       |
+|                                           (0 to 3)                         |
++----------------------------------------------------------------------------+
+| Output Parameters : -                                                      |
++----------------------------------------------------------------------------+
+| Return Value      :  0: No error                                           |
+|                     -1: The handle parameter of the board is wrong         |
+|                     -2: No counter module found                            |
+|                     -3: Counter not initialised see function               |
+|                         "i_APCI1710_InitCounter"                           |
+|                     -4: Interrupt routine not installed see function       |
+|                         "i_APCI1710_SetBoardIntRoutine"                    |
++----------------------------------------------------------------------------+
+*/
+
+INT   i_APCI1710_DisableLatchInterrupt        (comedi_device *dev,
+                                                BYTE b_ModulNbr)
+       {
+       INT i_ReturnValue = 0;
+       
+       /**************************/
+       /* Test the module number */
+       /**************************/
+
+       if (b_ModulNbr < 4)
+          {
+          /*******************************/
+          /* Test if counter initialised */
+          /*******************************/
+
+          if (devpriv->
+              s_ModuleInfo [b_ModulNbr].
+              s_SiemensCounterInfo.
+              s_InitFlag.
+              b_CounterInit == 1)
+             {
+
+                /***************************/
+                /* Write the configuration */
+                /***************************/
+
+                  outl(devpriv->s_ModuleInfo [b_ModulNbr].
+                        s_SiemensCounterInfo.
+                        s_ModeRegister.
+                        dw_ModeRegister1_2_3_4 & ((APCI1710_DISABLE_LATCH_INT << 8) | 0xFF),devpriv->s_BoardInfos.
+                        ui_Address + 20 + (64 * b_ModulNbr));
+
+                  mdelay(1000);
+
+                /*********************/
+                /* Disable interrupt */
+                /*********************/
+
+                devpriv->
+                s_ModuleInfo [b_ModulNbr].
+                s_SiemensCounterInfo.
+                s_ModeRegister.
+                s_ByteModeRegister.
+                b_ModeRegister2 = devpriv->
+                                  s_ModuleInfo [b_ModulNbr].
+                                  s_SiemensCounterInfo.
+                                  s_ModeRegister.
+                                  s_ByteModeRegister.
+                                  b_ModeRegister2 & APCI1710_DISABLE_LATCH_INT;
+
+             }
+          else
+             {
+             /****************************************/
+             /* Counter not initialised see function */
+             /* "i_APCI1710_InitCounter"             */
+             /****************************************/
+
+             DPRINTK("Counter not initialised\n");     
+             i_ReturnValue = -3;
+             }
+          }
+       else
+          {
+          /*************************************************/
+          /* The selected module number parameter is wrong */
+          /*************************************************/
+
+          DPRINTK("The selected module number parameter is wrong\n");  
+          i_ReturnValue = -2;
+          }
+
+       return (i_ReturnValue);
+       }
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     : _INT_ i_APCI1710_Write16BitCounterValue                |
+|                                               (BYTE_  b_BoardHandle        |
+|                                                BYTE_  b_ModulNbr,          |
+|                                                BYTE_  b_SelectedCounter,   |
+|                                                UINT_ ui_WriteValue)        |
++----------------------------------------------------------------------------+
+| Task              : Write a 16-Bit value (ui_WriteValue) in to the selected|
+|                     16-Bit counter (b_SelectedCounter) from selected module|
+|                     (b_ModulNbr).                                          |
++----------------------------------------------------------------------------+
+| Input Parameters  : BYTE_ b_BoardHandle     : Handle of board APCI-1710    |
+|                     BYTE_ b_ModulNbr        : Module number to configure   |
+|                                              (0 to 3)                      |
+|                     BYTE_ b_SelectedCounter : Selected 16-Bit counter      |
+|                                               (0 or 1)                     |
+|                     UINT_ ui_WriteValue     : 16-Bit write value           |
++----------------------------------------------------------------------------+
+| Output Parameters : -                                                      |
++----------------------------------------------------------------------------+
+| Return Value      :  0: No error                                           |
+|                     -1: The handle parameter of the board is wrong         |
+|                     -2: No counter module found                            |
+|                     -3: Counter not initialised see function               |
+|                         "i_APCI1710_InitCounter"                           |
+|                     -4: The selected 16-Bit counter parameter is wrong     |
++----------------------------------------------------------------------------+
+*/
+
+INT   i_APCI1710_Write16BitCounterValue       (comedi_device *dev,
+                                                BYTE  b_ModulNbr,
+                                                BYTE  b_SelectedCounter,
+                                                UINT  ui_WriteValue)
+       {
+       INT i_ReturnValue = 0;
+       
+       
+       /**************************/
+       /* Test the module number */
+       /**************************/
+
+       if (b_ModulNbr < 4)
+          {
+          /*******************************/
+          /* Test if counter initialised */
+          /*******************************/
+
+          if (devpriv->
+              s_ModuleInfo [b_ModulNbr].
+              s_SiemensCounterInfo.
+              s_InitFlag.
+              b_CounterInit == 1)
+             {
+             /******************************/
+             /* Test the counter selection */
+             /******************************/
+
+             if (b_SelectedCounter < 2)
+                {
+                /*******************/
+                /* Write the value */
+                /*******************/
+
+               outl((ULONG) ((ULONG) (ui_WriteValue) << (16 * b_SelectedCounter)),devpriv->s_BoardInfos.
+                        ui_Address + 8 + (b_SelectedCounter * 4) + (64 * b_ModulNbr));
+                }
+             else
+                {
+                /**************************************************/
+                /* The selected 16-Bit counter parameter is wrong */
+                /**************************************************/
+
+                DPRINTK("The selected 16-Bit counter parameter is wrong\n");
+                i_ReturnValue = -4;
+                }
+             }
+          else
+             {
+             /****************************************/
+             /* Counter not initialised see function */
+             /* "i_APCI1710_InitCounter"             */
+             /****************************************/
+
+             DPRINTK("Counter not initialised\n");     
+             i_ReturnValue = -3;
+             }
+          }
+       else
+          {
+          /*************************************************/
+          /* The selected module number parameter is wrong */
+          /*************************************************/
+
+          DPRINTK("The selected module number parameter is wrong\n");
+          i_ReturnValue = -2;
+          }
+
+       return (i_ReturnValue);
+       }
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     : _INT_ i_APCI1710_Write32BitCounterValue                |
+|                                               (BYTE_   b_BoardHandle       |
+|                                                BYTE_   b_ModulNbr,         |
+|                                                ULONG_ ul_WriteValue)       |
++----------------------------------------------------------------------------+
+| Task              : Write a 32-Bit value (ui_WriteValue) in to the selected|
+|                     module (b_ModulNbr).                                   |
++----------------------------------------------------------------------------+
+| Input Parameters  : BYTE_ b_BoardHandle     : Handle of board APCI-1710    |
+|                     BYTE_ b_ModulNbr        : Module number to configure   |
+|                                              (0 to 3)                      |
+|                     ULONG_ ul_WriteValue    : 32-Bit write value           |
++----------------------------------------------------------------------------+
+| Output Parameters : -                                                      |
++----------------------------------------------------------------------------+
+| Return Value      :  0: No error                                           |
+|                     -1: The handle parameter of the board is wrong         |
+|                     -2: No counter module found                            |
+|                     -3: Counter not initialised see function               |
+|                         "i_APCI1710_InitCounter"                           |
++----------------------------------------------------------------------------+
+*/
+
+INT   i_APCI1710_Write32BitCounterValue       (comedi_device *dev,
+                                                BYTE   b_ModulNbr,
+                                                ULONG ul_WriteValue)
+       {
+       INT i_ReturnValue = 0;
+       
+       
+       /**************************/
+       /* Test the module number */
+       /**************************/
+
+       if (b_ModulNbr < 4)
+          {
+          /*******************************/
+          /* Test if counter initialised */
+          /*******************************/
+
+          if (devpriv->
+              s_ModuleInfo [b_ModulNbr].
+              s_SiemensCounterInfo.
+              s_InitFlag.
+              b_CounterInit == 1)
+             {
+             /*******************/
+             /* Write the value */
+             /*******************/
+
+                  outl(ul_WriteValue,devpriv->s_BoardInfos.
+                     ui_Address + 4 + (64 * b_ModulNbr));
+             }
+          else
+             {
+             /****************************************/
+             /* Counter not initialised see function */
+             /* "i_APCI1710_InitCounter"             */
+             /****************************************/
+
+             DPRINTK("Counter not initialised\n");     
+             i_ReturnValue = -3;
+             }
+          }
+       else
+          {
+          /*************************************************/
+          /* The selected module number parameter is wrong */
+          /*************************************************/
+
+          DPRINTK("The selected module number parameter is wrong\n");  
+          i_ReturnValue = -2;
+          }
+
+       return (i_ReturnValue);
+       }
+
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     : _INT_ i_APCI1710_EnableIndex (BYTE_  b_BoardHandle,    |
+|                                                   BYTE_  b_ModulNbr)       |
++----------------------------------------------------------------------------+
+| Task              : Enable the INDEX actions                               |
++----------------------------------------------------------------------------+
+| Input Parameters  : BYTE_ b_BoardHandle     : Handle of board APCI-1710    |
+|                     BYTE_ b_ModulNbr        : Module number to configure   |
+|                                               (0 to 3)                     |
++----------------------------------------------------------------------------+
+| Output Parameters : -                                                      |
++----------------------------------------------------------------------------+
+| Return Value      :  0: No error                                           |
+|                     -1: The handle parameter of the board is wrong         |
+|                     -2: No counter module found                            |
+|                     -3: Counter not initialised see function               |
+|                         "i_APCI1710_InitCounter"                           |
+|                     -4: Index not initialised see function                 |
+|                         "i_APCI1710_InitIndex"                             |
++----------------------------------------------------------------------------+
+*/
+
+INT   i_APCI1710_EnableIndex  (comedi_device *dev,
+                                BYTE b_ModulNbr)
+       {
+       INT    i_ReturnValue = 0;
+       ULONG ul_InterruptLatchReg;
+       
+       
+       /**************************/
+       /* Test the module number */
+       /**************************/
+
+       if (b_ModulNbr < 4)
+          {
+          /*******************************/
+          /* Test if counter initialised */
+          /*******************************/
+
+          if (devpriv->
+              s_ModuleInfo [b_ModulNbr].
+              s_SiemensCounterInfo.
+              s_InitFlag.
+              b_CounterInit == 1)
+             {
+             /*****************************/
+             /* Test if index initialised */
+             /*****************************/
+
+             if (devpriv->
+                 s_ModuleInfo [b_ModulNbr].
+                 s_SiemensCounterInfo.
+                 s_InitFlag.
+                 b_IndexInit)
+                {
+                devpriv->
+                s_ModuleInfo [b_ModulNbr].
+                s_SiemensCounterInfo.
+                s_ModeRegister.
+                s_ByteModeRegister.
+                b_ModeRegister2 = devpriv->
+                                  s_ModuleInfo [b_ModulNbr].
+                                  s_SiemensCounterInfo.
+                                  s_ModeRegister.
+                                  s_ByteModeRegister.
+                                  b_ModeRegister2 | APCI1710_ENABLE_INDEX;
+
+                 ul_InterruptLatchReg=inl(devpriv->s_BoardInfos.
+                       ui_Address + 24 + (64 * b_ModulNbr));
+
+
+                 outl(devpriv->s_ModuleInfo [b_ModulNbr].
+                        s_SiemensCounterInfo.
+                        s_ModeRegister.
+                        dw_ModeRegister1_2_3_4,devpriv->s_BoardInfos.
+                        ui_Address + 20 + (64 * b_ModulNbr));
+                }
+             else
+                {
+                /*************************************************************/
+                /* Index not initialised see function "i_APCI1710_InitIndex" */
+                /*************************************************************/
+
+                DPRINTK("Index not initialised \n");
+                i_ReturnValue = -4;
+                }
+             }
+          else
+             {
+             /****************************************/
+             /* Counter not initialised see function */
+             /* "i_APCI1710_InitCounter"             */
+             /****************************************/
+
+             DPRINTK("Counter not initialised\n");     
+             i_ReturnValue = -3;
+             }
+          }
+       else
+          {
+          /*************************************************/
+          /* The selected module number parameter is wrong */
+          /*************************************************/
+
+          DPRINTK("The selected module number parameter is wrong\n");
+          i_ReturnValue = -2;
+          }
+
+       return (i_ReturnValue);
+       }
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     : _INT_ i_APCI1710_DisableIndex (BYTE_  b_BoardHandle,   |
+|                                                    BYTE_  b_ModulNbr)      |
++----------------------------------------------------------------------------+
+| Task              : Disable the INDEX actions                              |
++----------------------------------------------------------------------------+
+| Input Parameters  : BYTE_ b_BoardHandle     : Handle of board APCI-1710    |
+|                     BYTE_ b_ModulNbr        : Module number to configure   |
+|                                               (0 to 3)                     |
++----------------------------------------------------------------------------+
+| Output Parameters : -                                                      |
++----------------------------------------------------------------------------+
+| Return Value      :  0: No error                                           |
+|                     -1: The handle parameter of the board is wrong         |
+|                     -2: No counter module found                            |
+|                     -3: Counter not initialised see function               |
+|                         "i_APCI1710_InitCounter"                           |
+|                     -4: Index not initialised see function                 |
+|                         "i_APCI1710_InitIndex"                             |
++----------------------------------------------------------------------------+
+*/
+
+INT  i_APCI1710_DisableIndex (comedi_device *dev,
+                                BYTE b_ModulNbr)
+       {
+       INT i_ReturnValue = 0;
+       
+       
+       /**************************/
+       /* Test the module number */
+       /**************************/
+
+       if (b_ModulNbr < 4)
+          {
+          /*******************************/
+          /* Test if counter initialised */
+          /*******************************/
+
+          if (devpriv->
+              s_ModuleInfo [b_ModulNbr].
+              s_SiemensCounterInfo.
+              s_InitFlag.
+              b_CounterInit == 1)
+             {
+             /*****************************/
+             /* Test if index initialised */
+             /*****************************/
+
+             if (devpriv->
+                 s_ModuleInfo [b_ModulNbr].
+                 s_SiemensCounterInfo.
+                 s_InitFlag.
+                 b_IndexInit)
+                {
+                devpriv->
+                s_ModuleInfo [b_ModulNbr].
+                s_SiemensCounterInfo.
+                s_ModeRegister.
+                s_ByteModeRegister.
+                b_ModeRegister2 = devpriv->
+                                  s_ModuleInfo [b_ModulNbr].
+                                  s_SiemensCounterInfo.
+                                  s_ModeRegister.
+                                  s_ByteModeRegister.
+                                  b_ModeRegister2 & APCI1710_DISABLE_INDEX;
+
+                outl(devpriv->s_ModuleInfo [b_ModulNbr].
+                        s_SiemensCounterInfo.
+                        s_ModeRegister.
+                        dw_ModeRegister1_2_3_4,devpriv->s_BoardInfos.
+                        ui_Address + 20 + (64 * b_ModulNbr));
+                }
+             else
+                {
+                /*************************************************************/
+                /* Index not initialised see function "i_APCI1710_InitIndex" */
+                /*************************************************************/
+
+                DPRINTK("Index not initialised  \n");
+                i_ReturnValue = -4;
+                }
+             }
+          else
+             {
+             /****************************************/
+             /* Counter not initialised see function */
+             /* "i_APCI1710_InitCounter"             */
+             /****************************************/
+
+             DPRINTK("Counter not initialised\n");     
+             i_ReturnValue = -3;
+             }
+          }
+       else
+          {
+          /*************************************************/
+          /* The selected module number parameter is wrong */
+          /*************************************************/
+
+          DPRINTK("The selected module number parameter is wrong\n");  
+          i_ReturnValue = -2;
+          }
+
+       return (i_ReturnValue);
+       }
+
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     : _INT_ i_APCI1710_EnableCompareLogic                    |
+|                               (BYTE_   b_BoardHandle,                      |
+|                                BYTE_   b_ModulNbr)                         |
++----------------------------------------------------------------------------+
+| Task              : Enable the 32-Bit compare logic. At that moment that   |
+|                     the incremental counter arrive to the compare value a  |
+|                     interrupt is generated.                                |
++----------------------------------------------------------------------------+
+| Input Parameters  : BYTE_  b_BoardHandle    : Handle of board APCI-1710    |
+|                     BYTE_  b_ModulNbr       : Module number to configure   |
+|                                               (0 to 3)                     |
++----------------------------------------------------------------------------+
+| Output Parameters : -
++----------------------------------------------------------------------------+
+| Return Value      :  0: No error                                           |
+|                     -1: The handle parameter of the board is wrong         |
+|                     -2: No counter module found                            |
+|                     -3: Counter not initialised see function               |
+|                         "i_APCI1710_InitCounter"                           |
+|                     -4: Compare logic not initialised.                     |
+|                         See function "i_APCI1710_InitCompareLogic"         |
+|                     -5: Interrupt function not initialised.                |
+|                         See function "i_APCI1710_SetBoardIntRoutineX"      |
++----------------------------------------------------------------------------+
+*/
+
+INT   i_APCI1710_EnableCompareLogic   (comedi_device *dev,
+                                        BYTE   b_ModulNbr)
+       {
+       INT    i_ReturnValue = 0;
+       
+       
+       /**************************/
+       /* Test the module number */
+       /**************************/
+
+       if (b_ModulNbr < 4)
+          {
+          /*******************************/
+          /* Test if counter initialised */
+          /*******************************/
+
+          if (devpriv->
+              s_ModuleInfo [b_ModulNbr].
+              s_SiemensCounterInfo.
+              s_InitFlag.
+              b_CounterInit == 1)
+             {
+             /*************************************/
+             /* Test if compare logic initialised */
+             /*************************************/
+
+             if (devpriv->
+                 s_ModuleInfo [b_ModulNbr].
+                 s_SiemensCounterInfo.
+                 s_InitFlag.
+                 b_CompareLogicInit == 1)
+                {
+                   devpriv->
+                   s_ModuleInfo [b_ModulNbr].
+                   s_SiemensCounterInfo.
+                   s_ModeRegister.
+                   s_ByteModeRegister.
+                   b_ModeRegister3 = devpriv->
+                                     s_ModuleInfo [b_ModulNbr].
+                                     s_SiemensCounterInfo.
+                                     s_ModeRegister.
+                                     s_ByteModeRegister.
+                                     b_ModeRegister3 | APCI1710_ENABLE_COMPARE_INT;
+
+                   /***************************/
+                   /* Write the configuration */
+                   /***************************/
+
+                       outl(devpriv->s_ModuleInfo [b_ModulNbr].
+                           s_SiemensCounterInfo.
+                           s_ModeRegister.
+                           dw_ModeRegister1_2_3_4,devpriv->s_BoardInfos.
+                           ui_Address + 20 + (64 * b_ModulNbr));
+                }
+             else
+                {
+                /*********************************/
+                /* Compare logic not initialised */
+                /*********************************/
+
+                DPRINTK("Compare logic not initialised\n");
+                i_ReturnValue = -4;
+                }
+             }
+          else
+             {
+             /****************************************/
+             /* Counter not initialised see function */
+             /* "i_APCI1710_InitCounter"             */
+             /****************************************/
+
+             DPRINTK("Counter not initialised\n");     
+             i_ReturnValue = -3;
+             }
+          }
+       else
+          {
+          /*************************************************/
+          /* The selected module number parameter is wrong */
+          /*************************************************/
+
+          DPRINTK("The selected module number parameter is wrong\n");
+          i_ReturnValue = -2;
+          }
+
+       return (i_ReturnValue);
+       }
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     : _INT_ i_APCI1710_DisableCompareLogic                   |
+|                               (BYTE_   b_BoardHandle,                      |
+|                                BYTE_   b_ModulNbr)                         |
++----------------------------------------------------------------------------+
+| Task              : Disable the 32-Bit compare logic.
++----------------------------------------------------------------------------+
+| Input Parameters  : BYTE_  b_BoardHandle    : Handle of board APCI-1710    |
+|                     BYTE_  b_ModulNbr       : Module number to configure   |
+|                                               (0 to 3)                     |
++----------------------------------------------------------------------------+
+| Output Parameters : -
++----------------------------------------------------------------------------+
+| Return Value      :  0: No error                                           |
+|                     -1: The handle parameter of the board is wrong         |
+|                     -2: No counter module found                            |
+|                     -3: Counter not initialised see function               |
+|                         "i_APCI1710_InitCounter"                           |
+|                     -4: Compare logic not initialised.                     |
+|                         See function "i_APCI1710_InitCompareLogic"         |
++----------------------------------------------------------------------------+
+*/
+
+INT   i_APCI1710_DisableCompareLogic  (comedi_device *dev,
+                                        BYTE   b_ModulNbr)
+       {
+       INT    i_ReturnValue = 0;
+       
+       /**************************/
+       /* Test the module number */
+       /**************************/
+
+       if (b_ModulNbr < 4)
+          {
+          /*******************************/
+          /* Test if counter initialised */
+          /*******************************/
+
+          if (devpriv->
+              s_ModuleInfo [b_ModulNbr].
+              s_SiemensCounterInfo.
+              s_InitFlag.
+              b_CounterInit == 1)
+             {
+             /*************************************/
+             /* Test if compare logic initialised */
+             /*************************************/
+
+             if (devpriv->
+                 s_ModuleInfo [b_ModulNbr].
+                 s_SiemensCounterInfo.
+                 s_InitFlag.
+                 b_CompareLogicInit == 1)
+                {
+                devpriv->
+                s_ModuleInfo [b_ModulNbr].
+                s_SiemensCounterInfo.
+                s_ModeRegister.
+                s_ByteModeRegister.
+                b_ModeRegister3 = devpriv->
+                                  s_ModuleInfo [b_ModulNbr].
+                                  s_SiemensCounterInfo.
+                                  s_ModeRegister.
+                                  s_ByteModeRegister.
+                                  b_ModeRegister3 & APCI1710_DISABLE_COMPARE_INT;
+
+                /***************************/
+                /* Write the configuration */
+                /***************************/
+
+                outl(devpriv->s_ModuleInfo [b_ModulNbr].
+                        s_SiemensCounterInfo.
+                        s_ModeRegister.
+                        dw_ModeRegister1_2_3_4,devpriv->s_BoardInfos.
+                        ui_Address + 20 + (64 * b_ModulNbr));
+                }
+             else
+                {
+                /*********************************/
+                /* Compare logic not initialised */
+                /*********************************/
+
+                DPRINTK("Compare logic not initialised\n");
+                i_ReturnValue = -4;
+                }
+             }
+          else
+             {
+             /****************************************/
+             /* Counter not initialised see function */
+             /* "i_APCI1710_InitCounter"             */
+             /****************************************/
+
+             DPRINTK("Counter not initialised\n");     
+             i_ReturnValue = -3;
+             }
+          }
+       else
+          {
+          /*************************************************/
+          /* The selected module number parameter is wrong */
+          /*************************************************/
+
+          DPRINTK("The selected module number parameter is wrong\n");
+          i_ReturnValue = -2;
+          }
+
+       return (i_ReturnValue);
+       }
+
+
+       /*
++----------------------------------------------------------------------------+
+| Function Name     : _INT_ i_APCI1710_EnableFrequencyMeasurement            |
+|                              (BYTE_   b_BoardHandle,                      |
+|                               BYTE_   b_ModulNbr,                         |
+|                               BYTE_   b_InterruptEnable)                  |
++----------------------------------------------------------------------------+
+| Task              : Enables the frequency measurement function             |
++----------------------------------------------------------------------------+
+| Input Parameters  : BYTE_  b_BoardHandle    : Handle of board APCI-1710    |
+|                    BYTE_  b_ModulNbr       : Number of the module to be   |
+|                                              configured (0 to 3)          |
+|                    BYTE_  b_InterruptEnable: Enable or disable the        |
+|                                              interrupt.                   |
+|                                              APCI1710_ENABLE:             |
+|                                              Enable the interrupt         |
+|                                              APCI1710_DISABLE:            |
+|                                              Disable the interrupt        |
++----------------------------------------------------------------------------+
+| Output Parameters : -                                                      |
++----------------------------------------------------------------------------+
+| Return Value      :  0: No error                                           |
+|                     -1: The handle parameter of the board is wrong         |
+|                     -2: The selected module number is wrong                |
+|                     -3: Counter not initialised see function               |
+|                        "i_APCI1710_InitCounter"                           |
+|                     -4: Frequency measurement logic not initialised.       |
+|                        See function "i_APCI1710_InitFrequencyMeasurement" |
+|                     -5: Interrupt parameter is wrong                       |
+|                     -6: Interrupt function not initialised.                |
++----------------------------------------------------------------------------+
+*/
+
+INT    i_APCI1710_EnableFrequencyMeasurement   (comedi_device *dev,
+                                                BYTE    b_ModulNbr,
+                                                BYTE    b_InterruptEnable)
+       {
+       INT    i_ReturnValue = 0;
+       
+       
+       /**************************/
+       /* Test the module number */
+       /**************************/
+
+       if (b_ModulNbr < 4)
+          {
+          /*******************************/
+          /* Test if counter initialised */
+          /*******************************/
+
+          if (devpriv->
+              s_ModuleInfo [b_ModulNbr].
+              s_SiemensCounterInfo.
+              s_InitFlag.
+              b_CounterInit == 1)
+             {
+             /********************************************/
+             /* Test if frequency mesurement initialised */
+             /********************************************/
+
+             if (devpriv->
+                 s_ModuleInfo [b_ModulNbr].
+                 s_SiemensCounterInfo.
+                 s_InitFlag.
+                 b_FrequencyMeasurementInit == 1)
+                {
+                /***************************/
+                /* Test the interrupt mode */
+                /***************************/
+
+                if ((b_InterruptEnable == APCI1710_DISABLE) ||
+                    (b_InterruptEnable == APCI1710_ENABLE))
+                   {
+
+                      /************************************/
+                      /* Enable the frequency measurement */
+                      /************************************/
+
+                      devpriv->
+                      s_ModuleInfo [b_ModulNbr].
+                      s_SiemensCounterInfo.
+                      s_ModeRegister.
+                      s_ByteModeRegister.
+                      b_ModeRegister3 = devpriv->
+                                        s_ModuleInfo [b_ModulNbr].
+                                        s_SiemensCounterInfo.
+                                        s_ModeRegister.
+                                        s_ByteModeRegister.
+                                        b_ModeRegister3 | APCI1710_ENABLE_FREQUENCY;
+
+                      /*********************************************/
+                      /* Disable or enable the frequency interrupt */
+                      /*********************************************/
+
+                      devpriv->
+                      s_ModuleInfo [b_ModulNbr].
+                      s_SiemensCounterInfo.
+                      s_ModeRegister.
+                      s_ByteModeRegister.
+                      b_ModeRegister3 = (devpriv->
+                                         s_ModuleInfo [b_ModulNbr].
+                                         s_SiemensCounterInfo.
+                                         s_ModeRegister.
+                                         s_ByteModeRegister.
+                                         b_ModeRegister3 & APCI1710_DISABLE_FREQUENCY_INT) | (b_InterruptEnable << 3);
+
+                      /***************************/
+                      /* Write the configuration */
+                      /***************************/
+
+                          outl(devpriv->s_ModuleInfo [b_ModulNbr].
+                              s_SiemensCounterInfo.
+                              s_ModeRegister.
+                              dw_ModeRegister1_2_3_4,devpriv->s_BoardInfos.
+                              ui_Address + 20 + (64 * b_ModulNbr));
+
+                      devpriv->
+                      s_ModuleInfo [b_ModulNbr].
+                      s_SiemensCounterInfo.
+                      s_InitFlag.
+                      b_FrequencyMeasurementEnable = 1;
+                   }
+                else
+                   {
+                   /********************************/
+                   /* Interrupt parameter is wrong */
+                   /********************************/
+
+                   DPRINTK("Interrupt parameter is wrong\n");
+                   i_ReturnValue = -5;
+                   }
+                }
+             else
+                {
+                /***********************************************/
+                /* Frequency measurement logic not initialised */
+                /***********************************************/
+
+                DPRINTK("Frequency measurement logic not initialised\n");
+                i_ReturnValue = -4;
+                }
+             }
+          else
+             {
+             /****************************************/
+             /* Counter not initialised see function */
+             /* "i_APCI1710_InitCounter"             */
+             /****************************************/
+
+             DPRINTK("Counter not initialised\n");     
+             i_ReturnValue = -3;
+             }
+          }
+       else
+          {
+          /*************************************************/
+          /* The selected module number parameter is wrong */
+          /*************************************************/
+
+          DPRINTK("The selected module number parameter is wrong\n"); 
+          i_ReturnValue = -2;
+          }
+
+       return (i_ReturnValue);
+       }
+
+       /*
++----------------------------------------------------------------------------+
+| Function Name     : _INT_ i_APCI1710_DisableFrequencyMeasurement           |
+|                              (BYTE_   b_BoardHandle,                      |
+|                               BYTE_   b_ModulNbr)                         |
++----------------------------------------------------------------------------+
+| Task              : Disables the frequency measurement function             |
++----------------------------------------------------------------------------+
+| Input Parameters  : BYTE_  b_BoardHandle    : Handle of board APCI-1710    |
+|                    BYTE_  b_ModulNbr       : Number of the module to be   |
+|                                              configured (0 to 3)          |
++----------------------------------------------------------------------------+
+| Output Parameters : -                                                      |
++----------------------------------------------------------------------------+
+| Return Value      :  0: No error                                           |
+|                     -1: The handle parameter of the board is wrong         |
+|                     -2: The selected module number is wrong                |
+|                     -3: Counter not initialised see function               |
+|                        "i_APCI1710_InitCounter"                           |
+|                     -4: Frequency measurement logic not initialised.       |
+|                        See function "i_APCI1710_InitFrequencyMeasurement" |
++----------------------------------------------------------------------------+
+*/
+
+INT    i_APCI1710_DisableFrequencyMeasurement  (comedi_device *dev,
+                                                BYTE    b_ModulNbr)
+       {
+       INT    i_ReturnValue = 0;
+       
+       /**************************/
+       /* Test the module number */
+       /**************************/
+
+       if (b_ModulNbr < 4)
+          {
+          /*******************************/
+          /* Test if counter initialised */
+          /*******************************/
+
+          if (devpriv->
+              s_ModuleInfo [b_ModulNbr].
+              s_SiemensCounterInfo.
+              s_InitFlag.
+              b_CounterInit == 1)
+             {
+             /********************************************/
+             /* Test if frequency mesurement initialised */
+             /********************************************/
+
+             if (devpriv->
+                 s_ModuleInfo [b_ModulNbr].
+                 s_SiemensCounterInfo.
+                 s_InitFlag.
+                 b_FrequencyMeasurementInit == 1)
+                {
+                /*************************************/
+                /* Disable the frequency measurement */
+                /*************************************/
+
+                devpriv->
+                s_ModuleInfo [b_ModulNbr].
+                s_SiemensCounterInfo.
+                s_ModeRegister.
+                s_ByteModeRegister.
+                b_ModeRegister3 = devpriv->
+                                  s_ModuleInfo [b_ModulNbr].
+                                  s_SiemensCounterInfo.
+                                  s_ModeRegister.
+                                  s_ByteModeRegister.
+                                  b_ModeRegister3 & APCI1710_DISABLE_FREQUENCY
+                                  // Begin CG 29/06/01 CG 1100/0231 -> 0701/0232 Frequence measure IRQ must be cleared
+                                  & APCI1710_DISABLE_FREQUENCY_INT;
+                                  // End CG 29/06/01 CG 1100/0231 -> 0701/0232 Frequence measure IRQ must be cleared
+
+                /***************************/
+                /* Write the configuration */
+                /***************************/
+
+                outl(devpriv->s_ModuleInfo [b_ModulNbr].
+                        s_SiemensCounterInfo.
+                        s_ModeRegister.
+                        dw_ModeRegister1_2_3_4,devpriv->s_BoardInfos.
+                        ui_Address + 20 + (64 * b_ModulNbr));
+
+                /*************************************/
+                /* Disable the frequency measurement */
+                /*************************************/
+
+                devpriv->
+                s_ModuleInfo [b_ModulNbr].
+                s_SiemensCounterInfo.
+                s_InitFlag.
+                b_FrequencyMeasurementEnable = 0;
+                }
+             else
+                {
+                /***********************************************/
+                /* Frequency measurement logic not initialised */
+                /***********************************************/
+
+                DPRINTK("Frequency measurement logic not initialised\n");
+                i_ReturnValue = -4;
+                }
+             }
+          else
+             {
+             /****************************************/
+             /* Counter not initialised see function */
+             /* "i_APCI1710_InitCounter"             */
+             /****************************************/
+
+             DPRINTK("Counter not initialised\n");     
+             i_ReturnValue = -3;
+             }
+          }
+       else
+          {
+          /*************************************************/
+          /* The selected module number parameter is wrong */
+          /*************************************************/
+
+          DPRINTK("The selected module number parameter is wrong\n");  
+          i_ReturnValue = -2;
+          }
+
+       return (i_ReturnValue);
+       }
+
+/*########################################################################### */
+
+                                                       // INSN READ
+
+/*########################################################################### */
+
+                                        
+
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     :INT       i_APCI1710_InsnWriteINCCPT(comedi_device *dev,comedi_subdevice *s,
+comedi_insn *insn,lsampl_t *data)                   |
++----------------------------------------------------------------------------+
+| Task              : Read and Get functions for INC_CPT                                       |
++----------------------------------------------------------------------------+
+| Input Parameters  : 
++----------------------------------------------------------------------------+
+| Output Parameters : -                                                      |
++----------------------------------------------------------------------------+
+| Return Value      : 
++----------------------------------------------------------------------------+
+*/
+INT    i_APCI1710_InsnReadINCCPT(comedi_device *dev,comedi_subdevice *s,
+comedi_insn *insn,lsampl_t *data)
+{
+       UINT ui_ReadType;
+       INT  i_ReturnValue=0;
+        
+       ui_ReadType=CR_CHAN(insn->chanspec);
+
+       devpriv->tsk_Current=current; // Save the current process task structure
+       switch(ui_ReadType)
+       {
+       case APCI1710_INCCPT_READLATCHREGISTERSTATUS:
+               i_ReturnValue=i_APCI1710_ReadLatchRegisterStatus      (dev,
+                                                (BYTE)   CR_AREF(insn->chanspec),
+                                                (BYTE)   CR_RANGE(insn->chanspec),
+                                                (PBYTE)  &data[0]);
+       break;
+
+       case APCI1710_INCCPT_READLATCHREGISTERVALUE:
+               i_ReturnValue=i_APCI1710_ReadLatchRegisterValue       (dev,
+                                                (BYTE)   CR_AREF(insn->chanspec),
+                                                (BYTE)   CR_RANGE(insn->chanspec),
+                                                (PULONG) &data[0]);
+                printk("Latch Register Value %d\n",data[0]);
+       break;
+
+       case APCI1710_INCCPT_READ16BITCOUNTERVALUE:
+               i_ReturnValue=i_APCI1710_Read16BitCounterValue        (dev,
+                                                (BYTE)   CR_AREF(insn->chanspec),
+                                                (BYTE)   CR_RANGE(insn->chanspec),
+                                                (PUINT) &data[0]);
+       break;
+    
+       case APCI1710_INCCPT_READ32BITCOUNTERVALUE:
+               i_ReturnValue=i_APCI1710_Read32BitCounterValue        (dev,
+                                                (BYTE)   CR_AREF(insn->chanspec),
+                                                (PULONG)  &data[0]);
+       break;
+    
+       case APCI1710_INCCPT_GETINDEXSTATUS:
+                i_ReturnValue=i_APCI1710_GetIndexStatus      (dev,
+                                       (BYTE)   CR_AREF(insn->chanspec),
+                                       (PBYTE) &data[0]);
+       break;
+    
+       case APCI1710_INCCPT_GETREFERENCESTATUS:
+                i_ReturnValue=i_APCI1710_GetReferenceStatus      (dev,
+                                           (BYTE)   CR_AREF(insn->chanspec),
+                                           (PBYTE)  &data[0]);
+       break;
+    
+       case APCI1710_INCCPT_GETUASSTATUS:
+               i_ReturnValue=i_APCI1710_GetUASStatus (dev,
+                                (BYTE)   CR_AREF(insn->chanspec),
+                                (PBYTE) &data[0]);
+       break;
+    
+       case APCI1710_INCCPT_GETCBSTATUS:
+               i_ReturnValue=i_APCI1710_GetCBStatus  (dev,
+                                (BYTE)   CR_AREF(insn->chanspec),
+                                (PBYTE) &data[0]);
+       break;
+    
+       case APCI1710_INCCPT_GET16BITCBSTATUS:
+               i_ReturnValue=i_APCI1710_Get16BitCBStatus       (dev,
+                                (BYTE)   CR_AREF(insn->chanspec),
+                                (PBYTE) &data[0],
+                                (PBYTE) &data[1]);
+       break;
+    
+       case APCI1710_INCCPT_GETUDSTATUS:
+               i_ReturnValue=i_APCI1710_GetUDStatus  (dev,
+                                (BYTE)   CR_AREF(insn->chanspec),
+                                (PBYTE) &data[0]);
+       
+       break;
+    
+       case APCI1710_INCCPT_GETINTERRUPTUDLATCHEDSTATUS:
+               i_ReturnValue=i_APCI1710_GetInterruptUDLatchedStatus  (dev,
+                                (BYTE)   CR_AREF(insn->chanspec),
+                                (PBYTE) &data[0]);
+       break;
+    
+       case APCI1710_INCCPT_READFREQUENCYMEASUREMENT:
+               i_ReturnValue=i_APCI1710_ReadFrequencyMeasurement (dev,
+                                (BYTE)   CR_AREF(insn->chanspec),
+                                (PBYTE)  &data[0],
+                                (PBYTE)  &data[1],
+                                (PULONG) &data[2]);
+       break;
+         
+        case APCI1710_INCCPT_READINTERRUPT:
+               data[0]=devpriv->s_InterruptParameters.
+                                                     s_FIFOInterruptParameters [devpriv->
+                                                                                s_InterruptParameters.
+                                                                                ui_Read].b_OldModuleMask;
+               data[1]=devpriv->s_InterruptParameters.
+                                                     s_FIFOInterruptParameters [devpriv->
+                                                                                s_InterruptParameters.
+                                                                                ui_Read].ul_OldInterruptMask;
+               data[2]=devpriv->s_InterruptParameters.
+                                                     s_FIFOInterruptParameters [devpriv->
+                                                                                s_InterruptParameters.
+                                                                                ui_Read].ul_OldCounterLatchValue;
+
+                            
+               /**************************/
+               /* Increment the read FIFO */
+               /***************************/
+
+               devpriv->
+               s_InterruptParameters.
+               ui_Read = (devpriv->s_InterruptParameters.
+                                       ui_Read + 1) % APCI1710_SAVE_INTERRUPT;
+         
+               break;                      
+    
+       default:
+               printk("ReadType Parameter wrong\n");
+       }
+
+       if(i_ReturnValue>=0) i_ReturnValue =insn->n;
+       return (i_ReturnValue); 
+
+}
+
+
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     : _INT_ i_APCI1710_ReadLatchRegisterStatus               |
+|                                                   (BYTE_   b_BoardHandle,  |
+|                                                    BYTE_   b_ModulNbr,     |
+|                                                    BYTE_   b_LatchReg,     |
+|                                                    PBYTE_ pb_LatchStatus)  |
++----------------------------------------------------------------------------+
+| Task              : Read the latch register status from selected module    |
+|                     (b_ModulNbr) and selected latch register (b_LatchReg). |
++----------------------------------------------------------------------------+
+| Input Parameters  : BYTE_ b_BoardHandle : Handle of board APCI-1710        |
+|                     BYTE_ b_ModulNbr    : Module number to configure       |
+|                                           (0 to 3)                         |
+|                     BYTE_ b_LatchReg    : Selected latch register          |
+|                               0 : for the first latch register             |
+|                               1 : for the second latch register            |
++----------------------------------------------------------------------------+
+| Output Parameters : PBYTE_ pb_LatchStatus :   Latch register status.       |
+|                                               0 : No latch occur           |
+|                                               1 : A software latch occur   |
+|                                               2 : A hardware latch occur   |
+|                                               3 : A software and hardware  |
+|                                                   latch occur              |
++----------------------------------------------------------------------------+
+| Return Value      :  0: No error                                           |
+|                     -1: The handle parameter of the board is wrong         |
+|                     -2: No counter module found                            |
+|                     -3: Counter not initialised see function               |
+|                         "i_APCI1710_InitCounter"                           |
+|                     -4: The selected latch register parameter is wrong     |
++----------------------------------------------------------------------------+
+*/
+
+INT   i_APCI1710_ReadLatchRegisterStatus      (comedi_device *dev,
+                                                BYTE   b_ModulNbr,
+                                                BYTE   b_LatchReg,
+                                                PBYTE pb_LatchStatus)
+       {
+       INT    i_ReturnValue = 0;
+       DWORD dw_LatchReg;
+       
+       /**************************/
+       /* Test the module number */
+       /**************************/
+
+       if (b_ModulNbr < 4)
+          {
+          /*******************************/
+          /* Test if counter initialised */
+          /*******************************/
+
+          if (devpriv->
+              s_ModuleInfo [b_ModulNbr].
+              s_SiemensCounterInfo.
+              s_InitFlag.
+              b_CounterInit == 1)
+             {
+             /*************************************/
+             /* Test the latch register parameter */
+             /*************************************/
+
+             if (b_LatchReg < 2)
+                {
+                       dw_LatchReg=inl(devpriv->s_BoardInfos.
+                                                       ui_Address + (64 * b_ModulNbr));
+
+                *pb_LatchStatus = (BYTE) ((dw_LatchReg >> (b_LatchReg * 4)) & 0x3);
+                }
+             else
+                {
+                /**************************************************/
+                /* The selected latch register parameter is wrong */
+                /**************************************************/
+
+                DPRINTK("The selected latch register parameter is wrong\n");
+                i_ReturnValue = -4;
+                }
+             }
+          else
+             {
+             /****************************************/
+             /* Counter not initialised see function */
+             /* "i_APCI1710_InitCounter"             */
+             /****************************************/
+
+             DPRINTK("Counter not initialised\n");
+             i_ReturnValue = -3;
+             }
+          }
+       else
+          {
+          /*************************************************/
+          /* The selected module number parameter is wrong */
+          /*************************************************/
+
+          DPRINTK("The selected module number parameter is wrong\n");  
+          i_ReturnValue = -2;
+          }
+
+
+       return (i_ReturnValue);
+       }
+
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     : _INT_ i_APCI1710_ReadLatchRegisterValue                |
+|                                                   (BYTE_     b_BoardHandle,|
+|                                                    BYTE_     b_ModulNbr,   |
+|                                                    BYTE_     b_LatchReg,   |
+|                                                    PULONG_ pul_LatchValue) |
++----------------------------------------------------------------------------+
+| Task              : Read the latch register value from selected module     |
+|                     (b_ModulNbr) and selected latch register (b_LatchReg). |
++----------------------------------------------------------------------------+
+| Input Parameters  : BYTE_ b_BoardHandle : Handle of board APCI-1710        |
+|                     BYTE_ b_ModulNbr    : Module number to configure       |
+|                                           (0 to 3)                         |
+|                     BYTE_ b_LatchReg    : Selected latch register          |
+|                               0 : for the first latch register             |
+|                               1 : for the second latch register            |
++----------------------------------------------------------------------------+
+| Output Parameters : PULONG_ pul_LatchValue : Latch register value          |
++----------------------------------------------------------------------------+
+| Return Value      :  0: No error                                           |
+|                     -1: The handle parameter of the board is wrong         |
+|                     -2: No counter module found                            |
+|                     -3: Counter not initialised see function               |
+|                         "i_APCI1710_InitCounter"                           |
+|                     -4: The selected latch register parameter is wrong     |
++----------------------------------------------------------------------------+
+*/
+
+INT   i_APCI1710_ReadLatchRegisterValue       (comedi_device *dev,
+                                                BYTE     b_ModulNbr,
+                                                BYTE     b_LatchReg,
+                                                PULONG pul_LatchValue)
+       {
+       INT i_ReturnValue = 0;
+       
+       /**************************/
+       /* Test the module number */
+       /**************************/
+
+       if (b_ModulNbr < 4)
+          {
+          /*******************************/
+          /* Test if counter initialised */
+          /*******************************/
+
+          if (devpriv->
+              s_ModuleInfo [b_ModulNbr].
+              s_SiemensCounterInfo.
+              s_InitFlag.
+              b_CounterInit == 1)
+             {
+             /*************************************/
+             /* Test the latch register parameter */
+             /*************************************/
+
+             if (b_LatchReg < 2)
+                {
+                       *pul_LatchValue=inl(devpriv->s_BoardInfos.
+                       ui_Address + ((b_LatchReg + 1) * 4) + (64 * b_ModulNbr));
+                    
+                }
+             else
+                {
+                /**************************************************/
+                /* The selected latch register parameter is wrong */
+                /**************************************************/
+
+                DPRINTK("The selected latch register parameter is wrong\n");
+                i_ReturnValue = -4;
+                }
+             }
+          else
+             {
+             /****************************************/
+             /* Counter not initialised see function */
+             /* "i_APCI1710_InitCounter"             */
+             /****************************************/
+
+             DPRINTK("Counter not initialised\n");     
+             i_ReturnValue = -3;
+             }
+          }
+       else
+          {
+          /*************************************************/
+          /* The selected module number parameter is wrong */
+          /*************************************************/
+
+          DPRINTK("The selected module number parameter is wrong\n");  
+          i_ReturnValue = -2;
+          }
+
+       return (i_ReturnValue);
+       }
+
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     : _INT_ i_APCI1710_Read16BitCounterValue                 |
+|                                       (BYTE_     b_BoardHandle,            |
+|                                        BYTE_     b_ModulNbr,               |
+|                                        BYTE_     b_SelectedCounter,        |
+|                                        PUINT_   pui_CounterValue)          |
++----------------------------------------------------------------------------+
+| Task              : Latch the selected 16-Bit counter (b_SelectedCounter)  |
+|                     from selected module (b_ModulNbr) in to the first      |
+|                     latch register and return the latched value.           |
++----------------------------------------------------------------------------+
+| Input Parameters  : BYTE_ b_BoardHandle     : Handle of board APCI-1710    |
+|                     BYTE_ b_ModulNbr        : Module number to configure   |
+|                                              (0 to 3)                      |
+|                     BYTE_ b_SelectedCounter : Selected 16-Bit counter      |
+|                                               (0 or 1)                     |
++----------------------------------------------------------------------------+
+| Output Parameters : PUINT_ pui_CounterValue : 16-Bit counter value         |
++----------------------------------------------------------------------------+
+| Return Value      :  0: No error                                           |
+|                     -1: The handle parameter of the board is wrong         |
+|                     -2: No counter module found                            |
+|                     -3: Counter not initialised see function               |
+|                         "i_APCI1710_InitCounter"                           |
+|                     -4: The selected 16-Bit counter parameter is wrong     |
++----------------------------------------------------------------------------+
+*/
+
+INT   i_APCI1710_Read16BitCounterValue        (comedi_device *dev,
+                                                BYTE    b_ModulNbr,
+                                                BYTE    b_SelectedCounter,
+                                                PUINT pui_CounterValue)
+       {
+       INT    i_ReturnValue = 0;
+       DWORD dw_LathchValue = 0;
+       
+       /**************************/
+       /* Test the module number */
+       /**************************/
+
+       if (b_ModulNbr < 4)
+          {
+          /*******************************/
+          /* Test if counter initialised */
+          /*******************************/
+
+          if (devpriv->
+              s_ModuleInfo [b_ModulNbr].
+              s_SiemensCounterInfo.
+              s_InitFlag.
+              b_CounterInit == 1)
+             {
+             /******************************/
+             /* Test the counter selection */
+             /******************************/
+
+             if (b_SelectedCounter < 2)
+                {
+                /*********************/
+                /* Latch the counter */
+                /*********************/
+
+                         outl(1,devpriv->s_BoardInfos.
+                        ui_Address + (64 * b_ModulNbr));
+
+                /************************/
+                /* Read the latch value */
+                /************************/
+
+                       dw_LathchValue=inl(devpriv->s_BoardInfos.
+                       ui_Address + 4 + (64 * b_ModulNbr));
+
+                *pui_CounterValue = (UINT) ((dw_LathchValue >> (16 * b_SelectedCounter)) & 0xFFFFU);
+                }
+             else
+                {
+                /**************************************************/
+                /* The selected 16-Bit counter parameter is wrong */
+                /**************************************************/
+
+                DPRINTK("The selected 16-Bit counter parameter is wrong\n");
+                i_ReturnValue = -4;
+                }
+             }
+          else
+             {
+             /****************************************/
+             /* Counter not initialised see function */
+             /* "i_APCI1710_InitCounter"             */
+             /****************************************/
+
+             DPRINTK("Counter not initialised\n");     
+             i_ReturnValue = -3;
+             }
+          }
+       else
+          {
+          /*************************************************/
+          /* The selected module number parameter is wrong */
+          /*************************************************/
+
+          DPRINTK("The selected module number parameter is wrong\n");
+          i_ReturnValue = -2;
+          }
+
+       return (i_ReturnValue);
+       }
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     : _INT_ i_APCI1710_Read32BitCounterValue                 |
+|                                       (BYTE_     b_BoardHandle,            |
+|                                        BYTE_     b_ModulNbr,               |
+|                                        PULONG_ pul_CounterValue)           |
++----------------------------------------------------------------------------+
+| Task              : Latch the 32-Bit counter from selected module          |
+|                     (b_ModulNbr) in to the first latch register and return |
+|                     the latched value.                                     |
++----------------------------------------------------------------------------+
+| Input Parameters  : BYTE_ b_BoardHandle     : Handle of board APCI-1710    |
+|                     BYTE_ b_ModulNbr        : Module number to configure   |
+|                                              (0 to 3)                      |
++----------------------------------------------------------------------------+
+| Output Parameters : PULONG_  pul_CounterValue : 32-Bit counter value       |
++----------------------------------------------------------------------------+
+| Return Value      :  0: No error                                           |
+|                     -1: The handle parameter of the board is wrong         |
+|                     -2: No counter module found                            |
+|                     -3: Counter not initialised see function               |
+|                         "i_APCI1710_InitCounter"                           |
++----------------------------------------------------------------------------+
+*/
+
+INT   i_APCI1710_Read32BitCounterValue        (comedi_device *dev,
+                                                BYTE      b_ModulNbr,
+                                                PULONG  pul_CounterValue)
+       {
+       INT    i_ReturnValue = 0;
+       
+       
+       /**************************/
+       /* Test the module number */
+       /**************************/
+
+       if (b_ModulNbr < 4)
+          {
+          /*******************************/
+          /* Test if counter initialised */
+          /*******************************/
+
+          if (devpriv->
+              s_ModuleInfo [b_ModulNbr].
+              s_SiemensCounterInfo.
+              s_InitFlag.
+              b_CounterInit == 1)
+             {
+             /*********************/
+             /* Tatch the counter */
+             /*********************/
+
+                  outl(1,devpriv->s_BoardInfos.
+                     ui_Address + (64 * b_ModulNbr));
+
+             /************************/
+             /* Read the latch value */
+             /************************/
+
+                  *pul_CounterValue=inl(devpriv->s_BoardInfos.
+                    ui_Address + 4 + (64 * b_ModulNbr));
+             }
+          else
+             {
+             /****************************************/
+             /* Counter not initialised see function */
+             /* "i_APCI1710_InitCounter"             */
+             /****************************************/
+
+             DPRINTK("Counter not initialised\n");
+             i_ReturnValue = -3;
+             }
+          }
+       else
+          {
+          /*************************************************/
+          /* The selected module number parameter is wrong */
+          /*************************************************/
+
+          DPRINTK("The selected module number parameter is wrong\n");  
+          i_ReturnValue = -2;
+          }
+
+       return (i_ReturnValue);
+       }
+
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     : _INT_ i_APCI1710_GetIndexStatus (BYTE_   b_BoardHandle,|
+|                                                      BYTE_   b_ModulNbr,   |
+|                                                      PBYTE_ pb_IndexStatus)|
++----------------------------------------------------------------------------+
+| Task              : Return the index status                                |
++----------------------------------------------------------------------------+
+| Input Parameters  : BYTE_ b_BoardHandle     : Handle of board APCI-1710    |
+|                     BYTE_ b_ModulNbr        : Module number to configure   |
+|                                               (0 to 3)                     |
++----------------------------------------------------------------------------+
+| Output Parameters : PBYTE_ pb_IndexStatus   : 0 : No INDEX occur           |
+|                                               1 : A INDEX occur            |
++----------------------------------------------------------------------------+
+| Return Value      :  0: No error                                           |
+|                     -1: The handle parameter of the board is wrong         |
+|                     -2: No counter module found                            |
+|                     -3: Counter not initialised see function               |
+|                         "i_APCI1710_InitCounter"                           |
+|                     -4: Index not initialised see function                 |
+|                         "i_APCI1710_InitIndex"                             |
++----------------------------------------------------------------------------+
+*/
+
+INT   i_APCI1710_GetIndexStatus      (comedi_device *dev,
+                                       BYTE   b_ModulNbr,
+                                       PBYTE pb_IndexStatus)
+       {
+       INT    i_ReturnValue = 0;
+       DWORD dw_StatusReg   = 0;
+       
+       /**************************/
+       /* Test the module number */
+       /**************************/
+
+       if (b_ModulNbr < 4)
+          {
+          /*******************************/
+          /* Test if counter initialised */
+          /*******************************/
+
+          if (devpriv->
+              s_ModuleInfo [b_ModulNbr].
+              s_SiemensCounterInfo.
+              s_InitFlag.
+              b_CounterInit == 1)
+             {
+             /*****************************/
+             /* Test if index initialised */
+             /*****************************/
+
+             if (devpriv->
+                 s_ModuleInfo [b_ModulNbr].
+                 s_SiemensCounterInfo.
+                 s_InitFlag.
+                 b_IndexInit)
+                {
+                        dw_StatusReg= inl(devpriv->s_BoardInfos.
+                        ui_Address + 12 + (64 * b_ModulNbr));
+
+                *pb_IndexStatus = (BYTE) (dw_StatusReg & 1);
+                }
+             else
+                {
+                /*************************************************************/
+                /* Index not initialised see function "i_APCI1710_InitIndex" */
+                /*************************************************************/
+
+                DPRINTK("Index not initialised\n");
+                i_ReturnValue = -4;
+                }
+             }
+          else
+             {
+             /****************************************/
+             /* Counter not initialised see function */
+             /* "i_APCI1710_InitCounter"             */
+             /****************************************/
+
+             DPRINTK("Counter not initialised\n");     
+             i_ReturnValue = -3;
+             }
+          }
+       else
+          {
+          /*************************************************/
+          /* The selected module number parameter is wrong */
+          /*************************************************/
+
+          DPRINTK("The selected module number parameter is wrong\n");  
+          i_ReturnValue = -2;
+          }
+
+       return (i_ReturnValue);
+       }
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     : _INT_ i_APCI1710_GetReferenceStatus                    |
+|                                                (BYTE_   b_BoardHandle,     |
+|                                                 BYTE_   b_ModulNbr,        |
+|                                                 PBYTE_ pb_ReferenceStatus) |
++----------------------------------------------------------------------------+
+| Task              : Return the reference status                            |
++----------------------------------------------------------------------------+
+| Input Parameters  : BYTE_ b_BoardHandle     : Handle of board APCI-1710    |
+|                     BYTE_ b_ModulNbr        : Module number to configure   |
+|                                               (0 to 3)                     |
++----------------------------------------------------------------------------+
+| Output Parameters : PBYTE_ pb_ReferenceStatus   : 0 : No REFERENCE occur   |
+|                                                   1 : A REFERENCE occur    |
++----------------------------------------------------------------------------+
+| Return Value      :  0: No error                                           |
+|                     -1: The handle parameter of the board is wrong         |
+|                     -2: No counter module found                            |
+|                     -3: Counter not initialised see function               |
+|                         "i_APCI1710_InitCounter"                           |
+|                     -4: Reference not initialised see function             |
+|                         "i_APCI1710_InitReference"                         |
++----------------------------------------------------------------------------+
+*/
+
+INT   i_APCI1710_GetReferenceStatus      (comedi_device *dev,
+                                           BYTE   b_ModulNbr,
+                                           PBYTE  pb_ReferenceStatus)
+       {
+       INT    i_ReturnValue = 0;
+       DWORD dw_StatusReg   = 0;
+       
+       /**************************/
+       /* Test the module number */
+       /**************************/
+
+       if (b_ModulNbr < 4)
+          {
+          /*******************************/
+          /* Test if counter initialised */
+          /*******************************/
+
+          if (devpriv->
+              s_ModuleInfo [b_ModulNbr].
+              s_SiemensCounterInfo.
+              s_InitFlag.
+              b_CounterInit == 1)
+             {
+             /*********************************/
+             /* Test if reference initialised */
+             /*********************************/
+
+             if (devpriv->
+                 s_ModuleInfo [b_ModulNbr].
+                 s_SiemensCounterInfo.
+                 s_InitFlag.
+                 b_ReferenceInit)
+                {
+                       dw_StatusReg=inl(devpriv->s_BoardInfos.
+                        ui_Address + 24 + (64 * b_ModulNbr));
+
+                *pb_ReferenceStatus = (BYTE) (~dw_StatusReg & 1);
+                }
+             else
+                {
+                /*********************************************************************/
+                /* Reference not initialised see function "i_APCI1710_InitReference" */
+                /*********************************************************************/
+
+                DPRINTK("Reference not initialised\n");
+                i_ReturnValue = -4;
+                }
+             }
+          else
+             {
+             /****************************************/
+             /* Counter not initialised see function */
+             /* "i_APCI1710_InitCounter"             */
+             /****************************************/
+
+             DPRINTK("Counter not initialised\n");     
+             i_ReturnValue = -3;
+             }
+          }
+       else
+          {
+          /*************************************************/
+          /* The selected module number parameter is wrong */
+          /*************************************************/
+
+          DPRINTK("The selected module number parameter is wrong\n");
+          i_ReturnValue = -2;
+          }
+
+       return (i_ReturnValue);
+       }
+
+
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     : _INT_ i_APCI1710_GetUASStatus                          |
+|                               (BYTE_   b_BoardHandle,                      |
+|                                BYTE_   b_ModulNbr,                         |
+|                                PBYTE_ pb_UASStatus)                        |
++----------------------------------------------------------------------------+
+| Task              : Return the error signal (UAS) status                   |
++----------------------------------------------------------------------------+
+| Input Parameters  : BYTE_ b_BoardHandle     : Handle of board APCI-1710    |
+|                     BYTE_ b_ModulNbr        : Module number to configure   |
+|                                               (0 to 3)                     |
++----------------------------------------------------------------------------+
+| Output Parameters : PBYTE_ pb_UASStatus      : 0 : UAS is low "0"          |
+|                                                1 : UAS is high "1"         |
++----------------------------------------------------------------------------+
+| Return Value      :  0: No error                                           |
+|                     -1: The handle parameter of the board is wrong         |
+|                     -2: No counter module found                            |
+|                     -3: Counter not initialised see function               |
+|                         "i_APCI1710_InitCounter"                           |
++----------------------------------------------------------------------------+
+*/
+
+INT   i_APCI1710_GetUASStatus (comedi_device *dev,
+                                BYTE   b_ModulNbr,
+                                PBYTE pb_UASStatus)
+       {
+       INT    i_ReturnValue = 0;
+       DWORD dw_StatusReg   = 0;
+       
+       
+       /**************************/
+       /* Test the module number */
+       /**************************/
+
+       if (b_ModulNbr < 4)
+          {
+          /*******************************/
+          /* Test if counter initialised */
+          /*******************************/
+
+          if (devpriv->
+              s_ModuleInfo [b_ModulNbr].
+              s_SiemensCounterInfo.
+              s_InitFlag.
+              b_CounterInit == 1)
+             {
+                  dw_StatusReg=inl(devpriv->s_BoardInfos.
+                     ui_Address + 24 + (64 * b_ModulNbr));
+
+             *pb_UASStatus = (BYTE) ((dw_StatusReg >> 1) & 1);
+             }
+          else
+             {
+             /****************************************/
+             /* Counter not initialised see function */
+             /* "i_APCI1710_InitCounter"             */
+             /****************************************/
+
+             DPRINTK("Counter not initialised\n");     
+             i_ReturnValue = -3;
+             }
+          }
+       else
+          {
+          /*************************************************/
+          /* The selected module number parameter is wrong */
+          /*************************************************/
+
+          DPRINTK("The selected module number parameter is wrong\n");  
+          i_ReturnValue = -2;
+       
+          }
+
+       return (i_ReturnValue);
+       }
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     : _INT_ i_APCI1710_GetCBStatus                           |
+|                               (BYTE_   b_BoardHandle,                      |
+|                                BYTE_   b_ModulNbr,                         |
+|                                PBYTE_ pb_CBStatus)                         |
++----------------------------------------------------------------------------+
+| Task              : Return the counter overflow status                     |
++----------------------------------------------------------------------------+
+| Input Parameters  : BYTE_ b_BoardHandle     : Handle of board APCI-1710    |
+|                     BYTE_ b_ModulNbr        : Module number to configure   |
+|                                               (0 to 3)                     |
++----------------------------------------------------------------------------+
+| Output Parameters : PBYTE_ pb_CBStatus      : 0 : Counter no overflow      |
+|                                               1 : Counter overflow         |
++----------------------------------------------------------------------------+
+| Return Value      :  0: No error                                           |
+|                     -1: The handle parameter of the board is wrong         |
+|                     -2: No counter module found                            |
+|                     -3: Counter not initialised see function               |
+|                         "i_APCI1710_InitCounter"                           |
++----------------------------------------------------------------------------+
+*/
+
+INT   i_APCI1710_GetCBStatus  (comedi_device *dev,
+                                BYTE   b_ModulNbr,
+                                PBYTE pb_CBStatus)
+       {
+       INT    i_ReturnValue = 0;
+       DWORD dw_StatusReg   = 0;
+       
+
+       
+       /**************************/
+       /* Test the module number */
+       /**************************/
+
+       if (b_ModulNbr < 4)
+          {
+          /*******************************/
+          /* Test if counter initialised */
+          /*******************************/
+
+          if (devpriv->
+              s_ModuleInfo [b_ModulNbr].
+              s_SiemensCounterInfo.
+              s_InitFlag.
+              b_CounterInit == 1)
+             {
+                       dw_StatusReg=inl(devpriv->s_BoardInfos.
+                     ui_Address + 16 + (64 * b_ModulNbr));
+
+             *pb_CBStatus = (BYTE) (dw_StatusReg & 1);
+                             
+             }
+          else
+             {
+             /****************************************/
+             /* Counter not initialised see function */
+             /* "i_APCI1710_InitCounter"             */
+             /****************************************/
+
+             DPRINTK("Counter not initialised\n");     
+             i_ReturnValue = -3;
+             }
+          }
+       else
+          {
+          /*************************************************/
+          /* The selected module number parameter is wrong */
+          /*************************************************/
+
+          DPRINTK("The selected module number parameter is wrong\n");  
+          i_ReturnValue = -2;
+          }
+
+       return (i_ReturnValue);
+       }
+
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     : _INT_ i_APCI1710_Get16BitCBStatus                      |
+|                                      (BYTE_     b_BoardHandle,            |
+|                                       BYTE_     b_ModulNbr,               |
+|                                       PBYTE_ pb_CBStatusCounter0,         |
+|                                       PBYTE_ pb_CBStatusCounter1)         |
++----------------------------------------------------------------------------+
+| Task              : Returns the counter overflow (counter initialised to   |
+|                    2*16-bit) status from selected incremental counter     |
+|                    module                                                 |
++----------------------------------------------------------------------------+
+| Input Parameters  : BYTE_ b_BoardHandle     : Handle of board APCI-1710    |
+|                     BYTE_ b_ModulNbr        : Module number to configure   |
+|                                               (0 to 3)                     |
++----------------------------------------------------------------------------+
+| Output Parameters : PBYTE_ pb_CBStatusCounter0 : 0 : No overflow occur for |
+|                                                     the first 16-bit      |
+|                                                     counter               |
+|                                                 1 : Overflow occur for the|
+|                                                     first 16-bit counter  |
+|                    PBYTE_ pb_CBStatusCounter1 : 0 : No overflow occur for |
+|                                                     the second 16-bit     |
+|                                                     counter               |
+|                                                 1 : Overflow occur for the|
+|                                                     second 16-bit counter |
++----------------------------------------------------------------------------+
+| Return Value      :  0: No error                                           |
+|                     -1: The handle parameter of the board is wrong         |
+|                     -2: No counter module found                            |
+|                     -3: Counter not initialised see function               |
+|                         "i_APCI1710_InitCounter"                           |
+|                     -4: Counter not initialised to 2*16-bit mode.          |
+|                        See function "i_APCI1710_InitCounter"              |
+|                     -5: Firmware revision error                            |
++----------------------------------------------------------------------------+
+*/
+
+INT    i_APCI1710_Get16BitCBStatus     (comedi_device *dev,
+                                        BYTE     b_ModulNbr,
+                                        PBYTE pb_CBStatusCounter0,
+                                        PBYTE pb_CBStatusCounter1)
+       {
+       INT    i_ReturnValue = 0;
+       DWORD dw_StatusReg   = 0;
+       
+
+       
+       /**************************/
+       /* Test the module number */
+       /**************************/
+
+       if (b_ModulNbr < 4)
+          {
+          /*******************************/
+          /* Test if counter initialised */
+          /*******************************/
+
+          if (devpriv->
+              s_ModuleInfo [b_ModulNbr].
+              s_SiemensCounterInfo.
+              s_InitFlag.
+              b_CounterInit == 1)
+             {
+             /*************************/
+             /* Test if 2*16-Bit mode */
+             /*************************/
+
+             if ((devpriv->
+                  s_ModuleInfo [b_ModulNbr].
+                  s_SiemensCounterInfo.
+                  s_ModeRegister.
+                  s_ByteModeRegister.
+                  b_ModeRegister1 & 0x10) == 0x10)
+                {
+                /*****************************/
+                /* Test the Firmware version */
+                /*****************************/
+
+                if ((devpriv->
+                     s_BoardInfos.
+                     dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) >= 0x3136)
+                   {
+                        dw_StatusReg=inl(devpriv->s_BoardInfos.
+                           ui_Address + 16 + (64 * b_ModulNbr));
+
+                   *pb_CBStatusCounter1 = (BYTE) ((dw_StatusReg >> 0) & 1);
+                   *pb_CBStatusCounter0 = (BYTE) ((dw_StatusReg >> 1) & 1);
+                   } // if ((ps_APCI1710Variable->s_Board [b_BoardHandle].s_BoardInfos.dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) >= 0x3136)
+                else
+                   {
+                   /****************************/
+                   /* Firmware revision error  */
+                   /****************************/
+
+                   i_ReturnValue = -5;
+                   } // if ((ps_APCI1710Variable->s_Board [b_BoardHandle].s_BoardInfos.dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) >= 0x3136)
+                } // if ((ps_APCI1710Variable->s_Board [b_BoardHandle].s_ModuleInfo [b_ModulNbr].s_SiemensCounterInfo.s_ModeRegister.s_ByteModeRegister.b_ModeRegister1 & 0x10) == 0x10)
+             else
+                {
+                /********************************************/
+                /* Counter not initialised to 2*16-bit mode */
+                /* "i_APCI1710_InitCounter"                 */
+                /********************************************/
+
+                DPRINTK("Counter not initialised\n");
+                i_ReturnValue = -4;
+                } // if ((ps_APCI1710Variable->s_Board [b_BoardHandle].s_ModuleInfo [b_ModulNbr].s_SiemensCounterInfo.s_ModeRegister.s_ByteModeRegister.b_ModeRegister1 & 0x10) == 0x10)
+             } // if (ps_APCI1710Variable->s_Board [b_BoardHandle].s_ModuleInfo [b_ModulNbr].s_SiemensCounterInfo.s_InitFlag.b_CounterInit == 1)
+          else
+             {
+             /****************************************/
+             /* Counter not initialised see function */
+             /* "i_APCI1710_InitCounter"             */
+             /****************************************/
+
+             DPRINTK("Counter not initialised\n");             
+             i_ReturnValue = -3;
+             } // if (ps_APCI1710Variable->s_Board [b_BoardHandle].s_ModuleInfo [b_ModulNbr].s_SiemensCounterInfo.s_InitFlag.b_CounterInit == 1)
+          } // if (b_ModulNbr < 4)
+       else
+          {
+          /*************************************************/
+          /* The selected module number parameter is wrong */
+          /*************************************************/
+
+          DPRINTK("The selected module number parameter is wrong\n");
+          i_ReturnValue = -2;
+          } // if (b_ModulNbr < 4)
+
+       return (i_ReturnValue);
+       }
+
+
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     : _INT_ i_APCI1710_GetUDStatus                           |
+|                               (BYTE_   b_BoardHandle,                      |
+|                                BYTE_   b_ModulNbr,                         |
+|                                PBYTE_ pb_UDStatus)                         |
++----------------------------------------------------------------------------+
+| Task              : Return the counter progress status                     |
++----------------------------------------------------------------------------+
+| Input Parameters  : BYTE_ b_BoardHandle     : Handle of board APCI-1710    |
+|                     BYTE_ b_ModulNbr        : Module number to configure   |
+|                                               (0 to 3)                     |
++----------------------------------------------------------------------------+
+| Output Parameters : PBYTE_ pb_UDStatus      : 0 : Counter progress in the  |
+|                                                   selected mode down       |
+|                                               1 : Counter progress in the  |
+|                                                   selected mode up         |
++----------------------------------------------------------------------------+
+| Return Value      :  0: No error                                           |
+|                     -1: The handle parameter of the board is wrong         |
+|                     -2: No counter module found                            |
+|                     -3: Counter not initialised see function               |
+|                         "i_APCI1710_InitCounter"                           |
++----------------------------------------------------------------------------+
+*/
+
+INT   i_APCI1710_GetUDStatus  (comedi_device *dev,
+                                BYTE   b_ModulNbr,
+                                PBYTE pb_UDStatus)
+       {
+       INT    i_ReturnValue = 0;
+       DWORD dw_StatusReg   = 0;
+       
+       
+       /**************************/
+       /* Test the module number */
+       /**************************/
+
+       if (b_ModulNbr < 4)
+          {
+          /*******************************/
+          /* Test if counter initialised */
+          /*******************************/
+
+          if (devpriv->
+              s_ModuleInfo [b_ModulNbr].
+              s_SiemensCounterInfo.
+              s_InitFlag.
+              b_CounterInit == 1)
+             {
+                  dw_StatusReg=inl(devpriv->s_BoardInfos.
+                     ui_Address + 24 + (64 * b_ModulNbr));
+
+             *pb_UDStatus = (BYTE) ((dw_StatusReg >> 2) & 1);
+               
+             }
+          else
+             {
+             /****************************************/
+             /* Counter not initialised see function */
+             /* "i_APCI1710_InitCounter"             */
+             /****************************************/
+
+             DPRINTK("Counter not initialised\n");     
+             i_ReturnValue = -3;
+             }
+          }
+       else
+          {
+          /*************************************************/
+          /* The selected module number parameter is wrong */
+          /*************************************************/
+
+          DPRINTK("The selected module number parameter is wrong\n");  
+          i_ReturnValue = -2;
+          }
+
+       return (i_ReturnValue);
+       }
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     : _INT_ i_APCI1710_GetInterruptUDLatchedStatus           |
+|                               (BYTE_   b_BoardHandle,                      |
+|                                BYTE_   b_ModulNbr,                         |
+|                                PBYTE_ pb_UDStatus)                         |
++----------------------------------------------------------------------------+
+| Task              : Return the counter progress latched status after a     |
+|                     index interrupt occur.                                 |
++----------------------------------------------------------------------------+
+| Input Parameters  : BYTE_ b_BoardHandle     : Handle of board APCI-1710    |
+|                     BYTE_ b_ModulNbr        : Module number to configure   |
+|                                               (0 to 3)                     |
++----------------------------------------------------------------------------+
+| Output Parameters : PBYTE_ pb_UDStatus      : 0 : Counter progress in the  |
+|                                                   selected mode down       |
+|                                               1 : Counter progress in the  |
+|                                                   selected mode up         |
+|                                               2 : No index interrupt occur |
++----------------------------------------------------------------------------+
+| Return Value      :  0: No error                                           |
+|                     -1: The handle parameter of the board is wrong         |
+|                     -2: No counter module found                            |
+|                     -3: Counter not initialised see function               |
+|                         "i_APCI1710_InitCounter"                           |
+|                     -4: Interrupt function not initialised.                |
+|                         See function "i_APCI1710_SetBoardIntRoutineX"      |
++----------------------------------------------------------------------------+
+*/
+
+INT   i_APCI1710_GetInterruptUDLatchedStatus  (comedi_device *dev,
+                                                BYTE   b_ModulNbr,
+                                                PBYTE pb_UDStatus)
+       {
+       INT    i_ReturnValue = 0;
+       DWORD dw_StatusReg   = 0;
+       
+
+       /**************************/
+       /* Test the module number */
+       /**************************/
+
+       if (b_ModulNbr < 4)
+          {
+          /*******************************/
+          /* Test if counter initialised */
+          /*******************************/
+
+          if (devpriv->
+              s_ModuleInfo [b_ModulNbr].
+              s_SiemensCounterInfo.
+              s_InitFlag.
+              b_CounterInit == 1)
+             {
+                /*********************************/
+                /* Test if index interrupt occur */
+                /*********************************/
+
+                if (devpriv->
+                    s_ModuleInfo [b_ModulNbr].
+                    s_SiemensCounterInfo.
+                    s_InitFlag.
+                    b_IndexInterruptOccur == 1)
+                   {
+                   devpriv->
+                   s_ModuleInfo [b_ModulNbr].
+                   s_SiemensCounterInfo.
+                   s_InitFlag.
+                   b_IndexInterruptOccur = 0;
+
+                       dw_StatusReg=inl(devpriv->s_BoardInfos.
+                           ui_Address + 12 + (64 * b_ModulNbr));
+
+                   *pb_UDStatus = (BYTE) ((dw_StatusReg >> 1) & 1);
+                   }
+                else
+                   {
+                   /****************************/
+                   /* No index interrupt occur */
+                   /****************************/
+
+                   *pb_UDStatus = 2;
+                   }
+             }
+          else
+             {
+             /****************************************/
+             /* Counter not initialised see function */
+             /* "i_APCI1710_InitCounter"             */
+             /****************************************/
+
+             DPRINTK("Counter not initialised\n");     
+             i_ReturnValue = -3;
+             }
+          }
+       else
+          {
+          /*************************************************/
+          /* The selected module number parameter is wrong */
+          /*************************************************/
+
+          DPRINTK("The selected module number parameter is wrong\n");  
+          i_ReturnValue = -2;
+          }
+
+       return (i_ReturnValue);
+       }
+
+
+       /*
++----------------------------------------------------------------------------+
+| Function Name     : _INT_ i_APCI1710_ReadFrequencyMeasurement              |
+|                              (BYTE_            b_BoardHandle,             |
+|                               BYTE_            b_ModulNbr,                |
+|                               PBYTE_          pb_Status,                  |
+|                               PULONG_        pul_ReadValue)               |
++----------------------------------------------------------------------------+
+| Task              : Returns the status (pb_Status) and the number of       |
+|                    increments in the set time.                            |
+|                    See function " i_APCI1710_InitFrequencyMeasurement "   |
++----------------------------------------------------------------------------+
+| Input Parameters  : BYTE_  b_BoardHandle    : Handle of board APCI-1710    |
+|                    BYTE_  b_ModulNbr       : Number of the module to be   |
+|                                              configured (0 to 3)          |
++----------------------------------------------------------------------------+
+| Output Parameters : PBYTE_   pb_Status     : Returns the frequency        |
+|                                              measurement status           |
+|                                              0 : Counting cycle not       |
+|                                                  started.                 |
+|                                              1 : Counting cycle started.  |
+|                                              2 : Counting cycle stopped.  |
+|                                                  The measurement cycle is |
+|                                                  completed.               |
+|                    PBYTE_ pb_UDStatus      : 0 : Counter progress in the  |
+|                                                   selected mode down       |
+|                                               1 : Counter progress in the  |
+|                                                   selected mode up         |
+|                    PULONG_ pul_ReadValue   : Return the number of         |
+|                                              increments in the defined    |
+|                                              time base.                   |
++----------------------------------------------------------------------------+
+| Return Value      :  0: No error                                           |
+|                     -1: The handle parameter of the board is wrong         |
+|                     -2: The selected module number is wrong                |
+|                     -3: Counter not initialised see function               |
+|                        "i_APCI1710_InitCounter"                           |
+|                     -4: Frequency measurement logic not initialised.       |
+|                        See function "i_APCI1710_InitFrequencyMeasurement" |
++----------------------------------------------------------------------------+
+*/
+
+INT    i_APCI1710_ReadFrequencyMeasurement (comedi_device *dev,
+                                            BYTE        b_ModulNbr,
+                                            PBYTE       pb_Status,
+                                            PBYTE       pb_UDStatus,
+                                            PULONG      pul_ReadValue)
+       {
+       INT    i_ReturnValue = 0;
+       UINT  ui_16BitValue;
+       DWORD dw_StatusReg;
+       
+
+
+       /**************************/
+       /* Test the module number */
+       /**************************/
+
+       if (b_ModulNbr < 4)
+          {
+          /*******************************/
+          /* Test if counter initialised */
+          /*******************************/
+
+          if (devpriv->
+              s_ModuleInfo [b_ModulNbr].
+              s_SiemensCounterInfo.
+              s_InitFlag.
+              b_CounterInit == 1)
+             {
+             /********************************************/
+             /* Test if frequency mesurement initialised */
+             /********************************************/
+
+             if (devpriv->
+                 s_ModuleInfo [b_ModulNbr].
+                 s_SiemensCounterInfo.
+                 s_InitFlag.
+                 b_FrequencyMeasurementInit == 1)
+                {
+                /******************/
+                /* Test if enable */
+                /******************/
+
+                if (devpriv->
+                    s_ModuleInfo [b_ModulNbr].
+                    s_SiemensCounterInfo.
+                    s_InitFlag.
+                    b_FrequencyMeasurementEnable == 1)
+                   {
+                   /*******************/
+                   /* Read the status */
+                   /*******************/
+
+                        dw_StatusReg=inl(devpriv->s_BoardInfos.
+                          ui_Address + 32 + (64 * b_ModulNbr));
+
+                   /**************************/
+                   /* Test if frequency stop */
+                   /**************************/
+
+                   if (dw_StatusReg & 1)
+                      {
+                      *pb_Status   = 2;
+                      *pb_UDStatus = (BYTE) ((dw_StatusReg >> 1) & 3);
+
+                      /******************/
+                      /* Read the value */
+                      /******************/
+
+                          *pul_ReadValue=inl(devpriv->s_BoardInfos.
+                             ui_Address + 28 + (64 * b_ModulNbr));
+                                                    
+
+                      if (*pb_UDStatus == 0)
+                         {
+                         /*************************/
+                         /* Test the counter mode */
+                         /*************************/
+
+                         if ((devpriv->
+                              s_ModuleInfo [b_ModulNbr].
+                              s_SiemensCounterInfo.
+                              s_ModeRegister.
+                              s_ByteModeRegister.
+                              b_ModeRegister1 & APCI1710_16BIT_COUNTER) == APCI1710_16BIT_COUNTER)
+                            {
+                            /****************************************/
+                            /* Test if 16-bit counter 1 pulse occur */
+                            /****************************************/
+
+                            if ((*pul_ReadValue & 0xFFFFU) != 0)
+                               {
+                               ui_16BitValue  = (UINT) *pul_ReadValue & 0xFFFFU;
+                               *pul_ReadValue = (*pul_ReadValue & 0xFFFF0000UL) | (0xFFFFU - ui_16BitValue);
+                               }
+
+                            /****************************************/
+                            /* Test if 16-bit counter 2 pulse occur */
+                            /****************************************/
+
+                            if ((*pul_ReadValue & 0xFFFF0000UL) != 0)
+                               {
+                               ui_16BitValue  = (UINT) ((*pul_ReadValue >> 16) & 0xFFFFU);
+                               *pul_ReadValue = (*pul_ReadValue & 0xFFFFUL) | ((0xFFFFU - ui_16BitValue) << 16);
+                               }
+                            }
+                         else
+                            {
+                            if (*pul_ReadValue != 0)
+                               {
+                               *pul_ReadValue = 0xFFFFFFFFUL - *pul_ReadValue;
+                               }
+                            }
+                         }
+                      else
+                         {
+                         if (*pb_UDStatus == 1)
+                            {
+                            /****************************************/
+                            /* Test if 16-bit counter 2 pulse occur */
+                            /****************************************/
+
+                            if ((*pul_ReadValue & 0xFFFF0000UL) != 0)
+                               {
+                               ui_16BitValue  = (UINT) ((*pul_ReadValue >> 16) & 0xFFFFU);
+                               *pul_ReadValue = (*pul_ReadValue & 0xFFFFUL) | ((0xFFFFU - ui_16BitValue) << 16);
+                               }
+                            }
+                         else
+                            {
+                            if (*pb_UDStatus == 2)
+                               {
+                               /****************************************/
+                               /* Test if 16-bit counter 1 pulse occur */
+                               /****************************************/
+
+                               if ((*pul_ReadValue & 0xFFFFU) != 0)
+                                  {
+                                  ui_16BitValue  = (UINT) *pul_ReadValue & 0xFFFFU;
+                                  *pul_ReadValue = (*pul_ReadValue & 0xFFFF0000UL) | (0xFFFFU - ui_16BitValue);
+                                  }
+                               }
+                            }
+                         }
+                      }
+                   else
+                      {
+                      *pb_Status   = 1;
+                      *pb_UDStatus = 0;
+                      }
+                   }
+                else
+                   {
+                   *pb_Status   = 0;
+                   *pb_UDStatus = 0;
+                   }
+                }
+             else
+                {
+                /***********************************************/
+                /* Frequency measurement logic not initialised */
+                /***********************************************/
+
+                DPRINTK("Frequency measurement logic not initialised\n");
+                i_ReturnValue = -4;
+                }
+             }
+          else
+             {
+             /****************************************/
+             /* Counter not initialised see function */
+             /* "i_APCI1710_InitCounter"             */
+             /****************************************/
+
+             DPRINTK("Counter not initialised\n");     
+             i_ReturnValue = -3;
+             }
+          }
+       else
+          {
+          /*************************************************/
+          /* The selected module number parameter is wrong */
+          /*************************************************/
+
+          DPRINTK("The selected module number parameter is wrong\n");
+          i_ReturnValue = -2;
+          }
+
+       return (i_ReturnValue);
+       }
index 9824970dac0beb2790d1bd03a2fbde0fe4062461..cdb8d0e19b966afcd62058532fad4fd61eb0b0e9 100644 (file)
-/**\r
-@verbatim\r
-\r
-Copyright (C) 2004,2005  ADDI-DATA GmbH for the source code of this module. \r
-        \r
-        ADDI-DATA GmbH \r
-        Dieselstrasse 3 \r
-        D-77833 Ottersweier \r
-        Tel: +19(0)7223/9493-0 \r
-        Fax: +49(0)7223/9493-92 \r
-        http://www.addi-data-com \r
-        info@addi-data.com \r
-\r
-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.\r
-\r
-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.\r
-\r
-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 USA\r
-\r
-You shoud also find the complete GPL in the COPYING file accompanying this source code.\r
-\r
-@endverbatim\r
-*/\r
-\r
-\r
-#define APCI1710_16BIT_COUNTER                         0x10\r
-#define APCI1710_32BIT_COUNTER                         0x0\r
-#define APCI1710_QUADRUPLE_MODE                        0x0\r
-#define APCI1710_DOUBLE_MODE                           0x3\r
-#define APCI1710_SIMPLE_MODE                           0xF\r
-#define APCI1710_DIRECT_MODE                           0x80\r
-#define APCI1710_HYSTERESIS_ON                         0x60\r
-#define APCI1710_HYSTERESIS_OFF                        0x0\r
-#define APCI1710_INCREMENT                             0x60\r
-#define APCI1710_DECREMENT                             0x0\r
-#define APCI1710_LATCH_COUNTER                         0x1\r
-#define APCI1710_CLEAR_COUNTER                         0x0\r
-#define APCI1710_LOW                                   0x0\r
-#define APCI1710_HIGH                                  0x1\r
-\r
-/*********************/\r
-/* Version 0600-0229 */\r
-/*********************/\r
-\r
-#define APCI1710_HIGH_EDGE_CLEAR_COUNTER               0x0\r
-#define APCI1710_HIGH_EDGE_LATCH_COUNTER               0x1\r
-#define APCI1710_LOW_EDGE_CLEAR_COUNTER                0x2\r
-#define APCI1710_LOW_EDGE_LATCH_COUNTER                0x3\r
-#define APCI1710_HIGH_EDGE_LATCH_AND_CLEAR_COUNTER     0x4\r
-#define APCI1710_LOW_EDGE_LATCH_AND_CLEAR_COUNTER      0x5\r
-#define APCI1710_SOURCE_0                              0x0\r
-#define APCI1710_SOURCE_1                              0x1\r
-\r
-\r
-\r
-#define APCI1710_30MHZ           30\r
-#define APCI1710_33MHZ           33\r
-#define APCI1710_40MHZ           40\r
-\r
-\r
-#define APCI1710_ENABLE_LATCH_INT              0x80\r
-#define APCI1710_DISABLE_LATCH_INT             (~APCI1710_ENABLE_LATCH_INT)\r
-\r
-#define APCI1710_INDEX_LATCH_COUNTER           0x10\r
-#define APCI1710_INDEX_AUTO_MODE               0x8\r
-#define APCI1710_ENABLE_INDEX                  0x4\r
-#define APCI1710_DISABLE_INDEX                 (~APCI1710_ENABLE_INDEX)\r
-#define APCI1710_ENABLE_LATCH_AND_CLEAR        0x8\r
-#define APCI1710_DISABLE_LATCH_AND_CLEAR       (~APCI1710_ENABLE_LATCH_AND_CLEAR)\r
-#define APCI1710_SET_LOW_INDEX_LEVEL           0x4\r
-#define APCI1710_SET_HIGH_INDEX_LEVEL           (~APCI1710_SET_LOW_INDEX_LEVEL)\r
-#define APCI1710_INVERT_INDEX_RFERENCE         0x2\r
-#define APCI1710_DEFAULT_INDEX_RFERENCE         (~APCI1710_INVERT_INDEX_RFERENCE)\r
-\r
-#define APCI1710_ENABLE_INDEX_INT              0x1\r
-#define APCI1710_DISABLE_INDEX_INT             (~APCI1710_ENABLE_INDEX_INT)\r
-\r
-#define APCI1710_ENABLE_FREQUENCY              0x4\r
-#define APCI1710_DISABLE_FREQUENCY             (~APCI1710_ENABLE_FREQUENCY)\r
-\r
-#define APCI1710_ENABLE_FREQUENCY_INT          0x8\r
-#define APCI1710_DISABLE_FREQUENCY_INT         (~APCI1710_ENABLE_FREQUENCY_INT)\r
-\r
-#define APCI1710_ENABLE_40MHZ_FREQUENCY                0x40\r
-#define APCI1710_DISABLE_40MHZ_FREQUENCY       (~APCI1710_ENABLE_40MHZ_FREQUENCY)\r
-\r
-#define APCI1710_ENABLE_40MHZ_FILTER           0x80\r
-#define APCI1710_DISABLE_40MHZ_FILTER          (~APCI1710_ENABLE_40MHZ_FILTER)\r
-\r
-#define APCI1710_ENABLE_COMPARE_INT            0x2\r
-#define APCI1710_DISABLE_COMPARE_INT           (~APCI1710_ENABLE_COMPARE_INT)\r
-\r
-#define APCI1710_ENABLE_INDEX_ACTION           0x20\r
-#define APCI1710_DISABLE_INDEX_ACTION          (~APCI1710_ENABLE_INDEX_ACTION)\r
-#define APCI1710_REFERENCE_HIGH                0x40\r
-#define APCI1710_REFERENCE_LOW                 (~APCI1710_REFERENCE_HIGH)\r
-\r
-\r
-   #define APCI1710_TOR_GATE_LOW               0x40\r
-   #define APCI1710_TOR_GATE_HIGH              (~APCI1710_TOR_GATE_LOW)\r
-\r
-\r
-//     INSN CONFIG \r
-#define        APCI1710_INCCPT_INITCOUNTER                                                     100\r
-#define APCI1710_INCCPT_COUNTERAUTOTEST                                                101\r
-#define APCI1710_INCCPT_INITINDEX                                                      102\r
-#define APCI1710_INCCPT_INITREFERENCE                                          103\r
-#define APCI1710_INCCPT_INITEXTERNALSTROBE                                     104\r
-#define APCI1710_INCCPT_INITCOMPARELOGIC                                       105\r
-#define APCI1710_INCCPT_INITFREQUENCYMEASUREMENT                       106\r
-\r
-// INSN READ\r
-#define APCI1710_INCCPT_READLATCHREGISTERSTATUS                                200                                              \r
-#define APCI1710_INCCPT_READLATCHREGISTERVALUE                         201\r
-#define APCI1710_INCCPT_READ16BITCOUNTERVALUE                          202        \r
-#define APCI1710_INCCPT_READ32BITCOUNTERVALUE                          203\r
-#define APCI1710_INCCPT_GETINDEXSTATUS                                         204\r
-#define APCI1710_INCCPT_GETREFERENCESTATUS                                     205\r
-#define APCI1710_INCCPT_GETUASSTATUS                                           206\r
-#define APCI1710_INCCPT_GETCBSTATUS                                                    207\r
-#define APCI1710_INCCPT_GET16BITCBSTATUS                                       208\r
-#define APCI1710_INCCPT_GETUDSTATUS                                                    209\r
-#define APCI1710_INCCPT_GETINTERRUPTUDLATCHEDSTATUS                    210\r
-#define APCI1710_INCCPT_READFREQUENCYMEASUREMENT                       211\r
-#define APCI1710_INCCPT_READINTERRUPT                       212\r
-\r
-//INSN BITS\r
-#define APCI1710_INCCPT_CLEARCOUNTERVALUE                                      300\r
-#define APCI1710_INCCPT_CLEARALLCOUNTERVALUE                           301\r
-#define APCI1710_INCCPT_SETINPUTFILTER                                         302\r
-#define APCI1710_INCCPT_LATCHCOUNTER                                           303\r
-#define APCI1710_INCCPT_SETINDEXANDREFERENCESOURCE                     304\r
-#define APCI1710_INCCPT_SETDIGITALCHLON                                                305\r
-#define APCI1710_INCCPT_SETDIGITALCHLOFF                                       306\r
-\r
-// INSN WRITE\r
-#define APCI1710_INCCPT_ENABLELATCHINTERRUPT                           400\r
-#define APCI1710_INCCPT_DISABLELATCHINTERRUPT                          401\r
-#define APCI1710_INCCPT_WRITE16BITCOUNTERVALUE                         402\r
-#define APCI1710_INCCPT_WRITE32BITCOUNTERVALUE                         403\r
-#define APCI1710_INCCPT_ENABLEINDEX                                                    404     \r
-#define APCI1710_INCCPT_DISABLEINDEX                                           405\r
-#define APCI1710_INCCPT_ENABLECOMPARELOGIC                                     406     \r
-#define APCI1710_INCCPT_DISABLECOMPARELOGIC                                    407\r
-#define APCI1710_INCCPT_ENABLEFREQUENCYMEASUREMENT                     408\r
-#define APCI1710_INCCPT_DISABLEFREQUENCYMEASUREMENT                    409\r
-\r
-\r
-/************ Main Functions *************/  \r
-INT    i_APCI1710_InsnConfigINCCPT(comedi_device *dev,comedi_subdevice *s,\r
-comedi_insn *insn,lsampl_t *data);\r
-\r
-INT    i_APCI1710_InsnBitsINCCPT(comedi_device *dev,comedi_subdevice *s,\r
-comedi_insn *insn,lsampl_t *data);\r
-\r
-INT    i_APCI1710_InsnWriteINCCPT(comedi_device *dev,comedi_subdevice *s,\r
-comedi_insn *insn,lsampl_t *data);\r
-\r
-INT    i_APCI1710_InsnReadINCCPT(comedi_device *dev,comedi_subdevice *s,\r
-comedi_insn *insn,lsampl_t *data);\r
-\r
-/*********** Supplementary Functions********/\r
-\r
-\r
-// INSN CONFIG\r
-\r
-INT   i_APCI1710_InitCounter (comedi_device *dev,\r
-                               BYTE          b_ModulNbr,\r
-                               BYTE          b_CounterRange,\r
-                               BYTE          b_FirstCounterModus,\r
-                               BYTE          b_FirstCounterOption,\r
-                               BYTE          b_SecondCounterModus,\r
-                               BYTE          b_SecondCounterOption);\r
-\r
-INT  i_APCI1710_CounterAutoTest  (comedi_device *dev,PBYTE   pb_TestStatus);\r
-\r
-INT   i_APCI1710_InitIndex    (comedi_device *dev,\r
-                                BYTE b_ModulNbr,\r
-                                BYTE b_ReferenceAction,\r
-                                BYTE b_IndexOperation,\r
-                                BYTE b_AutoMode,\r
-                                BYTE b_InterruptEnable);\r
-\r
-INT   i_APCI1710_InitReference        (comedi_device *dev,\r
-                                        BYTE b_ModulNbr,\r
-                                        BYTE b_ReferenceLevel);\r
-\r
-INT    i_APCI1710_InitExternalStrobe   (comedi_device *dev,\r
-                                        BYTE b_ModulNbr,\r
-                                        BYTE b_ExternalStrobe,\r
-                                        BYTE b_ExternalStrobeLevel);\r
-\r
-INT   i_APCI1710_InitCompareLogic     (comedi_device *dev,\r
-                                        BYTE   b_ModulNbr,\r
-                                        UINT  ui_CompareValue);\r
-\r
-INT    i_APCI1710_InitFrequencyMeasurement     (comedi_device *dev,\r
-                                                BYTE            b_ModulNbr,\r
-                                                BYTE            b_PCIInputClock,\r
-                                                BYTE            b_TimingUnity,\r
-                                                ULONG           ul_TimingInterval,\r
-                                                PULONG      pul_RealTimingInterval);\r
-\r
-\r
-//INSN BITS\r
-\r
-INT   i_APCI1710_ClearCounterValue    (comedi_device *dev,\r
-                                        BYTE b_ModulNbr);\r
-\r
-INT   i_APCI1710_ClearAllCounterValue (comedi_device *dev);\r
-\r
-INT    i_APCI1710_SetInputFilter       (comedi_device *dev,\r
-                                                                       BYTE b_ModulNbr,\r
-                                    BYTE b_PCIInputClock,\r
-                                                                       BYTE b_Filter);\r
-\r
-INT   i_APCI1710_LatchCounter (comedi_device *dev,\r
-                                BYTE b_ModulNbr,\r
-                                BYTE b_LatchReg);\r
-\r
-INT    i_APCI1710_SetIndexAndReferenceSource   (comedi_device *dev,\r
-                                                BYTE b_ModulNbr,\r
-                                                BYTE b_SourceSelection);\r
-\r
-INT    i_APCI1710_SetDigitalChlOn (comedi_device *dev,\r
-                                   BYTE  b_ModulNbr);\r
-\r
-INT    i_APCI1710_SetDigitalChlOff (comedi_device *dev,\r
-                                    BYTE  b_ModulNbr);\r
-\r
-\r
-// INSN WRITE\r
-INT  i_APCI1710_EnableLatchInterrupt (comedi_device *dev,\r
-                                        BYTE b_ModulNbr);\r
-\r
-\r
-INT   i_APCI1710_DisableLatchInterrupt        (comedi_device *dev,\r
-                                                BYTE b_ModulNbr);\r
-\r
-INT   i_APCI1710_Write16BitCounterValue       (comedi_device *dev,\r
-                                                BYTE  b_ModulNbr,\r
-                                                BYTE  b_SelectedCounter,\r
-                                                UINT  ui_WriteValue);\r
-\r
-INT   i_APCI1710_Write32BitCounterValue       (comedi_device *dev,\r
-                                                BYTE   b_ModulNbr,\r
-                                                ULONG ul_WriteValue);\r
-\r
-INT   i_APCI1710_EnableIndex  (comedi_device *dev,\r
-                                BYTE b_ModulNbr);\r
-\r
-INT  i_APCI1710_DisableIndex (comedi_device *dev,\r
-                                BYTE b_ModulNbr);\r
-\r
-INT   i_APCI1710_EnableCompareLogic   (comedi_device *dev,\r
-                                        BYTE   b_ModulNbr);\r
-\r
-INT   i_APCI1710_DisableCompareLogic  (comedi_device *dev,\r
-                                        BYTE   b_ModulNbr);\r
-\r
-INT    i_APCI1710_EnableFrequencyMeasurement   (comedi_device *dev,\r
-                                                BYTE    b_ModulNbr,\r
-                                                BYTE    b_InterruptEnable);\r
-\r
-INT    i_APCI1710_DisableFrequencyMeasurement  (comedi_device *dev,\r
-                                                BYTE    b_ModulNbr);\r
-\r
-\r
-// INSN READ\r
-\r
-INT   i_APCI1710_ReadLatchRegisterStatus      (comedi_device *dev,\r
-                                                BYTE   b_ModulNbr,\r
-                                                BYTE   b_LatchReg,\r
-                                                PBYTE pb_LatchStatus);\r
-\r
-INT   i_APCI1710_ReadLatchRegisterValue       (comedi_device *dev,\r
-                                                BYTE     b_ModulNbr,\r
-                                                BYTE     b_LatchReg,\r
-                                                PULONG pul_LatchValue);\r
-\r
-INT   i_APCI1710_Read16BitCounterValue        (comedi_device *dev,\r
-                                                BYTE    b_ModulNbr,\r
-                                                BYTE    b_SelectedCounter,\r
-                                                PUINT pui_CounterValue);\r
-\r
-INT   i_APCI1710_Read32BitCounterValue        (comedi_device *dev,\r
-                                                BYTE      b_ModulNbr,\r
-                                                PULONG  pul_CounterValue);\r
-\r
-INT   i_APCI1710_GetIndexStatus      (comedi_device *dev,\r
-                                       BYTE   b_ModulNbr,\r
-                                       PBYTE pb_IndexStatus);\r
-\r
-INT   i_APCI1710_GetReferenceStatus      (comedi_device *dev,\r
-                                           BYTE   b_ModulNbr,\r
-                                           PBYTE  pb_ReferenceStatus);\r
-\r
-INT   i_APCI1710_GetUASStatus (comedi_device *dev,\r
-                                BYTE   b_ModulNbr,\r
-                                PBYTE pb_UASStatus);\r
-\r
-INT   i_APCI1710_GetCBStatus  (comedi_device *dev,\r
-                                BYTE   b_ModulNbr,\r
-                                PBYTE pb_CBStatus);\r
-\r
-INT   i_APCI1710_Get16BitCBStatus      (comedi_device *dev,\r
-                                        BYTE     b_ModulNbr,\r
-                                        PBYTE pb_CBStatusCounter0,\r
-                                        PBYTE pb_CBStatusCounter1);\r
-\r
-INT   i_APCI1710_GetUDStatus  (comedi_device *dev,\r
-                                BYTE   b_ModulNbr,\r
-                                PBYTE pb_UDStatus);\r
-\r
-INT   i_APCI1710_GetInterruptUDLatchedStatus  (comedi_device *dev,\r
-                                                BYTE   b_ModulNbr,\r
-                                                PBYTE pb_UDStatus);\r
-\r
-INT    i_APCI1710_ReadFrequencyMeasurement (comedi_device *dev,\r
-                                            BYTE        b_ModulNbr,\r
-                                            PBYTE       pb_Status,\r
-                                            PBYTE       pb_UDStatus,\r
-                                            PULONG      pul_ReadValue);\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
+/**
+@verbatim
+
+Copyright (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 USA
+
+You shoud also find the complete GPL in the COPYING file accompanying this source code.
+
+@endverbatim
+*/
+
+
+#define APCI1710_16BIT_COUNTER                         0x10
+#define APCI1710_32BIT_COUNTER                         0x0
+#define APCI1710_QUADRUPLE_MODE                        0x0
+#define APCI1710_DOUBLE_MODE                           0x3
+#define APCI1710_SIMPLE_MODE                           0xF
+#define APCI1710_DIRECT_MODE                           0x80
+#define APCI1710_HYSTERESIS_ON                         0x60
+#define APCI1710_HYSTERESIS_OFF                        0x0
+#define APCI1710_INCREMENT                             0x60
+#define APCI1710_DECREMENT                             0x0
+#define APCI1710_LATCH_COUNTER                         0x1
+#define APCI1710_CLEAR_COUNTER                         0x0
+#define APCI1710_LOW                                   0x0
+#define APCI1710_HIGH                                  0x1
+
+/*********************/
+/* Version 0600-0229 */
+/*********************/
+
+#define APCI1710_HIGH_EDGE_CLEAR_COUNTER               0x0
+#define APCI1710_HIGH_EDGE_LATCH_COUNTER               0x1
+#define APCI1710_LOW_EDGE_CLEAR_COUNTER                0x2
+#define APCI1710_LOW_EDGE_LATCH_COUNTER                0x3
+#define APCI1710_HIGH_EDGE_LATCH_AND_CLEAR_COUNTER     0x4
+#define APCI1710_LOW_EDGE_LATCH_AND_CLEAR_COUNTER      0x5
+#define APCI1710_SOURCE_0                              0x0
+#define APCI1710_SOURCE_1                              0x1
+
+
+
+#define APCI1710_30MHZ           30
+#define APCI1710_33MHZ           33
+#define APCI1710_40MHZ           40
+
+
+#define APCI1710_ENABLE_LATCH_INT              0x80
+#define APCI1710_DISABLE_LATCH_INT             (~APCI1710_ENABLE_LATCH_INT)
+
+#define APCI1710_INDEX_LATCH_COUNTER           0x10
+#define APCI1710_INDEX_AUTO_MODE               0x8
+#define APCI1710_ENABLE_INDEX                  0x4
+#define APCI1710_DISABLE_INDEX                 (~APCI1710_ENABLE_INDEX)
+#define APCI1710_ENABLE_LATCH_AND_CLEAR        0x8
+#define APCI1710_DISABLE_LATCH_AND_CLEAR       (~APCI1710_ENABLE_LATCH_AND_CLEAR)
+#define APCI1710_SET_LOW_INDEX_LEVEL           0x4
+#define APCI1710_SET_HIGH_INDEX_LEVEL           (~APCI1710_SET_LOW_INDEX_LEVEL)
+#define APCI1710_INVERT_INDEX_RFERENCE         0x2
+#define APCI1710_DEFAULT_INDEX_RFERENCE         (~APCI1710_INVERT_INDEX_RFERENCE)
+
+#define APCI1710_ENABLE_INDEX_INT              0x1
+#define APCI1710_DISABLE_INDEX_INT             (~APCI1710_ENABLE_INDEX_INT)
+
+#define APCI1710_ENABLE_FREQUENCY              0x4
+#define APCI1710_DISABLE_FREQUENCY             (~APCI1710_ENABLE_FREQUENCY)
+
+#define APCI1710_ENABLE_FREQUENCY_INT          0x8
+#define APCI1710_DISABLE_FREQUENCY_INT         (~APCI1710_ENABLE_FREQUENCY_INT)
+
+#define APCI1710_ENABLE_40MHZ_FREQUENCY                0x40
+#define APCI1710_DISABLE_40MHZ_FREQUENCY       (~APCI1710_ENABLE_40MHZ_FREQUENCY)
+
+#define APCI1710_ENABLE_40MHZ_FILTER           0x80
+#define APCI1710_DISABLE_40MHZ_FILTER          (~APCI1710_ENABLE_40MHZ_FILTER)
+
+#define APCI1710_ENABLE_COMPARE_INT            0x2
+#define APCI1710_DISABLE_COMPARE_INT           (~APCI1710_ENABLE_COMPARE_INT)
+
+#define APCI1710_ENABLE_INDEX_ACTION           0x20
+#define APCI1710_DISABLE_INDEX_ACTION          (~APCI1710_ENABLE_INDEX_ACTION)
+#define APCI1710_REFERENCE_HIGH                0x40
+#define APCI1710_REFERENCE_LOW                 (~APCI1710_REFERENCE_HIGH)
+
+
+   #define APCI1710_TOR_GATE_LOW               0x40
+   #define APCI1710_TOR_GATE_HIGH              (~APCI1710_TOR_GATE_LOW)
+
+
+//     INSN CONFIG 
+#define        APCI1710_INCCPT_INITCOUNTER                                                     100
+#define APCI1710_INCCPT_COUNTERAUTOTEST                                                101
+#define APCI1710_INCCPT_INITINDEX                                                      102
+#define APCI1710_INCCPT_INITREFERENCE                                          103
+#define APCI1710_INCCPT_INITEXTERNALSTROBE                                     104
+#define APCI1710_INCCPT_INITCOMPARELOGIC                                       105
+#define APCI1710_INCCPT_INITFREQUENCYMEASUREMENT                       106
+
+// INSN READ
+#define APCI1710_INCCPT_READLATCHREGISTERSTATUS                                200                                              
+#define APCI1710_INCCPT_READLATCHREGISTERVALUE                         201
+#define APCI1710_INCCPT_READ16BITCOUNTERVALUE                          202        
+#define APCI1710_INCCPT_READ32BITCOUNTERVALUE                          203
+#define APCI1710_INCCPT_GETINDEXSTATUS                                         204
+#define APCI1710_INCCPT_GETREFERENCESTATUS                                     205
+#define APCI1710_INCCPT_GETUASSTATUS                                           206
+#define APCI1710_INCCPT_GETCBSTATUS                                                    207
+#define APCI1710_INCCPT_GET16BITCBSTATUS                                       208
+#define APCI1710_INCCPT_GETUDSTATUS                                                    209
+#define APCI1710_INCCPT_GETINTERRUPTUDLATCHEDSTATUS                    210
+#define APCI1710_INCCPT_READFREQUENCYMEASUREMENT                       211
+#define APCI1710_INCCPT_READINTERRUPT                       212
+
+//INSN BITS
+#define APCI1710_INCCPT_CLEARCOUNTERVALUE                                      300
+#define APCI1710_INCCPT_CLEARALLCOUNTERVALUE                           301
+#define APCI1710_INCCPT_SETINPUTFILTER                                         302
+#define APCI1710_INCCPT_LATCHCOUNTER                                           303
+#define APCI1710_INCCPT_SETINDEXANDREFERENCESOURCE                     304
+#define APCI1710_INCCPT_SETDIGITALCHLON                                                305
+#define APCI1710_INCCPT_SETDIGITALCHLOFF                                       306
+
+// INSN WRITE
+#define APCI1710_INCCPT_ENABLELATCHINTERRUPT                           400
+#define APCI1710_INCCPT_DISABLELATCHINTERRUPT                          401
+#define APCI1710_INCCPT_WRITE16BITCOUNTERVALUE                         402
+#define APCI1710_INCCPT_WRITE32BITCOUNTERVALUE                         403
+#define APCI1710_INCCPT_ENABLEINDEX                                                    404     
+#define APCI1710_INCCPT_DISABLEINDEX                                           405
+#define APCI1710_INCCPT_ENABLECOMPARELOGIC                                     406     
+#define APCI1710_INCCPT_DISABLECOMPARELOGIC                                    407
+#define APCI1710_INCCPT_ENABLEFREQUENCYMEASUREMENT                     408
+#define APCI1710_INCCPT_DISABLEFREQUENCYMEASUREMENT                    409
+
+
+/************ Main Functions *************/  
+INT    i_APCI1710_InsnConfigINCCPT(comedi_device *dev,comedi_subdevice *s,
+comedi_insn *insn,lsampl_t *data);
+
+INT    i_APCI1710_InsnBitsINCCPT(comedi_device *dev,comedi_subdevice *s,
+comedi_insn *insn,lsampl_t *data);
+
+INT    i_APCI1710_InsnWriteINCCPT(comedi_device *dev,comedi_subdevice *s,
+comedi_insn *insn,lsampl_t *data);
+
+INT    i_APCI1710_InsnReadINCCPT(comedi_device *dev,comedi_subdevice *s,
+comedi_insn *insn,lsampl_t *data);
+
+/*********** Supplementary Functions********/
+
+
+// INSN CONFIG
+
+INT   i_APCI1710_InitCounter (comedi_device *dev,
+                               BYTE          b_ModulNbr,
+                               BYTE          b_CounterRange,
+                               BYTE          b_FirstCounterModus,
+                               BYTE          b_FirstCounterOption,
+                               BYTE          b_SecondCounterModus,
+                               BYTE          b_SecondCounterOption);
+
+INT  i_APCI1710_CounterAutoTest  (comedi_device *dev,PBYTE   pb_TestStatus);
+
+INT   i_APCI1710_InitIndex    (comedi_device *dev,
+                                BYTE b_ModulNbr,
+                                BYTE b_ReferenceAction,
+                                BYTE b_IndexOperation,
+                                BYTE b_AutoMode,
+                                BYTE b_InterruptEnable);
+
+INT   i_APCI1710_InitReference        (comedi_device *dev,
+                                        BYTE b_ModulNbr,
+                                        BYTE b_ReferenceLevel);
+
+INT    i_APCI1710_InitExternalStrobe   (comedi_device *dev,
+                                        BYTE b_ModulNbr,
+                                        BYTE b_ExternalStrobe,
+                                        BYTE b_ExternalStrobeLevel);
+
+INT   i_APCI1710_InitCompareLogic     (comedi_device *dev,
+                                        BYTE   b_ModulNbr,
+                                        UINT  ui_CompareValue);
+
+INT    i_APCI1710_InitFrequencyMeasurement     (comedi_device *dev,
+                                                BYTE            b_ModulNbr,
+                                                BYTE            b_PCIInputClock,
+                                                BYTE            b_TimingUnity,
+                                                ULONG           ul_TimingInterval,
+                                                PULONG      pul_RealTimingInterval);
+
+
+//INSN BITS
+
+INT   i_APCI1710_ClearCounterValue    (comedi_device *dev,
+                                        BYTE b_ModulNbr);
+
+INT   i_APCI1710_ClearAllCounterValue (comedi_device *dev);
+
+INT    i_APCI1710_SetInputFilter       (comedi_device *dev,
+                                                                       BYTE b_ModulNbr,
+                                    BYTE b_PCIInputClock,
+                                                                       BYTE b_Filter);
+
+INT   i_APCI1710_LatchCounter (comedi_device *dev,
+                                BYTE b_ModulNbr,
+                                BYTE b_LatchReg);
+
+INT    i_APCI1710_SetIndexAndReferenceSource   (comedi_device *dev,
+                                                BYTE b_ModulNbr,
+                                                BYTE b_SourceSelection);
+
+INT    i_APCI1710_SetDigitalChlOn (comedi_device *dev,
+                                   BYTE  b_ModulNbr);
+
+INT    i_APCI1710_SetDigitalChlOff (comedi_device *dev,
+                                    BYTE  b_ModulNbr);
+
+
+// INSN WRITE
+INT  i_APCI1710_EnableLatchInterrupt (comedi_device *dev,
+                                        BYTE b_ModulNbr);
+
+
+INT   i_APCI1710_DisableLatchInterrupt        (comedi_device *dev,
+                                                BYTE b_ModulNbr);
+
+INT   i_APCI1710_Write16BitCounterValue       (comedi_device *dev,
+                                                BYTE  b_ModulNbr,
+                                                BYTE  b_SelectedCounter,
+                                                UINT  ui_WriteValue);
+
+INT   i_APCI1710_Write32BitCounterValue       (comedi_device *dev,
+                                                BYTE   b_ModulNbr,
+                                                ULONG ul_WriteValue);
+
+INT   i_APCI1710_EnableIndex  (comedi_device *dev,
+                                BYTE b_ModulNbr);
+
+INT  i_APCI1710_DisableIndex (comedi_device *dev,
+                                BYTE b_ModulNbr);
+
+INT   i_APCI1710_EnableCompareLogic   (comedi_device *dev,
+                                        BYTE   b_ModulNbr);
+
+INT   i_APCI1710_DisableCompareLogic  (comedi_device *dev,
+                                        BYTE   b_ModulNbr);
+
+INT    i_APCI1710_EnableFrequencyMeasurement   (comedi_device *dev,
+                                                BYTE    b_ModulNbr,
+                                                BYTE    b_InterruptEnable);
+
+INT    i_APCI1710_DisableFrequencyMeasurement  (comedi_device *dev,
+                                                BYTE    b_ModulNbr);
+
+
+// INSN READ
+
+INT   i_APCI1710_ReadLatchRegisterStatus      (comedi_device *dev,
+                                                BYTE   b_ModulNbr,
+                                                BYTE   b_LatchReg,
+                                                PBYTE pb_LatchStatus);
+
+INT   i_APCI1710_ReadLatchRegisterValue       (comedi_device *dev,
+                                                BYTE     b_ModulNbr,
+                                                BYTE     b_LatchReg,
+                                                PULONG pul_LatchValue);
+
+INT   i_APCI1710_Read16BitCounterValue        (comedi_device *dev,
+                                                BYTE    b_ModulNbr,
+                                                BYTE    b_SelectedCounter,
+                                                PUINT pui_CounterValue);
+
+INT   i_APCI1710_Read32BitCounterValue        (comedi_device *dev,
+                                                BYTE      b_ModulNbr,
+                                                PULONG  pul_CounterValue);
+
+INT   i_APCI1710_GetIndexStatus      (comedi_device *dev,
+                                       BYTE   b_ModulNbr,
+                                       PBYTE pb_IndexStatus);
+
+INT   i_APCI1710_GetReferenceStatus      (comedi_device *dev,
+                                           BYTE   b_ModulNbr,
+                                           PBYTE  pb_ReferenceStatus);
+
+INT   i_APCI1710_GetUASStatus (comedi_device *dev,
+                                BYTE   b_ModulNbr,
+                                PBYTE pb_UASStatus);
+
+INT   i_APCI1710_GetCBStatus  (comedi_device *dev,
+                                BYTE   b_ModulNbr,
+                                PBYTE pb_CBStatus);
+
+INT   i_APCI1710_Get16BitCBStatus      (comedi_device *dev,
+                                        BYTE     b_ModulNbr,
+                                        PBYTE pb_CBStatusCounter0,
+                                        PBYTE pb_CBStatusCounter1);
+
+INT   i_APCI1710_GetUDStatus  (comedi_device *dev,
+                                BYTE   b_ModulNbr,
+                                PBYTE pb_UDStatus);
+
+INT   i_APCI1710_GetInterruptUDLatchedStatus  (comedi_device *dev,
+                                                BYTE   b_ModulNbr,
+                                                PBYTE pb_UDStatus);
+
+INT    i_APCI1710_ReadFrequencyMeasurement (comedi_device *dev,
+                                            BYTE        b_ModulNbr,
+                                            PBYTE       pb_Status,
+                                            PBYTE       pb_UDStatus,
+                                            PULONG      pul_ReadValue);
+
+
+
+
+
+
+
index 77733e83aefd03dfff91bea36657e056da598ce4..e9f11c250144085609bba28c1109e530e13f96b8 100644 (file)
-/**\r
-@verbatim\r
-\r
-Copyright (C) 2004,2005  ADDI-DATA GmbH for the source code of this module. \r
-        \r
-        ADDI-DATA GmbH \r
-        Dieselstrasse 3 \r
-        D-77833 Ottersweier \r
-        Tel: +19(0)7223/9493-0 \r
-        Fax: +49(0)7223/9493-92 \r
-        http://www.addi-data-com \r
-        info@addi-data.com \r
-\r
-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.\r
-\r
-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.\r
-\r
-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 USA\r
-\r
-You shoud also find the complete GPL in the COPYING file accompanying this source code.\r
-\r
-@endverbatim\r
-*/\r
-/*\r
-    \r
-  +-----------------------------------------------------------------------+\r
-  | (C) ADDI-DATA GmbH          Dieselstraße 3       D-77833 Ottersweier  |\r
-  +-----------------------------------------------------------------------+\r
-  | Tel : +49 (0) 7223/9493-0     | email    : info@addi-data.com         |\r
-  | Fax : +49 (0) 7223/9493-92    | Internet : http://www.addi-data.com   |\r
-  +-----------------------------------------------------------------------+\r
-  | Project     : API APCI1710    | Compiler : gcc                        |\r
-  | Module name : Inp_CPT.C       | Version  : 2.96                       |\r
-  +-------------------------------+---------------------------------------+\r
-  | Project manager: Eric Stolz   | Date     :  02/12/2002                |\r
-  +-----------------------------------------------------------------------+\r
-  | Description :   APCI-1710 pulse encoder module                        |\r
-  |                                                                       |\r
-  |                                                                       |\r
-  +-----------------------------------------------------------------------+\r
-  |                             UPDATES                                   |\r
-  +-----------------------------------------------------------------------+\r
-  |   Date   |   Author  |          Description of updates                |\r
-  +----------+-----------+------------------------------------------------+\r
-  |          |           |                                                |\r
-  |----------|-----------|------------------------------------------------|\r
-  | 08/05/00 | Guinot C  | - 0400/0228 All Function in RING 0             |\r
-  |          |           |   available                                    |\r
-  +-----------------------------------------------------------------------+\r
-*/\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-|                               Included files                               |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-#include "APCI1710_Inp_cpt.h"\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : _INT_ i_APCI1710_InitPulseEncoder                      |\r
-|                               (BYTE_          b_BoardHandle,               |\r
-|                                BYTE_          b_ModulNbr,                  |\r
-|                                BYTE_          b_PulseEncoderNbr,           |\r
-|                                BYTE_          b_InputLevelSelection,       |\r
-|                                BYTE_          b_TriggerOutputAction,       |\r
-|                                ULONG_        ul_StartValue)                |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Configure the pulse encoder operating mode selected via|\r
-|                     b_ModulNbr and b_PulseEncoderNbr. The pulse encoder    |\r
-|                     after each pulse decrement the counter value from 1.   |\r
-|                                                                            |\r
-|                     You must calling this function be for you call any     |\r
-|                     other function witch access of pulse encoders.         |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : BYTE_ b_BoardHandle         : Handle of board APCI-1710|\r
-|                     BYTE_ b_ModulNbr            : Module number to         |\r
-|                                                   configure (0 to 3)       |\r
-|                     BYTE_ b_PulseEncoderNbr     : Pulse encoder selection  |\r
-|                                                   (0 to 3)                 |\r
-|                     BYTE_ b_InputLevelSelection : Input level selection    |\r
-|                                                   (0 or 1)                 |\r
-|                                                       0 : Set pulse encoder|\r
-|                                                           count the the low|\r
-|                                                           level pulse.     |\r
-|                                                       1 : Set pulse encoder|\r
-|                                                           count the the    |\r
-|                                                           high level pulse.|\r
-|                     BYTE_ b_TriggerOutputAction : Digital TRIGGER output   |\r
-|                                                   action                   |\r
-|                                                       0 : No action        |\r
-|                                                       1 : Set the trigger  |\r
-|                                                           output to "1"    |\r
-|                                                           (high) after the |\r
-|                                                           passage from 1 to|\r
-|                                                           0 from pulse     |\r
-|                                                           encoder.         |\r
-|                                                       2 : Set the trigger  |\r
-|                                                           output to "0"    |\r
-|                                                           (low) after the  |\r
-|                                                           passage from 1 to|\r
-|                                                           0 from pulse     |\r
-|                                                           encoder          |\r
-|                     ULONG_ ul_StartValue        : Pulse encoder start value|\r
-|                                                   (1 to 4294967295) \r
-       b_ModulNbr                              =(BYTE) CR_AREF(insn->chanspec);\r
-       b_PulseEncoderNbr               =(BYTE) data[0];\r
-       b_InputLevelSelection   =(BYTE) data[1];\r
-       b_TriggerOutputAction   =(BYTE) data[2];\r
-       ul_StartValue                   =(ULONG) data[3];\r
-       |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : -                                                      |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      : 0: No error                                            |\r
-|                    -1: The handle parameter of the board is wrong          |\r
-|                    -2: The module is not a pulse encoder module            |\r
-|                    -3: Pulse encoder selection is wrong                    |\r
-|                    -4: Input level selection is wrong                      |\r
-|                    -5: Digital TRIGGER output action selection is wrong    |\r
-|                    -6: Pulse encoder start value is wrong                  |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-INT  i_APCI1710_InsnConfigInitPulseEncoder(comedi_device *dev,comedi_subdevice *s,\r
-       comedi_insn *insn,lsampl_t *data)\r
-       {\r
-       INT    i_ReturnValue = 0;\r
-       DWORD dw_IntRegister;\r
-       \r
-       BYTE   b_ModulNbr;\r
-       BYTE   b_PulseEncoderNbr;\r
-       BYTE   b_InputLevelSelection;\r
-       BYTE   b_TriggerOutputAction;\r
-       ULONG  ul_StartValue;\r
-    \r
-       b_ModulNbr                              =(BYTE)  CR_AREF(insn->chanspec);\r
-       b_PulseEncoderNbr               =(BYTE)  data[0];\r
-       b_InputLevelSelection   =(BYTE)  data[1];\r
-       b_TriggerOutputAction   =(BYTE)  data[2];\r
-       ul_StartValue                   =(ULONG) data[3];\r
-\r
-       i_ReturnValue           =insn->n;\r
-       \r
-\r
-       /***********************************/\r
-       /* Test the selected module number */\r
-       /***********************************/\r
-\r
-       if (b_ModulNbr <= 3)\r
-          {\r
-          /*************************/\r
-          /* Test if pulse encoder */\r
-          /*************************/\r
-\r
-          if ((devpriv->s_BoardInfos.\r
-               dw_MolduleConfiguration [b_ModulNbr] & APCI1710_PULSE_ENCODER) == APCI1710_PULSE_ENCODER)\r
-             {\r
-             /******************************************/\r
-             /* Test the selected pulse encoder number */\r
-             /******************************************/\r
-\r
-             if (b_PulseEncoderNbr <= 3)\r
-                {\r
-                /************************/\r
-                /* Test the input level */\r
-                /************************/\r
-\r
-                if ((b_InputLevelSelection == 0) || (b_InputLevelSelection == 1))\r
-                   {\r
-                   /*******************************************/\r
-                   /* Test the ouput TRIGGER action selection */\r
-                   /*******************************************/\r
-\r
-                   if ((b_TriggerOutputAction <= 2) || (b_PulseEncoderNbr > 0))\r
-                      {\r
-                      if (ul_StartValue > 1)\r
-                         {\r
-                        \r
-                                dw_IntRegister= inl(devpriv->s_BoardInfos.ui_Address + 20 + (64 * b_ModulNbr));\r
-\r
-                         /***********************/\r
-                         /* Set the start value */\r
-                         /***********************/\r
-\r
-\r
-                                outl(ul_StartValue,devpriv->s_BoardInfos.ui_Address + (b_PulseEncoderNbr * 4) + (64 * b_ModulNbr));\r
-\r
-                         /***********************/\r
-                         /* Set the input level */\r
-                         /***********************/\r
-                         devpriv->s_ModuleInfo [b_ModulNbr].\r
-                         s_PulseEncoderModuleInfo.\r
-                         dw_SetRegister = (devpriv->s_ModuleInfo [b_ModulNbr].\r
-                                           s_PulseEncoderModuleInfo.\r
-                                           dw_SetRegister & (0xFFFFFFFFUL - (1UL << (8 + b_PulseEncoderNbr)))) |\r
-                                          ((1UL & (~b_InputLevelSelection)) << (8 + b_PulseEncoderNbr));\r
-\r
-                         /*******************************/\r
-                         /* Test if output trigger used */\r
-                         /*******************************/\r
-\r
-                         if ((b_TriggerOutputAction > 0) && (b_PulseEncoderNbr > 1))\r
-                            {\r
-                            /****************************/\r
-                            /* Enable the output action */\r
-                            /****************************/\r
-\r
-                            devpriv->s_ModuleInfo [b_ModulNbr].\r
-                            s_PulseEncoderModuleInfo.\r
-                            dw_SetRegister = devpriv->s_ModuleInfo [b_ModulNbr].\r
-                                             s_PulseEncoderModuleInfo.\r
-                                             dw_SetRegister |\r
-                                             (1UL << (4 + b_PulseEncoderNbr));\r
-\r
-                            /*********************************/\r
-                            /* Set the output TRIGGER action */\r
-                            /*********************************/\r
-\r
-                            devpriv->s_ModuleInfo [b_ModulNbr].\r
-                            s_PulseEncoderModuleInfo.\r
-                            dw_SetRegister = (devpriv->s_ModuleInfo [b_ModulNbr].\r
-                                              s_PulseEncoderModuleInfo.\r
-                                              dw_SetRegister & (0xFFFFFFFFUL - (1UL << (12 + b_PulseEncoderNbr)))) |\r
-                                             ((1UL & (b_TriggerOutputAction - 1)) << (12 + b_PulseEncoderNbr));\r
-                            }\r
-                         else\r
-                            {\r
-                            /*****************************/\r
-                            /* Disable the output action */\r
-                            /*****************************/\r
-\r
-                            devpriv->s_ModuleInfo [b_ModulNbr].\r
-                            s_PulseEncoderModuleInfo.\r
-                            dw_SetRegister = devpriv->s_ModuleInfo [b_ModulNbr].\r
-                                             s_PulseEncoderModuleInfo.\r
-                                             dw_SetRegister & (0xFFFFFFFFUL - (1UL << (4 + b_PulseEncoderNbr)));\r
-                            }\r
-\r
-                         /*************************/\r
-                         /* Set the configuration */\r
-                         /*************************/\r
-\r
-                         \r
-                         outl(devpriv->s_ModuleInfo [b_ModulNbr].\r
-                                 s_PulseEncoderModuleInfo.dw_SetRegister,devpriv->s_BoardInfos.\r
-                                 ui_Address + 20 + (64 * b_ModulNbr));\r
-\r
-                         devpriv->s_ModuleInfo [b_ModulNbr].\r
-                         s_PulseEncoderModuleInfo.\r
-                         s_PulseEncoderInfo [b_PulseEncoderNbr].\r
-                         b_PulseEncoderInit = 1;\r
-                         }\r
-                      else\r
-                         {\r
-                         /**************************************/\r
-                         /* Pulse encoder start value is wrong */\r
-                         /**************************************/\r
-\r
-                         DPRINTK("Pulse encoder start value is wrong\n");\r
-                         i_ReturnValue = -6;\r
-                         }\r
-                      }\r
-                   else\r
-                      {\r
-                      /****************************************************/\r
-                      /* Digital TRIGGER output action selection is wrong */\r
-                      /****************************************************/\r
-\r
-                          DPRINTK("Digital TRIGGER output action selection is wrong\n");       \r
-                      i_ReturnValue = -5;\r
-                      }\r
-                   }\r
-                else\r
-                   {\r
-                   /**********************************/\r
-                   /* Input level selection is wrong */\r
-                   /**********************************/\r
-\r
-                   DPRINTK("Input level selection is wrong\n");\r
-                   i_ReturnValue = -4;\r
-                   }\r
-                }\r
-             else\r
-                {\r
-                /************************************/\r
-                /* Pulse encoder selection is wrong */\r
-                /************************************/\r
-\r
-                DPRINTK("Pulse encoder selection is wrong\n");\r
-                i_ReturnValue = -3;\r
-                }\r
-             }\r
-          else\r
-             {\r
-             /********************************************/\r
-             /* The module is not a pulse encoder module */\r
-             /********************************************/\r
-\r
-             DPRINTK("The module is not a pulse encoder module\n");    \r
-             i_ReturnValue = -2;\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /********************************************/\r
-          /* The module is not a pulse encoder module */\r
-          /********************************************/\r
-\r
-          DPRINTK("The module is not a pulse encoder module\n");       \r
-          i_ReturnValue = -2;\r
-          }\r
-\r
-       return (i_ReturnValue);\r
-       }\r
-\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : _INT_ i_APCI1710_EnablePulseEncoder                    |\r
-|                                       (BYTE_  b_BoardHandle,               |\r
-|                                        BYTE_  b_ModulNbr,                  |\r
-|                                        BYTE_  b_PulseEncoderNbr,           |\r
-|                                        BYTE_  b_CycleSelection,            |\r
-|                                        BYTE_  b_InterruptHandling)         |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Enableor disable  the selected pulse encoder (b_PulseEncoderNbr)  |\r
-|                     from selected module (b_ModulNbr). Each input pulse    |\r
-|                     decrement the pulse encoder counter value from 1.      |\r
-|                     If you enabled the interrupt (b_InterruptHandling), a  |\r
-|                     interrupt is generated when the pulse encoder has run  |\r
-|                     down.                                                  |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : BYTE_   b_BoardHandle       : Handle of board APCI-1710|\r
-|                     BYTE_   b_ModulNbr          : Module number to         |\r
-|                                                   configure (0 to 3)       |\r
-|                     BYTE_   b_PulseEncoderNbr   : Pulse encoder selection  |\r
-|                                                   (0 to 3)                 |\r
-|                     BYTE_   b_CycleSelection    : APCI1710_CONTINUOUS:     |\r
-|                                                       Each time the        |\r
-|                                                       counting value is set|\r
-|                                                       on "0", the pulse    |\r
-|                                                       encoder load the     |\r
-|                                                       start value after    |\r
-|                                                       the next pulse.      |\r
-|                                                   APCI1710_SINGLE:         |\r
-|                                                       If the counter is set|\r
-|                                                       on "0", the pulse    |\r
-|                                                       encoder is stopped.  |\r
-|                     BYTE_   b_InterruptHandling : Interrupts can be        |\r
-|                                                   generated, when the pulse|\r
-|                                                   encoder has run down.    |\r
-|                                                   With this parameter the  |\r
-|                                                   user decides if          |\r
-|                                                   interrupts are used or   |\r
-|                                                   not.                     |\r
-|                                                     APCI1710_ENABLE:       |\r
-|                                                     Interrupts are enabled |\r
-|                                                     APCI1710_DISABLE:      |\r
-|                                                     Interrupts are disabled\r
-\r
-       b_ModulNbr                      =(BYTE) CR_AREF(insn->chanspec);\r
-       b_Action                        =(BYTE) data[0];\r
-       b_PulseEncoderNbr       =(BYTE) data[1];\r
-       b_CycleSelection        =(BYTE) data[2];\r
-       b_InterruptHandling     =(BYTE) data[3];|\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : -                                                      |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      :  0: No error                                           |\r
-|                     -1: The handle parameter of the board is wrong         |\r
-|                     -2: Module selection is wrong                          |\r
-|                     -3: Pulse encoder selection is wrong                   |\r
-|                     -4: Pulse encoder not initialised.                     |\r
-|                         See function "i_APCI1710_InitPulseEncoder"         |\r
-|                     -5: Cycle selection mode is wrong                      |\r
-|                     -6: Interrupt handling mode is wrong                   |\r
-|                     -7: Interrupt routine not installed.                   |\r
-|                         See function "i_APCI1710_SetBoardIntRoutineX"      |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-\r
- INT i_APCI1710_InsnWriteEnableDisablePulseEncoder(comedi_device *dev,comedi_subdevice *s,\r
-       comedi_insn *insn,lsampl_t *data)\r
-       {\r
-       INT    i_ReturnValue = 0;\r
-       BYTE  b_ModulNbr;\r
-       BYTE  b_PulseEncoderNbr ;\r
-       BYTE  b_CycleSelection  ;\r
-       BYTE  b_InterruptHandling;\r
-       BYTE  b_Action;\r
-\r
-       i_ReturnValue           =insn->n;\r
-       b_ModulNbr                      =(BYTE) CR_AREF(insn->chanspec);\r
-       b_Action                        =(BYTE) data[0];\r
-       b_PulseEncoderNbr       =(BYTE) data[1];\r
-       b_CycleSelection        =(BYTE) data[2];\r
-       b_InterruptHandling     =(BYTE) data[3];\r
-\r
-\r
-       \r
-       /***********************************/\r
-       /* Test the selected module number */\r
-       /***********************************/\r
-\r
-       if (b_ModulNbr <= 3)\r
-          {\r
-          /******************************************/\r
-          /* Test the selected pulse encoder number */\r
-          /******************************************/\r
-\r
-          if (b_PulseEncoderNbr <= 3)\r
-             {\r
-             /*************************************/\r
-             /* Test if pulse encoder initialised */\r
-             /*************************************/\r
-\r
-             if (devpriv->s_ModuleInfo [b_ModulNbr].\r
-                 s_PulseEncoderModuleInfo.\r
-                 s_PulseEncoderInfo [b_PulseEncoderNbr].\r
-                 b_PulseEncoderInit == 1)\r
-                {\r
-                       switch(b_Action)\r
-                       {\r
-\r
-                       case APCI1710_ENABLE:\r
-                /****************************/\r
-                /* Test the cycle selection */\r
-                /****************************/\r
-\r
-                if (b_CycleSelection == APCI1710_CONTINUOUS || b_CycleSelection == APCI1710_SINGLE)\r
-                   {\r
-                   /*******************************/\r
-                   /* Test the interrupt handling */\r
-                   /*******************************/\r
-\r
-                   if (b_InterruptHandling == APCI1710_ENABLE || b_InterruptHandling == APCI1710_DISABLE)\r
-                      {\r
-                      /******************************/\r
-                      /* Test if interrupt not used */\r
-                      /******************************/\r
-\r
-                      if (b_InterruptHandling == APCI1710_DISABLE)\r
-                         {\r
-                         /*************************/\r
-                         /* Disable the interrupt */\r
-                         /*************************/\r
-\r
-                         devpriv->s_ModuleInfo [b_ModulNbr].\r
-                         s_PulseEncoderModuleInfo.\r
-                         dw_SetRegister = devpriv->s_ModuleInfo [b_ModulNbr].\r
-                                          s_PulseEncoderModuleInfo.\r
-                                          dw_SetRegister & (0xFFFFFFFFUL - (1UL << b_PulseEncoderNbr));\r
-                         }\r
-                      else\r
-                         {\r
-                                               \r
-                            /************************/\r
-                            /* Enable the interrupt */\r
-                            /************************/\r
-\r
-                            devpriv->s_ModuleInfo [b_ModulNbr].\r
-                            s_PulseEncoderModuleInfo.\r
-                            dw_SetRegister = devpriv->s_ModuleInfo [b_ModulNbr].\r
-                                             s_PulseEncoderModuleInfo.\r
-                                             dw_SetRegister | (1UL << b_PulseEncoderNbr);\r
-                               devpriv->tsk_Current=current; // Save the current process task structure\r
-\r
-                          \r
-                         }\r
-\r
-                      if (i_ReturnValue>=0)\r
-                         {\r
-                         /***********************************/\r
-                         /* Enable or disable the interrupt */\r
-                         /***********************************/\r
-\r
-                         \r
-                               outl(devpriv->s_ModuleInfo [b_ModulNbr].\r
-                                 s_PulseEncoderModuleInfo.\r
-                                 dw_SetRegister,devpriv->s_BoardInfos.\r
-                                 ui_Address + 20 + (64 * b_ModulNbr));\r
-\r
-                         /****************************/\r
-                         /* Enable the pulse encoder */\r
-                         /****************************/\r
-                         devpriv->s_ModuleInfo [b_ModulNbr].\r
-                         s_PulseEncoderModuleInfo.\r
-                         dw_ControlRegister = devpriv->s_ModuleInfo [b_ModulNbr].\r
-                                              s_PulseEncoderModuleInfo.\r
-                                              dw_ControlRegister | (1UL << b_PulseEncoderNbr);\r
-\r
-                         /**********************/\r
-                         /* Set the cycle mode */\r
-                         /**********************/\r
-\r
-                         devpriv->s_ModuleInfo [b_ModulNbr].\r
-                         s_PulseEncoderModuleInfo.\r
-                         dw_ControlRegister = (devpriv->s_ModuleInfo [b_ModulNbr].\r
-                                               s_PulseEncoderModuleInfo.\r
-                                               dw_ControlRegister & (0xFFFFFFFFUL - (1 << (b_PulseEncoderNbr + 4)))) |\r
-                                               ((b_CycleSelection & 1UL) << (4 + b_PulseEncoderNbr));\r
-\r
-                         /****************************/\r
-                         /* Enable the pulse encoder */\r
-                         /****************************/\r
-\r
-                         \r
-                         outl(devpriv->s_ModuleInfo [b_ModulNbr].\r
-                                 s_PulseEncoderModuleInfo.\r
-                                 dw_ControlRegister,devpriv->s_BoardInfos.\r
-                                 ui_Address + 16 + (64 * b_ModulNbr));\r
-                         }\r
-                      }\r
-                   else\r
-                      {\r
-                      /************************************/\r
-                      /* Interrupt handling mode is wrong */\r
-                      /************************************/\r
-\r
-                          DPRINTK("Interrupt handling mode is wrong\n");\r
-                      i_ReturnValue = -6;\r
-                      }\r
-                   }\r
-                else\r
-                   {\r
-                   /*********************************/\r
-                   /* Cycle selection mode is wrong */\r
-                   /*********************************/\r
-\r
-                       DPRINTK("Cycle selection mode is wrong\n");\r
-                   i_ReturnValue = -5;\r
-                   }\r
-                break;\r
-\r
-                case APCI1710_DISABLE:\r
-                devpriv->s_ModuleInfo [b_ModulNbr].\r
-                s_PulseEncoderModuleInfo.\r
-                dw_ControlRegister = devpriv->s_ModuleInfo [b_ModulNbr].\r
-                                     s_PulseEncoderModuleInfo.\r
-                                     dw_ControlRegister & (0xFFFFFFFFUL - (1UL << b_PulseEncoderNbr));\r
-\r
-                /*****************************/\r
-                /* Disable the pulse encoder */\r
-                /*****************************/\r
-\r
-               \r
-                outl(devpriv->s_ModuleInfo [b_ModulNbr].\r
-                        s_PulseEncoderModuleInfo.\r
-                        dw_ControlRegister,devpriv->s_BoardInfos.\r
-                        ui_Address + 16 + (64 * b_ModulNbr));\r
-\r
-                       break;\r
-                }// switch End\r
-\r
-                }\r
-             else\r
-                {\r
-                /*********************************/\r
-                /* Pulse encoder not initialised */\r
-                /*********************************/\r
-\r
-                DPRINTK("Pulse encoder not initialised\n");\r
-                i_ReturnValue = -4;\r
-                }\r
-             }\r
-          else\r
-             {\r
-             /************************************/\r
-             /* Pulse encoder selection is wrong */\r
-             /************************************/\r
-\r
-             DPRINTK("Pulse encoder selection is wrong\n");    \r
-             i_ReturnValue = -3;\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /*****************************/\r
-          /* Module selection is wrong */\r
-          /*****************************/\r
-\r
-          DPRINTK("Module selection is wrong\n");      \r
-          i_ReturnValue = -2;\r
-          }\r
-\r
-       return (i_ReturnValue);\r
-       }\r
-\r
-\r
-\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : _INT_ i_APCI1710_ReadPulseEncoderStatus                |\r
-|                                       (BYTE_  b_BoardHandle,               |\r
-|                                        BYTE_  b_ModulNbr,                  |\r
-|                                        BYTE_  b_PulseEncoderNbr,           |\r
-|                                        PBYTE_ pb_Status)                   |\r
-+----------------------------------------------------------------------------+\r
-| Task    APCI1710_PULSEENCODER_READ          : Reads the pulse encoder status \r
-                                                                                       and valuefrom selected pulse     |\r
-|                     encoder (b_PulseEncoderNbr) from selected module       |\r
-|                     (b_ModulNbr).                                          |\r
-+----------------------------------------------------------------------------+\r
-       BYTE   b_Type; data[0]\r
-   APCI1710_PULSEENCODER_WRITE                         \r
- Writes a 32-bit value (ul_WriteValue) into the selected|\r
-|                     pulse encoder (b_PulseEncoderNbr) from selected module |\r
-|                     (b_ModulNbr). This operation set the new start pulse   |\r
-|                     encoder value.\r
- APCI1710_PULSEENCODER_READ\r
-| Input Parameters  : BYTE_   b_BoardHandle       : Handle of board APCI-1710|\r
-|            CRAREF()         BYTE_   b_ModulNbr          : Module number to         |\r
-|                                                   configure (0 to 3)       |\r
-|              data[1]       BYTE_   b_PulseEncoderNbr   : Pulse encoder selection  |\r
-|                                                   (0 to 3)   \r
-   APCI1710_PULSEENCODER_WRITE  \r
-                               data[2]         ULONG_ ul_WriteValue        : 32-bit value to be       |\r
-|                                                   written             |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : PBYTE_ pb_Status            : Pulse encoder status.    |\r
-|                                                       0 : No overflow occur|\r
-|                                                       1 : Overflow occur \r
-                                               PULONG_ pul_ReadValue       : Pulse encoder value      |  |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      :  0: No error                                           |\r
-|                     -1: The handle parameter of the board is wrong         |\r
-|                     -2: Module selection is wrong                          |\r
-|                     -3: Pulse encoder selection is wrong                   |\r
-|                     -4: Pulse encoder not initialised.                     |\r
-|                         See function "i_APCI1710_InitPulseEncoder"         |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-\r
-/*_INT_   i_APCI1710_ReadPulseEncoderStatus       (BYTE_   b_BoardHandle,\r
-                                                BYTE_   b_ModulNbr,\r
-                                                BYTE_   b_PulseEncoderNbr,\r
-\r
-                                                PBYTE_ pb_Status)\r
-                                                */\r
-INT   i_APCI1710_InsnBitsReadWritePulseEncoder(comedi_device *dev,comedi_subdevice *s,\r
-       comedi_insn *insn,lsampl_t *data)\r
-       {\r
-       INT    i_ReturnValue = 0;\r
-       DWORD dw_StatusRegister;\r
-       BYTE   b_ModulNbr;\r
-       BYTE   b_PulseEncoderNbr;\r
-       PBYTE  pb_Status;\r
-       BYTE   b_Type;\r
-       PULONG pul_ReadValue;\r
-       ULONG ul_WriteValue ; \r
-                             \r
-       i_ReturnValue=insn->n;\r
-       b_ModulNbr              =(BYTE) CR_AREF(insn->chanspec);\r
-       b_Type                  =(BYTE)   data[0] ;\r
-       b_PulseEncoderNbr=(BYTE) data[1];\r
-       pb_Status               =(PBYTE) &data[0];\r
-       pul_ReadValue   =(PULONG) &data[1];\r
-    \r
-       /***********************************/\r
-       /* Test the selected module number */\r
-       /***********************************/\r
-\r
-       if (b_ModulNbr <= 3)\r
-          {\r
-          /******************************************/\r
-          /* Test the selected pulse encoder number */\r
-          /******************************************/\r
-\r
-          if (b_PulseEncoderNbr <= 3)\r
-             {\r
-             /*************************************/\r
-             /* Test if pulse encoder initialised */\r
-             /*************************************/\r
-\r
-             if (devpriv->s_ModuleInfo [b_ModulNbr].\r
-                 s_PulseEncoderModuleInfo.\r
-                 s_PulseEncoderInfo [b_PulseEncoderNbr].\r
-                 b_PulseEncoderInit == 1)\r
-                {\r
-\r
-               switch(b_Type)\r
-               {\r
-               case APCI1710_PULSEENCODER_READ:\r
-                /****************************/\r
-                /* Read the status register */\r
-                /****************************/\r
-\r
-               \r
-                       dw_StatusRegister=inl(devpriv->s_BoardInfos.\r
-                       ui_Address + 16 + (64 * b_ModulNbr));\r
-\r
-                devpriv->s_ModuleInfo [b_ModulNbr].\r
-                s_PulseEncoderModuleInfo.\r
-                dw_StatusRegister = devpriv->\r
-                                    s_ModuleInfo [b_ModulNbr].\r
-                                    s_PulseEncoderModuleInfo.\r
-                                    dw_StatusRegister | dw_StatusRegister;\r
-\r
-                *pb_Status = (BYTE) (devpriv->s_ModuleInfo [b_ModulNbr].\r
-                             s_PulseEncoderModuleInfo.\r
-                             dw_StatusRegister >> (1 + b_PulseEncoderNbr)) & 1;\r
-\r
-                devpriv->s_ModuleInfo [b_ModulNbr].\r
-                s_PulseEncoderModuleInfo.\r
-                dw_StatusRegister = devpriv->s_ModuleInfo [b_ModulNbr].\r
-                                    s_PulseEncoderModuleInfo.\r
-                                    dw_StatusRegister & (0xFFFFFFFFUL - (1 << (1 + b_PulseEncoderNbr)));\r
-\r
-                /******************/\r
-                /* Read the value */\r
-                /******************/\r
-                \r
-\r
-               *pul_ReadValue=inl(devpriv->s_BoardInfos.\r
-                       ui_Address + (4 * b_PulseEncoderNbr) + (64 * b_ModulNbr));\r
-                break;\r
-\r
-               case APCI1710_PULSEENCODER_WRITE:\r
-                       ul_WriteValue = (ULONG) data[2];\r
-                       /*******************/\r
-                       /* Write the value */\r
-                       /*******************/\r
-\r
-                       \r
-                       outl(ul_WriteValue,devpriv->s_BoardInfos.\r
-                        ui_Address + (4 * b_PulseEncoderNbr) + (64 * b_ModulNbr));\r
-\r
-               }//end of switch\r
-                }\r
-             else\r
-                {\r
-                /*********************************/\r
-                /* Pulse encoder not initialised */\r
-                /*********************************/\r
-\r
-                DPRINTK("Pulse encoder not initialised\n");\r
-                i_ReturnValue = -4;\r
-                }\r
-             }\r
-          else\r
-             {\r
-             /************************************/\r
-             /* Pulse encoder selection is wrong */\r
-             /************************************/\r
-\r
-             DPRINTK("Pulse encoder selection is wrong\n");            \r
-             i_ReturnValue = -3;\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /*****************************/\r
-          /* Module selection is wrong */\r
-          /*****************************/\r
-\r
-          DPRINTK("Module selection is wrong\n");\r
-          i_ReturnValue = -2;\r
-          }\r
-\r
-       return (i_ReturnValue);\r
-       }\r
-\r
-\r
-INT   i_APCI1710_InsnReadInterruptPulseEncoder(comedi_device *dev,comedi_subdevice *s,\r
-       comedi_insn *insn,lsampl_t *data)\r
-{\r
-\r
-       data[0] = devpriv->s_InterruptParameters.\r
-                                                     s_FIFOInterruptParameters [devpriv->\r
-                                                                                s_InterruptParameters.\r
-                                                                                ui_Read].b_OldModuleMask;\r
-        data[1] = devpriv->s_InterruptParameters.\r
-                                                     s_FIFOInterruptParameters [devpriv->\r
-                                                                                s_InterruptParameters.\r
-                                                                                ui_Read].ul_OldInterruptMask;\r
-        data[2] = devpriv->s_InterruptParameters.\r
-                                                     s_FIFOInterruptParameters [devpriv->\r
-                                                                                s_InterruptParameters.\r
-                                                                                ui_Read].ul_OldCounterLatchValue;\r
-\r
-                            \r
-       /***************************/\r
-       /* Increment the read FIFO */\r
-       /***************************/\r
-\r
-       devpriv->s_InterruptParameters.\r
-       ui_Read = (devpriv->\r
-       s_InterruptParameters.ui_Read + 1) % APCI1710_SAVE_INTERRUPT;\r
-\r
-        return insn->n;\r
-\r
-\r
-}\r
-\r
-\r
+/**
+@verbatim
+
+Copyright (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 USA
+
+You 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 */
+                      /****************************************************/
+
+                          DPRINTK("Digital TRIGGER output action selection is wrong\n");       
+                      i_ReturnValue = -5;
+                      }
+                   }
+                else
+                   {
+                   /**********************************/
+                   /* Input level selection is wrong */
+                   /**********************************/
+
+                   DPRINTK("Input level selection is wrong\n");
+                   i_ReturnValue = -4;
+                   }
+                }
+             else
+                {
+                /************************************/
+                /* Pulse encoder selection is wrong */
+                /************************************/
+
+                DPRINTK("Pulse encoder selection is wrong\n");
+                i_ReturnValue = -3;
+                }
+             }
+          else
+             {
+             /********************************************/
+             /* The module is not a pulse encoder module */
+             /********************************************/
+
+             DPRINTK("The module is not a pulse encoder module\n");    
+             i_ReturnValue = -2;
+             }
+          }
+       else
+          {
+          /********************************************/
+          /* The module is not a pulse encoder module */
+          /********************************************/
+
+          DPRINTK("The module is not a pulse encoder module\n");       
+          i_ReturnValue = -2;
+          }
+
+       return (i_ReturnValue);
+       }
+
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     : _INT_ i_APCI1710_EnablePulseEncoder                    |
+|                                       (BYTE_  b_BoardHandle,               |
+|                                        BYTE_  b_ModulNbr,                  |
+|                                        BYTE_  b_PulseEncoderNbr,           |
+|                                        BYTE_  b_CycleSelection,            |
+|                                        BYTE_  b_InterruptHandling)         |
++----------------------------------------------------------------------------+
+| Task              : Enableor disable  the selected pulse encoder (b_PulseEncoderNbr)  |
+|                     from selected module (b_ModulNbr). Each input pulse    |
+|                     decrement the pulse encoder counter value from 1.      |
+|                     If you enabled the interrupt (b_InterruptHandling), a  |
+|                     interrupt is generated when the pulse encoder has run  |
+|                     down.                                                  |
++----------------------------------------------------------------------------+
+| 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_CycleSelection    : APCI1710_CONTINUOUS:     |
+|                                                       Each time the        |
+|                                                       counting value is set|
+|                                                       on "0", the pulse    |
+|                                                       encoder load the     |
+|                                                       start value after    |
+|                                                       the next pulse.      |
+|                                                   APCI1710_SINGLE:         |
+|                                                       If the counter is set|
+|                                                       on "0", the pulse    |
+|                                                       encoder is stopped.  |
+|                     BYTE_   b_InterruptHandling : Interrupts can be        |
+|                                                   generated, when the pulse|
+|                                                   encoder has run down.    |
+|                                                   With this parameter the  |
+|                                                   user decides if          |
+|                                                   interrupts are used or   |
+|                                                   not.                     |
+|                                                     APCI1710_ENABLE:       |
+|                                                     Interrupts are enabled |
+|                                                     APCI1710_DISABLE:      |
+|                                                     Interrupts are disabled
+
+       b_ModulNbr                      =(BYTE) CR_AREF(insn->chanspec);
+       b_Action                        =(BYTE) data[0];
+       b_PulseEncoderNbr       =(BYTE) data[1];
+       b_CycleSelection        =(BYTE) data[2];
+       b_InterruptHandling     =(BYTE) data[3];|
++----------------------------------------------------------------------------+
+| Output Parameters : -                                                      |
++----------------------------------------------------------------------------+
+| Return Value      :  0: No error                                           |
+|                     -1: The handle parameter of the board is wrong         |
+|                     -2: Module selection is wrong                          |
+|                     -3: Pulse encoder selection is wrong                   |
+|                     -4: Pulse encoder not initialised.                     |
+|                         See function "i_APCI1710_InitPulseEncoder"         |
+|                     -5: Cycle selection mode is wrong                      |
+|                     -6: Interrupt handling mode is wrong                   |
+|                     -7: Interrupt routine not installed.                   |
+|                         See function "i_APCI1710_SetBoardIntRoutineX"      |
++----------------------------------------------------------------------------+
+*/
+
+
+ INT i_APCI1710_InsnWriteEnableDisablePulseEncoder(comedi_device *dev,comedi_subdevice *s,
+       comedi_insn *insn,lsampl_t *data)
+       {
+       INT    i_ReturnValue = 0;
+       BYTE  b_ModulNbr;
+       BYTE  b_PulseEncoderNbr ;
+       BYTE  b_CycleSelection  ;
+       BYTE  b_InterruptHandling;
+       BYTE  b_Action;
+
+       i_ReturnValue           =insn->n;
+       b_ModulNbr                      =(BYTE) CR_AREF(insn->chanspec);
+       b_Action                        =(BYTE) data[0];
+       b_PulseEncoderNbr       =(BYTE) data[1];
+       b_CycleSelection        =(BYTE) data[2];
+       b_InterruptHandling     =(BYTE) data[3];
+
+
+       
+       /***********************************/
+       /* Test the selected module number */
+       /***********************************/
+
+       if (b_ModulNbr <= 3)
+          {
+          /******************************************/
+          /* Test the selected pulse encoder number */
+          /******************************************/
+
+          if (b_PulseEncoderNbr <= 3)
+             {
+             /*************************************/
+             /* Test if pulse encoder initialised */
+             /*************************************/
+
+             if (devpriv->s_ModuleInfo [b_ModulNbr].
+                 s_PulseEncoderModuleInfo.
+                 s_PulseEncoderInfo [b_PulseEncoderNbr].
+                 b_PulseEncoderInit == 1)
+                {
+                       switch(b_Action)
+                       {
+
+                       case APCI1710_ENABLE:
+                /****************************/
+                /* Test the cycle selection */
+                /****************************/
+
+                if (b_CycleSelection == APCI1710_CONTINUOUS || b_CycleSelection == APCI1710_SINGLE)
+                   {
+                   /*******************************/
+                   /* Test the interrupt handling */
+                   /*******************************/
+
+                   if (b_InterruptHandling == APCI1710_ENABLE || b_InterruptHandling == APCI1710_DISABLE)
+                      {
+                      /******************************/
+                      /* Test if interrupt not used */
+                      /******************************/
+
+                      if (b_InterruptHandling == APCI1710_DISABLE)
+                         {
+                         /*************************/
+                         /* Disable the interrupt */
+                         /*************************/
+
+                         devpriv->s_ModuleInfo [b_ModulNbr].
+                         s_PulseEncoderModuleInfo.
+                         dw_SetRegister = devpriv->s_ModuleInfo [b_ModulNbr].
+                                          s_PulseEncoderModuleInfo.
+                                          dw_SetRegister & (0xFFFFFFFFUL - (1UL << b_PulseEncoderNbr));
+                         }
+                      else
+                         {
+                                               
+                            /************************/
+                            /* Enable the interrupt */
+                            /************************/
+
+                            devpriv->s_ModuleInfo [b_ModulNbr].
+                            s_PulseEncoderModuleInfo.
+                            dw_SetRegister = devpriv->s_ModuleInfo [b_ModulNbr].
+                                             s_PulseEncoderModuleInfo.
+                                             dw_SetRegister | (1UL << b_PulseEncoderNbr);
+                               devpriv->tsk_Current=current; // Save the current process task structure
+
+                          
+                         }
+
+                      if (i_ReturnValue>=0)
+                         {
+                         /***********************************/
+                         /* Enable or disable the interrupt */
+                         /***********************************/
+
+                         
+                               outl(devpriv->s_ModuleInfo [b_ModulNbr].
+                                 s_PulseEncoderModuleInfo.
+                                 dw_SetRegister,devpriv->s_BoardInfos.
+                                 ui_Address + 20 + (64 * b_ModulNbr));
+
+                         /****************************/
+                         /* Enable the pulse encoder */
+                         /****************************/
+                         devpriv->s_ModuleInfo [b_ModulNbr].
+                         s_PulseEncoderModuleInfo.
+                         dw_ControlRegister = devpriv->s_ModuleInfo [b_ModulNbr].
+                                              s_PulseEncoderModuleInfo.
+                                              dw_ControlRegister | (1UL << b_PulseEncoderNbr);
+
+                         /**********************/
+                         /* Set the cycle mode */
+                         /**********************/
+
+                         devpriv->s_ModuleInfo [b_ModulNbr].
+                         s_PulseEncoderModuleInfo.
+                         dw_ControlRegister = (devpriv->s_ModuleInfo [b_ModulNbr].
+                                               s_PulseEncoderModuleInfo.
+                                               dw_ControlRegister & (0xFFFFFFFFUL - (1 << (b_PulseEncoderNbr + 4)))) |
+                                               ((b_CycleSelection & 1UL) << (4 + b_PulseEncoderNbr));
+
+                         /****************************/
+                         /* Enable the pulse encoder */
+                         /****************************/
+
+                         
+                         outl(devpriv->s_ModuleInfo [b_ModulNbr].
+                                 s_PulseEncoderModuleInfo.
+                                 dw_ControlRegister,devpriv->s_BoardInfos.
+                                 ui_Address + 16 + (64 * b_ModulNbr));
+                         }
+                      }
+                   else
+                      {
+                      /************************************/
+                      /* Interrupt handling mode is wrong */
+                      /************************************/
+
+                          DPRINTK("Interrupt handling mode is wrong\n");
+                      i_ReturnValue = -6;
+                      }
+                   }
+                else
+                   {
+                   /*********************************/
+                   /* Cycle selection mode is wrong */
+                   /*********************************/
+
+                       DPRINTK("Cycle selection mode is wrong\n");
+                   i_ReturnValue = -5;
+                   }
+                break;
+
+                case APCI1710_DISABLE:
+                devpriv->s_ModuleInfo [b_ModulNbr].
+                s_PulseEncoderModuleInfo.
+                dw_ControlRegister = devpriv->s_ModuleInfo [b_ModulNbr].
+                                     s_PulseEncoderModuleInfo.
+                                     dw_ControlRegister & (0xFFFFFFFFUL - (1UL << b_PulseEncoderNbr));
+
+                /*****************************/
+                /* Disable the pulse encoder */
+                /*****************************/
+
+               
+                outl(devpriv->s_ModuleInfo [b_ModulNbr].
+                        s_PulseEncoderModuleInfo.
+                        dw_ControlRegister,devpriv->s_BoardInfos.
+                        ui_Address + 16 + (64 * b_ModulNbr));
+
+                       break;
+                }// switch End
+
+                }
+             else
+                {
+                /*********************************/
+                /* Pulse encoder not initialised */
+                /*********************************/
+
+                DPRINTK("Pulse encoder not initialised\n");
+                i_ReturnValue = -4;
+                }
+             }
+          else
+             {
+             /************************************/
+             /* Pulse encoder selection is wrong */
+             /************************************/
+
+             DPRINTK("Pulse encoder selection is wrong\n");    
+             i_ReturnValue = -3;
+             }
+          }
+       else
+          {
+          /*****************************/
+          /* Module selection is wrong */
+          /*****************************/
+
+          DPRINTK("Module selection is wrong\n");      
+          i_ReturnValue = -2;
+          }
+
+       return (i_ReturnValue);
+       }
+
+
+
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     : _INT_ i_APCI1710_ReadPulseEncoderStatus                |
+|                                       (BYTE_  b_BoardHandle,               |
+|                                        BYTE_  b_ModulNbr,                  |
+|                                        BYTE_  b_PulseEncoderNbr,           |
+|                                        PBYTE_ pb_Status)                   |
++----------------------------------------------------------------------------+
+| Task    APCI1710_PULSEENCODER_READ          : Reads the pulse encoder status 
+                                                                                       and valuefrom selected pulse     |
+|                     encoder (b_PulseEncoderNbr) from selected module       |
+|                     (b_ModulNbr).                                          |
++----------------------------------------------------------------------------+
+       BYTE   b_Type; data[0]
+   APCI1710_PULSEENCODER_WRITE                         
+ Writes a 32-bit value (ul_WriteValue) into the selected|
+|                     pulse encoder (b_PulseEncoderNbr) from selected module |
+|                     (b_ModulNbr). This operation set the new start pulse   |
+|                     encoder value.
+ APCI1710_PULSEENCODER_READ
+| Input Parameters  : BYTE_   b_BoardHandle       : Handle of board APCI-1710|
+|            CRAREF()         BYTE_   b_ModulNbr          : Module number to         |
+|                                                   configure (0 to 3)       |
+|              data[1]       BYTE_   b_PulseEncoderNbr   : Pulse encoder selection  |
+|                                                   (0 to 3)   
+   APCI1710_PULSEENCODER_WRITE  
+                               data[2]         ULONG_ ul_WriteValue        : 32-bit value to be       |
+|                                                   written             |
++----------------------------------------------------------------------------+
+| Output Parameters : PBYTE_ pb_Status            : Pulse encoder status.    |
+|                                                       0 : No overflow occur|
+|                                                       1 : Overflow occur 
+                                               PULONG_ pul_ReadValue       : Pulse encoder value      |  |
++----------------------------------------------------------------------------+
+| Return Value      :  0: No error                                           |
+|                     -1: The handle parameter of the board is wrong         |
+|                     -2: Module selection is wrong                          |
+|                     -3: Pulse encoder selection is wrong                   |
+|                     -4: Pulse encoder not initialised.                     |
+|                         See function "i_APCI1710_InitPulseEncoder"         |
++----------------------------------------------------------------------------+
+*/
+
+
+/*_INT_   i_APCI1710_ReadPulseEncoderStatus       (BYTE_   b_BoardHandle,
+                                                BYTE_   b_ModulNbr,
+                                                BYTE_   b_PulseEncoderNbr,
+
+                                                PBYTE_ pb_Status)
+                                                */
+INT   i_APCI1710_InsnBitsReadWritePulseEncoder(comedi_device *dev,comedi_subdevice *s,
+       comedi_insn *insn,lsampl_t *data)
+       {
+       INT    i_ReturnValue = 0;
+       DWORD dw_StatusRegister;
+       BYTE   b_ModulNbr;
+       BYTE   b_PulseEncoderNbr;
+       PBYTE  pb_Status;
+       BYTE   b_Type;
+       PULONG pul_ReadValue;
+       ULONG ul_WriteValue ; 
+                             
+       i_ReturnValue=insn->n;
+       b_ModulNbr              =(BYTE) CR_AREF(insn->chanspec);
+       b_Type                  =(BYTE)   data[0] ;
+       b_PulseEncoderNbr=(BYTE) data[1];
+       pb_Status               =(PBYTE) &data[0];
+       pul_ReadValue   =(PULONG) &data[1];
+    
+       /***********************************/
+       /* Test the selected module number */
+       /***********************************/
+
+       if (b_ModulNbr <= 3)
+          {
+          /******************************************/
+          /* Test the selected pulse encoder number */
+          /******************************************/
+
+          if (b_PulseEncoderNbr <= 3)
+             {
+             /*************************************/
+             /* Test if pulse encoder initialised */
+             /*************************************/
+
+             if (devpriv->s_ModuleInfo [b_ModulNbr].
+                 s_PulseEncoderModuleInfo.
+                 s_PulseEncoderInfo [b_PulseEncoderNbr].
+                 b_PulseEncoderInit == 1)
+                {
+
+               switch(b_Type)
+               {
+               case APCI1710_PULSEENCODER_READ:
+                /****************************/
+                /* Read the status register */
+                /****************************/
+
+               
+                       dw_StatusRegister=inl(devpriv->s_BoardInfos.
+                       ui_Address + 16 + (64 * b_ModulNbr));
+
+                devpriv->s_ModuleInfo [b_ModulNbr].
+                s_PulseEncoderModuleInfo.
+                dw_StatusRegister = devpriv->
+                                    s_ModuleInfo [b_ModulNbr].
+                                    s_PulseEncoderModuleInfo.
+                                    dw_StatusRegister | dw_StatusRegister;
+
+                *pb_Status = (BYTE) (devpriv->s_ModuleInfo [b_ModulNbr].
+                             s_PulseEncoderModuleInfo.
+                             dw_StatusRegister >> (1 + b_PulseEncoderNbr)) & 1;
+
+                devpriv->s_ModuleInfo [b_ModulNbr].
+                s_PulseEncoderModuleInfo.
+                dw_StatusRegister = devpriv->s_ModuleInfo [b_ModulNbr].
+                                    s_PulseEncoderModuleInfo.
+                                    dw_StatusRegister & (0xFFFFFFFFUL - (1 << (1 + b_PulseEncoderNbr)));
+
+                /******************/
+                /* Read the value */
+                /******************/
+                
+
+               *pul_ReadValue=inl(devpriv->s_BoardInfos.
+                       ui_Address + (4 * b_PulseEncoderNbr) + (64 * b_ModulNbr));
+                break;
+
+               case APCI1710_PULSEENCODER_WRITE:
+                       ul_WriteValue = (ULONG) data[2];
+                       /*******************/
+                       /* Write the value */
+                       /*******************/
+
+                       
+                       outl(ul_WriteValue,devpriv->s_BoardInfos.
+                        ui_Address + (4 * b_PulseEncoderNbr) + (64 * b_ModulNbr));
+
+               }//end of switch
+                }
+             else
+                {
+                /*********************************/
+                /* Pulse encoder not initialised */
+                /*********************************/
+
+                DPRINTK("Pulse encoder not initialised\n");
+                i_ReturnValue = -4;
+                }
+             }
+          else
+             {
+             /************************************/
+             /* Pulse encoder selection is wrong */
+             /************************************/
+
+             DPRINTK("Pulse encoder selection is wrong\n");            
+             i_ReturnValue = -3;
+             }
+          }
+       else
+          {
+          /*****************************/
+          /* Module selection is wrong */
+          /*****************************/
+
+          DPRINTK("Module selection is wrong\n");
+          i_ReturnValue = -2;
+          }
+
+       return (i_ReturnValue);
+       }
+
+
+INT   i_APCI1710_InsnReadInterruptPulseEncoder(comedi_device *dev,comedi_subdevice *s,
+       comedi_insn *insn,lsampl_t *data)
+{
+
+       data[0] = devpriv->s_InterruptParameters.
+                                                     s_FIFOInterruptParameters [devpriv->
+                                                                                s_InterruptParameters.
+                                                                                ui_Read].b_OldModuleMask;
+        data[1] = devpriv->s_InterruptParameters.
+                                                     s_FIFOInterruptParameters [devpriv->
+                                                                                s_InterruptParameters.
+                                                                                ui_Read].ul_OldInterruptMask;
+        data[2] = devpriv->s_InterruptParameters.
+                                                     s_FIFOInterruptParameters [devpriv->
+                                                                                s_InterruptParameters.
+                                                                                ui_Read].ul_OldCounterLatchValue;
+
+                            
+       /***************************/
+       /* Increment the read FIFO */
+       /***************************/
+
+       devpriv->s_InterruptParameters.
+       ui_Read = (devpriv->
+       s_InterruptParameters.ui_Read + 1) % APCI1710_SAVE_INTERRUPT;
+
+        return insn->n;
+
+
+}
+
+
+
index aa95b7d35b2fa51b26366753d1590f02124b0263..5edd3ad5b6ed6421c785ec5475ea0501ad4d5ea4 100644 (file)
@@ -1 +1,61 @@
-/**\r@verbatim\r\rCopyright (C) 2004,2005  ADDI-DATA GmbH for the source code of this module. \r        \r        ADDI-DATA GmbH \r        Dieselstrasse 3 \r        D-77833 Ottersweier \r        Tel: +19(0)7223/9493-0 \r        Fax: +49(0)7223/9493-92 \r        http://www.addi-data-com \r        info@addi-data.com \r\rThis 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.\r\rThis 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.\r\rYou 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 USA\r\rYou shoud also find the complete GPL in the COPYING file accompanying this source code.\r\r@endverbatim\r*/\r\r\r\r   #define APCI1710_SINGLE     0\r   #define APCI1710_CONTINUOUS 1\r\r\r#define APCI1710_PULSEENCODER_READ                0   \r#define APCI1710_PULSEENCODER_WRITE                1\r\r\rINT  i_APCI1710_InsnConfigInitPulseEncoder(comedi_device *dev,comedi_subdevice *s,\r comedi_insn *insn,lsampl_t *data);\r\r\r\r\rINT i_APCI1710_InsnWriteEnableDisablePulseEncoder(comedi_device *dev,comedi_subdevice *s,\r       comedi_insn *insn,lsampl_t *data);\r/*\r+----------------------------------------------------------------------------+\r|                       READ PULSE ENCODER FUNCTIONS                         |\r+----------------------------------------------------------------------------+\r*/\r\rINT   i_APCI1710_InsnReadInterruptPulseEncoder(comedi_device *dev,comedi_subdevice *s,\r  comedi_insn *insn,lsampl_t *data);\r\r/*\r+----------------------------------------------------------------------------+\r|                       WRITE PULSE ENCODER FUNCTIONS                        |\r+----------------------------------------------------------------------------+\r*/\r\r INT   i_APCI1710_InsnBitsReadWritePulseEncoder(comedi_device *dev,comedi_subdevice *s,\r        comedi_insn *insn,lsampl_t *data);\r\r\r
\ No newline at end of file
+/**
+@verbatim
+
+Copyright (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 USA
+
+You shoud also find the complete GPL in the COPYING file accompanying this source code.
+
+@endverbatim
+*/
+
+
+
+   #define APCI1710_SINGLE     0
+   #define APCI1710_CONTINUOUS 1
+
+
+#define APCI1710_PULSEENCODER_READ             0   
+#define APCI1710_PULSEENCODER_WRITE            1
+
+
+INT  i_APCI1710_InsnConfigInitPulseEncoder(comedi_device *dev,comedi_subdevice *s,
+       comedi_insn *insn,lsampl_t *data);
+
+
+
+
+INT i_APCI1710_InsnWriteEnableDisablePulseEncoder(comedi_device *dev,comedi_subdevice *s,
+       comedi_insn *insn,lsampl_t *data);
+/*
++----------------------------------------------------------------------------+
+|                       READ PULSE ENCODER FUNCTIONS                         |
++----------------------------------------------------------------------------+
+*/
+
+INT   i_APCI1710_InsnReadInterruptPulseEncoder(comedi_device *dev,comedi_subdevice *s,
+       comedi_insn *insn,lsampl_t *data);
+
+/*
++----------------------------------------------------------------------------+
+|                       WRITE PULSE ENCODER FUNCTIONS                        |
++----------------------------------------------------------------------------+
+*/
+
+ INT   i_APCI1710_InsnBitsReadWritePulseEncoder(comedi_device *dev,comedi_subdevice *s,
+       comedi_insn *insn,lsampl_t *data);
+
+
index 2423717aaa4f85e93f3c79b9cfe628f10a0e986c..8cf1f28f4c0f7cb53c79aff9caf025bea50919d1 100644 (file)
-/**\r
-@verbatim\r
-\r
-Copyright (C) 2004,2005  ADDI-DATA GmbH for the source code of this module. \r
-        \r
-        ADDI-DATA GmbH \r
-        Dieselstrasse 3 \r
-        D-77833 Ottersweier \r
-        Tel: +19(0)7223/9493-0 \r
-        Fax: +49(0)7223/9493-92 \r
-        http://www.addi-data-com \r
-        info@addi-data.com \r
-\r
-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.\r
-\r
-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.\r
-\r
-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 USA\r
-\r
-You shoud also find the complete GPL in the COPYING file accompanying this source code.\r
-\r
-@endverbatim\r
-*/\r
-/*\r
-    \r
-  +-----------------------------------------------------------------------+\r
-  | (C) ADDI-DATA GmbH          Dieselstraße 3       D-77833 Ottersweier  |\r
-  +-----------------------------------------------------------------------+\r
-  | Tel : +49 (0) 7223/9493-0     | email    : info@addi-data.com         |\r
-  | Fax : +49 (0) 7223/9493-92    | Internet : http://www.addi-data.com   |\r
-  +-----------------------------------------------------------------------+\r
-  | Project     : API APCI1710    | Compiler : gcc                        |\r
-  | Module name : PWM.C           | Version  : 2.96                       |\r
-  +-------------------------------+---------------------------------------+\r
-  | Project manager: Eric Stolz   | Date     :  02/12/2002                |\r
-  +-----------------------------------------------------------------------+\r
-  | Description :   APCI-1710 Wulse wide modulation module                |\r
-  |                                                                       |\r
-  |                                                                       |\r
-  +-----------------------------------------------------------------------+\r
-  |                             UPDATES                                   |\r
-  +-----------------------------------------------------------------------+\r
-  |   Date   |   Author  |          Description of updates                |\r
-  +-----------------------------------------------------------------------+\r
-  | 08/05/00 | Guinot C  | - 0400/0228 All Function in RING 0             |\r
-  |          |           |   available                                    |\r
-  +-----------------------------------------------------------------------+\r
-*/\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-|                               Included files                               |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-\r
-#include "APCI1710_Pwm.h"\r
-\r
-\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     :INT i_APCI1710_InsnConfigPWM(comedi_device *dev,\r
-comedi_subdevice *s,comedi_insn *insn,lsampl_t *data)                        |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Pwm Init and Get Pwm Initialisation                    |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : \r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : -                                                      |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      : \r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-INT    i_APCI1710_InsnConfigPWM(comedi_device *dev,comedi_subdevice *s,\r
-comedi_insn *insn,lsampl_t *data)\r
-{\r
-       BYTE b_ConfigType;\r
-       INT i_ReturnValue=0;\r
-        b_ConfigType=CR_CHAN(insn->chanspec);\r
-       \r
-\r
-       switch(b_ConfigType)\r
-       {\r
-       case APCI1710_PWM_INIT :\r
-               i_ReturnValue=i_APCI1710_InitPWM      (dev,\r
-                                (BYTE)CR_AREF(insn->chanspec), //  b_ModulNbr\r
-                                (BYTE) data[0],   //b_PWM\r
-                                (BYTE) data[1],   // b_ClockSelection\r
-                                (BYTE) data[2],   // b_TimingUnit\r
-                                (ULONG)data[3],   //ul_LowTiming\r
-                                (ULONG)data[4],   //ul_HighTiming\r
-                                (PULONG)&data[0], //pul_RealLowTiming\r
-                                (PULONG)&data[1] //pul_RealHighTiming\r
-                          );\r
-               break;\r
-\r
-       case APCI1710_PWM_GETINITDATA :\r
-               i_ReturnValue=i_APCI1710_GetPWMInitialisation (dev,\r
-                                        (BYTE)CR_AREF(insn->chanspec), // b_ModulNbr\r
-                                        (BYTE) data[0],   //b_PWM\r
-                                        (PBYTE)&data[0],    //pb_TimingUnit\r
-                                        (PULONG)&data[1], //pul_LowTiming\r
-                                        (PULONG)&data[2], //pul_HighTiming\r
-                                        (PBYTE) &data[3],  // pb_StartLevel\r
-                                        (PBYTE) &data[4], // pb_StopMode\r
-                                        (PBYTE) &data[5], // pb_StopLevel\r
-                                        (PBYTE) &data[6], // pb_ExternGate\r
-                                        (PBYTE) &data[7], // pb_InterruptEnable\r
-                                        (PBYTE) &data[8]  // pb_Enable\r
-                              );\r
-               break;\r
-\r
-       default:\r
-               printk(" Config Parameter Wrong\n");\r
-       }\r
-\r
-       if(i_ReturnValue>=0) i_ReturnValue =insn->n;\r
-       return (i_ReturnValue);\r
-}\r
-\r
-\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : _INT_ i_APCI1710_InitPWM                               |\r
-|                                       (BYTE_     b_BoardHandle,            |\r
-|                                        BYTE_     b_ModulNbr,               |\r
-|                                        BYTE_     b_PWM,                    |\r
-|                                        BYTE_     b_ClockSelection,         |\r
-|                                        BYTE_     b_TimingUnit,             |\r
-|                                        ULONG_   ul_LowTiming,              |\r
-|                                        ULONG_   ul_HighTiming,             |\r
-|                                        PULONG_ pul_RealLowTiming,          |\r
-|                                        PULONG_ pul_RealHighTiming)         |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Configure the selected PWM (b_PWM) from selected module|\r
-|                     (b_ModulNbr). The ul_LowTiming, ul_HighTiming and      |\r
-|                     ul_TimingUnit determine the low/high timing base for   |\r
-|                     the period. pul_RealLowTiming, pul_RealHighTiming      |\r
-|                     return the real timing value.                          |\r
-|                     You must calling this function be for you call any     |\r
-|                     other function witch access of the PWM.                |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : BYTE_     b_BoardHandle    : Handle of board APCI-1710 |\r
-|                     BYTE_     b_ModulNbr       : Module number to configure|\r
-|                                                  (0 to 3)                  |\r
-|                     BYTE_     b_PWM            : Selected PWM (0 or 1).    |\r
-|                     BYTE_     b_ClockSelection : Selection from PCI bus    |\r
-|                                                  clock                     |\r
-|                                                   - APCI1710_30MHZ :       |\r
-|                                                     The PC have a 30 MHz   |\r
-|                                                     PCI bus clock          |\r
-|                                                   - APCI1710_33MHZ :       |\r
-|                                                     The PC have a 33 MHz   |\r
-|                                                     PCI bus clock          |\r
-|                                                   - APCI1710_40MHZ         |\r
-|                                                     The APCI-1710 have a   |\r
-|                                                     integrated 40Mhz       |\r
-|                                                     quartz.                |\r
-|                     BYTE_     b_TimingUnit     : Base timing Unit (0 to 4) |\r
-|                                                       0 : ns               |\r
-|                                                       1 : æs               |\r
-|                                                       2 : ms               |\r
-|                                                       3 : s                |\r
-|                                                       4 : mn               |\r
-|                     ULONG_    ul_LowTiming     : Low base timing value.    |\r
-|                     ULONG_    ul_HighTiming    : High base timing value.   |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : PULONG_  pul_RealLowTiming  : Real low base timing     |\r
-|                                                   value.                   |\r
-|                     PULONG_  pul_RealHighTiming : Real high base timing    |\r
-|                                                   value.                   |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      : 0: No error                                            |\r
-|                    -1: The handle parameter of the board is wrong          |\r
-|                    -2: Module selection wrong                              |\r
-|                    -3: The module is not a PWM module                      |\r
-|                    -4: PWM selection is wrong                              |\r
-|                    -5: The selected input clock is wrong                   |\r
-|                    -6: Timing Unit selection is wrong                      |\r
-|                    -7: Low base timing selection is wrong                  |\r
-|                    -8: High base timing selection is wrong                 |\r
-|                    -9: You can not used the 40MHz clock selection with     |\r
-|                        this board                                          |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-INT   i_APCI1710_InitPWM      (comedi_device *dev,\r
-                                BYTE     b_ModulNbr,\r
-                                BYTE    b_PWM,\r
-                                BYTE     b_ClockSelection,\r
-                                BYTE     b_TimingUnit,\r
-                                ULONG   ul_LowTiming,\r
-                                ULONG   ul_HighTiming,\r
-                                PULONG pul_RealLowTiming,\r
-                                PULONG pul_RealHighTiming)\r
-       {\r
-       INT    i_ReturnValue = 0;\r
-       ULONG ul_LowTimerValue = 0;\r
-       ULONG ul_HighTimerValue = 0;\r
-       DWORD dw_Command;\r
-       double d_RealLowTiming = 0;\r
-       double d_RealHighTiming = 0;\r
-       \r
-\r
-       /**************************/\r
-       /* Test the module number */\r
-       /**************************/\r
-\r
-       if (b_ModulNbr < 4)\r
-          {\r
-          /***************/\r
-          /* Test if PWM */\r
-          /***************/\r
-\r
-          if ((devpriv->\r
-               s_BoardInfos.\r
-               dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_PWM)\r
-             {\r
-             /**************************/\r
-             /* Test the PWM selection */\r
-             /**************************/\r
-\r
-             if (b_PWM <= 1)\r
-                {\r
-                /******************/\r
-                /* Test the clock */\r
-                /******************/\r
-\r
-                if ((b_ClockSelection == APCI1710_30MHZ) ||\r
-                    (b_ClockSelection == APCI1710_33MHZ) ||\r
-                    (b_ClockSelection == APCI1710_40MHZ))\r
-                   {\r
-                   /************************/\r
-                   /* Test the timing unit */\r
-                   /************************/\r
-\r
-                   if (b_TimingUnit <= 4)\r
-                      {\r
-                      /*********************************/\r
-                      /* Test the low timing selection */\r
-                      /*********************************/\r
-\r
-                      if (((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 0) && (ul_LowTiming >= 266) && (ul_LowTiming <= 0xFFFFFFFFUL)) ||\r
-                          ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 1) && (ul_LowTiming >= 1)   && (ul_LowTiming <= 571230650UL))  ||\r
-                          ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 2) && (ul_LowTiming >= 1)   && (ul_LowTiming <= 571230UL))     ||\r
-                          ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 3) && (ul_LowTiming >= 1)   && (ul_LowTiming <= 571UL))        ||\r
-                          ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 4) && (ul_LowTiming >= 1)   && (ul_LowTiming <= 9UL))          ||\r
-                          ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 0) && (ul_LowTiming >= 242) && (ul_LowTiming <= 0xFFFFFFFFUL)) ||\r
-                          ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 1) && (ul_LowTiming >= 1)   && (ul_LowTiming <= 519691043UL))  ||\r
-                          ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 2) && (ul_LowTiming >= 1)   && (ul_LowTiming <= 519691UL))     ||\r
-                          ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 3) && (ul_LowTiming >= 1)   && (ul_LowTiming <= 520UL))        ||\r
-                          ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 4) && (ul_LowTiming >= 1)   && (ul_LowTiming <= 8UL))          ||\r
-                          ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 0) && (ul_LowTiming >= 200) && (ul_LowTiming <= 0xFFFFFFFFUL)) ||\r
-                          ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 1) && (ul_LowTiming >= 1)   && (ul_LowTiming <= 429496729UL))  ||\r
-                          ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 2) && (ul_LowTiming >= 1)   && (ul_LowTiming <= 429496UL))     ||\r
-                          ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 3) && (ul_LowTiming >= 1)   && (ul_LowTiming <= 429UL))        ||\r
-                          ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 4) && (ul_LowTiming >= 1)   && (ul_LowTiming <= 7UL)))\r
-                         {\r
-                         /**********************************/\r
-                         /* Test the High timing selection */\r
-                         /**********************************/\r
-\r
-                         if (((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 0) && (ul_HighTiming >= 266) && (ul_HighTiming <= 0xFFFFFFFFUL)) ||\r
-                             ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 1) && (ul_HighTiming >= 1)   && (ul_HighTiming <= 571230650UL))  ||\r
-                             ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 2) && (ul_HighTiming >= 1)   && (ul_HighTiming <= 571230UL))     ||\r
-                             ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 3) && (ul_HighTiming >= 1)   && (ul_HighTiming <= 571UL))        ||\r
-                             ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 4) && (ul_HighTiming >= 1)   && (ul_HighTiming <= 9UL))          ||\r
-                             ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 0) && (ul_HighTiming >= 242) && (ul_HighTiming <= 0xFFFFFFFFUL)) ||\r
-                             ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 1) && (ul_HighTiming >= 1)   && (ul_HighTiming <= 519691043UL))  ||\r
-                             ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 2) && (ul_HighTiming >= 1)   && (ul_HighTiming <= 519691UL))     ||\r
-                             ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 3) && (ul_HighTiming >= 1)   && (ul_HighTiming <= 520UL))        ||\r
-                             ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 4) && (ul_HighTiming >= 1)   && (ul_HighTiming <= 8UL))          ||\r
-                             ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 0) && (ul_HighTiming >= 200) && (ul_HighTiming <= 0xFFFFFFFFUL)) ||\r
-                             ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 1) && (ul_HighTiming >= 1)   && (ul_HighTiming <= 429496729UL))  ||\r
-                             ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 2) && (ul_HighTiming >= 1)   && (ul_HighTiming <= 429496UL))     ||\r
-                             ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 3) && (ul_HighTiming >= 1)   && (ul_HighTiming <= 429UL))        ||\r
-                             ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 4) && (ul_HighTiming >= 1)   && (ul_HighTiming <= 7UL)))\r
-                            {\r
-                            /**************************/\r
-                            /* Test the board version */\r
-                            /**************************/\r
-\r
-                            if (((b_ClockSelection == APCI1710_40MHZ) && (devpriv->\r
-                                                                          s_BoardInfos.\r
-                                                                          b_BoardVersion > 0)) ||\r
-                                (b_ClockSelection != APCI1710_40MHZ))\r
-                               {\r
-\r
-                               /************************************/\r
-                               /* Calculate the low division fator */\r
-                               /************************************/\r
-\r
-                               fpu_begin ();\r
-                               \r
-                               switch (b_TimingUnit)\r
-                                  {\r
-                                  /******/\r
-                                  /* ns */\r
-                                  /******/\r
-\r
-                                  case 0:\r
-                                       \r
-                                          /******************/\r
-                                          /* Timer 0 factor */\r
-                                          /******************/\r
-\r
-                                          ul_LowTimerValue = (ULONG) (ul_LowTiming * (0.00025 * b_ClockSelection));\r
-\r
-                                          /*******************/\r
-                                          /* Round the value */\r
-                                          /*******************/\r
-\r
-                                          if ((double) ((double) ul_LowTiming * (0.00025 * (double) b_ClockSelection)) >= ((double) ((double) ul_LowTimerValue + 0.5)))\r
-                                             {\r
-                                             ul_LowTimerValue = ul_LowTimerValue + 1;\r
-                                             }\r
-\r
-                                          /*****************************/\r
-                                          /* Calculate the real timing */\r
-                                          /*****************************/\r
-\r
-                                          *pul_RealLowTiming = (ULONG) (ul_LowTimerValue / (0.00025 * (double) b_ClockSelection));\r
-                                          d_RealLowTiming = (double) ul_LowTimerValue / (0.00025 * (double) b_ClockSelection);\r
-\r
-                                          if ((double) ((double) ul_LowTimerValue / (0.00025 * (double) b_ClockSelection)) >= (double) ((double) *pul_RealLowTiming + 0.5))\r
-                                             {\r
-                                             *pul_RealLowTiming = *pul_RealLowTiming + 1;\r
-                                             }\r
-\r
-                                          ul_LowTiming     = ul_LowTiming - 1;\r
-                                          ul_LowTimerValue = ul_LowTimerValue - 2;\r
-\r
-                                          if (b_ClockSelection != APCI1710_40MHZ)\r
-                                             {\r
-                                             ul_LowTimerValue = (ULONG) ((double) (ul_LowTimerValue) * 1.007752288);\r
-                                             }\r
-                                       \r
-\r
-                                       break;\r
-\r
-                                  /******/\r
-                                  /* æs */\r
-                                  /******/\r
-\r
-                                  case 1:\r
-                                       \r
-                                          /******************/\r
-                                          /* Timer 0 factor */\r
-                                          /******************/\r
-\r
-                                          ul_LowTimerValue = (ULONG) (ul_LowTiming * (0.25 * b_ClockSelection));\r
-\r
-                                          /*******************/\r
-                                          /* Round the value */\r
-                                          /*******************/\r
-\r
-                                          if ((double) ((double) ul_LowTiming * (0.25 * (double) b_ClockSelection)) >= ((double) ((double) ul_LowTimerValue + 0.5)))\r
-                                             {\r
-                                             ul_LowTimerValue = ul_LowTimerValue + 1;\r
-                                             }\r
-\r
-                                          /*****************************/\r
-                                          /* Calculate the real timing */\r
-                                          /*****************************/\r
-\r
-                                          *pul_RealLowTiming = (ULONG) (ul_LowTimerValue / (0.25 * (double) b_ClockSelection));\r
-                                          d_RealLowTiming    = (double) ul_LowTimerValue / ((double) 0.25 * (double) b_ClockSelection);\r
-\r
-                                          if ((double) ((double) ul_LowTimerValue / (0.25 * (double) b_ClockSelection)) >= (double) ((double) *pul_RealLowTiming + 0.5))\r
-                                             {\r
-                                             *pul_RealLowTiming = *pul_RealLowTiming + 1;\r
-                                             }\r
-\r
-                                          ul_LowTiming     = ul_LowTiming - 1;\r
-                                          ul_LowTimerValue = ul_LowTimerValue - 2;\r
-\r
-                                          if (b_ClockSelection != APCI1710_40MHZ)\r
-                                             {\r
-                                             ul_LowTimerValue = (ULONG) ((double) (ul_LowTimerValue) * 1.007752288);\r
-                                             }\r
-                                       \r
-\r
-                                       break;\r
-\r
-                                  /******/\r
-                                  /* ms */\r
-                                  /******/\r
-\r
-                                  case 2:\r
-                                       \r
-                                          /******************/\r
-                                          /* Timer 0 factor */\r
-                                          /******************/\r
-\r
-                                          ul_LowTimerValue = ul_LowTiming * (250.0 * b_ClockSelection);\r
-\r
-                                          /*******************/\r
-                                          /* Round the value */\r
-                                          /*******************/\r
-\r
-                                          if ((double) ((double) ul_LowTiming * (250.0 * (double) b_ClockSelection)) >= ((double) ((double) ul_LowTimerValue + 0.5)))\r
-                                             {\r
-                                             ul_LowTimerValue = ul_LowTimerValue + 1;\r
-                                             }\r
-\r
-                                          /*****************************/\r
-                                          /* Calculate the real timing */\r
-                                          /*****************************/\r
-\r
-                                          *pul_RealLowTiming = (ULONG) (ul_LowTimerValue / (250.0 * (double) b_ClockSelection));\r
-                                          d_RealLowTiming    = (double) ul_LowTimerValue / (250.0 * (double) b_ClockSelection);\r
-\r
-                                          if ((double) ((double) ul_LowTimerValue / (250.0 * (double) b_ClockSelection)) >= (double) ((double) *pul_RealLowTiming + 0.5))\r
-                                             {\r
-                                             *pul_RealLowTiming = *pul_RealLowTiming + 1;\r
-                                             }\r
-\r
-                                          ul_LowTiming     = ul_LowTiming - 1;\r
-                                          ul_LowTimerValue = ul_LowTimerValue - 2;\r
-\r
-                                          if (b_ClockSelection != APCI1710_40MHZ)\r
-                                             {\r
-                                             ul_LowTimerValue = (ULONG) ((double) (ul_LowTimerValue) * 1.007752288);\r
-                                             }\r
-                                       \r
-                                       break;\r
-\r
-                                  /*****/\r
-                                  /* s */\r
-                                  /*****/\r
-\r
-                                  case 3:\r
-                                          /******************/\r
-                                          /* Timer 0 factor */\r
-                                          /******************/\r
-\r
-                                          ul_LowTimerValue = (ULONG) (ul_LowTiming * (250000.0 * b_ClockSelection));\r
-\r
-                                          /*******************/\r
-                                          /* Round the value */\r
-                                          /*******************/\r
-\r
-                                          if ((double) ((double) ul_LowTiming * (250000.0 * (double) b_ClockSelection)) >= ((double) ((double) ul_LowTimerValue + 0.5)))\r
-                                             {\r
-                                             ul_LowTimerValue = ul_LowTimerValue + 1;\r
-                                             }\r
-\r
-                                          /*****************************/\r
-                                          /* Calculate the real timing */\r
-                                          /*****************************/\r
-\r
-                                          *pul_RealLowTiming = (ULONG) (ul_LowTimerValue / (250000.0 * (double) b_ClockSelection));\r
-                                          d_RealLowTiming    = (double) ul_LowTimerValue / (250000.0 * (double) b_ClockSelection);\r
-\r
-                                          if ((double) ((double) ul_LowTimerValue / (250000.0 * (double) b_ClockSelection)) >= (double) ((double) *pul_RealLowTiming + 0.5))\r
-                                             {\r
-                                             *pul_RealLowTiming = *pul_RealLowTiming + 1;\r
-                                             }\r
-\r
-                                          ul_LowTiming     = ul_LowTiming - 1;\r
-                                          ul_LowTimerValue = ul_LowTimerValue - 2;\r
-\r
-                                          if (b_ClockSelection != APCI1710_40MHZ)\r
-                                             {\r
-                                             ul_LowTimerValue = (ULONG) ((double) (ul_LowTimerValue) * 1.007752288);\r
-                                             }\r
-                                       \r
-\r
-                                       break;\r
-\r
-                                  /******/\r
-                                  /* mn */\r
-                                  /******/\r
-\r
-                                  case 4:\r
-                                       \r
-                                          /******************/\r
-                                          /* Timer 0 factor */\r
-                                          /******************/\r
-\r
-                                          ul_LowTimerValue = (ULONG) ((ul_LowTiming * 60) * (250000.0 * b_ClockSelection));\r
-\r
-                                          /*******************/\r
-                                          /* Round the value */\r
-                                          /*******************/\r
-\r
-                                          if ((double) ((double) (ul_LowTiming * 60.0) * (250000.0 * (double) b_ClockSelection)) >= ((double) ((double) ul_LowTimerValue + 0.5)))\r
-                                             {\r
-                                             ul_LowTimerValue = ul_LowTimerValue + 1;\r
-                                             }\r
-\r
-                                          /*****************************/\r
-                                          /* Calculate the real timing */\r
-                                          /*****************************/\r
-\r
-                                          *pul_RealLowTiming = (ULONG) (ul_LowTimerValue / (250000.0 * (double) b_ClockSelection)) / 60;\r
-                                          d_RealLowTiming    = ((double) ul_LowTimerValue / (250000.0 * (double) b_ClockSelection)) / 60.0;\r
-\r
-                                          if ((double) (((double) ul_LowTimerValue / (250000.0 * (double) b_ClockSelection)) / 60.0) >= (double) ((double) *pul_RealLowTiming + 0.5))\r
-                                             {\r
-                                             *pul_RealLowTiming = *pul_RealLowTiming + 1;\r
-                                             }\r
-\r
-                                          ul_LowTiming     = ul_LowTiming - 1;\r
-                                          ul_LowTimerValue = ul_LowTimerValue - 2;\r
-\r
-                                          if (b_ClockSelection != APCI1710_40MHZ)\r
-                                             {\r
-                                             ul_LowTimerValue = (ULONG) ((double) (ul_LowTimerValue) * 1.007752288);\r
-                                             }\r
-                                       \r
-                                       break;\r
-                                  }\r
-\r
-                               /*************************************/\r
-                               /* Calculate the high division fator */\r
-                               /*************************************/\r
-\r
-                               switch (b_TimingUnit)\r
-                                  {\r
-                                  /******/\r
-                                  /* ns */\r
-                                  /******/\r
-\r
-                                  case 0:\r
-                                       \r
-                                          /******************/\r
-                                          /* Timer 0 factor */\r
-                                          /******************/\r
-\r
-                                          ul_HighTimerValue = (ULONG) (ul_HighTiming * (0.00025 * b_ClockSelection));\r
-\r
-                                          /*******************/\r
-                                          /* Round the value */\r
-                                          /*******************/\r
-\r
-                                          if ((double) ((double) ul_HighTiming * (0.00025 * (double) b_ClockSelection)) >= ((double) ((double) ul_HighTimerValue + 0.5)))\r
-                                             {\r
-                                             ul_HighTimerValue = ul_HighTimerValue + 1;\r
-                                             }\r
-\r
-                                          /*****************************/\r
-                                          /* Calculate the real timing */\r
-                                          /*****************************/\r
-\r
-                                          *pul_RealHighTiming = (ULONG) (ul_HighTimerValue / (0.00025 * (double) b_ClockSelection));\r
-                                          d_RealHighTiming    = (double) ul_HighTimerValue / (0.00025 * (double) b_ClockSelection);\r
-\r
-                                          if ((double) ((double) ul_HighTimerValue / (0.00025 * (double) b_ClockSelection)) >= (double) ((double) *pul_RealHighTiming + 0.5))\r
-                                             {\r
-                                             *pul_RealHighTiming = *pul_RealHighTiming + 1;\r
-                                             }\r
-\r
-                                          ul_HighTiming     = ul_HighTiming - 1;\r
-                                          ul_HighTimerValue = ul_HighTimerValue - 2;\r
-\r
-                                          if (b_ClockSelection != APCI1710_40MHZ)\r
-                                             {\r
-                                             ul_HighTimerValue = (ULONG) ((double) (ul_HighTimerValue) * 1.007752288);\r
-                                             }\r
-                                       \r
-\r
-                                       break;\r
-\r
-                                  /******/\r
-                                  /* æs */\r
-                                  /******/\r
-\r
-                                  case 1:\r
-                                       \r
-                                          /******************/\r
-                                          /* Timer 0 factor */\r
-                                          /******************/\r
-\r
-                                          ul_HighTimerValue = (ULONG) (ul_HighTiming * (0.25 * b_ClockSelection));\r
-\r
-                                          /*******************/\r
-                                          /* Round the value */\r
-                                          /*******************/\r
-\r
-                                          if ((double) ((double) ul_HighTiming * (0.25 * (double) b_ClockSelection)) >= ((double) ((double) ul_HighTimerValue + 0.5)))\r
-                                             {\r
-                                             ul_HighTimerValue = ul_HighTimerValue + 1;\r
-                                             }\r
-\r
-                                          /*****************************/\r
-                                          /* Calculate the real timing */\r
-                                          /*****************************/\r
-\r
-                                          *pul_RealHighTiming = (ULONG) (ul_HighTimerValue / (0.25 * (double) b_ClockSelection));\r
-                                          d_RealHighTiming    = (double) ul_HighTimerValue / ((double) 0.25 * (double) b_ClockSelection);\r
-\r
-                                          if ((double) ((double) ul_HighTimerValue / (0.25 * (double) b_ClockSelection)) >= (double) ((double) *pul_RealHighTiming + 0.5))\r
-                                             {\r
-                                             *pul_RealHighTiming = *pul_RealHighTiming + 1;\r
-                                             }\r
-\r
-                                          ul_HighTiming     = ul_HighTiming - 1;\r
-                                          ul_HighTimerValue = ul_HighTimerValue - 2;\r
-\r
-                                          if (b_ClockSelection != APCI1710_40MHZ)\r
-                                             {\r
-                                             ul_HighTimerValue = (ULONG) ((double) (ul_HighTimerValue) * 1.007752288);\r
-                                             }\r
-                                       \r
-\r
-                                       break;\r
-\r
-                                  /******/\r
-                                  /* ms */\r
-                                  /******/\r
-\r
-                                  case 2:\r
-                                       \r
-                                          /******************/\r
-                                          /* Timer 0 factor */\r
-                                          /******************/\r
-\r
-                                          ul_HighTimerValue = ul_HighTiming * (250.0 * b_ClockSelection);\r
-\r
-                                          /*******************/\r
-                                          /* Round the value */\r
-                                          /*******************/\r
-\r
-                                          if ((double) ((double) ul_HighTiming * (250.0 * (double) b_ClockSelection)) >= ((double) ((double) ul_HighTimerValue + 0.5)))\r
-                                             {\r
-                                             ul_HighTimerValue = ul_HighTimerValue + 1;\r
-                                             }\r
-\r
-                                          /*****************************/\r
-                                          /* Calculate the real timing */\r
-                                          /*****************************/\r
-\r
-                                          *pul_RealHighTiming = (ULONG) (ul_HighTimerValue / (250.0 * (double) b_ClockSelection));\r
-                                          d_RealHighTiming    = (double) ul_HighTimerValue / (250.0 * (double) b_ClockSelection);\r
-\r
-                                          if ((double) ((double) ul_HighTimerValue / (250.0 * (double) b_ClockSelection)) >= (double) ((double) *pul_RealHighTiming + 0.5))\r
-                                             {\r
-                                             *pul_RealHighTiming = *pul_RealHighTiming + 1;\r
-                                             }\r
-\r
-                                          ul_HighTiming     = ul_HighTiming - 1;\r
-                                          ul_HighTimerValue = ul_HighTimerValue - 2;\r
-\r
-                                          if (b_ClockSelection != APCI1710_40MHZ)\r
-                                             {\r
-                                             ul_HighTimerValue = (ULONG) ((double) (ul_HighTimerValue) * 1.007752288);\r
-                                             }\r
-                                       \r
-\r
-                                       break;\r
-\r
-                                  /*****/\r
-                                  /* s */\r
-                                  /*****/\r
-\r
-                                  case 3:\r
-                                       \r
-                                          /******************/\r
-                                          /* Timer 0 factor */\r
-                                          /******************/\r
-\r
-                                          ul_HighTimerValue = (ULONG) (ul_HighTiming * (250000.0 * b_ClockSelection));\r
-\r
-                                          /*******************/\r
-                                          /* Round the value */\r
-                                          /*******************/\r
-\r
-                                          if ((double) ((double) ul_HighTiming * (250000.0 * (double) b_ClockSelection)) >= ((double) ((double) ul_HighTimerValue + 0.5)))\r
-                                             {\r
-                                             ul_HighTimerValue = ul_HighTimerValue + 1;\r
-                                             }\r
-\r
-                                          /*****************************/\r
-                                          /* Calculate the real timing */\r
-                                          /*****************************/\r
-\r
-                                          *pul_RealHighTiming = (ULONG) (ul_HighTimerValue / (250000.0 * (double) b_ClockSelection));\r
-                                          d_RealHighTiming    = (double) ul_HighTimerValue / (250000.0 * (double) b_ClockSelection);\r
-\r
-                                          if ((double) ((double) ul_HighTimerValue / (250000.0 * (double) b_ClockSelection)) >= (double) ((double) *pul_RealHighTiming + 0.5))\r
-                                             {\r
-                                             *pul_RealHighTiming = *pul_RealHighTiming + 1;\r
-                                             }\r
-\r
-                                          ul_HighTiming     = ul_HighTiming - 1;\r
-                                          ul_HighTimerValue = ul_HighTimerValue - 2;\r
-\r
-                                          if (b_ClockSelection != APCI1710_40MHZ)\r
-                                             {\r
-                                             ul_HighTimerValue = (ULONG) ((double) (ul_HighTimerValue) * 1.007752288);\r
-                                             }\r
-                                       \r
-\r
-                                       break;\r
-\r
-                                  /******/\r
-                                  /* mn */\r
-                                  /******/\r
-\r
-                                  case 4:\r
-                                       \r
-                                          /******************/\r
-                                          /* Timer 0 factor */\r
-                                          /******************/\r
-\r
-                                          ul_HighTimerValue = (ULONG) ((ul_HighTiming * 60) * (250000.0 * b_ClockSelection));\r
-\r
-                                          /*******************/\r
-                                          /* Round the value */\r
-                                          /*******************/\r
-\r
-                                          if ((double) ((double) (ul_HighTiming * 60.0) * (250000.0 * (double) b_ClockSelection)) >= ((double) ((double) ul_HighTimerValue + 0.5)))\r
-                                             {\r
-                                             ul_HighTimerValue = ul_HighTimerValue + 1;\r
-                                             }\r
-\r
-                                          /*****************************/\r
-                                          /* Calculate the real timing */\r
-                                          /*****************************/\r
-\r
-                                          *pul_RealHighTiming = (ULONG) (ul_HighTimerValue / (250000.0 * (double) b_ClockSelection)) / 60;\r
-                                          d_RealHighTiming    = ((double) ul_HighTimerValue / (250000.0 * (double) b_ClockSelection)) / 60.0;\r
-\r
-                                          if ((double) (((double) ul_HighTimerValue / (250000.0 * (double) b_ClockSelection)) / 60.0) >= (double) ((double) *pul_RealHighTiming + 0.5))\r
-                                             {\r
-                                             *pul_RealHighTiming = *pul_RealHighTiming + 1;\r
-                                             }\r
-\r
-                                          ul_HighTiming     = ul_HighTiming - 1;\r
-                                          ul_HighTimerValue = ul_HighTimerValue - 2;\r
-\r
-                                          if (b_ClockSelection != APCI1710_40MHZ)\r
-                                             {\r
-                                             ul_HighTimerValue = (ULONG) ((double) (ul_HighTimerValue) * 1.007752288);\r
-                                             }\r
-                                       \r
-                                       break;\r
-                                  }\r
-\r
-                               fpu_end ();\r
-                               /****************************/\r
-                               /* Save the clock selection */\r
-                               /****************************/\r
-\r
-                               devpriv->\r
-                               s_ModuleInfo [b_ModulNbr].\r
-                               s_PWMModuleInfo.\r
-                               b_ClockSelection = b_ClockSelection;\r
-\r
-                               /************************/\r
-                               /* Save the timing unit */\r
-                               /************************/\r
-\r
-                               devpriv->\r
-                               s_ModuleInfo [b_ModulNbr].\r
-                               s_PWMModuleInfo.\r
-                               s_PWMInfo [b_PWM].\r
-                               b_TimingUnit = b_TimingUnit;\r
-\r
-                               /****************************/\r
-                               /* Save the low base timing */\r
-                               /****************************/\r
-\r
-                               devpriv->\r
-                               s_ModuleInfo [b_ModulNbr].\r
-                               s_PWMModuleInfo.\r
-                               s_PWMInfo [b_PWM].\r
-                               d_LowTiming = d_RealLowTiming;\r
-\r
-                               devpriv->\r
-                               s_ModuleInfo [b_ModulNbr].\r
-                               s_PWMModuleInfo.\r
-                               s_PWMInfo [b_PWM].\r
-                               ul_RealLowTiming = *pul_RealLowTiming;\r
-\r
-                               /****************************/\r
-                               /* Save the high base timing */\r
-                               /****************************/\r
-\r
-                               devpriv->\r
-                               s_ModuleInfo [b_ModulNbr].\r
-                               s_PWMModuleInfo.\r
-                               s_PWMInfo [b_PWM].\r
-                               d_HighTiming = d_RealHighTiming;\r
-\r
-                               devpriv->\r
-                               s_ModuleInfo [b_ModulNbr].\r
-                               s_PWMModuleInfo.\r
-                               s_PWMInfo [b_PWM].\r
-                               ul_RealHighTiming = *pul_RealHighTiming;\r
-\r
-                               /************************/\r
-                               /* Write the low timing */\r
-                               /************************/\r
-\r
-                         outl(ul_LowTimerValue,devpriv->s_BoardInfos.\r
-                                       ui_Address + 0 + (20 * b_PWM) + (64 * b_ModulNbr));\r
-\r
-                               /*************************/\r
-                               /* Write the high timing */\r
-                               /*************************/\r
-\r
-                        outl(ul_HighTimerValue,devpriv->s_BoardInfos.\r
-                                       ui_Address + 4 + (20 * b_PWM) + (64 * b_ModulNbr));\r
-\r
-                               /***************************/\r
-                               /* Set the clock selection */\r
-                               /***************************/\r
-\r
-                         dw_Command=inl(devpriv->s_BoardInfos.\r
-                                      ui_Address + 8 + (20 * b_PWM) + (64 * b_ModulNbr));\r
-\r
-                               dw_Command = dw_Command & 0x7F;\r
-\r
-                               if (b_ClockSelection == APCI1710_40MHZ)\r
-                                  {\r
-                                  dw_Command = dw_Command | 0x80;\r
-                                  }\r
-\r
-                               /***************************/\r
-                               /* Set the clock selection */\r
-                               /***************************/\r
-\r
-                                 outl(dw_Command,devpriv->s_BoardInfos.\r
-                                       ui_Address + 8 + (20 * b_PWM) + (64 * b_ModulNbr));\r
-\r
-                               /*************/\r
-                               /* PWM init. */\r
-                               /*************/\r
-                               devpriv->\r
-                               s_ModuleInfo [b_ModulNbr].\r
-                               s_PWMModuleInfo.\r
-                               s_PWMInfo [b_PWM].\r
-                               b_PWMInit = 1;\r
-                               }\r
-                            else\r
-                               {\r
-                               /***************************************************/\r
-                               /* You can not used the 40MHz clock selection with */\r
-                               /* this board                                      */\r
-                               /***************************************************/\r
-                        DPRINTK("You can not used the 40MHz clock selection with this board\n");\r
-                               i_ReturnValue = -9;\r
-                               }\r
-                            }\r
-                         else\r
-                            {\r
-                            /***************************************/\r
-                            /* High base timing selection is wrong */\r
-                            /***************************************/\r
-                                DPRINTK("High base timing selection is wrong\n");\r
-                            i_ReturnValue = -8;\r
-                            }\r
-                         }\r
-                      else\r
-                         {\r
-                         /**************************************/\r
-                         /* Low base timing selection is wrong */\r
-                         /**************************************/\r
-                         DPRINTK("Low base timing selection is wrong\n");\r
-                         i_ReturnValue = -7;\r
-                         }\r
-                      } // if ((b_TimingUnit >= 0) && (b_TimingUnit <= 4))\r
-                   else\r
-                      {\r
-                      /**********************************/\r
-                      /* Timing unit selection is wrong */\r
-                      /**********************************/\r
-                          DPRINTK("Timing unit selection is wrong\n");\r
-                      i_ReturnValue = -6;\r
-                      } // if ((b_TimingUnit >= 0) && (b_TimingUnit <= 4))\r
-                   } // if ((b_ClockSelection == APCI1710_30MHZ) || (b_ClockSelection == APCI1710_33MHZ) || (b_ClockSelection == APCI1710_40MHZ))\r
-                else\r
-                   {\r
-                   /*******************************/\r
-                   /* The selected clock is wrong */\r
-                   /*******************************/\r
-                       DPRINTK("The selected clock is wrong\n"); \r
-                   i_ReturnValue = -5;\r
-                   } // if ((b_ClockSelection == APCI1710_30MHZ) || (b_ClockSelection == APCI1710_33MHZ) || (b_ClockSelection == APCI1710_40MHZ))\r
-                } // if (b_PWM >= 0 && b_PWM <= 1)\r
-             else\r
-                {\r
-                /******************************/\r
-                /* Tor PWM selection is wrong */\r
-                /******************************/\r
-                DPRINTK("Tor PWM selection is wrong\n");       \r
-                i_ReturnValue = -4;\r
-                } // if (b_PWM >= 0 && b_PWM <= 1)\r
-             }\r
-          else\r
-             {\r
-             /**********************************/\r
-             /* The module is not a PWM module */\r
-             /**********************************/\r
-             DPRINTK("The module is not a PWM module\n");      \r
-             i_ReturnValue = -3;\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /***********************/\r
-          /* Module number error */\r
-          /***********************/\r
-          DPRINTK("Module number error\n");    \r
-          i_ReturnValue = -2;\r
-          }\r
-\r
-       return (i_ReturnValue);\r
-       }\r
-\r
-\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : _INT_ i_APCI1710_GetPWMInitialisation                  |\r
-|                                       (BYTE_     b_BoardHandle,            |\r
-|                                        BYTE_     b_ModulNbr,               |\r
-|                                        BYTE_     b_PWM,                    |\r
-|                                        PBYTE_   pb_TimingUnit,             |\r
-|                                        PULONG_ pul_LowTiming,              |\r
-|                                        PULONG_ pul_HighTiming,             |\r
-|                                        PBYTE_   pb_StartLevel,             |\r
-|                                        PBYTE_   pb_StopMode,               |\r
-|                                        PBYTE_   pb_StopLevel,              |\r
-|                                        PBYTE_   pb_ExternGate,             |\r
-|                                        PBYTE_   pb_InterruptEnable,        |\r
-|                                        PBYTE_   pb_Enable)                 |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Return the PWM (b_PWM) initialisation from selected    |\r
-|                     module (b_ModulNbr). You must calling the              |\r
-|                     "i_APCI1710_InitPWM" function be for you call this     |\r
-|                     function.                                              |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : BYTE_ b_BoardHandle : Handle of board APCI-1710        |\r
-|                     BYTE_ b_ModulNbr    : Selected module number (0 to 3)  |\r
-|                     BYTE_ b_PWM         : Selected PWM (0 or 1)            |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : PBYTE_  pb_TimingUnit      : Base timing Unit (0 to 4) |\r
-|                                                       0 : ns               |\r
-|                                                       1 : æs               |\r
-|                                                       2 : ms               |\r
-|                                                       3 : s                |\r
-|                                                       4 : mn               |\r
-|                     PULONG_ pul_LowTiming      : Low base timing value.    |\r
-|                     PULONG_ pul_HighTiming     : High base timing value.   |\r
-|                     PBYTE_  pb_StartLevel      : Start period level        |\r
-|                                                  selection                 |\r
-|                                                       0 : The period start |\r
-|                                                           with a low level |\r
-|                                                       1 : The period start |\r
-|                                                           with a high level|\r
-|                     PBYTE_  pb_StopMode        : Stop mode selection       |\r
-|                                                  0 : The PWM is stopped    |\r
-|                                                      directly after the    |\r
-|                                                     "i_APCI1710_DisablePWM"|\r
-|                                                      function and break the|\r
-|                                                      last period           |\r
-|                                                  1 : After the             |\r
-|                                                     "i_APCI1710_DisablePWM"|\r
-|                                                      function the PWM is   |\r
-|                                                      stopped at the end    |\r
-|                                                      from last period cycle|\r
-|                     PBYTE_  pb_StopLevel        : Stop PWM level selection |\r
-|                                                    0 : The output signal   |\r
-|                                                        keep the level after|\r
-|                                                        the                 |\r
-|                                                     "i_APCI1710_DisablePWM"|\r
-|                                                        function            |\r
-|                                                    1 : The output signal is|\r
-|                                                        set to low after the|\r
-|                                                     "i_APCI1710_DisablePWM"|\r
-|                                                        function            |\r
-|                                                    2 : The output signal is|\r
-|                                                        set to high after   |\r
-|                                                        the                 |\r
-|                                                     "i_APCI1710_DisablePWM"|\r
-|                                                        function            |\r
-|                     PBYTE_  pb_ExternGate      : Extern gate action        |\r
-|                                                  selection                 |\r
-|                                                   0 : Extern gate signal   |\r
-|                                                       not used.            |\r
-|                                                   1 : Extern gate signal   |\r
-|                                                       used.                |\r
-|                     PBYTE_  pb_InterruptEnable : Enable or disable the PWM |\r
-|                                                  interrupt.                |\r
-|                                                  - APCI1710_ENABLE :       |\r
-|                                                    Enable the PWM interrupt|\r
-|                                                    A interrupt occur after |\r
-|                                                    each period             |\r
-|                                                  - APCI1710_DISABLE :      |\r
-|                                                    Disable the PWM         |\r
-|                                                    interrupt               |\r
-|                     PBYTE_  pb_Enable          : Indicate if the PWM is    |\r
-|                                                  enabled or no             |\r
-|                                                       0 : PWM not enabled  |\r
-|                                                       1 : PWM enabled      |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      :  0: No error                                           |\r
-|                     -1: The handle parameter of the board is wrong         |\r
-|                     -2: Module selection wrong                             |\r
-|                     -3: The module is not a PWM module                     |\r
-|                     -4: PWM selection is wrong                             |\r
-|                     -5: PWM not initialised see function                   |\r
-|                         "i_APCI1710_InitPWM"                               |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-INT  i_APCI1710_GetPWMInitialisation (comedi_device *dev,\r
-                                        BYTE     b_ModulNbr,\r
-                                        BYTE     b_PWM,\r
-                                        PBYTE   pb_TimingUnit,\r
-                                        PULONG pul_LowTiming,\r
-                                        PULONG pul_HighTiming,\r
-                                        PBYTE   pb_StartLevel,\r
-                                        PBYTE   pb_StopMode,\r
-                                        PBYTE   pb_StopLevel,\r
-                                        PBYTE   pb_ExternGate,\r
-                                        PBYTE   pb_InterruptEnable,\r
-                                        PBYTE   pb_Enable)\r
-       {\r
-       INT    i_ReturnValue = 0;\r
-       DWORD dw_Status;\r
-       DWORD dw_Command;\r
-\r
-               \r
-       \r
-       /**************************/\r
-       /* Test the module number */\r
-       /**************************/\r
-\r
-       if (b_ModulNbr < 4)\r
-          {\r
-          /***************/\r
-          /* Test if PWM */\r
-          /***************/\r
-\r
-          if ((devpriv->\r
-               s_BoardInfos.\r
-               dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_PWM)\r
-             {\r
-             /**************************/\r
-             /* Test the PWM selection */\r
-             /**************************/\r
-\r
-             if (b_PWM <= 1)\r
-                {\r
-                /***************************/\r
-                /* Test if PWM initialised */\r
-                /***************************/\r
-\r
-                  dw_Status=inl(devpriv->s_BoardInfos.\r
-                       ui_Address + 12 + (20 * b_PWM) + (64 * b_ModulNbr));\r
-\r
-                if (dw_Status & 0x10)\r
-                   {\r
-                   /***********************/\r
-                   /* Read the low timing */\r
-                   /***********************/\r
-\r
-                       *pul_LowTiming = inl(devpriv->s_BoardInfos.\r
-                          ui_Address + 0 + (20 * b_PWM) + (64 * b_ModulNbr));\r
-\r
-                   /************************/\r
-                   /* Read the high timing */\r
-                   /************************/\r
-\r
-                     *pul_HighTiming= inl(devpriv->s_BoardInfos.\r
-                          ui_Address + 4 + (20 * b_PWM) + (64 * b_ModulNbr));\r
-\r
-                   /********************/\r
-                   /* Read the command */\r
-                   /********************/\r
-\r
-                     dw_Command = inl(devpriv->s_BoardInfos.\r
-                          ui_Address + 8 + (20 * b_PWM) + (64 * b_ModulNbr));\r
-\r
-                   *pb_StartLevel      = (BYTE) ((dw_Command >> 5) & 1);\r
-                   *pb_StopMode        = (BYTE) ((dw_Command >> 0) & 1);\r
-                   *pb_StopLevel       = (BYTE) ((dw_Command >> 1) & 1);\r
-                   *pb_ExternGate      = (BYTE) ((dw_Command >> 4) & 1);\r
-                   *pb_InterruptEnable = (BYTE) ((dw_Command >> 3) & 1);\r
-\r
-                   if (*pb_StopLevel)\r
-                      {\r
-                      *pb_StopLevel = *pb_StopLevel + (BYTE) ((dw_Command >> 2) & 1);\r
-                      }\r
-\r
-                   /********************/\r
-                   /* Read the command */\r
-                   /********************/\r
-\r
-                     dw_Command=inl(devpriv->s_BoardInfos.\r
-                          ui_Address + 8 + (20 * b_PWM) + (64 * b_ModulNbr));\r
-\r
-                   *pb_Enable = (BYTE) ((dw_Command >> 0) & 1);\r
-\r
-                   *pb_TimingUnit = devpriv->\r
-                                    s_ModuleInfo [b_ModulNbr].\r
-                                    s_PWMModuleInfo.\r
-                                    s_PWMInfo [b_PWM].\r
-                                    b_TimingUnit;\r
-                   } // if (dw_Status & 0x10)\r
-                else\r
-                   {\r
-                   /***********************/\r
-                   /* PWM not initialised */\r
-                   /***********************/\r
-                    DPRINTK("PWM not initialised\n");\r
-                   i_ReturnValue = -5;\r
-                   } // if (dw_Status & 0x10)\r
-                } // if (b_PWM >= 0 && b_PWM <= 1)\r
-             else\r
-                {\r
-                /******************************/\r
-                /* Tor PWM selection is wrong */\r
-                /******************************/\r
-                DPRINTK("Tor PWM selection is wrong\n");\r
-                i_ReturnValue = -4;\r
-                } // if (b_PWM >= 0 && b_PWM <= 1)\r
-             }\r
-          else\r
-             {\r
-             /**********************************/\r
-             /* The module is not a PWM module */\r
-             /**********************************/\r
-             DPRINTK("The module is not a PWM module\n");      \r
-             i_ReturnValue = -3;\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /***********************/\r
-          /* Module number error */\r
-          /***********************/\r
-          DPRINTK("Module number error\n");\r
-          i_ReturnValue = -2;\r
-          }\r
-\r
-       return (i_ReturnValue);\r
-       }\r
-\r
-\r
-\r
-\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     :INT i_APCI1710_InsnWritePWM(comedi_device *dev,\r
-comedi_subdevice *s,comedi_insn *insn,lsampl_t *data)                        |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Pwm Enable Disable and Set New Timing                  |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : \r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : -                                                      |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      : \r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-INT    i_APCI1710_InsnWritePWM(comedi_device *dev,comedi_subdevice *s,\r
-comedi_insn *insn,lsampl_t *data)\r
-{\r
-       BYTE b_WriteType;\r
-       INT i_ReturnValue=0;\r
-    b_WriteType=CR_CHAN(insn->chanspec);\r
-\r
-    \r
-       switch(b_WriteType)\r
-       {\r
-       case APCI1710_PWM_ENABLE :\r
-               i_ReturnValue=i_APCI1710_EnablePWM    (dev,\r
-                                (BYTE)  CR_AREF(insn->chanspec),\r
-                                (BYTE)  data[0],\r
-                                (BYTE)  data[1],\r
-                                (BYTE)  data[2],\r
-                                (BYTE)  data[3],\r
-                                (BYTE)  data[4],\r
-                                (BYTE)  data[5]);\r
-               break;\r
-\r
-       case APCI1710_PWM_DISABLE :\r
-               i_ReturnValue=i_APCI1710_DisablePWM   (dev,\r
-                                (BYTE)  CR_AREF(insn->chanspec),\r
-                                (BYTE)  data[0]);\r
-               break;\r
-\r
-       case APCI1710_PWM_NEWTIMING:\r
-               i_ReturnValue=i_APCI1710_SetNewPWMTiming        (dev,\r
-                                        (BYTE)  CR_AREF(insn->chanspec),\r
-                                        (BYTE)  data[0],\r
-                                        (BYTE)    data[1],\r
-                                        (ULONG)   data[2],\r
-                                        (ULONG)   data[3]);\r
-               break;\r
-\r
-       \r
-       default:\r
-               printk("Write Config Parameter Wrong\n");\r
-       }\r
-\r
-       if(i_ReturnValue>=0) i_ReturnValue =insn->n;\r
-       return (i_ReturnValue);\r
-}\r
-\r
-\r
-\r
-\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : _INT_     i_APCI1710_EnablePWM                         |\r
-|                                       (BYTE_  b_BoardHandle,               |\r
-|                                        BYTE_  b_ModulNbr,                  |\r
-|                                        BYTE_  b_PWM,                       |\r
-|                                        BYTE_  b_StartLevel,                |\r
-|                                        BYTE_  b_StopMode,                  |\r
-|                                        BYTE_  b_StopLevel,                 |\r
-|                                        BYTE_  b_ExternGate,                |\r
-|                                        BYTE_  b_InterruptEnable)           |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Enable the selected PWM (b_PWM) from selected module   |\r
-|                     (b_ModulNbr). You must calling the "i_APCI1710_InitPWM"|\r
-|                     function be for you call this function.                |\r
-|                     If you enable the PWM interrupt, the PWM generate a    |\r
-|                     interrupt after each period.                           |\r
-|                     See function "i_APCI1710_SetBoardIntRoutineX" and the  |\r
-|                     Interrupt mask description chapter.                    |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : BYTE_ b_BoardHandle     : Handle of board APCI-1710    |\r
-|                     BYTE_ b_ModulNbr        : Selected module number       |\r
-|                                               (0 to 3)                     |\r
-|                     BYTE_ b_PWM             : Selected PWM (0 or 1)        |\r
-|                     BYTE_ b_StartLevel      : Start period level selection |\r
-|                                                0 : The period start with a |\r
-|                                                    low level               |\r
-|                                                1 : The period start with a |\r
-|                                                    high level              |\r
-|                     BYTE_ b_StopMode        : Stop mode selection          |\r
-|                                                0 : The PWM is stopped      |\r
-|                                                    directly after the      |\r
-|                                                    "i_APCI1710_DisablePWM" |\r
-|                                                    function and break the  |\r
-|                                                    last period             |\r
-|                                                1 : After the               |\r
-|                                                    "i_APCI1710_DisablePWM" |\r
-|                                                     function the PWM is    |\r
-|                                                     stopped at the end from|\r
-|                                                     last period cycle.     |\r
-|                     BYTE_ b_StopLevel       : Stop PWM level selection     |\r
-|                                                0 : The output signal keep  |\r
-|                                                    the level after the     |\r
-|                                                    "i_APCI1710_DisablePWM" |\r
-|                                                    function                |\r
-|                                                1 : The output signal is set|\r
-|                                                    to low after the        |\r
-|                                                    "i_APCI1710_DisablePWM" |\r
-|                                                    function                |\r
-|                                                2 : The output signal is set|\r
-|                                                    to high after the       |\r
-|                                                    "i_APCI1710_DisablePWM" |\r
-|                                                    function                |\r
-|                     BYTE_ b_ExternGate      : Extern gate action selection |\r
-|                                                0 : Extern gate signal not  |\r
-|                                                    used.                   |\r
-|                                                1 : Extern gate signal used.|\r
-|                     BYTE_ b_InterruptEnable : Enable or disable the PWM    |\r
-|                                               interrupt.                   |\r
-|                                               - APCI1710_ENABLE :          |\r
-|                                                 Enable the PWM interrupt   |\r
-|                                                 A interrupt occur after    |\r
-|                                                 each period                |\r
-|                                               - APCI1710_DISABLE :         |\r
-|                                                 Disable the PWM interrupt  |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : -                                                      |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      : 0:  No error                                           |\r
-|                    -1:  The handle parameter of the board is wrong         |\r
-|                    -2:  Module selection wrong                             |\r
-|                    -3:  The module is not a PWM module                     |\r
-|                    -4:  PWM selection is wrong                             |\r
-|                    -5:  PWM not initialised see function                   |\r
-|                         "i_APCI1710_InitPWM"                               |\r
-|                    -6:  PWM start level selection is wrong                 |\r
-|                    -7:  PWM stop mode selection is wrong                   |\r
-|                    -8:  PWM stop level selection is wrong                  |\r
-|                    -9:  Extern gate signal selection is wrong              |\r
-|                    -10: Interrupt parameter is wrong                       |\r
-|                    -11: Interrupt function not initialised.                |\r
-|                         See function "i_APCI1710_SetBoardIntRoutineX"      |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-INT   i_APCI1710_EnablePWM    (comedi_device *dev,\r
-                                BYTE  b_ModulNbr,\r
-                                BYTE  b_PWM,\r
-                                BYTE  b_StartLevel,\r
-                                BYTE  b_StopMode,\r
-                                BYTE  b_StopLevel,\r
-                                BYTE  b_ExternGate,\r
-                                BYTE  b_InterruptEnable)\r
-       {\r
-       INT    i_ReturnValue = 0;\r
-       DWORD dw_Status;\r
-       DWORD dw_Command;\r
-\r
-               \r
-        devpriv->tsk_Current=current; // Save the current process task structure\r
-       /**************************/\r
-       /* Test the module number */\r
-       /**************************/\r
-\r
-       if (b_ModulNbr < 4)\r
-          {\r
-          /***************/\r
-          /* Test if PWM */\r
-          /***************/\r
-\r
-          if ((devpriv->\r
-               s_BoardInfos.\r
-               dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_PWM)\r
-             {\r
-             /**************************/\r
-             /* Test the PWM selection */\r
-             /**************************/\r
-\r
-             if (b_PWM <= 1)\r
-                {\r
-                /***************************/\r
-                /* Test if PWM initialised */\r
-                /***************************/\r
-\r
-                dw_Status=      inl(devpriv->s_BoardInfos.\r
-                       ui_Address + 12 + (20 * b_PWM) + (64 * b_ModulNbr));\r
-\r
-                if (dw_Status & 0x10)\r
-                   {\r
-                   /**********************************/\r
-                   /* Test the start level selection */\r
-                   /**********************************/\r
-\r
-                   if (b_StartLevel <= 1)\r
-                      {\r
-                      /**********************/\r
-                      /* Test the stop mode */\r
-                      /**********************/\r
-\r
-                      if (b_StopMode <= 1)\r
-                         {\r
-                         /***********************/\r
-                         /* Test the stop level */\r
-                         /***********************/\r
-\r
-                         if (b_StopLevel <= 2)\r
-                            {\r
-                            /*****************************/\r
-                            /* Test the extern gate mode */\r
-                            /*****************************/\r
-\r
-                            if (b_ExternGate <= 1)\r
-                               {\r
-                               /*****************************/\r
-                               /* Test the interrupt action */\r
-                               /*****************************/\r
-\r
-                               if (b_InterruptEnable == APCI1710_ENABLE || b_InterruptEnable == APCI1710_DISABLE)\r
-                                  {\r
-                                  /******************************************/\r
-                                  /* Test if interrupt function initialised */\r
-                                  /******************************************/\r
-\r
-                                     /********************/\r
-                                     /* Read the command */\r
-                                     /********************/\r
-\r
-                                           dw_Command=inl(devpriv->s_BoardInfos.\r
-                                            ui_Address + 8 + (20 * b_PWM) + (64 * b_ModulNbr));\r
-\r
-                                     dw_Command = dw_Command & 0x80;\r
-\r
-                                     /********************/\r
-                                     /* Make the command */\r
-                                     /********************/\r
-\r
-                                     dw_Command = dw_Command | b_StopMode | (b_InterruptEnable << 3) | (b_ExternGate << 4) | (b_StartLevel << 5);\r
-\r
-                                     if (b_StopLevel & 3)\r
-                                        {\r
-                                        dw_Command = dw_Command | 2;\r
-\r
-                                        if (b_StopLevel & 2)\r
-                                           {\r
-                                           dw_Command = dw_Command | 4;\r
-                                           }\r
-                                        }\r
-\r
-\r
-                                     devpriv->\r
-                                     s_ModuleInfo [b_ModulNbr].\r
-                                     s_PWMModuleInfo.\r
-                                     s_PWMInfo [b_PWM].\r
-                                     b_InterruptEnable = b_InterruptEnable;\r
-\r
-                                     /*******************/\r
-                                     /* Set the command */\r
-                                     /*******************/\r
-\r
-                                         outl(dw_Command,devpriv->s_BoardInfos.\r
-                                             ui_Address + 8 + (20 * b_PWM) + (64 * b_ModulNbr));\r
-\r
-                                     /******************/\r
-                                     /* Enable the PWM */\r
-                                     /******************/\r
-                                         outl(1,devpriv->s_BoardInfos.\r
-                                             ui_Address + 12 + (20 * b_PWM) + (64 * b_ModulNbr));\r
-                                  } // if (b_InterruptEnable == APCI1710_ENABLE || b_InterruptEnable == APCI1710_DISABLE)\r
-                               else\r
-                                  {\r
-                                  /********************************/\r
-                                  /* Interrupt parameter is wrong */\r
-                                  /********************************/\r
-                           DPRINTK("Interrupt parameter is wrong\n");\r
-                                  i_ReturnValue = -10;\r
-                                  } // if (b_InterruptEnable == APCI1710_ENABLE || b_InterruptEnable == APCI1710_DISABLE)\r
-                               } // if (b_ExternGate >= 0 && b_ExternGate <= 1)\r
-                            else\r
-                               {\r
-                               /*****************************************/\r
-                               /* Extern gate signal selection is wrong */\r
-                               /*****************************************/\r
-                               DPRINTK("Extern gate signal selection is wrong\n");\r
-                               i_ReturnValue = -9;\r
-                               } // if (b_ExternGate >= 0 && b_ExternGate <= 1)\r
-                            } // if (b_StopLevel >= 0 && b_StopLevel <= 2)\r
-                         else\r
-                            {\r
-                            /*************************************/\r
-                            /* PWM stop level selection is wrong */\r
-                            /*************************************/\r
-                                DPRINTK("PWM stop level selection is wrong\n");\r
-                            i_ReturnValue = -8;\r
-                            } // if (b_StopLevel >= 0 && b_StopLevel <= 2)\r
-                         } // if (b_StopMode >= 0 && b_StopMode <= 1)\r
-                      else\r
-                         {\r
-                         /************************************/\r
-                         /* PWM stop mode selection is wrong */\r
-                         /************************************/\r
-                         DPRINTK("PWM stop mode selection is wrong\n");        \r
-                         i_ReturnValue = -7;\r
-                         } // if (b_StopMode >= 0 && b_StopMode <= 1)\r
-                      } // if (b_StartLevel >= 0 && b_StartLevel <= 1)\r
-                   else\r
-                      {\r
-                      /**************************************/\r
-                      /* PWM start level selection is wrong */\r
-                      /**************************************/\r
-                          DPRINTK("PWM start level selection is wrong\n");       \r
-                      i_ReturnValue = -6;\r
-                      } // if (b_StartLevel >= 0 && b_StartLevel <= 1)\r
-                   } // if (dw_Status & 0x10)\r
-                else\r
-                   {\r
-                   /***********************/\r
-                   /* PWM not initialised */\r
-                   /***********************/\r
-                       DPRINTK("PWM not initialised\n");\r
-                   i_ReturnValue = -5;\r
-                   } // if (dw_Status & 0x10)\r
-                } // if (b_PWM >= 0 && b_PWM <= 1)\r
-             else\r
-                {\r
-                /******************************/\r
-                /* Tor PWM selection is wrong */\r
-                /******************************/\r
-                DPRINTK("Tor PWM selection is wrong\n");\r
-                i_ReturnValue = -4;\r
-                } // if (b_PWM >= 0 && b_PWM <= 1)\r
-             }\r
-          else\r
-             {\r
-             /**********************************/\r
-             /* The module is not a PWM module */\r
-             /**********************************/\r
-             DPRINTK("The module is not a PWM module\n");      \r
-             i_ReturnValue = -3;\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /***********************/\r
-          /* Module number error */\r
-          /***********************/\r
-          DPRINTK("Module number error\n");    \r
-          i_ReturnValue = -2;\r
-          }\r
-\r
-       return (i_ReturnValue);\r
-       }\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : _INT_ i_APCI1710_DisablePWM (BYTE_  b_BoardHandle,     |\r
-|                                                  BYTE_  b_ModulNbr,        |\r
-|                                                  BYTE_  b_PWM)             |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Disable the selected PWM (b_PWM) from selected module  |\r
-|                     (b_ModulNbr). The output signal level depend of the    |\r
-|                     initialisation by the "i_APCI1710_EnablePWM".          |\r
-|                     See the b_StartLevel, b_StopMode and b_StopLevel       |\r
-|                     parameters from this function.                         |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  :BYTE_ b_BoardHandle : Handle of board APCI-1710         |\r
-|                    BYTE_ b_ModulNbr    : Selected module number (0 to 3)   |\r
-|                    BYTE_ b_PWM         : Selected PWM (0 or 1)             |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : -                                                      |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      :  0: No error                                           |\r
-|                     -1: The handle parameter of the board is wrong         |\r
-|                     -2: Module selection wrong                             |\r
-|                     -3: The module is not a PWM module                     |\r
-|                     -4: PWM selection is wrong                             |\r
-|                     -5: PWM not initialised see function                   |\r
-|                         "i_APCI1710_InitPWM"                               |\r
-|                     -6: PWM not enabled see function                       |\r
-|                         "i_APCI1710_EnablePWM"                             |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-INT   i_APCI1710_DisablePWM   (comedi_device *dev,\r
-                                BYTE  b_ModulNbr,\r
-                                BYTE  b_PWM)\r
-       {\r
-       INT    i_ReturnValue = 0;\r
-       DWORD dw_Status;\r
-\r
-       /**************************/\r
-       /* Test the module number */\r
-       /**************************/\r
-\r
-       if (b_ModulNbr < 4)\r
-          {\r
-          /***************/\r
-          /* Test if PWM */\r
-          /***************/\r
-\r
-          if ((devpriv->s_BoardInfos.\r
-               dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_PWM)\r
-             {\r
-             /**************************/\r
-             /* Test the PWM selection */\r
-             /**************************/\r
-\r
-             if (b_PWM <= 1)\r
-                {\r
-                /***************************/\r
-                /* Test if PWM initialised */\r
-                /***************************/\r
-\r
-           dw_Status=inl(devpriv->s_BoardInfos.\r
-                       ui_Address + 12 + (20 * b_PWM) + (64 * b_ModulNbr));\r
-\r
-                if (dw_Status & 0x10)\r
-                   {\r
-                   /***********************/\r
-                   /* Test if PWM enabled */\r
-                   /***********************/\r
-\r
-                   if (dw_Status & 0x1)\r
-                      {\r
-                      /*******************/\r
-                      /* Disable the PWM */\r
-                      /*******************/\r
-                               outl(0,devpriv->s_BoardInfos.\r
-                              ui_Address + 12 + (20 * b_PWM) + (64 * b_ModulNbr));\r
-                      } // if (dw_Status & 0x1)\r
-                   else\r
-                      {\r
-                      /*******************/\r
-                      /* PWM not enabled */\r
-                      /*******************/\r
-                          DPRINTK("PWM not enabled\n");        \r
-                      i_ReturnValue = -6;\r
-                      } // if (dw_Status & 0x1)\r
-                   } // if (dw_Status & 0x10)\r
-                else\r
-                   {\r
-                   /***********************/\r
-                   /* PWM not initialised */\r
-                   /***********************/\r
-                       DPRINTK(" PWM not initialised\n");\r
-                   i_ReturnValue = -5;\r
-                   } // if (dw_Status & 0x10)\r
-                } // if (b_PWM >= 0 && b_PWM <= 1)\r
-             else\r
-                {\r
-                /******************************/\r
-                /* Tor PWM selection is wrong */\r
-                /******************************/\r
-                DPRINTK("Tor PWM selection is wrong\n");       \r
-                i_ReturnValue = -4;\r
-                } // if (b_PWM >= 0 && b_PWM <= 1)\r
-             }\r
-          else\r
-             {\r
-             /**********************************/\r
-             /* The module is not a PWM module */\r
-             /**********************************/\r
-             DPRINTK("The module is not a PWM module\n");      \r
-             i_ReturnValue = -3;\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /***********************/\r
-          /* Module number error */\r
-          /***********************/\r
-          DPRINTK("Module number error\n");\r
-          i_ReturnValue = -2;\r
-          }\r
-\r
-       return (i_ReturnValue);\r
-       }\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : _INT_ i_APCI1710_SetNewPWMTiming                       |\r
-|                                       (BYTE_     b_BoardHandle,            |\r
-|                                        BYTE_     b_ModulNbr,               |\r
-|                                        BYTE_     b_PWM,                    |\r
-|                                        BYTE_     b_ClockSelection,         |\r
-|                                        BYTE_     b_TimingUnit,             |\r
-|                                        ULONG_   ul_LowTiming,              |\r
-|                                        ULONG_   ul_HighTiming)             |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Set a new timing. The ul_LowTiming, ul_HighTiming and  |\r
-|                     ul_TimingUnit determine the low/high timing base for   |\r
-|                     the period.                                            |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : BYTE_     b_BoardHandle    : Handle of board APCI-1710 |\r
-|                     BYTE_     b_ModulNbr       : Module number to configure|\r
-|                                                  (0 to 3)                  |\r
-|                     BYTE_     b_PWM            : Selected PWM (0 or 1).    |\r
-|                     BYTE_     b_TimingUnit     : Base timing Unit (0 to 4) |\r
-|                                                       0 : ns               |\r
-|                                                       1 : æs               |\r
-|                                                       2 : ms               |\r
-|                                                       3 : s                |\r
-|                                                       4 : mn               |\r
-|                     ULONG_    ul_LowTiming     : Low base timing value.    |\r
-|                     ULONG_    ul_HighTiming    : High base timing value.   |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : -                                                      |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      : 0: No error                                            |\r
-|                    -1: The handle parameter of the board is wrong          |\r
-|                    -2: Module selection wrong                              |\r
-|                    -3: The module is not a PWM module                      |\r
-|                    -4: PWM selection is wrong                              |\r
-|                    -5: PWM not initialised                                 |\r
-|                    -6: Timing Unit selection is wrong                      |\r
-|                    -7: Low base timing selection is wrong                  |\r
-|                    -8: High base timing selection is wrong                 |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-INT   i_APCI1710_SetNewPWMTiming       (comedi_device *dev,\r
-                                        BYTE     b_ModulNbr,\r
-                                        BYTE     b_PWM,\r
-                                        BYTE     b_TimingUnit,\r
-                                        ULONG   ul_LowTiming,\r
-                                        ULONG   ul_HighTiming)\r
-       {\r
-       BYTE   b_ClockSelection;\r
-       INT    i_ReturnValue = 0;\r
-       ULONG ul_LowTimerValue = 0;\r
-       ULONG ul_HighTimerValue = 0;\r
-       ULONG ul_RealLowTiming = 0;\r
-       ULONG ul_RealHighTiming = 0;\r
-       DWORD dw_Status;\r
-       DWORD dw_Command;\r
-       double d_RealLowTiming = 0;\r
-       double d_RealHighTiming = 0;\r
-       \r
-\r
-       /**************************/\r
-       /* Test the module number */\r
-       /**************************/\r
-\r
-       if (b_ModulNbr < 4)\r
-          {\r
-          /***************/\r
-          /* Test if PWM */\r
-          /***************/\r
-\r
-          if ((devpriv->s_BoardInfos.\r
-               dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_PWM)\r
-             {\r
-             /**************************/\r
-             /* Test the PWM selection */\r
-             /**************************/\r
-\r
-             if (b_PWM <= 1)\r
-                {\r
-                /***************************/\r
-                /* Test if PWM initialised */\r
-                /***************************/\r
-\r
-                       dw_Status=inl(devpriv->s_BoardInfos.\r
-                       ui_Address + 12 + (20 * b_PWM) + (64 * b_ModulNbr));\r
-\r
-                if (dw_Status & 0x10)\r
-                   {\r
-                   b_ClockSelection = devpriv->\r
-                                      s_ModuleInfo [b_ModulNbr].\r
-                                      s_PWMModuleInfo.\r
-                                      b_ClockSelection;\r
-\r
-                   /************************/\r
-                   /* Test the timing unit */\r
-                   /************************/\r
-\r
-                   if (b_TimingUnit <= 4)\r
-                      {\r
-                      /*********************************/\r
-                      /* Test the low timing selection */\r
-                      /*********************************/\r
-\r
-                      if (((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 0) && (ul_LowTiming >= 266) && (ul_LowTiming <= 0xFFFFFFFFUL)) ||\r
-                          ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 1) && (ul_LowTiming >= 1)   && (ul_LowTiming <= 571230650UL))  ||\r
-                          ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 2) && (ul_LowTiming >= 1)   && (ul_LowTiming <= 571230UL))     ||\r
-                          ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 3) && (ul_LowTiming >= 1)   && (ul_LowTiming <= 571UL))        ||\r
-                          ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 4) && (ul_LowTiming >= 1)   && (ul_LowTiming <= 9UL))          ||\r
-                          ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 0) && (ul_LowTiming >= 242) && (ul_LowTiming <= 0xFFFFFFFFUL)) ||\r
-                          ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 1) && (ul_LowTiming >= 1)   && (ul_LowTiming <= 519691043UL))  ||\r
-                          ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 2) && (ul_LowTiming >= 1)   && (ul_LowTiming <= 519691UL))     ||\r
-                          ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 3) && (ul_LowTiming >= 1)   && (ul_LowTiming <= 520UL))        ||\r
-                          ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 4) && (ul_LowTiming >= 1)   && (ul_LowTiming <= 8UL))          ||\r
-                          ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 0) && (ul_LowTiming >= 200) && (ul_LowTiming <= 0xFFFFFFFFUL)) ||\r
-                          ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 1) && (ul_LowTiming >= 1)   && (ul_LowTiming <= 429496729UL))  ||\r
-                          ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 2) && (ul_LowTiming >= 1)   && (ul_LowTiming <= 429496UL))     ||\r
-                          ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 3) && (ul_LowTiming >= 1)   && (ul_LowTiming <= 429UL))        ||\r
-                          ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 4) && (ul_LowTiming >= 1)   && (ul_LowTiming <= 7UL)))\r
-                         {\r
-                         /**********************************/\r
-                         /* Test the High timing selection */\r
-                         /**********************************/\r
-\r
-                         if (((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 0) && (ul_HighTiming >= 266) && (ul_HighTiming <= 0xFFFFFFFFUL)) ||\r
-                             ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 1) && (ul_HighTiming >= 1)   && (ul_HighTiming <= 571230650UL))  ||\r
-                             ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 2) && (ul_HighTiming >= 1)   && (ul_HighTiming <= 571230UL))     ||\r
-                             ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 3) && (ul_HighTiming >= 1)   && (ul_HighTiming <= 571UL))        ||\r
-                             ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 4) && (ul_HighTiming >= 1)   && (ul_HighTiming <= 9UL))          ||\r
-                             ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 0) && (ul_HighTiming >= 242) && (ul_HighTiming <= 0xFFFFFFFFUL)) ||\r
-                             ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 1) && (ul_HighTiming >= 1)   && (ul_HighTiming <= 519691043UL))  ||\r
-                             ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 2) && (ul_HighTiming >= 1)   && (ul_HighTiming <= 519691UL))     ||\r
-                             ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 3) && (ul_HighTiming >= 1)   && (ul_HighTiming <= 520UL))        ||\r
-                             ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 4) && (ul_HighTiming >= 1)   && (ul_HighTiming <= 8UL))          ||\r
-                             ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 0) && (ul_HighTiming >= 200) && (ul_HighTiming <= 0xFFFFFFFFUL)) ||\r
-                             ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 1) && (ul_HighTiming >= 1)   && (ul_HighTiming <= 429496729UL))  ||\r
-                             ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 2) && (ul_HighTiming >= 1)   && (ul_HighTiming <= 429496UL))     ||\r
-                             ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 3) && (ul_HighTiming >= 1)   && (ul_HighTiming <= 429UL))        ||\r
-                             ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 4) && (ul_HighTiming >= 1)   && (ul_HighTiming <= 7UL)))\r
-                            {\r
-                            /************************************/\r
-                            /* Calculate the low division fator */\r
-                            /************************************/\r
-\r
-                            fpu_begin ();\r
-                            switch (b_TimingUnit)\r
-                               {\r
-                               /******/\r
-                               /* ns */\r
-                               /******/\r
-\r
-                               case 0:\r
-                                    \r
-                                       /******************/\r
-                                       /* Timer 0 factor */\r
-                                       /******************/\r
-\r
-                                       ul_LowTimerValue = (ULONG) (ul_LowTiming * (0.00025 * b_ClockSelection));\r
-\r
-                                       /*******************/\r
-                                       /* Round the value */\r
-                                       /*******************/\r
-\r
-                                       if ((double) ((double) ul_LowTiming * (0.00025 * (double) b_ClockSelection)) >= ((double) ((double) ul_LowTimerValue + 0.5)))\r
-                                          {\r
-                                          ul_LowTimerValue = ul_LowTimerValue + 1;\r
-                                          }\r
-\r
-                                       /*****************************/\r
-                                       /* Calculate the real timing */\r
-                                       /*****************************/\r
-\r
-                                       ul_RealLowTiming = (ULONG) (ul_LowTimerValue / (0.00025 * (double) b_ClockSelection));\r
-                                       d_RealLowTiming = (double) ul_LowTimerValue / (0.00025 * (double) b_ClockSelection);\r
-\r
-                                       if ((double) ((double) ul_LowTimerValue / (0.00025 * (double) b_ClockSelection)) >= (double) ((double) ul_RealLowTiming + 0.5))\r
-                                          {\r
-                                          ul_RealLowTiming = ul_RealLowTiming + 1;\r
-                                          }\r
-\r
-                                       ul_LowTiming     = ul_LowTiming - 1;\r
-                                       ul_LowTimerValue = ul_LowTimerValue - 2;\r
-\r
-                                       if (b_ClockSelection != APCI1710_40MHZ)\r
-                                          {\r
-                                          ul_LowTimerValue = (ULONG) ((double) (ul_LowTimerValue) * 1.007752288);\r
-                                          }\r
-                                   \r
-\r
-                                    break;\r
-\r
-                               /******/\r
-                               /* æs */\r
-                               /******/\r
-\r
-                               case 1:\r
-                                   \r
-                                       /******************/\r
-                                       /* Timer 0 factor */\r
-                                       /******************/\r
-\r
-                                       ul_LowTimerValue = (ULONG) (ul_LowTiming * (0.25 * b_ClockSelection));\r
-\r
-                                       /*******************/\r
-                                       /* Round the value */\r
-                                       /*******************/\r
-\r
-                                       if ((double) ((double) ul_LowTiming * (0.25 * (double) b_ClockSelection)) >= ((double) ((double) ul_LowTimerValue + 0.5)))\r
-                                          {\r
-                                          ul_LowTimerValue = ul_LowTimerValue + 1;\r
-                                          }\r
-\r
-                                       /*****************************/\r
-                                       /* Calculate the real timing */\r
-                                       /*****************************/\r
-\r
-                                       ul_RealLowTiming = (ULONG) (ul_LowTimerValue / (0.25 * (double) b_ClockSelection));\r
-                                       d_RealLowTiming    = (double) ul_LowTimerValue / ((double) 0.25 * (double) b_ClockSelection);\r
-\r
-                                       if ((double) ((double) ul_LowTimerValue / (0.25 * (double) b_ClockSelection)) >= (double) ((double) ul_RealLowTiming + 0.5))\r
-                                          {\r
-                                          ul_RealLowTiming = ul_RealLowTiming + 1;\r
-                                          }\r
-\r
-                                       ul_LowTiming     = ul_LowTiming - 1;\r
-                                       ul_LowTimerValue = ul_LowTimerValue - 2;\r
-\r
-                                       if (b_ClockSelection != APCI1710_40MHZ)\r
-                                          {\r
-                                          ul_LowTimerValue = (ULONG) ((double) (ul_LowTimerValue) * 1.007752288);\r
-                                          }\r
-                                   \r
-                                    break;\r
-\r
-                               /******/\r
-                               /* ms */\r
-                               /******/\r
-\r
-                               case 2:\r
-                                    \r
-                                       /******************/\r
-                                       /* Timer 0 factor */\r
-                                       /******************/\r
-\r
-                                       ul_LowTimerValue = ul_LowTiming * (250.0 * b_ClockSelection);\r
-\r
-                                       /*******************/\r
-                                       /* Round the value */\r
-                                       /*******************/\r
-\r
-                                       if ((double) ((double) ul_LowTiming * (250.0 * (double) b_ClockSelection)) >= ((double) ((double) ul_LowTimerValue + 0.5)))\r
-                                          {\r
-                                          ul_LowTimerValue = ul_LowTimerValue + 1;\r
-                                          }\r
-\r
-                                       /*****************************/\r
-                                       /* Calculate the real timing */\r
-                                       /*****************************/\r
-\r
-                                       ul_RealLowTiming = (ULONG) (ul_LowTimerValue / (250.0 * (double) b_ClockSelection));\r
-                                       d_RealLowTiming    = (double) ul_LowTimerValue / (250.0 * (double) b_ClockSelection);\r
-\r
-                                       if ((double) ((double) ul_LowTimerValue / (250.0 * (double) b_ClockSelection)) >= (double) ((double) ul_RealLowTiming + 0.5))\r
-                                          {\r
-                                          ul_RealLowTiming = ul_RealLowTiming + 1;\r
-                                          }\r
-\r
-                                       ul_LowTiming     = ul_LowTiming - 1;\r
-                                       ul_LowTimerValue = ul_LowTimerValue - 2;\r
-\r
-                                       if (b_ClockSelection != APCI1710_40MHZ)\r
-                                          {\r
-                                          ul_LowTimerValue = (ULONG) ((double) (ul_LowTimerValue) * 1.007752288);\r
-                                          }\r
-                                    \r
-                                    break;\r
-\r
-                               /*****/\r
-                               /* s */\r
-                               /*****/\r
-\r
-                               case 3:\r
-                                    \r
-                                       /******************/\r
-                                       /* Timer 0 factor */\r
-                                       /******************/\r
-\r
-                                       ul_LowTimerValue = (ULONG) (ul_LowTiming * (250000.0 * b_ClockSelection));\r
-\r
-                                       /*******************/\r
-                                       /* Round the value */\r
-                                       /*******************/\r
-\r
-                                       if ((double) ((double) ul_LowTiming * (250000.0 * (double) b_ClockSelection)) >= ((double) ((double) ul_LowTimerValue + 0.5)))\r
-                                          {\r
-                                          ul_LowTimerValue = ul_LowTimerValue + 1;\r
-                                          }\r
-\r
-                                       /*****************************/\r
-                                       /* Calculate the real timing */\r
-                                       /*****************************/\r
-\r
-                                       ul_RealLowTiming = (ULONG) (ul_LowTimerValue / (250000.0 * (double) b_ClockSelection));\r
-                                       d_RealLowTiming    = (double) ul_LowTimerValue / (250000.0 * (double) b_ClockSelection);\r
-\r
-                                       if ((double) ((double) ul_LowTimerValue / (250000.0 * (double) b_ClockSelection)) >= (double) ((double) ul_RealLowTiming + 0.5))\r
-                                          {\r
-                                          ul_RealLowTiming = ul_RealLowTiming + 1;\r
-                                          }\r
-\r
-                                       ul_LowTiming     = ul_LowTiming - 1;\r
-                                       ul_LowTimerValue = ul_LowTimerValue - 2;\r
-\r
-                                       if (b_ClockSelection != APCI1710_40MHZ)\r
-                                          {\r
-                                          ul_LowTimerValue = (ULONG) ((double) (ul_LowTimerValue) * 1.007752288);\r
-                                          }\r
-                                   \r
-                                    break;\r
-\r
-                               /******/\r
-                               /* mn */\r
-                               /******/\r
-\r
-                               case 4:\r
-                                    \r
-                                       /******************/\r
-                                       /* Timer 0 factor */\r
-                                       /******************/\r
-\r
-                                       ul_LowTimerValue = (ULONG) ((ul_LowTiming * 60) * (250000.0 * b_ClockSelection));\r
-\r
-                                       /*******************/\r
-                                       /* Round the value */\r
-                                       /*******************/\r
-\r
-                                       if ((double) ((double) (ul_LowTiming * 60.0) * (250000.0 * (double) b_ClockSelection)) >= ((double) ((double) ul_LowTimerValue + 0.5)))\r
-                                          {\r
-                                          ul_LowTimerValue = ul_LowTimerValue + 1;\r
-                                          }\r
-\r
-                                       /*****************************/\r
-                                       /* Calculate the real timing */\r
-                                       /*****************************/\r
-\r
-                                       ul_RealLowTiming = (ULONG) (ul_LowTimerValue / (250000.0 * (double) b_ClockSelection)) / 60;\r
-                                       d_RealLowTiming    = ((double) ul_LowTimerValue / (250000.0 * (double) b_ClockSelection)) / 60.0;\r
-\r
-                                       if ((double) (((double) ul_LowTimerValue / (250000.0 * (double) b_ClockSelection)) / 60.0) >= (double) ((double) ul_RealLowTiming + 0.5))\r
-                                          {\r
-                                          ul_RealLowTiming = ul_RealLowTiming + 1;\r
-                                          }\r
-\r
-                                       ul_LowTiming     = ul_LowTiming - 1;\r
-                                       ul_LowTimerValue = ul_LowTimerValue - 2;\r
-\r
-                                       if (b_ClockSelection != APCI1710_40MHZ)\r
-                                          {\r
-                                          ul_LowTimerValue = (ULONG) ((double) (ul_LowTimerValue) * 1.007752288);\r
-                                          }\r
-                                    \r
-                                    break;\r
-                               }\r
-\r
-                            /*************************************/\r
-                            /* Calculate the high division fator */\r
-                            /*************************************/\r
-\r
-                            switch (b_TimingUnit)\r
-                               {\r
-                               /******/\r
-                               /* ns */\r
-                               /******/\r
-\r
-                               case 0:\r
-                                   \r
-                                       /******************/\r
-                                       /* Timer 0 factor */\r
-                                       /******************/\r
-\r
-                                       ul_HighTimerValue = (ULONG) (ul_HighTiming * (0.00025 * b_ClockSelection));\r
-\r
-                                       /*******************/\r
-                                       /* Round the value */\r
-                                       /*******************/\r
-\r
-                                       if ((double) ((double) ul_HighTiming * (0.00025 * (double) b_ClockSelection)) >= ((double) ((double) ul_HighTimerValue + 0.5)))\r
-                                          {\r
-                                          ul_HighTimerValue = ul_HighTimerValue + 1;\r
-                                          }\r
-\r
-                                       /*****************************/\r
-                                       /* Calculate the real timing */\r
-                                       /*****************************/\r
-\r
-                                       ul_RealHighTiming = (ULONG) (ul_HighTimerValue / (0.00025 * (double) b_ClockSelection));\r
-                                       d_RealHighTiming    = (double) ul_HighTimerValue / (0.00025 * (double) b_ClockSelection);\r
-\r
-                                       if ((double) ((double) ul_HighTimerValue / (0.00025 * (double) b_ClockSelection)) >= (double) ((double) ul_RealHighTiming + 0.5))\r
-                                          {\r
-                                          ul_RealHighTiming = ul_RealHighTiming + 1;\r
-                                          }\r
-\r
-                                       ul_HighTiming     = ul_HighTiming - 1;\r
-                                       ul_HighTimerValue = ul_HighTimerValue - 2;\r
-\r
-                                       if (b_ClockSelection != APCI1710_40MHZ)\r
-                                          {\r
-                                          ul_HighTimerValue = (ULONG) ((double) (ul_HighTimerValue) * 1.007752288);\r
-                                          }\r
-                                    \r
-\r
-                                    break;\r
-\r
-                               /******/\r
-                               /* æs */\r
-                               /******/\r
-\r
-                               case 1:\r
-                                    \r
-                                       /******************/\r
-                                       /* Timer 0 factor */\r
-                                       /******************/\r
-\r
-                                       ul_HighTimerValue = (ULONG) (ul_HighTiming * (0.25 * b_ClockSelection));\r
-\r
-                                       /*******************/\r
-                                       /* Round the value */\r
-                                       /*******************/\r
-\r
-                                       if ((double) ((double) ul_HighTiming * (0.25 * (double) b_ClockSelection)) >= ((double) ((double) ul_HighTimerValue + 0.5)))\r
-                                          {\r
-                                          ul_HighTimerValue = ul_HighTimerValue + 1;\r
-                                          }\r
-\r
-                                       /*****************************/\r
-                                       /* Calculate the real timing */\r
-                                       /*****************************/\r
-\r
-                                       ul_RealHighTiming = (ULONG) (ul_HighTimerValue / (0.25 * (double) b_ClockSelection));\r
-                                       d_RealHighTiming    = (double) ul_HighTimerValue / ((double) 0.25 * (double) b_ClockSelection);\r
-\r
-                                       if ((double) ((double) ul_HighTimerValue / (0.25 * (double) b_ClockSelection)) >= (double) ((double) ul_RealHighTiming + 0.5))\r
-                                          {\r
-                                          ul_RealHighTiming = ul_RealHighTiming + 1;\r
-                                          }\r
-\r
-                                       ul_HighTiming     = ul_HighTiming - 1;\r
-                                       ul_HighTimerValue = ul_HighTimerValue - 2;\r
-\r
-                                       if (b_ClockSelection != APCI1710_40MHZ)\r
-                                          {\r
-                                          ul_HighTimerValue = (ULONG) ((double) (ul_HighTimerValue) * 1.007752288);\r
-                                          }\r
-                                   \r
-                                    break;\r
-\r
-                               /******/\r
-                               /* ms */\r
-                               /******/\r
-\r
-                               case 2:\r
-                                    \r
-                                       /******************/\r
-                                       /* Timer 0 factor */\r
-                                       /******************/\r
-\r
-                                       ul_HighTimerValue = ul_HighTiming * (250.0 * b_ClockSelection);\r
-\r
-                                       /*******************/\r
-                                       /* Round the value */\r
-                                       /*******************/\r
-\r
-                                       if ((double) ((double) ul_HighTiming * (250.0 * (double) b_ClockSelection)) >= ((double) ((double) ul_HighTimerValue + 0.5)))\r
-                                          {\r
-                                          ul_HighTimerValue = ul_HighTimerValue + 1;\r
-                                          }\r
-\r
-                                       /*****************************/\r
-                                       /* Calculate the real timing */\r
-                                       /*****************************/\r
-\r
-                                       ul_RealHighTiming = (ULONG) (ul_HighTimerValue / (250.0 * (double) b_ClockSelection));\r
-                                       d_RealHighTiming    = (double) ul_HighTimerValue / (250.0 * (double) b_ClockSelection);\r
-\r
-                                       if ((double) ((double) ul_HighTimerValue / (250.0 * (double) b_ClockSelection)) >= (double) ((double) ul_RealHighTiming + 0.5))\r
-                                          {\r
-                                          ul_RealHighTiming = ul_RealHighTiming + 1;\r
-                                          }\r
-\r
-                                       ul_HighTiming     = ul_HighTiming - 1;\r
-                                       ul_HighTimerValue = ul_HighTimerValue - 2;\r
-\r
-                                       if (b_ClockSelection != APCI1710_40MHZ)\r
-                                          {\r
-                                          ul_HighTimerValue = (ULONG) ((double) (ul_HighTimerValue) * 1.007752288);\r
-                                          }\r
-                                  \r
-                                    break;\r
-\r
-                               /*****/\r
-                               /* s */\r
-                               /*****/\r
-\r
-                               case 3:\r
-                                   \r
-                                       /******************/\r
-                                       /* Timer 0 factor */\r
-                                       /******************/\r
-\r
-                                       ul_HighTimerValue = (ULONG) (ul_HighTiming * (250000.0 * b_ClockSelection));\r
-\r
-                                       /*******************/\r
-                                       /* Round the value */\r
-                                       /*******************/\r
-\r
-                                       if ((double) ((double) ul_HighTiming * (250000.0 * (double) b_ClockSelection)) >= ((double) ((double) ul_HighTimerValue + 0.5)))\r
-                                          {\r
-                                          ul_HighTimerValue = ul_HighTimerValue + 1;\r
-                                          }\r
-\r
-                                       /*****************************/\r
-                                       /* Calculate the real timing */\r
-                                       /*****************************/\r
-\r
-                                       ul_RealHighTiming = (ULONG) (ul_HighTimerValue / (250000.0 * (double) b_ClockSelection));\r
-                                       d_RealHighTiming    = (double) ul_HighTimerValue / (250000.0 * (double) b_ClockSelection);\r
-\r
-                                       if ((double) ((double) ul_HighTimerValue / (250000.0 * (double) b_ClockSelection)) >= (double) ((double) ul_RealHighTiming + 0.5))\r
-                                          {\r
-                                          ul_RealHighTiming = ul_RealHighTiming + 1;\r
-                                          }\r
-\r
-                                       ul_HighTiming     = ul_HighTiming - 1;\r
-                                       ul_HighTimerValue = ul_HighTimerValue - 2;\r
-\r
-                                       if (b_ClockSelection != APCI1710_40MHZ)\r
-                                          {\r
-                                          ul_HighTimerValue = (ULONG) ((double) (ul_HighTimerValue) * 1.007752288);\r
-                                          }\r
-                                   \r
-                                    break;\r
-\r
-                               /******/\r
-                               /* mn */\r
-                               /******/\r
-\r
-                               case 4:\r
-                                   \r
-                                       /******************/\r
-                                       /* Timer 0 factor */\r
-                                       /******************/\r
-\r
-                                       ul_HighTimerValue = (ULONG) ((ul_HighTiming * 60) * (250000.0 * b_ClockSelection));\r
-\r
-                                       /*******************/\r
-                                       /* Round the value */\r
-                                       /*******************/\r
-\r
-                                       if ((double) ((double) (ul_HighTiming * 60.0) * (250000.0 * (double) b_ClockSelection)) >= ((double) ((double) ul_HighTimerValue + 0.5)))\r
-                                          {\r
-                                          ul_HighTimerValue = ul_HighTimerValue + 1;\r
-                                          }\r
-\r
-                                       /*****************************/\r
-                                       /* Calculate the real timing */\r
-                                       /*****************************/\r
-\r
-                                       ul_RealHighTiming = (ULONG) (ul_HighTimerValue / (250000.0 * (double) b_ClockSelection)) / 60;\r
-                                       d_RealHighTiming    = ((double) ul_HighTimerValue / (250000.0 * (double) b_ClockSelection)) / 60.0;\r
-\r
-                                       if ((double) (((double) ul_HighTimerValue / (250000.0 * (double) b_ClockSelection)) / 60.0) >= (double) ((double) ul_RealHighTiming + 0.5))\r
-                                          {\r
-                                          ul_RealHighTiming = ul_RealHighTiming + 1;\r
-                                          }\r
-\r
-                                       ul_HighTiming     = ul_HighTiming - 1;\r
-                                       ul_HighTimerValue = ul_HighTimerValue - 2;\r
-\r
-                                       if (b_ClockSelection != APCI1710_40MHZ)\r
-                                          {\r
-                                          ul_HighTimerValue = (ULONG) ((double) (ul_HighTimerValue) * 1.007752288);\r
-                                          }\r
-                                    \r
-                                    break;\r
-                               }\r
-                               \r
-                            fpu_end ();\r
-                            \r
-                            /************************/\r
-                            /* Save the timing unit */\r
-                            /************************/\r
-\r
-                            devpriv->\r
-                            s_ModuleInfo [b_ModulNbr].\r
-                            s_PWMModuleInfo.\r
-                            s_PWMInfo [b_PWM].\r
-                            b_TimingUnit = b_TimingUnit;\r
-\r
-                            /****************************/\r
-                            /* Save the low base timing */\r
-                            /****************************/\r
-\r
-                            devpriv->\r
-                            s_ModuleInfo [b_ModulNbr].\r
-                            s_PWMModuleInfo.\r
-                            s_PWMInfo [b_PWM].\r
-                            d_LowTiming = d_RealLowTiming;\r
-\r
-                            devpriv->\r
-                            s_ModuleInfo [b_ModulNbr].\r
-                            s_PWMModuleInfo.\r
-                            s_PWMInfo [b_PWM].\r
-                            ul_RealLowTiming = ul_RealLowTiming;\r
-\r
-                            /****************************/\r
-                            /* Save the high base timing */\r
-                            /****************************/\r
-\r
-                            devpriv->\r
-                            s_ModuleInfo [b_ModulNbr].\r
-                            s_PWMModuleInfo.\r
-                            s_PWMInfo [b_PWM].\r
-                            d_HighTiming = d_RealHighTiming;\r
-\r
-                            devpriv->\r
-                            s_ModuleInfo [b_ModulNbr].\r
-                            s_PWMModuleInfo.\r
-                            s_PWMInfo [b_PWM].\r
-                            ul_RealHighTiming = ul_RealHighTiming;\r
-\r
-                            /************************/\r
-                            /* Write the low timing */\r
-                            /************************/\r
-\r
-                                outl(ul_LowTimerValue,devpriv->s_BoardInfos.\r
-                                    ui_Address + 0 + (20 * b_PWM) + (64 * b_ModulNbr));\r
-\r
-                            /*************************/\r
-                            /* Write the high timing */\r
-                            /*************************/\r
-\r
-                                outl(ul_HighTimerValue,devpriv->s_BoardInfos.\r
-                                    ui_Address + 4 + (20 * b_PWM) + (64 * b_ModulNbr));\r
-\r
-                            /***************************/\r
-                            /* Set the clock selection */\r
-                            /***************************/\r
-\r
-                                dw_Command=inl(devpriv->s_BoardInfos.\r
-                                   ui_Address + 8 + (20 * b_PWM) + (64 * b_ModulNbr));\r
-\r
-                            dw_Command = dw_Command & 0x7F;\r
-\r
-                            if (b_ClockSelection == APCI1710_40MHZ)\r
-                               {\r
-                               dw_Command = dw_Command | 0x80;\r
-                               }\r
-\r
-                            /***************************/\r
-                            /* Set the clock selection */\r
-                            /***************************/\r
-\r
-                                outl(dw_Command,devpriv->s_BoardInfos.\r
-                                    ui_Address + 8 + (20 * b_PWM) + (64 * b_ModulNbr));\r
-                            }\r
-                         else\r
-                            {\r
-                            /***************************************/\r
-                            /* High base timing selection is wrong */\r
-                            /***************************************/\r
-                         DPRINTK("High base timing selection is wrong\n");\r
-                            i_ReturnValue = -8;\r
-                            }\r
-                         }\r
-                      else\r
-                         {\r
-                         /**************************************/\r
-                         /* Low base timing selection is wrong */\r
-                         /**************************************/\r
-                         DPRINTK("Low base timing selection is wrong\n");\r
-                         i_ReturnValue = -7;\r
-                         }\r
-                      } // if ((b_TimingUnit >= 0) && (b_TimingUnit <= 4))\r
-                   else\r
-                      {\r
-                      /**********************************/\r
-                      /* Timing unit selection is wrong */\r
-                      /**********************************/\r
-                          DPRINTK("Timing unit selection is wrong\n"); \r
-                      i_ReturnValue = -6;\r
-                      } // if ((b_TimingUnit >= 0) && (b_TimingUnit <= 4))\r
-                   } // if (dw_Status & 0x10)\r
-                else\r
-                   {\r
-                   /***********************/\r
-                   /* PWM not initialised */\r
-                   /***********************/\r
-                       DPRINTK("PWM not initialised\n");       \r
-                   i_ReturnValue = -5;\r
-                   } // if (dw_Status & 0x10)\r
-                } // if (b_PWM >= 0 && b_PWM <= 1)\r
-             else\r
-                {\r
-                /******************************/\r
-                /* Tor PWM selection is wrong */\r
-                /******************************/\r
-                DPRINTK("Tor PWM selection is wrong\n");\r
-                i_ReturnValue = -4;\r
-                } // if (b_PWM >= 0 && b_PWM <= 1)\r
-             }\r
-          else\r
-             {\r
-             /**********************************/\r
-             /* The module is not a PWM module */\r
-             /**********************************/\r
-             DPRINTK("The module is not a PWM module\n");      \r
-             i_ReturnValue = -3;\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /***********************/\r
-          /* Module number error */\r
-          /***********************/\r
-          DPRINTK("Module number error\n");    \r
-          i_ReturnValue = -2;\r
-          }\r
-\r
-       return (i_ReturnValue);\r
-       }\r
-\r
-\r
-\r
-\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : _INT_ i_APCI1710_GetPWMStatus                          |\r
-|                               (BYTE_    b_BoardHandle,                     |\r
-|                                BYTE_    b_ModulNbr,                        |\r
-|                                BYTE_    b_PWM,                             |\r
-|                                PBYTE_  pb_PWMOutputStatus,                 |\r
-|                                PBYTE_  pb_ExternGateStatus)                |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Return the status from selected PWM (b_PWM) from       |\r
-|                     selected module (b_ModulNbr).                          |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : BYTE_  b_BoardHandle : Handle of board APCI-1710       |\r
-|                     BYTE_  b_PWM         : Selected PWM (0 or 1)           |\r
-|                     BYTE_  b_ModulNbr    : Selected module number (0 to 3)\r
-       b_ModulNbr                      =(BYTE)  CR_AREF(insn->chanspec);\r
-       b_PWM                           =(BYTE)  data[0];\r
-       \r
- |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : PBYTE_  pb_PWMOutputStatus  : Return the PWM output    |\r
-|                                                   level status.            |\r
-|                                                    0 : The PWM output level|\r
-|                                                        is low.             |\r
-|                                                    1 : The PWM output level|\r
-|                                                        is high.            |\r
-|                     PBYTE_  pb_ExternGateStatus : Return the extern gate   |\r
-|                                                   level status.            |\r
-|                                                    0 : The extern gate is  |\r
-|                                                        low.                |\r
-|                                                    1 : The extern gate is  |\r
-|                                                        high.  \r
-    pb_PWMOutputStatus =(PBYTE) data[0];\r
-       pb_ExternGateStatus =(PBYTE) data[1];             |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      :  0: No error                                           |\r
-|                     -1: The handle parameter of the board is wrong         |\r
-|                     -2: Module selection wrong                             |\r
-|                     -3: The module is not a PWM module                     |\r
-|                     -4: PWM selection is wrong                             |\r
-|                     -5: PWM not initialised see function                   |\r
-|                         "i_APCI1710_InitPWM"                               |\r
-|                     -6: PWM not enabled see function "i_APCI1710_EnablePWM"|\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-INT i_APCI1710_InsnReadGetPWMStatus(comedi_device *dev,comedi_subdevice *s,\r
-       comedi_insn *insn,lsampl_t *data)\r
-       {\r
-       INT    i_ReturnValue = 0;\r
-       DWORD  dw_Status;\r
-\r
-       BYTE    b_ModulNbr;\r
-       BYTE    b_PWM;\r
-       PBYTE   pb_PWMOutputStatus;\r
-       PBYTE   pb_ExternGateStatus;\r
-       \r
-       i_ReturnValue           = insn->n;\r
-       b_ModulNbr                      =(BYTE)  CR_AREF(insn->chanspec);\r
-       b_PWM                           =(BYTE)  CR_CHAN(insn->chanspec);\r
-       pb_PWMOutputStatus      =(PBYTE) &data[0];\r
-       pb_ExternGateStatus =(PBYTE) &data[1];\r
-\r
-       /**************************/\r
-       /* Test the module number */\r
-       /**************************/\r
-\r
-       if (b_ModulNbr < 4)\r
-          {\r
-          /***************/\r
-          /* Test if PWM */\r
-          /***************/\r
-\r
-          if ((devpriv->s_BoardInfos.\r
-               dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_PWM)\r
-             {\r
-             /**************************/\r
-             /* Test the PWM selection */\r
-             /**************************/\r
-\r
-             if (b_PWM <= 1)\r
-                {\r
-                /***************************/\r
-                /* Test if PWM initialised */\r
-                /***************************/\r
-\r
-                dw_Status=inl(devpriv->s_BoardInfos.\r
-                       ui_Address + 12 + (20 * b_PWM) + (64 * b_ModulNbr));\r
-\r
-                if (dw_Status & 0x10)\r
-                   {\r
-                   /***********************/\r
-                   /* Test if PWM enabled */\r
-                   /***********************/\r
-\r
-                   if (dw_Status & 0x1)\r
-                      {\r
-                      *pb_PWMOutputStatus  = (BYTE) ((dw_Status >> 7) & 1);\r
-                      *pb_ExternGateStatus = (BYTE) ((dw_Status >> 6) & 1);\r
-                      } // if (dw_Status & 0x1)\r
-                   else\r
-                      {\r
-                      /*******************/\r
-                      /* PWM not enabled */\r
-                      /*******************/\r
-\r
-                      DPRINTK("PWM not enabled \n");\r
-                      i_ReturnValue = -6;\r
-                      } // if (dw_Status & 0x1)\r
-                   } // if (dw_Status & 0x10)\r
-                else\r
-                   {\r
-                   /***********************/\r
-                   /* PWM not initialised */\r
-                   /***********************/\r
-\r
-                       DPRINTK("PWM not initialised\n");\r
-                   i_ReturnValue = -5;\r
-                   } // if (dw_Status & 0x10)\r
-                } // if (b_PWM >= 0 && b_PWM <= 1)\r
-             else\r
-                {\r
-                /******************************/\r
-                /* Tor PWM selection is wrong */\r
-                /******************************/\r
-\r
-                DPRINTK("Tor PWM selection is wrong\n");\r
-                i_ReturnValue = -4;\r
-                } // if (b_PWM >= 0 && b_PWM <= 1)\r
-             }\r
-          else\r
-             {\r
-             /**********************************/\r
-             /* The module is not a PWM module */\r
-             /**********************************/\r
-\r
-             DPRINTK("The module is not a PWM module\n");\r
-             i_ReturnValue = -3;\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /***********************/\r
-          /* Module number error */\r
-          /***********************/\r
-\r
-          DPRINTK("Module number error\n");\r
-          i_ReturnValue = -2;\r
-          }\r
-\r
-       return (i_ReturnValue);\r
-       }\r
-\r
-\r
-INT i_APCI1710_InsnBitsReadPWMInterrupt(comedi_device *dev,comedi_subdevice *s,\r
-       comedi_insn *insn,lsampl_t *data)\r
-\r
-{\r
-                               data[0]=devpriv->s_InterruptParameters.\r
-                                                     s_FIFOInterruptParameters [devpriv->\r
-                                                                                s_InterruptParameters.\r
-                                                                                ui_Read].b_OldModuleMask;\r
-                         data[1]=devpriv->s_InterruptParameters.\r
-                                                     s_FIFOInterruptParameters [devpriv->\r
-                                                                                s_InterruptParameters.\r
-                                                                                ui_Read].ul_OldInterruptMask;\r
-                         data[2]=devpriv->s_InterruptParameters.\r
-                                                     s_FIFOInterruptParameters [devpriv->\r
-                                                                                s_InterruptParameters.\r
-                                                                                ui_Read].ul_OldCounterLatchValue;\r
-\r
-                            \r
-                            /**************************/\r
-                            /* Increment the read FIFO */\r
-                            /***************************/\r
-\r
-                            devpriv->\r
-                            s_InterruptParameters.\r
-                            ui_Read = (devpriv->\r
-                                       s_InterruptParameters.\r
-                                       ui_Read + 1) % APCI1710_SAVE_INTERRUPT;\r
-\r
-                               return insn->n;\r
-\r
-}\r
+/**
+@verbatim
+
+Copyright (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 USA
+
+You 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 : PWM.C           | Version  : 2.96                       |
+  +-------------------------------+---------------------------------------+
+  | Project manager: Eric Stolz   | Date     :  02/12/2002                |
+  +-----------------------------------------------------------------------+
+  | Description :   APCI-1710 Wulse wide modulation module                |
+  |                                                                       |
+  |                                                                       |
+  +-----------------------------------------------------------------------+
+  |                             UPDATES                                   |
+  +-----------------------------------------------------------------------+
+  |   Date   |   Author  |          Description of updates                |
+  +-----------------------------------------------------------------------+
+  | 08/05/00 | Guinot C  | - 0400/0228 All Function in RING 0             |
+  |          |           |   available                                    |
+  +-----------------------------------------------------------------------+
+*/
+
+/*
++----------------------------------------------------------------------------+
+|                               Included files                               |
++----------------------------------------------------------------------------+
+*/
+
+
+#include "APCI1710_Pwm.h"
+
+
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     :INT i_APCI1710_InsnConfigPWM(comedi_device *dev,
+comedi_subdevice *s,comedi_insn *insn,lsampl_t *data)                        |
++----------------------------------------------------------------------------+
+| Task              : Pwm Init and Get Pwm Initialisation                    |
++----------------------------------------------------------------------------+
+| Input Parameters  : 
++----------------------------------------------------------------------------+
+| Output Parameters : -                                                      |
++----------------------------------------------------------------------------+
+| Return Value      : 
++----------------------------------------------------------------------------+
+*/
+
+INT    i_APCI1710_InsnConfigPWM(comedi_device *dev,comedi_subdevice *s,
+comedi_insn *insn,lsampl_t *data)
+{
+       BYTE b_ConfigType;
+       INT i_ReturnValue=0;
+        b_ConfigType=CR_CHAN(insn->chanspec);
+       
+
+       switch(b_ConfigType)
+       {
+       case APCI1710_PWM_INIT :
+               i_ReturnValue=i_APCI1710_InitPWM      (dev,
+                                (BYTE)CR_AREF(insn->chanspec), //  b_ModulNbr
+                                (BYTE) data[0],   //b_PWM
+                                (BYTE) data[1],   // b_ClockSelection
+                                (BYTE) data[2],   // b_TimingUnit
+                                (ULONG)data[3],   //ul_LowTiming
+                                (ULONG)data[4],   //ul_HighTiming
+                                (PULONG)&data[0], //pul_RealLowTiming
+                                (PULONG)&data[1] //pul_RealHighTiming
+                          );
+               break;
+
+       case APCI1710_PWM_GETINITDATA :
+               i_ReturnValue=i_APCI1710_GetPWMInitialisation (dev,
+                                        (BYTE)CR_AREF(insn->chanspec), // b_ModulNbr
+                                        (BYTE) data[0],   //b_PWM
+                                        (PBYTE)&data[0],    //pb_TimingUnit
+                                        (PULONG)&data[1], //pul_LowTiming
+                                        (PULONG)&data[2], //pul_HighTiming
+                                        (PBYTE) &data[3],  // pb_StartLevel
+                                        (PBYTE) &data[4], // pb_StopMode
+                                        (PBYTE) &data[5], // pb_StopLevel
+                                        (PBYTE) &data[6], // pb_ExternGate
+                                        (PBYTE) &data[7], // pb_InterruptEnable
+                                        (PBYTE) &data[8]  // pb_Enable
+                              );
+               break;
+
+       default:
+               printk(" Config Parameter Wrong\n");
+       }
+
+       if(i_ReturnValue>=0) i_ReturnValue =insn->n;
+       return (i_ReturnValue);
+}
+
+
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     : _INT_ i_APCI1710_InitPWM                               |
+|                                       (BYTE_     b_BoardHandle,            |
+|                                        BYTE_     b_ModulNbr,               |
+|                                        BYTE_     b_PWM,                    |
+|                                        BYTE_     b_ClockSelection,         |
+|                                        BYTE_     b_TimingUnit,             |
+|                                        ULONG_   ul_LowTiming,              |
+|                                        ULONG_   ul_HighTiming,             |
+|                                        PULONG_ pul_RealLowTiming,          |
+|                                        PULONG_ pul_RealHighTiming)         |
++----------------------------------------------------------------------------+
+| Task              : Configure the selected PWM (b_PWM) from selected module|
+|                     (b_ModulNbr). The ul_LowTiming, ul_HighTiming and      |
+|                     ul_TimingUnit determine the low/high timing base for   |
+|                     the period. pul_RealLowTiming, pul_RealHighTiming      |
+|                     return the real timing value.                          |
+|                     You must calling this function be for you call any     |
+|                     other function witch access of the PWM.                |
++----------------------------------------------------------------------------+
+| Input Parameters  : BYTE_     b_BoardHandle    : Handle of board APCI-1710 |
+|                     BYTE_     b_ModulNbr       : Module number to configure|
+|                                                  (0 to 3)                  |
+|                     BYTE_     b_PWM            : Selected PWM (0 or 1).    |
+|                     BYTE_     b_ClockSelection : Selection from PCI bus    |
+|                                                  clock                     |
+|                                                   - APCI1710_30MHZ :       |
+|                                                     The PC have a 30 MHz   |
+|                                                     PCI bus clock          |
+|                                                   - APCI1710_33MHZ :       |
+|                                                     The PC have a 33 MHz   |
+|                                                     PCI bus clock          |
+|                                                   - APCI1710_40MHZ         |
+|                                                     The APCI-1710 have a   |
+|                                                     integrated 40Mhz       |
+|                                                     quartz.                |
+|                     BYTE_     b_TimingUnit     : Base timing Unit (0 to 4) |
+|                                                       0 : ns               |
+|                                                       1 : æs               |
+|                                                       2 : ms               |
+|                                                       3 : s                |
+|                                                       4 : mn               |
+|                     ULONG_    ul_LowTiming     : Low base timing value.    |
+|                     ULONG_    ul_HighTiming    : High base timing value.   |
++----------------------------------------------------------------------------+
+| Output Parameters : PULONG_  pul_RealLowTiming  : Real low base timing     |
+|                                                   value.                   |
+|                     PULONG_  pul_RealHighTiming : Real high base timing    |
+|                                                   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 PWM module                      |
+|                    -4: PWM selection is wrong                              |
+|                    -5: The selected input clock is wrong                   |
+|                    -6: Timing Unit selection is wrong                      |
+|                    -7: Low base timing selection is wrong                  |
+|                    -8: High base timing selection is wrong                 |
+|                    -9: You can not used the 40MHz clock selection with     |
+|                        this board                                          |
++----------------------------------------------------------------------------+
+*/
+
+INT   i_APCI1710_InitPWM      (comedi_device *dev,
+                                BYTE     b_ModulNbr,
+                                BYTE    b_PWM,
+                                BYTE     b_ClockSelection,
+                                BYTE     b_TimingUnit,
+                                ULONG   ul_LowTiming,
+                                ULONG   ul_HighTiming,
+                                PULONG pul_RealLowTiming,
+                                PULONG pul_RealHighTiming)
+       {
+       INT    i_ReturnValue = 0;
+       ULONG ul_LowTimerValue = 0;
+       ULONG ul_HighTimerValue = 0;
+       DWORD dw_Command;
+       double d_RealLowTiming = 0;
+       double d_RealHighTiming = 0;
+       
+
+       /**************************/
+       /* Test the module number */
+       /**************************/
+
+       if (b_ModulNbr < 4)
+          {
+          /***************/
+          /* Test if PWM */
+          /***************/
+
+          if ((devpriv->
+               s_BoardInfos.
+               dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_PWM)
+             {
+             /**************************/
+             /* Test the PWM selection */
+             /**************************/
+
+             if (b_PWM <= 1)
+                {
+                /******************/
+                /* Test the clock */
+                /******************/
+
+                if ((b_ClockSelection == APCI1710_30MHZ) ||
+                    (b_ClockSelection == APCI1710_33MHZ) ||
+                    (b_ClockSelection == APCI1710_40MHZ))
+                   {
+                   /************************/
+                   /* Test the timing unit */
+                   /************************/
+
+                   if (b_TimingUnit <= 4)
+                      {
+                      /*********************************/
+                      /* Test the low timing selection */
+                      /*********************************/
+
+                      if (((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 0) && (ul_LowTiming >= 266) && (ul_LowTiming <= 0xFFFFFFFFUL)) ||
+                          ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 1) && (ul_LowTiming >= 1)   && (ul_LowTiming <= 571230650UL))  ||
+                          ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 2) && (ul_LowTiming >= 1)   && (ul_LowTiming <= 571230UL))     ||
+                          ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 3) && (ul_LowTiming >= 1)   && (ul_LowTiming <= 571UL))        ||
+                          ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 4) && (ul_LowTiming >= 1)   && (ul_LowTiming <= 9UL))          ||
+                          ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 0) && (ul_LowTiming >= 242) && (ul_LowTiming <= 0xFFFFFFFFUL)) ||
+                          ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 1) && (ul_LowTiming >= 1)   && (ul_LowTiming <= 519691043UL))  ||
+                          ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 2) && (ul_LowTiming >= 1)   && (ul_LowTiming <= 519691UL))     ||
+                          ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 3) && (ul_LowTiming >= 1)   && (ul_LowTiming <= 520UL))        ||
+                          ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 4) && (ul_LowTiming >= 1)   && (ul_LowTiming <= 8UL))          ||
+                          ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 0) && (ul_LowTiming >= 200) && (ul_LowTiming <= 0xFFFFFFFFUL)) ||
+                          ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 1) && (ul_LowTiming >= 1)   && (ul_LowTiming <= 429496729UL))  ||
+                          ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 2) && (ul_LowTiming >= 1)   && (ul_LowTiming <= 429496UL))     ||
+                          ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 3) && (ul_LowTiming >= 1)   && (ul_LowTiming <= 429UL))        ||
+                          ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 4) && (ul_LowTiming >= 1)   && (ul_LowTiming <= 7UL)))
+                         {
+                         /**********************************/
+                         /* Test the High timing selection */
+                         /**********************************/
+
+                         if (((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 0) && (ul_HighTiming >= 266) && (ul_HighTiming <= 0xFFFFFFFFUL)) ||
+                             ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 1) && (ul_HighTiming >= 1)   && (ul_HighTiming <= 571230650UL))  ||
+                             ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 2) && (ul_HighTiming >= 1)   && (ul_HighTiming <= 571230UL))     ||
+                             ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 3) && (ul_HighTiming >= 1)   && (ul_HighTiming <= 571UL))        ||
+                             ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 4) && (ul_HighTiming >= 1)   && (ul_HighTiming <= 9UL))          ||
+                             ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 0) && (ul_HighTiming >= 242) && (ul_HighTiming <= 0xFFFFFFFFUL)) ||
+                             ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 1) && (ul_HighTiming >= 1)   && (ul_HighTiming <= 519691043UL))  ||
+                             ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 2) && (ul_HighTiming >= 1)   && (ul_HighTiming <= 519691UL))     ||
+                             ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 3) && (ul_HighTiming >= 1)   && (ul_HighTiming <= 520UL))        ||
+                             ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 4) && (ul_HighTiming >= 1)   && (ul_HighTiming <= 8UL))          ||
+                             ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 0) && (ul_HighTiming >= 200) && (ul_HighTiming <= 0xFFFFFFFFUL)) ||
+                             ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 1) && (ul_HighTiming >= 1)   && (ul_HighTiming <= 429496729UL))  ||
+                             ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 2) && (ul_HighTiming >= 1)   && (ul_HighTiming <= 429496UL))     ||
+                             ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 3) && (ul_HighTiming >= 1)   && (ul_HighTiming <= 429UL))        ||
+                             ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 4) && (ul_HighTiming >= 1)   && (ul_HighTiming <= 7UL)))
+                            {
+                            /**************************/
+                            /* Test the board version */
+                            /**************************/
+
+                            if (((b_ClockSelection == APCI1710_40MHZ) && (devpriv->
+                                                                          s_BoardInfos.
+                                                                          b_BoardVersion > 0)) ||
+                                (b_ClockSelection != APCI1710_40MHZ))
+                               {
+
+                               /************************************/
+                               /* Calculate the low division fator */
+                               /************************************/
+
+                               fpu_begin ();
+                               
+                               switch (b_TimingUnit)
+                                  {
+                                  /******/
+                                  /* ns */
+                                  /******/
+
+                                  case 0:
+                                       
+                                          /******************/
+                                          /* Timer 0 factor */
+                                          /******************/
+
+                                          ul_LowTimerValue = (ULONG) (ul_LowTiming * (0.00025 * b_ClockSelection));
+
+                                          /*******************/
+                                          /* Round the value */
+                                          /*******************/
+
+                                          if ((double) ((double) ul_LowTiming * (0.00025 * (double) b_ClockSelection)) >= ((double) ((double) ul_LowTimerValue + 0.5)))
+                                             {
+                                             ul_LowTimerValue = ul_LowTimerValue + 1;
+                                             }
+
+                                          /*****************************/
+                                          /* Calculate the real timing */
+                                          /*****************************/
+
+                                          *pul_RealLowTiming = (ULONG) (ul_LowTimerValue / (0.00025 * (double) b_ClockSelection));
+                                          d_RealLowTiming = (double) ul_LowTimerValue / (0.00025 * (double) b_ClockSelection);
+
+                                          if ((double) ((double) ul_LowTimerValue / (0.00025 * (double) b_ClockSelection)) >= (double) ((double) *pul_RealLowTiming + 0.5))
+                                             {
+                                             *pul_RealLowTiming = *pul_RealLowTiming + 1;
+                                             }
+
+                                          ul_LowTiming     = ul_LowTiming - 1;
+                                          ul_LowTimerValue = ul_LowTimerValue - 2;
+
+                                          if (b_ClockSelection != APCI1710_40MHZ)
+                                             {
+                                             ul_LowTimerValue = (ULONG) ((double) (ul_LowTimerValue) * 1.007752288);
+                                             }
+                                       
+
+                                       break;
+
+                                  /******/
+                                  /* æs */
+                                  /******/
+
+                                  case 1:
+                                       
+                                          /******************/
+                                          /* Timer 0 factor */
+                                          /******************/
+
+                                          ul_LowTimerValue = (ULONG) (ul_LowTiming * (0.25 * b_ClockSelection));
+
+                                          /*******************/
+                                          /* Round the value */
+                                          /*******************/
+
+                                          if ((double) ((double) ul_LowTiming * (0.25 * (double) b_ClockSelection)) >= ((double) ((double) ul_LowTimerValue + 0.5)))
+                                             {
+                                             ul_LowTimerValue = ul_LowTimerValue + 1;
+                                             }
+
+                                          /*****************************/
+                                          /* Calculate the real timing */
+                                          /*****************************/
+
+                                          *pul_RealLowTiming = (ULONG) (ul_LowTimerValue / (0.25 * (double) b_ClockSelection));
+                                          d_RealLowTiming    = (double) ul_LowTimerValue / ((double) 0.25 * (double) b_ClockSelection);
+
+                                          if ((double) ((double) ul_LowTimerValue / (0.25 * (double) b_ClockSelection)) >= (double) ((double) *pul_RealLowTiming + 0.5))
+                                             {
+                                             *pul_RealLowTiming = *pul_RealLowTiming + 1;
+                                             }
+
+                                          ul_LowTiming     = ul_LowTiming - 1;
+                                          ul_LowTimerValue = ul_LowTimerValue - 2;
+
+                                          if (b_ClockSelection != APCI1710_40MHZ)
+                                             {
+                                             ul_LowTimerValue = (ULONG) ((double) (ul_LowTimerValue) * 1.007752288);
+                                             }
+                                       
+
+                                       break;
+
+                                  /******/
+                                  /* ms */
+                                  /******/
+
+                                  case 2:
+                                       
+                                          /******************/
+                                          /* Timer 0 factor */
+                                          /******************/
+
+                                          ul_LowTimerValue = ul_LowTiming * (250.0 * b_ClockSelection);
+
+                                          /*******************/
+                                          /* Round the value */
+                                          /*******************/
+
+                                          if ((double) ((double) ul_LowTiming * (250.0 * (double) b_ClockSelection)) >= ((double) ((double) ul_LowTimerValue + 0.5)))
+                                             {
+                                             ul_LowTimerValue = ul_LowTimerValue + 1;
+                                             }
+
+                                          /*****************************/
+                                          /* Calculate the real timing */
+                                          /*****************************/
+
+                                          *pul_RealLowTiming = (ULONG) (ul_LowTimerValue / (250.0 * (double) b_ClockSelection));
+                                          d_RealLowTiming    = (double) ul_LowTimerValue / (250.0 * (double) b_ClockSelection);
+
+                                          if ((double) ((double) ul_LowTimerValue / (250.0 * (double) b_ClockSelection)) >= (double) ((double) *pul_RealLowTiming + 0.5))
+                                             {
+                                             *pul_RealLowTiming = *pul_RealLowTiming + 1;
+                                             }
+
+                                          ul_LowTiming     = ul_LowTiming - 1;
+                                          ul_LowTimerValue = ul_LowTimerValue - 2;
+
+                                          if (b_ClockSelection != APCI1710_40MHZ)
+                                             {
+                                             ul_LowTimerValue = (ULONG) ((double) (ul_LowTimerValue) * 1.007752288);
+                                             }
+                                       
+                                       break;
+
+                                  /*****/
+                                  /* s */
+                                  /*****/
+
+                                  case 3:
+                                          /******************/
+                                          /* Timer 0 factor */
+                                          /******************/
+
+                                          ul_LowTimerValue = (ULONG) (ul_LowTiming * (250000.0 * b_ClockSelection));
+
+                                          /*******************/
+                                          /* Round the value */
+                                          /*******************/
+
+                                          if ((double) ((double) ul_LowTiming * (250000.0 * (double) b_ClockSelection)) >= ((double) ((double) ul_LowTimerValue + 0.5)))
+                                             {
+                                             ul_LowTimerValue = ul_LowTimerValue + 1;
+                                             }
+
+                                          /*****************************/
+                                          /* Calculate the real timing */
+                                          /*****************************/
+
+                                          *pul_RealLowTiming = (ULONG) (ul_LowTimerValue / (250000.0 * (double) b_ClockSelection));
+                                          d_RealLowTiming    = (double) ul_LowTimerValue / (250000.0 * (double) b_ClockSelection);
+
+                                          if ((double) ((double) ul_LowTimerValue / (250000.0 * (double) b_ClockSelection)) >= (double) ((double) *pul_RealLowTiming + 0.5))
+                                             {
+                                             *pul_RealLowTiming = *pul_RealLowTiming + 1;
+                                             }
+
+                                          ul_LowTiming     = ul_LowTiming - 1;
+                                          ul_LowTimerValue = ul_LowTimerValue - 2;
+
+                                          if (b_ClockSelection != APCI1710_40MHZ)
+                                             {
+                                             ul_LowTimerValue = (ULONG) ((double) (ul_LowTimerValue) * 1.007752288);
+                                             }
+                                       
+
+                                       break;
+
+                                  /******/
+                                  /* mn */
+                                  /******/
+
+                                  case 4:
+                                       
+                                          /******************/
+                                          /* Timer 0 factor */
+                                          /******************/
+
+                                          ul_LowTimerValue = (ULONG) ((ul_LowTiming * 60) * (250000.0 * b_ClockSelection));
+
+                                          /*******************/
+                                          /* Round the value */
+                                          /*******************/
+
+                                          if ((double) ((double) (ul_LowTiming * 60.0) * (250000.0 * (double) b_ClockSelection)) >= ((double) ((double) ul_LowTimerValue + 0.5)))
+                                             {
+                                             ul_LowTimerValue = ul_LowTimerValue + 1;
+                                             }
+
+                                          /*****************************/
+                                          /* Calculate the real timing */
+                                          /*****************************/
+
+                                          *pul_RealLowTiming = (ULONG) (ul_LowTimerValue / (250000.0 * (double) b_ClockSelection)) / 60;
+                                          d_RealLowTiming    = ((double) ul_LowTimerValue / (250000.0 * (double) b_ClockSelection)) / 60.0;
+
+                                          if ((double) (((double) ul_LowTimerValue / (250000.0 * (double) b_ClockSelection)) / 60.0) >= (double) ((double) *pul_RealLowTiming + 0.5))
+                                             {
+                                             *pul_RealLowTiming = *pul_RealLowTiming + 1;
+                                             }
+
+                                          ul_LowTiming     = ul_LowTiming - 1;
+                                          ul_LowTimerValue = ul_LowTimerValue - 2;
+
+                                          if (b_ClockSelection != APCI1710_40MHZ)
+                                             {
+                                             ul_LowTimerValue = (ULONG) ((double) (ul_LowTimerValue) * 1.007752288);
+                                             }
+                                       
+                                       break;
+                                  }
+
+                               /*************************************/
+                               /* Calculate the high division fator */
+                               /*************************************/
+
+                               switch (b_TimingUnit)
+                                  {
+                                  /******/
+                                  /* ns */
+                                  /******/
+
+                                  case 0:
+                                       
+                                          /******************/
+                                          /* Timer 0 factor */
+                                          /******************/
+
+                                          ul_HighTimerValue = (ULONG) (ul_HighTiming * (0.00025 * b_ClockSelection));
+
+                                          /*******************/
+                                          /* Round the value */
+                                          /*******************/
+
+                                          if ((double) ((double) ul_HighTiming * (0.00025 * (double) b_ClockSelection)) >= ((double) ((double) ul_HighTimerValue + 0.5)))
+                                             {
+                                             ul_HighTimerValue = ul_HighTimerValue + 1;
+                                             }
+
+                                          /*****************************/
+                                          /* Calculate the real timing */
+                                          /*****************************/
+
+                                          *pul_RealHighTiming = (ULONG) (ul_HighTimerValue / (0.00025 * (double) b_ClockSelection));
+                                          d_RealHighTiming    = (double) ul_HighTimerValue / (0.00025 * (double) b_ClockSelection);
+
+                                          if ((double) ((double) ul_HighTimerValue / (0.00025 * (double) b_ClockSelection)) >= (double) ((double) *pul_RealHighTiming + 0.5))
+                                             {
+                                             *pul_RealHighTiming = *pul_RealHighTiming + 1;
+                                             }
+
+                                          ul_HighTiming     = ul_HighTiming - 1;
+                                          ul_HighTimerValue = ul_HighTimerValue - 2;
+
+                                          if (b_ClockSelection != APCI1710_40MHZ)
+                                             {
+                                             ul_HighTimerValue = (ULONG) ((double) (ul_HighTimerValue) * 1.007752288);
+                                             }
+                                       
+
+                                       break;
+
+                                  /******/
+                                  /* æs */
+                                  /******/
+
+                                  case 1:
+                                       
+                                          /******************/
+                                          /* Timer 0 factor */
+                                          /******************/
+
+                                          ul_HighTimerValue = (ULONG) (ul_HighTiming * (0.25 * b_ClockSelection));
+
+                                          /*******************/
+                                          /* Round the value */
+                                          /*******************/
+
+                                          if ((double) ((double) ul_HighTiming * (0.25 * (double) b_ClockSelection)) >= ((double) ((double) ul_HighTimerValue + 0.5)))
+                                             {
+                                             ul_HighTimerValue = ul_HighTimerValue + 1;
+                                             }
+
+                                          /*****************************/
+                                          /* Calculate the real timing */
+                                          /*****************************/
+
+                                          *pul_RealHighTiming = (ULONG) (ul_HighTimerValue / (0.25 * (double) b_ClockSelection));
+                                          d_RealHighTiming    = (double) ul_HighTimerValue / ((double) 0.25 * (double) b_ClockSelection);
+
+                                          if ((double) ((double) ul_HighTimerValue / (0.25 * (double) b_ClockSelection)) >= (double) ((double) *pul_RealHighTiming + 0.5))
+                                             {
+                                             *pul_RealHighTiming = *pul_RealHighTiming + 1;
+                                             }
+
+                                          ul_HighTiming     = ul_HighTiming - 1;
+                                          ul_HighTimerValue = ul_HighTimerValue - 2;
+
+                                          if (b_ClockSelection != APCI1710_40MHZ)
+                                             {
+                                             ul_HighTimerValue = (ULONG) ((double) (ul_HighTimerValue) * 1.007752288);
+                                             }
+                                       
+
+                                       break;
+
+                                  /******/
+                                  /* ms */
+                                  /******/
+
+                                  case 2:
+                                       
+                                          /******************/
+                                          /* Timer 0 factor */
+                                          /******************/
+
+                                          ul_HighTimerValue = ul_HighTiming * (250.0 * b_ClockSelection);
+
+                                          /*******************/
+                                          /* Round the value */
+                                          /*******************/
+
+                                          if ((double) ((double) ul_HighTiming * (250.0 * (double) b_ClockSelection)) >= ((double) ((double) ul_HighTimerValue + 0.5)))
+                                             {
+                                             ul_HighTimerValue = ul_HighTimerValue + 1;
+                                             }
+
+                                          /*****************************/
+                                          /* Calculate the real timing */
+                                          /*****************************/
+
+                                          *pul_RealHighTiming = (ULONG) (ul_HighTimerValue / (250.0 * (double) b_ClockSelection));
+                                          d_RealHighTiming    = (double) ul_HighTimerValue / (250.0 * (double) b_ClockSelection);
+
+                                          if ((double) ((double) ul_HighTimerValue / (250.0 * (double) b_ClockSelection)) >= (double) ((double) *pul_RealHighTiming + 0.5))
+                                             {
+                                             *pul_RealHighTiming = *pul_RealHighTiming + 1;
+                                             }
+
+                                          ul_HighTiming     = ul_HighTiming - 1;
+                                          ul_HighTimerValue = ul_HighTimerValue - 2;
+
+                                          if (b_ClockSelection != APCI1710_40MHZ)
+                                             {
+                                             ul_HighTimerValue = (ULONG) ((double) (ul_HighTimerValue) * 1.007752288);
+                                             }
+                                       
+
+                                       break;
+
+                                  /*****/
+                                  /* s */
+                                  /*****/
+
+                                  case 3:
+                                       
+                                          /******************/
+                                          /* Timer 0 factor */
+                                          /******************/
+
+                                          ul_HighTimerValue = (ULONG) (ul_HighTiming * (250000.0 * b_ClockSelection));
+
+                                          /*******************/
+                                          /* Round the value */
+                                          /*******************/
+
+                                          if ((double) ((double) ul_HighTiming * (250000.0 * (double) b_ClockSelection)) >= ((double) ((double) ul_HighTimerValue + 0.5)))
+                                             {
+                                             ul_HighTimerValue = ul_HighTimerValue + 1;
+                                             }
+
+                                          /*****************************/
+                                          /* Calculate the real timing */
+                                          /*****************************/
+
+                                          *pul_RealHighTiming = (ULONG) (ul_HighTimerValue / (250000.0 * (double) b_ClockSelection));
+                                          d_RealHighTiming    = (double) ul_HighTimerValue / (250000.0 * (double) b_ClockSelection);
+
+                                          if ((double) ((double) ul_HighTimerValue / (250000.0 * (double) b_ClockSelection)) >= (double) ((double) *pul_RealHighTiming + 0.5))
+                                             {
+                                             *pul_RealHighTiming = *pul_RealHighTiming + 1;
+                                             }
+
+                                          ul_HighTiming     = ul_HighTiming - 1;
+                                          ul_HighTimerValue = ul_HighTimerValue - 2;
+
+                                          if (b_ClockSelection != APCI1710_40MHZ)
+                                             {
+                                             ul_HighTimerValue = (ULONG) ((double) (ul_HighTimerValue) * 1.007752288);
+                                             }
+                                       
+
+                                       break;
+
+                                  /******/
+                                  /* mn */
+                                  /******/
+
+                                  case 4:
+                                       
+                                          /******************/
+                                          /* Timer 0 factor */
+                                          /******************/
+
+                                          ul_HighTimerValue = (ULONG) ((ul_HighTiming * 60) * (250000.0 * b_ClockSelection));
+
+                                          /*******************/
+                                          /* Round the value */
+                                          /*******************/
+
+                                          if ((double) ((double) (ul_HighTiming * 60.0) * (250000.0 * (double) b_ClockSelection)) >= ((double) ((double) ul_HighTimerValue + 0.5)))
+                                             {
+                                             ul_HighTimerValue = ul_HighTimerValue + 1;
+                                             }
+
+                                          /*****************************/
+                                          /* Calculate the real timing */
+                                          /*****************************/
+
+                                          *pul_RealHighTiming = (ULONG) (ul_HighTimerValue / (250000.0 * (double) b_ClockSelection)) / 60;
+                                          d_RealHighTiming    = ((double) ul_HighTimerValue / (250000.0 * (double) b_ClockSelection)) / 60.0;
+
+                                          if ((double) (((double) ul_HighTimerValue / (250000.0 * (double) b_ClockSelection)) / 60.0) >= (double) ((double) *pul_RealHighTiming + 0.5))
+                                             {
+                                             *pul_RealHighTiming = *pul_RealHighTiming + 1;
+                                             }
+
+                                          ul_HighTiming     = ul_HighTiming - 1;
+                                          ul_HighTimerValue = ul_HighTimerValue - 2;
+
+                                          if (b_ClockSelection != APCI1710_40MHZ)
+                                             {
+                                             ul_HighTimerValue = (ULONG) ((double) (ul_HighTimerValue) * 1.007752288);
+                                             }
+                                       
+                                       break;
+                                  }
+
+                               fpu_end ();
+                               /****************************/
+                               /* Save the clock selection */
+                               /****************************/
+
+                               devpriv->
+                               s_ModuleInfo [b_ModulNbr].
+                               s_PWMModuleInfo.
+                               b_ClockSelection = b_ClockSelection;
+
+                               /************************/
+                               /* Save the timing unit */
+                               /************************/
+
+                               devpriv->
+                               s_ModuleInfo [b_ModulNbr].
+                               s_PWMModuleInfo.
+                               s_PWMInfo [b_PWM].
+                               b_TimingUnit = b_TimingUnit;
+
+                               /****************************/
+                               /* Save the low base timing */
+                               /****************************/
+
+                               devpriv->
+                               s_ModuleInfo [b_ModulNbr].
+                               s_PWMModuleInfo.
+                               s_PWMInfo [b_PWM].
+                               d_LowTiming = d_RealLowTiming;
+
+                               devpriv->
+                               s_ModuleInfo [b_ModulNbr].
+                               s_PWMModuleInfo.
+                               s_PWMInfo [b_PWM].
+                               ul_RealLowTiming = *pul_RealLowTiming;
+
+                               /****************************/
+                               /* Save the high base timing */
+                               /****************************/
+
+                               devpriv->
+                               s_ModuleInfo [b_ModulNbr].
+                               s_PWMModuleInfo.
+                               s_PWMInfo [b_PWM].
+                               d_HighTiming = d_RealHighTiming;
+
+                               devpriv->
+                               s_ModuleInfo [b_ModulNbr].
+                               s_PWMModuleInfo.
+                               s_PWMInfo [b_PWM].
+                               ul_RealHighTiming = *pul_RealHighTiming;
+
+                               /************************/
+                               /* Write the low timing */
+                               /************************/
+
+                         outl(ul_LowTimerValue,devpriv->s_BoardInfos.
+                                       ui_Address + 0 + (20 * b_PWM) + (64 * b_ModulNbr));
+
+                               /*************************/
+                               /* Write the high timing */
+                               /*************************/
+
+                        outl(ul_HighTimerValue,devpriv->s_BoardInfos.
+                                       ui_Address + 4 + (20 * b_PWM) + (64 * b_ModulNbr));
+
+                               /***************************/
+                               /* Set the clock selection */
+                               /***************************/
+
+                         dw_Command=inl(devpriv->s_BoardInfos.
+                                      ui_Address + 8 + (20 * b_PWM) + (64 * b_ModulNbr));
+
+                               dw_Command = dw_Command & 0x7F;
+
+                               if (b_ClockSelection == APCI1710_40MHZ)
+                                  {
+                                  dw_Command = dw_Command | 0x80;
+                                  }
+
+                               /***************************/
+                               /* Set the clock selection */
+                               /***************************/
+
+                                 outl(dw_Command,devpriv->s_BoardInfos.
+                                       ui_Address + 8 + (20 * b_PWM) + (64 * b_ModulNbr));
+
+                               /*************/
+                               /* PWM init. */
+                               /*************/
+                               devpriv->
+                               s_ModuleInfo [b_ModulNbr].
+                               s_PWMModuleInfo.
+                               s_PWMInfo [b_PWM].
+                               b_PWMInit = 1;
+                               }
+                            else
+                               {
+                               /***************************************************/
+                               /* You can not used the 40MHz clock selection with */
+                               /* this board                                      */
+                               /***************************************************/
+                        DPRINTK("You can not used the 40MHz clock selection with this board\n");
+                               i_ReturnValue = -9;
+                               }
+                            }
+                         else
+                            {
+                            /***************************************/
+                            /* High base timing selection is wrong */
+                            /***************************************/
+                                DPRINTK("High base timing selection is wrong\n");
+                            i_ReturnValue = -8;
+                            }
+                         }
+                      else
+                         {
+                         /**************************************/
+                         /* Low base timing selection is wrong */
+                         /**************************************/
+                         DPRINTK("Low base timing selection is wrong\n");
+                         i_ReturnValue = -7;
+                         }
+                      } // if ((b_TimingUnit >= 0) && (b_TimingUnit <= 4))
+                   else
+                      {
+                      /**********************************/
+                      /* Timing unit selection is wrong */
+                      /**********************************/
+                          DPRINTK("Timing unit selection is wrong\n");
+                      i_ReturnValue = -6;
+                      } // if ((b_TimingUnit >= 0) && (b_TimingUnit <= 4))
+                   } // if ((b_ClockSelection == APCI1710_30MHZ) || (b_ClockSelection == APCI1710_33MHZ) || (b_ClockSelection == APCI1710_40MHZ))
+                else
+                   {
+                   /*******************************/
+                   /* The selected clock is wrong */
+                   /*******************************/
+                       DPRINTK("The selected clock is wrong\n"); 
+                   i_ReturnValue = -5;
+                   } // if ((b_ClockSelection == APCI1710_30MHZ) || (b_ClockSelection == APCI1710_33MHZ) || (b_ClockSelection == APCI1710_40MHZ))
+                } // if (b_PWM >= 0 && b_PWM <= 1)
+             else
+                {
+                /******************************/
+                /* Tor PWM selection is wrong */
+                /******************************/
+                DPRINTK("Tor PWM selection is wrong\n");       
+                i_ReturnValue = -4;
+                } // if (b_PWM >= 0 && b_PWM <= 1)
+             }
+          else
+             {
+             /**********************************/
+             /* The module is not a PWM module */
+             /**********************************/
+             DPRINTK("The module is not a PWM module\n");      
+             i_ReturnValue = -3;
+             }
+          }
+       else
+          {
+          /***********************/
+          /* Module number error */
+          /***********************/
+          DPRINTK("Module number error\n");    
+          i_ReturnValue = -2;
+          }
+
+       return (i_ReturnValue);
+       }
+
+
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     : _INT_ i_APCI1710_GetPWMInitialisation                  |
+|                                       (BYTE_     b_BoardHandle,            |
+|                                        BYTE_     b_ModulNbr,               |
+|                                        BYTE_     b_PWM,                    |
+|                                        PBYTE_   pb_TimingUnit,             |
+|                                        PULONG_ pul_LowTiming,              |
+|                                        PULONG_ pul_HighTiming,             |
+|                                        PBYTE_   pb_StartLevel,             |
+|                                        PBYTE_   pb_StopMode,               |
+|                                        PBYTE_   pb_StopLevel,              |
+|                                        PBYTE_   pb_ExternGate,             |
+|                                        PBYTE_   pb_InterruptEnable,        |
+|                                        PBYTE_   pb_Enable)                 |
++----------------------------------------------------------------------------+
+| Task              : Return the PWM (b_PWM) initialisation from selected    |
+|                     module (b_ModulNbr). You must calling the              |
+|                     "i_APCI1710_InitPWM" function be for you call this     |
+|                     function.                                              |
++----------------------------------------------------------------------------+
+| Input Parameters  : BYTE_ b_BoardHandle : Handle of board APCI-1710        |
+|                     BYTE_ b_ModulNbr    : Selected module number (0 to 3)  |
+|                     BYTE_ b_PWM         : Selected PWM (0 or 1)            |
++----------------------------------------------------------------------------+
+| Output Parameters : PBYTE_  pb_TimingUnit      : Base timing Unit (0 to 4) |
+|                                                       0 : ns               |
+|                                                       1 : æs               |
+|                                                       2 : ms               |
+|                                                       3 : s                |
+|                                                       4 : mn               |
+|                     PULONG_ pul_LowTiming      : Low base timing value.    |
+|                     PULONG_ pul_HighTiming     : High base timing value.   |
+|                     PBYTE_  pb_StartLevel      : Start period level        |
+|                                                  selection                 |
+|                                                       0 : The period start |
+|                                                           with a low level |
+|                                                       1 : The period start |
+|                                                           with a high level|
+|                     PBYTE_  pb_StopMode        : Stop mode selection       |
+|                                                  0 : The PWM is stopped    |
+|                                                      directly after the    |
+|                                                     "i_APCI1710_DisablePWM"|
+|                                                      function and break the|
+|                                                      last period           |
+|                                                  1 : After the             |
+|                                                     "i_APCI1710_DisablePWM"|
+|                                                      function the PWM is   |
+|                                                      stopped at the end    |
+|                                                      from last period cycle|
+|                     PBYTE_  pb_StopLevel        : Stop PWM level selection |
+|                                                    0 : The output signal   |
+|                                                        keep the level after|
+|                                                        the                 |
+|                                                     "i_APCI1710_DisablePWM"|
+|                                                        function            |
+|                                                    1 : The output signal is|
+|                                                        set to low after the|
+|                                                     "i_APCI1710_DisablePWM"|
+|                                                        function            |
+|                                                    2 : The output signal is|
+|                                                        set to high after   |
+|                                                        the                 |
+|                                                     "i_APCI1710_DisablePWM"|
+|                                                        function            |
+|                     PBYTE_  pb_ExternGate      : Extern gate action        |
+|                                                  selection                 |
+|                                                   0 : Extern gate signal   |
+|                                                       not used.            |
+|                                                   1 : Extern gate signal   |
+|                                                       used.                |
+|                     PBYTE_  pb_InterruptEnable : Enable or disable the PWM |
+|                                                  interrupt.                |
+|                                                  - APCI1710_ENABLE :       |
+|                                                    Enable the PWM interrupt|
+|                                                    A interrupt occur after |
+|                                                    each period             |
+|                                                  - APCI1710_DISABLE :      |
+|                                                    Disable the PWM         |
+|                                                    interrupt               |
+|                     PBYTE_  pb_Enable          : Indicate if the PWM is    |
+|                                                  enabled or no             |
+|                                                       0 : PWM not enabled  |
+|                                                       1 : PWM enabled      |
++----------------------------------------------------------------------------+
+| Return Value      :  0: No error                                           |
+|                     -1: The handle parameter of the board is wrong         |
+|                     -2: Module selection wrong                             |
+|                     -3: The module is not a PWM module                     |
+|                     -4: PWM selection is wrong                             |
+|                     -5: PWM not initialised see function                   |
+|                         "i_APCI1710_InitPWM"                               |
++----------------------------------------------------------------------------+
+*/
+
+INT  i_APCI1710_GetPWMInitialisation (comedi_device *dev,
+                                        BYTE     b_ModulNbr,
+                                        BYTE     b_PWM,
+                                        PBYTE   pb_TimingUnit,
+                                        PULONG pul_LowTiming,
+                                        PULONG pul_HighTiming,
+                                        PBYTE   pb_StartLevel,
+                                        PBYTE   pb_StopMode,
+                                        PBYTE   pb_StopLevel,
+                                        PBYTE   pb_ExternGate,
+                                        PBYTE   pb_InterruptEnable,
+                                        PBYTE   pb_Enable)
+       {
+       INT    i_ReturnValue = 0;
+       DWORD dw_Status;
+       DWORD dw_Command;
+
+               
+       
+       /**************************/
+       /* Test the module number */
+       /**************************/
+
+       if (b_ModulNbr < 4)
+          {
+          /***************/
+          /* Test if PWM */
+          /***************/
+
+          if ((devpriv->
+               s_BoardInfos.
+               dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_PWM)
+             {
+             /**************************/
+             /* Test the PWM selection */
+             /**************************/
+
+             if (b_PWM <= 1)
+                {
+                /***************************/
+                /* Test if PWM initialised */
+                /***************************/
+
+                  dw_Status=inl(devpriv->s_BoardInfos.
+                       ui_Address + 12 + (20 * b_PWM) + (64 * b_ModulNbr));
+
+                if (dw_Status & 0x10)
+                   {
+                   /***********************/
+                   /* Read the low timing */
+                   /***********************/
+
+                       *pul_LowTiming = inl(devpriv->s_BoardInfos.
+                          ui_Address + 0 + (20 * b_PWM) + (64 * b_ModulNbr));
+
+                   /************************/
+                   /* Read the high timing */
+                   /************************/
+
+                     *pul_HighTiming= inl(devpriv->s_BoardInfos.
+                          ui_Address + 4 + (20 * b_PWM) + (64 * b_ModulNbr));
+
+                   /********************/
+                   /* Read the command */
+                   /********************/
+
+                     dw_Command = inl(devpriv->s_BoardInfos.
+                          ui_Address + 8 + (20 * b_PWM) + (64 * b_ModulNbr));
+
+                   *pb_StartLevel      = (BYTE) ((dw_Command >> 5) & 1);
+                   *pb_StopMode        = (BYTE) ((dw_Command >> 0) & 1);
+                   *pb_StopLevel       = (BYTE) ((dw_Command >> 1) & 1);
+                   *pb_ExternGate      = (BYTE) ((dw_Command >> 4) & 1);
+                   *pb_InterruptEnable = (BYTE) ((dw_Command >> 3) & 1);
+
+                   if (*pb_StopLevel)
+                      {
+                      *pb_StopLevel = *pb_StopLevel + (BYTE) ((dw_Command >> 2) & 1);
+                      }
+
+                   /********************/
+                   /* Read the command */
+                   /********************/
+
+                     dw_Command=inl(devpriv->s_BoardInfos.
+                          ui_Address + 8 + (20 * b_PWM) + (64 * b_ModulNbr));
+
+                   *pb_Enable = (BYTE) ((dw_Command >> 0) & 1);
+
+                   *pb_TimingUnit = devpriv->
+                                    s_ModuleInfo [b_ModulNbr].
+                                    s_PWMModuleInfo.
+                                    s_PWMInfo [b_PWM].
+                                    b_TimingUnit;
+                   } // if (dw_Status & 0x10)
+                else
+                   {
+                   /***********************/
+                   /* PWM not initialised */
+                   /***********************/
+                    DPRINTK("PWM not initialised\n");
+                   i_ReturnValue = -5;
+                   } // if (dw_Status & 0x10)
+                } // if (b_PWM >= 0 && b_PWM <= 1)
+             else
+                {
+                /******************************/
+                /* Tor PWM selection is wrong */
+                /******************************/
+                DPRINTK("Tor PWM selection is wrong\n");
+                i_ReturnValue = -4;
+                } // if (b_PWM >= 0 && b_PWM <= 1)
+             }
+          else
+             {
+             /**********************************/
+             /* The module is not a PWM module */
+             /**********************************/
+             DPRINTK("The module is not a PWM module\n");      
+             i_ReturnValue = -3;
+             }
+          }
+       else
+          {
+          /***********************/
+          /* Module number error */
+          /***********************/
+          DPRINTK("Module number error\n");
+          i_ReturnValue = -2;
+          }
+
+       return (i_ReturnValue);
+       }
+
+
+
+
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     :INT i_APCI1710_InsnWritePWM(comedi_device *dev,
+comedi_subdevice *s,comedi_insn *insn,lsampl_t *data)                        |
++----------------------------------------------------------------------------+
+| Task              : Pwm Enable Disable and Set New Timing                  |
++----------------------------------------------------------------------------+
+| Input Parameters  : 
++----------------------------------------------------------------------------+
+| Output Parameters : -                                                      |
++----------------------------------------------------------------------------+
+| Return Value      : 
++----------------------------------------------------------------------------+
+*/
+
+INT    i_APCI1710_InsnWritePWM(comedi_device *dev,comedi_subdevice *s,
+comedi_insn *insn,lsampl_t *data)
+{
+       BYTE b_WriteType;
+       INT i_ReturnValue=0;
+    b_WriteType=CR_CHAN(insn->chanspec);
+
+    
+       switch(b_WriteType)
+       {
+       case APCI1710_PWM_ENABLE :
+               i_ReturnValue=i_APCI1710_EnablePWM    (dev,
+                                (BYTE)  CR_AREF(insn->chanspec),
+                                (BYTE)  data[0],
+                                (BYTE)  data[1],
+                                (BYTE)  data[2],
+                                (BYTE)  data[3],
+                                (BYTE)  data[4],
+                                (BYTE)  data[5]);
+               break;
+
+       case APCI1710_PWM_DISABLE :
+               i_ReturnValue=i_APCI1710_DisablePWM   (dev,
+                                (BYTE)  CR_AREF(insn->chanspec),
+                                (BYTE)  data[0]);
+               break;
+
+       case APCI1710_PWM_NEWTIMING:
+               i_ReturnValue=i_APCI1710_SetNewPWMTiming        (dev,
+                                        (BYTE)  CR_AREF(insn->chanspec),
+                                        (BYTE)  data[0],
+                                        (BYTE)    data[1],
+                                        (ULONG)   data[2],
+                                        (ULONG)   data[3]);
+               break;
+
+       
+       default:
+               printk("Write Config Parameter Wrong\n");
+       }
+
+       if(i_ReturnValue>=0) i_ReturnValue =insn->n;
+       return (i_ReturnValue);
+}
+
+
+
+
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     : _INT_     i_APCI1710_EnablePWM                         |
+|                                       (BYTE_  b_BoardHandle,               |
+|                                        BYTE_  b_ModulNbr,                  |
+|                                        BYTE_  b_PWM,                       |
+|                                        BYTE_  b_StartLevel,                |
+|                                        BYTE_  b_StopMode,                  |
+|                                        BYTE_  b_StopLevel,                 |
+|                                        BYTE_  b_ExternGate,                |
+|                                        BYTE_  b_InterruptEnable)           |
++----------------------------------------------------------------------------+
+| Task              : Enable the selected PWM (b_PWM) from selected module   |
+|                     (b_ModulNbr). You must calling the "i_APCI1710_InitPWM"|
+|                     function be for you call this function.                |
+|                     If you enable the PWM interrupt, the PWM generate a    |
+|                     interrupt after each period.                           |
+|                     See function "i_APCI1710_SetBoardIntRoutineX" and the  |
+|                     Interrupt mask description chapter.                    |
++----------------------------------------------------------------------------+
+| Input Parameters  : BYTE_ b_BoardHandle     : Handle of board APCI-1710    |
+|                     BYTE_ b_ModulNbr        : Selected module number       |
+|                                               (0 to 3)                     |
+|                     BYTE_ b_PWM             : Selected PWM (0 or 1)        |
+|                     BYTE_ b_StartLevel      : Start period level selection |
+|                                                0 : The period start with a |
+|                                                    low level               |
+|                                                1 : The period start with a |
+|                                                    high level              |
+|                     BYTE_ b_StopMode        : Stop mode selection          |
+|                                                0 : The PWM is stopped      |
+|                                                    directly after the      |
+|                                                    "i_APCI1710_DisablePWM" |
+|                                                    function and break the  |
+|                                                    last period             |
+|                                                1 : After the               |
+|                                                    "i_APCI1710_DisablePWM" |
+|                                                     function the PWM is    |
+|                                                     stopped at the end from|
+|                                                     last period cycle.     |
+|                     BYTE_ b_StopLevel       : Stop PWM level selection     |
+|                                                0 : The output signal keep  |
+|                                                    the level after the     |
+|                                                    "i_APCI1710_DisablePWM" |
+|                                                    function                |
+|                                                1 : The output signal is set|
+|                                                    to low after the        |
+|                                                    "i_APCI1710_DisablePWM" |
+|                                                    function                |
+|                                                2 : The output signal is set|
+|                                                    to high after the       |
+|                                                    "i_APCI1710_DisablePWM" |
+|                                                    function                |
+|                     BYTE_ b_ExternGate      : Extern gate action selection |
+|                                                0 : Extern gate signal not  |
+|                                                    used.                   |
+|                                                1 : Extern gate signal used.|
+|                     BYTE_ b_InterruptEnable : Enable or disable the PWM    |
+|                                               interrupt.                   |
+|                                               - APCI1710_ENABLE :          |
+|                                                 Enable the PWM interrupt   |
+|                                                 A interrupt occur after    |
+|                                                 each period                |
+|                                               - APCI1710_DISABLE :         |
+|                                                 Disable the PWM interrupt  |
++----------------------------------------------------------------------------+
+| Output Parameters : -                                                      |
++----------------------------------------------------------------------------+
+| Return Value      : 0:  No error                                           |
+|                    -1:  The handle parameter of the board is wrong         |
+|                    -2:  Module selection wrong                             |
+|                    -3:  The module is not a PWM module                     |
+|                    -4:  PWM selection is wrong                             |
+|                    -5:  PWM not initialised see function                   |
+|                         "i_APCI1710_InitPWM"                               |
+|                    -6:  PWM start level selection is wrong                 |
+|                    -7:  PWM stop mode selection is wrong                   |
+|                    -8:  PWM stop level selection is wrong                  |
+|                    -9:  Extern gate signal selection is wrong              |
+|                    -10: Interrupt parameter is wrong                       |
+|                    -11: Interrupt function not initialised.                |
+|                         See function "i_APCI1710_SetBoardIntRoutineX"      |
++----------------------------------------------------------------------------+
+*/
+
+INT   i_APCI1710_EnablePWM    (comedi_device *dev,
+                                BYTE  b_ModulNbr,
+                                BYTE  b_PWM,
+                                BYTE  b_StartLevel,
+                                BYTE  b_StopMode,
+                                BYTE  b_StopLevel,
+                                BYTE  b_ExternGate,
+                                BYTE  b_InterruptEnable)
+       {
+       INT    i_ReturnValue = 0;
+       DWORD dw_Status;
+       DWORD dw_Command;
+
+               
+        devpriv->tsk_Current=current; // Save the current process task structure
+       /**************************/
+       /* Test the module number */
+       /**************************/
+
+       if (b_ModulNbr < 4)
+          {
+          /***************/
+          /* Test if PWM */
+          /***************/
+
+          if ((devpriv->
+               s_BoardInfos.
+               dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_PWM)
+             {
+             /**************************/
+             /* Test the PWM selection */
+             /**************************/
+
+             if (b_PWM <= 1)
+                {
+                /***************************/
+                /* Test if PWM initialised */
+                /***************************/
+
+                dw_Status=      inl(devpriv->s_BoardInfos.
+                       ui_Address + 12 + (20 * b_PWM) + (64 * b_ModulNbr));
+
+                if (dw_Status & 0x10)
+                   {
+                   /**********************************/
+                   /* Test the start level selection */
+                   /**********************************/
+
+                   if (b_StartLevel <= 1)
+                      {
+                      /**********************/
+                      /* Test the stop mode */
+                      /**********************/
+
+                      if (b_StopMode <= 1)
+                         {
+                         /***********************/
+                         /* Test the stop level */
+                         /***********************/
+
+                         if (b_StopLevel <= 2)
+                            {
+                            /*****************************/
+                            /* Test the extern gate mode */
+                            /*****************************/
+
+                            if (b_ExternGate <= 1)
+                               {
+                               /*****************************/
+                               /* Test the interrupt action */
+                               /*****************************/
+
+                               if (b_InterruptEnable == APCI1710_ENABLE || b_InterruptEnable == APCI1710_DISABLE)
+                                  {
+                                  /******************************************/
+                                  /* Test if interrupt function initialised */
+                                  /******************************************/
+
+                                     /********************/
+                                     /* Read the command */
+                                     /********************/
+
+                                           dw_Command=inl(devpriv->s_BoardInfos.
+                                            ui_Address + 8 + (20 * b_PWM) + (64 * b_ModulNbr));
+
+                                     dw_Command = dw_Command & 0x80;
+
+                                     /********************/
+                                     /* Make the command */
+                                     /********************/
+
+                                     dw_Command = dw_Command | b_StopMode | (b_InterruptEnable << 3) | (b_ExternGate << 4) | (b_StartLevel << 5);
+
+                                     if (b_StopLevel & 3)
+                                        {
+                                        dw_Command = dw_Command | 2;
+
+                                        if (b_StopLevel & 2)
+                                           {
+                                           dw_Command = dw_Command | 4;
+                                           }
+                                        }
+
+
+                                     devpriv->
+                                     s_ModuleInfo [b_ModulNbr].
+                                     s_PWMModuleInfo.
+                                     s_PWMInfo [b_PWM].
+                                     b_InterruptEnable = b_InterruptEnable;
+
+                                     /*******************/
+                                     /* Set the command */
+                                     /*******************/
+
+                                         outl(dw_Command,devpriv->s_BoardInfos.
+                                             ui_Address + 8 + (20 * b_PWM) + (64 * b_ModulNbr));
+
+                                     /******************/
+                                     /* Enable the PWM */
+                                     /******************/
+                                         outl(1,devpriv->s_BoardInfos.
+                                             ui_Address + 12 + (20 * b_PWM) + (64 * b_ModulNbr));
+                                  } // if (b_InterruptEnable == APCI1710_ENABLE || b_InterruptEnable == APCI1710_DISABLE)
+                               else
+                                  {
+                                  /********************************/
+                                  /* Interrupt parameter is wrong */
+                                  /********************************/
+                           DPRINTK("Interrupt parameter is wrong\n");
+                                  i_ReturnValue = -10;
+                                  } // if (b_InterruptEnable == APCI1710_ENABLE || b_InterruptEnable == APCI1710_DISABLE)
+                               } // if (b_ExternGate >= 0 && b_ExternGate <= 1)
+                            else
+                               {
+                               /*****************************************/
+                               /* Extern gate signal selection is wrong */
+                               /*****************************************/
+                               DPRINTK("Extern gate signal selection is wrong\n");
+                               i_ReturnValue = -9;
+                               } // if (b_ExternGate >= 0 && b_ExternGate <= 1)
+                            } // if (b_StopLevel >= 0 && b_StopLevel <= 2)
+                         else
+                            {
+                            /*************************************/
+                            /* PWM stop level selection is wrong */
+                            /*************************************/
+                                DPRINTK("PWM stop level selection is wrong\n");
+                            i_ReturnValue = -8;
+                            } // if (b_StopLevel >= 0 && b_StopLevel <= 2)
+                         } // if (b_StopMode >= 0 && b_StopMode <= 1)
+                      else
+                         {
+                         /************************************/
+                         /* PWM stop mode selection is wrong */
+                         /************************************/
+                         DPRINTK("PWM stop mode selection is wrong\n");        
+                         i_ReturnValue = -7;
+                         } // if (b_StopMode >= 0 && b_StopMode <= 1)
+                      } // if (b_StartLevel >= 0 && b_StartLevel <= 1)
+                   else
+                      {
+                      /**************************************/
+                      /* PWM start level selection is wrong */
+                      /**************************************/
+                          DPRINTK("PWM start level selection is wrong\n");       
+                      i_ReturnValue = -6;
+                      } // if (b_StartLevel >= 0 && b_StartLevel <= 1)
+                   } // if (dw_Status & 0x10)
+                else
+                   {
+                   /***********************/
+                   /* PWM not initialised */
+                   /***********************/
+                       DPRINTK("PWM not initialised\n");
+                   i_ReturnValue = -5;
+                   } // if (dw_Status & 0x10)
+                } // if (b_PWM >= 0 && b_PWM <= 1)
+             else
+                {
+                /******************************/
+                /* Tor PWM selection is wrong */
+                /******************************/
+                DPRINTK("Tor PWM selection is wrong\n");
+                i_ReturnValue = -4;
+                } // if (b_PWM >= 0 && b_PWM <= 1)
+             }
+          else
+             {
+             /**********************************/
+             /* The module is not a PWM module */
+             /**********************************/
+             DPRINTK("The module is not a PWM module\n");      
+             i_ReturnValue = -3;
+             }
+          }
+       else
+          {
+          /***********************/
+          /* Module number error */
+          /***********************/
+          DPRINTK("Module number error\n");    
+          i_ReturnValue = -2;
+          }
+
+       return (i_ReturnValue);
+       }
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     : _INT_ i_APCI1710_DisablePWM (BYTE_  b_BoardHandle,     |
+|                                                  BYTE_  b_ModulNbr,        |
+|                                                  BYTE_  b_PWM)             |
++----------------------------------------------------------------------------+
+| Task              : Disable the selected PWM (b_PWM) from selected module  |
+|                     (b_ModulNbr). The output signal level depend of the    |
+|                     initialisation by the "i_APCI1710_EnablePWM".          |
+|                     See the b_StartLevel, b_StopMode and b_StopLevel       |
+|                     parameters from this function.                         |
++----------------------------------------------------------------------------+
+| Input Parameters  :BYTE_ b_BoardHandle : Handle of board APCI-1710         |
+|                    BYTE_ b_ModulNbr    : Selected module number (0 to 3)   |
+|                    BYTE_ b_PWM         : Selected PWM (0 or 1)             |
++----------------------------------------------------------------------------+
+| Output Parameters : -                                                      |
++----------------------------------------------------------------------------+
+| Return Value      :  0: No error                                           |
+|                     -1: The handle parameter of the board is wrong         |
+|                     -2: Module selection wrong                             |
+|                     -3: The module is not a PWM module                     |
+|                     -4: PWM selection is wrong                             |
+|                     -5: PWM not initialised see function                   |
+|                         "i_APCI1710_InitPWM"                               |
+|                     -6: PWM not enabled see function                       |
+|                         "i_APCI1710_EnablePWM"                             |
++----------------------------------------------------------------------------+
+*/
+
+INT   i_APCI1710_DisablePWM   (comedi_device *dev,
+                                BYTE  b_ModulNbr,
+                                BYTE  b_PWM)
+       {
+       INT    i_ReturnValue = 0;
+       DWORD dw_Status;
+
+       /**************************/
+       /* Test the module number */
+       /**************************/
+
+       if (b_ModulNbr < 4)
+          {
+          /***************/
+          /* Test if PWM */
+          /***************/
+
+          if ((devpriv->s_BoardInfos.
+               dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_PWM)
+             {
+             /**************************/
+             /* Test the PWM selection */
+             /**************************/
+
+             if (b_PWM <= 1)
+                {
+                /***************************/
+                /* Test if PWM initialised */
+                /***************************/
+
+           dw_Status=inl(devpriv->s_BoardInfos.
+                       ui_Address + 12 + (20 * b_PWM) + (64 * b_ModulNbr));
+
+                if (dw_Status & 0x10)
+                   {
+                   /***********************/
+                   /* Test if PWM enabled */
+                   /***********************/
+
+                   if (dw_Status & 0x1)
+                      {
+                      /*******************/
+                      /* Disable the PWM */
+                      /*******************/
+                               outl(0,devpriv->s_BoardInfos.
+                              ui_Address + 12 + (20 * b_PWM) + (64 * b_ModulNbr));
+                      } // if (dw_Status & 0x1)
+                   else
+                      {
+                      /*******************/
+                      /* PWM not enabled */
+                      /*******************/
+                          DPRINTK("PWM not enabled\n");        
+                      i_ReturnValue = -6;
+                      } // if (dw_Status & 0x1)
+                   } // if (dw_Status & 0x10)
+                else
+                   {
+                   /***********************/
+                   /* PWM not initialised */
+                   /***********************/
+                       DPRINTK(" PWM not initialised\n");
+                   i_ReturnValue = -5;
+                   } // if (dw_Status & 0x10)
+                } // if (b_PWM >= 0 && b_PWM <= 1)
+             else
+                {
+                /******************************/
+                /* Tor PWM selection is wrong */
+                /******************************/
+                DPRINTK("Tor PWM selection is wrong\n");       
+                i_ReturnValue = -4;
+                } // if (b_PWM >= 0 && b_PWM <= 1)
+             }
+          else
+             {
+             /**********************************/
+             /* The module is not a PWM module */
+             /**********************************/
+             DPRINTK("The module is not a PWM module\n");      
+             i_ReturnValue = -3;
+             }
+          }
+       else
+          {
+          /***********************/
+          /* Module number error */
+          /***********************/
+          DPRINTK("Module number error\n");
+          i_ReturnValue = -2;
+          }
+
+       return (i_ReturnValue);
+       }
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     : _INT_ i_APCI1710_SetNewPWMTiming                       |
+|                                       (BYTE_     b_BoardHandle,            |
+|                                        BYTE_     b_ModulNbr,               |
+|                                        BYTE_     b_PWM,                    |
+|                                        BYTE_     b_ClockSelection,         |
+|                                        BYTE_     b_TimingUnit,             |
+|                                        ULONG_   ul_LowTiming,              |
+|                                        ULONG_   ul_HighTiming)             |
++----------------------------------------------------------------------------+
+| Task              : Set a new timing. The ul_LowTiming, ul_HighTiming and  |
+|                     ul_TimingUnit determine the low/high timing base for   |
+|                     the period.                                            |
++----------------------------------------------------------------------------+
+| Input Parameters  : BYTE_     b_BoardHandle    : Handle of board APCI-1710 |
+|                     BYTE_     b_ModulNbr       : Module number to configure|
+|                                                  (0 to 3)                  |
+|                     BYTE_     b_PWM            : Selected PWM (0 or 1).    |
+|                     BYTE_     b_TimingUnit     : Base timing Unit (0 to 4) |
+|                                                       0 : ns               |
+|                                                       1 : æs               |
+|                                                       2 : ms               |
+|                                                       3 : s                |
+|                                                       4 : mn               |
+|                     ULONG_    ul_LowTiming     : Low base timing value.    |
+|                     ULONG_    ul_HighTiming    : High base timing value.   |
++----------------------------------------------------------------------------+
+| Output Parameters : -                                                      |
++----------------------------------------------------------------------------+
+| Return Value      : 0: No error                                            |
+|                    -1: The handle parameter of the board is wrong          |
+|                    -2: Module selection wrong                              |
+|                    -3: The module is not a PWM module                      |
+|                    -4: PWM selection is wrong                              |
+|                    -5: PWM not initialised                                 |
+|                    -6: Timing Unit selection is wrong                      |
+|                    -7: Low base timing selection is wrong                  |
+|                    -8: High base timing selection is wrong                 |
++----------------------------------------------------------------------------+
+*/
+
+INT   i_APCI1710_SetNewPWMTiming       (comedi_device *dev,
+                                        BYTE     b_ModulNbr,
+                                        BYTE     b_PWM,
+                                        BYTE     b_TimingUnit,
+                                        ULONG   ul_LowTiming,
+                                        ULONG   ul_HighTiming)
+       {
+       BYTE   b_ClockSelection;
+       INT    i_ReturnValue = 0;
+       ULONG ul_LowTimerValue = 0;
+       ULONG ul_HighTimerValue = 0;
+       ULONG ul_RealLowTiming = 0;
+       ULONG ul_RealHighTiming = 0;
+       DWORD dw_Status;
+       DWORD dw_Command;
+       double d_RealLowTiming = 0;
+       double d_RealHighTiming = 0;
+       
+
+       /**************************/
+       /* Test the module number */
+       /**************************/
+
+       if (b_ModulNbr < 4)
+          {
+          /***************/
+          /* Test if PWM */
+          /***************/
+
+          if ((devpriv->s_BoardInfos.
+               dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_PWM)
+             {
+             /**************************/
+             /* Test the PWM selection */
+             /**************************/
+
+             if (b_PWM <= 1)
+                {
+                /***************************/
+                /* Test if PWM initialised */
+                /***************************/
+
+                       dw_Status=inl(devpriv->s_BoardInfos.
+                       ui_Address + 12 + (20 * b_PWM) + (64 * b_ModulNbr));
+
+                if (dw_Status & 0x10)
+                   {
+                   b_ClockSelection = devpriv->
+                                      s_ModuleInfo [b_ModulNbr].
+                                      s_PWMModuleInfo.
+                                      b_ClockSelection;
+
+                   /************************/
+                   /* Test the timing unit */
+                   /************************/
+
+                   if (b_TimingUnit <= 4)
+                      {
+                      /*********************************/
+                      /* Test the low timing selection */
+                      /*********************************/
+
+                      if (((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 0) && (ul_LowTiming >= 266) && (ul_LowTiming <= 0xFFFFFFFFUL)) ||
+                          ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 1) && (ul_LowTiming >= 1)   && (ul_LowTiming <= 571230650UL))  ||
+                          ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 2) && (ul_LowTiming >= 1)   && (ul_LowTiming <= 571230UL))     ||
+                          ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 3) && (ul_LowTiming >= 1)   && (ul_LowTiming <= 571UL))        ||
+                          ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 4) && (ul_LowTiming >= 1)   && (ul_LowTiming <= 9UL))          ||
+                          ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 0) && (ul_LowTiming >= 242) && (ul_LowTiming <= 0xFFFFFFFFUL)) ||
+                          ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 1) && (ul_LowTiming >= 1)   && (ul_LowTiming <= 519691043UL))  ||
+                          ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 2) && (ul_LowTiming >= 1)   && (ul_LowTiming <= 519691UL))     ||
+                          ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 3) && (ul_LowTiming >= 1)   && (ul_LowTiming <= 520UL))        ||
+                          ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 4) && (ul_LowTiming >= 1)   && (ul_LowTiming <= 8UL))          ||
+                          ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 0) && (ul_LowTiming >= 200) && (ul_LowTiming <= 0xFFFFFFFFUL)) ||
+                          ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 1) && (ul_LowTiming >= 1)   && (ul_LowTiming <= 429496729UL))  ||
+                          ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 2) && (ul_LowTiming >= 1)   && (ul_LowTiming <= 429496UL))     ||
+                          ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 3) && (ul_LowTiming >= 1)   && (ul_LowTiming <= 429UL))        ||
+                          ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 4) && (ul_LowTiming >= 1)   && (ul_LowTiming <= 7UL)))
+                         {
+                         /**********************************/
+                         /* Test the High timing selection */
+                         /**********************************/
+
+                         if (((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 0) && (ul_HighTiming >= 266) && (ul_HighTiming <= 0xFFFFFFFFUL)) ||
+                             ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 1) && (ul_HighTiming >= 1)   && (ul_HighTiming <= 571230650UL))  ||
+                             ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 2) && (ul_HighTiming >= 1)   && (ul_HighTiming <= 571230UL))     ||
+                             ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 3) && (ul_HighTiming >= 1)   && (ul_HighTiming <= 571UL))        ||
+                             ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 4) && (ul_HighTiming >= 1)   && (ul_HighTiming <= 9UL))          ||
+                             ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 0) && (ul_HighTiming >= 242) && (ul_HighTiming <= 0xFFFFFFFFUL)) ||
+                             ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 1) && (ul_HighTiming >= 1)   && (ul_HighTiming <= 519691043UL))  ||
+                             ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 2) && (ul_HighTiming >= 1)   && (ul_HighTiming <= 519691UL))     ||
+                             ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 3) && (ul_HighTiming >= 1)   && (ul_HighTiming <= 520UL))        ||
+                             ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 4) && (ul_HighTiming >= 1)   && (ul_HighTiming <= 8UL))          ||
+                             ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 0) && (ul_HighTiming >= 200) && (ul_HighTiming <= 0xFFFFFFFFUL)) ||
+                             ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 1) && (ul_HighTiming >= 1)   && (ul_HighTiming <= 429496729UL))  ||
+                             ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 2) && (ul_HighTiming >= 1)   && (ul_HighTiming <= 429496UL))     ||
+                             ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 3) && (ul_HighTiming >= 1)   && (ul_HighTiming <= 429UL))        ||
+                             ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 4) && (ul_HighTiming >= 1)   && (ul_HighTiming <= 7UL)))
+                            {
+                            /************************************/
+                            /* Calculate the low division fator */
+                            /************************************/
+
+                            fpu_begin ();
+                            switch (b_TimingUnit)
+                               {
+                               /******/
+                               /* ns */
+                               /******/
+
+                               case 0:
+                                    
+                                       /******************/
+                                       /* Timer 0 factor */
+                                       /******************/
+
+                                       ul_LowTimerValue = (ULONG) (ul_LowTiming * (0.00025 * b_ClockSelection));
+
+                                       /*******************/
+                                       /* Round the value */
+                                       /*******************/
+
+                                       if ((double) ((double) ul_LowTiming * (0.00025 * (double) b_ClockSelection)) >= ((double) ((double) ul_LowTimerValue + 0.5)))
+                                          {
+                                          ul_LowTimerValue = ul_LowTimerValue + 1;
+                                          }
+
+                                       /*****************************/
+                                       /* Calculate the real timing */
+                                       /*****************************/
+
+                                       ul_RealLowTiming = (ULONG) (ul_LowTimerValue / (0.00025 * (double) b_ClockSelection));
+                                       d_RealLowTiming = (double) ul_LowTimerValue / (0.00025 * (double) b_ClockSelection);
+
+                                       if ((double) ((double) ul_LowTimerValue / (0.00025 * (double) b_ClockSelection)) >= (double) ((double) ul_RealLowTiming + 0.5))
+                                          {
+                                          ul_RealLowTiming = ul_RealLowTiming + 1;
+                                          }
+
+                                       ul_LowTiming     = ul_LowTiming - 1;
+                                       ul_LowTimerValue = ul_LowTimerValue - 2;
+
+                                       if (b_ClockSelection != APCI1710_40MHZ)
+                                          {
+                                          ul_LowTimerValue = (ULONG) ((double) (ul_LowTimerValue) * 1.007752288);
+                                          }
+                                   
+
+                                    break;
+
+                               /******/
+                               /* æs */
+                               /******/
+
+                               case 1:
+                                   
+                                       /******************/
+                                       /* Timer 0 factor */
+                                       /******************/
+
+                                       ul_LowTimerValue = (ULONG) (ul_LowTiming * (0.25 * b_ClockSelection));
+
+                                       /*******************/
+                                       /* Round the value */
+                                       /*******************/
+
+                                       if ((double) ((double) ul_LowTiming * (0.25 * (double) b_ClockSelection)) >= ((double) ((double) ul_LowTimerValue + 0.5)))
+                                          {
+                                          ul_LowTimerValue = ul_LowTimerValue + 1;
+                                          }
+
+                                       /*****************************/
+                                       /* Calculate the real timing */
+                                       /*****************************/
+
+                                       ul_RealLowTiming = (ULONG) (ul_LowTimerValue / (0.25 * (double) b_ClockSelection));
+                                       d_RealLowTiming    = (double) ul_LowTimerValue / ((double) 0.25 * (double) b_ClockSelection);
+
+                                       if ((double) ((double) ul_LowTimerValue / (0.25 * (double) b_ClockSelection)) >= (double) ((double) ul_RealLowTiming + 0.5))
+                                          {
+                                          ul_RealLowTiming = ul_RealLowTiming + 1;
+                                          }
+
+                                       ul_LowTiming     = ul_LowTiming - 1;
+                                       ul_LowTimerValue = ul_LowTimerValue - 2;
+
+                                       if (b_ClockSelection != APCI1710_40MHZ)
+                                          {
+                                          ul_LowTimerValue = (ULONG) ((double) (ul_LowTimerValue) * 1.007752288);
+                                          }
+                                   
+                                    break;
+
+                               /******/
+                               /* ms */
+                               /******/
+
+                               case 2:
+                                    
+                                       /******************/
+                                       /* Timer 0 factor */
+                                       /******************/
+
+                                       ul_LowTimerValue = ul_LowTiming * (250.0 * b_ClockSelection);
+
+                                       /*******************/
+                                       /* Round the value */
+                                       /*******************/
+
+                                       if ((double) ((double) ul_LowTiming * (250.0 * (double) b_ClockSelection)) >= ((double) ((double) ul_LowTimerValue + 0.5)))
+                                          {
+                                          ul_LowTimerValue = ul_LowTimerValue + 1;
+                                          }
+
+                                       /*****************************/
+                                       /* Calculate the real timing */
+                                       /*****************************/
+
+                                       ul_RealLowTiming = (ULONG) (ul_LowTimerValue / (250.0 * (double) b_ClockSelection));
+                                       d_RealLowTiming    = (double) ul_LowTimerValue / (250.0 * (double) b_ClockSelection);
+
+                                       if ((double) ((double) ul_LowTimerValue / (250.0 * (double) b_ClockSelection)) >= (double) ((double) ul_RealLowTiming + 0.5))
+                                          {
+                                          ul_RealLowTiming = ul_RealLowTiming + 1;
+                                          }
+
+                                       ul_LowTiming     = ul_LowTiming - 1;
+                                       ul_LowTimerValue = ul_LowTimerValue - 2;
+
+                                       if (b_ClockSelection != APCI1710_40MHZ)
+                                          {
+                                          ul_LowTimerValue = (ULONG) ((double) (ul_LowTimerValue) * 1.007752288);
+                                          }
+                                    
+                                    break;
+
+                               /*****/
+                               /* s */
+                               /*****/
+
+                               case 3:
+                                    
+                                       /******************/
+                                       /* Timer 0 factor */
+                                       /******************/
+
+                                       ul_LowTimerValue = (ULONG) (ul_LowTiming * (250000.0 * b_ClockSelection));
+
+                                       /*******************/
+                                       /* Round the value */
+                                       /*******************/
+
+                                       if ((double) ((double) ul_LowTiming * (250000.0 * (double) b_ClockSelection)) >= ((double) ((double) ul_LowTimerValue + 0.5)))
+                                          {
+                                          ul_LowTimerValue = ul_LowTimerValue + 1;
+                                          }
+
+                                       /*****************************/
+                                       /* Calculate the real timing */
+                                       /*****************************/
+
+                                       ul_RealLowTiming = (ULONG) (ul_LowTimerValue / (250000.0 * (double) b_ClockSelection));
+                                       d_RealLowTiming    = (double) ul_LowTimerValue / (250000.0 * (double) b_ClockSelection);
+
+                                       if ((double) ((double) ul_LowTimerValue / (250000.0 * (double) b_ClockSelection)) >= (double) ((double) ul_RealLowTiming + 0.5))
+                                          {
+                                          ul_RealLowTiming = ul_RealLowTiming + 1;
+                                          }
+
+                                       ul_LowTiming     = ul_LowTiming - 1;
+                                       ul_LowTimerValue = ul_LowTimerValue - 2;
+
+                                       if (b_ClockSelection != APCI1710_40MHZ)
+                                          {
+                                          ul_LowTimerValue = (ULONG) ((double) (ul_LowTimerValue) * 1.007752288);
+                                          }
+                                   
+                                    break;
+
+                               /******/
+                               /* mn */
+                               /******/
+
+                               case 4:
+                                    
+                                       /******************/
+                                       /* Timer 0 factor */
+                                       /******************/
+
+                                       ul_LowTimerValue = (ULONG) ((ul_LowTiming * 60) * (250000.0 * b_ClockSelection));
+
+                                       /*******************/
+                                       /* Round the value */
+                                       /*******************/
+
+                                       if ((double) ((double) (ul_LowTiming * 60.0) * (250000.0 * (double) b_ClockSelection)) >= ((double) ((double) ul_LowTimerValue + 0.5)))
+                                          {
+                                          ul_LowTimerValue = ul_LowTimerValue + 1;
+                                          }
+
+                                       /*****************************/
+                                       /* Calculate the real timing */
+                                       /*****************************/
+
+                                       ul_RealLowTiming = (ULONG) (ul_LowTimerValue / (250000.0 * (double) b_ClockSelection)) / 60;
+                                       d_RealLowTiming    = ((double) ul_LowTimerValue / (250000.0 * (double) b_ClockSelection)) / 60.0;
+
+                                       if ((double) (((double) ul_LowTimerValue / (250000.0 * (double) b_ClockSelection)) / 60.0) >= (double) ((double) ul_RealLowTiming + 0.5))
+                                          {
+                                          ul_RealLowTiming = ul_RealLowTiming + 1;
+                                          }
+
+                                       ul_LowTiming     = ul_LowTiming - 1;
+                                       ul_LowTimerValue = ul_LowTimerValue - 2;
+
+                                       if (b_ClockSelection != APCI1710_40MHZ)
+                                          {
+                                          ul_LowTimerValue = (ULONG) ((double) (ul_LowTimerValue) * 1.007752288);
+                                          }
+                                    
+                                    break;
+                               }
+
+                            /*************************************/
+                            /* Calculate the high division fator */
+                            /*************************************/
+
+                            switch (b_TimingUnit)
+                               {
+                               /******/
+                               /* ns */
+                               /******/
+
+                               case 0:
+                                   
+                                       /******************/
+                                       /* Timer 0 factor */
+                                       /******************/
+
+                                       ul_HighTimerValue = (ULONG) (ul_HighTiming * (0.00025 * b_ClockSelection));
+
+                                       /*******************/
+                                       /* Round the value */
+                                       /*******************/
+
+                                       if ((double) ((double) ul_HighTiming * (0.00025 * (double) b_ClockSelection)) >= ((double) ((double) ul_HighTimerValue + 0.5)))
+                                          {
+                                          ul_HighTimerValue = ul_HighTimerValue + 1;
+                                          }
+
+                                       /*****************************/
+                                       /* Calculate the real timing */
+                                       /*****************************/
+
+                                       ul_RealHighTiming = (ULONG) (ul_HighTimerValue / (0.00025 * (double) b_ClockSelection));
+                                       d_RealHighTiming    = (double) ul_HighTimerValue / (0.00025 * (double) b_ClockSelection);
+
+                                       if ((double) ((double) ul_HighTimerValue / (0.00025 * (double) b_ClockSelection)) >= (double) ((double) ul_RealHighTiming + 0.5))
+                                          {
+                                          ul_RealHighTiming = ul_RealHighTiming + 1;
+                                          }
+
+                                       ul_HighTiming     = ul_HighTiming - 1;
+                                       ul_HighTimerValue = ul_HighTimerValue - 2;
+
+                                       if (b_ClockSelection != APCI1710_40MHZ)
+                                          {
+                                          ul_HighTimerValue = (ULONG) ((double) (ul_HighTimerValue) * 1.007752288);
+                                          }
+                                    
+
+                                    break;
+
+                               /******/
+                               /* æs */
+                               /******/
+
+                               case 1:
+                                    
+                                       /******************/
+                                       /* Timer 0 factor */
+                                       /******************/
+
+                                       ul_HighTimerValue = (ULONG) (ul_HighTiming * (0.25 * b_ClockSelection));
+
+                                       /*******************/
+                                       /* Round the value */
+                                       /*******************/
+
+                                       if ((double) ((double) ul_HighTiming * (0.25 * (double) b_ClockSelection)) >= ((double) ((double) ul_HighTimerValue + 0.5)))
+                                          {
+                                          ul_HighTimerValue = ul_HighTimerValue + 1;
+                                          }
+
+                                       /*****************************/
+                                       /* Calculate the real timing */
+                                       /*****************************/
+
+                                       ul_RealHighTiming = (ULONG) (ul_HighTimerValue / (0.25 * (double) b_ClockSelection));
+                                       d_RealHighTiming    = (double) ul_HighTimerValue / ((double) 0.25 * (double) b_ClockSelection);
+
+                                       if ((double) ((double) ul_HighTimerValue / (0.25 * (double) b_ClockSelection)) >= (double) ((double) ul_RealHighTiming + 0.5))
+                                          {
+                                          ul_RealHighTiming = ul_RealHighTiming + 1;
+                                          }
+
+                                       ul_HighTiming     = ul_HighTiming - 1;
+                                       ul_HighTimerValue = ul_HighTimerValue - 2;
+
+                                       if (b_ClockSelection != APCI1710_40MHZ)
+                                          {
+                                          ul_HighTimerValue = (ULONG) ((double) (ul_HighTimerValue) * 1.007752288);
+                                          }
+                                   
+                                    break;
+
+                               /******/
+                               /* ms */
+                               /******/
+
+                               case 2:
+                                    
+                                       /******************/
+                                       /* Timer 0 factor */
+                                       /******************/
+
+                                       ul_HighTimerValue = ul_HighTiming * (250.0 * b_ClockSelection);
+
+                                       /*******************/
+                                       /* Round the value */
+                                       /*******************/
+
+                                       if ((double) ((double) ul_HighTiming * (250.0 * (double) b_ClockSelection)) >= ((double) ((double) ul_HighTimerValue + 0.5)))
+                                          {
+                                          ul_HighTimerValue = ul_HighTimerValue + 1;
+                                          }
+
+                                       /*****************************/
+                                       /* Calculate the real timing */
+                                       /*****************************/
+
+                                       ul_RealHighTiming = (ULONG) (ul_HighTimerValue / (250.0 * (double) b_ClockSelection));
+                                       d_RealHighTiming    = (double) ul_HighTimerValue / (250.0 * (double) b_ClockSelection);
+
+                                       if ((double) ((double) ul_HighTimerValue / (250.0 * (double) b_ClockSelection)) >= (double) ((double) ul_RealHighTiming + 0.5))
+                                          {
+                                          ul_RealHighTiming = ul_RealHighTiming + 1;
+                                          }
+
+                                       ul_HighTiming     = ul_HighTiming - 1;
+                                       ul_HighTimerValue = ul_HighTimerValue - 2;
+
+                                       if (b_ClockSelection != APCI1710_40MHZ)
+                                          {
+                                          ul_HighTimerValue = (ULONG) ((double) (ul_HighTimerValue) * 1.007752288);
+                                          }
+                                  
+                                    break;
+
+                               /*****/
+                               /* s */
+                               /*****/
+
+                               case 3:
+                                   
+                                       /******************/
+                                       /* Timer 0 factor */
+                                       /******************/
+
+                                       ul_HighTimerValue = (ULONG) (ul_HighTiming * (250000.0 * b_ClockSelection));
+
+                                       /*******************/
+                                       /* Round the value */
+                                       /*******************/
+
+                                       if ((double) ((double) ul_HighTiming * (250000.0 * (double) b_ClockSelection)) >= ((double) ((double) ul_HighTimerValue + 0.5)))
+                                          {
+                                          ul_HighTimerValue = ul_HighTimerValue + 1;
+                                          }
+
+                                       /*****************************/
+                                       /* Calculate the real timing */
+                                       /*****************************/
+
+                                       ul_RealHighTiming = (ULONG) (ul_HighTimerValue / (250000.0 * (double) b_ClockSelection));
+                                       d_RealHighTiming    = (double) ul_HighTimerValue / (250000.0 * (double) b_ClockSelection);
+
+                                       if ((double) ((double) ul_HighTimerValue / (250000.0 * (double) b_ClockSelection)) >= (double) ((double) ul_RealHighTiming + 0.5))
+                                          {
+                                          ul_RealHighTiming = ul_RealHighTiming + 1;
+                                          }
+
+                                       ul_HighTiming     = ul_HighTiming - 1;
+                                       ul_HighTimerValue = ul_HighTimerValue - 2;
+
+                                       if (b_ClockSelection != APCI1710_40MHZ)
+                                          {
+                                          ul_HighTimerValue = (ULONG) ((double) (ul_HighTimerValue) * 1.007752288);
+                                          }
+                                   
+                                    break;
+
+                               /******/
+                               /* mn */
+                               /******/
+
+                               case 4:
+                                   
+                                       /******************/
+                                       /* Timer 0 factor */
+                                       /******************/
+
+                                       ul_HighTimerValue = (ULONG) ((ul_HighTiming * 60) * (250000.0 * b_ClockSelection));
+
+                                       /*******************/
+                                       /* Round the value */
+                                       /*******************/
+
+                                       if ((double) ((double) (ul_HighTiming * 60.0) * (250000.0 * (double) b_ClockSelection)) >= ((double) ((double) ul_HighTimerValue + 0.5)))
+                                          {
+                                          ul_HighTimerValue = ul_HighTimerValue + 1;
+                                          }
+
+                                       /*****************************/
+                                       /* Calculate the real timing */
+                                       /*****************************/
+
+                                       ul_RealHighTiming = (ULONG) (ul_HighTimerValue / (250000.0 * (double) b_ClockSelection)) / 60;
+                                       d_RealHighTiming    = ((double) ul_HighTimerValue / (250000.0 * (double) b_ClockSelection)) / 60.0;
+
+                                       if ((double) (((double) ul_HighTimerValue / (250000.0 * (double) b_ClockSelection)) / 60.0) >= (double) ((double) ul_RealHighTiming + 0.5))
+                                          {
+                                          ul_RealHighTiming = ul_RealHighTiming + 1;
+                                          }
+
+                                       ul_HighTiming     = ul_HighTiming - 1;
+                                       ul_HighTimerValue = ul_HighTimerValue - 2;
+
+                                       if (b_ClockSelection != APCI1710_40MHZ)
+                                          {
+                                          ul_HighTimerValue = (ULONG) ((double) (ul_HighTimerValue) * 1.007752288);
+                                          }
+                                    
+                                    break;
+                               }
+                               
+                            fpu_end ();
+                            
+                            /************************/
+                            /* Save the timing unit */
+                            /************************/
+
+                            devpriv->
+                            s_ModuleInfo [b_ModulNbr].
+                            s_PWMModuleInfo.
+                            s_PWMInfo [b_PWM].
+                            b_TimingUnit = b_TimingUnit;
+
+                            /****************************/
+                            /* Save the low base timing */
+                            /****************************/
+
+                            devpriv->
+                            s_ModuleInfo [b_ModulNbr].
+                            s_PWMModuleInfo.
+                            s_PWMInfo [b_PWM].
+                            d_LowTiming = d_RealLowTiming;
+
+                            devpriv->
+                            s_ModuleInfo [b_ModulNbr].
+                            s_PWMModuleInfo.
+                            s_PWMInfo [b_PWM].
+                            ul_RealLowTiming = ul_RealLowTiming;
+
+                            /****************************/
+                            /* Save the high base timing */
+                            /****************************/
+
+                            devpriv->
+                            s_ModuleInfo [b_ModulNbr].
+                            s_PWMModuleInfo.
+                            s_PWMInfo [b_PWM].
+                            d_HighTiming = d_RealHighTiming;
+
+                            devpriv->
+                            s_ModuleInfo [b_ModulNbr].
+                            s_PWMModuleInfo.
+                            s_PWMInfo [b_PWM].
+                            ul_RealHighTiming = ul_RealHighTiming;
+
+                            /************************/
+                            /* Write the low timing */
+                            /************************/
+
+                                outl(ul_LowTimerValue,devpriv->s_BoardInfos.
+                                    ui_Address + 0 + (20 * b_PWM) + (64 * b_ModulNbr));
+
+                            /*************************/
+                            /* Write the high timing */
+                            /*************************/
+
+                                outl(ul_HighTimerValue,devpriv->s_BoardInfos.
+                                    ui_Address + 4 + (20 * b_PWM) + (64 * b_ModulNbr));
+
+                            /***************************/
+                            /* Set the clock selection */
+                            /***************************/
+
+                                dw_Command=inl(devpriv->s_BoardInfos.
+                                   ui_Address + 8 + (20 * b_PWM) + (64 * b_ModulNbr));
+
+                            dw_Command = dw_Command & 0x7F;
+
+                            if (b_ClockSelection == APCI1710_40MHZ)
+                               {
+                               dw_Command = dw_Command | 0x80;
+                               }
+
+                            /***************************/
+                            /* Set the clock selection */
+                            /***************************/
+
+                                outl(dw_Command,devpriv->s_BoardInfos.
+                                    ui_Address + 8 + (20 * b_PWM) + (64 * b_ModulNbr));
+                            }
+                         else
+                            {
+                            /***************************************/
+                            /* High base timing selection is wrong */
+                            /***************************************/
+                         DPRINTK("High base timing selection is wrong\n");
+                            i_ReturnValue = -8;
+                            }
+                         }
+                      else
+                         {
+                         /**************************************/
+                         /* Low base timing selection is wrong */
+                         /**************************************/
+                         DPRINTK("Low base timing selection is wrong\n");
+                         i_ReturnValue = -7;
+                         }
+                      } // if ((b_TimingUnit >= 0) && (b_TimingUnit <= 4))
+                   else
+                      {
+                      /**********************************/
+                      /* Timing unit selection is wrong */
+                      /**********************************/
+                          DPRINTK("Timing unit selection is wrong\n"); 
+                      i_ReturnValue = -6;
+                      } // if ((b_TimingUnit >= 0) && (b_TimingUnit <= 4))
+                   } // if (dw_Status & 0x10)
+                else
+                   {
+                   /***********************/
+                   /* PWM not initialised */
+                   /***********************/
+                       DPRINTK("PWM not initialised\n");       
+                   i_ReturnValue = -5;
+                   } // if (dw_Status & 0x10)
+                } // if (b_PWM >= 0 && b_PWM <= 1)
+             else
+                {
+                /******************************/
+                /* Tor PWM selection is wrong */
+                /******************************/
+                DPRINTK("Tor PWM selection is wrong\n");
+                i_ReturnValue = -4;
+                } // if (b_PWM >= 0 && b_PWM <= 1)
+             }
+          else
+             {
+             /**********************************/
+             /* The module is not a PWM module */
+             /**********************************/
+             DPRINTK("The module is not a PWM module\n");      
+             i_ReturnValue = -3;
+             }
+          }
+       else
+          {
+          /***********************/
+          /* Module number error */
+          /***********************/
+          DPRINTK("Module number error\n");    
+          i_ReturnValue = -2;
+          }
+
+       return (i_ReturnValue);
+       }
+
+
+
+
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     : _INT_ i_APCI1710_GetPWMStatus                          |
+|                               (BYTE_    b_BoardHandle,                     |
+|                                BYTE_    b_ModulNbr,                        |
+|                                BYTE_    b_PWM,                             |
+|                                PBYTE_  pb_PWMOutputStatus,                 |
+|                                PBYTE_  pb_ExternGateStatus)                |
++----------------------------------------------------------------------------+
+| Task              : Return the status from selected PWM (b_PWM) from       |
+|                     selected module (b_ModulNbr).                          |
++----------------------------------------------------------------------------+
+| Input Parameters  : BYTE_  b_BoardHandle : Handle of board APCI-1710       |
+|                     BYTE_  b_PWM         : Selected PWM (0 or 1)           |
+|                     BYTE_  b_ModulNbr    : Selected module number (0 to 3)
+       b_ModulNbr                      =(BYTE)  CR_AREF(insn->chanspec);
+       b_PWM                           =(BYTE)  data[0];
+       
+ |
++----------------------------------------------------------------------------+
+| Output Parameters : PBYTE_  pb_PWMOutputStatus  : Return the PWM output    |
+|                                                   level status.            |
+|                                                    0 : The PWM output level|
+|                                                        is low.             |
+|                                                    1 : The PWM output level|
+|                                                        is high.            |
+|                     PBYTE_  pb_ExternGateStatus : Return the extern gate   |
+|                                                   level status.            |
+|                                                    0 : The extern gate is  |
+|                                                        low.                |
+|                                                    1 : The extern gate is  |
+|                                                        high.  
+    pb_PWMOutputStatus =(PBYTE) data[0];
+       pb_ExternGateStatus =(PBYTE) data[1];             |
++----------------------------------------------------------------------------+
+| Return Value      :  0: No error                                           |
+|                     -1: The handle parameter of the board is wrong         |
+|                     -2: Module selection wrong                             |
+|                     -3: The module is not a PWM module                     |
+|                     -4: PWM selection is wrong                             |
+|                     -5: PWM not initialised see function                   |
+|                         "i_APCI1710_InitPWM"                               |
+|                     -6: PWM not enabled see function "i_APCI1710_EnablePWM"|
++----------------------------------------------------------------------------+
+*/
+
+INT i_APCI1710_InsnReadGetPWMStatus(comedi_device *dev,comedi_subdevice *s,
+       comedi_insn *insn,lsampl_t *data)
+       {
+       INT    i_ReturnValue = 0;
+       DWORD  dw_Status;
+
+       BYTE    b_ModulNbr;
+       BYTE    b_PWM;
+       PBYTE   pb_PWMOutputStatus;
+       PBYTE   pb_ExternGateStatus;
+       
+       i_ReturnValue           = insn->n;
+       b_ModulNbr                      =(BYTE)  CR_AREF(insn->chanspec);
+       b_PWM                           =(BYTE)  CR_CHAN(insn->chanspec);
+       pb_PWMOutputStatus      =(PBYTE) &data[0];
+       pb_ExternGateStatus =(PBYTE) &data[1];
+
+       /**************************/
+       /* Test the module number */
+       /**************************/
+
+       if (b_ModulNbr < 4)
+          {
+          /***************/
+          /* Test if PWM */
+          /***************/
+
+          if ((devpriv->s_BoardInfos.
+               dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_PWM)
+             {
+             /**************************/
+             /* Test the PWM selection */
+             /**************************/
+
+             if (b_PWM <= 1)
+                {
+                /***************************/
+                /* Test if PWM initialised */
+                /***************************/
+
+                dw_Status=inl(devpriv->s_BoardInfos.
+                       ui_Address + 12 + (20 * b_PWM) + (64 * b_ModulNbr));
+
+                if (dw_Status & 0x10)
+                   {
+                   /***********************/
+                   /* Test if PWM enabled */
+                   /***********************/
+
+                   if (dw_Status & 0x1)
+                      {
+                      *pb_PWMOutputStatus  = (BYTE) ((dw_Status >> 7) & 1);
+                      *pb_ExternGateStatus = (BYTE) ((dw_Status >> 6) & 1);
+                      } // if (dw_Status & 0x1)
+                   else
+                      {
+                      /*******************/
+                      /* PWM not enabled */
+                      /*******************/
+
+                      DPRINTK("PWM not enabled \n");
+                      i_ReturnValue = -6;
+                      } // if (dw_Status & 0x1)
+                   } // if (dw_Status & 0x10)
+                else
+                   {
+                   /***********************/
+                   /* PWM not initialised */
+                   /***********************/
+
+                       DPRINTK("PWM not initialised\n");
+                   i_ReturnValue = -5;
+                   } // if (dw_Status & 0x10)
+                } // if (b_PWM >= 0 && b_PWM <= 1)
+             else
+                {
+                /******************************/
+                /* Tor PWM selection is wrong */
+                /******************************/
+
+                DPRINTK("Tor PWM selection is wrong\n");
+                i_ReturnValue = -4;
+                } // if (b_PWM >= 0 && b_PWM <= 1)
+             }
+          else
+             {
+             /**********************************/
+             /* The module is not a PWM module */
+             /**********************************/
+
+             DPRINTK("The module is not a PWM module\n");
+             i_ReturnValue = -3;
+             }
+          }
+       else
+          {
+          /***********************/
+          /* Module number error */
+          /***********************/
+
+          DPRINTK("Module number error\n");
+          i_ReturnValue = -2;
+          }
+
+       return (i_ReturnValue);
+       }
+
+
+INT i_APCI1710_InsnBitsReadPWMInterrupt(comedi_device *dev,comedi_subdevice *s,
+       comedi_insn *insn,lsampl_t *data)
+
+{
+                               data[0]=devpriv->s_InterruptParameters.
+                                                     s_FIFOInterruptParameters [devpriv->
+                                                                                s_InterruptParameters.
+                                                                                ui_Read].b_OldModuleMask;
+                         data[1]=devpriv->s_InterruptParameters.
+                                                     s_FIFOInterruptParameters [devpriv->
+                                                                                s_InterruptParameters.
+                                                                                ui_Read].ul_OldInterruptMask;
+                         data[2]=devpriv->s_InterruptParameters.
+                                                     s_FIFOInterruptParameters [devpriv->
+                                                                                s_InterruptParameters.
+                                                                                ui_Read].ul_OldCounterLatchValue;
+
+                            
+                            /**************************/
+                            /* Increment the read FIFO */
+                            /***************************/
+
+                            devpriv->
+                            s_InterruptParameters.
+                            ui_Read = (devpriv->
+                                       s_InterruptParameters.
+                                       ui_Read + 1) % APCI1710_SAVE_INTERRUPT;
+
+                               return insn->n;
+
+}
index e5f67e1918efea2a51a1e6b4a6d48efcd253e15b..afd28d305b3d7229e5fdd978bc9a6dec7a8877a6 100644 (file)
-/**\r
-@verbatim\r
-\r
-Copyright (C) 2004,2005  ADDI-DATA GmbH for the source code of this module. \r
-        \r
-        ADDI-DATA GmbH \r
-        Dieselstrasse 3 \r
-        D-77833 Ottersweier \r
-        Tel: +19(0)7223/9493-0 \r
-        Fax: +49(0)7223/9493-92 \r
-        http://www.addi-data-com \r
-        info@addi-data.com \r
-\r
-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.\r
-\r
-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.\r
-\r
-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 USA\r
-\r
-You shoud also find the complete GPL in the COPYING file accompanying this source code.\r
-\r
-@endverbatim\r
-*/\r
-\r
-\r
-\r
-\r
-\r
-   #define APCI1710_30MHZ           30\r
-   #define APCI1710_33MHZ           33\r
-   #define APCI1710_40MHZ           40\r
-\r
-\r
-#define APCI1710_PWM_INIT                      0\r
-#define APCI1710_PWM_GETINITDATA       1\r
-\r
-#define APCI1710_PWM_DISABLE        0\r
-#define APCI1710_PWM_ENABLE                    1\r
-#define APCI1710_PWM_NEWTIMING      2 \r
-\r
-\r
-\r
-\r
-INT    i_APCI1710_InsnConfigPWM(comedi_device *dev,comedi_subdevice *s,\r
-comedi_insn *insn,lsampl_t *data);\r
-\r
-INT   i_APCI1710_InitPWM      (comedi_device *dev,\r
-                                BYTE     b_ModulNbr,\r
-                                BYTE    b_PWM,\r
-                                BYTE     b_ClockSelection,\r
-                                BYTE     b_TimingUnit,\r
-                                ULONG   ul_LowTiming,\r
-                                ULONG   ul_HighTiming,\r
-                                PULONG pul_RealLowTiming,\r
-                                PULONG pul_RealHighTiming);\r
-\r
-INT  i_APCI1710_GetPWMInitialisation (comedi_device *dev,\r
-                                        BYTE     b_ModulNbr,\r
-                                        BYTE     b_PWM,\r
-                                        PBYTE   pb_TimingUnit,\r
-                                        PULONG pul_LowTiming,\r
-                                        PULONG pul_HighTiming,\r
-                                        PBYTE   pb_StartLevel,\r
-                                        PBYTE   pb_StopMode,\r
-                                        PBYTE   pb_StopLevel,\r
-                                        PBYTE   pb_ExternGate,\r
-                                        PBYTE   pb_InterruptEnable,\r
-                                        PBYTE   pb_Enable);\r
-\r
-\r
-\r
-\r
-INT    i_APCI1710_InsnWritePWM(comedi_device *dev,comedi_subdevice *s,\r
-comedi_insn *insn,lsampl_t *data);\r
-\r
-INT i_APCI1710_EnablePWM    (comedi_device *dev,\r
-                                BYTE  b_ModulNbr,\r
-                                BYTE  b_PWM,\r
-                                BYTE  b_StartLevel,\r
-                                BYTE  b_StopMode,\r
-                                BYTE  b_StopLevel,\r
-                                BYTE  b_ExternGate,\r
-                                BYTE  b_InterruptEnable);\r
-\r
-INT i_APCI1710_SetNewPWMTiming (comedi_device *dev,\r
-                                        BYTE     b_ModulNbr,\r
-                                        BYTE     b_PWM,\r
-                                        BYTE     b_TimingUnit,\r
-                                        ULONG   ul_LowTiming,\r
-                                        ULONG   ul_HighTiming);\r
-\r
-INT i_APCI1710_DisablePWM   (comedi_device *dev,\r
-                                BYTE  b_ModulNbr,\r
-                                BYTE  b_PWM);\r
-\r
-INT i_APCI1710_InsnReadGetPWMStatus(comedi_device *dev,comedi_subdevice *s,\r
-       comedi_insn *insn,lsampl_t *data);\r
-\r
-INT i_APCI1710_InsnBitsReadPWMInterrupt(comedi_device *dev,comedi_subdevice *s,\r
-       comedi_insn *insn,lsampl_t *data);\r
-\r
+/**
+@verbatim
+
+Copyright (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 USA
+
+You shoud also find the complete GPL in the COPYING file accompanying this source code.
+
+@endverbatim
+*/
+
+
+
+
+
+   #define APCI1710_30MHZ           30
+   #define APCI1710_33MHZ           33
+   #define APCI1710_40MHZ           40
+
+
+#define APCI1710_PWM_INIT                      0
+#define APCI1710_PWM_GETINITDATA       1
+
+#define APCI1710_PWM_DISABLE        0
+#define APCI1710_PWM_ENABLE                    1
+#define APCI1710_PWM_NEWTIMING      2 
+
+
+
+
+INT    i_APCI1710_InsnConfigPWM(comedi_device *dev,comedi_subdevice *s,
+comedi_insn *insn,lsampl_t *data);
+
+INT   i_APCI1710_InitPWM      (comedi_device *dev,
+                                BYTE     b_ModulNbr,
+                                BYTE    b_PWM,
+                                BYTE     b_ClockSelection,
+                                BYTE     b_TimingUnit,
+                                ULONG   ul_LowTiming,
+                                ULONG   ul_HighTiming,
+                                PULONG pul_RealLowTiming,
+                                PULONG pul_RealHighTiming);
+
+INT  i_APCI1710_GetPWMInitialisation (comedi_device *dev,
+                                        BYTE     b_ModulNbr,
+                                        BYTE     b_PWM,
+                                        PBYTE   pb_TimingUnit,
+                                        PULONG pul_LowTiming,
+                                        PULONG pul_HighTiming,
+                                        PBYTE   pb_StartLevel,
+                                        PBYTE   pb_StopMode,
+                                        PBYTE   pb_StopLevel,
+                                        PBYTE   pb_ExternGate,
+                                        PBYTE   pb_InterruptEnable,
+                                        PBYTE   pb_Enable);
+
+
+
+
+INT    i_APCI1710_InsnWritePWM(comedi_device *dev,comedi_subdevice *s,
+comedi_insn *insn,lsampl_t *data);
+
+INT i_APCI1710_EnablePWM    (comedi_device *dev,
+                                BYTE  b_ModulNbr,
+                                BYTE  b_PWM,
+                                BYTE  b_StartLevel,
+                                BYTE  b_StopMode,
+                                BYTE  b_StopLevel,
+                                BYTE  b_ExternGate,
+                                BYTE  b_InterruptEnable);
+
+INT i_APCI1710_SetNewPWMTiming (comedi_device *dev,
+                                        BYTE     b_ModulNbr,
+                                        BYTE     b_PWM,
+                                        BYTE     b_TimingUnit,
+                                        ULONG   ul_LowTiming,
+                                        ULONG   ul_HighTiming);
+
+INT i_APCI1710_DisablePWM   (comedi_device *dev,
+                                BYTE  b_ModulNbr,
+                                BYTE  b_PWM);
+
+INT i_APCI1710_InsnReadGetPWMStatus(comedi_device *dev,comedi_subdevice *s,
+       comedi_insn *insn,lsampl_t *data);
+
+INT i_APCI1710_InsnBitsReadPWMInterrupt(comedi_device *dev,comedi_subdevice *s,
+       comedi_insn *insn,lsampl_t *data);
+
index 8c60541818428c9f2232060357cf1442a1c2475f..0a639b1d63bf4da467b83248e7ce520bc46e78fe 100644 (file)
-/**\r
-@verbatim\r
-\r
-Copyright (C) 2004,2005  ADDI-DATA GmbH for the source code of this module. \r
-        \r
-        ADDI-DATA GmbH \r
-        Dieselstrasse 3 \r
-        D-77833 Ottersweier \r
-        Tel: +19(0)7223/9493-0 \r
-        Fax: +49(0)7223/9493-92 \r
-        http://www.addi-data-com \r
-        info@addi-data.com \r
-\r
-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.\r
-\r
-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.\r
-\r
-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 USA\r
-\r
-You shoud also find the complete GPL in the COPYING file accompanying this source code.\r
-\r
-@endverbatim\r
-*/\r
-/*\r
-    \r
-  +-----------------------------------------------------------------------+\r
-  | (C) ADDI-DATA GmbH          Dieselstraße 3       D-77833 Ottersweier  |\r
-  +-----------------------------------------------------------------------+\r
-  | Tel : +49 (0) 7223/9493-0     | email    : info@addi-data.com         |\r
-  | Fax : +49 (0) 7223/9493-92    | Internet : http://www.addi-data.com   |\r
-  +-----------------------------------------------------------------------+\r
-  | Project     : API APCI1710    | Compiler : gcc                        |\r
-  | Module name : SSI.C           | Version  : 2.96                       |\r
-  +-------------------------------+---------------------------------------+\r
-  | Project manager: Eric Stolz   | Date     :  02/12/2002                |\r
-  +-----------------------------------------------------------------------+\r
-  | Description :   APCI-1710 SSI counter module                          |\r
-  |                                                                       |\r
-  |                                                                       |\r
-  +-----------------------------------------------------------------------+\r
-  |                             UPDATES                                   |\r
-  +-----------------------------------------------------------------------+\r
-  |   Date   |   Author  |          Description of updates                |\r
-  +----------+-----------+------------------------------------------------+\r
-  | 13/05/98 | S. Weber  | SSI digital input / output implementation      |\r
-  |----------|-----------|------------------------------------------------|\r
-  | 22/03/00 | C.Guinot  | 0100/0226 -> 0200/0227                         |\r
-  |          |           | Änderung in InitSSI Funktion                   |\r
-  |          |           | b_SSIProfile >= 2 anstatt b_SSIProfile > 2     |\r
-  |          |           |                                                |\r
-  +-----------------------------------------------------------------------+\r
-  | 08/05/00 | Guinot C  | - 0400/0228 All Function in RING 0             |\r
-  |          |           |   available                                    |\r
-  +-----------------------------------------------------------------------+\r
-*/\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-|                               Included files                               |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-\r
-#include "APCI1710_Ssi.h"\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : _INT_ i_APCI1710_InitSSI                               |\r
-|                               (BYTE_    b_BoardHandle,                     |\r
-|                                BYTE_    b_ModulNbr,                        |\r
-|                                BYTE_    b_SSIProfile,                      |\r
-|                                BYTE_    b_PositionTurnLength,              |\r
-|                                BYTE_    b_TurnCptLength,                   |\r
-|                                BYTE_    b_PCIInputClock,                   |\r
-|                                ULONG_  ul_SSIOutputClock,                  |\r
-|                                BYTE_    b_SSICountingMode)                 |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Configure the SSI operating mode from selected module  |\r
-|                     (b_ModulNbr). You must calling this function be for you|\r
-|                     call any other function witch access of SSI.           |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : BYTE_ b_BoardHandle         : Handle of board APCI-1710|\r
-|                     BYTE_ b_ModulNbr            : Module number to         |\r
-|                                                   configure (0 to 3)       |\r
-|                     BYTE_  b_SSIProfile         : Selection from SSI       |\r
-|                                                   profile length (2 to 32).|\r
-|                     BYTE_  b_PositionTurnLength : Selection from SSI       |\r
-|                                                   position data length     |\r
-|                                                   (1 to 31).               |\r
-|                     BYTE_  b_TurnCptLength      : Selection from SSI turn  |\r
-|                                                   counter data length      |\r
-|                                                   (1 to 31).               |\r
-|                     BYTE   b_PCIInputClock      : Selection from PCI bus   |\r
-|                                                   clock                    |\r
-|                                                 - APCI1710_30MHZ :         |\r
-|                                                   The PC have a PCI bus    |\r
-|                                                   clock from 30 MHz        |\r
-|                                                 - APCI1710_33MHZ :         |\r
-|                                                   The PC have a PCI bus    |\r
-|                                                   clock from 33 MHz        |\r
-|                     ULONG_ ul_SSIOutputClock    : Selection from SSI output|\r
-|                                                   clock.                   |\r
-|                                                   From  229 to 5 000 000 Hz|\r
-|                                                   for 30 MHz selection.    |\r
-|                                                   From  252 to 5 000 000 Hz|\r
-|                                                   for 33 MHz selection.    |\r
-|                     BYTE   b_SSICountingMode    : SSI counting mode        |\r
-|                                                   selection                |\r
-|                                                 - APCI1710_BINARY_MODE :   |\r
-|                                                    Binary counting mode.   |\r
-|                                                 - APCI1710_GRAY_MODE :     |\r
-|                                                    Gray counting mode.\r
-\r
-       b_ModulNbr                      = CR_AREF(insn->chanspec);\r
-       b_SSIProfile            = (BYTE) data[0];  \r
-       b_PositionTurnLength= (BYTE) data[1];  \r
-       b_TurnCptLength         = (BYTE) data[2];\r
-       b_PCIInputClock         = (BYTE) data[3];\r
-       ul_SSIOutputClock       = (ULONG) data[4];\r
-       b_SSICountingMode       = (BYTE)  data[5];     |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : -                                                      |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      : 0: No error                                            |\r
-|                    -1: The handle parameter of the board is wrong          |\r
-|                    -2: The module parameter is wrong                       |\r
-|                    -3: The module is not a SSI module                      |\r
-|                    -4: The selected SSI profile length is wrong            |\r
-|                    -5: The selected SSI position data length is wrong      |\r
-|                    -6: The selected SSI turn counter data length is wrong  |\r
-|                    -7: The selected PCI input clock is wrong               |\r
-|                    -8: The selected SSI output clock is wrong              |\r
-|                    -9: The selected SSI counting mode parameter is wrong   |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-\r
-INT   i_APCI1710_InsnConfigInitSSI(comedi_device *dev,comedi_subdevice *s,\r
-       comedi_insn *insn,lsampl_t *data)\r
-       {\r
-       INT    i_ReturnValue = 0;\r
-       UINT   ui_TimerValue;\r
-       BYTE   b_ModulNbr,b_SSIProfile,b_PositionTurnLength,b_TurnCptLength,b_PCIInputClock,b_SSICountingMode;\r
-       ULONG  ul_SSIOutputClock;\r
-                       \r
-       b_ModulNbr                      = CR_AREF(insn->chanspec);\r
-       b_SSIProfile            = (BYTE) data[0];  \r
-       b_PositionTurnLength= (BYTE) data[1];  \r
-       b_TurnCptLength         = (BYTE) data[2];\r
-       b_PCIInputClock         = (BYTE) data[3];\r
-       ul_SSIOutputClock       = (ULONG) data[4];\r
-       b_SSICountingMode       = (BYTE)  data[5];\r
-\r
-       i_ReturnValue           = insn->n;\r
-       /**************************/\r
-       /* Test the module number */\r
-       /**************************/\r
-\r
-       if (b_ModulNbr < 4)\r
-          {\r
-          /***********************/\r
-          /* Test if SSI counter */\r
-          /***********************/\r
-\r
-          if ((devpriv->s_BoardInfos.\r
-               dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_SSI_COUNTER)\r
-             {\r
-             /*******************************/\r
-             /* Test the SSI profile length */\r
-             /*******************************/\r
-\r
-             // CG 22/03/00 b_SSIProfile >= 2 anstatt b_SSIProfile > 2\r
-             if (b_SSIProfile >= 2 && b_SSIProfile < 33)\r
-                {\r
-                /*************************************/\r
-                /* Test the SSI position data length */\r
-                /*************************************/\r
-\r
-                if (b_PositionTurnLength > 0 && b_PositionTurnLength < 32)\r
-                   {\r
-                   /*****************************************/\r
-                   /* Test the SSI turn counter data length */\r
-                   /*****************************************/\r
-\r
-                   if (b_TurnCptLength > 0 && b_TurnCptLength < 32)\r
-                      {\r
-                      /***************************/\r
-                      /* Test the profile length */\r
-                      /***************************/\r
-\r
-                      if ((b_TurnCptLength + b_PositionTurnLength) <= b_SSIProfile)\r
-                         {\r
-                         /****************************/\r
-                         /* Test the PCI input clock */\r
-                         /****************************/\r
-\r
-                         if (b_PCIInputClock == APCI1710_30MHZ || b_PCIInputClock == APCI1710_33MHZ)\r
-                            {\r
-                            /*************************/\r
-                            /* Test the output clock */\r
-                            /*************************/\r
-\r
-                            if ((b_PCIInputClock == APCI1710_30MHZ &&\r
-                                 (ul_SSIOutputClock > 228 && ul_SSIOutputClock <= 5000000UL)) ||\r
-                                (b_PCIInputClock == APCI1710_33MHZ &&\r
-                                 (ul_SSIOutputClock > 251 && ul_SSIOutputClock <= 5000000UL)))\r
-                               {\r
-                               if (b_SSICountingMode == APCI1710_BINARY_MODE ||\r
-                                   b_SSICountingMode == APCI1710_GRAY_MODE)\r
-                                  {\r
-                                  /**********************/\r
-                                  /* Save configuration */\r
-                                  /**********************/\r
-                                  devpriv->s_ModuleInfo [b_ModulNbr].\r
-                                  s_SSICounterInfo.\r
-                                  b_SSIProfile = b_SSIProfile;\r
-\r
-                                  \r
-                                  devpriv->s_ModuleInfo [b_ModulNbr].\r
-                                  s_SSICounterInfo.\r
-                                  b_PositionTurnLength = b_PositionTurnLength;\r
-\r
-                                  devpriv->s_ModuleInfo [b_ModulNbr].\r
-                                  s_SSICounterInfo.\r
-                                  b_TurnCptLength = b_TurnCptLength;\r
-\r
-                                  /*********************************/\r
-                                  /* Initialise the profile length */\r
-                                  /*********************************/\r
-\r
-                                  if (b_SSICountingMode == APCI1710_BINARY_MODE)\r
-                                     {\r
-                                   \r
-                                       outl(b_SSIProfile + 1,devpriv->s_BoardInfos.ui_Address + 4 + (64 * b_ModulNbr));\r
-                                     }\r
-                                  else\r
-                                     {\r
-                                               \r
-                                          outl(b_SSIProfile,devpriv->s_BoardInfos.ui_Address + 4 + (64 * b_ModulNbr));\r
-                                     }\r
-\r
-                                  /******************************/\r
-                                  /* Calculate the output clock */\r
-                                  /******************************/\r
-\r
-                                  ui_TimerValue = (UINT) (((ULONG) (b_PCIInputClock) * 500000UL) / ul_SSIOutputClock);\r
-\r
-                                  /************************/\r
-                                  /* Initialise the timer */\r
-                                  /************************/\r
-\r
-                                 \r
-                                   outl(ui_TimerValue,devpriv->s_BoardInfos.ui_Address + (64 * b_ModulNbr));\r
-\r
-\r
-                                  /********************************/\r
-                                  /* Initialise the counting mode */\r
-                                  /********************************/\r
-                                       \r
-                                       outl(7 * b_SSICountingMode,devpriv->s_BoardInfos.ui_Address + 12 + (64 * b_ModulNbr));\r
-                                  \r
-                                       devpriv->s_ModuleInfo [b_ModulNbr].s_SSICounterInfo.b_SSIInit = 1;\r
-                                  }\r
-                               else\r
-                                  {\r
-                                  /*****************************************************/\r
-                                  /* The selected SSI counting mode parameter is wrong */\r
-                                  /*****************************************************/\r
-\r
-                          DPRINTK("The selected SSI counting mode parameter is wrong\n");\r
-                                  i_ReturnValue = -9;\r
-                                  }\r
-                               }\r
-                            else\r
-                               {\r
-                               /******************************************/\r
-                               /* The selected SSI output clock is wrong */\r
-                               /******************************************/\r
-\r
-                               DPRINTK("The selected SSI output clock is wrong\n");\r
-                               i_ReturnValue = -8;\r
-                               }\r
-                            }\r
-                         else\r
-                            {\r
-                            /*****************************************/\r
-                            /* The selected PCI input clock is wrong */\r
-                            /*****************************************/\r
-\r
-                                DPRINTK("The selected PCI input clock is wrong\n");\r
-                            i_ReturnValue = -7;\r
-                            }\r
-                         }\r
-                      else\r
-                         {\r
-                         /********************************************/\r
-                         /* The selected SSI profile length is wrong */\r
-                         /********************************************/\r
-\r
-                         DPRINTK("The selected SSI profile length is wrong\n");        \r
-                         i_ReturnValue = -4;\r
-                         }\r
-                      }\r
-                   else\r
-                      {\r
-                      /******************************************************/\r
-                      /* The selected SSI turn counter data length is wrong */\r
-                      /******************************************************/\r
-\r
-                          DPRINTK("The selected SSI turn counter data length is wrong\n");     \r
-                      i_ReturnValue = -6;\r
-                      }\r
-                   }\r
-                else\r
-                   {\r
-                   /**************************************************/\r
-                   /* The selected SSI position data length is wrong */\r
-                   /**************************************************/\r
-\r
-                       DPRINTK("The selected SSI position data length is wrong\n");\r
-                   i_ReturnValue = -5;\r
-                   }\r
-                }\r
-             else\r
-                {\r
-                /********************************************/\r
-                /* The selected SSI profile length is wrong */\r
-                /********************************************/\r
-\r
-                DPRINTK("The selected SSI profile length is wrong\n");\r
-                i_ReturnValue = -4;\r
-                }\r
-             }\r
-          else\r
-             {\r
-             /**********************************/\r
-             /* The module is not a SSI module */\r
-             /**********************************/\r
-\r
-             DPRINTK("The module is not a SSI module\n");      \r
-             i_ReturnValue = -3;\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /***********************/\r
-          /* Module number error */\r
-          /***********************/\r
-\r
-          DPRINTK("Module number error\n");\r
-          i_ReturnValue = -2;\r
-          }\r
-\r
-       return (i_ReturnValue);\r
-       }\r
-\r
-\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : _INT_  i_APCI1710_Read1SSIValue                        |\r
-|                               (BYTE_     b_BoardHandle,                    |\r
-|                                BYTE_     b_ModulNbr,                       |\r
-|                                BYTE_     b_SelectedSSI,                    |\r
-|                                PULONG_ pul_Position,                       |\r
-|                                PULONG_ pul_TurnCpt) \r
- INT i_APCI1710_ReadSSIValue(comedi_device *dev,comedi_subdevice *s,\r
-       comedi_insn *insn,lsampl_t *data)                       |\r
-+----------------------------------------------------------------------------+\r
-| Task              :\r
-\r
-  \r
-                                               Read the selected SSI counter (b_SelectedSSI) from     |\r
-|                     selected module (b_ModulNbr).\r
-                                               or Read all SSI counter (b_SelectedSSI) from              |\r
-|                     selected module (b_ModulNbr).                            |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : BYTE_ b_BoardHandle         : Handle of board APCI-1710|\r
-|                     BYTE_ b_ModulNbr            : Module number to         |\r
-|                                                   configure (0 to 3)       |\r
-|                     BYTE_ b_SelectedSSI         : Selection from SSI       |\r
-|                                                   counter (0 to 2)    \r
-\r
-    b_ModulNbr         =   (BYTE) CR_AREF(insn->chanspec);\r
-       b_SelectedSSI   =       (BYTE) CR_CHAN(insn->chanspec); (in case of single ssi)\r
-       b_ReadType              =       (BYTE) CR_RANGE(insn->chanspec);\r
-|\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : PULONG_  pul_Position       : SSI position in the turn |\r
-|                     PULONG_  pul_TurnCpt        : Number of turns \r
-\r
-pul_Position   =       (PULONG) &data[0];\r
-       pul_TurnCpt             =       (PULONG) &data[1];         |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      : 0: No error                                            |\r
-|                    -1: The handle parameter of the board is wrong          |\r
-|                    -2: The module parameter is wrong                       |\r
-|                    -3: The module is not a SSI module                      |\r
-|                    -4: SSI not initialised see function                    |\r
-|                        "i_APCI1710_InitSSI"                                |\r
-|                    -5: The selected SSI is wrong                           |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-   INT i_APCI1710_InsnReadSSIValue(comedi_device *dev,comedi_subdevice *s,\r
-       comedi_insn *insn,lsampl_t *data)\r
-       {\r
-       INT    i_ReturnValue = 0;\r
-       BYTE   b_Cpt;\r
-       BYTE   b_Length;\r
-       BYTE   b_Schift;\r
-       BYTE   b_SSICpt;\r
-       DWORD dw_And;\r
-       DWORD dw_And1;\r
-       DWORD dw_And2;\r
-       DWORD dw_StatusReg;\r
-       DWORD dw_CounterValue;\r
-       BYTE  b_ModulNbr;\r
-       BYTE  b_SelectedSSI;\r
-       BYTE  b_ReadType;\r
-       PULONG pul_Position;\r
-       PULONG pul_TurnCpt;\r
-       PULONG pul_Position1;\r
-       PULONG pul_TurnCpt1;\r
-\r
-\r
-       i_ReturnValue   =       insn->n;         \r
-       pul_Position1   =       (PULONG) &data[0];\r
-// For Read1\r
-       pul_TurnCpt1    =       (PULONG) &data[1];\r
-// For Read all\r
-               pul_Position    =       (PULONG) &data[0];//0-2\r
-       pul_TurnCpt     =       (PULONG) &data[3];//3-5\r
-       b_ModulNbr              =   (BYTE) CR_AREF(insn->chanspec);\r
-       b_SelectedSSI   =       (BYTE) CR_CHAN(insn->chanspec);\r
-       b_ReadType              =       (BYTE) CR_RANGE(insn->chanspec);\r
-\r
-       /**************************/\r
-       /* Test the module number */\r
-       /**************************/\r
-\r
-       if (b_ModulNbr < 4)\r
-          {\r
-          /***********************/\r
-          /* Test if SSI counter */\r
-          /***********************/\r
-\r
-          if ((devpriv->s_BoardInfos.\r
-               dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_SSI_COUNTER)\r
-             {\r
-             /***************************/\r
-             /* Test if SSI initialised */\r
-             /***************************/\r
-\r
-             if (devpriv->s_ModuleInfo [b_ModulNbr].\r
-                 s_SSICounterInfo.\r
-                 b_SSIInit == 1)\r
-                {\r
-          \r
-                       switch(b_ReadType)\r
-                       {\r
-\r
-                       case APCI1710_SSI_READ1VALUE :\r
-                /****************************************/\r
-                /* Test the selected SSI counter number */\r
-                /****************************************/\r
-\r
-                if (b_SelectedSSI < 3)\r
-                   {\r
-                   /************************/\r
-                   /* Start the conversion */\r
-                   /************************/\r
-\r
-\r
-                       outl(0,devpriv->s_BoardInfos.ui_Address + 8 + (64 * b_ModulNbr));\r
-                       \r
-\r
-                   do\r
-                      {\r
-                      /*******************/\r
-                      /* Read the status */\r
-                      /*******************/\r
-                               \r
-                               dw_StatusReg = inl(devpriv->s_BoardInfos.ui_Address + (64 * b_ModulNbr));\r
-                      }\r
-                   while ((dw_StatusReg & 0x1) != 0);\r
-\r
-                   /******************************/\r
-                   /* Read the SSI counter value */\r
-                   /******************************/\r
-               \r
-                       dw_CounterValue = inl(devpriv->s_BoardInfos.ui_Address + 4 + (b_SelectedSSI * 4) + (64 * b_ModulNbr));\r
-\r
-                   b_Length = devpriv->s_ModuleInfo [b_ModulNbr].s_SSICounterInfo.b_SSIProfile / 2;\r
-\r
-                   if ((b_Length * 2) != devpriv->s_ModuleInfo [b_ModulNbr].s_SSICounterInfo.b_SSIProfile)\r
-                      {\r
-                      b_Length ++;\r
-                      }\r
-\r
-                   b_Schift = b_Length - devpriv->s_ModuleInfo [b_ModulNbr].\r
-                                         s_SSICounterInfo.\r
-                                         b_PositionTurnLength;\r
-\r
-\r
-                   *pul_Position1 = dw_CounterValue >> b_Schift;\r
-\r
-                   dw_And = 1;\r
-\r
-                   for (b_Cpt = 0; b_Cpt < devpriv->s_ModuleInfo [b_ModulNbr].\r
-                                           s_SSICounterInfo.\r
-                                           b_PositionTurnLength; b_Cpt ++)\r
-                      {\r
-                      dw_And = dw_And * 2;\r
-                      }\r
-\r
-                   *pul_Position1 = *pul_Position1 & ((dw_And) - 1);\r
-\r
-                   *pul_TurnCpt1 = dw_CounterValue >> b_Length;\r
-\r
-                   dw_And = 1;\r
-\r
-                   for (b_Cpt = 0; b_Cpt < devpriv->s_ModuleInfo [b_ModulNbr].\r
-                                           s_SSICounterInfo.\r
-                                           b_TurnCptLength; b_Cpt ++)\r
-                      {\r
-                      dw_And = dw_And * 2;\r
-                      }\r
-\r
-                   *pul_TurnCpt1 = *pul_TurnCpt1 & ((dw_And) - 1);\r
-                   }\r
-                else\r
-                   {\r
-                   /*****************************/\r
-                   /* The selected SSI is wrong */\r
-                   /*****************************/\r
-\r
-                   DPRINTK("The selected SSI is wrong\n");\r
-                   i_ReturnValue = -5;\r
-                   }\r
-               break;\r
-\r
-                case APCI1710_SSI_READALLVALUE :\r
-                        dw_And1 = 1;\r
-\r
-                for (b_Cpt = 0; b_Cpt < devpriv->s_ModuleInfo [b_ModulNbr].\r
-                                        s_SSICounterInfo.\r
-                                        b_PositionTurnLength; b_Cpt ++)\r
-                   {\r
-                   dw_And1 = dw_And1 * 2;\r
-                   }\r
-\r
-                dw_And2 = 1;\r
-\r
-                for (b_Cpt = 0; b_Cpt < devpriv->s_ModuleInfo [b_ModulNbr].\r
-                                        s_SSICounterInfo.\r
-                                        b_TurnCptLength; b_Cpt ++)\r
-                   {\r
-                   dw_And2 = dw_And2 * 2;\r
-                   }\r
-\r
-                /************************/\r
-                /* Start the conversion */\r
-                /************************/\r
-               \r
-                outl(0,devpriv->s_BoardInfos.ui_Address + 8 + (64 * b_ModulNbr));\r
-\r
-                do\r
-                   {\r
-                   /*******************/\r
-                   /* Read the status */\r
-                   /*******************/\r
-                       \r
-                       dw_StatusReg = inl(devpriv->s_BoardInfos.ui_Address + (64 * b_ModulNbr));\r
-                   }\r
-                while ((dw_StatusReg & 0x1) != 0);\r
-\r
-                for (b_SSICpt = 0; b_SSICpt < 3; b_SSICpt ++)\r
-                   {\r
-                   /******************************/\r
-                   /* Read the SSI counter value */\r
-                   /******************************/\r
-\r
-                 \r
-                        dw_CounterValue = inl(devpriv->s_BoardInfos.ui_Address + 4 + (b_SSICpt * 4) + (64 * b_ModulNbr));\r
-\r
-                   b_Length = devpriv->s_ModuleInfo [b_ModulNbr].\r
-                              s_SSICounterInfo.\r
-                              b_SSIProfile / 2;\r
-\r
-                   if ((b_Length * 2) != devpriv->s_ModuleInfo [b_ModulNbr].\r
-                                         s_SSICounterInfo.\r
-                                         b_SSIProfile)\r
-                      {\r
-                      b_Length ++;\r
-                      }\r
-\r
-                   b_Schift = b_Length - devpriv->s_ModuleInfo [b_ModulNbr].\r
-                                         s_SSICounterInfo.\r
-                                         b_PositionTurnLength;\r
-\r
-\r
-                   pul_Position [b_SSICpt] = dw_CounterValue >> b_Schift;\r
-                   pul_Position [b_SSICpt] = pul_Position [b_SSICpt] & ((dw_And1) - 1);\r
-\r
-                   pul_TurnCpt [b_SSICpt] = dw_CounterValue >> b_Length;\r
-                   pul_TurnCpt [b_SSICpt] = pul_TurnCpt [b_SSICpt] & ((dw_And2) - 1);\r
-                   }\r
-                break;\r
-\r
-                default :\r
-                        printk("Read Type Inputs Wrong\n");\r
-\r
-                } // switch  ending\r
-\r
-                }\r
-             else\r
-                {\r
-                /***********************/\r
-                /* SSI not initialised */\r
-                /***********************/\r
-\r
-                DPRINTK("SSI not initialised\n");\r
-                i_ReturnValue = -4;\r
-                }\r
-             }\r
-          else\r
-             {\r
-             /**********************************/\r
-             /* The module is not a SSI module */\r
-             /**********************************/\r
-\r
-             DPRINTK("The module is not a SSI module\n");\r
-             i_ReturnValue = -3;\r
\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /***********************/\r
-          /* Module number error */\r
-          /***********************/\r
-\r
-          DPRINTK("Module number error\n");    \r
-          i_ReturnValue = -2;\r
-          }\r
-\r
-       return (i_ReturnValue);\r
-       }\r
-\r
-\r
-\r
-\r
-\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : _INT_   i_APCI1710_ReadSSI1DigitalInput                |\r
-|                                       (BYTE_     b_BoardHandle,            |\r
-|                                        BYTE_     b_ModulNbr,               |\r
-|                                        BYTE_     b_InputChannel,           |\r
-|                                        PBYTE_   pb_ChannelStatus)          |\r
-+----------------------------------------------------------------------------+\r
-| Task              :\r
-                                       (0) Set the digital output from selected SSI moule         |\r
-|                     (b_ModuleNbr) ON\r
-                    (1) Set the digital output from selected SSI moule         |\r
-|                     (b_ModuleNbr) OFF        \r
-                                       (2)Read the status from selected SSI digital input        |\r
-|                     (b_InputChannel)  \r
-                    (3)Read the status from all SSI digital inputs from       |\r
-|                     selected SSI module (b_ModulNbr)                   |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : BYTE_ b_BoardHandle         : Handle of board APCI-1710|\r
-|                     BYTE_ b_ModulNbr    CR_AREF        : Module number to         |\r
-|                                                   configure (0 to 3)       |\r
-|                     BYTE_ b_InputChannel CR_CHAN       : Selection from digital   |\r
-|                        data[0] which IOTYPE                           input ( 0 to 2)          |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : PBYTE_  pb_ChannelStatus    : Digital input channel    |\r
-|                                 data[0]                  status                   |\r
-|                                                   0 : Channle is not active|\r
-|                                                   1 : Channle is active    |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      : 0: No error                                            |\r
-|                    -1: The handle parameter of the board is wrong          |\r
-|                    -2: The module parameter is wrong                       |\r
-|                    -3: The module is not a SSI module                      |\r
-|                    -4: The selected SSI digital input is wrong             |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-\r
-\r
-INT    i_APCI1710_InsnBitsSSIDigitalIO(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,\r
-lsampl_t *data)\r
-       {\r
-       INT     i_ReturnValue = 0;\r
-       DWORD   dw_StatusReg;\r
-       BYTE    b_ModulNbr;\r
-       BYTE    b_InputChannel;\r
-       PBYTE   pb_ChannelStatus;\r
-        PBYTE   pb_InputStatus;\r
-       BYTE    b_IOType;\r
-       i_ReturnValue = insn->n;\r
-        b_ModulNbr    = (BYTE) CR_AREF(insn->chanspec);\r
-        b_IOType      = (BYTE) data[0];\r
-       \r
-       /**************************/\r
-       /* Test the module number */\r
-       /**************************/\r
-\r
-       if (b_ModulNbr < 4)\r
-          {\r
-          /***********************/\r
-          /* Test if SSI counter */\r
-          /***********************/\r
-\r
-          if ((devpriv->s_BoardInfos.\r
-               dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_SSI_COUNTER)\r
-             {\r
-           switch(b_IOType)\r
-                  {\r
-                  case    APCI1710_SSI_SET_CHANNELON :\r
-                                       /*****************************/\r
-                                       /* Set the digital output ON */\r
-                                       /*****************************/\r
-\r
-                                       \r
-                   outl(1,devpriv->s_BoardInfos.ui_Address + 16 + (64 * b_ModulNbr));\r
-                              break ;\r
-\r
-                  case    APCI1710_SSI_SET_CHANNELOFF :\r
-                                       /******************************/\r
-                                       /* Set the digital output OFF */\r
-                                       /******************************/\r
-\r
-                               \r
-                                  outl(0,devpriv->s_BoardInfos.ui_Address + 16 + (64 * b_ModulNbr));\r
-                              break ;\r
-                  \r
-               \r
-\r
-                  case APCI1710_SSI_READ_1CHANNEL:\r
-                                  /******************************************/\r
-                                  /* Test the digital imnput channel number */\r
-                                  /******************************************/\r
-\r
-                                       b_InputChannel = (BYTE) CR_CHAN(insn->chanspec);\r
-                                       pb_ChannelStatus = (PBYTE) &data[0];\r
-\r
-                                       if (b_InputChannel <= 2)\r
-                                       {\r
-                                       /**************************/\r
-                                       /* Read all digital input */\r
-                                       /**************************/\r
-       \r
-                                       \r
-                                       dw_StatusReg = inl(devpriv->s_BoardInfos.ui_Address + (64 * b_ModulNbr));\r
-                                       *pb_ChannelStatus = (BYTE) (((~dw_StatusReg) >> (4 + b_InputChannel)) & 1);\r
-                                       }\r
-                                       else\r
-                                       {\r
-                                       /********************************/\r
-                                       /* Selected digital input error */\r
-                                       /********************************/\r
-\r
-                           DPRINTK("Selected digital input error\n");\r
-                                       i_ReturnValue = -4;\r
-                                       }\r
-                                       break;\r
-\r
-                       case APCI1710_SSI_READ_ALLCHANNEL:\r
-                                       /**************************/\r
-                                       /* Read all digital input */\r
-                                       /**************************/\r
-                                       pb_InputStatus = (PBYTE) &data[0];\r
-\r
-                               \r
-                                       dw_StatusReg      = inl(devpriv->s_BoardInfos.ui_Address + (64 * b_ModulNbr));\r
-                                       *pb_InputStatus = (BYTE) (((~dw_StatusReg) >> 4) & 7);\r
-                                       break;\r
-\r
-                       default :\r
-                                       printk("IO type wrong\n");\r
-\r
-                } //switch end\r
-             }\r
-          else\r
-             {\r
-             /**********************************/\r
-             /* The module is not a SSI module */\r
-             /**********************************/\r
-\r
-             DPRINTK("The module is not a SSI module\n");      \r
-             i_ReturnValue = -3;\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /***********************/\r
-          /* Module number error */\r
-          /***********************/\r
-\r
-          DPRINTK("Module number error\n");\r
-          i_ReturnValue = -2;\r
-          }\r
-\r
-       return (i_ReturnValue);\r
-       }\r
+/**
+@verbatim
+
+Copyright (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 USA
+
+You 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 : SSI.C           | Version  : 2.96                       |
+  +-------------------------------+---------------------------------------+
+  | Project manager: Eric Stolz   | Date     :  02/12/2002                |
+  +-----------------------------------------------------------------------+
+  | Description :   APCI-1710 SSI counter module                          |
+  |                                                                       |
+  |                                                                       |
+  +-----------------------------------------------------------------------+
+  |                             UPDATES                                   |
+  +-----------------------------------------------------------------------+
+  |   Date   |   Author  |          Description of updates                |
+  +----------+-----------+------------------------------------------------+
+  | 13/05/98 | S. Weber  | SSI digital input / output implementation      |
+  |----------|-----------|------------------------------------------------|
+  | 22/03/00 | C.Guinot  | 0100/0226 -> 0200/0227                         |
+  |          |           | Änderung in InitSSI Funktion                   |
+  |          |           | b_SSIProfile >= 2 anstatt b_SSIProfile > 2     |
+  |          |           |                                                |
+  +-----------------------------------------------------------------------+
+  | 08/05/00 | Guinot C  | - 0400/0228 All Function in RING 0             |
+  |          |           |   available                                    |
+  +-----------------------------------------------------------------------+
+*/
+
+/*
++----------------------------------------------------------------------------+
+|                               Included files                               |
++----------------------------------------------------------------------------+
+*/
+
+
+#include "APCI1710_Ssi.h"
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     : _INT_ i_APCI1710_InitSSI                               |
+|                               (BYTE_    b_BoardHandle,                     |
+|                                BYTE_    b_ModulNbr,                        |
+|                                BYTE_    b_SSIProfile,                      |
+|                                BYTE_    b_PositionTurnLength,              |
+|                                BYTE_    b_TurnCptLength,                   |
+|                                BYTE_    b_PCIInputClock,                   |
+|                                ULONG_  ul_SSIOutputClock,                  |
+|                                BYTE_    b_SSICountingMode)                 |
++----------------------------------------------------------------------------+
+| Task              : Configure the SSI operating mode from selected module  |
+|                     (b_ModulNbr). You must calling this function be for you|
+|                     call any other function witch access of SSI.           |
++----------------------------------------------------------------------------+
+| Input Parameters  : BYTE_ b_BoardHandle         : Handle of board APCI-1710|
+|                     BYTE_ b_ModulNbr            : Module number to         |
+|                                                   configure (0 to 3)       |
+|                     BYTE_  b_SSIProfile         : Selection from SSI       |
+|                                                   profile length (2 to 32).|
+|                     BYTE_  b_PositionTurnLength : Selection from SSI       |
+|                                                   position data length     |
+|                                                   (1 to 31).               |
+|                     BYTE_  b_TurnCptLength      : Selection from SSI turn  |
+|                                                   counter data length      |
+|                                                   (1 to 31).               |
+|                     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        |
+|                     ULONG_ ul_SSIOutputClock    : Selection from SSI output|
+|                                                   clock.                   |
+|                                                   From  229 to 5 000 000 Hz|
+|                                                   for 30 MHz selection.    |
+|                                                   From  252 to 5 000 000 Hz|
+|                                                   for 33 MHz selection.    |
+|                     BYTE   b_SSICountingMode    : SSI counting mode        |
+|                                                   selection                |
+|                                                 - APCI1710_BINARY_MODE :   |
+|                                                    Binary counting mode.   |
+|                                                 - APCI1710_GRAY_MODE :     |
+|                                                    Gray counting mode.
+
+       b_ModulNbr                      = CR_AREF(insn->chanspec);
+       b_SSIProfile            = (BYTE) data[0];  
+       b_PositionTurnLength= (BYTE) data[1];  
+       b_TurnCptLength         = (BYTE) data[2];
+       b_PCIInputClock         = (BYTE) data[3];
+       ul_SSIOutputClock       = (ULONG) data[4];
+       b_SSICountingMode       = (BYTE)  data[5];     |
++----------------------------------------------------------------------------+
+| Output Parameters : -                                                      |
++----------------------------------------------------------------------------+
+| Return Value      : 0: No error                                            |
+|                    -1: The handle parameter of the board is wrong          |
+|                    -2: The module parameter is wrong                       |
+|                    -3: The module is not a SSI module                      |
+|                    -4: The selected SSI profile length is wrong            |
+|                    -5: The selected SSI position data length is wrong      |
+|                    -6: The selected SSI turn counter data length is wrong  |
+|                    -7: The selected PCI input clock is wrong               |
+|                    -8: The selected SSI output clock is wrong              |
+|                    -9: The selected SSI counting mode parameter is wrong   |
++----------------------------------------------------------------------------+
+*/
+
+
+INT   i_APCI1710_InsnConfigInitSSI(comedi_device *dev,comedi_subdevice *s,
+       comedi_insn *insn,lsampl_t *data)
+       {
+       INT    i_ReturnValue = 0;
+       UINT   ui_TimerValue;
+       BYTE   b_ModulNbr,b_SSIProfile,b_PositionTurnLength,b_TurnCptLength,b_PCIInputClock,b_SSICountingMode;
+       ULONG  ul_SSIOutputClock;
+                       
+       b_ModulNbr                      = CR_AREF(insn->chanspec);
+       b_SSIProfile            = (BYTE) data[0];  
+       b_PositionTurnLength= (BYTE) data[1];  
+       b_TurnCptLength         = (BYTE) data[2];
+       b_PCIInputClock         = (BYTE) data[3];
+       ul_SSIOutputClock       = (ULONG) data[4];
+       b_SSICountingMode       = (BYTE)  data[5];
+
+       i_ReturnValue           = insn->n;
+       /**************************/
+       /* Test the module number */
+       /**************************/
+
+       if (b_ModulNbr < 4)
+          {
+          /***********************/
+          /* Test if SSI counter */
+          /***********************/
+
+          if ((devpriv->s_BoardInfos.
+               dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_SSI_COUNTER)
+             {
+             /*******************************/
+             /* Test the SSI profile length */
+             /*******************************/
+
+             // CG 22/03/00 b_SSIProfile >= 2 anstatt b_SSIProfile > 2
+             if (b_SSIProfile >= 2 && b_SSIProfile < 33)
+                {
+                /*************************************/
+                /* Test the SSI position data length */
+                /*************************************/
+
+                if (b_PositionTurnLength > 0 && b_PositionTurnLength < 32)
+                   {
+                   /*****************************************/
+                   /* Test the SSI turn counter data length */
+                   /*****************************************/
+
+                   if (b_TurnCptLength > 0 && b_TurnCptLength < 32)
+                      {
+                      /***************************/
+                      /* Test the profile length */
+                      /***************************/
+
+                      if ((b_TurnCptLength + b_PositionTurnLength) <= b_SSIProfile)
+                         {
+                         /****************************/
+                         /* Test the PCI input clock */
+                         /****************************/
+
+                         if (b_PCIInputClock == APCI1710_30MHZ || b_PCIInputClock == APCI1710_33MHZ)
+                            {
+                            /*************************/
+                            /* Test the output clock */
+                            /*************************/
+
+                            if ((b_PCIInputClock == APCI1710_30MHZ &&
+                                 (ul_SSIOutputClock > 228 && ul_SSIOutputClock <= 5000000UL)) ||
+                                (b_PCIInputClock == APCI1710_33MHZ &&
+                                 (ul_SSIOutputClock > 251 && ul_SSIOutputClock <= 5000000UL)))
+                               {
+                               if (b_SSICountingMode == APCI1710_BINARY_MODE ||
+                                   b_SSICountingMode == APCI1710_GRAY_MODE)
+                                  {
+                                  /**********************/
+                                  /* Save configuration */
+                                  /**********************/
+                                  devpriv->s_ModuleInfo [b_ModulNbr].
+                                  s_SSICounterInfo.
+                                  b_SSIProfile = b_SSIProfile;
+
+                                  
+                                  devpriv->s_ModuleInfo [b_ModulNbr].
+                                  s_SSICounterInfo.
+                                  b_PositionTurnLength = b_PositionTurnLength;
+
+                                  devpriv->s_ModuleInfo [b_ModulNbr].
+                                  s_SSICounterInfo.
+                                  b_TurnCptLength = b_TurnCptLength;
+
+                                  /*********************************/
+                                  /* Initialise the profile length */
+                                  /*********************************/
+
+                                  if (b_SSICountingMode == APCI1710_BINARY_MODE)
+                                     {
+                                   
+                                       outl(b_SSIProfile + 1,devpriv->s_BoardInfos.ui_Address + 4 + (64 * b_ModulNbr));
+                                     }
+                                  else
+                                     {
+                                               
+                                          outl(b_SSIProfile,devpriv->s_BoardInfos.ui_Address + 4 + (64 * b_ModulNbr));
+                                     }
+
+                                  /******************************/
+                                  /* Calculate the output clock */
+                                  /******************************/
+
+                                  ui_TimerValue = (UINT) (((ULONG) (b_PCIInputClock) * 500000UL) / ul_SSIOutputClock);
+
+                                  /************************/
+                                  /* Initialise the timer */
+                                  /************************/
+
+                                 
+                                   outl(ui_TimerValue,devpriv->s_BoardInfos.ui_Address + (64 * b_ModulNbr));
+
+
+                                  /********************************/
+                                  /* Initialise the counting mode */
+                                  /********************************/
+                                       
+                                       outl(7 * b_SSICountingMode,devpriv->s_BoardInfos.ui_Address + 12 + (64 * b_ModulNbr));
+                                  
+                                       devpriv->s_ModuleInfo [b_ModulNbr].s_SSICounterInfo.b_SSIInit = 1;
+                                  }
+                               else
+                                  {
+                                  /*****************************************************/
+                                  /* The selected SSI counting mode parameter is wrong */
+                                  /*****************************************************/
+
+                          DPRINTK("The selected SSI counting mode parameter is wrong\n");
+                                  i_ReturnValue = -9;
+                                  }
+                               }
+                            else
+                               {
+                               /******************************************/
+                               /* The selected SSI output clock is wrong */
+                               /******************************************/
+
+                               DPRINTK("The selected SSI output clock is wrong\n");
+                               i_ReturnValue = -8;
+                               }
+                            }
+                         else
+                            {
+                            /*****************************************/
+                            /* The selected PCI input clock is wrong */
+                            /*****************************************/
+
+                                DPRINTK("The selected PCI input clock is wrong\n");
+                            i_ReturnValue = -7;
+                            }
+                         }
+                      else
+                         {
+                         /********************************************/
+                         /* The selected SSI profile length is wrong */
+                         /********************************************/
+
+                         DPRINTK("The selected SSI profile length is wrong\n");        
+                         i_ReturnValue = -4;
+                         }
+                      }
+                   else
+                      {
+                      /******************************************************/
+                      /* The selected SSI turn counter data length is wrong */
+                      /******************************************************/
+
+                          DPRINTK("The selected SSI turn counter data length is wrong\n");     
+                      i_ReturnValue = -6;
+                      }
+                   }
+                else
+                   {
+                   /**************************************************/
+                   /* The selected SSI position data length is wrong */
+                   /**************************************************/
+
+                       DPRINTK("The selected SSI position data length is wrong\n");
+                   i_ReturnValue = -5;
+                   }
+                }
+             else
+                {
+                /********************************************/
+                /* The selected SSI profile length is wrong */
+                /********************************************/
+
+                DPRINTK("The selected SSI profile length is wrong\n");
+                i_ReturnValue = -4;
+                }
+             }
+          else
+             {
+             /**********************************/
+             /* The module is not a SSI module */
+             /**********************************/
+
+             DPRINTK("The module is not a SSI module\n");      
+             i_ReturnValue = -3;
+             }
+          }
+       else
+          {
+          /***********************/
+          /* Module number error */
+          /***********************/
+
+          DPRINTK("Module number error\n");
+          i_ReturnValue = -2;
+          }
+
+       return (i_ReturnValue);
+       }
+
+
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     : _INT_  i_APCI1710_Read1SSIValue                        |
+|                               (BYTE_     b_BoardHandle,                    |
+|                                BYTE_     b_ModulNbr,                       |
+|                                BYTE_     b_SelectedSSI,                    |
+|                                PULONG_ pul_Position,                       |
+|                                PULONG_ pul_TurnCpt) 
+ INT i_APCI1710_ReadSSIValue(comedi_device *dev,comedi_subdevice *s,
+       comedi_insn *insn,lsampl_t *data)                       |
++----------------------------------------------------------------------------+
+| Task              :
+
+  
+                                               Read the selected SSI counter (b_SelectedSSI) from     |
+|                     selected module (b_ModulNbr).
+                                               or Read all SSI counter (b_SelectedSSI) from              |
+|                     selected module (b_ModulNbr).                            |
++----------------------------------------------------------------------------+
+| Input Parameters  : BYTE_ b_BoardHandle         : Handle of board APCI-1710|
+|                     BYTE_ b_ModulNbr            : Module number to         |
+|                                                   configure (0 to 3)       |
+|                     BYTE_ b_SelectedSSI         : Selection from SSI       |
+|                                                   counter (0 to 2)    
+
+    b_ModulNbr         =   (BYTE) CR_AREF(insn->chanspec);
+       b_SelectedSSI   =       (BYTE) CR_CHAN(insn->chanspec); (in case of single ssi)
+       b_ReadType              =       (BYTE) CR_RANGE(insn->chanspec);
+|
++----------------------------------------------------------------------------+
+| Output Parameters : PULONG_  pul_Position       : SSI position in the turn |
+|                     PULONG_  pul_TurnCpt        : Number of turns 
+
+pul_Position   =       (PULONG) &data[0];
+       pul_TurnCpt             =       (PULONG) &data[1];         |
++----------------------------------------------------------------------------+
+| Return Value      : 0: No error                                            |
+|                    -1: The handle parameter of the board is wrong          |
+|                    -2: The module parameter is wrong                       |
+|                    -3: The module is not a SSI module                      |
+|                    -4: SSI not initialised see function                    |
+|                        "i_APCI1710_InitSSI"                                |
+|                    -5: The selected SSI is wrong                           |
++----------------------------------------------------------------------------+
+*/
+
+   INT i_APCI1710_InsnReadSSIValue(comedi_device *dev,comedi_subdevice *s,
+       comedi_insn *insn,lsampl_t *data)
+       {
+       INT    i_ReturnValue = 0;
+       BYTE   b_Cpt;
+       BYTE   b_Length;
+       BYTE   b_Schift;
+       BYTE   b_SSICpt;
+       DWORD dw_And;
+       DWORD dw_And1;
+       DWORD dw_And2;
+       DWORD dw_StatusReg;
+       DWORD dw_CounterValue;
+       BYTE  b_ModulNbr;
+       BYTE  b_SelectedSSI;
+       BYTE  b_ReadType;
+       PULONG pul_Position;
+       PULONG pul_TurnCpt;
+       PULONG pul_Position1;
+       PULONG pul_TurnCpt1;
+
+
+       i_ReturnValue   =       insn->n;         
+       pul_Position1   =       (PULONG) &data[0];
+// For Read1
+       pul_TurnCpt1    =       (PULONG) &data[1];
+// For Read all
+               pul_Position    =       (PULONG) &data[0];//0-2
+       pul_TurnCpt     =       (PULONG) &data[3];//3-5
+       b_ModulNbr              =   (BYTE) CR_AREF(insn->chanspec);
+       b_SelectedSSI   =       (BYTE) CR_CHAN(insn->chanspec);
+       b_ReadType              =       (BYTE) CR_RANGE(insn->chanspec);
+
+       /**************************/
+       /* Test the module number */
+       /**************************/
+
+       if (b_ModulNbr < 4)
+          {
+          /***********************/
+          /* Test if SSI counter */
+          /***********************/
+
+          if ((devpriv->s_BoardInfos.
+               dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_SSI_COUNTER)
+             {
+             /***************************/
+             /* Test if SSI initialised */
+             /***************************/
+
+             if (devpriv->s_ModuleInfo [b_ModulNbr].
+                 s_SSICounterInfo.
+                 b_SSIInit == 1)
+                {
+          
+                       switch(b_ReadType)
+                       {
+
+                       case APCI1710_SSI_READ1VALUE :
+                /****************************************/
+                /* Test the selected SSI counter number */
+                /****************************************/
+
+                if (b_SelectedSSI < 3)
+                   {
+                   /************************/
+                   /* Start the conversion */
+                   /************************/
+
+
+                       outl(0,devpriv->s_BoardInfos.ui_Address + 8 + (64 * b_ModulNbr));
+                       
+
+                   do
+                      {
+                      /*******************/
+                      /* Read the status */
+                      /*******************/
+                               
+                               dw_StatusReg = inl(devpriv->s_BoardInfos.ui_Address + (64 * b_ModulNbr));
+                      }
+                   while ((dw_StatusReg & 0x1) != 0);
+
+                   /******************************/
+                   /* Read the SSI counter value */
+                   /******************************/
+               
+                       dw_CounterValue = inl(devpriv->s_BoardInfos.ui_Address + 4 + (b_SelectedSSI * 4) + (64 * b_ModulNbr));
+
+                   b_Length = devpriv->s_ModuleInfo [b_ModulNbr].s_SSICounterInfo.b_SSIProfile / 2;
+
+                   if ((b_Length * 2) != devpriv->s_ModuleInfo [b_ModulNbr].s_SSICounterInfo.b_SSIProfile)
+                      {
+                      b_Length ++;
+                      }
+
+                   b_Schift = b_Length - devpriv->s_ModuleInfo [b_ModulNbr].
+                                         s_SSICounterInfo.
+                                         b_PositionTurnLength;
+
+
+                   *pul_Position1 = dw_CounterValue >> b_Schift;
+
+                   dw_And = 1;
+
+                   for (b_Cpt = 0; b_Cpt < devpriv->s_ModuleInfo [b_ModulNbr].
+                                           s_SSICounterInfo.
+                                           b_PositionTurnLength; b_Cpt ++)
+                      {
+                      dw_And = dw_And * 2;
+                      }
+
+                   *pul_Position1 = *pul_Position1 & ((dw_And) - 1);
+
+                   *pul_TurnCpt1 = dw_CounterValue >> b_Length;
+
+                   dw_And = 1;
+
+                   for (b_Cpt = 0; b_Cpt < devpriv->s_ModuleInfo [b_ModulNbr].
+                                           s_SSICounterInfo.
+                                           b_TurnCptLength; b_Cpt ++)
+                      {
+                      dw_And = dw_And * 2;
+                      }
+
+                   *pul_TurnCpt1 = *pul_TurnCpt1 & ((dw_And) - 1);
+                   }
+                else
+                   {
+                   /*****************************/
+                   /* The selected SSI is wrong */
+                   /*****************************/
+
+                   DPRINTK("The selected SSI is wrong\n");
+                   i_ReturnValue = -5;
+                   }
+               break;
+
+                case APCI1710_SSI_READALLVALUE :
+                        dw_And1 = 1;
+
+                for (b_Cpt = 0; b_Cpt < devpriv->s_ModuleInfo [b_ModulNbr].
+                                        s_SSICounterInfo.
+                                        b_PositionTurnLength; b_Cpt ++)
+                   {
+                   dw_And1 = dw_And1 * 2;
+                   }
+
+                dw_And2 = 1;
+
+                for (b_Cpt = 0; b_Cpt < devpriv->s_ModuleInfo [b_ModulNbr].
+                                        s_SSICounterInfo.
+                                        b_TurnCptLength; b_Cpt ++)
+                   {
+                   dw_And2 = dw_And2 * 2;
+                   }
+
+                /************************/
+                /* Start the conversion */
+                /************************/
+               
+                outl(0,devpriv->s_BoardInfos.ui_Address + 8 + (64 * b_ModulNbr));
+
+                do
+                   {
+                   /*******************/
+                   /* Read the status */
+                   /*******************/
+                       
+                       dw_StatusReg = inl(devpriv->s_BoardInfos.ui_Address + (64 * b_ModulNbr));
+                   }
+                while ((dw_StatusReg & 0x1) != 0);
+
+                for (b_SSICpt = 0; b_SSICpt < 3; b_SSICpt ++)
+                   {
+                   /******************************/
+                   /* Read the SSI counter value */
+                   /******************************/
+
+                 
+                        dw_CounterValue = inl(devpriv->s_BoardInfos.ui_Address + 4 + (b_SSICpt * 4) + (64 * b_ModulNbr));
+
+                   b_Length = devpriv->s_ModuleInfo [b_ModulNbr].
+                              s_SSICounterInfo.
+                              b_SSIProfile / 2;
+
+                   if ((b_Length * 2) != devpriv->s_ModuleInfo [b_ModulNbr].
+                                         s_SSICounterInfo.
+                                         b_SSIProfile)
+                      {
+                      b_Length ++;
+                      }
+
+                   b_Schift = b_Length - devpriv->s_ModuleInfo [b_ModulNbr].
+                                         s_SSICounterInfo.
+                                         b_PositionTurnLength;
+
+
+                   pul_Position [b_SSICpt] = dw_CounterValue >> b_Schift;
+                   pul_Position [b_SSICpt] = pul_Position [b_SSICpt] & ((dw_And1) - 1);
+
+                   pul_TurnCpt [b_SSICpt] = dw_CounterValue >> b_Length;
+                   pul_TurnCpt [b_SSICpt] = pul_TurnCpt [b_SSICpt] & ((dw_And2) - 1);
+                   }
+                break;
+
+                default :
+                        printk("Read Type Inputs Wrong\n");
+
+                } // switch  ending
+
+                }
+             else
+                {
+                /***********************/
+                /* SSI not initialised */
+                /***********************/
+
+                DPRINTK("SSI not initialised\n");
+                i_ReturnValue = -4;
+                }
+             }
+          else
+             {
+             /**********************************/
+             /* The module is not a SSI module */
+             /**********************************/
+
+             DPRINTK("The module is not a SSI module\n");
+             i_ReturnValue = -3;
+             }
+          }
+       else
+          {
+          /***********************/
+          /* Module number error */
+          /***********************/
+
+          DPRINTK("Module number error\n");    
+          i_ReturnValue = -2;
+          }
+
+       return (i_ReturnValue);
+       }
+
+
+
+
+
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     : _INT_   i_APCI1710_ReadSSI1DigitalInput                |
+|                                       (BYTE_     b_BoardHandle,            |
+|                                        BYTE_     b_ModulNbr,               |
+|                                        BYTE_     b_InputChannel,           |
+|                                        PBYTE_   pb_ChannelStatus)          |
++----------------------------------------------------------------------------+
+| Task              :
+                                       (0) Set the digital output from selected SSI moule         |
+|                     (b_ModuleNbr) ON
+                    (1) Set the digital output from selected SSI moule         |
+|                     (b_ModuleNbr) OFF        
+                                       (2)Read the status from selected SSI digital input        |
+|                     (b_InputChannel)  
+                    (3)Read the status from all SSI digital inputs from       |
+|                     selected SSI module (b_ModulNbr)                   |
++----------------------------------------------------------------------------+
+| Input Parameters  : BYTE_ b_BoardHandle         : Handle of board APCI-1710|
+|                     BYTE_ b_ModulNbr    CR_AREF        : Module number to         |
+|                                                   configure (0 to 3)       |
+|                     BYTE_ b_InputChannel CR_CHAN       : Selection from digital   |
+|                        data[0] which IOTYPE                           input ( 0 to 2)          |
++----------------------------------------------------------------------------+
+| Output Parameters : PBYTE_  pb_ChannelStatus    : Digital input channel    |
+|                                 data[0]                  status                   |
+|                                                   0 : Channle is not active|
+|                                                   1 : Channle is active    |
++----------------------------------------------------------------------------+
+| Return Value      : 0: No error                                            |
+|                    -1: The handle parameter of the board is wrong          |
+|                    -2: The module parameter is wrong                       |
+|                    -3: The module is not a SSI module                      |
+|                    -4: The selected SSI digital input is wrong             |
++----------------------------------------------------------------------------+
+*/
+
+
+
+INT    i_APCI1710_InsnBitsSSIDigitalIO(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,
+lsampl_t *data)
+       {
+       INT     i_ReturnValue = 0;
+       DWORD   dw_StatusReg;
+       BYTE    b_ModulNbr;
+       BYTE    b_InputChannel;
+       PBYTE   pb_ChannelStatus;
+        PBYTE   pb_InputStatus;
+       BYTE    b_IOType;
+       i_ReturnValue = insn->n;
+        b_ModulNbr    = (BYTE) CR_AREF(insn->chanspec);
+        b_IOType      = (BYTE) data[0];
+       
+       /**************************/
+       /* Test the module number */
+       /**************************/
+
+       if (b_ModulNbr < 4)
+          {
+          /***********************/
+          /* Test if SSI counter */
+          /***********************/
+
+          if ((devpriv->s_BoardInfos.
+               dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_SSI_COUNTER)
+             {
+           switch(b_IOType)
+                  {
+                  case    APCI1710_SSI_SET_CHANNELON :
+                                       /*****************************/
+                                       /* Set the digital output ON */
+                                       /*****************************/
+
+                                       
+                   outl(1,devpriv->s_BoardInfos.ui_Address + 16 + (64 * b_ModulNbr));
+                              break ;
+
+                  case    APCI1710_SSI_SET_CHANNELOFF :
+                                       /******************************/
+                                       /* Set the digital output OFF */
+                                       /******************************/
+
+                               
+                                  outl(0,devpriv->s_BoardInfos.ui_Address + 16 + (64 * b_ModulNbr));
+                              break ;
+                  
+               
+
+                  case APCI1710_SSI_READ_1CHANNEL:
+                                  /******************************************/
+                                  /* Test the digital imnput channel number */
+                                  /******************************************/
+
+                                       b_InputChannel = (BYTE) CR_CHAN(insn->chanspec);
+                                       pb_ChannelStatus = (PBYTE) &data[0];
+
+                                       if (b_InputChannel <= 2)
+                                       {
+                                       /**************************/
+                                       /* Read all digital input */
+                                       /**************************/
+       
+                                       
+                                       dw_StatusReg = inl(devpriv->s_BoardInfos.ui_Address + (64 * b_ModulNbr));
+                                       *pb_ChannelStatus = (BYTE) (((~dw_StatusReg) >> (4 + b_InputChannel)) & 1);
+                                       }
+                                       else
+                                       {
+                                       /********************************/
+                                       /* Selected digital input error */
+                                       /********************************/
+
+                           DPRINTK("Selected digital input error\n");
+                                       i_ReturnValue = -4;
+                                       }
+                                       break;
+
+                       case APCI1710_SSI_READ_ALLCHANNEL:
+                                       /**************************/
+                                       /* Read all digital input */
+                                       /**************************/
+                                       pb_InputStatus = (PBYTE) &data[0];
+
+                               
+                                       dw_StatusReg      = inl(devpriv->s_BoardInfos.ui_Address + (64 * b_ModulNbr));
+                                       *pb_InputStatus = (BYTE) (((~dw_StatusReg) >> 4) & 7);
+                                       break;
+
+                       default :
+                                       printk("IO type wrong\n");
+
+                } //switch end
+             }
+          else
+             {
+             /**********************************/
+             /* The module is not a SSI module */
+             /**********************************/
+
+             DPRINTK("The module is not a SSI module\n");      
+             i_ReturnValue = -3;
+             }
+          }
+       else
+          {
+          /***********************/
+          /* Module number error */
+          /***********************/
+
+          DPRINTK("Module number error\n");
+          i_ReturnValue = -2;
+          }
+
+       return (i_ReturnValue);
+       }
index f5cf48432ee56ccb06054a7b1903cf1e396fb999..513e60bb14d8b3d38a6737157fdcc1570659b61c 100644 (file)
@@ -1,62 +1,62 @@
-/**\r
-@verbatim\r
-\r
-Copyright (C) 2004,2005  ADDI-DATA GmbH for the source code of this module. \r
-        \r
-        ADDI-DATA GmbH \r
-        Dieselstrasse 3 \r
-        D-77833 Ottersweier \r
-        Tel: +19(0)7223/9493-0 \r
-        Fax: +49(0)7223/9493-92 \r
-        http://www.addi-data-com \r
-        info@addi-data.com \r
-\r
-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.\r
-\r
-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.\r
-\r
-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 USA\r
-\r
-You shoud also find the complete GPL in the COPYING file accompanying this source code.\r
-\r
-@endverbatim\r
-*/\r
-\r
-\r
-\r
-#define APCI1710_30MHZ           30\r
-#define APCI1710_33MHZ           33\r
-#define APCI1710_40MHZ           40\r
-\r
-\r
-#define APCI1710_BINARY_MODE     0x1\r
-#define APCI1710_GRAY_MODE       0x0\r
-\r
-#define APCI1710_SSI_READ1VALUE                                1\r
-#define APCI1710_SSI_READALLVALUE                      2\r
-\r
-\r
-#define APCI1710_SSI_SET_CHANNELON       0\r
-#define APCI1710_SSI_SET_CHANNELOFF            1\r
-#define APCI1710_SSI_READ_1CHANNEL             2\r
-#define APCI1710_SSI_READ_ALLCHANNEL           3\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-|                       SSI INISIALISATION FUNCTION                          |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-INT   i_APCI1710_InsnConfigInitSSI(comedi_device *dev,comedi_subdevice *s,\r
-       comedi_insn *insn,lsampl_t *data);\r
-\r
-\r
-INT i_APCI1710_InsnReadSSIValue(comedi_device *dev,comedi_subdevice *s,\r
-       comedi_insn *insn,lsampl_t *data);\r
-\r
-\r
-\r
-INT    i_APCI1710_InsnBitsSSIDigitalIO(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,\r
-lsampl_t *data);\r
-\r
-\r
-\r
+/**
+@verbatim
+
+Copyright (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 USA
+
+You shoud also find the complete GPL in the COPYING file accompanying this source code.
+
+@endverbatim
+*/
+
+
+
+#define APCI1710_30MHZ           30
+#define APCI1710_33MHZ           33
+#define APCI1710_40MHZ           40
+
+
+#define APCI1710_BINARY_MODE     0x1
+#define APCI1710_GRAY_MODE       0x0
+
+#define APCI1710_SSI_READ1VALUE                                1
+#define APCI1710_SSI_READALLVALUE                      2
+
+
+#define APCI1710_SSI_SET_CHANNELON       0
+#define APCI1710_SSI_SET_CHANNELOFF            1
+#define APCI1710_SSI_READ_1CHANNEL             2
+#define APCI1710_SSI_READ_ALLCHANNEL           3
+
+/*
++----------------------------------------------------------------------------+
+|                       SSI INISIALISATION FUNCTION                          |
++----------------------------------------------------------------------------+
+*/
+INT   i_APCI1710_InsnConfigInitSSI(comedi_device *dev,comedi_subdevice *s,
+       comedi_insn *insn,lsampl_t *data);
+
+
+INT i_APCI1710_InsnReadSSIValue(comedi_device *dev,comedi_subdevice *s,
+       comedi_insn *insn,lsampl_t *data);
+
+
+
+INT    i_APCI1710_InsnBitsSSIDigitalIO(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,
+lsampl_t *data);
+
+
+
index dbebeeefa3f4a61c96909e9bde3be602bd02d161..f02d2eb4e4ee717b07e047db99458ece8497c1b6 100644 (file)
-/**\r
-@verbatim\r
-\r
-Copyright (C) 2004,2005  ADDI-DATA GmbH for the source code of this module. \r
-        \r
-        ADDI-DATA GmbH \r
-        Dieselstrasse 3 \r
-        D-77833 Ottersweier \r
-        Tel: +19(0)7223/9493-0 \r
-        Fax: +49(0)7223/9493-92 \r
-        http://www.addi-data-com \r
-        info@addi-data.com \r
-\r
-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.\r
-\r
-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.\r
-\r
-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 USA\r
-\r
-You shoud also find the complete GPL in the COPYING file accompanying this source code.\r
-\r
-@endverbatim\r
-*/\r
-/*\r
-    \r
-  +-----------------------------------------------------------------------+\r
-  | (C) ADDI-DATA GmbH          Dieselstraße 3       D-77833 Ottersweier  |\r
-  +-----------------------------------------------------------------------+\r
-  | Tel : +49 (0) 7223/9493-0     | email    : info@addi-data.com         |\r
-  | Fax : +49 (0) 7223/9493-92    | Internet : http://www.addi-data.com   |\r
-  +-----------------------------------------------------------------------+\r
-  | Project     : API APCI1710    | Compiler : gcc                        |\r
-  | Module name : TOR.C           | Version  : 2.96                       |\r
-  +-------------------------------+---------------------------------------+\r
-  | Project manager: Eric Stolz   | Date     :  02/12/2002                |\r
-  +-----------------------------------------------------------------------+\r
-  | Description :   APCI-1710 tor counter module                          |\r
-  |                                                                       |\r
-  |                                                                       |\r
-  +-----------------------------------------------------------------------+\r
-  |                             UPDATES                                   |\r
-  +-----------------------------------------------------------------------+\r
-  |   Date   |   Author  |          Description of updates                |\r
-  +----------+-----------+------------------------------------------------+\r
-  | 27/01/99 | S. Weber  | 40 MHz implementation                          |\r
-  +-----------------------------------------------------------------------+\r
-  | 28/04/00 | S. Weber  | Simple,double and quadruple mode implementation|\r
-  |          |           | Extern clock implementation                    |\r
-  +-----------------------------------------------------------------------+\r
-  | 08/05/00 | Guinot C  | - 0400/0228 All Function in RING 0             |\r
-  |          |           |   available                                    |\r
-  +-----------------------------------------------------------------------+\r
-*/\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-|                               Included files                               |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-\r
-#include "APCI1710_Tor.h"\r
-\r
-\r
-\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : _INT_     i_APCI1710_InitTorCounter                    |\r
-|                                       (BYTE_     b_BoardHandle,            |\r
-|                                        BYTE_     b_ModulNbr,               |\r
-|                                        BYTE_     b_TorCounter,             |\r
-|                                        BYTE_     b_PCIInputClock,          |\r
-|                                        BYTE_     b_TimingUnit,             |\r
-|                                        ULONG_   ul_TimingInterval,         |\r
-|                                        PULONG_ pul_RealTimingInterval)     |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Configure the selected tor counter (b_TorCounter)      |\r
-|                     from selected module (b_ModulNbr).                     |\r
-|                     The ul_TimingInterval and ul_TimingUnit determine the  |\r
-|                     timing base for the measurement.                       |\r
-|                     The pul_RealTimingInterval return the real timing      |\r
-|                     value. You must calling this function be for you call  |\r
-|                     any other function witch access of the tor counter.    |\r
-|                                                                            |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  :    |\r
-|                     \r
-               CR_AREF BYTE_   b_ModulNbr       : Module number to configure  |\r
-|                                                (0 to 3)                    |\r
-|           data[0] BYTE_   b_TorCounter     : Tor counter selection       |\r
-|                                                (0 or 1).                   |\r
-|           data[1] BYTE_   b_PCIInputClock  : Selection from PCI bus clock|\r
-|                                                - APCI1710_30MHZ :          |\r
-|                                                  The PC have a PCI bus     |\r
-|                                                  clock from 30 MHz         |\r
-|                                                - APCI1710_33MHZ :          |\r
-|                                                  The PC have a PCI bus     |\r
-|                                                  clock from 33 MHz         |\r
-|                                                - APCI1710_40MHZ            |\r
-|                                                  The APCI-1710 have a      |\r
-|                                                  integrated 40Mhz          |\r
-|                                                  quartz.                   |\r
-|                                                - APCI1710_GATE_INPUT       |\r
-|                                                  Used the gate input for   |\r
-|                                                 the base clock. If you    |\r
-|                                                 have selected this option,|\r
-|                                                 than it is not possibl to |\r
-|                                                 used the gate input for   |\r
-|                                                 enabled the acquisition   |\r
-|           data[2] BYTE_   b_TimingUnit    : Base timing unit (0 to 4)    |\r
-|                                                 0 : ns                     |\r
-|                                                 1 : µs                     |\r
-|                                                 2 : ms                     |\r
-|                                                 3 : s                      |\r
-|                                                 4 : mn                     |\r
-|           data[3]          ULONG_ ul_TimingInterval : Base timing value.          |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : PULONG_  pul_RealTimingInterval : Real  base timing    |\r
-|                     data[0]                                  value.               |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      :  0: No error                                           |\r
-|                     -1: The handle parameter of the board is wrong         |\r
-|                     -2: Module selection wrong                             |\r
-|                     -3: The module is not a tor counter module             |\r
-|                     -4: Tor counter selection is wrong                     |\r
-|                     -5: The selected PCI input clock is wrong              |\r
-|                     -6: Timing unit selection is wrong                     |\r
-|                     -7: Base timing selection is wrong                     |\r
-|                     -8: You can not used the 40MHz clock selection wich    |\r
-|                         this board                                         |\r
-|                     -9: You can not used the 40MHz clock selection wich    |\r
-|                         this TOR version                                   |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-\r
-\r
-INT   i_APCI1710_InsnConfigInitTorCounter(comedi_device *dev,comedi_subdevice *s,\r
-       comedi_insn *insn,lsampl_t *data)\r
-       {\r
-       INT    i_ReturnValue = 0;\r
-       ULONG ul_TimerValue  = 0;\r
-       DWORD dw_Command;\r
-       double d_RealTimingInterval = 0;\r
-       BYTE     b_ModulNbr;\r
-       BYTE     b_TorCounter;\r
-       BYTE     b_PCIInputClock;\r
-       BYTE     b_TimingUnit;\r
-       ULONG    ul_TimingInterval;\r
-       ULONG   ul_RealTimingInterval = 0;\r
-\r
-       i_ReturnValue                   =   insn->n;\r
-       b_ModulNbr                              =   (BYTE)  CR_AREF(insn->chanspec);\r
-\r
-       b_TorCounter                    =       (BYTE)  data[0];\r
-       b_PCIInputClock                 =       (BYTE)  data[1];\r
-       b_TimingUnit                    =       (BYTE)  data[2];\r
-       ul_TimingInterval               =       (ULONG) data[3];\r
-       printk("INPUT clock %d\n",b_PCIInputClock);\r
-       \r
-               /**************************/\r
-               /* Test the module number */\r
-               /**************************/\r
-\r
-       if (b_ModulNbr < 4)\r
-          {\r
-               /***********************/\r
-               /* Test if tor counter */\r
-               /***********************/\r
-\r
-          if ((devpriv->s_BoardInfos.\r
-               dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_TOR_COUNTER)\r
-             {\r
-             /**********************************/\r
-             /* Test the tor counter selection */\r
-             /**********************************/\r
-\r
-             if (b_TorCounter <= 1)\r
-                {\r
-                /**************************/\r
-                /* Test the PCI bus clock */\r
-                /**************************/\r
-\r
-                if ((b_PCIInputClock == APCI1710_30MHZ) ||\r
-                    (b_PCIInputClock == APCI1710_33MHZ) ||\r
-                    (b_PCIInputClock == APCI1710_40MHZ) ||\r
-                    (b_PCIInputClock == APCI1710_GATE_INPUT))\r
-                   {\r
-                   /************************/\r
-                   /* Test the timing unit */\r
-                   /************************/\r
-\r
-                   if ((b_TimingUnit <= 4) || (b_PCIInputClock == APCI1710_GATE_INPUT))\r
-                      {\r
-                      /**********************************/\r
-                      /* Test the base timing selection */\r
-                      /**********************************/\r
-\r
-                      if(((b_PCIInputClock == APCI1710_30MHZ)   && (b_TimingUnit == 0) && (ul_TimingInterval >= 133) && (ul_TimingInterval <= 0xFFFFFFFFUL)) ||\r
-                          ((b_PCIInputClock == APCI1710_30MHZ)      && (b_TimingUnit == 1) && (ul_TimingInterval >= 1)   && (ul_TimingInterval <= 571230650UL))  ||\r
-                          ((b_PCIInputClock == APCI1710_30MHZ)      && (b_TimingUnit == 2) && (ul_TimingInterval >= 1)   && (ul_TimingInterval <= 571230UL))     ||\r
-                          ((b_PCIInputClock == APCI1710_30MHZ)      && (b_TimingUnit == 3) && (ul_TimingInterval >= 1)   && (ul_TimingInterval <= 571UL))        ||\r
-                          ((b_PCIInputClock == APCI1710_30MHZ)      && (b_TimingUnit == 4) && (ul_TimingInterval >= 1)   && (ul_TimingInterval <= 9UL))          ||\r
-                          ((b_PCIInputClock == APCI1710_33MHZ)      && (b_TimingUnit == 0) && (ul_TimingInterval >= 121) && (ul_TimingInterval <= 0xFFFFFFFFUL)) ||\r
-                          ((b_PCIInputClock == APCI1710_33MHZ)      && (b_TimingUnit == 1) && (ul_TimingInterval >= 1)   && (ul_TimingInterval <= 519691043UL))  ||\r
-                          ((b_PCIInputClock == APCI1710_33MHZ)      && (b_TimingUnit == 2) && (ul_TimingInterval >= 1)   && (ul_TimingInterval <= 519691UL))     ||\r
-                          ((b_PCIInputClock == APCI1710_33MHZ)      && (b_TimingUnit == 3) && (ul_TimingInterval >= 1)   && (ul_TimingInterval <= 520UL))        ||\r
-                          ((b_PCIInputClock == APCI1710_33MHZ)      && (b_TimingUnit == 4) && (ul_TimingInterval >= 1)   && (ul_TimingInterval <= 8UL))          ||\r
-                          ((b_PCIInputClock == APCI1710_40MHZ)      && (b_TimingUnit == 0) && (ul_TimingInterval >= 100) && (ul_TimingInterval <= 0xFFFFFFFFUL)) ||\r
-                          ((b_PCIInputClock == APCI1710_40MHZ)      && (b_TimingUnit == 1) && (ul_TimingInterval >= 1)   && (ul_TimingInterval <= 429496729UL))  ||\r
-                          ((b_PCIInputClock == APCI1710_40MHZ)      && (b_TimingUnit == 2) && (ul_TimingInterval >= 1)   && (ul_TimingInterval <= 429496UL))     ||\r
-                          ((b_PCIInputClock == APCI1710_40MHZ)      && (b_TimingUnit == 3) && (ul_TimingInterval >= 1)   && (ul_TimingInterval <= 429UL))        ||\r
-                          ((b_PCIInputClock == APCI1710_40MHZ)      && (b_TimingUnit == 4) && (ul_TimingInterval >= 1)   && (ul_TimingInterval <= 7UL))          ||\r
-                          ((b_PCIInputClock == APCI1710_GATE_INPUT) && (ul_TimingInterval >= 2)))\r
-                         {\r
-                               /**************************/\r
-                               /* Test the board version */\r
-                               /**************************/\r
-\r
-                         if (((b_PCIInputClock == APCI1710_40MHZ) && (devpriv->s_BoardInfos.\r
-                                                                     b_BoardVersion > 0)) ||\r
-                             (b_PCIInputClock != APCI1710_40MHZ))\r
-                            {\r
-                            /************************/\r
-                            /* Test the TOR version */\r
-                            /************************/\r
-\r
-                            if (((b_PCIInputClock == APCI1710_40MHZ) && ((devpriv->s_BoardInfos.\r
-                                                                         dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) >= 0x3131)) ||\r
-                                ((b_PCIInputClock == APCI1710_GATE_INPUT) && ((devpriv->s_BoardInfos.\r
-                                                                              dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) >= 0x3132)) ||\r
-                                (b_PCIInputClock == APCI1710_30MHZ) ||\r
-                                (b_PCIInputClock == APCI1710_33MHZ))\r
-                               {\r
-                               /*********************************/\r
-                               /* Test if not extern clock used */\r
-                               /*********************************/\r
-\r
-                               if (b_PCIInputClock != APCI1710_GATE_INPUT)\r
-                                  {\r
-                                  fpu_begin ();\r
-                                  /****************************************/\r
-                                  /* Calculate the timer 0 division fator */\r
-                                  /****************************************/\r
-\r
-                                  switch (b_TimingUnit)\r
-                                     {\r
-                                     /******/\r
-                                     /* ns */\r
-                                     /******/\r
-\r
-                                     case 0:\r
-                                          \r
-                                             /******************/\r
-                                             /* Timer 0 factor */\r
-                                             /******************/\r
-\r
-                                             ul_TimerValue = (ULONG) (ul_TimingInterval * (0.00025 * b_PCIInputClock));\r
-\r
-                                             /*******************/\r
-                                             /* Round the value */\r
-                                             /*******************/\r
-\r
-                                             if ((double) ((double) ul_TimingInterval * (0.00025 * (double) b_PCIInputClock)) >= ((double) ((double) ul_TimerValue + 0.5)))\r
-                                                {\r
-                                                ul_TimerValue = ul_TimerValue + 1;\r
-                                                }\r
-\r
-                                             /*****************************/\r
-                                             /* Calculate the real timing */\r
-                                             /*****************************/\r
-\r
-                                             ul_RealTimingInterval = (ULONG) (ul_TimerValue / (0.00025 * (double) b_PCIInputClock));\r
-                                             d_RealTimingInterval = (double) ul_TimerValue / (0.00025 * (double) b_PCIInputClock);\r
-\r
-                                             if ((double) ((double) ul_TimerValue / (0.00025 * (double) b_PCIInputClock)) >= (double) ((double) ul_RealTimingInterval + 0.5))\r
-                                                {\r
-                                                ul_RealTimingInterval = ul_RealTimingInterval + 1;\r
-                                                }\r
-\r
-                                             ul_TimingInterval = ul_TimingInterval - 1;\r
-                                             ul_TimerValue     = ul_TimerValue - 2;\r
-\r
-                                             if (b_PCIInputClock != APCI1710_40MHZ)\r
-                                                {\r
-                                                ul_TimerValue     = (ULONG) ((double) (ul_TimerValue) * 1.007752288);\r
-                                                }\r
-                                          \r
-\r
-                                          break;\r
-\r
-                                     /******/\r
-                                     /* æs */\r
-                                     /******/\r
-\r
-                                     case 1:\r
-                                          \r
-                                             /******************/\r
-                                             /* Timer 0 factor */\r
-                                             /******************/\r
-\r
-                                             ul_TimerValue = (ULONG) (ul_TimingInterval * (0.25 * b_PCIInputClock));\r
-\r
-                                             /*******************/\r
-                                             /* Round the value */\r
-                                             /*******************/\r
-\r
-                                             if ((double) ((double) ul_TimingInterval * (0.25 * (double) b_PCIInputClock)) >= ((double) ((double) ul_TimerValue + 0.5)))\r
-                                                {\r
-                                                ul_TimerValue = ul_TimerValue + 1;\r
-                                                }\r
-\r
-                                             /*****************************/\r
-                                             /* Calculate the real timing */\r
-                                             /*****************************/\r
-\r
-                                             ul_RealTimingInterval = (ULONG) (ul_TimerValue / (0.25 * (double) b_PCIInputClock));\r
-                                             d_RealTimingInterval = (double) ul_TimerValue / ((double) 0.25 * (double) b_PCIInputClock);\r
-\r
-                                            if ((double) ((double) ul_TimerValue / (0.25 * (double) b_PCIInputClock)) >= (double) ((double) ul_RealTimingInterval + 0.5))\r
-                                                {\r
-                                                ul_RealTimingInterval = ul_RealTimingInterval + 1;\r
-                                                }\r
-\r
-                                             ul_TimingInterval = ul_TimingInterval - 1;\r
-                                             ul_TimerValue     = ul_TimerValue - 2;\r
-\r
-                                             if (b_PCIInputClock != APCI1710_40MHZ)\r
-                                                {\r
-                                                ul_TimerValue     = (ULONG) ((double) (ul_TimerValue) * 1.007752288);\r
-                                                }\r
-                                          \r
-\r
-                                          break;\r
-\r
-                                     /******/\r
-                                     /* ms */\r
-                                     /******/\r
-\r
-                                     case 2:\r
-                                          \r
-                                             /******************/\r
-                                             /* Timer 0 factor */\r
-                                             /******************/\r
-\r
-                                             ul_TimerValue = ul_TimingInterval * (250.0 * b_PCIInputClock);\r
-\r
-                                             /*******************/\r
-                                             /* Round the value */\r
-                                             /*******************/\r
-\r
-                                             if ((double) ((double) ul_TimingInterval * (250.0 * (double) b_PCIInputClock)) >= ((double) ((double) ul_TimerValue + 0.5)))\r
-                                                {\r
-                                                ul_TimerValue = ul_TimerValue + 1;\r
-                                                }\r
-\r
-                                             /*****************************/\r
-                                             /* Calculate the real timing */\r
-                                             /*****************************/\r
-\r
-                                             ul_RealTimingInterval = (ULONG) (ul_TimerValue / (250.0 * (double) b_PCIInputClock));\r
-                                             d_RealTimingInterval = (double) ul_TimerValue / (250.0 * (double) b_PCIInputClock);\r
-\r
-                                             if ((double) ((double) ul_TimerValue / (250.0 * (double) b_PCIInputClock)) >= (double) ((double) ul_RealTimingInterval + 0.5))\r
-                                                {\r
-                                                ul_RealTimingInterval = ul_RealTimingInterval + 1;\r
-                                                }\r
-\r
-                                             ul_TimingInterval = ul_TimingInterval - 1;\r
-                                             ul_TimerValue     = ul_TimerValue - 2;\r
-\r
-                                             if (b_PCIInputClock != APCI1710_40MHZ)\r
-                                                {\r
-                                                ul_TimerValue     = (ULONG) ((double) (ul_TimerValue) * 1.007752288);\r
-                                                }\r
-                                          \r
-\r
-                                          break;\r
-\r
-                                     /*****/\r
-                                     /* s */\r
-                                     /*****/\r
-\r
-                                     case 3:\r
-                                          \r
-                                             /******************/\r
-                                             /* Timer 0 factor */\r
-                                             /******************/\r
-\r
-                                             ul_TimerValue = (ULONG) (ul_TimingInterval * (250000.0 * b_PCIInputClock));\r
-\r
-                                             /*******************/\r
-                                             /* Round the value */\r
-                                             /*******************/\r
-\r
-                                             if ((double) ((double) ul_TimingInterval * (250000.0 * (double) b_PCIInputClock)) >= ((double) ((double) ul_TimerValue + 0.5)))\r
-                                                {\r
-                                                ul_TimerValue = ul_TimerValue + 1;\r
-                                                }\r
-\r
-                                             /*****************************/\r
-                                             /* Calculate the real timing */\r
-                                             /*****************************/\r
-\r
-                                             ul_RealTimingInterval = (ULONG) (ul_TimerValue / (250000.0 * (double) b_PCIInputClock));\r
-                                             d_RealTimingInterval = (double) ul_TimerValue / (250000.0 * (double) b_PCIInputClock);\r
-\r
-                                             if ((double) ((double) ul_TimerValue / (250000.0 * (double) b_PCIInputClock)) >= (double) ((double) ul_RealTimingInterval + 0.5))\r
-                                                {\r
-                                                ul_RealTimingInterval = ul_RealTimingInterval + 1;\r
-                                                }\r
-\r
-                                             ul_TimingInterval = ul_TimingInterval - 1;\r
-                                             ul_TimerValue     = ul_TimerValue - 2;\r
-\r
-                                             if (b_PCIInputClock != APCI1710_40MHZ)\r
-                                                {\r
-                                                ul_TimerValue     = (ULONG) ((double) (ul_TimerValue) * 1.007752288);\r
-                                                }\r
-                                          \r
-\r
-                                          break;\r
-\r
-                                     /******/\r
-                                     /* mn */\r
-                                     /******/\r
-\r
-                                     case 4:\r
-                                          \r
-                                             /******************/\r
-                                             /* Timer 0 factor */\r
-                                             /******************/\r
-\r
-                                             ul_TimerValue = (ULONG) ((ul_TimingInterval * 60) * (250000.0 * b_PCIInputClock));\r
-\r
-                                             /*******************/\r
-                                             /* Round the value */\r
-                                             /*******************/\r
-\r
-                                             if ((double) ((double) (ul_TimingInterval * 60.0) * (250000.0 * (double) b_PCIInputClock)) >= ((double) ((double) ul_TimerValue + 0.5)))\r
-                                                {\r
-                                                ul_TimerValue = ul_TimerValue + 1;\r
-                                                }\r
-\r
-                                             /*****************************/\r
-                                             /* Calculate the real timing */\r
-                                             /*****************************/\r
-\r
-                                             ul_RealTimingInterval = (ULONG) (ul_TimerValue / (250000.0 * (double) b_PCIInputClock)) / 60;\r
-                                             d_RealTimingInterval = ((double) ul_TimerValue / (250000.0 * (double) b_PCIInputClock)) / 60.0;\r
-\r
-                                             if ((double) (((double) ul_TimerValue / (250000.0 * (double) b_PCIInputClock)) / 60.0) >= (double) ((double) ul_RealTimingInterval + 0.5))\r
-                                                {\r
-                                                ul_RealTimingInterval = ul_RealTimingInterval + 1;\r
-                                                }\r
-\r
-                                             ul_TimingInterval = ul_TimingInterval - 1;\r
-                                             ul_TimerValue     = ul_TimerValue - 2;\r
-\r
-                                             if (b_PCIInputClock != APCI1710_40MHZ)\r
-                                                {\r
-                                                ul_TimerValue     = (ULONG) ((double) (ul_TimerValue) * 1.007752288);\r
-                                                }\r
-                                          \r
-                                          break;\r
-                                     }\r
-                                     \r
-                                  fpu_end ();\r
-                                  } // if (b_PCIInputClock != APCI1710_GATE_INPUT)\r
-                               else\r
-                                  {\r
-                                  /*************************************************************/\r
-                                  /* 2 Clock used for the overflow and the reload from counter */\r
-                                  /*************************************************************/\r
-\r
-                                  ul_TimerValue = ul_TimingInterval - 2;\r
-                                  } // if (b_PCIInputClock != APCI1710_GATE_INPUT)\r
-\r
-                               /****************************/\r
-                               /* Save the PCI input clock */\r
-                               /****************************/\r
-                               devpriv->s_ModuleInfo [b_ModulNbr].\r
-                               s_TorCounterModuleInfo.\r
-                               b_PCIInputClock = b_PCIInputClock;\r
-\r
-                               /************************/\r
-                               /* Save the timing unit */\r
-                               /************************/\r
-\r
-                               devpriv->s_ModuleInfo [b_ModulNbr].\r
-                               s_TorCounterModuleInfo.\r
-                               s_TorCounterInfo [b_TorCounter].\r
-                               b_TimingUnit = b_TimingUnit;\r
-\r
-                               /************************/\r
-                               /* Save the base timing */\r
-                               /************************/\r
-                               devpriv->s_ModuleInfo [b_ModulNbr].\r
-                               s_TorCounterModuleInfo.\r
-                               s_TorCounterInfo [b_TorCounter].\r
-                               d_TimingInterval = d_RealTimingInterval;\r
-\r
-                               devpriv->s_ModuleInfo [b_ModulNbr].\r
-                               s_TorCounterModuleInfo.\r
-                               s_TorCounterInfo [b_TorCounter].\r
-                               ul_RealTimingInterval = ul_RealTimingInterval;\r
-\r
-                               /*******************/\r
-                               /* Get the command */\r
-                               /*******************/\r
-\r
-                               \r
-                               dw_Command = inl(devpriv->s_BoardInfos.ui_Address + 4 + (16 * b_TorCounter) + (64 * b_ModulNbr));\r
-\r
-                               dw_Command = (dw_Command >> 4) & 0xF;\r
-\r
-                               /******************/\r
-                               /* Test if 40 MHz */\r
-                               /******************/\r
-\r
-                               if (b_PCIInputClock == APCI1710_40MHZ)\r
-                                  {\r
-                                  /****************************/\r
-                                  /* Set the 40 MHz selection */\r
-                                  /****************************/\r
-\r
-                                  dw_Command = dw_Command | 0x10;\r
-                                  }\r
-\r
-                               /*****************************/\r
-                               /* Test if extern clock used */\r
-                               /*****************************/\r
-\r
-                               if (b_PCIInputClock == APCI1710_GATE_INPUT)\r
-                                  {\r
-                                  /****************************/\r
-                                  /* Set the 40 MHz selection */\r
-                                  /****************************/\r
-\r
-                                  dw_Command = dw_Command | 0x20;\r
-                                  }\r
-\r
-                               /*************************/\r
-                               /* Write the new command */\r
-                               /*************************/\r
-\r
-                       \r
-                               outl(dw_Command,devpriv->s_BoardInfos.ui_Address + 4 + (16 * b_TorCounter) + (64 * b_ModulNbr));\r
\r
-                               /*******************/\r
-                               /* Disable the tor */\r
-                               /*******************/\r
-                               \r
-                               outl(0,devpriv->s_BoardInfos.\r
-                                       ui_Address + 8 + (16 * b_TorCounter) + (64 * b_ModulNbr));\r
-                               /*************************/\r
-                               /* Set the timer 1 value */\r
-                               /*************************/\r
-\r
-                       \r
-                               outl(ul_TimerValue,devpriv->s_BoardInfos.ui_Address + 0 + (16 * b_TorCounter) + (64 * b_ModulNbr));\r
-\r
-                               /*********************/\r
-                               /* Tor counter init. */\r
-                               /*********************/\r
-\r
-                               devpriv->s_ModuleInfo [b_ModulNbr].\r
-                               s_TorCounterModuleInfo.\r
-                               s_TorCounterInfo [b_TorCounter].\r
-                               b_TorCounterInit = 1;\r
-                               }\r
-                            else\r
-                               {\r
-                               /***********************************************/\r
-                               /* TOR version error for 40MHz clock selection */\r
-                               /***********************************************/\r
-\r
-                       DPRINTK("TOR version error for 40MHz clock selection\n");\r
-                               i_ReturnValue = -9;\r
-                               }\r
-                            }\r
-                         else\r
-                            {\r
-                            /**************************************************************/\r
-                            /* You can not used the 40MHz clock selection wich this board */\r
-                            /**************************************************************/\r
-\r
-                                DPRINTK("You can not used the 40MHz clock selection wich this board\n");\r
-                            i_ReturnValue = -8;\r
-                            }\r
-                         }\r
-                      else\r
-                         {\r
-                         /**********************************/\r
-                         /* Base timing selection is wrong */\r
-                         /**********************************/\r
-\r
-                         DPRINTK("Base timing selection is wrong\n");\r
-                         i_ReturnValue = -7;\r
-                         }\r
-                      } // if ((b_TimingUnit >= 0) && (b_TimingUnit <= 4))\r
-                   else\r
-                      {\r
-                      /**********************************/\r
-                      /* Timing unit selection is wrong */\r
-                      /**********************************/\r
-\r
-                          DPRINTK("Timing unit selection is wrong\n");          \r
-                      i_ReturnValue = -6;\r
-                      } // if ((b_TimingUnit >= 0) && (b_TimingUnit <= 4))\r
-                   } // if ((b_PCIInputClock == APCI1710_30MHZ) || (b_PCIInputClock == APCI1710_33MHZ))\r
-                else\r
-                   {\r
-                   /*****************************************/\r
-                   /* The selected PCI input clock is wrong */\r
-                   /*****************************************/\r
-\r
-                       DPRINTK("The selected PCI input clock is wrong\n");\r
-                   i_ReturnValue = -5;\r
-                   } // if ((b_PCIInputClock == APCI1710_30MHZ) || (b_PCIInputClock == APCI1710_33MHZ))\r
-                } // if (b_TorCounterMode >= 0 && b_TorCounterMode <= 7)\r
-             else\r
-                {\r
-                /**********************************/\r
-                /* Tor Counter selection is wrong */\r
-                /**********************************/\r
-\r
-                DPRINTK("Tor Counter selection is wrong\n");\r
-                i_ReturnValue = -4;\r
-                } // if (b_TorCounterMode >= 0 && b_TorCounterMode <= 7)\r
-             }\r
-          else\r
-             {\r
-             /******************************************/\r
-             /* The module is not a tor counter module */\r
-             /******************************************/\r
-\r
-             DPRINTK("The module is not a tor counter module\n");              \r
-             i_ReturnValue = -3;\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /***********************/\r
-          /* Module number error */\r
-          /***********************/\r
-\r
-          DPRINTK("Module number error\n");\r
-          i_ReturnValue = -2;\r
-          }\r
-    data[0] = (UINT) ul_RealTimingInterval;\r
-       return (i_ReturnValue);\r
-       }\r
-\r
-\r
-\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : _INT_ i_APCI1710_EnableTorCounter                      |\r
-|                                               (BYTE_ b_BoardHandle,        |\r
-|                                                BYTE_ b_ModulNbr,           |\r
-|                                               BYTE_ b_TorCounter,         |\r
-|                                               BYTE_ b_InputMode,          |\r
-|                                               BYTE_ b_ExternGate,         |\r
-|                                                BYTE_ b_CycleMode,          |\r
-|                                                BYTE_ b_InterruptEnable)    |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Enable the tor counter (b_TorCounter) from selected    |\r
-|                    module (b_ModulNbr). You must calling the              |\r
-|                     "i_APCI1710_InitTorCounter" function be for you call   |\r
-|                    this function.                                         |\r
-|                     If you enable the tor counter interrupt, the           |\r
-|                     tor counter generate a interrupt after the timing cycle|\r
-|                     See function "i_APCI1710_SetBoardIntRoutineX" and the  |\r
-|                     Interrupt mask description chapter from this manual.   |\r
-|                     The b_CycleMode parameter determine if you will        |\r
-|                     measured a single or more cycle.                       |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : BYTE_ b_BoardHandle  : Handle of board APCI-1710       |\r
-|                     BYTE_ b_ModulNbr     : Selected module number (0 to 3) |\r
-|                     BYTE_ b_TorCounter   : Tor counter selection (0 or 1). |\r
-|                    BYTE_ b_InputMode    : Input signal level selection    |\r
-|                                              0 : Tor count each low level |\r
-|                                              1 : Tor count each high level|\r
-|                    BYTE_ b_ExternGate   : Extern gate action selection    |\r
-|                                              0 : Extern gate signal not   |\r
-|                                                  used                     |\r
-|                                              1 : Extern gate signal used. |\r
-|                                                  If you selected the      |\r
-|                                                  single mode, each high   |\r
-|                                                  level signal start the   |\r
-|                                                  counter.                 |\r
-|                                                  If you selected the      |\r
-|                                                  continuous mode, the     |\r
-|                                                  first high level signal  |\r
-|                                                  start the tor counter    |\r
-|                                                                           |\r
-|                                            APCI1710_TOR_QUADRUPLE _MODE : |\r
-|                                            In the quadruple mode, the edge|\r
-|                                            analysis circuit generates a   |\r
-|                                            counting pulse from each edge  |\r
-|                                            of 2 signals which are phase   |\r
-|                                            shifted in relation to each    |\r
-|                                            other.                         |\r
-|                                            The gate input is used for the |\r
-|                                            signal B                       |\r
-|                                                                           |\r
-|                                            APCI1710_TOR_DOUBLE_MODE:      |\r
-|                                            Functions in the same way as   |\r
-|                                            the quadruple mode, except that|\r
-|                                            only two of the four edges are |\r
-|                                            analysed per period.           |\r
-|                                            The gate input is used for the |\r
-|                                            signal B                       |\r
-|                                                                           |\r
-|                                            APCI1710_TOR_SIMPLE_MODE:      |\r
-|                                            Functions in the same way as   |\r
-|                                            the quadruple mode, except that|\r
-|                                            only one of the four edges is  |\r
-|                                            analysed per period.           |\r
-|                                            The gate input is used for the |\r
-|                                            signal B                       |\r
-|                                                                           |\r
-|                     BYTE_ b_CycleMode    : Selected the tor counter        |\r
-|                                            acquisition mode                |\r
-|                     BYTE_ b_InterruptEnable : Enable or disable the        |\r
-|                                               tor counter interrupt.       |\r
-|                                               APCI1710_ENABLE:             |\r
-|                                               Enable the tor counter       |\r
-|                                               interrupt                    |\r
-|                                               APCI1710_DISABLE:            |\r
-|                                               Disable the tor counter      |\r
-|                                               interrupt                    |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : -                                                      |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      :  0: No error                                           |\r
-|                     -1: The handle parameter of the board is wrong         |\r
-|                     -2: Module selection wrong                             |\r
-|                     -3: The module is not a tor counter module             |\r
-|                     -4: Tor counter selection is wrong                     |\r
-|                     -5: Tor counter not initialised see function           |\r
-|                         "i_APCI1710_InitTorCounter"                        |\r
-|                     -6: Tor input signal selection is wrong                |\r
-|                     -7: Extern gate signal mode is wrong                   |\r
-|                     -8: Tor counter acquisition mode cycle is wrong        |\r
-|                     -9: Interrupt parameter is wrong                       |\r
-|                     -10:Interrupt function not initialised.                |\r
-|                         See function "i_APCI1710_SetBoardIntRoutineX"      |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : _INT_ i_APCI1710_DisableTorCounter                     |\r
-|                                               (BYTE_  b_BoardHandle,       |\r
-|                                                BYTE_  b_ModulNbr,          |\r
-|                                               BYTE_  b_TorCounter)        |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Disable the tor counter (b_TorCounter) from selected   |\r
-|                    module (b_ModulNbr). If you disable the tor counter    |\r
-|                    after a start cycle occur and you restart the tor      |\r
-|                    counter witch the " i_APCI1710_EnableTorCounter"       |\r
-|                    function, the status register is cleared               |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : BYTE_ b_BoardHandle  : Handle of board APCI-1710       |\r
-|                     BYTE_ b_ModulNbr     : Selected module number (0 to 3) |\r
-|                     BYTE_ b_TorCounter   : Tor counter selection (0 or 1). |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : -                                                      |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      :  0: No error                                           |\r
-|                     -1: The handle parameter of the board is wrong         |\r
-|                     -2: Module selection wrong                             |\r
-|                     -3: The module is not a tor counter module             |\r
-|                     -4: Tor counter selection is wrong                     |\r
-|                     -5: Tor counter not initialised see function           |\r
-|                         "i_APCI1710_InitTorCounter"                        |\r
-|                     -6: Tor counter not enabled see function               |\r
-|                         "i_APCI1710_EnableTorCounter"                      |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-\r
-\r
-INT  i_APCI1710_InsnWriteEnableDisableTorCounter (comedi_device *dev,comedi_subdevice *s,\r
-       comedi_insn *insn,lsampl_t *data)\r
-       {\r
-       INT    i_ReturnValue = 0;\r
-       DWORD dw_Status;\r
-       DWORD dw_DummyRead;\r
-       DWORD dw_ConfigReg;\r
-       BYTE b_ModulNbr,b_Action;\r
-       BYTE b_TorCounter;\r
-       BYTE b_InputMode;\r
-       BYTE b_ExternGate;\r
-       BYTE b_CycleMode;\r
-       BYTE b_InterruptEnable;\r
-\r
-       b_ModulNbr                      =(BYTE) CR_AREF(insn->chanspec);\r
-       b_Action                        =(BYTE) data[0]; // enable or disable\r
-       b_TorCounter            =(BYTE) data[1];\r
-       b_InputMode                     =(BYTE) data[2] ;\r
-       b_ExternGate            =(BYTE) data[3] ;\r
-       b_CycleMode                     =(BYTE) data[4] ;\r
-       b_InterruptEnable       =(BYTE) data[5] ;\r
-       i_ReturnValue           = insn->n;      ;\r
-       devpriv->tsk_Current=current; // Save the current process task structure\r
-       /**************************/\r
-       /* Test the module number */\r
-       /**************************/\r
-\r
-       if (b_ModulNbr < 4)\r
-          {\r
-          /***********************/\r
-          /* Test if tor counter */\r
-          /***********************/\r
-\r
-          if ((devpriv->s_BoardInfos.\r
-               dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_TOR_COUNTER)\r
-             {\r
-             /**********************************/\r
-             /* Test the tor counter selection */\r
-             /**********************************/\r
-\r
-             if (b_TorCounter <= 1)\r
-                {\r
-          switch(b_Action)// Enable or Disable\r
-                 {\r
-                 case APCI1710_ENABLE :\r
-                /***********************************/\r
-                /* Test if tor counter initialised */\r
-                /***********************************/\r
-\r
-               \r
-\r
-               dw_Status =inl(devpriv->s_BoardInfos.ui_Address + 8 + (16 * b_TorCounter) + (64 * b_ModulNbr));\r
-\r
-                if (dw_Status & 0x10)\r
-                   {\r
-                   /******************************/\r
-                   /* Test the input signal mode */\r
-                   /******************************/\r
-\r
-                   if (b_InputMode == 0                           ||\r
-                       b_InputMode == 1                                 ||\r
-                       b_InputMode == APCI1710_TOR_SIMPLE_MODE    ||\r
-                       b_InputMode == APCI1710_TOR_DOUBLE_MODE    ||\r
-                       b_InputMode == APCI1710_TOR_QUADRUPLE_MODE)\r
-                      {\r
-                      /************************************/\r
-                      /* Test the extern gate signal mode */\r
-                      /************************************/\r
-\r
-                     if (b_ExternGate == 0 || b_ExternGate == 1 || b_InputMode > 1)\r
-                         {\r
-                         /*********************************/\r
-                         /* Test the cycle mode parameter */\r
-                         /*********************************/\r
-\r
-                         if ((b_CycleMode == APCI1710_SINGLE) || (b_CycleMode == APCI1710_CONTINUOUS))\r
-                            {\r
-                            /***************************/\r
-                            /* Test the interrupt flag */\r
-                            /***************************/\r
-\r
-                            if ((b_InterruptEnable == APCI1710_ENABLE) || (b_InterruptEnable == APCI1710_DISABLE))\r
-                               {\r
-\r
-                               \r
-                               \r
-                                  /***************************/\r
-                                  /* Save the interrupt mode */\r
-                                  /***************************/\r
-\r
-                                  devpriv->s_ModuleInfo [b_ModulNbr].\r
-                                  s_TorCounterModuleInfo.\r
-                                  s_TorCounterInfo [b_TorCounter].\r
-                                  b_InterruptEnable = b_InterruptEnable;\r
-\r
-                                  /*******************/\r
-                                  /* Get the command */\r
-                                  /*******************/\r
-\r
-                                 \r
-                                  dw_ConfigReg = inl(devpriv->s_BoardInfos.ui_Address + 4 + (16 * b_TorCounter) + (64 * b_ModulNbr));\r
-\r
-                                  dw_ConfigReg = (dw_ConfigReg >> 4) & 0x30;\r
-\r
-                                  /********************************/\r
-                                  /* Test if not direct mode used */\r
-                                  /********************************/\r
-\r
-                                  if (b_InputMode > 1)\r
-                                     {\r
-                                     /*******************************/\r
-                                     /* Extern gate can not be used */\r
-                                     /*******************************/\r
-\r
-                                     b_ExternGate = 0;\r
-\r
-                                     /*******************************************/\r
-                                     /* Enable the extern gate for the Signal B */\r
-                                     /*******************************************/\r
-\r
-                                     dw_ConfigReg = dw_ConfigReg | 0x40;\r
-\r
-                                     /***********************/\r
-                                     /* Test if simple mode */\r
-                                     /***********************/\r
-\r
-                                     if (b_InputMode == APCI1710_TOR_SIMPLE_MODE)\r
-                                        {\r
-                                        /**************************/\r
-                                        /* Enable the sinple mode */\r
-                                        /**************************/\r
-\r
-                                        dw_ConfigReg = dw_ConfigReg | 0x780;\r
-\r
-                                        } // if (b_InputMode == APCI1710_TOR_SIMPLE_MODE)\r
-\r
-                                     /***********************/\r
-                                     /* Test if double mode */\r
-                                     /***********************/\r
-\r
-                                     if (b_InputMode == APCI1710_TOR_DOUBLE_MODE)\r
-                                        {\r
-                                        /**************************/\r
-                                        /* Enable the double mode */\r
-                                        /**************************/\r
-\r
-                                        dw_ConfigReg = dw_ConfigReg | 0x180;\r
-\r
-                                        } // if (b_InputMode == APCI1710_TOR_DOUBLE_MODE)\r
-\r
-                                     b_InputMode = 0;\r
-                                     } // if (b_InputMode > 1)\r
-\r
-                                  /*******************/\r
-                                  /* Set the command */\r
-                                  /*******************/\r
-\r
-                                  dw_ConfigReg = dw_ConfigReg | b_CycleMode | (b_InterruptEnable * 2) | (b_InputMode * 4) | (b_ExternGate * 8);\r
-\r
-                                  /*****************************/\r
-                                  /* Clear the status register */\r
-                                  /*****************************/\r
-\r
-                                \r
-                                     dw_DummyRead = inl(devpriv->s_BoardInfos.\r
-                                         ui_Address + 0 + (16 * b_TorCounter) + (64 * b_ModulNbr));\r
-\r
-                                  /***************************************/\r
-                                  /* Clear the interrupt status register */\r
-                                  /***************************************/\r
-\r
-                               \r
-                                   dw_DummyRead=inl(devpriv->s_BoardInfos.\r
-                                         ui_Address + 12 + (16 * b_TorCounter) + (64 * b_ModulNbr));  \r
-\r
-                                  /********************/\r
-                                  /* Set the commando */\r
-                                  /********************/\r
-\r
-\r
-                                       outl(dw_ConfigReg,devpriv->s_BoardInfos.\r
-                                               ui_Address + 4 + (16 * b_TorCounter) + (64 * b_ModulNbr));\r
-\r
-                                  /****************/\r
-                                  /* Set the gate */\r
-                                  /****************/\r
-                               \r
-\r
-                                       outl(1,devpriv->s_BoardInfos.\r
-                                          ui_Address + 8 + (16 * b_TorCounter) + (64 * b_ModulNbr));\r
-                                  \r
-                               } // if ((b_InterruptEnable == APCI1710_ENABLE) || (b_InterruptEnable == APCI1710_DISABLE))\r
-                            else\r
-                               {\r
-                               /********************************/\r
-                               /* Interrupt parameter is wrong */\r
-                               /********************************/\r
-\r
-                               DPRINTK("Interrupt parameter is wrong\n");\r
-                               i_ReturnValue = -9;\r
-                               } // if ((b_InterruptEnable == APCI1710_ENABLE) || (b_InterruptEnable == APCI1710_DISABLE))\r
-                            } // if ((b_CycleMode == APCI1710_SINGLE) || (b_CycleMode == APCI1710_CONTINUOUS))\r
-                         else\r
-                            {\r
-                            /***********************************************/\r
-                            /* Tor counter acquisition mode cycle is wrong */\r
-                            /***********************************************/\r
-\r
-                                DPRINTK("Tor counter acquisition mode cycle is wrong\n");\r
-                            i_ReturnValue = -8;\r
-                            } // if ((b_CycleMode == APCI1710_SINGLE) || (b_CycleMode == APCI1710_CONTINUOUS))\r
-                         } // if (b_ExternGate >= 0 && b_ExternGate <= 1)\r
-                      else\r
-                         {\r
-                         /***********************************/\r
-                         /* Extern gate input mode is wrong */\r
-                         /***********************************/\r
-\r
-                         DPRINTK("Extern gate input mode is wrong\n");\r
-                         i_ReturnValue = -7;\r
-                         } // if (b_ExternGate >= 0 && b_ExternGate <= 1)\r
-                      } // if (b_InputMode >= 0 && b_InputMode <= 1)\r
-                   else\r
-                      {\r
-                      /***************************************/\r
-                      /* Tor input signal selection is wrong */\r
-                      /***************************************/\r
-\r
-                          DPRINTK("Tor input signal selection is wrong\n");\r
-                      i_ReturnValue = -6;\r
-                      }\r
-                   }\r
-                else\r
-                   {\r
-                   /*******************************/\r
-                   /* Tor counter not initialised */\r
-                   /*******************************/\r
-\r
-                       DPRINTK("Tor counter not initialised\n");\r
-                   i_ReturnValue = -5;\r
-                   }\r
-                break;\r
-\r
-        case APCI1710_DISABLE :\r
-                        /***********************************/\r
-                /* Test if tor counter initialised */\r
-                /***********************************/\r
-               \r
-                       dw_Status = inl(devpriv->s_BoardInfos.\r
-                       ui_Address + 8 + (16 * b_TorCounter) + (64 * b_ModulNbr));\r
-\r
-                /*******************************/\r
-                /* Test if counter initialised */\r
-                /*******************************/\r
-\r
-                if (dw_Status & 0x10)\r
-                   {\r
-                   /***************************/\r
-                   /* Test if counter enabled */\r
-                   /***************************/\r
-\r
-                   if (dw_Status & 0x1)\r
-                      {\r
-                      /****************************/\r
-                      /* Clear the interrupt mode */\r
-                      /****************************/\r
-                               devpriv->s_ModuleInfo [b_ModulNbr].\r
-                      s_TorCounterModuleInfo.\r
-                      s_TorCounterInfo [b_TorCounter].\r
-                      b_InterruptEnable = APCI1710_DISABLE;\r
-\r
-\r
-                      /******************/\r
-                      /* Clear the gate */\r
-                      /******************/\r
-                       \r
-                               outl(0,devpriv->s_BoardInfos.ui_Address + 8 + (16 * b_TorCounter) + (64 * b_ModulNbr));\r
-                      } // if (dw_Status & 0x1)\r
-                   else\r
-                      {\r
-                      /***************************/\r
-                      /* Tor counter not enabled */\r
-                      /***************************/\r
-\r
-                               DPRINTK("Tor counter not enabled \n");\r
-                      i_ReturnValue = -6;\r
-                      } // if (dw_Status & 0x1)\r
-                   } // if (dw_Status & 0x10)\r
-                else\r
-                   {\r
-                   /*******************************/\r
-                   /* Tor counter not initialised */\r
-                   /*******************************/\r
-\r
-                       DPRINTK("Tor counter not initialised\n");       \r
-                   i_ReturnValue = -5;\r
-                   } // // if (dw_Status & 0x10)\r
-                \r
-\r
-\r
-                } // switch\r
-               } // if (b_TorCounter <= 1)\r
-             else\r
-                {\r
-                /**********************************/\r
-                /* Tor counter selection is wrong */\r
-                /**********************************/\r
-\r
-                DPRINTK("Tor counter selection is wrong\n");   \r
-                i_ReturnValue = -4;\r
-                } // if (b_TorCounter <= 1)\r
-             }\r
-          else\r
-             {\r
-             /******************************************/\r
-             /* The module is not a tor counter module */\r
-             /******************************************/\r
-\r
-             DPRINTK("The module is not a tor counter module \n");     \r
-             i_ReturnValue = -3;\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /***********************/\r
-          /* Module number error */\r
-          /***********************/\r
-\r
-          DPRINTK("Module number error \n");   \r
-          i_ReturnValue = -2;\r
-          }\r
-\r
-       return (i_ReturnValue);\r
-       }\r
-\r
-\r
-\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : _INT_ i_APCI1710_GetTorCounterInitialisation           |\r
-|                                               (BYTE_     b_BoardHandle,    |\r
-|                                                BYTE_     b_ModulNbr,       |\r
-|                                               BYTE_     b_TorCounter,     |\r
-|                                               PBYTE_   pb_TimingUnit,     |\r
-|                                               PULONG_ pul_TimingInterval, |\r
-|                                               PBYTE_   pb_InputMode,      |\r
-|                                               PBYTE_   pb_ExternGate,     |\r
-|                                                PBYTE_   pb_CycleMode,      |\r
-|                                               PBYTE_   pb_Enable,         |\r
-|                                                PBYTE_   pb_InterruptEnable)|\r
-+----------------------------------------------------------------------------+\r
-| Task              : Enable the tor counter (b_TorCounter) from selected    |\r
-|                    module (b_ModulNbr). You must calling the              |\r
-|                     "i_APCI1710_InitTorCounter" function be for you call   |\r
-|                    this function.                                         |\r
-|                     If you enable the tor counter interrupt, the           |\r
-|                     tor counter generate a interrupt after the timing cycle|\r
-|                     See function "i_APCI1710_SetBoardIntRoutineX" and the  |\r
-|                     Interrupt mask description chapter from this manual.   |\r
-|                     The b_CycleMode parameter determine if you will        |\r
-|                     measured a single or more cycle.                       |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : BYTE_ b_BoardHandle  : Handle of board APCI-1710       |\r
-|                     BYTE_ b_ModulNbr     : Selected module number (0 to 3) |\r
-|                     BYTE_ b_TorCounter   : Tor counter selection (0 or 1)\r
-\r
-       b_ModulNbr                      =       CR_AREF(insn->chanspec);\r
-       b_TorCounter            =       CR_CHAN(insn->chanspec);\r
-. |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : PBYTE_  pb_TimingUnit    : Base timing unit (0 to 4)   |\r
-|                                                 0 : ns                     |\r
-|                                                 1 : µs                     |\r
-|                                                 2 : ms                     |\r
-|                                                 3 : s                      |\r
-|                                                 4 : mn                     |\r
-|                     PULONG_ pul_TimingInterval : Base timing value.        |\r
-|                    PBYTE_ pb_InputMode        : Input signal level        |\r
-|                                                 selection                 |\r
-|                                              0 : Tor count each low level |\r
-|                                              1 : Tor count each high level|\r
-|                    PBYTE_ pb_ExternGate      : Extern gate action         |\r
-|                                                selection                  |\r
-|                                                0 : Extern gate signal not |\r
-|                                                    used                   |\r
-|                                                1 : Extern gate signal used|\r
-|                     PBYTE_ pb_CycleMode       : Tor counter acquisition    |\r
-|                                                mode                       |\r
-|                    PBYTE_ pb_Enable          : Indicate if the tor counter|\r
-|                                                is enabled or no           |\r
-|                                                0 : Tor counter disabled   |\r
-|                                                1 : Tor counter enabled    |\r
-|                     PBYTE_ pb_InterruptEnable : Enable or disable the      |\r
-|                                                 tor counter interrupt.     |\r
-|                                                 APCI1710_ENABLE:           |\r
-|                                                 Enable the tor counter     |\r
-|                                                 interrupt                  |\r
-|                                                 APCI1710_DISABLE:          |\r
-|                                                 Disable the tor counter    |\r
-|                                                 interrupt \r
-       pb_TimingUnit           =       (PBYTE) &data[0];\r
-       pul_TimingInterval      =  (PULONG) &data[1];\r
-       pb_InputMode            =       (PBYTE) &data[2];\r
-       pb_ExternGate           =       (PBYTE) &data[3];\r
-       pb_CycleMode            =       (PBYTE) &data[4];\r
-       pb_Enable                       =       (PBYTE) &data[5];\r
-       pb_InterruptEnable      =       (PBYTE) &data[6];\r
-                 |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      :  0: No error                                           |\r
-|                     -1: The handle parameter of the board is wrong         |\r
-|                     -2: Module selection wrong                             |\r
-|                     -3: The module is not a tor counter module             |\r
-|                     -4: Tor counter selection is wrong                     |\r
-|                     -5: Tor counter not initialised see function           |\r
-|                         "i_APCI1710_InitTorCounter"                        |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-\r
-INT i_APCI1710_InsnReadGetTorCounterInitialisation(comedi_device *dev,comedi_subdevice *s,\r
-       comedi_insn *insn,lsampl_t *data)\r
-       {\r
-       INT    i_ReturnValue = 0;\r
-       DWORD dw_Status;\r
-       BYTE     b_ModulNbr;\r
-       BYTE     b_TorCounter;\r
-       PBYTE   pb_TimingUnit;\r
-       PULONG pul_TimingInterval;\r
-       PBYTE   pb_InputMode;\r
-       PBYTE   pb_ExternGate;\r
-       PBYTE   pb_CycleMode;\r
-       PBYTE   pb_Enable;\r
-       PBYTE   pb_InterruptEnable      ;\r
-       \r
-       i_ReturnValue           =       insn->n;\r
-       b_ModulNbr                      =       CR_AREF(insn->chanspec);\r
-       b_TorCounter            =       CR_CHAN(insn->chanspec);\r
-\r
-       pb_TimingUnit           =       (PBYTE) &data[0];\r
-       pul_TimingInterval      =  (PULONG) &data[1];\r
-       pb_InputMode            =       (PBYTE) &data[2];\r
-       pb_ExternGate           =       (PBYTE) &data[3];\r
-       pb_CycleMode            =       (PBYTE) &data[4];\r
-       pb_Enable                       =       (PBYTE) &data[5];\r
-       pb_InterruptEnable      =       (PBYTE) &data[6];\r
-\r
-       /**************************/\r
-       /* Test the module number */\r
-       /**************************/\r
-\r
-       if (b_ModulNbr < 4)\r
-          {\r
-          /***********************/\r
-          /* Test if tor counter */\r
-          /***********************/\r
-\r
-          if ((devpriv->s_BoardInfos.\r
-               dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_TOR_COUNTER)\r
-             {\r
-             /**********************************/\r
-             /* Test the tor counter selection */\r
-             /**********************************/\r
-\r
-             if (b_TorCounter <= 1)\r
-                {\r
-          \r
-                 \r
-                /***********************************/\r
-                /* Test if tor counter initialised */\r
-                /***********************************/\r
-\r
-               \r
-                       dw_Status = inl(devpriv->s_BoardInfos.\r
-                       ui_Address + 8 + (16 * b_TorCounter) + (64 * b_ModulNbr));\r
-\r
-\r
-                if (dw_Status & 0x10)\r
-                   {\r
-                   *pb_Enable = dw_Status & 1;\r
-\r
-                   /********************/\r
-                   /* Get the commando */\r
-                   /********************/\r
-\r
-               \r
-                        dw_Status=inl(devpriv->s_BoardInfos.\r
-                          ui_Address + 4 + (16 * b_TorCounter) + (64 * b_ModulNbr));\r
-\r
-                   *pb_CycleMode       = (BYTE) ((dw_Status >> 4) & 1);\r
-                   *pb_InterruptEnable = (BYTE) ((dw_Status >> 5) & 1);\r
-\r
-                   /******************************************************/\r
-                   /* Test if extern gate used for clock or for signal B */\r
-                   /******************************************************/\r
-\r
-                   if (dw_Status & 0x600)\r
-                      {\r
-                      /*****************************************/\r
-                      /* Test if extern gate used for signal B */\r
-                      /*****************************************/\r
-\r
-                      if (dw_Status & 0x400)\r
-                         {\r
-                         /***********************/\r
-                         /* Test if simple mode */\r
-                         /***********************/\r
-\r
-                         if ((dw_Status & 0x7800) == 0x7800)\r
-                            {\r
-                            *pb_InputMode = APCI1710_TOR_SIMPLE_MODE;\r
-                            }\r
-\r
-                         /***********************/\r
-                         /* Test if double mode */\r
-                         /***********************/\r
-\r
-                         if ((dw_Status & 0x7800) == 0x1800)\r
-                            {\r
-                            *pb_InputMode = APCI1710_TOR_DOUBLE_MODE;\r
-                            }\r
-\r
-                         /**************************/\r
-                         /* Test if quadruple mode */\r
-                         /**************************/\r
-\r
-                         if ((dw_Status & 0x7800) == 0x0000)\r
-                            {\r
-                            *pb_InputMode = APCI1710_TOR_QUADRUPLE_MODE;\r
-                            }\r
-                         } // if (dw_Status & 0x400)\r
-                      else\r
-                         {\r
-                         *pb_InputMode = 1;\r
-                         } // // if (dw_Status & 0x400)\r
-\r
-                      /************************/\r
-                      /* Extern gate not used */\r
-                      /************************/\r
-\r
-                      *pb_ExternGate = 0;\r
-                      } // if (dw_Status & 0x600)\r
-                   else\r
-                      {\r
-                      *pb_InputMode  = (BYTE) ((dw_Status >> 6) & 1);\r
-                      *pb_ExternGate = (BYTE) ((dw_Status >> 7) & 1);\r
-                      } // if (dw_Status & 0x600)\r
-\r
-                   *pb_TimingUnit     = devpriv->s_ModuleInfo [b_ModulNbr].\r
-                                        s_TorCounterModuleInfo.\r
-                                        s_TorCounterInfo [b_TorCounter].\r
-                                        b_TimingUnit;\r
-\r
-                   *pul_TimingInterval = devpriv->s_ModuleInfo [b_ModulNbr].\r
-                                         s_TorCounterModuleInfo.\r
-                                         s_TorCounterInfo [b_TorCounter].\r
-                                         ul_RealTimingInterval;\r
-                   }\r
-                else\r
-                   {\r
-                   /*******************************/\r
-                   /* Tor counter not initialised */\r
-                   /*******************************/\r
-\r
-                       DPRINTK("Tor counter not initialised\n");\r
-                   i_ReturnValue = -5;\r
-                   }\r
-                  \r
-                } // if (b_TorCounter <= 1)\r
-             else\r
-                {\r
-                /**********************************/\r
-                /* Tor counter selection is wrong */\r
-                /**********************************/\r
-\r
-                DPRINTK("Tor counter selection is wrong \n");\r
-                i_ReturnValue = -4;\r
-                } // if (b_TorCounter <= 1)\r
-             }\r
-          else\r
-             {\r
-             /******************************************/\r
-             /* The module is not a tor counter module */\r
-             /******************************************/\r
-\r
-             DPRINTK("The module is not a tor counter module\n");\r
-             i_ReturnValue = -3;\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /***********************/\r
-          /* Module number error */\r
-          /***********************/\r
-\r
-          DPRINTK("Module number error\n");\r
-          i_ReturnValue = -2;\r
-          }\r
-\r
-       return (i_ReturnValue);\r
-       }\r
-\r
-\r
-\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : _INT_ i_APCI1710_ReadTorCounterValue                   |\r
-|                               (BYTE_     b_BoardHandle,                    |\r
-|                                BYTE_     b_ModulNbr,                       |\r
-|                               BYTE_     b_TorCounter,                     |\r
-|                                UINT_    ui_TimeOut,                        |\r
-|                                PBYTE_   pb_TorCounterStatus,               |\r
-|                                PULONG_ pul_TorCounterValue)                |\r
-+----------------------------------------------------------------------------+\r
-| Task         case APCI1710_TOR_GETPROGRESSSTATUS: Return the tor counter \r
-(b_TorCounter) status (pb_TorCounterStatus) from selected tor counter        |\r
-|                    module (b_ModulNbr). \r
-               \r
-                                case APCI1710_TOR_GETCOUNTERVALUE :\r
-  Return the tor counter (b_TorCounter) status           |\r
-|                    (pb_TorCounterStatus) and the timing value             |\r
-|                    (pul_TorCounterValue) after a conting cycle stop       |\r
-|                     from selected tor counter module (b_ModulNbr).         |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : BYTE_ b_BoardHandle  : Handle of board APCI-1710       |\r
-|                     BYTE_ b_ModulNbr     : Selected module number (0 to 3) |\r
-|                     BYTE_ b_TorCounter   : Tor counter selection (0 or 1).\r
-       b_ModulNbr    = CR_AREF(insn->chanspec);\r
-       b_ReadType    = (BYTE) data[0]; \r
-       b_TorCounter  = (BYTE) data[1];\r
-       ui_TimeOut        = (UINT) data[2]; |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : PBYTE_  pb_TorCounterStatus : Return the tor counter   |\r
-|                                                    status.                 |\r
-|                                               0 : Conting cycle not started|\r
-|                                                   Software gate not set.   |\r
-|                                               1 : Conting cycle started.   |\r
-|                                                   Software gate set.       |\r
-|                                               2 : Conting cycle stopped.   |\r
-|                                                   The conting cycle is     |\r
-|                                                   terminate.               |\r
-|                                               3 : A overflow occur. You    |\r
-|                                                   must change the base     |\r
-|                                                   timing witch the         |\r
-|                                                   function                 |\r
-|                                                 "i_APCI1710_InitTorCounter"|\r
-|                                              4 : Timeeout occur           |\r
-|                     PULONG  pul_TorCounterValue  : Tor counter value.  \r
-       pb_TorCounterStatus=(PBYTE) &data[0];\r
-       pul_TorCounterValue=(PULONG) &data[1];    |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      :  0: No error                                           |\r
-|                     -1: The handle parameter of the board is wrong         |\r
-|                     -2: Module selection wrong                             |\r
-|                     -3: The module is not a tor counter module             |\r
-|                     -4: Tor counter selection is wrong                     |\r
-|                     -5: Tor counter not initialised see function           |\r
-|                         "i_APCI1710_InitTorCounter"                        |\r
-|                     -6: Tor counter not enabled see function               |\r
-|                         "i_APCI1710_EnableTorCounter"                      |\r
-|                     -7: Timeout parameter is wrong (0 to 65535)            |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-\r
-INT i_APCI1710_InsnBitsGetTorCounterProgressStatusAndValue(comedi_device *dev,comedi_subdevice *s,\r
-       comedi_insn *insn,lsampl_t *data)\r
-       {\r
-       INT    i_ReturnValue = 0;\r
-       DWORD  dw_Status;\r
-       DWORD  dw_TimeOut = 0;\r
-\r
-       BYTE    b_ModulNbr;\r
-       BYTE    b_TorCounter;\r
-       BYTE    b_ReadType;\r
-       UINT    ui_TimeOut;\r
-       PBYTE   pb_TorCounterStatus;\r
-       PULONG  pul_TorCounterValue;\r
-\r
-       i_ReturnValue = insn->n;\r
-       b_ModulNbr    = CR_AREF(insn->chanspec);\r
-       b_ReadType    = (BYTE) data[0]; \r
-       b_TorCounter  = (BYTE) data[1];\r
-       ui_TimeOut        = (UINT) data[2];\r
-       pb_TorCounterStatus=(PBYTE) &data[0];\r
-       pul_TorCounterValue=(PULONG) &data[1];\r
-       \r
-       /**************************/\r
-       /* Test the module number */\r
-       /**************************/\r
-\r
-\r
-        if(b_ReadType==APCI1710_TOR_READINTERRUPT)\r
-        {\r
-         \r
-                       data[0]=devpriv->s_InterruptParameters.\r
-                                                     s_FIFOInterruptParameters [devpriv->\r
-                                                                                s_InterruptParameters.\r
-                                                                                ui_Read].b_OldModuleMask;\r
-                       data[1]=devpriv->s_InterruptParameters.\r
-                                                     s_FIFOInterruptParameters [devpriv->\r
-                                                                                s_InterruptParameters.\r
-                                                                                ui_Read].ul_OldInterruptMask;\r
-                       data[2]=devpriv->s_InterruptParameters.\r
-                                                     s_FIFOInterruptParameters [devpriv->\r
-                                                                                s_InterruptParameters.\r
-                                                                                ui_Read].ul_OldCounterLatchValue;\r
-\r
-                            \r
-                          /**************************/\r
-                          /* Increment the read FIFO */\r
-                          /***************************/\r
-\r
-                          devpriv->\r
-                          s_InterruptParameters.\r
-                          ui_Read = (devpriv->\r
-                          s_InterruptParameters.\r
-                          ui_Read + 1) % APCI1710_SAVE_INTERRUPT;\r
\r
-         return insn->n;\r
-        } \r
-\r
-       if (b_ModulNbr < 4)\r
-          {\r
-          /***********************/\r
-          /* Test if tor counter */\r
-          /***********************/\r
-\r
-          if ((devpriv->s_BoardInfos.\r
-               dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_TOR_COUNTER)\r
-             {\r
-             /**********************************/\r
-             /* Test the tor counter selection */\r
-             /**********************************/\r
-\r
-             if (b_TorCounter <= 1)\r
-                {\r
-                /***********************************/\r
-                /* Test if tor counter initialised */\r
-                /***********************************/\r
-\r
-               \r
-\r
-                       dw_Status=inl(devpriv->s_BoardInfos.\r
-                       ui_Address + 8 + (16 * b_TorCounter) + (64 * b_ModulNbr));\r
-\r
-                /*******************************/\r
-                /* Test if counter initialised */\r
-                /*******************************/\r
-\r
-                if (dw_Status & 0x10)\r
-                   {\r
-                   /***************************/\r
-                   /* Test if counter enabled */\r
-                   /***************************/\r
-\r
-                   if (dw_Status & 0x1)\r
-                      {\r
-                  \r
-                               switch(b_ReadType)\r
-                               {\r
-\r
-                               case APCI1710_TOR_GETPROGRESSSTATUS:\r
-                       /*******************/\r
-                      /* Read the status */\r
-                      /*******************/\r
-               \r
-                                       dw_Status=inl(devpriv->s_BoardInfos.\r
-                              ui_Address + 4 + (16 * b_TorCounter) + (64 * b_ModulNbr));\r
-\r
-                      dw_Status = dw_Status & 0xF;\r
-\r
-                      /*****************/\r
-                      /* Test if start */\r
-                      /*****************/\r
-\r
-                      if (dw_Status & 1)\r
-                         {\r
-                         if (dw_Status & 2)\r
-                            {\r
-                            if (dw_Status & 4)\r
-                               {\r
-                               /************************/\r
-                               /* Tor counter owerflow */\r
-                               /************************/\r
-\r
-                               *pb_TorCounterStatus = 3;\r
-                               }\r
-                            else\r
-                               {\r
-                               /***********************/\r
-                               /* Tor counter started */\r
-                               /***********************/\r
-\r
-                               *pb_TorCounterStatus = 2;\r
-                               }\r
-                            }\r
-                         else\r
-                            {\r
-                            /***********************/\r
-                            /* Tor counter started */\r
-                            /***********************/\r
-\r
-                            *pb_TorCounterStatus = 1;\r
-                            }\r
-                         }\r
-                      else\r
-                         {\r
-                         /***************************/\r
-                         /* Tor counter not started */\r
-                         /***************************/\r
-\r
-                         *pb_TorCounterStatus = 0;\r
-                         }\r
-                        break;\r
-\r
-                case APCI1710_TOR_GETCOUNTERVALUE :\r
-                               \r
-                      /*****************************/\r
-                      /* Test the timout parameter */\r
-                      /*****************************/\r
-\r
-                      if ((ui_TimeOut >= 0) && (ui_TimeOut <= 65535UL))\r
-                         {\r
-                         for (;;)\r
-                            {\r
-                            /*******************/\r
-                            /* Read the status */\r
-                            /*******************/\r
-                               \r
-                               dw_Status=inl(devpriv->s_BoardInfos.\r
-                                   ui_Address + 4 + (16 * b_TorCounter) + (64 * b_ModulNbr));\r
-                            /********************/\r
-                            /* Test if overflow */\r
-                            /********************/\r
-\r
-                            if ((dw_Status & 4) == 4)\r
-                               {\r
-                               /******************/\r
-                               /* Overflow occur */\r
-                               /******************/\r
-\r
-                               *pb_TorCounterStatus = 3;\r
-\r
-                               /******************/\r
-                               /* Read the value */\r
-                               /******************/\r
-\r
-                       \r
-                               *pul_TorCounterValue=inl(devpriv->s_BoardInfos.\r
-                                      ui_Address + 0 + (16 * b_TorCounter) + (64 * b_ModulNbr));\r
-                               break;\r
-                               } // if ((dw_Status & 4) == 4)\r
-                            else\r
-                               {\r
-                               /*******************************/\r
-                               /* Test if measurement stopped */\r
-                               /*******************************/\r
-\r
-                               if ((dw_Status & 2) == 2)\r
-                                  {\r
-                                  /***********************/\r
-                                  /* A stop signal occur */\r
-                                  /***********************/\r
-\r
-                                  *pb_TorCounterStatus = 2;\r
-\r
-                                  /******************/\r
-                                  /* Read the value */\r
-                                  /******************/\r
-\r
-\r
-                                    *pul_TorCounterValue=inl(devpriv->s_BoardInfos.\r
-                                         ui_Address + 0 + (16 * b_TorCounter) + (64 * b_ModulNbr));\r
-\r
-                                  break;\r
-                                  } // if ((dw_Status & 2) == 2)\r
-                               else\r
-                                  {\r
-                                  /*******************************/\r
-                                  /* Test if measurement started */\r
-                                  /*******************************/\r
-\r
-                                  if ((dw_Status & 1) == 1)\r
-                                     {\r
-                                     /************************/\r
-                                     /* A start signal occur */\r
-                                     /************************/\r
-\r
-                                     *pb_TorCounterStatus = 1;\r
-                                     } // if ((dw_Status & 1) == 1)\r
-                                  else\r
-                                     {\r
-                                     /***************************/\r
-                                     /* Measurement not started */\r
-                                     /***************************/\r
-\r
-                                     *pb_TorCounterStatus = 0;\r
-                                     } // if ((dw_Status & 1) == 1)\r
-                                  } // if ((dw_Status & 2) == 2)\r
-                               } // if ((dw_Status & 8) == 8)\r
-\r
-                            if (dw_TimeOut == ui_TimeOut)\r
-                               {\r
-                               /*****************/\r
-                               /* Timeout occur */\r
-                               /*****************/\r
-\r
-                               break;\r
-                               }\r
-                            else\r
-                               {\r
-                               /*************************/\r
-                               /* Increment the timeout */\r
-                               /*************************/\r
-\r
-                               dw_TimeOut = dw_TimeOut + 1;\r
-                       \r
-                               mdelay(1000);\r
-                               }\r
-                            } // for (;;)\r
-\r
-                         /*************************/\r
-                         /* Test if timeout occur */\r
-                         /*************************/\r
-\r
-                         if ((*pb_TorCounterStatus != 3) && (dw_TimeOut == ui_TimeOut) && (ui_TimeOut != 0))\r
-                            {\r
-                            /*****************/\r
-                            /* Timeout occur */\r
-                            /*****************/\r
-\r
-                            *pb_TorCounterStatus = 4;\r
-                            }\r
-                         }\r
-                      else\r
-                         {\r
-                         /******************************/\r
-                         /* Timeout parameter is wrong */\r
-                         /******************************/\r
-\r
-                     DPRINTK("Timeout parameter is wrong\n");\r
-                         i_ReturnValue = -7;\r
-                         }\r
-                          break;\r
-\r
-           \r
-             default:\r
-                                printk("Inputs wrong\n");\r
-                       } // switch end\r
-                      } // if (dw_Status & 0x1)\r
-                   else\r
-                      {\r
-                      /***************************/\r
-                      /* Tor counter not enabled */\r
-                      /***************************/\r
-\r
-                          DPRINTK("Tor counter not enabled\n");\r
-                      i_ReturnValue = -6;\r
-                      } // if (dw_Status & 0x1)\r
-                   }\r
-                else\r
-                   {\r
-                   /*******************************/\r
-                   /* Tor counter not initialised */\r
-                   /*******************************/\r
-\r
-                       DPRINTK("Tor counter not initialised\n");\r
-                   i_ReturnValue = -5;\r
-                   }\r
-                } // if (b_TorCounter <= 1)\r
-             else\r
-                {\r
-                /**********************************/\r
-                /* Tor counter selection is wrong */\r
-                /**********************************/\r
-\r
-                 DPRINTK("Tor counter selection is wrong\n");\r
-                i_ReturnValue = -4;\r
-                } // if (b_TorCounter <= 1)\r
-             }\r
-          else\r
-             {\r
-             /******************************************/\r
-             /* The module is not a tor counter module */\r
-             /******************************************/\r
-\r
-              DPRINTK("The module is not a tor counter module\n");     \r
-             i_ReturnValue = -3;\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /***********************/\r
-          /* Module number error */\r
-          /***********************/\r
-\r
-           DPRINTK("Module number error\n");   \r
-          i_ReturnValue = -2;\r
-          }\r
-\r
-       \r
-       return (i_ReturnValue);\r
-       }\r
-\r
-\r
+/**
+@verbatim
+
+Copyright (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 USA
+
+You 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 */
+                                             /*****************************/
+
+                                             ul_RealTimingInterval = (ULONG) (ul_TimerValue / (250.0 * (double) b_PCIInputClock));
+                                             d_RealTimingInterval = (double) ul_TimerValue / (250.0 * (double) b_PCIInputClock);
+
+                                             if ((double) ((double) ul_TimerValue / (250.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) * 1.007752288);
+                                                }
+                                          
+
+                                          break;
+
+                                     /*****/
+                                     /* s */
+                                     /*****/
+
+                                     case 3:
+                                          
+                                             /******************/
+                                             /* Timer 0 factor */
+                                             /******************/
+
+                                             ul_TimerValue = (ULONG) (ul_TimingInterval * (250000.0 * b_PCIInputClock));
+
+                                             /*******************/
+                                             /* Round the value */
+                                             /*******************/
+
+                                             if ((double) ((double) ul_TimingInterval * (250000.0 * (double) b_PCIInputClock)) >= ((double) ((double) ul_TimerValue + 0.5)))
+                                                {
+                                                ul_TimerValue = ul_TimerValue + 1;
+                                                }
+
+                                             /*****************************/
+                                             /* Calculate the real timing */
+                                             /*****************************/
+
+                                             ul_RealTimingInterval = (ULONG) (ul_TimerValue / (250000.0 * (double) b_PCIInputClock));
+                                             d_RealTimingInterval = (double) ul_TimerValue / (250000.0 * (double) b_PCIInputClock);
+
+                                             if ((double) ((double) ul_TimerValue / (250000.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) * 1.007752288);
+                                                }
+                                          
+
+                                          break;
+
+                                     /******/
+                                     /* mn */
+                                     /******/
+
+                                     case 4:
+                                          
+                                             /******************/
+                                             /* Timer 0 factor */
+                                             /******************/
+
+                                             ul_TimerValue = (ULONG) ((ul_TimingInterval * 60) * (250000.0 * b_PCIInputClock));
+
+                                             /*******************/
+                                             /* Round the value */
+                                             /*******************/
+
+                                             if ((double) ((double) (ul_TimingInterval * 60.0) * (250000.0 * (double) b_PCIInputClock)) >= ((double) ((double) ul_TimerValue + 0.5)))
+                                                {
+                                                ul_TimerValue = ul_TimerValue + 1;
+                                                }
+
+                                             /*****************************/
+                                             /* Calculate the real timing */
+                                             /*****************************/
+
+                                             ul_RealTimingInterval = (ULONG) (ul_TimerValue / (250000.0 * (double) b_PCIInputClock)) / 60;
+                                             d_RealTimingInterval = ((double) ul_TimerValue / (250000.0 * (double) b_PCIInputClock)) / 60.0;
+
+                                             if ((double) (((double) ul_TimerValue / (250000.0 * (double) b_PCIInputClock)) / 60.0) >= (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;
+                                     }
+                                     
+                                  fpu_end ();
+                                  } // if (b_PCIInputClock != APCI1710_GATE_INPUT)
+                               else
+                                  {
+                                  /*************************************************************/
+                                  /* 2 Clock used for the overflow and the reload from counter */
+                                  /*************************************************************/
+
+                                  ul_TimerValue = ul_TimingInterval - 2;
+                                  } // if (b_PCIInputClock != APCI1710_GATE_INPUT)
+
+                               /****************************/
+                               /* Save the PCI input clock */
+                               /****************************/
+                               devpriv->s_ModuleInfo [b_ModulNbr].
+                               s_TorCounterModuleInfo.
+                               b_PCIInputClock = b_PCIInputClock;
+
+                               /************************/
+                               /* Save the timing unit */
+                               /************************/
+
+                               devpriv->s_ModuleInfo [b_ModulNbr].
+                               s_TorCounterModuleInfo.
+                               s_TorCounterInfo [b_TorCounter].
+                               b_TimingUnit = b_TimingUnit;
+
+                               /************************/
+                               /* Save the base timing */
+                               /************************/
+                               devpriv->s_ModuleInfo [b_ModulNbr].
+                               s_TorCounterModuleInfo.
+                               s_TorCounterInfo [b_TorCounter].
+                               d_TimingInterval = d_RealTimingInterval;
+
+                               devpriv->s_ModuleInfo [b_ModulNbr].
+                               s_TorCounterModuleInfo.
+                               s_TorCounterInfo [b_TorCounter].
+                               ul_RealTimingInterval = ul_RealTimingInterval;
+
+                               /*******************/
+                               /* Get the command */
+                               /*******************/
+
+                               
+                               dw_Command = inl(devpriv->s_BoardInfos.ui_Address + 4 + (16 * b_TorCounter) + (64 * b_ModulNbr));
+
+                               dw_Command = (dw_Command >> 4) & 0xF;
+
+                               /******************/
+                               /* Test if 40 MHz */
+                               /******************/
+
+                               if (b_PCIInputClock == APCI1710_40MHZ)
+                                  {
+                                  /****************************/
+                                  /* Set the 40 MHz selection */
+                                  /****************************/
+
+                                  dw_Command = dw_Command | 0x10;
+                                  }
+
+                               /*****************************/
+                               /* Test if extern clock used */
+                               /*****************************/
+
+                               if (b_PCIInputClock == APCI1710_GATE_INPUT)
+                                  {
+                                  /****************************/
+                                  /* Set the 40 MHz selection */
+                                  /****************************/
+
+                                  dw_Command = dw_Command | 0x20;
+                                  }
+
+                               /*************************/
+                               /* Write the new command */
+                               /*************************/
+
+                       
+                               outl(dw_Command,devpriv->s_BoardInfos.ui_Address + 4 + (16 * b_TorCounter) + (64 * b_ModulNbr));
+                               /*******************/
+                               /* Disable the tor */
+                               /*******************/
+                               
+                               outl(0,devpriv->s_BoardInfos.
+                                       ui_Address + 8 + (16 * b_TorCounter) + (64 * b_ModulNbr));
+                               /*************************/
+                               /* Set the timer 1 value */
+                               /*************************/
+
+                       
+                               outl(ul_TimerValue,devpriv->s_BoardInfos.ui_Address + 0 + (16 * b_TorCounter) + (64 * b_ModulNbr));
+
+                               /*********************/
+                               /* Tor counter init. */
+                               /*********************/
+
+                               devpriv->s_ModuleInfo [b_ModulNbr].
+                               s_TorCounterModuleInfo.
+                               s_TorCounterInfo [b_TorCounter].
+                               b_TorCounterInit = 1;
+                               }
+                            else
+                               {
+                               /***********************************************/
+                               /* TOR version error for 40MHz clock selection */
+                               /***********************************************/
+
+                       DPRINTK("TOR version error for 40MHz clock selection\n");
+                               i_ReturnValue = -9;
+                               }
+                            }
+                         else
+                            {
+                            /**************************************************************/
+                            /* You can not used the 40MHz clock selection wich this board */
+                            /**************************************************************/
+
+                                DPRINTK("You can not used the 40MHz clock selection wich this board\n");
+                            i_ReturnValue = -8;
+                            }
+                         }
+                      else
+                         {
+                         /**********************************/
+                         /* Base timing selection is wrong */
+                         /**********************************/
+
+                         DPRINTK("Base timing selection is wrong\n");
+                         i_ReturnValue = -7;
+                         }
+                      } // if ((b_TimingUnit >= 0) && (b_TimingUnit <= 4))
+                   else
+                      {
+                      /**********************************/
+                      /* Timing unit selection is wrong */
+                      /**********************************/
+
+                          DPRINTK("Timing unit selection is wrong\n");          
+                      i_ReturnValue = -6;
+                      } // if ((b_TimingUnit >= 0) && (b_TimingUnit <= 4))
+                   } // if ((b_PCIInputClock == APCI1710_30MHZ) || (b_PCIInputClock == APCI1710_33MHZ))
+                else
+                   {
+                   /*****************************************/
+                   /* The selected PCI input clock is wrong */
+                   /*****************************************/
+
+                       DPRINTK("The selected PCI input clock is wrong\n");
+                   i_ReturnValue = -5;
+                   } // if ((b_PCIInputClock == APCI1710_30MHZ) || (b_PCIInputClock == APCI1710_33MHZ))
+                } // if (b_TorCounterMode >= 0 && b_TorCounterMode <= 7)
+             else
+                {
+                /**********************************/
+                /* Tor Counter selection is wrong */
+                /**********************************/
+
+                DPRINTK("Tor Counter selection is wrong\n");
+                i_ReturnValue = -4;
+                } // if (b_TorCounterMode >= 0 && b_TorCounterMode <= 7)
+             }
+          else
+             {
+             /******************************************/
+             /* The module is not a tor counter module */
+             /******************************************/
+
+             DPRINTK("The module is not a tor counter module\n");              
+             i_ReturnValue = -3;
+             }
+          }
+       else
+          {
+          /***********************/
+          /* Module number error */
+          /***********************/
+
+          DPRINTK("Module number error\n");
+          i_ReturnValue = -2;
+          }
+    data[0] = (UINT) ul_RealTimingInterval;
+       return (i_ReturnValue);
+       }
+
+
+
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     : _INT_ i_APCI1710_EnableTorCounter                      |
+|                                               (BYTE_ b_BoardHandle,        |
+|                                                BYTE_ b_ModulNbr,           |
+|                                               BYTE_ b_TorCounter,         |
+|                                               BYTE_ b_InputMode,          |
+|                                               BYTE_ b_ExternGate,         |
+|                                                BYTE_ b_CycleMode,          |
+|                                                BYTE_ b_InterruptEnable)    |
++----------------------------------------------------------------------------+
+| Task              : Enable the tor counter (b_TorCounter) from selected    |
+|                    module (b_ModulNbr). You must calling the              |
+|                     "i_APCI1710_InitTorCounter" function be for you call   |
+|                    this function.                                         |
+|                     If you enable the tor counter interrupt, the           |
+|                     tor counter generate a interrupt after the timing cycle|
+|                     See function "i_APCI1710_SetBoardIntRoutineX" and the  |
+|                     Interrupt mask description chapter from this manual.   |
+|                     The b_CycleMode parameter determine if you will        |
+|                     measured a single or more cycle.                       |
++----------------------------------------------------------------------------+
+| Input Parameters  : BYTE_ b_BoardHandle  : Handle of board APCI-1710       |
+|                     BYTE_ b_ModulNbr     : Selected module number (0 to 3) |
+|                     BYTE_ b_TorCounter   : Tor counter selection (0 or 1). |
+|                    BYTE_ b_InputMode    : Input signal level selection    |
+|                                              0 : Tor count each low level |
+|                                              1 : Tor count each high level|
+|                    BYTE_ b_ExternGate   : Extern gate action selection    |
+|                                              0 : Extern gate signal not   |
+|                                                  used                     |
+|                                              1 : Extern gate signal used. |
+|                                                  If you selected the      |
+|                                                  single mode, each high   |
+|                                                  level signal start the   |
+|                                                  counter.                 |
+|                                                  If you selected the      |
+|                                                  continuous mode, the     |
+|                                                  first high level signal  |
+|                                                  start the tor counter    |
+|                                                                           |
+|                                            APCI1710_TOR_QUADRUPLE _MODE : |
+|                                            In the quadruple mode, the edge|
+|                                            analysis circuit generates a   |
+|                                            counting pulse from each edge  |
+|                                            of 2 signals which are phase   |
+|                                            shifted in relation to each    |
+|                                            other.                         |
+|                                            The gate input is used for the |
+|                                            signal B                       |
+|                                                                           |
+|                                            APCI1710_TOR_DOUBLE_MODE:      |
+|                                            Functions in the same way as   |
+|                                            the quadruple mode, except that|
+|                                            only two of the four edges are |
+|                                            analysed per period.           |
+|                                            The gate input is used for the |
+|                                            signal B                       |
+|                                                                           |
+|                                            APCI1710_TOR_SIMPLE_MODE:      |
+|                                            Functions in the same way as   |
+|                                            the quadruple mode, except that|
+|                                            only one of the four edges is  |
+|                                            analysed per period.           |
+|                                            The gate input is used for the |
+|                                            signal B                       |
+|                                                                           |
+|                     BYTE_ b_CycleMode    : Selected the tor counter        |
+|                                            acquisition mode                |
+|                     BYTE_ b_InterruptEnable : Enable or disable the        |
+|                                               tor counter interrupt.       |
+|                                               APCI1710_ENABLE:             |
+|                                               Enable the tor counter       |
+|                                               interrupt                    |
+|                                               APCI1710_DISABLE:            |
+|                                               Disable the tor counter      |
+|                                               interrupt                    |
++----------------------------------------------------------------------------+
+| Output Parameters : -                                                      |
++----------------------------------------------------------------------------+
+| 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: Tor counter not initialised see function           |
+|                         "i_APCI1710_InitTorCounter"                        |
+|                     -6: Tor input signal selection is wrong                |
+|                     -7: Extern gate signal mode is wrong                   |
+|                     -8: Tor counter acquisition mode cycle is wrong        |
+|                     -9: Interrupt parameter is wrong                       |
+|                     -10:Interrupt function not initialised.                |
+|                         See function "i_APCI1710_SetBoardIntRoutineX"      |
++----------------------------------------------------------------------------+
+*/
+/*
++----------------------------------------------------------------------------+
+| Function Name     : _INT_ i_APCI1710_DisableTorCounter                     |
+|                                               (BYTE_  b_BoardHandle,       |
+|                                                BYTE_  b_ModulNbr,          |
+|                                               BYTE_  b_TorCounter)        |
++----------------------------------------------------------------------------+
+| Task              : Disable the tor counter (b_TorCounter) from selected   |
+|                    module (b_ModulNbr). If you disable the tor counter    |
+|                    after a start cycle occur and you restart the tor      |
+|                    counter witch the " i_APCI1710_EnableTorCounter"       |
+|                    function, the status register is cleared               |
++----------------------------------------------------------------------------+
+| Input Parameters  : BYTE_ b_BoardHandle  : Handle of board APCI-1710       |
+|                     BYTE_ b_ModulNbr     : Selected module number (0 to 3) |
+|                     BYTE_ b_TorCounter   : Tor counter selection (0 or 1). |
++----------------------------------------------------------------------------+
+| Output Parameters : -                                                      |
++----------------------------------------------------------------------------+
+| 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: Tor counter not initialised see function           |
+|                         "i_APCI1710_InitTorCounter"                        |
+|                     -6: Tor counter not enabled see function               |
+|                         "i_APCI1710_EnableTorCounter"                      |
++----------------------------------------------------------------------------+
+*/
+
+
+
+INT  i_APCI1710_InsnWriteEnableDisableTorCounter (comedi_device *dev,comedi_subdevice *s,
+       comedi_insn *insn,lsampl_t *data)
+       {
+       INT    i_ReturnValue = 0;
+       DWORD dw_Status;
+       DWORD dw_DummyRead;
+       DWORD dw_ConfigReg;
+       BYTE b_ModulNbr,b_Action;
+       BYTE b_TorCounter;
+       BYTE b_InputMode;
+       BYTE b_ExternGate;
+       BYTE b_CycleMode;
+       BYTE b_InterruptEnable;
+
+       b_ModulNbr                      =(BYTE) CR_AREF(insn->chanspec);
+       b_Action                        =(BYTE) data[0]; // enable or disable
+       b_TorCounter            =(BYTE) data[1];
+       b_InputMode                     =(BYTE) data[2] ;
+       b_ExternGate            =(BYTE) data[3] ;
+       b_CycleMode                     =(BYTE) data[4] ;
+       b_InterruptEnable       =(BYTE) data[5] ;
+       i_ReturnValue           = insn->n;      ;
+       devpriv->tsk_Current=current; // Save the current process task structure
+       /**************************/
+       /* 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)
+                {
+          switch(b_Action)// Enable or Disable
+                 {
+                 case APCI1710_ENABLE :
+                /***********************************/
+                /* Test if tor counter initialised */
+                /***********************************/
+
+               
+
+               dw_Status =inl(devpriv->s_BoardInfos.ui_Address + 8 + (16 * b_TorCounter) + (64 * b_ModulNbr));
+
+                if (dw_Status & 0x10)
+                   {
+                   /******************************/
+                   /* Test the input signal mode */
+                   /******************************/
+
+                   if (b_InputMode == 0                           ||
+                       b_InputMode == 1                                 ||
+                       b_InputMode == APCI1710_TOR_SIMPLE_MODE    ||
+                       b_InputMode == APCI1710_TOR_DOUBLE_MODE    ||
+                       b_InputMode == APCI1710_TOR_QUADRUPLE_MODE)
+                      {
+                      /************************************/
+                      /* Test the extern gate signal mode */
+                      /************************************/
+
+                     if (b_ExternGate == 0 || b_ExternGate == 1 || b_InputMode > 1)
+                         {
+                         /*********************************/
+                         /* Test the cycle mode parameter */
+                         /*********************************/
+
+                         if ((b_CycleMode == APCI1710_SINGLE) || (b_CycleMode == APCI1710_CONTINUOUS))
+                            {
+                            /***************************/
+                            /* Test the interrupt flag */
+                            /***************************/
+
+                            if ((b_InterruptEnable == APCI1710_ENABLE) || (b_InterruptEnable == APCI1710_DISABLE))
+                               {
+
+                               
+                               
+                                  /***************************/
+                                  /* Save the interrupt mode */
+                                  /***************************/
+
+                                  devpriv->s_ModuleInfo [b_ModulNbr].
+                                  s_TorCounterModuleInfo.
+                                  s_TorCounterInfo [b_TorCounter].
+                                  b_InterruptEnable = b_InterruptEnable;
+
+                                  /*******************/
+                                  /* Get the command */
+                                  /*******************/
+
+                                 
+                                  dw_ConfigReg = inl(devpriv->s_BoardInfos.ui_Address + 4 + (16 * b_TorCounter) + (64 * b_ModulNbr));
+
+                                  dw_ConfigReg = (dw_ConfigReg >> 4) & 0x30;
+
+                                  /********************************/
+                                  /* Test if not direct mode used */
+                                  /********************************/
+
+                                  if (b_InputMode > 1)
+                                     {
+                                     /*******************************/
+                                     /* Extern gate can not be used */
+                                     /*******************************/
+
+                                     b_ExternGate = 0;
+
+                                     /*******************************************/
+                                     /* Enable the extern gate for the Signal B */
+                                     /*******************************************/
+
+                                     dw_ConfigReg = dw_ConfigReg | 0x40;
+
+                                     /***********************/
+                                     /* Test if simple mode */
+                                     /***********************/
+
+                                     if (b_InputMode == APCI1710_TOR_SIMPLE_MODE)
+                                        {
+                                        /**************************/
+                                        /* Enable the sinple mode */
+                                        /**************************/
+
+                                        dw_ConfigReg = dw_ConfigReg | 0x780;
+
+                                        } // if (b_InputMode == APCI1710_TOR_SIMPLE_MODE)
+
+                                     /***********************/
+                                     /* Test if double mode */
+                                     /***********************/
+
+                                     if (b_InputMode == APCI1710_TOR_DOUBLE_MODE)
+                                        {
+                                        /**************************/
+                                        /* Enable the double mode */
+                                        /**************************/
+
+                                        dw_ConfigReg = dw_ConfigReg | 0x180;
+
+                                        } // if (b_InputMode == APCI1710_TOR_DOUBLE_MODE)
+
+                                     b_InputMode = 0;
+                                     } // if (b_InputMode > 1)
+
+                                  /*******************/
+                                  /* Set the command */
+                                  /*******************/
+
+                                  dw_ConfigReg = dw_ConfigReg | b_CycleMode | (b_InterruptEnable * 2) | (b_InputMode * 4) | (b_ExternGate * 8);
+
+                                  /*****************************/
+                                  /* Clear the status register */
+                                  /*****************************/
+
+                                
+                                     dw_DummyRead = inl(devpriv->s_BoardInfos.
+                                         ui_Address + 0 + (16 * b_TorCounter) + (64 * b_ModulNbr));
+
+                                  /***************************************/
+                                  /* Clear the interrupt status register */
+                                  /***************************************/
+
+                               
+                                   dw_DummyRead=inl(devpriv->s_BoardInfos.
+                                         ui_Address + 12 + (16 * b_TorCounter) + (64 * b_ModulNbr));  
+
+                                  /********************/
+                                  /* Set the commando */
+                                  /********************/
+
+
+                                       outl(dw_ConfigReg,devpriv->s_BoardInfos.
+                                               ui_Address + 4 + (16 * b_TorCounter) + (64 * b_ModulNbr));
+
+                                  /****************/
+                                  /* Set the gate */
+                                  /****************/
+                               
+
+                                       outl(1,devpriv->s_BoardInfos.
+                                          ui_Address + 8 + (16 * b_TorCounter) + (64 * b_ModulNbr));
+                                  
+                               } // if ((b_InterruptEnable == APCI1710_ENABLE) || (b_InterruptEnable == APCI1710_DISABLE))
+                            else
+                               {
+                               /********************************/
+                               /* Interrupt parameter is wrong */
+                               /********************************/
+
+                               DPRINTK("Interrupt parameter is wrong\n");
+                               i_ReturnValue = -9;
+                               } // if ((b_InterruptEnable == APCI1710_ENABLE) || (b_InterruptEnable == APCI1710_DISABLE))
+                            } // if ((b_CycleMode == APCI1710_SINGLE) || (b_CycleMode == APCI1710_CONTINUOUS))
+                         else
+                            {
+                            /***********************************************/
+                            /* Tor counter acquisition mode cycle is wrong */
+                            /***********************************************/
+
+                                DPRINTK("Tor counter acquisition mode cycle is wrong\n");
+                            i_ReturnValue = -8;
+                            } // if ((b_CycleMode == APCI1710_SINGLE) || (b_CycleMode == APCI1710_CONTINUOUS))
+                         } // if (b_ExternGate >= 0 && b_ExternGate <= 1)
+                      else
+                         {
+                         /***********************************/
+                         /* Extern gate input mode is wrong */
+                         /***********************************/
+
+                         DPRINTK("Extern gate input mode is wrong\n");
+                         i_ReturnValue = -7;
+                         } // if (b_ExternGate >= 0 && b_ExternGate <= 1)
+                      } // if (b_InputMode >= 0 && b_InputMode <= 1)
+                   else
+                      {
+                      /***************************************/
+                      /* Tor input signal selection is wrong */
+                      /***************************************/
+
+                          DPRINTK("Tor input signal selection is wrong\n");
+                      i_ReturnValue = -6;
+                      }
+                   }
+                else
+                   {
+                   /*******************************/
+                   /* Tor counter not initialised */
+                   /*******************************/
+
+                       DPRINTK("Tor counter not initialised\n");
+                   i_ReturnValue = -5;
+                   }
+                break;
+
+        case APCI1710_DISABLE :
+                        /***********************************/
+                /* Test if tor counter initialised */
+                /***********************************/
+               
+                       dw_Status = inl(devpriv->s_BoardInfos.
+                       ui_Address + 8 + (16 * b_TorCounter) + (64 * b_ModulNbr));
+
+                /*******************************/
+                /* Test if counter initialised */
+                /*******************************/
+
+                if (dw_Status & 0x10)
+                   {
+                   /***************************/
+                   /* Test if counter enabled */
+                   /***************************/
+
+                   if (dw_Status & 0x1)
+                      {
+                      /****************************/
+                      /* Clear the interrupt mode */
+                      /****************************/
+                               devpriv->s_ModuleInfo [b_ModulNbr].
+                      s_TorCounterModuleInfo.
+                      s_TorCounterInfo [b_TorCounter].
+                      b_InterruptEnable = APCI1710_DISABLE;
+
+
+                      /******************/
+                      /* Clear the gate */
+                      /******************/
+                       
+                               outl(0,devpriv->s_BoardInfos.ui_Address + 8 + (16 * b_TorCounter) + (64 * b_ModulNbr));
+                      } // if (dw_Status & 0x1)
+                   else
+                      {
+                      /***************************/
+                      /* Tor counter not enabled */
+                      /***************************/
+
+                               DPRINTK("Tor counter not enabled \n");
+                      i_ReturnValue = -6;
+                      } // if (dw_Status & 0x1)
+                   } // if (dw_Status & 0x10)
+                else
+                   {
+                   /*******************************/
+                   /* Tor counter not initialised */
+                   /*******************************/
+
+                       DPRINTK("Tor counter not initialised\n");       
+                   i_ReturnValue = -5;
+                   } // // if (dw_Status & 0x10)
+                
+
+
+                } // switch
+               } // if (b_TorCounter <= 1)
+             else
+                {
+                /**********************************/
+                /* Tor counter selection is wrong */
+                /**********************************/
+
+                DPRINTK("Tor counter selection is wrong\n");   
+                i_ReturnValue = -4;
+                } // if (b_TorCounter <= 1)
+             }
+          else
+             {
+             /******************************************/
+             /* The module is not a tor counter module */
+             /******************************************/
+
+             DPRINTK("The module is not a tor counter module \n");     
+             i_ReturnValue = -3;
+             }
+          }
+       else
+          {
+          /***********************/
+          /* Module number error */
+          /***********************/
+
+          DPRINTK("Module number error \n");   
+          i_ReturnValue = -2;
+          }
+
+       return (i_ReturnValue);
+       }
+
+
+
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     : _INT_ i_APCI1710_GetTorCounterInitialisation           |
+|                                               (BYTE_     b_BoardHandle,    |
+|                                                BYTE_     b_ModulNbr,       |
+|                                               BYTE_     b_TorCounter,     |
+|                                               PBYTE_   pb_TimingUnit,     |
+|                                               PULONG_ pul_TimingInterval, |
+|                                               PBYTE_   pb_InputMode,      |
+|                                               PBYTE_   pb_ExternGate,     |
+|                                                PBYTE_   pb_CycleMode,      |
+|                                               PBYTE_   pb_Enable,         |
+|                                                PBYTE_   pb_InterruptEnable)|
++----------------------------------------------------------------------------+
+| Task              : Enable the tor counter (b_TorCounter) from selected    |
+|                    module (b_ModulNbr). You must calling the              |
+|                     "i_APCI1710_InitTorCounter" function be for you call   |
+|                    this function.                                         |
+|                     If you enable the tor counter interrupt, the           |
+|                     tor counter generate a interrupt after the timing cycle|
+|                     See function "i_APCI1710_SetBoardIntRoutineX" and the  |
+|                     Interrupt mask description chapter from this manual.   |
+|                     The b_CycleMode parameter determine if you will        |
+|                     measured a single or more cycle.                       |
++----------------------------------------------------------------------------+
+| Input Parameters  : BYTE_ b_BoardHandle  : Handle of board APCI-1710       |
+|                     BYTE_ b_ModulNbr     : Selected module number (0 to 3) |
+|                     BYTE_ b_TorCounter   : Tor counter selection (0 or 1)
+
+       b_ModulNbr                      =       CR_AREF(insn->chanspec);
+       b_TorCounter            =       CR_CHAN(insn->chanspec);
+. |
++----------------------------------------------------------------------------+
+| Output Parameters : PBYTE_  pb_TimingUnit    : Base timing unit (0 to 4)   |
+|                                                 0 : ns                     |
+|                                                 1 : µs                     |
+|                                                 2 : ms                     |
+|                                                 3 : s                      |
+|                                                 4 : mn                     |
+|                     PULONG_ pul_TimingInterval : Base timing value.        |
+|                    PBYTE_ pb_InputMode        : Input signal level        |
+|                                                 selection                 |
+|                                              0 : Tor count each low level |
+|                                              1 : Tor count each high level|
+|                    PBYTE_ pb_ExternGate      : Extern gate action         |
+|                                                selection                  |
+|                                                0 : Extern gate signal not |
+|                                                    used                   |
+|                                                1 : Extern gate signal used|
+|                     PBYTE_ pb_CycleMode       : Tor counter acquisition    |
+|                                                mode                       |
+|                    PBYTE_ pb_Enable          : Indicate if the tor counter|
+|                                                is enabled or no           |
+|                                                0 : Tor counter disabled   |
+|                                                1 : Tor counter enabled    |
+|                     PBYTE_ pb_InterruptEnable : Enable or disable the      |
+|                                                 tor counter interrupt.     |
+|                                                 APCI1710_ENABLE:           |
+|                                                 Enable the tor counter     |
+|                                                 interrupt                  |
+|                                                 APCI1710_DISABLE:          |
+|                                                 Disable the tor counter    |
+|                                                 interrupt 
+       pb_TimingUnit           =       (PBYTE) &data[0];
+       pul_TimingInterval      =  (PULONG) &data[1];
+       pb_InputMode            =       (PBYTE) &data[2];
+       pb_ExternGate           =       (PBYTE) &data[3];
+       pb_CycleMode            =       (PBYTE) &data[4];
+       pb_Enable                       =       (PBYTE) &data[5];
+       pb_InterruptEnable      =       (PBYTE) &data[6];
+                 |
++----------------------------------------------------------------------------+
+| 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: Tor counter not initialised see function           |
+|                         "i_APCI1710_InitTorCounter"                        |
++----------------------------------------------------------------------------+
+*/
+
+
+INT i_APCI1710_InsnReadGetTorCounterInitialisation(comedi_device *dev,comedi_subdevice *s,
+       comedi_insn *insn,lsampl_t *data)
+       {
+       INT    i_ReturnValue = 0;
+       DWORD dw_Status;
+       BYTE     b_ModulNbr;
+       BYTE     b_TorCounter;
+       PBYTE   pb_TimingUnit;
+       PULONG pul_TimingInterval;
+       PBYTE   pb_InputMode;
+       PBYTE   pb_ExternGate;
+       PBYTE   pb_CycleMode;
+       PBYTE   pb_Enable;
+       PBYTE   pb_InterruptEnable      ;
+       
+       i_ReturnValue           =       insn->n;
+       b_ModulNbr                      =       CR_AREF(insn->chanspec);
+       b_TorCounter            =       CR_CHAN(insn->chanspec);
+
+       pb_TimingUnit           =       (PBYTE) &data[0];
+       pul_TimingInterval      =  (PULONG) &data[1];
+       pb_InputMode            =       (PBYTE) &data[2];
+       pb_ExternGate           =       (PBYTE) &data[3];
+       pb_CycleMode            =       (PBYTE) &data[4];
+       pb_Enable                       =       (PBYTE) &data[5];
+       pb_InterruptEnable      =       (PBYTE) &data[6];
+
+       /**************************/
+       /* 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 if tor counter initialised */
+                /***********************************/
+
+               
+                       dw_Status = inl(devpriv->s_BoardInfos.
+                       ui_Address + 8 + (16 * b_TorCounter) + (64 * b_ModulNbr));
+
+
+                if (dw_Status & 0x10)
+                   {
+                   *pb_Enable = dw_Status & 1;
+
+                   /********************/
+                   /* Get the commando */
+                   /********************/
+
+               
+                        dw_Status=inl(devpriv->s_BoardInfos.
+                          ui_Address + 4 + (16 * b_TorCounter) + (64 * b_ModulNbr));
+
+                   *pb_CycleMode       = (BYTE) ((dw_Status >> 4) & 1);
+                   *pb_InterruptEnable = (BYTE) ((dw_Status >> 5) & 1);
+
+                   /******************************************************/
+                   /* Test if extern gate used for clock or for signal B */
+                   /******************************************************/
+
+                   if (dw_Status & 0x600)
+                      {
+                      /*****************************************/
+                      /* Test if extern gate used for signal B */
+                      /*****************************************/
+
+                      if (dw_Status & 0x400)
+                         {
+                         /***********************/
+                         /* Test if simple mode */
+                         /***********************/
+
+                         if ((dw_Status & 0x7800) == 0x7800)
+                            {
+                            *pb_InputMode = APCI1710_TOR_SIMPLE_MODE;
+                            }
+
+                         /***********************/
+                         /* Test if double mode */
+                         /***********************/
+
+                         if ((dw_Status & 0x7800) == 0x1800)
+                            {
+                            *pb_InputMode = APCI1710_TOR_DOUBLE_MODE;
+                            }
+
+                         /**************************/
+                         /* Test if quadruple mode */
+                         /**************************/
+
+                         if ((dw_Status & 0x7800) == 0x0000)
+                            {
+                            *pb_InputMode = APCI1710_TOR_QUADRUPLE_MODE;
+                            }
+                         } // if (dw_Status & 0x400)
+                      else
+                         {
+                         *pb_InputMode = 1;
+                         } // // if (dw_Status & 0x400)
+
+                      /************************/
+                      /* Extern gate not used */
+                      /************************/
+
+                      *pb_ExternGate = 0;
+                      } // if (dw_Status & 0x600)
+                   else
+                      {
+                      *pb_InputMode  = (BYTE) ((dw_Status >> 6) & 1);
+                      *pb_ExternGate = (BYTE) ((dw_Status >> 7) & 1);
+                      } // if (dw_Status & 0x600)
+
+                   *pb_TimingUnit     = devpriv->s_ModuleInfo [b_ModulNbr].
+                                        s_TorCounterModuleInfo.
+                                        s_TorCounterInfo [b_TorCounter].
+                                        b_TimingUnit;
+
+                   *pul_TimingInterval = devpriv->s_ModuleInfo [b_ModulNbr].
+                                         s_TorCounterModuleInfo.
+                                         s_TorCounterInfo [b_TorCounter].
+                                         ul_RealTimingInterval;
+                   }
+                else
+                   {
+                   /*******************************/
+                   /* Tor counter not initialised */
+                   /*******************************/
+
+                       DPRINTK("Tor counter not initialised\n");
+                   i_ReturnValue = -5;
+                   }
+                  
+                } // if (b_TorCounter <= 1)
+             else
+                {
+                /**********************************/
+                /* Tor counter selection is wrong */
+                /**********************************/
+
+                DPRINTK("Tor counter selection is wrong \n");
+                i_ReturnValue = -4;
+                } // if (b_TorCounter <= 1)
+             }
+          else
+             {
+             /******************************************/
+             /* The module is not a tor counter module */
+             /******************************************/
+
+             DPRINTK("The module is not a tor counter module\n");
+             i_ReturnValue = -3;
+             }
+          }
+       else
+          {
+          /***********************/
+          /* Module number error */
+          /***********************/
+
+          DPRINTK("Module number error\n");
+          i_ReturnValue = -2;
+          }
+
+       return (i_ReturnValue);
+       }
+
+
+
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     : _INT_ i_APCI1710_ReadTorCounterValue                   |
+|                               (BYTE_     b_BoardHandle,                    |
+|                                BYTE_     b_ModulNbr,                       |
+|                               BYTE_     b_TorCounter,                     |
+|                                UINT_    ui_TimeOut,                        |
+|                                PBYTE_   pb_TorCounterStatus,               |
+|                                PULONG_ pul_TorCounterValue)                |
++----------------------------------------------------------------------------+
+| Task         case APCI1710_TOR_GETPROGRESSSTATUS: Return the tor counter 
+(b_TorCounter) status (pb_TorCounterStatus) from selected tor counter        |
+|                    module (b_ModulNbr). 
+               
+                                case APCI1710_TOR_GETCOUNTERVALUE :
+  Return the tor counter (b_TorCounter) status           |
+|                    (pb_TorCounterStatus) and the timing value             |
+|                    (pul_TorCounterValue) after a conting cycle stop       |
+|                     from selected tor counter module (b_ModulNbr).         |
++----------------------------------------------------------------------------+
+| Input Parameters  : BYTE_ b_BoardHandle  : Handle of board APCI-1710       |
+|                     BYTE_ b_ModulNbr     : Selected module number (0 to 3) |
+|                     BYTE_ b_TorCounter   : Tor counter selection (0 or 1).
+       b_ModulNbr    = CR_AREF(insn->chanspec);
+       b_ReadType    = (BYTE) data[0]; 
+       b_TorCounter  = (BYTE) data[1];
+       ui_TimeOut        = (UINT) data[2]; |
++----------------------------------------------------------------------------+
+| Output Parameters : PBYTE_  pb_TorCounterStatus : Return the tor counter   |
+|                                                    status.                 |
+|                                               0 : Conting cycle not started|
+|                                                   Software gate not set.   |
+|                                               1 : Conting cycle started.   |
+|                                                   Software gate set.       |
+|                                               2 : Conting cycle stopped.   |
+|                                                   The conting cycle is     |
+|                                                   terminate.               |
+|                                               3 : A overflow occur. You    |
+|                                                   must change the base     |
+|                                                   timing witch the         |
+|                                                   function                 |
+|                                                 "i_APCI1710_InitTorCounter"|
+|                                              4 : Timeeout occur           |
+|                     PULONG  pul_TorCounterValue  : Tor counter value.  
+       pb_TorCounterStatus=(PBYTE) &data[0];
+       pul_TorCounterValue=(PULONG) &data[1];    |
++----------------------------------------------------------------------------+
+| 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: Tor counter not initialised see function           |
+|                         "i_APCI1710_InitTorCounter"                        |
+|                     -6: Tor counter not enabled see function               |
+|                         "i_APCI1710_EnableTorCounter"                      |
+|                     -7: Timeout parameter is wrong (0 to 65535)            |
++----------------------------------------------------------------------------+
+*/
+
+
+INT i_APCI1710_InsnBitsGetTorCounterProgressStatusAndValue(comedi_device *dev,comedi_subdevice *s,
+       comedi_insn *insn,lsampl_t *data)
+       {
+       INT    i_ReturnValue = 0;
+       DWORD  dw_Status;
+       DWORD  dw_TimeOut = 0;
+
+       BYTE    b_ModulNbr;
+       BYTE    b_TorCounter;
+       BYTE    b_ReadType;
+       UINT    ui_TimeOut;
+       PBYTE   pb_TorCounterStatus;
+       PULONG  pul_TorCounterValue;
+
+       i_ReturnValue = insn->n;
+       b_ModulNbr    = CR_AREF(insn->chanspec);
+       b_ReadType    = (BYTE) data[0]; 
+       b_TorCounter  = (BYTE) data[1];
+       ui_TimeOut        = (UINT) data[2];
+       pb_TorCounterStatus=(PBYTE) &data[0];
+       pul_TorCounterValue=(PULONG) &data[1];
+       
+       /**************************/
+       /* Test the module number */
+       /**************************/
+
+
+        if(b_ReadType==APCI1710_TOR_READINTERRUPT)
+        {
+         
+                       data[0]=devpriv->s_InterruptParameters.
+                                                     s_FIFOInterruptParameters [devpriv->
+                                                                                s_InterruptParameters.
+                                                                                ui_Read].b_OldModuleMask;
+                       data[1]=devpriv->s_InterruptParameters.
+                                                     s_FIFOInterruptParameters [devpriv->
+                                                                                s_InterruptParameters.
+                                                                                ui_Read].ul_OldInterruptMask;
+                       data[2]=devpriv->s_InterruptParameters.
+                                                     s_FIFOInterruptParameters [devpriv->
+                                                                                s_InterruptParameters.
+                                                                                ui_Read].ul_OldCounterLatchValue;
+
+                            
+                          /**************************/
+                          /* Increment the read FIFO */
+                          /***************************/
+
+                          devpriv->
+                          s_InterruptParameters.
+                          ui_Read = (devpriv->
+                          s_InterruptParameters.
+                          ui_Read + 1) % APCI1710_SAVE_INTERRUPT;
+         return insn->n;
+        } 
+
+       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 if tor counter initialised */
+                /***********************************/
+
+               
+
+                       dw_Status=inl(devpriv->s_BoardInfos.
+                       ui_Address + 8 + (16 * b_TorCounter) + (64 * b_ModulNbr));
+
+                /*******************************/
+                /* Test if counter initialised */
+                /*******************************/
+
+                if (dw_Status & 0x10)
+                   {
+                   /***************************/
+                   /* Test if counter enabled */
+                   /***************************/
+
+                   if (dw_Status & 0x1)
+                      {
+                  
+                               switch(b_ReadType)
+                               {
+
+                               case APCI1710_TOR_GETPROGRESSSTATUS:
+                       /*******************/
+                      /* Read the status */
+                      /*******************/
+               
+                                       dw_Status=inl(devpriv->s_BoardInfos.
+                              ui_Address + 4 + (16 * b_TorCounter) + (64 * b_ModulNbr));
+
+                      dw_Status = dw_Status & 0xF;
+
+                      /*****************/
+                      /* Test if start */
+                      /*****************/
+
+                      if (dw_Status & 1)
+                         {
+                         if (dw_Status & 2)
+                            {
+                            if (dw_Status & 4)
+                               {
+                               /************************/
+                               /* Tor counter owerflow */
+                               /************************/
+
+                               *pb_TorCounterStatus = 3;
+                               }
+                            else
+                               {
+                               /***********************/
+                               /* Tor counter started */
+                               /***********************/
+
+                               *pb_TorCounterStatus = 2;
+                               }
+                            }
+                         else
+                            {
+                            /***********************/
+                            /* Tor counter started */
+                            /***********************/
+
+                            *pb_TorCounterStatus = 1;
+                            }
+                         }
+                      else
+                         {
+                         /***************************/
+                         /* Tor counter not started */
+                         /***************************/
+
+                         *pb_TorCounterStatus = 0;
+                         }
+                        break;
+
+                case APCI1710_TOR_GETCOUNTERVALUE :
+                               
+                      /*****************************/
+                      /* Test the timout parameter */
+                      /*****************************/
+
+                      if ((ui_TimeOut >= 0) && (ui_TimeOut <= 65535UL))
+                         {
+                         for (;;)
+                            {
+                            /*******************/
+                            /* Read the status */
+                            /*******************/
+                               
+                               dw_Status=inl(devpriv->s_BoardInfos.
+                                   ui_Address + 4 + (16 * b_TorCounter) + (64 * b_ModulNbr));
+                            /********************/
+                            /* Test if overflow */
+                            /********************/
+
+                            if ((dw_Status & 4) == 4)
+                               {
+                               /******************/
+                               /* Overflow occur */
+                               /******************/
+
+                               *pb_TorCounterStatus = 3;
+
+                               /******************/
+                               /* Read the value */
+                               /******************/
+
+                       
+                               *pul_TorCounterValue=inl(devpriv->s_BoardInfos.
+                                      ui_Address + 0 + (16 * b_TorCounter) + (64 * b_ModulNbr));
+                               break;
+                               } // if ((dw_Status & 4) == 4)
+                            else
+                               {
+                               /*******************************/
+                               /* Test if measurement stopped */
+                               /*******************************/
+
+                               if ((dw_Status & 2) == 2)
+                                  {
+                                  /***********************/
+                                  /* A stop signal occur */
+                                  /***********************/
+
+                                  *pb_TorCounterStatus = 2;
+
+                                  /******************/
+                                  /* Read the value */
+                                  /******************/
+
+
+                                    *pul_TorCounterValue=inl(devpriv->s_BoardInfos.
+                                         ui_Address + 0 + (16 * b_TorCounter) + (64 * b_ModulNbr));
+
+                                  break;
+                                  } // if ((dw_Status & 2) == 2)
+                               else
+                                  {
+                                  /*******************************/
+                                  /* Test if measurement started */
+                                  /*******************************/
+
+                                  if ((dw_Status & 1) == 1)
+                                     {
+                                     /************************/
+                                     /* A start signal occur */
+                                     /************************/
+
+                                     *pb_TorCounterStatus = 1;
+                                     } // if ((dw_Status & 1) == 1)
+                                  else
+                                     {
+                                     /***************************/
+                                     /* Measurement not started */
+                                     /***************************/
+
+                                     *pb_TorCounterStatus = 0;
+                                     } // if ((dw_Status & 1) == 1)
+                                  } // if ((dw_Status & 2) == 2)
+                               } // if ((dw_Status & 8) == 8)
+
+                            if (dw_TimeOut == ui_TimeOut)
+                               {
+                               /*****************/
+                               /* Timeout occur */
+                               /*****************/
+
+                               break;
+                               }
+                            else
+                               {
+                               /*************************/
+                               /* Increment the timeout */
+                               /*************************/
+
+                               dw_TimeOut = dw_TimeOut + 1;
+                       
+                               mdelay(1000);
+                               }
+                            } // for (;;)
+
+                         /*************************/
+                         /* Test if timeout occur */
+                         /*************************/
+
+                         if ((*pb_TorCounterStatus != 3) && (dw_TimeOut == ui_TimeOut) && (ui_TimeOut != 0))
+                            {
+                            /*****************/
+                            /* Timeout occur */
+                            /*****************/
+
+                            *pb_TorCounterStatus = 4;
+                            }
+                         }
+                      else
+                         {
+                         /******************************/
+                         /* Timeout parameter is wrong */
+                         /******************************/
+
+                     DPRINTK("Timeout parameter is wrong\n");
+                         i_ReturnValue = -7;
+                         }
+                          break;
+
+           
+             default:
+                                printk("Inputs wrong\n");
+                       } // switch end
+                      } // if (dw_Status & 0x1)
+                   else
+                      {
+                      /***************************/
+                      /* Tor counter not enabled */
+                      /***************************/
+
+                          DPRINTK("Tor counter not enabled\n");
+                      i_ReturnValue = -6;
+                      } // if (dw_Status & 0x1)
+                   }
+                else
+                   {
+                   /*******************************/
+                   /* Tor counter not initialised */
+                   /*******************************/
+
+                       DPRINTK("Tor counter not initialised\n");
+                   i_ReturnValue = -5;
+                   }
+                } // if (b_TorCounter <= 1)
+             else
+                {
+                /**********************************/
+                /* Tor counter selection is wrong */
+                /**********************************/
+
+                 DPRINTK("Tor counter selection is wrong\n");
+                i_ReturnValue = -4;
+                } // if (b_TorCounter <= 1)
+             }
+          else
+             {
+             /******************************************/
+             /* The module is not a tor counter module */
+             /******************************************/
+
+              DPRINTK("The module is not a tor counter module\n");     
+             i_ReturnValue = -3;
+             }
+          }
+       else
+          {
+          /***********************/
+          /* Module number error */
+          /***********************/
+
+           DPRINTK("Module number error\n");   
+          i_ReturnValue = -2;
+          }
+
+       
+       return (i_ReturnValue);
+       }
+
+
index 5a29214f013ee98f8417eb82a4ccf9af3eb33096..4ef23c169f7f6137d88dc559904f581a3c641c85 100644 (file)
@@ -1,80 +1,80 @@
-/**\r
-@verbatim\r
-\r
-Copyright (C) 2004,2005  ADDI-DATA GmbH for the source code of this module. \r
-        \r
-        ADDI-DATA GmbH \r
-        Dieselstrasse 3 \r
-        D-77833 Ottersweier \r
-        Tel: +19(0)7223/9493-0 \r
-        Fax: +49(0)7223/9493-92 \r
-        http://www.addi-data-com \r
-        info@addi-data.com \r
-\r
-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.\r
-\r
-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.\r
-\r
-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 USA\r
-\r
-You shoud also find the complete GPL in the COPYING file accompanying this source code.\r
-\r
-@endverbatim\r
-*/\r
-\r
-\r
-\r
-\r
-   #define APCI1710_30MHZ           30\r
-   #define APCI1710_33MHZ           33\r
-   #define APCI1710_40MHZ           40\r
-\r
-\r
-\r
-   #define APCI1710_GATE_INPUT 10\r
-\r
-\r
-#define APCI1710_TOR_SIMPLE_MODE    2\r
-#define APCI1710_TOR_DOUBLE_MODE    3\r
-#define APCI1710_TOR_QUADRUPLE_MODE 4\r
-\r
-\r
-#define APCI1710_SINGLE     0\r
-#define APCI1710_CONTINUOUS 1\r
-\r
-\r
-#define APCI1710_TOR_GETPROGRESSSTATUS 0\r
-#define APCI1710_TOR_GETCOUNTERVALUE   1\r
-#define APCI1710_TOR_READINTERRUPT      2\r
-\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-|                       TOR_COUNTER INISIALISATION FUNCTION                  |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-INT   i_APCI1710_InsnConfigInitTorCounter(comedi_device *dev,comedi_subdevice *s,\r
-       comedi_insn *insn,lsampl_t *data);\r
-\r
-\r
-\r
-\r
-\r
-\r
-INT  i_APCI1710_InsnWriteEnableDisableTorCounter (comedi_device *dev,comedi_subdevice *s,\r
-       comedi_insn *insn,lsampl_t *data);\r
-\r
-\r
-INT i_APCI1710_InsnReadGetTorCounterInitialisation(comedi_device *dev,comedi_subdevice *s,\r
-       comedi_insn *insn,lsampl_t *data);\r
-/*\r
-+----------------------------------------------------------------------------+\r
-|                       TOR_COUNTER READ FUNCTION                            |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-\r
-\r
-INT i_APCI1710_InsnBitsGetTorCounterProgressStatusAndValue(comedi_device *dev,comedi_subdevice *s,\r
-       comedi_insn *insn,lsampl_t *data);\r
+/**
+@verbatim
+
+Copyright (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 USA
+
+You shoud also find the complete GPL in the COPYING file accompanying this source code.
+
+@endverbatim
+*/
+
+
+
+
+   #define APCI1710_30MHZ           30
+   #define APCI1710_33MHZ           33
+   #define APCI1710_40MHZ           40
+
+
+
+   #define APCI1710_GATE_INPUT 10
+
+
+#define APCI1710_TOR_SIMPLE_MODE    2
+#define APCI1710_TOR_DOUBLE_MODE    3
+#define APCI1710_TOR_QUADRUPLE_MODE 4
+
+
+#define APCI1710_SINGLE     0
+#define APCI1710_CONTINUOUS 1
+
+
+#define APCI1710_TOR_GETPROGRESSSTATUS 0
+#define APCI1710_TOR_GETCOUNTERVALUE   1
+#define APCI1710_TOR_READINTERRUPT      2
+
+
+/*
++----------------------------------------------------------------------------+
+|                       TOR_COUNTER INISIALISATION FUNCTION                  |
++----------------------------------------------------------------------------+
+*/
+
+INT   i_APCI1710_InsnConfigInitTorCounter(comedi_device *dev,comedi_subdevice *s,
+       comedi_insn *insn,lsampl_t *data);
+
+
+
+
+
+
+INT  i_APCI1710_InsnWriteEnableDisableTorCounter (comedi_device *dev,comedi_subdevice *s,
+       comedi_insn *insn,lsampl_t *data);
+
+
+INT i_APCI1710_InsnReadGetTorCounterInitialisation(comedi_device *dev,comedi_subdevice *s,
+       comedi_insn *insn,lsampl_t *data);
+/*
++----------------------------------------------------------------------------+
+|                       TOR_COUNTER READ FUNCTION                            |
++----------------------------------------------------------------------------+
+*/
+
+
+
+INT i_APCI1710_InsnBitsGetTorCounterProgressStatusAndValue(comedi_device *dev,comedi_subdevice *s,
+       comedi_insn *insn,lsampl_t *data);
index af98adb80ef209279c8d9f68c72122ebc1bddfc7..91d3bf902fe76cc6c1deb8d6fd8e61b92426d12e 100644 (file)
-/**\r
-@verbatim\r
-\r
-Copyright (C) 2004,2005  ADDI-DATA GmbH for the source code of this module. \r
-        \r
-        ADDI-DATA GmbH \r
-        Dieselstrasse 3 \r
-        D-77833 Ottersweier \r
-        Tel: +19(0)7223/9493-0 \r
-        Fax: +49(0)7223/9493-92 \r
-        http://www.addi-data-com \r
-        info@addi-data.com \r
-\r
-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.\r
-\r
-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.\r
-\r
-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 USA\r
-\r
-You shoud also find the complete GPL in the COPYING file accompanying this source code.\r
-\r
-@endverbatim\r
-*/\r
-/*\r
-    \r
-  +-----------------------------------------------------------------------+\r
-  | (C) ADDI-DATA GmbH          Dieselstraße 3       D-77833 Ottersweier  |\r
-  +-----------------------------------------------------------------------+\r
-  | Tel : +49 (0) 7223/9493-0     | email    : info@addi-data.com         |\r
-  | Fax : +49 (0) 7223/9493-92    | Internet : http://www.addi-data.com   |\r
-  +-----------------------------------------------------------------------+\r
-  | Project     : API APCI1710    | Compiler : gcc                        |\r
-  | Module name : TTL.C           | Version  : 2.96                       |\r
-  +-------------------------------+---------------------------------------+\r
-  | Project manager: Eric Stolz   | Date     :  02/12/2002                |\r
-  +-----------------------------------------------------------------------+\r
-  | Description :   APCI-1710 TTL I/O module                              |\r
-  |                                                                       |\r
-  |                                                                       |\r
-  +-----------------------------------------------------------------------+\r
-  |                             UPDATES                                   |\r
-  +-----------------------------------------------------------------------+\r
-  |   Date   |   Author  |          Description of updates                |\r
-  +----------+-----------+------------------------------------------------+\r
-  | 13/05/98 | S. Weber  | TTL digital input / output implementation      |\r
-  |----------|-----------|------------------------------------------------|\r
-  | 08/05/00 | Guinot C  | - 0400/0228 All Function in RING 0             |\r
-  |          |           |   available                                    |\r
-  +-----------------------------------------------------------------------+\r
-  |          |           |                                                |\r
-  |          |           |                                                |\r
-  +-----------------------------------------------------------------------+\r
-*/\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-|                               Included files                               |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-#include "APCI1710_Ttl.h"\r
-\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : _INT_ i_APCI1710_InitTTLIODirection                    |\r
-|                               (BYTE_    b_BoardHandle,                     |\r
-|                               BYTE_    b_ModulNbr,                        |\r
-|                               BYTE_    b_PortAMode,                       |\r
-|                               BYTE_    b_PortBMode,                       |\r
-|                               BYTE_    b_PortCMode,                       |\r
-|                               BYTE_    b_PortDMode)                       |\r
-+----------------------------------------------------------------------------+\r
-| Task           APCI1710_TTL_INIT (using defaults)   : Configure the TTL I/O operating mode from selected     |\r
-|                     module  (b_ModulNbr). You must calling this function be|\r
-|                     for you call any other function witch access of TTL.   |\r
-                                APCI1710_TTL_INITDIRECTION(user inputs for direction) \r
-\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : BYTE_ b_BoardHandle         : Handle of board APCI-1710|\r
-|                     BYTE_ b_ModulNbr            : Module number to         |\r
-|                                                   configure (0 to 3)  \r
-               b_ModulNbr = (BYTE) CR_AREF(insn->chanspec);\r
-               b_InitType = (BYTE) data[0];\r
-               b_PortAMode     = (BYTE) data[1];\r
-               b_PortBMode = (BYTE) data[2];\r
-               b_PortCMode = (BYTE) data[3];\r
-               b_PortDMode     = (BYTE) data[4];|\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : -                                                      |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      : 0: No error                                            |\r
-|                    -1: The handle parameter of the board is wrong          |\r
-|                    -2: The module parameter is wrong                       |\r
-|                    -3: The module is not a TTL module                      |\r
-|                   -4: Function not available for this version             |\r
-|                   -5: Port A mode selection is wrong                      |\r
-|                   -6: Port B mode selection is wrong                      |\r
-|                   -7: Port C mode selection is wrong                      |\r
-|                   -8: Port D mode selection is wrong                      |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-\r
-INT   i_APCI1710_InsnConfigInitTTLIO(comedi_device *dev,comedi_subdevice *s,\r
-       comedi_insn *insn,lsampl_t *data) \r
-       {\r
-               INT             i_ReturnValue = 0;\r
-               BYTE    b_ModulNbr;\r
-               BYTE    b_InitType;\r
-               BYTE    b_PortAMode;\r
-               BYTE    b_PortBMode;\r
-               BYTE    b_PortCMode;\r
-               BYTE    b_PortDMode;\r
-\r
-               b_ModulNbr = (BYTE) CR_AREF(insn->chanspec);\r
-               b_InitType = (BYTE) data[0];\r
-               i_ReturnValue = insn->n;\r
-\r
-       /**************************/\r
-       /* Test the module number */\r
-       /**************************/\r
-                                                                                                                                                                          \r
-       if (b_ModulNbr < 4)\r
-          {\r
-          /**************************/\r
-          /* Test if TTL I/O module */\r
-          /**************************/\r
-\r
-          if ((devpriv->s_BoardInfos.\r
-               dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_TTL_IO)\r
-             {\r
-            switch(b_InitType)\r
-                       {\r
-                       case APCI1710_TTL_INIT :\r
-\r
-                       devpriv->s_ModuleInfo [b_ModulNbr].\r
-             s_TTLIOInfo.b_TTLInit = 1;\r
-\r
-             /***************************/\r
-             /* Set TTL port A to input */\r
-             /***************************/\r
-\r
-             devpriv->s_ModuleInfo [b_ModulNbr].\r
-             s_TTLIOInfo.\r
-             b_PortConfiguration [0] = 0;\r
-\r
-             /***************************/\r
-             /* Set TTL port B to input */\r
-             /***************************/\r
-\r
-             devpriv->s_ModuleInfo [b_ModulNbr].\r
-             s_TTLIOInfo.\r
-             b_PortConfiguration [1] = 0;\r
-\r
-             /***************************/\r
-             /* Set TTL port C to input */\r
-             /***************************/\r
-\r
-             devpriv->s_ModuleInfo [b_ModulNbr].\r
-             s_TTLIOInfo.\r
-             b_PortConfiguration [2] = 0;\r
-\r
-             /****************************/\r
-             /* Set TTL port D to output */\r
-             /****************************/\r
-\r
-             devpriv->s_ModuleInfo [b_ModulNbr].\r
-             s_TTLIOInfo.\r
-             b_PortConfiguration [3] = 1;\r
-\r
-             /*************************/\r
-             /* Set the configuration */\r
-             /*************************/\r
-                       \r
-                 outl(0x8,devpriv->s_BoardInfos.ui_Address + 20 + (64 * b_ModulNbr));\r
-                       break;\r
-\r
-\r
-                       case APCI1710_TTL_INITDIRECTION :\r
-\r
-                       b_PortAMode     = (BYTE) data[1];\r
-                       b_PortBMode = (BYTE) data[2];\r
-                       b_PortCMode = (BYTE) data[3];\r
-                       b_PortDMode     = (BYTE) data[4];\r
-\r
-             /********************/\r
-             /* Test the version */\r
-             /********************/\r
-\r
-             if ((devpriv->s_BoardInfos.\r
-                  dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) >= 0x3230)\r
-                {\r
-                /************************/\r
-                /* Test the port A mode */\r
-                /************************/\r
-\r
-                if ((b_PortAMode == 0) || (b_PortAMode == 1))\r
-                   {\r
-                   /************************/\r
-                   /* Test the port B mode */\r
-                   /************************/\r
-\r
-                   if ((b_PortBMode == 0) || (b_PortBMode == 1))\r
-                      {\r
-                      /************************/\r
-                      /* Test the port C mode */\r
-                      /************************/\r
-\r
-                      if ((b_PortCMode == 0) || (b_PortCMode == 1))\r
-                         {\r
-                         /************************/\r
-                         /* Test the port D mode */\r
-                         /************************/\r
-\r
-                         if ((b_PortDMode == 0) || (b_PortDMode == 1))\r
-                            {\r
-                            devpriv->s_ModuleInfo [b_ModulNbr].\r
-                            s_TTLIOInfo.\r
-                            b_TTLInit = 1;\r
-\r
-                            /***********************/\r
-                            /* Set TTL port A mode */\r
-                            /***********************/\r
-\r
-                            devpriv->s_ModuleInfo [b_ModulNbr].\r
-                            s_TTLIOInfo.\r
-                            b_PortConfiguration [0] = b_PortAMode;\r
-\r
-                            /***********************/\r
-                            /* Set TTL port B mode */\r
-                            /***********************/\r
-\r
-                            devpriv->s_ModuleInfo [b_ModulNbr].\r
-                            s_TTLIOInfo.\r
-                            b_PortConfiguration [1] = b_PortBMode;\r
-\r
-                            /***********************/\r
-                            /* Set TTL port C mode */\r
-                            /***********************/\r
-\r
-                            devpriv->s_ModuleInfo [b_ModulNbr].\r
-                            s_TTLIOInfo.\r
-                            b_PortConfiguration [2] = b_PortCMode;\r
-\r
-                            /***********************/\r
-                            /* Set TTL port D mode */\r
-                            /***********************/\r
-\r
-                            devpriv->s_ModuleInfo [b_ModulNbr].\r
-                            s_TTLIOInfo.\r
-                            b_PortConfiguration [3] = b_PortDMode;\r
-\r
-                            /*************************/\r
-                            /* Set the configuration */\r
-                            /*************************/\r
-\r
-                            \r
-                                outl((b_PortAMode << 0) |\r
-                                         (b_PortBMode << 1) |\r
-                                         (b_PortCMode << 2) |\r
-                                         (b_PortDMode << 3),devpriv->s_BoardInfos.\r
-                                    ui_Address + 20 + (64 * b_ModulNbr));\r
-                            }\r
-                         else\r
-                            {\r
-                            /**********************************/\r
-                            /* Port D mode selection is wrong */\r
-                            /**********************************/\r
-\r
-                        DPRINTK("Port D mode selection is wrong\n");\r
-                            i_ReturnValue = -8;\r
-                            }\r
-                         }\r
-                      else\r
-                         {\r
-                         /**********************************/\r
-                         /* Port C mode selection is wrong */\r
-                         /**********************************/\r
-\r
-                         DPRINTK("Port C mode selection is wrong\n");\r
-                         i_ReturnValue = -7;\r
-                         }\r
-                      }\r
-                   else\r
-                      {\r
-                      /**********************************/\r
-                      /* Port B mode selection is wrong */\r
-                      /**********************************/\r
-\r
-                          DPRINTK("Port B mode selection is wrong\n");\r
-                      i_ReturnValue = -6;\r
-                      }\r
-                   }\r
-                else\r
-                   {\r
-                   /**********************************/\r
-                   /* Port A mode selection is wrong */\r
-                   /**********************************/\r
-\r
-                       DPRINTK("Port A mode selection is wrong\n");\r
-                   i_ReturnValue = -5;\r
-                   }\r
-                }\r
-             else\r
-                {\r
-                /*******************************************/\r
-                /* Function not available for this version */\r
-                /*******************************************/\r
-\r
-                DPRINTK("Function not available for this version\n");\r
-                i_ReturnValue = -4;\r
-                }\r
-                 break;\r
-\r
-                 DPRINTK("\n");\r
-                 default:\r
-                         printk("Bad Config Type\n");\r
-                 }// switch end\r
-             }\r
-          else\r
-             {\r
-             /**********************************/\r
-             /* The module is not a TTL module */\r
-             /**********************************/\r
-\r
-             DPRINTK("The module is not a TTL module\n");\r
-             i_ReturnValue = -3;\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /***********************/\r
-          /* Module number error */\r
-          /***********************/\r
-\r
-          DPRINTK("Module number error\n");\r
-          i_ReturnValue = -2;\r
-          }\r
-\r
-       return (i_ReturnValue);\r
-       }\r
-\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-|                            INPUT FUNCTIONS                                 |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : _INT_   i_APCI1710_ReadTTLIOChannelValue               |\r
-|                                       (BYTE_     b_BoardHandle,            |\r
-|                                        BYTE_     b_ModulNbr,               |\r
-|                                        BYTE_     b_SelectedPort,           |\r
-|                                        BYTE_     b_InputChannel,           |\r
-|                                        PBYTE_   pb_ChannelStatus)          |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Read the status from selected TTL digital input        |\r
-|                     (b_InputChannel) \r
-+----------------------------------------------------------------------------+\r
-| Task              : Read the status from digital input port                |\r
-|                     (b_SelectedPort) from selected TTL module (b_ModulNbr) |\r
-+----------------------------------------------------------------------------+ \r
-\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : BYTE_ b_BoardHandle         : Handle of board APCI-1710|\r
-|                     BYTE_ b_ModulNbr            : Module number to         |\r
-|                                                   configure (0 to 7)       |\r
-|                     BYTE_ b_SelectedPort,       : Selection from TTL I/O   |\r
-|                                                   port (0 to 2)            |\r
-|                                                      0 : Port A selection  |\r
-|                                                      1 : Port B selection  |\r
-|                                                      2 : Port C selection  |\r
-|                                                      3 : Port D selection  |\r
-|                     BYTE_ b_InputChannel        : Selection from digital   |\r
-|                                                   input ( 0 to 2)        \r
-APCI1710_TTL_READCHANNEL  \r
-       b_ModulNbr        = CR_AREF(insn->chanspec);\r
-       b_SelectedPort= CR_RANGE(insn->chanspec);\r
-       b_InputChannel= CR_CHAN(insn->chanspec);\r
-       b_ReadType        = (BYTE) data[0];\r
-\r
- APCI1710_TTL_READPORT|\r
-       b_ModulNbr        = CR_AREF(insn->chanspec);\r
-       b_SelectedPort= CR_RANGE(insn->chanspec);\r
-       b_ReadType        = (BYTE) data[0];\r
-\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : data[0]\r
-\r
-       PBYTE_  pb_ChannelStatus    : Digital input channel    |\r
-|                                                   status                   |\r
-|                                                   0 : Channle is not active|\r
-|                                                   1 : Channle is active    |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      : 0: No error                                            |\r
-|                    -1: The handle parameter of the board is wrong          |\r
-|                    -2: The module parameter is wrong                       |\r
-|                    -3: The module is not a TTL module                      |\r
-|                    -4: The selected TTL input port is wrong                |\r
-|                    -5: The selected TTL digital input is wrong             |\r
-|                    -6: TTL I/O not initialised                             |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-\r
-INT  i_APCI1710_InsnBitsReadTTLIO(comedi_device *dev,comedi_subdevice *s,\r
-       comedi_insn *insn,lsampl_t *data)\r
-       {\r
-       INT    i_ReturnValue = 0;\r
-       DWORD dw_StatusReg;\r
-       BYTE    b_ModulNbr;\r
-       BYTE    b_SelectedPort;\r
-       BYTE    b_InputChannel;\r
-       BYTE    b_ReadType;\r
-       PBYTE   pb_ChannelStatus;\r
-       PBYTE  pb_PortValue;\r
-       \r
-               \r
-       i_ReturnValue = insn->n;\r
-       b_ReadType        = (BYTE) data[0];\r
-       b_ModulNbr        = CR_AREF(insn->chanspec);\r
-       b_SelectedPort= CR_RANGE(insn->chanspec);\r
-       b_InputChannel= CR_CHAN(insn->chanspec);\r
-\r
-       \r
-       \r
-       \r
-       /**************************/\r
-       /* Test the module number */\r
-       /**************************/\r
-\r
-       if (b_ModulNbr < 4)\r
-          {\r
-          /**************************/\r
-          /* Test if TTL I/O module */\r
-          /**************************/\r
-\r
-          if ((devpriv->s_BoardInfos.\r
-               dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_TTL_IO)\r
-             {\r
-                  switch(b_ReadType)\r
-                  {\r
-\r
-                  case APCI1710_TTL_READCHANNEL:\r
-                       pb_ChannelStatus = (PBYTE) &data[0];\r
-             /********************************/\r
-             /* Test the TTL I/O port number */\r
-             /********************************/\r
-\r
-             if (((b_SelectedPort <= 2) && ((devpriv->s_BoardInfos.\r
-                                             dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) == 0x3130)) ||\r
-                 ((b_SelectedPort <= 3) && ((devpriv->s_BoardInfos.\r
-                                            dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) >= 0x3230)))\r
-                {\r
-                /******************************************/\r
-                /* Test the digital imnput channel number */\r
-                /******************************************/\r
-\r
-                if (((b_InputChannel <= 7) && (b_SelectedPort < 3)) ||\r
-                    ((b_InputChannel <= 1) && (b_SelectedPort == 3)))\r
-                   {\r
-                   /******************************************/\r
-                   /* Test if the TTL I/O module initialised */\r
-                   /******************************************/\r
-\r
-                   if (devpriv->s_ModuleInfo [b_ModulNbr].\r
-                       s_TTLIOInfo.\r
-                       b_TTLInit == 1)\r
-                      {\r
-                      /***********************************/\r
-                      /* Test if TTL port used for input */\r
-                      /***********************************/\r
-\r
-                      if (((devpriv->s_BoardInfos.\r
-                            dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) == 0x3130) ||\r
-                          (((devpriv->s_BoardInfos.\r
-                             dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) >= 0x3230) &&\r
-                           (devpriv->s_ModuleInfo [b_ModulNbr].\r
-                            s_TTLIOInfo.\r
-                            b_PortConfiguration [b_SelectedPort] == 0)))\r
-                         {\r
-                         /**************************/\r
-                         /* Read all digital input */\r
-                         /**************************/\r
-                       \r
-                               dw_StatusReg = inl(devpriv->s_BoardInfos.ui_Address + (64 * b_ModulNbr));\r
-\r
-                         *pb_ChannelStatus = (BYTE) ((dw_StatusReg >> (8 * b_SelectedPort)) >>\r
- b_InputChannel) & 1;\r
-                         }\r
-                      else\r
-                         {\r
-                         /*******************************/\r
-                         /* Selected TTL I/O port error */\r
-                         /*******************************/\r
-\r
-                         DPRINTK("Selected TTL I/O port error\n");\r
-                         i_ReturnValue = -4;\r
-                         }\r
-                      }\r
-                   else\r
-                      {\r
-                      /***************************/\r
-                      /* TTL I/O not initialised */\r
-                      /***************************/\r
-\r
-                          DPRINTK("TTL I/O not initialised\n");        \r
-                      i_ReturnValue = -6;\r
-                      }\r
-                   }\r
-                else\r
-                   {\r
-                   /********************************/\r
-                   /* Selected digital input error */\r
-                   /********************************/\r
-\r
-                       DPRINTK("Selected digital input error\n");\r
-                   i_ReturnValue = -5;\r
-                   }\r
-                }\r
-             else\r
-                {\r
-                /*******************************/\r
-                /* Selected TTL I/O port error */\r
-                /*******************************/\r
-\r
-                DPRINTK("Selected TTL I/O port error\n");\r
-                i_ReturnValue = -4;\r
-                }\r
-                 break;\r
-\r
-                 case APCI1710_TTL_READPORT:\r
-                         pb_PortValue = (PBYTE) &data[0];\r
-                         /********************************/\r
-                         /* Test the TTL I/O port number */\r
-                         /********************************/\r
-\r
-             if (((b_SelectedPort <= 2) && ((devpriv->s_BoardInfos.\r
-                                             dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) == 0x3130)) ||\r
-                 ((b_SelectedPort <= 3) && ((devpriv->s_BoardInfos.\r
-                                             dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) >= 0x3230)))\r
-                {\r
-                /******************************************/\r
-                /* Test if the TTL I/O module initialised */\r
-                /******************************************/\r
-\r
-                if (devpriv->s_ModuleInfo [b_ModulNbr].\r
-                    s_TTLIOInfo.\r
-                    b_TTLInit == 1)\r
-                   {\r
-                   /***********************************/\r
-                   /* Test if TTL port used for input */\r
-                   /***********************************/\r
-\r
-                   if (((devpriv->s_BoardInfos.\r
-                         dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) == 0x3130) ||\r
-                       (((devpriv->s_BoardInfos.\r
-                          dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) >= 0x3230) &&\r
-                        (devpriv->s_ModuleInfo [b_ModulNbr].\r
-                         s_TTLIOInfo.\r
-                         b_PortConfiguration [b_SelectedPort] == 0)))\r
-                       {\r
-                      /**************************/\r
-                      /* Read all digital input */\r
-                      /**************************/\r
-                               \r
-                               dw_StatusReg=inl(devpriv->s_BoardInfos.ui_Address + (64 * b_ModulNbr));\r
-\r
-                      *pb_PortValue = (BYTE) ((dw_StatusReg >> (8 * b_SelectedPort)) & 0xFF);\r
-                      }\r
-                   else\r
-                      {\r
-                      /*******************************/\r
-                      /* Selected TTL I/O port error */\r
-                      /*******************************/\r
-\r
-                      DPRINTK("Selected TTL I/O port error\n");\r
-                      i_ReturnValue = -4;\r
-                      }\r
-                   }\r
-                else\r
-                   {\r
-                   /***************************/\r
-                   /* TTL I/O not initialised */\r
-                   /***************************/\r
-\r
-                       DPRINTK("TTL I/O not initialised\n");\r
-                   i_ReturnValue = -5;\r
-                   }\r
-                }\r
-             else\r
-                {\r
-                /*******************************/\r
-                /* Selected TTL I/O port error */\r
-                /*******************************/\r
-\r
-                DPRINTK("Selected TTL I/O port error\n");      \r
-                i_ReturnValue = -4;\r
-                }\r
-                 break;\r
-\r
-                 default:\r
-                          printk("Bad ReadType\n");\r
-                  \r
-                  }//End Switch\r
-             }\r
-          else\r
-             {\r
-             /**********************************/\r
-             /* The module is not a TTL module */\r
-             /**********************************/\r
-\r
-             DPRINTK("The module is not a TTL module\n");      \r
-             i_ReturnValue = -3;\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /***********************/\r
-          /* Module number error */\r
-          /***********************/\r
-\r
-          DPRINTK("Module number error\n");    \r
-          i_ReturnValue = -2;\r
-          }\r
-\r
-       return (i_ReturnValue);\r
-       }\r
-\r
-\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : INT i_APCI1710_InsnReadTTLIOAllPortValue(comedi_device \r
-*dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data)              |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Read the status from all digital input ports           |\r
-|                     (port A, port B and port C) from selected TTL          |\r
-|                    module (b_ModulNbr)                                    |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : BYTE_ b_BoardHandle         : Handle of board APCI-1710|\r
-|                     BYTE_ b_ModulNbr            : Module number to         |\r
-|                                                   configure (0 to 3)       |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : PULONG_  pul_PortValue      : Digital TTL inputs port  |\r
-|                                                   status                   |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      : 0: No error                                            |\r
-|                    -1: The handle parameter of the board is wrong          |\r
-|                    -2: The module parameter is wrong                       |\r
-|                    -3: The module is not a TTL module                      |\r
-|                    -4: TTL I/O not initialised                             |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-INT i_APCI1710_InsnReadTTLIOAllPortValue(comedi_device *dev,comedi_subdevice *s,\r
-comedi_insn *insn,lsampl_t *data)\r
-       {\r
-       INT    i_ReturnValue = 0;\r
-       DWORD dw_StatusReg;\r
-       BYTE    b_ModulNbr;\r
-        PULONG pul_PortValue;\r
-      \r
-        b_ModulNbr=(BYTE) CR_AREF(insn->chanspec); \r
-        i_ReturnValue=insn->n;\r
-        pul_PortValue=(PULONG) &data[0]; \r
-\r
-       /**************************/\r
-       /* Test the module number */\r
-       /**************************/\r
-\r
-       if (b_ModulNbr < 4)\r
-          {\r
-          /**************************/\r
-          /* Test if TTL I/O module */\r
-          /**************************/\r
-\r
-          if ((devpriv->s_BoardInfos.\r
-               dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_TTL_IO)\r
-             {\r
-             /******************************************/\r
-             /* Test if the TTL I/O module initialised */\r
-             /******************************************/\r
-\r
-             if (devpriv->\r
-                 s_ModuleInfo [b_ModulNbr].\r
-                 s_TTLIOInfo.\r
-                 b_TTLInit == 1)\r
-                {\r
-                /**************************/\r
-                /* Read all digital input */\r
-                /**************************/\r
-\r
-\r
-                       dw_StatusReg=inl(devpriv->s_BoardInfos.\r
-                       ui_Address + (64 * b_ModulNbr));\r
-\r
-                /**********************/\r
-                /* Test if TTL Rev1.0 */\r
-                /**********************/\r
-\r
-                if ((devpriv->s_BoardInfos.\r
-                     dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) == 0x3130)\r
-                   {\r
-                   *pul_PortValue = dw_StatusReg & 0xFFFFFFUL;\r
-                   }\r
-                else\r
-                   {\r
-                   /**************************************/\r
-                   /* Test if port A not used for output */\r
-                   /**************************************/\r
-\r
-                   if (devpriv->s_ModuleInfo [b_ModulNbr].\r
-                       s_TTLIOInfo.b_PortConfiguration [0] == 1)\r
-                      {\r
-                      *pul_PortValue = dw_StatusReg & 0x3FFFF00UL;\r
-                      }\r
-\r
-                   /**************************************/\r
-                   /* Test if port B not used for output */\r
-                   /**************************************/\r
-\r
-                   if (devpriv->\r
-                       s_ModuleInfo [b_ModulNbr].\r
-                       s_TTLIOInfo.\r
-                       b_PortConfiguration [1] == 1)\r
-                      {\r
-                      *pul_PortValue = dw_StatusReg & 0x3FF00FFUL;\r
-                      }\r
-\r
-                   /**************************************/\r
-                   /* Test if port C not used for output */\r
-                   /**************************************/\r
-\r
-                   if (devpriv->\r
-                       s_ModuleInfo [b_ModulNbr].\r
-                       s_TTLIOInfo.\r
-                       b_PortConfiguration [2] == 1)\r
-                      {\r
-                      *pul_PortValue = dw_StatusReg & 0x300FFFFUL;\r
-                      }\r
-\r
-                   /**************************************/\r
-                   /* Test if port D not used for output */\r
-                   /**************************************/\r
-\r
-                   if (devpriv->\r
-                       s_ModuleInfo [b_ModulNbr].\r
-                       s_TTLIOInfo.\r
-                       b_PortConfiguration [3] == 1)\r
-                      {\r
-                      *pul_PortValue = dw_StatusReg & 0xFFFFFFUL;\r
-                      }\r
-                   }\r
-                }\r
-             else\r
-                {\r
-                /***************************/\r
-                /* TTL I/O not initialised */\r
-                /***************************/\r
-                DPRINTK("TTL I/O not initialised\n");\r
-                i_ReturnValue = -5;\r
-                }\r
-             }\r
-          else\r
-             {\r
-             /**********************************/\r
-             /* The module is not a TTL module */\r
-             /**********************************/\r
-             DPRINTK("The module is not a TTL module\n");      \r
-             i_ReturnValue = -3;\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /***********************/\r
-          /* Module number error */\r
-          /***********************/\r
-          DPRINTK("Module number error\n");\r
-          i_ReturnValue = -2;\r
-          }\r
-\r
-       return (i_ReturnValue);\r
-       }\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-|                            OUTPUT FUNCTIONS                                |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : _INT_ i_APCI1710_SetTTLIOChlOn                         |\r
-|                               (BYTE_           b_BoardHandle,              |\r
-|                                BYTE_           b_ModulNbr,                 |\r
-|                                BYTE_           b_OutputChannel) \r
-INT i_APCI1710_InsnWriteSetTTLIOChlOnOff(comedi_device *dev,comedi_subdevice *s,\r
-       comedi_insn *insn,lsampl_t *data)           |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Sets or resets  the output witch has been passed with the         |\r
-|                     parameter b_Channel. Setting an output means setting   |\r
-|                     an ouput high.                                         |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : BYTE_ b_BoardHandle   : Handle of board APCI-1710      |\r
-|                     BYTE_ b_ModulNbr      : Selected module number (0 to 3)|\r
-|                     BYTE_ b_OutputChannel : Selection from digital output  |\r
-|                                             channel (0 or 1)               |\r
-|                                                0      : PD0                |\r
-|                                                1      : PD1                |\r
-|                                               2 to 9 : PA                 |\r
-|                                              10 to 17: PB                 |\r
-|                                              18 to 25: PC                 |\r
-\r
-  b_ModulNbr      = CR_AREF(insn->chanspec);\r
-       b_OutputChannel= CR_CHAN(insn->chanspec);\r
-       ui_State           = data[0]; // ON or OFF\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : -                                                      |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      : 0: No error                                            |\r
-|                    -1: The handle parameter of the board is wrong          |\r
-|                    -2: The module parameter is wrong                       |\r
-|                    -3: The module is not a TTL I/O module                  |\r
-|                    -4: The selected digital output is wrong                |\r
-|                    -5: TTL I/O not initialised see function                |\r
-|                        " i_APCI1710_InitTTLIO"\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-INT i_APCI1710_InsnWriteSetTTLIOChlOnOff(comedi_device *dev,comedi_subdevice *s,\r
-       comedi_insn *insn,lsampl_t *data)\r
-       {\r
-       INT    i_ReturnValue = 0;       \r
-       DWORD dw_StatusReg   = 0;\r
-       BYTE b_ModulNbr;\r
-       BYTE b_OutputChannel;\r
-       UINT ui_State;\r
-\r
-       i_ReturnValue  = insn->n;\r
-       b_ModulNbr         = CR_AREF(insn->chanspec);\r
-       b_OutputChannel= CR_CHAN(insn->chanspec);\r
-       ui_State           = data[0]; // ON or OFF\r
-\r
-       /**************************/\r
-       /* Test the module number */\r
-       /**************************/\r
-\r
-       if (b_ModulNbr < 4)\r
-          {\r
-          /**************************/\r
-          /* Test if TTL I/O module */\r
-          /**************************/\r
-\r
-          if ((devpriv->s_BoardInfos.\r
-               dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_TTL_IO)\r
-             {\r
-             /******************************************/\r
-             /* Test if the TTL I/O module initialised */\r
-             /******************************************/\r
-\r
-             if (devpriv->s_ModuleInfo [b_ModulNbr].\r
-                 s_TTLIOInfo.\r
-                 b_TTLInit == 1)\r
-                {\r
-                /***********************************/\r
-                /* Test the TTL I/O channel number */\r
-                /***********************************/\r
-\r
-                if (((b_OutputChannel <= 1) && ((devpriv->s_BoardInfos.\r
-                                                dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) == 0x3130)) ||\r
-                    ((b_OutputChannel <= 25) && ((devpriv->s_BoardInfos.\r
-                                                 dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) >= 0x3230)))\r
-                   {\r
-                   /****************************************************/\r
-                   /* Test if the selected channel is a output channel */\r
-                   /****************************************************/\r
-\r
-                   if (((b_OutputChannel <= 1) && (devpriv->\r
-                       s_ModuleInfo [b_ModulNbr].\r
-                                                                             s_TTLIOInfo.\r
-                                                                             b_PortConfiguration [3] == 1)) ||\r
-                       ((b_OutputChannel >= 2) && (b_OutputChannel <= 9) && (devpriv->s_ModuleInfo [b_ModulNbr].\r
-                                                                             s_TTLIOInfo.\r
-                                                                             b_PortConfiguration [0] == 1)) ||\r
-                       ((b_OutputChannel >= 10) && (b_OutputChannel <= 17) && (devpriv->s_ModuleInfo [b_ModulNbr].\r
-                                                                               s_TTLIOInfo.\r
-                                                                               b_PortConfiguration [1] == 1)) ||\r
-                       ((b_OutputChannel >= 18) && (b_OutputChannel <= 25) && (devpriv->s_ModuleInfo [b_ModulNbr].\r
-                                                                               s_TTLIOInfo.\r
-                                                                               b_PortConfiguration [2] == 1)))\r
-                      {\r
-                      /************************/\r
-                      /* Test if PD0 selected */\r
-                      /************************/\r
-\r
-                      if (b_OutputChannel == 0)\r
-                         {\r
-\r
-                outl(ui_State,devpriv->s_BoardInfos.\r
-                                 ui_Address + (64 * b_ModulNbr));\r
-                         }\r
-                      else\r
-              {\r
-                         /************************/\r
-                         /* Test if PD1 selected */\r
-                         /************************/\r
-\r
-                         if (b_OutputChannel == 1)\r
-                            {\r
-\r
-                                 outl(ui_State,devpriv->s_BoardInfos.\r
-                                    ui_Address + 4 + (64 * b_ModulNbr));\r
-                            }\r
-                         else\r
-                            {\r
-                            b_OutputChannel = b_OutputChannel - 2;\r
-\r
-                            /********************/\r
-                            /* Read all channel */\r
-                            /********************/\r
-\r
-                           \r
-                                       dw_StatusReg =inl(devpriv->s_BoardInfos.\r
-                                   ui_Address + (64 * b_ModulNbr));\r
-                 if(ui_State) // ON\r
-                 {\r
-                            dw_StatusReg = (dw_StatusReg >> ((b_OutputChannel / 8) * 8)) & 0xFF;\r
-                            dw_StatusReg = dw_StatusReg | (1 << (b_OutputChannel % 8));\r
-                                }else    // Off\r
-                                {\r
-                 dw_StatusReg = (dw_StatusReg >> ((b_OutputChannel / 8) * 8)) & 0xFF;\r
-                            dw_StatusReg = dw_StatusReg & (0xFF - (1 << (b_OutputChannel % 8)));\r
-\r
-                                }\r
-\r
-                            /****************************/\r
-                            /* Set the new output value */\r
-                            /****************************/\r
-\r
-               \r
-                                outl(dw_StatusReg,devpriv->s_BoardInfos.\r
-                                    ui_Address + 8 + ((b_OutputChannel / 8) * 4) + (64 * b_ModulNbr));\r
-                            }\r
-                         }\r
-                      }\r
-                   else\r
-                      {\r
-                      /************************************/\r
-                      /* The selected TTL output is wrong */\r
-                      /************************************/\r
-\r
-                          DPRINTK(" The selected TTL output is wrong\n");      \r
-                      i_ReturnValue = -4;\r
-                      }\r
-                   }\r
-                else\r
-                   {\r
-                   /************************************/\r
-                   /* The selected TTL output is wrong */\r
-                   /************************************/\r
-\r
-                       DPRINTK("The selected TTL output is wrong\n");  \r
-                   i_ReturnValue = -4;\r
-                   }\r
-                }\r
-             else\r
-                {\r
-                /***************************/\r
-                /* TTL I/O not initialised */\r
-                /***************************/\r
-\r
-                DPRINTK("TTL I/O not initialised\n");  \r
-                i_ReturnValue = -5;\r
-                }\r
-             }\r
-          else\r
-             {\r
-             /**************************************/\r
-             /* The module is not a TTL I/O module */\r
-             /**************************************/\r
-\r
-             DPRINTK("The module is not a TTL I/O module\n");          \r
-             i_ReturnValue = -3;\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /***********************/\r
-          /* Module number error */\r
-          /***********************/\r
-\r
-          DPRINTK("Module number error\n");    \r
-          i_ReturnValue = -2;\r
-          }\r
-\r
-       return (i_ReturnValue);\r
-       }\r
-\r
-\r
+/**
+@verbatim
+
+Copyright (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 USA
+
+You 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 : TTL.C           | Version  : 2.96                       |
+  +-------------------------------+---------------------------------------+
+  | Project manager: Eric Stolz   | Date     :  02/12/2002                |
+  +-----------------------------------------------------------------------+
+  | Description :   APCI-1710 TTL I/O module                              |
+  |                                                                       |
+  |                                                                       |
+  +-----------------------------------------------------------------------+
+  |                             UPDATES                                   |
+  +-----------------------------------------------------------------------+
+  |   Date   |   Author  |          Description of updates                |
+  +----------+-----------+------------------------------------------------+
+  | 13/05/98 | S. Weber  | TTL digital input / output implementation      |
+  |----------|-----------|------------------------------------------------|
+  | 08/05/00 | Guinot C  | - 0400/0228 All Function in RING 0             |
+  |          |           |   available                                    |
+  +-----------------------------------------------------------------------+
+  |          |           |                                                |
+  |          |           |                                                |
+  +-----------------------------------------------------------------------+
+*/
+
+/*
++----------------------------------------------------------------------------+
+|                               Included files                               |
++----------------------------------------------------------------------------+
+*/
+
+#include "APCI1710_Ttl.h"
+
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     : _INT_ i_APCI1710_InitTTLIODirection                    |
+|                               (BYTE_    b_BoardHandle,                     |
+|                               BYTE_    b_ModulNbr,                        |
+|                               BYTE_    b_PortAMode,                       |
+|                               BYTE_    b_PortBMode,                       |
+|                               BYTE_    b_PortCMode,                       |
+|                               BYTE_    b_PortDMode)                       |
++----------------------------------------------------------------------------+
+| Task           APCI1710_TTL_INIT (using defaults)   : Configure the TTL I/O operating mode from selected     |
+|                     module  (b_ModulNbr). You must calling this function be|
+|                     for you call any other function witch access of TTL.   |
+                                APCI1710_TTL_INITDIRECTION(user inputs for direction) 
+
++----------------------------------------------------------------------------+
+| Input Parameters  : BYTE_ b_BoardHandle         : Handle of board APCI-1710|
+|                     BYTE_ b_ModulNbr            : Module number to         |
+|                                                   configure (0 to 3)  
+               b_ModulNbr = (BYTE) CR_AREF(insn->chanspec);
+               b_InitType = (BYTE) data[0];
+               b_PortAMode     = (BYTE) data[1];
+               b_PortBMode = (BYTE) data[2];
+               b_PortCMode = (BYTE) data[3];
+               b_PortDMode     = (BYTE) data[4];|
++----------------------------------------------------------------------------+
+| Output Parameters : -                                                      |
++----------------------------------------------------------------------------+
+| Return Value      : 0: No error                                            |
+|                    -1: The handle parameter of the board is wrong          |
+|                    -2: The module parameter is wrong                       |
+|                    -3: The module is not a TTL module                      |
+|                   -4: Function not available for this version             |
+|                   -5: Port A mode selection is wrong                      |
+|                   -6: Port B mode selection is wrong                      |
+|                   -7: Port C mode selection is wrong                      |
+|                   -8: Port D mode selection is wrong                      |
++----------------------------------------------------------------------------+
+*/
+
+
+INT   i_APCI1710_InsnConfigInitTTLIO(comedi_device *dev,comedi_subdevice *s,
+       comedi_insn *insn,lsampl_t *data) 
+       {
+               INT             i_ReturnValue = 0;
+               BYTE    b_ModulNbr;
+               BYTE    b_InitType;
+               BYTE    b_PortAMode;
+               BYTE    b_PortBMode;
+               BYTE    b_PortCMode;
+               BYTE    b_PortDMode;
+
+               b_ModulNbr = (BYTE) CR_AREF(insn->chanspec);
+               b_InitType = (BYTE) data[0];
+               i_ReturnValue = insn->n;
+
+       /**************************/
+       /* Test the module number */
+       /**************************/
+                                                                                                                                                                          
+       if (b_ModulNbr < 4)
+          {
+          /**************************/
+          /* Test if TTL I/O module */
+          /**************************/
+
+          if ((devpriv->s_BoardInfos.
+               dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_TTL_IO)
+             {
+            switch(b_InitType)
+                       {
+                       case APCI1710_TTL_INIT :
+
+                       devpriv->s_ModuleInfo [b_ModulNbr].
+             s_TTLIOInfo.b_TTLInit = 1;
+
+             /***************************/
+             /* Set TTL port A to input */
+             /***************************/
+
+             devpriv->s_ModuleInfo [b_ModulNbr].
+             s_TTLIOInfo.
+             b_PortConfiguration [0] = 0;
+
+             /***************************/
+             /* Set TTL port B to input */
+             /***************************/
+
+             devpriv->s_ModuleInfo [b_ModulNbr].
+             s_TTLIOInfo.
+             b_PortConfiguration [1] = 0;
+
+             /***************************/
+             /* Set TTL port C to input */
+             /***************************/
+
+             devpriv->s_ModuleInfo [b_ModulNbr].
+             s_TTLIOInfo.
+             b_PortConfiguration [2] = 0;
+
+             /****************************/
+             /* Set TTL port D to output */
+             /****************************/
+
+             devpriv->s_ModuleInfo [b_ModulNbr].
+             s_TTLIOInfo.
+             b_PortConfiguration [3] = 1;
+
+             /*************************/
+             /* Set the configuration */
+             /*************************/
+                       
+                 outl(0x8,devpriv->s_BoardInfos.ui_Address + 20 + (64 * b_ModulNbr));
+                       break;
+
+
+                       case APCI1710_TTL_INITDIRECTION :
+
+                       b_PortAMode     = (BYTE) data[1];
+                       b_PortBMode = (BYTE) data[2];
+                       b_PortCMode = (BYTE) data[3];
+                       b_PortDMode     = (BYTE) data[4];
+
+             /********************/
+             /* Test the version */
+             /********************/
+
+             if ((devpriv->s_BoardInfos.
+                  dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) >= 0x3230)
+                {
+                /************************/
+                /* Test the port A mode */
+                /************************/
+
+                if ((b_PortAMode == 0) || (b_PortAMode == 1))
+                   {
+                   /************************/
+                   /* Test the port B mode */
+                   /************************/
+
+                   if ((b_PortBMode == 0) || (b_PortBMode == 1))
+                      {
+                      /************************/
+                      /* Test the port C mode */
+                      /************************/
+
+                      if ((b_PortCMode == 0) || (b_PortCMode == 1))
+                         {
+                         /************************/
+                         /* Test the port D mode */
+                         /************************/
+
+                         if ((b_PortDMode == 0) || (b_PortDMode == 1))
+                            {
+                            devpriv->s_ModuleInfo [b_ModulNbr].
+                            s_TTLIOInfo.
+                            b_TTLInit = 1;
+
+                            /***********************/
+                            /* Set TTL port A mode */
+                            /***********************/
+
+                            devpriv->s_ModuleInfo [b_ModulNbr].
+                            s_TTLIOInfo.
+                            b_PortConfiguration [0] = b_PortAMode;
+
+                            /***********************/
+                            /* Set TTL port B mode */
+                            /***********************/
+
+                            devpriv->s_ModuleInfo [b_ModulNbr].
+                            s_TTLIOInfo.
+                            b_PortConfiguration [1] = b_PortBMode;
+
+                            /***********************/
+                            /* Set TTL port C mode */
+                            /***********************/
+
+                            devpriv->s_ModuleInfo [b_ModulNbr].
+                            s_TTLIOInfo.
+                            b_PortConfiguration [2] = b_PortCMode;
+
+                            /***********************/
+                            /* Set TTL port D mode */
+                            /***********************/
+
+                            devpriv->s_ModuleInfo [b_ModulNbr].
+                            s_TTLIOInfo.
+                            b_PortConfiguration [3] = b_PortDMode;
+
+                            /*************************/
+                            /* Set the configuration */
+                            /*************************/
+
+                            
+                                outl((b_PortAMode << 0) |
+                                         (b_PortBMode << 1) |
+                                         (b_PortCMode << 2) |
+                                         (b_PortDMode << 3),devpriv->s_BoardInfos.
+                                    ui_Address + 20 + (64 * b_ModulNbr));
+                            }
+                         else
+                            {
+                            /**********************************/
+                            /* Port D mode selection is wrong */
+                            /**********************************/
+
+                        DPRINTK("Port D mode selection is wrong\n");
+                            i_ReturnValue = -8;
+                            }
+                         }
+                      else
+                         {
+                         /**********************************/
+                         /* Port C mode selection is wrong */
+                         /**********************************/
+
+                         DPRINTK("Port C mode selection is wrong\n");
+                         i_ReturnValue = -7;
+                         }
+                      }
+                   else
+                      {
+                      /**********************************/
+                      /* Port B mode selection is wrong */
+                      /**********************************/
+
+                          DPRINTK("Port B mode selection is wrong\n");
+                      i_ReturnValue = -6;
+                      }
+                   }
+                else
+                   {
+                   /**********************************/
+                   /* Port A mode selection is wrong */
+                   /**********************************/
+
+                       DPRINTK("Port A mode selection is wrong\n");
+                   i_ReturnValue = -5;
+                   }
+                }
+             else
+                {
+                /*******************************************/
+                /* Function not available for this version */
+                /*******************************************/
+
+                DPRINTK("Function not available for this version\n");
+                i_ReturnValue = -4;
+                }
+                 break;
+
+                 DPRINTK("\n");
+                 default:
+                         printk("Bad Config Type\n");
+                 }// switch end
+             }
+          else
+             {
+             /**********************************/
+             /* The module is not a TTL module */
+             /**********************************/
+
+             DPRINTK("The module is not a TTL module\n");
+             i_ReturnValue = -3;
+             }
+          }
+       else
+          {
+          /***********************/
+          /* Module number error */
+          /***********************/
+
+          DPRINTK("Module number error\n");
+          i_ReturnValue = -2;
+          }
+
+       return (i_ReturnValue);
+       }
+
+
+/*
++----------------------------------------------------------------------------+
+|                            INPUT FUNCTIONS                                 |
++----------------------------------------------------------------------------+
+*/
+
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     : _INT_   i_APCI1710_ReadTTLIOChannelValue               |
+|                                       (BYTE_     b_BoardHandle,            |
+|                                        BYTE_     b_ModulNbr,               |
+|                                        BYTE_     b_SelectedPort,           |
+|                                        BYTE_     b_InputChannel,           |
+|                                        PBYTE_   pb_ChannelStatus)          |
++----------------------------------------------------------------------------+
+| Task              : Read the status from selected TTL digital input        |
+|                     (b_InputChannel) 
++----------------------------------------------------------------------------+
+| Task              : Read the status from digital input port                |
+|                     (b_SelectedPort) from selected TTL module (b_ModulNbr) |
++----------------------------------------------------------------------------+ 
+
++----------------------------------------------------------------------------+
+| Input Parameters  : BYTE_ b_BoardHandle         : Handle of board APCI-1710|
+|                     BYTE_ b_ModulNbr            : Module number to         |
+|                                                   configure (0 to 7)       |
+|                     BYTE_ b_SelectedPort,       : Selection from TTL I/O   |
+|                                                   port (0 to 2)            |
+|                                                      0 : Port A selection  |
+|                                                      1 : Port B selection  |
+|                                                      2 : Port C selection  |
+|                                                      3 : Port D selection  |
+|                     BYTE_ b_InputChannel        : Selection from digital   |
+|                                                   input ( 0 to 2)        
+APCI1710_TTL_READCHANNEL  
+       b_ModulNbr        = CR_AREF(insn->chanspec);
+       b_SelectedPort= CR_RANGE(insn->chanspec);
+       b_InputChannel= CR_CHAN(insn->chanspec);
+       b_ReadType        = (BYTE) data[0];
+
+ APCI1710_TTL_READPORT|
+       b_ModulNbr        = CR_AREF(insn->chanspec);
+       b_SelectedPort= CR_RANGE(insn->chanspec);
+       b_ReadType        = (BYTE) data[0];
+
++----------------------------------------------------------------------------+
+| Output Parameters : data[0]
+
+       PBYTE_  pb_ChannelStatus    : Digital input channel    |
+|                                                   status                   |
+|                                                   0 : Channle is not active|
+|                                                   1 : Channle is active    |
++----------------------------------------------------------------------------+
+| Return Value      : 0: No error                                            |
+|                    -1: The handle parameter of the board is wrong          |
+|                    -2: The module parameter is wrong                       |
+|                    -3: The module is not a TTL module                      |
+|                    -4: The selected TTL input port is wrong                |
+|                    -5: The selected TTL digital input is wrong             |
+|                    -6: TTL I/O not initialised                             |
++----------------------------------------------------------------------------+
+*/
+
+
+INT  i_APCI1710_InsnBitsReadTTLIO(comedi_device *dev,comedi_subdevice *s,
+       comedi_insn *insn,lsampl_t *data)
+       {
+       INT    i_ReturnValue = 0;
+       DWORD dw_StatusReg;
+       BYTE    b_ModulNbr;
+       BYTE    b_SelectedPort;
+       BYTE    b_InputChannel;
+       BYTE    b_ReadType;
+       PBYTE   pb_ChannelStatus;
+       PBYTE  pb_PortValue;
+       
+               
+       i_ReturnValue = insn->n;
+       b_ReadType        = (BYTE) data[0];
+       b_ModulNbr        = CR_AREF(insn->chanspec);
+       b_SelectedPort= CR_RANGE(insn->chanspec);
+       b_InputChannel= CR_CHAN(insn->chanspec);
+
+       
+       
+       
+       /**************************/
+       /* Test the module number */
+       /**************************/
+
+       if (b_ModulNbr < 4)
+          {
+          /**************************/
+          /* Test if TTL I/O module */
+          /**************************/
+
+          if ((devpriv->s_BoardInfos.
+               dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_TTL_IO)
+             {
+                  switch(b_ReadType)
+                  {
+
+                  case APCI1710_TTL_READCHANNEL:
+                       pb_ChannelStatus = (PBYTE) &data[0];
+             /********************************/
+             /* Test the TTL I/O port number */
+             /********************************/
+
+             if (((b_SelectedPort <= 2) && ((devpriv->s_BoardInfos.
+                                             dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) == 0x3130)) ||
+                 ((b_SelectedPort <= 3) && ((devpriv->s_BoardInfos.
+                                            dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) >= 0x3230)))
+                {
+                /******************************************/
+                /* Test the digital imnput channel number */
+                /******************************************/
+
+                if (((b_InputChannel <= 7) && (b_SelectedPort < 3)) ||
+                    ((b_InputChannel <= 1) && (b_SelectedPort == 3)))
+                   {
+                   /******************************************/
+                   /* Test if the TTL I/O module initialised */
+                   /******************************************/
+
+                   if (devpriv->s_ModuleInfo [b_ModulNbr].
+                       s_TTLIOInfo.
+                       b_TTLInit == 1)
+                      {
+                      /***********************************/
+                      /* Test if TTL port used for input */
+                      /***********************************/
+
+                      if (((devpriv->s_BoardInfos.
+                            dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) == 0x3130) ||
+                          (((devpriv->s_BoardInfos.
+                             dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) >= 0x3230) &&
+                           (devpriv->s_ModuleInfo [b_ModulNbr].
+                            s_TTLIOInfo.
+                            b_PortConfiguration [b_SelectedPort] == 0)))
+                         {
+                         /**************************/
+                         /* Read all digital input */
+                         /**************************/
+                       
+                               dw_StatusReg = inl(devpriv->s_BoardInfos.ui_Address + (64 * b_ModulNbr));
+
+                         *pb_ChannelStatus = (BYTE) ((dw_StatusReg >> (8 * b_SelectedPort)) >>
+ b_InputChannel) & 1;
+                         }
+                      else
+                         {
+                         /*******************************/
+                         /* Selected TTL I/O port error */
+                         /*******************************/
+
+                         DPRINTK("Selected TTL I/O port error\n");
+                         i_ReturnValue = -4;
+                         }
+                      }
+                   else
+                      {
+                      /***************************/
+                      /* TTL I/O not initialised */
+                      /***************************/
+
+                          DPRINTK("TTL I/O not initialised\n");        
+                      i_ReturnValue = -6;
+                      }
+                   }
+                else
+                   {
+                   /********************************/
+                   /* Selected digital input error */
+                   /********************************/
+
+                       DPRINTK("Selected digital input error\n");
+                   i_ReturnValue = -5;
+                   }
+                }
+             else
+                {
+                /*******************************/
+                /* Selected TTL I/O port error */
+                /*******************************/
+
+                DPRINTK("Selected TTL I/O port error\n");
+                i_ReturnValue = -4;
+                }
+                 break;
+
+                 case APCI1710_TTL_READPORT:
+                         pb_PortValue = (PBYTE) &data[0];
+                         /********************************/
+                         /* Test the TTL I/O port number */
+                         /********************************/
+
+             if (((b_SelectedPort <= 2) && ((devpriv->s_BoardInfos.
+                                             dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) == 0x3130)) ||
+                 ((b_SelectedPort <= 3) && ((devpriv->s_BoardInfos.
+                                             dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) >= 0x3230)))
+                {
+                /******************************************/
+                /* Test if the TTL I/O module initialised */
+                /******************************************/
+
+                if (devpriv->s_ModuleInfo [b_ModulNbr].
+                    s_TTLIOInfo.
+                    b_TTLInit == 1)
+                   {
+                   /***********************************/
+                   /* Test if TTL port used for input */
+                   /***********************************/
+
+                   if (((devpriv->s_BoardInfos.
+                         dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) == 0x3130) ||
+                       (((devpriv->s_BoardInfos.
+                          dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) >= 0x3230) &&
+                        (devpriv->s_ModuleInfo [b_ModulNbr].
+                         s_TTLIOInfo.
+                         b_PortConfiguration [b_SelectedPort] == 0)))
+                       {
+                      /**************************/
+                      /* Read all digital input */
+                      /**************************/
+                               
+                               dw_StatusReg=inl(devpriv->s_BoardInfos.ui_Address + (64 * b_ModulNbr));
+
+                      *pb_PortValue = (BYTE) ((dw_StatusReg >> (8 * b_SelectedPort)) & 0xFF);
+                      }
+                   else
+                      {
+                      /*******************************/
+                      /* Selected TTL I/O port error */
+                      /*******************************/
+
+                      DPRINTK("Selected TTL I/O port error\n");
+                      i_ReturnValue = -4;
+                      }
+                   }
+                else
+                   {
+                   /***************************/
+                   /* TTL I/O not initialised */
+                   /***************************/
+
+                       DPRINTK("TTL I/O not initialised\n");
+                   i_ReturnValue = -5;
+                   }
+                }
+             else
+                {
+                /*******************************/
+                /* Selected TTL I/O port error */
+                /*******************************/
+
+                DPRINTK("Selected TTL I/O port error\n");      
+                i_ReturnValue = -4;
+                }
+                 break;
+
+                 default:
+                          printk("Bad ReadType\n");
+                  
+                  }//End Switch
+             }
+          else
+             {
+             /**********************************/
+             /* The module is not a TTL module */
+             /**********************************/
+
+             DPRINTK("The module is not a TTL module\n");      
+             i_ReturnValue = -3;
+             }
+          }
+       else
+          {
+          /***********************/
+          /* Module number error */
+          /***********************/
+
+          DPRINTK("Module number error\n");    
+          i_ReturnValue = -2;
+          }
+
+       return (i_ReturnValue);
+       }
+
+
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     : INT i_APCI1710_InsnReadTTLIOAllPortValue(comedi_device 
+*dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data)              |
++----------------------------------------------------------------------------+
+| Task              : Read the status from all digital input ports           |
+|                     (port A, port B and port C) from selected TTL          |
+|                    module (b_ModulNbr)                                    |
++----------------------------------------------------------------------------+
+| Input Parameters  : BYTE_ b_BoardHandle         : Handle of board APCI-1710|
+|                     BYTE_ b_ModulNbr            : Module number to         |
+|                                                   configure (0 to 3)       |
++----------------------------------------------------------------------------+
+| Output Parameters : PULONG_  pul_PortValue      : Digital TTL inputs port  |
+|                                                   status                   |
++----------------------------------------------------------------------------+
+| Return Value      : 0: No error                                            |
+|                    -1: The handle parameter of the board is wrong          |
+|                    -2: The module parameter is wrong                       |
+|                    -3: The module is not a TTL module                      |
+|                    -4: TTL I/O not initialised                             |
++----------------------------------------------------------------------------+
+*/
+
+INT i_APCI1710_InsnReadTTLIOAllPortValue(comedi_device *dev,comedi_subdevice *s,
+comedi_insn *insn,lsampl_t *data)
+       {
+       INT    i_ReturnValue = 0;
+       DWORD dw_StatusReg;
+       BYTE    b_ModulNbr;
+        PULONG pul_PortValue;
+      
+        b_ModulNbr=(BYTE) CR_AREF(insn->chanspec); 
+        i_ReturnValue=insn->n;
+        pul_PortValue=(PULONG) &data[0]; 
+
+       /**************************/
+       /* Test the module number */
+       /**************************/
+
+       if (b_ModulNbr < 4)
+          {
+          /**************************/
+          /* Test if TTL I/O module */
+          /**************************/
+
+          if ((devpriv->s_BoardInfos.
+               dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_TTL_IO)
+             {
+             /******************************************/
+             /* Test if the TTL I/O module initialised */
+             /******************************************/
+
+             if (devpriv->
+                 s_ModuleInfo [b_ModulNbr].
+                 s_TTLIOInfo.
+                 b_TTLInit == 1)
+                {
+                /**************************/
+                /* Read all digital input */
+                /**************************/
+
+
+                       dw_StatusReg=inl(devpriv->s_BoardInfos.
+                       ui_Address + (64 * b_ModulNbr));
+
+                /**********************/
+                /* Test if TTL Rev1.0 */
+                /**********************/
+
+                if ((devpriv->s_BoardInfos.
+                     dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) == 0x3130)
+                   {
+                   *pul_PortValue = dw_StatusReg & 0xFFFFFFUL;
+                   }
+                else
+                   {
+                   /**************************************/
+                   /* Test if port A not used for output */
+                   /**************************************/
+
+                   if (devpriv->s_ModuleInfo [b_ModulNbr].
+                       s_TTLIOInfo.b_PortConfiguration [0] == 1)
+                      {
+                      *pul_PortValue = dw_StatusReg & 0x3FFFF00UL;
+                      }
+
+                   /**************************************/
+                   /* Test if port B not used for output */
+                   /**************************************/
+
+                   if (devpriv->
+                       s_ModuleInfo [b_ModulNbr].
+                       s_TTLIOInfo.
+                       b_PortConfiguration [1] == 1)
+                      {
+                      *pul_PortValue = dw_StatusReg & 0x3FF00FFUL;
+                      }
+
+                   /**************************************/
+                   /* Test if port C not used for output */
+                   /**************************************/
+
+                   if (devpriv->
+                       s_ModuleInfo [b_ModulNbr].
+                       s_TTLIOInfo.
+                       b_PortConfiguration [2] == 1)
+                      {
+                      *pul_PortValue = dw_StatusReg & 0x300FFFFUL;
+                      }
+
+                   /**************************************/
+                   /* Test if port D not used for output */
+                   /**************************************/
+
+                   if (devpriv->
+                       s_ModuleInfo [b_ModulNbr].
+                       s_TTLIOInfo.
+                       b_PortConfiguration [3] == 1)
+                      {
+                      *pul_PortValue = dw_StatusReg & 0xFFFFFFUL;
+                      }
+                   }
+                }
+             else
+                {
+                /***************************/
+                /* TTL I/O not initialised */
+                /***************************/
+                DPRINTK("TTL I/O not initialised\n");
+                i_ReturnValue = -5;
+                }
+             }
+          else
+             {
+             /**********************************/
+             /* The module is not a TTL module */
+             /**********************************/
+             DPRINTK("The module is not a TTL module\n");      
+             i_ReturnValue = -3;
+             }
+          }
+       else
+          {
+          /***********************/
+          /* Module number error */
+          /***********************/
+          DPRINTK("Module number error\n");
+          i_ReturnValue = -2;
+          }
+
+       return (i_ReturnValue);
+       }
+
+/*
++----------------------------------------------------------------------------+
+|                            OUTPUT FUNCTIONS                                |
++----------------------------------------------------------------------------+
+*/
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     : _INT_ i_APCI1710_SetTTLIOChlOn                         |
+|                               (BYTE_           b_BoardHandle,              |
+|                                BYTE_           b_ModulNbr,                 |
+|                                BYTE_           b_OutputChannel) 
+INT i_APCI1710_InsnWriteSetTTLIOChlOnOff(comedi_device *dev,comedi_subdevice *s,
+       comedi_insn *insn,lsampl_t *data)           |
++----------------------------------------------------------------------------+
+| Task              : Sets or resets  the output witch has been passed with the         |
+|                     parameter b_Channel. Setting an output means setting   |
+|                     an ouput high.                                         |
++----------------------------------------------------------------------------+
+| Input Parameters  : BYTE_ b_BoardHandle   : Handle of board APCI-1710      |
+|                     BYTE_ b_ModulNbr      : Selected module number (0 to 3)|
+|                     BYTE_ b_OutputChannel : Selection from digital output  |
+|                                             channel (0 or 1)               |
+|                                                0      : PD0                |
+|                                                1      : PD1                |
+|                                               2 to 9 : PA                 |
+|                                              10 to 17: PB                 |
+|                                              18 to 25: PC                 |
+
+  b_ModulNbr      = CR_AREF(insn->chanspec);
+       b_OutputChannel= CR_CHAN(insn->chanspec);
+       ui_State           = data[0]; // ON or OFF
++----------------------------------------------------------------------------+
+| Output Parameters : -                                                      |
++----------------------------------------------------------------------------+
+| Return Value      : 0: No error                                            |
+|                    -1: The handle parameter of the board is wrong          |
+|                    -2: The module parameter is wrong                       |
+|                    -3: The module is not a TTL I/O module                  |
+|                    -4: The selected digital output is wrong                |
+|                    -5: TTL I/O not initialised see function                |
+|                        " i_APCI1710_InitTTLIO"
++----------------------------------------------------------------------------+
+*/
+
+INT i_APCI1710_InsnWriteSetTTLIOChlOnOff(comedi_device *dev,comedi_subdevice *s,
+       comedi_insn *insn,lsampl_t *data)
+       {
+       INT    i_ReturnValue = 0;       
+       DWORD dw_StatusReg   = 0;
+       BYTE b_ModulNbr;
+       BYTE b_OutputChannel;
+       UINT ui_State;
+
+       i_ReturnValue  = insn->n;
+       b_ModulNbr         = CR_AREF(insn->chanspec);
+       b_OutputChannel= CR_CHAN(insn->chanspec);
+       ui_State           = data[0]; // ON or OFF
+
+       /**************************/
+       /* Test the module number */
+       /**************************/
+
+       if (b_ModulNbr < 4)
+          {
+          /**************************/
+          /* Test if TTL I/O module */
+          /**************************/
+
+          if ((devpriv->s_BoardInfos.
+               dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_TTL_IO)
+             {
+             /******************************************/
+             /* Test if the TTL I/O module initialised */
+             /******************************************/
+
+             if (devpriv->s_ModuleInfo [b_ModulNbr].
+                 s_TTLIOInfo.
+                 b_TTLInit == 1)
+                {
+                /***********************************/
+                /* Test the TTL I/O channel number */
+                /***********************************/
+
+                if (((b_OutputChannel <= 1) && ((devpriv->s_BoardInfos.
+                                                dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) == 0x3130)) ||
+                    ((b_OutputChannel <= 25) && ((devpriv->s_BoardInfos.
+                                                 dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF) >= 0x3230)))
+                   {
+                   /****************************************************/
+                   /* Test if the selected channel is a output channel */
+                   /****************************************************/
+
+                   if (((b_OutputChannel <= 1) && (devpriv->
+                       s_ModuleInfo [b_ModulNbr].
+                                                                             s_TTLIOInfo.
+                                                                             b_PortConfiguration [3] == 1)) ||
+                       ((b_OutputChannel >= 2) && (b_OutputChannel <= 9) && (devpriv->s_ModuleInfo [b_ModulNbr].
+                                                                             s_TTLIOInfo.
+                                                                             b_PortConfiguration [0] == 1)) ||
+                       ((b_OutputChannel >= 10) && (b_OutputChannel <= 17) && (devpriv->s_ModuleInfo [b_ModulNbr].
+                                                                               s_TTLIOInfo.
+                                                                               b_PortConfiguration [1] == 1)) ||
+                       ((b_OutputChannel >= 18) && (b_OutputChannel <= 25) && (devpriv->s_ModuleInfo [b_ModulNbr].
+                                                                               s_TTLIOInfo.
+                                                                               b_PortConfiguration [2] == 1)))
+                      {
+                      /************************/
+                      /* Test if PD0 selected */
+                      /************************/
+
+                      if (b_OutputChannel == 0)
+                         {
+
+                outl(ui_State,devpriv->s_BoardInfos.
+                                 ui_Address + (64 * b_ModulNbr));
+                         }
+                      else
+              {
+                         /************************/
+                         /* Test if PD1 selected */
+                         /************************/
+
+                         if (b_OutputChannel == 1)
+                            {
+
+                                 outl(ui_State,devpriv->s_BoardInfos.
+                                    ui_Address + 4 + (64 * b_ModulNbr));
+                            }
+                         else
+                            {
+                            b_OutputChannel = b_OutputChannel - 2;
+
+                            /********************/
+                            /* Read all channel */
+                            /********************/
+
+                           
+                                       dw_StatusReg =inl(devpriv->s_BoardInfos.
+                                   ui_Address + (64 * b_ModulNbr));
+                 if(ui_State) // ON
+                 {
+                            dw_StatusReg = (dw_StatusReg >> ((b_OutputChannel / 8) * 8)) & 0xFF;
+                            dw_StatusReg = dw_StatusReg | (1 << (b_OutputChannel % 8));
+                                }else    // Off
+                                {
+                 dw_StatusReg = (dw_StatusReg >> ((b_OutputChannel / 8) * 8)) & 0xFF;
+                            dw_StatusReg = dw_StatusReg & (0xFF - (1 << (b_OutputChannel % 8)));
+
+                                }
+
+                            /****************************/
+                            /* Set the new output value */
+                            /****************************/
+
+               
+                                outl(dw_StatusReg,devpriv->s_BoardInfos.
+                                    ui_Address + 8 + ((b_OutputChannel / 8) * 4) + (64 * b_ModulNbr));
+                            }
+                         }
+                      }
+                   else
+                      {
+                      /************************************/
+                      /* The selected TTL output is wrong */
+                      /************************************/
+
+                          DPRINTK(" The selected TTL output is wrong\n");      
+                      i_ReturnValue = -4;
+                      }
+                   }
+                else
+                   {
+                   /************************************/
+                   /* The selected TTL output is wrong */
+                   /************************************/
+
+                       DPRINTK("The selected TTL output is wrong\n");  
+                   i_ReturnValue = -4;
+                   }
+                }
+             else
+                {
+                /***************************/
+                /* TTL I/O not initialised */
+                /***************************/
+
+                DPRINTK("TTL I/O not initialised\n");  
+                i_ReturnValue = -5;
+                }
+             }
+          else
+             {
+             /**************************************/
+             /* The module is not a TTL I/O module */
+             /**************************************/
+
+             DPRINTK("The module is not a TTL I/O module\n");          
+             i_ReturnValue = -3;
+             }
+          }
+       else
+          {
+          /***********************/
+          /* Module number error */
+          /***********************/
+
+          DPRINTK("Module number error\n");    
+          i_ReturnValue = -2;
+          }
+
+       return (i_ReturnValue);
+       }
+
+
index 25403ece6e160cce2e24a6a41981cbeade02d793..f94318e88d1e6f799620bb4ae817aaf09c751208 100644 (file)
@@ -1,62 +1,62 @@
-/**\r
-@verbatim\r
-\r
-Copyright (C) 2004,2005  ADDI-DATA GmbH for the source code of this module. \r
-        \r
-        ADDI-DATA GmbH \r
-        Dieselstrasse 3 \r
-        D-77833 Ottersweier \r
-        Tel: +19(0)7223/9493-0 \r
-        Fax: +49(0)7223/9493-92 \r
-        http://www.addi-data-com \r
-        info@addi-data.com \r
-\r
-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.\r
-\r
-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.\r
-\r
-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 USA\r
-\r
-You shoud also find the complete GPL in the COPYING file accompanying this source code.\r
-\r
-@endverbatim\r
-*/\r
-\r
-\r
-\r
-\r
-#define APCI1710_TTL_INIT                      0\r
-#define APCI1710_TTL_INITDIRECTION  1\r
-\r
-\r
-#define APCI1710_TTL_READCHANNEL       0\r
-#define APCI1710_TTL_READPORT          1\r
-\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-|                       TTL INISIALISATION FUNCTION                          |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-\r
-       INT   i_APCI1710_InsnConfigInitTTLIO(comedi_device *dev,comedi_subdevice *s,\r
-       comedi_insn *insn,lsampl_t *data);\r
-/*\r
-+----------------------------------------------------------------------------+\r
-|                       TTL INPUT FUNCTION                                   |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-       INT  i_APCI1710_InsnBitsReadTTLIO(comedi_device *dev,comedi_subdevice *s,\r
-       comedi_insn *insn,lsampl_t *data);\r
-       INT i_APCI1710_InsnReadTTLIOAllPortValue(comedi_device *dev,comedi_subdevice *s,\r
-       comedi_insn *insn,lsampl_t *data);\r
-/*\r
-+----------------------------------------------------------------------------+\r
-|                            TTL OUTPUT FUNCTIONS                            |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-       INT i_APCI1710_InsnWriteSetTTLIOChlOnOff(comedi_device *dev,comedi_subdevice *s,\r
-       comedi_insn *insn,lsampl_t *data);\r
+/**
+@verbatim
+
+Copyright (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 USA
+
+You shoud also find the complete GPL in the COPYING file accompanying this source code.
+
+@endverbatim
+*/
+
+
+
+
+#define APCI1710_TTL_INIT                      0
+#define APCI1710_TTL_INITDIRECTION  1
+
+
+#define APCI1710_TTL_READCHANNEL       0
+#define APCI1710_TTL_READPORT          1
+
+
+/*
++----------------------------------------------------------------------------+
+|                       TTL INISIALISATION FUNCTION                          |
++----------------------------------------------------------------------------+
+*/
+
+
+       INT   i_APCI1710_InsnConfigInitTTLIO(comedi_device *dev,comedi_subdevice *s,
+       comedi_insn *insn,lsampl_t *data);
+/*
++----------------------------------------------------------------------------+
+|                       TTL INPUT FUNCTION                                   |
++----------------------------------------------------------------------------+
+*/
+
+       INT  i_APCI1710_InsnBitsReadTTLIO(comedi_device *dev,comedi_subdevice *s,
+       comedi_insn *insn,lsampl_t *data);
+       INT i_APCI1710_InsnReadTTLIOAllPortValue(comedi_device *dev,comedi_subdevice *s,
+       comedi_insn *insn,lsampl_t *data);
+/*
++----------------------------------------------------------------------------+
+|                            TTL OUTPUT FUNCTIONS                            |
++----------------------------------------------------------------------------+
+*/
+
+       INT i_APCI1710_InsnWriteSetTTLIOChlOnOff(comedi_device *dev,comedi_subdevice *s,
+       comedi_insn *insn,lsampl_t *data);
index 305a39fd800c75140c58cb6de4d3438062188846..0419508bbfb4a3bc0e7eb47aaa73fc6d1776570c 100755 (executable)
-/**\r
-@verbatim\r
-\r
-Copyright (C) 2004,2005  ADDI-DATA GmbH for the source code of this module. \r
-        \r
-        ADDI-DATA GmbH \r
-        Dieselstrasse 3 \r
-        D-77833 Ottersweier \r
-        Tel: +19(0)7223/9493-0 \r
-        Fax: +49(0)7223/9493-92 \r
-        http://www.addi-data-com \r
-        info@addi-data.com \r
-\r
-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.\r
-\r
-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.\r
-\r
-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 USA\r
-\r
-You shoud also find the complete GPL in the COPYING file accompanying this source code.\r
-\r
-@endverbatim\r
-*/\r
-/*    \r
-  +-----------------------------------------------------------------------+\r
-  | (C) ADDI-DATA GmbH          Dieselstraße 3       D-77833 Ottersweier  |\r
-  +-----------------------------------------------------------------------+\r
-  | Tel : +49 (0) 7223/9493-0     | email    : info@addi-data.com         |\r
-  | Fax : +49 (0) 7223/9493-92    | Internet : http://www.addi-data.com   |\r
-  +-------------------------------+---------------------------------------+\r
-  | Project : ADDI HEADER READ WRITER |     Compiler   : Visual C++       |\r
-  | Module name : S5920.cpp           |     Version    : 6.0              |\r
-  +-------------------------------+---------------------------------------+\r
-  | Author : E. LIBS                      Date : 02/05/2002               |\r
-  +-----------------------------------------------------------------------+\r
-  | Description   : DLL with the S5920 PCI Controller functions           |\r
-  +-----------------------------------------------------------------------+     \r
-  |                             UPDATE'S                                  |\r
-  +-----------------------------------------------------------------------+\r
-  |   Date   |   Author  |          Description of updates                |\r
-  +----------+-----------+------------------------------------------------+\r
-  | 28/08/02 | LIBS Eric | Add return codes each time a function of the   |\r
-  |          |           | Addi Library is called                         |\r
-  +-----------------------------------------------------------------------+\r
-  | 31/07/03 | KRAUTH J. | Changes for the MSX-Box                        |\r
-  +-----------------------------------------------------------------------+\r
-*/\r
-\r
-\r
-#include "addi_amcc_S5920.h"\r
-\r
-/*+----------------------------------------------------------------------------+*/\r
-/*| Function   Name   : INT i_AddiHeaderRW_ReadEeprom                          |*/\r
-/*|                               (INT    i_NbOfWordsToRead,                   |*/ \r
-/*|                                DWORD dw_PCIBoardEepromAddress,             |*/\r
-/*|                                WORD   w_EepromStartAddress,                |*/\r
-/*|                                PWORD pw_DataRead)                          |*/\r
-/*+----------------------------------------------------------------------------+*/\r
-/*| Task              : Read word from the 5920 eeprom.                        |*/\r
-/*+----------------------------------------------------------------------------+*/\r
-/*| Input Parameters  : INT    i_NbOfWordsToRead : Nbr. of word to read        |*/ \r
-/*|                     DWORD dw_PCIBoardEepromAddress : Address of the eeprom |*/\r
-/*|                     WORD   w_EepromStartAddress : Eeprom strat address     |*/\r
-/*+----------------------------------------------------------------------------+*/\r
-/*| Output Parameters : PWORD pw_DataRead : Read data                          |*/                                                     \r
-/*+----------------------------------------------------------------------------+*/\r
-/*| Return Value      : -                                                      |*/\r
-/*+----------------------------------------------------------------------------+*/\r
-\r
-INT i_AddiHeaderRW_ReadEeprom (INT    i_NbOfWordsToRead,\r
-                               DWORD dw_PCIBoardEepromAddress,\r
-                               WORD   w_EepromStartAddress,\r
-                               PWORD pw_DataRead)\r
-{\r
-   DWORD dw_eeprom_busy=0;    \r
-   INT i_Counter=0;    \r
-   INT i_WordCounter;\r
-   INT i;\r
-   BYTE pb_ReadByte[1];\r
-   BYTE b_ReadLowByte = 0;\r
-   BYTE b_ReadHighByte = 0;\r
-   BYTE b_SelectedAddressLow = 0;\r
-   BYTE b_SelectedAddressHigh = 0;\r
-   WORD w_ReadWord = 0;\r
-   \r
-   for (i_WordCounter = 0;i_WordCounter<i_NbOfWordsToRead;i_WordCounter++)\r
-      {\r
-      do\r
-         {                           \r
-         dw_eeprom_busy = inl (dw_PCIBoardEepromAddress + AMCC_OP_REG_MCSR);\r
-         dw_eeprom_busy=dw_eeprom_busy & EEPROM_BUSY;\r
-         }\r
-      while (dw_eeprom_busy==EEPROM_BUSY);\r
-\r
-      for(i_Counter=0;i_Counter<2;i_Counter++)\r
-        {\r
-        b_SelectedAddressLow=(w_EepromStartAddress+i_Counter) % 256; //Read the low 8 bit part\r
-        b_SelectedAddressHigh=(w_EepromStartAddress+i_Counter)/256;  //Read the high 8 bit part\r
-\r
-        //Select the load low address mode\r
-       outb (NVCMD_LOAD_LOW, dw_PCIBoardEepromAddress+AMCC_OP_REG_MCSR+3);\r
-\r
-        //Wait on busy\r
-        do\r
-        {\r
-            dw_eeprom_busy = inl (dw_PCIBoardEepromAddress + AMCC_OP_REG_MCSR);\r
-            dw_eeprom_busy=dw_eeprom_busy & EEPROM_BUSY;\r
-        }\r
-        while(dw_eeprom_busy==EEPROM_BUSY);\r
-\r
-        //Load the low address\r
-        outb(b_SelectedAddressLow, dw_PCIBoardEepromAddress+AMCC_OP_REG_MCSR+2);\r
-\r
-        //Wait on busy\r
-        do\r
-        {\r
-             dw_eeprom_busy = inl (dw_PCIBoardEepromAddress + AMCC_OP_REG_MCSR);\r
-             dw_eeprom_busy=dw_eeprom_busy & EEPROM_BUSY;\r
-        }\r
-        while(dw_eeprom_busy== EEPROM_BUSY);\r
-\r
-        //Select the load high address mode\r
-        outb(NVCMD_LOAD_HIGH, dw_PCIBoardEepromAddress+AMCC_OP_REG_MCSR+3);\r
-\r
-        //Wait on busy\r
-        do\r
-        {\r
-            dw_eeprom_busy = inl (dw_PCIBoardEepromAddress + AMCC_OP_REG_MCSR);\r
-            dw_eeprom_busy=dw_eeprom_busy & EEPROM_BUSY;\r
-        }\r
-        while(dw_eeprom_busy== EEPROM_BUSY);\r
-\r
-        //Load the high address\r
-        outb (b_SelectedAddressHigh, dw_PCIBoardEepromAddress+AMCC_OP_REG_MCSR+2);\r
-\r
-        //Wait on busy\r
-        do\r
-        {\r
-            dw_eeprom_busy = inl (dw_PCIBoardEepromAddress + AMCC_OP_REG_MCSR);\r
-            dw_eeprom_busy=dw_eeprom_busy & EEPROM_BUSY;\r
-        }\r
-        while(dw_eeprom_busy== EEPROM_BUSY);\r
-\r
-        //Select the READ mode\r
-        outb (NVCMD_BEGIN_READ, dw_PCIBoardEepromAddress+AMCC_OP_REG_MCSR+3);\r
-\r
-        //Wait on busy\r
-        do\r
-        {\r
-            dw_eeprom_busy = inl (dw_PCIBoardEepromAddress + AMCC_OP_REG_MCSR);\r
-            dw_eeprom_busy=dw_eeprom_busy & EEPROM_BUSY;\r
-        }\r
-        while(dw_eeprom_busy== EEPROM_BUSY);\r
-\r
-        //Read data into the EEPROM\r
-        *pb_ReadByte = inb (dw_PCIBoardEepromAddress+AMCC_OP_REG_MCSR+2);\r
-\r
-        //Wait on busy\r
-        do\r
-        {\r
-            dw_eeprom_busy = inl (dw_PCIBoardEepromAddress + AMCC_OP_REG_MCSR);\r
-            dw_eeprom_busy=dw_eeprom_busy & EEPROM_BUSY;\r
-        }\r
-        while(dw_eeprom_busy== EEPROM_BUSY);\r
-\r
-        //Select the upper address part\r
-        if(i_Counter==0)\r
-        {   b_ReadLowByte=pb_ReadByte[0];\r
-        }else\r
-        {   b_ReadHighByte=pb_ReadByte[0];\r
-        }\r
-                \r
-        //Sleep\r
-        for (i=0; i < 10000; i++);\r
-   \r
-    }\r
-    w_ReadWord=(b_ReadLowByte|( ( (unsigned short) b_ReadHighByte) *256) );\r
-      \r
-    pw_DataRead[i_WordCounter]=w_ReadWord;\r
-\r
-    w_EepromStartAddress +=2; // to read the next word    \r
-\r
-   } // for (...) i_NbOfWordsToRead\r
-   return (0);\r
+/**
+@verbatim
+
+Copyright (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 USA
+
+You 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 : ADDI HEADER READ WRITER |     Compiler   : Visual C++       |
+  | Module name : S5920.cpp           |     Version    : 6.0              |
+  +-------------------------------+---------------------------------------+
+  | Author : E. LIBS                      Date : 02/05/2002               |
+  +-----------------------------------------------------------------------+
+  | Description   : DLL with the S5920 PCI Controller functions           |
+  +-----------------------------------------------------------------------+     
+  |                             UPDATE'S                                  |
+  +-----------------------------------------------------------------------+
+  |   Date   |   Author  |          Description of updates                |
+  +----------+-----------+------------------------------------------------+
+  | 28/08/02 | LIBS Eric | Add return codes each time a function of the   |
+  |          |           | Addi Library is called                         |
+  +-----------------------------------------------------------------------+
+  | 31/07/03 | KRAUTH J. | Changes for the MSX-Box                        |
+  +-----------------------------------------------------------------------+
+*/
+
+
+#include "addi_amcc_S5920.h"
+
+/*+----------------------------------------------------------------------------+*/
+/*| Function   Name   : INT i_AddiHeaderRW_ReadEeprom                          |*/
+/*|                               (INT    i_NbOfWordsToRead,                   |*/ 
+/*|                                DWORD dw_PCIBoardEepromAddress,             |*/
+/*|                                WORD   w_EepromStartAddress,                |*/
+/*|                                PWORD pw_DataRead)                          |*/
+/*+----------------------------------------------------------------------------+*/
+/*| Task              : Read word from the 5920 eeprom.                        |*/
+/*+----------------------------------------------------------------------------+*/
+/*| Input Parameters  : INT    i_NbOfWordsToRead : Nbr. of word to read        |*/ 
+/*|                     DWORD dw_PCIBoardEepromAddress : Address of the eeprom |*/
+/*|                     WORD   w_EepromStartAddress : Eeprom strat address     |*/
+/*+----------------------------------------------------------------------------+*/
+/*| Output Parameters : PWORD pw_DataRead : Read data                          |*/                                                     
+/*+----------------------------------------------------------------------------+*/
+/*| Return Value      : -                                                      |*/
+/*+----------------------------------------------------------------------------+*/
+
+INT i_AddiHeaderRW_ReadEeprom (INT    i_NbOfWordsToRead,
+                               DWORD dw_PCIBoardEepromAddress,
+                               WORD   w_EepromStartAddress,
+                               PWORD pw_DataRead)
+{
+   DWORD dw_eeprom_busy=0;    
+   INT i_Counter=0;    
+   INT i_WordCounter;
+   INT i;
+   BYTE pb_ReadByte[1];
+   BYTE b_ReadLowByte = 0;
+   BYTE b_ReadHighByte = 0;
+   BYTE b_SelectedAddressLow = 0;
+   BYTE b_SelectedAddressHigh = 0;
+   WORD w_ReadWord = 0;
+   
+   for (i_WordCounter = 0;i_WordCounter<i_NbOfWordsToRead;i_WordCounter++)
+      {
+      do
+         {                           
+         dw_eeprom_busy = inl (dw_PCIBoardEepromAddress + AMCC_OP_REG_MCSR);
+         dw_eeprom_busy=dw_eeprom_busy & EEPROM_BUSY;
+         }
+      while (dw_eeprom_busy==EEPROM_BUSY);
+
+      for(i_Counter=0;i_Counter<2;i_Counter++)
+        {
+        b_SelectedAddressLow=(w_EepromStartAddress+i_Counter) % 256; //Read the low 8 bit part
+        b_SelectedAddressHigh=(w_EepromStartAddress+i_Counter)/256;  //Read the high 8 bit part
+
+        //Select the load low address mode
+       outb (NVCMD_LOAD_LOW, dw_PCIBoardEepromAddress+AMCC_OP_REG_MCSR+3);
+
+        //Wait on busy
+        do
+        {
+            dw_eeprom_busy = inl (dw_PCIBoardEepromAddress + AMCC_OP_REG_MCSR);
+            dw_eeprom_busy=dw_eeprom_busy & EEPROM_BUSY;
+        }
+        while(dw_eeprom_busy==EEPROM_BUSY);
+
+        //Load the low address
+        outb(b_SelectedAddressLow, dw_PCIBoardEepromAddress+AMCC_OP_REG_MCSR+2);
+
+        //Wait on busy
+        do
+        {
+             dw_eeprom_busy = inl (dw_PCIBoardEepromAddress + AMCC_OP_REG_MCSR);
+             dw_eeprom_busy=dw_eeprom_busy & EEPROM_BUSY;
+        }
+        while(dw_eeprom_busy== EEPROM_BUSY);
+
+        //Select the load high address mode
+        outb(NVCMD_LOAD_HIGH, dw_PCIBoardEepromAddress+AMCC_OP_REG_MCSR+3);
+
+        //Wait on busy
+        do
+        {
+            dw_eeprom_busy = inl (dw_PCIBoardEepromAddress + AMCC_OP_REG_MCSR);
+            dw_eeprom_busy=dw_eeprom_busy & EEPROM_BUSY;
+        }
+        while(dw_eeprom_busy== EEPROM_BUSY);
+
+        //Load the high address
+        outb (b_SelectedAddressHigh, dw_PCIBoardEepromAddress+AMCC_OP_REG_MCSR+2);
+
+        //Wait on busy
+        do
+        {
+            dw_eeprom_busy = inl (dw_PCIBoardEepromAddress + AMCC_OP_REG_MCSR);
+            dw_eeprom_busy=dw_eeprom_busy & EEPROM_BUSY;
+        }
+        while(dw_eeprom_busy== EEPROM_BUSY);
+
+        //Select the READ mode
+        outb (NVCMD_BEGIN_READ, dw_PCIBoardEepromAddress+AMCC_OP_REG_MCSR+3);
+
+        //Wait on busy
+        do
+        {
+            dw_eeprom_busy = inl (dw_PCIBoardEepromAddress + AMCC_OP_REG_MCSR);
+            dw_eeprom_busy=dw_eeprom_busy & EEPROM_BUSY;
+        }
+        while(dw_eeprom_busy== EEPROM_BUSY);
+
+        //Read data into the EEPROM
+        *pb_ReadByte = inb (dw_PCIBoardEepromAddress+AMCC_OP_REG_MCSR+2);
+
+        //Wait on busy
+        do
+        {
+            dw_eeprom_busy = inl (dw_PCIBoardEepromAddress + AMCC_OP_REG_MCSR);
+            dw_eeprom_busy=dw_eeprom_busy & EEPROM_BUSY;
+        }
+        while(dw_eeprom_busy== EEPROM_BUSY);
+
+        //Select the upper address part
+        if(i_Counter==0)
+        {   b_ReadLowByte=pb_ReadByte[0];
+        }else
+        {   b_ReadHighByte=pb_ReadByte[0];
+        }
+                
+        //Sleep
+        for (i=0; i < 10000; i++);
+   
+    }
+    w_ReadWord=(b_ReadLowByte|( ( (unsigned short) b_ReadHighByte) *256) );
+      
+    pw_DataRead[i_WordCounter]=w_ReadWord;
+
+    w_EepromStartAddress +=2; // to read the next word    
+
+   } // for (...) i_NbOfWordsToRead
+   return (0);
 }
\ No newline at end of file
index d341c0624f727dfa147346c098d8d23c66fa56ee..22494772f59e2a0eb302f1fa34f662bba40de355 100755 (executable)
@@ -1,63 +1,63 @@
-/**\r
-@verbatim\r
-\r
-Copyright (C) 2004,2005  ADDI-DATA GmbH for the source code of this module. \r
-        \r
-        ADDI-DATA GmbH \r
-        Dieselstrasse 3 \r
-        D-77833 Ottersweier \r
-        Tel: +19(0)7223/9493-0 \r
-        Fax: +49(0)7223/9493-92 \r
-        http://www.addi-data-com \r
-        info@addi-data.com \r
-\r
-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.\r
-\r
-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.\r
-\r
-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 USA\r
-\r
-You shoud also find the complete GPL in the COPYING file accompanying this source code.\r
-\r
-@endverbatim\r
-*/\r
-/*\r
-#define VOID           void\r
-#define INT            int\r
-#define UINT           unsigned int\r
-#define SHORT          short\r
-#define USHORT         unsigned short\r
-#define CHAR           char\r
-#define BYTE           unsigned char\r
-#define WORD           unsigned int\r
-#define LONG           long\r
-#define ULONG          unsigned long\r
-#define DWORD          unsigned long\r
-#define DOUBLE         double\r
-#define PINT           int *\r
-#define PUINT          unsigned int *\r
-#define PSHORT         short *\r
-#define PUSHORT        unsigned short *\r
-#define PCHAR          char *\r
-#define PBYTE          unsigned char *\r
-#define PWORD          unsigned int *\r
-#define PLONG          long *\r
-#define PULONG         unsigned long *\r
-#define PDWORD         unsigned long *\r
-#define PDOUBLE        double *\r
-*/\r
-\r
-#define AMCC_OP_REG_MCSR         0x3c\r
-#define EEPROM_BUSY   0x80000000\r
-#define NVCMD_LOAD_LOW  (0x4 << 5 ) // nvRam load low command\r
-#define NVCMD_LOAD_HIGH (0x5 << 5 ) // nvRam load high command\r
-#define NVCMD_BEGIN_READ (0x7 << 5 ) // nvRam begin read command\r
-#define NVCMD_BEGIN_WRITE  (0x6 << 5)  //EEPROM begin write command\r
-\r
-INT i_AddiHeaderRW_ReadEeprom ( INT i_NbOfWordsToRead,\r
-                               DWORD dw_PCIBoardEepromAddress,\r
-                               WORD w_EepromStartAddress,\r
-                               PWORD pw_DataRead);\r
-\r
-\r
-\r
+/**
+@verbatim
+
+Copyright (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 USA
+
+You shoud also find the complete GPL in the COPYING file accompanying this source code.
+
+@endverbatim
+*/
+/*
+#define VOID           void
+#define INT            int
+#define UINT           unsigned int
+#define SHORT          short
+#define USHORT         unsigned short
+#define CHAR           char
+#define BYTE           unsigned char
+#define WORD           unsigned int
+#define LONG           long
+#define ULONG          unsigned long
+#define DWORD          unsigned long
+#define DOUBLE         double
+#define PINT           int *
+#define PUINT          unsigned int *
+#define PSHORT         short *
+#define PUSHORT        unsigned short *
+#define PCHAR          char *
+#define PBYTE          unsigned char *
+#define PWORD          unsigned int *
+#define PLONG          long *
+#define PULONG         unsigned long *
+#define PDWORD         unsigned long *
+#define PDOUBLE        double *
+*/
+
+#define AMCC_OP_REG_MCSR         0x3c
+#define EEPROM_BUSY   0x80000000
+#define NVCMD_LOAD_LOW  (0x4 << 5 ) // nvRam load low command
+#define NVCMD_LOAD_HIGH (0x5 << 5 ) // nvRam load high command
+#define NVCMD_BEGIN_READ (0x7 << 5 ) // nvRam begin read command
+#define NVCMD_BEGIN_WRITE  (0x6 << 5)  //EEPROM begin write command
+
+INT i_AddiHeaderRW_ReadEeprom ( INT i_NbOfWordsToRead,
+                               DWORD dw_PCIBoardEepromAddress,
+                               WORD w_EepromStartAddress,
+                               PWORD pw_DataRead);
+
+
+
index 874667748a619a6111410ceda620e576d660906d..7b83d7ad4da4d61d3f11088e916d643e1437bdd4 100644 (file)
@@ -2539,38 +2539,6 @@ static int i_ADDI_Attach(comedi_device *dev,comedi_devconfig *it)
        
        if ((this_board->pc_EepromChip == NULL) || (strcmp (this_board->pc_EepromChip, ADDIDATA_9054) != 0))
           {
-          if (iobase_main)
-             {
-             if (check_region(iobase_main, this_board->i_IorangeBase1) < 0) 
-                {
-                printk("I/O port conflict\n");
-                return -EIO;
-                }
-             }
-          
-           //if(this_board->i_Dma)
-           if(iobase_a) 
-              {
-             if (check_region(iobase_a, this_board->i_IorangeBase0) < 0) 
-                {
-                printk("AMCC check region failed\n"); 
-                printk("I/O port conflict\n");
-                return -EIO;
-               }
-             }
-
-          // ##
-          if(io_addr[2])
-             {
-             if (check_region(io_addr[2], this_board->i_IorangeBase2) < 0) 
-                {
-                printk("\nBase 2 check region failed"); 
-                printk("\nI/O port conflict");
-                return -EIO;
-                }
-             }
-          //##
-       
           /************************************/
           /* Test if more that 1 address used */
           /************************************/
@@ -2714,7 +2682,7 @@ static int i_ADDI_Attach(comedi_device *dev,comedi_devconfig *it)
                 {
                 for (pages=4; pages>=0; pages--)
                    {
-                   if((devpriv->ul_DmaBufferVirtual[i]=__get_free_pages(GFP_KERNEL,pages)))
+                   if((devpriv->ul_DmaBufferVirtual[i]=(void *)__get_free_pages(GFP_KERNEL,pages)))
                       {
                       break;
                       }
index 636efb10a2b0ef4c1949730b78df59feba737580..b0f5bb4acc83e40c5629da991c9e123dd260a406 100644 (file)
-/**\r
-@verbatim\r
-\r
-Copyright (C) 2004,2005  ADDI-DATA GmbH for the source code of this module. \r
-        \r
-        ADDI-DATA GmbH \r
-        Dieselstrasse 3 \r
-        D-77833 Ottersweier \r
-        Tel: +19(0)7223/9493-0 \r
-        Fax: +49(0)7223/9493-92 \r
-        http://www.addi-data-com \r
-        info@addi-data.com \r
-\r
-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.\r
-\r
-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.\r
-\r
-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 USA\r
-\r
-You shoud also find the complete GPL in the COPYING file accompanying this source code.\r
-\r
-@endverbatim\r
-*/\r
-/*\r
-    \r
-  +-----------------------------------------------------------------------+\r
-  | (C) ADDI-DATA GmbH          Dieselstrasse 3      D-77833 Ottersweier  |\r
-  +-----------------------------------------------------------------------+\r
-  | Tel : +49 (0) 7223/9493-0     | email    : info@addi-data.com         |\r
-  | Fax : +49 (0) 7223/9493-92    | Internet : http://www.addi-data.com   |\r
-  +-----------------------------------------------------------------------+\r
-  | Project   : ADDI DATA         | Compiler : GCC                                   |\r
-  | Modulname : addi_eeprom.c     | Version  : 2.96                       |\r
-  +-------------------------------+---------------------------------------+\r
-  | Project manager: Eric Stolz   | Date     :  02/12/2002                |\r
-  +-----------------------------------------------------------------------+\r
-  | Description : ADDI EEPROM  Module                                     |\r
-  +-----------------------------------------------------------------------+\r
-  |                             UPDATE'S                                  |\r
-  +-----------------------------------------------------------------------+\r
-  |   Date   |   Author  |          Description of updates                |\r
-  +----------+-----------+------------------------------------------------+\r
-  |          |                  |                                                |\r
-  |          |           |                                               |\r
-  +----------+-----------+------------------------------------------------+\r
-*/\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-#define NVCMD_BEGIN_READ       (0x7 << 5 ) // nvRam begin read command\r
-#define NVCMD_LOAD_LOW         (0x4 << 5 ) // nvRam load low command\r
-#define NVCMD_LOAD_HIGH        (0x5 << 5 ) // nvRam load high command\r
-#define EE76_CMD_LEN           13              // bits in instructions \r
-#define EE_READ                0x0180          // 01 1000 0000 read instruction\r
-\r
-#define        WORD                            unsigned short\r
-#define PWORD                          unsigned short *\r
-#define PDWORD                         unsigned int  *\r
-\r
-#define        DWORD                           unsigned int\r
-\r
-\r
-\r
-#define EEPROM_DIGITALINPUT                    0\r
-#define EEPROM_DIGITALOUTPUT                   1\r
-#define EEPROM_ANALOGINPUT                             2\r
-#define EEPROM_ANALOGOUTPUT                            3\r
-#define EEPROM_TIMER                                   4\r
-#define EEPROM_WATCHDOG                                        5                       \r
-#define EEPROM_TIMER_WATCHDOG_COUNTER  10\r
-\r
-struct str_Functionality\r
-{\r
-       BYTE b_Type;\r
-       WORD w_Address;\r
-};\r
-\r
-\r
-typedef struct \r
-{\r
-       WORD w_HeaderSize;\r
-       BYTE b_Nfunctions;\r
-       struct str_Functionality s_Functions[7];\r
-}str_MainHeader;\r
-\r
-\r
-\r
-typedef struct\r
-{\r
- WORD w_Nchannel;\r
- BYTE b_Interruptible;\r
- WORD w_NinterruptLogic;\r
-}str_DigitalInputHeader;\r
-\r
-typedef struct\r
-{\r
- WORD w_Nchannel;\r
-}str_DigitalOutputHeader;\r
-\r
-// used for timer as well as watchdog\r
-\r
-typedef struct\r
-{\r
-  WORD w_HeaderSize;\r
-  BYTE b_Resolution;\r
-  BYTE b_Mode;                // in case of Watchdog it is functionality \r
-  WORD w_MinTiming;\r
-  BYTE b_TimeBase;\r
-}str_TimerDetails;\r
-typedef struct\r
-{\r
-\r
-  WORD w_Ntimer;\r
-  str_TimerDetails s_TimerDetails[4];  //  supports 4 timers\r
-}str_TimerMainHeader;  \r
-\r
-\r
-typedef struct\r
-{\r
-  WORD w_Nchannel;\r
-  BYTE b_Resolution;\r
-  }str_AnalogOutputHeader ;\r
-\r
-typedef struct\r
-{\r
-  WORD w_Nchannel;\r
-  WORD w_MinConvertTiming;\r
-  WORD w_MinDelayTiming;\r
-  BYTE b_HasDma;\r
-  BYTE b_Resolution;\r
-} str_AnalogInputHeader;\r
-\r
-               /*****************************************/\r
-               /*            Read Header Functions              */\r
-               /*****************************************/\r
-\r
-INT i_EepromReadMainHeader(WORD        w_PCIBoardEepromAddress,PCHAR   pc_PCIChipInformation,comedi_device *dev);\r
-\r
-INT i_EepromReadDigitalInputHeader(WORD w_PCIBoardEepromAddress,PCHAR pc_PCIChipInformation,WORD w_Address,str_DigitalInputHeader *s_Header);\r
-\r
-INT i_EepromReadDigitalOutputHeader(WORD w_PCIBoardEepromAddress,PCHAR pc_PCIChipInformation,WORD w_Address,str_DigitalOutputHeader *s_Header);\r
-\r
-INT i_EepromReadTimerHeader(WORD w_PCIBoardEepromAddress,PCHAR pc_PCIChipInformation,WORD w_Address,str_TimerMainHeader *s_Header);\r
-\r
-INT i_EepromReadAnlogOutputHeader(WORD w_PCIBoardEepromAddress,PCHAR pc_PCIChipInformation,WORD w_Address,str_AnalogOutputHeader *s_Header);\r
-\r
-INT i_EepromReadAnlogInputHeader(WORD w_PCIBoardEepromAddress,PCHAR pc_PCIChipInformation,WORD w_Address,str_AnalogInputHeader *s_Header);\r
-\r
-               /******************************************/\r
-               /*      Eeprom Specific Functions                         */\r
-               /******************************************/\r
-WORD w_EepromReadWord(WORD     w_PCIBoardEepromAddress,PCHAR   pc_PCIChipInformation,WORD   w_EepromStartAddress);\r
-VOID v_EepromWaitBusy(WORD     w_PCIBoardEepromAddress);\r
-VOID v_EepromClock76(DWORD dw_Address,DWORD dw_RegisterValue);\r
-VOID v_EepromWaitBusy(WORD     w_PCIBoardEepromAddress);\r
-VOID v_EepromSendCommand76(DWORD dw_Address,DWORD   dw_EepromCommand,BYTE    b_DataLengthInBits);\r
-VOID v_EepromCs76Read(DWORD dw_Address,WORD    w_offset,PWORD   pw_Value);\r
-\r
-\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function   Name   : WORD w_EepromReadWord                                  |\r
-|                              (WORD   w_PCIBoardEepromAddress,                         |\r
-|                               PCHAR  pc_PCIChipInformation,                           |\r
-|                               WORD   w_EepromStartAddress)                            |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Read from eepromn a word                               |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : WORD w_PCIBoardEepromAddress : PCI eeprom address      |\r
-|                                                                                                                                       |\r
-|                    PCHAR pc_PCIChipInformation  : PCI Chip Type.          |\r
-|                                                                                                                                       |\r
-|                    WORD w_EepromStartAddress    : Selected eeprom address |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : -                                                      |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      : Read word value from eeprom                            |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-WORD   w_EepromReadWord(WORD   w_PCIBoardEepromAddress,PCHAR   pc_PCIChipInformation,WORD   w_EepromStartAddress)\r
-\r
-{\r
-\r
-       BYTE b_Counter = 0;\r
-\r
-       BYTE b_ReadByte = 0;\r
-\r
-       BYTE b_ReadLowByte = 0;\r
-\r
-       BYTE b_ReadHighByte = 0;\r
-\r
-       BYTE b_SelectedAddressLow = 0;\r
-\r
-       BYTE b_SelectedAddressHigh = 0;\r
-\r
-       WORD w_ReadWord = 0;\r
-\r
-       \r
-\r
-\r
-        /**************************/\r
-\r
-        /* Test the PCI chip type */\r
-\r
-        /**************************/\r
-\r
-\r
-\r
-\r
-        if ((!strcmp(pc_PCIChipInformation, "S5920")) || \r
-\r
-            (!strcmp(pc_PCIChipInformation, "S5933")))\r
-\r
-        {\r
-\r
-               \r
-          for (b_Counter=0; b_Counter<2; b_Counter++)\r
-\r
-            {\r
-\r
-              b_SelectedAddressLow  = (w_EepromStartAddress + b_Counter) % 256; //Read the low 8 bit part\r
-\r
-              b_SelectedAddressHigh = (w_EepromStartAddress + b_Counter) / 256; //Read the high 8 bit part\r
-\r
-\r
-\r
-             /************************************/\r
-\r
-             /* Select the load low address mode */\r
-\r
-             /************************************/\r
-\r
-\r
-             outb(NVCMD_LOAD_LOW,w_PCIBoardEepromAddress + 0x3F);\r
-            \r
-\r
-             \r
-             /****************/\r
-\r
-             /* Wait on busy */\r
-\r
-             /****************/\r
-\r
-             v_EepromWaitBusy (w_PCIBoardEepromAddress);\r
-\r
-\r
-             /************************/\r
-\r
-             /* Load the low address */\r
-\r
-             /************************/\r
-\r
-\r
-             outb(b_SelectedAddressLow,w_PCIBoardEepromAddress + 0x3E);\r
-             \r
-\r
-     \r
-             /****************/\r
-\r
-             /* Wait on busy */\r
-\r
-             /****************/\r
-\r
-             v_EepromWaitBusy (w_PCIBoardEepromAddress);\r
-\r
-\r
-\r
-             /*************************************/\r
-\r
-             /* Select the load high address mode */\r
-\r
-             /*************************************/\r
-\r
-\r
-             outb(NVCMD_LOAD_HIGH,w_PCIBoardEepromAddress + 0x3F);\r
-            \r
-\r
-\r
-             /****************/\r
-\r
-             /* Wait on busy */\r
-\r
-             /****************/\r
-\r
-             v_EepromWaitBusy (w_PCIBoardEepromAddress);\r
-\r
-\r
-\r
-             /*************************/\r
-\r
-             /* Load the high address */\r
-\r
-             /*************************/\r
-\r
-\r
-             outb(b_SelectedAddressHigh,w_PCIBoardEepromAddress +0x3E);        \r
-            \r
-\r
-             /****************/\r
-\r
-             /* Wait on busy */\r
-\r
-             /****************/\r
-\r
-             v_EepromWaitBusy (w_PCIBoardEepromAddress);\r
-\r
-\r
-\r
-             /************************/\r
-\r
-             /* Select the READ mode */\r
-\r
-             /************************/\r
-\r
-\r
-             outb(NVCMD_BEGIN_READ,w_PCIBoardEepromAddress + 0x3F);  \r
-            \r
-\r
-             /****************/\r
-\r
-             /* Wait on busy */\r
-\r
-             /****************/\r
-\r
-\r
-             v_EepromWaitBusy (w_PCIBoardEepromAddress);\r
-\r
-\r
-\r
-             /*****************************/\r
-\r
-             /* Read data into the EEPROM */\r
-\r
-             /*****************************/\r
-\r
-              b_ReadByte = inb(w_PCIBoardEepromAddress + 0x3E);  \r
-\r
-            \r
-\r
-             \r
-             /****************/\r
-\r
-             /* Wait on busy */\r
-\r
-             /****************/\r
-\r
-\r
-\r
-             v_EepromWaitBusy (w_PCIBoardEepromAddress);\r
-\r
-\r
-\r
-             /*********************************/\r
-\r
-             /* Select the upper address part */\r
-\r
-             /*********************************/\r
-\r
-\r
-\r
-             if(b_Counter==0)\r
-\r
-                {\r
-\r
-                b_ReadLowByte=b_ReadByte;\r
-\r
-                } // if(b_Counter==0)\r
-\r
-             else\r
-\r
-                {\r
-\r
-                b_ReadHighByte=b_ReadByte;\r
-\r
-                } // if(b_Counter==0)\r
-\r
-           } // for (b_Counter=0; b_Counter<2; b_Counter++)\r
-\r
-\r
-\r
-          w_ReadWord=(b_ReadLowByte | (((WORD) b_ReadHighByte) * 256));\r
-\r
-        \r
-     \r
-           } // end of if ((!strcmp(pc_PCIChipInformation, "S5920")) || (!strcmp(pc_PCIChipInformation, "S5933"))) \r
-\r
-        if (!strcmp(pc_PCIChipInformation, "93C76"))\r
-\r
-           {\r
-\r
-           /*************************************/\r
-\r
-           /* Read 16 bit from the EEPROM 93C76 */\r
-\r
-           /*************************************/\r
-\r
-\r
-         \r
-           v_EepromCs76Read(w_PCIBoardEepromAddress, w_EepromStartAddress, &w_ReadWord);\r
-\r
-           }\r
-\r
-             \r
-       return (w_ReadWord);\r
-\r
-       }\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-/*\r
-\r
-+----------------------------------------------------------------------------+\r
-\r
-| Function   Name   : VOID v_EepromWaitBusy                                  |\r
-\r
-|                      (WORD   w_PCIBoardEepromAddress)                         |\r
-\r
-+----------------------------------------------------------------------------+\r
-\r
-| Task              : Wait the busy flag from PCI controller                 |\r
-\r
-+----------------------------------------------------------------------------+\r
-\r
-| Input Parameters  : WORD w_PCIBoardEepromAddress : PCI eeprom base address |\r
-\r
-+----------------------------------------------------------------------------+\r
-\r
-| Output Parameters : -                                                      |\r
-\r
-+----------------------------------------------------------------------------+\r
-\r
-| Return Value      : -                                                      |\r
-\r
-+----------------------------------------------------------------------------+\r
-\r
-*/\r
-\r
-\r
-\r
-VOID   v_EepromWaitBusy(WORD   w_PCIBoardEepromAddress)\r
-\r
-       {\r
-\r
-       BYTE b_EepromBusy = 0;\r
-\r
-\r
-\r
-       do\r
-\r
-         {\r
-\r
-          /*************/\r
-\r
-          /* IMPORTANT */\r
-\r
-          /*************/\r
-\r
-\r
-\r
-          /************************************************************************/\r
-\r
-          /* An error has been written in the AMCC 5933 book at the page B-13*/\r
-        \r
-           /* Ex: if you read a byte and look for the busy statusEEPROM=0x80 and   */\r
\r
-          /*      the operator register is AMCC_OP_REG_MCSR+3*/\r
\r
-          /*      WORD read  EEPROM=0x8000 andAMCC_OP_REG_MCSR+2                  */\r
-        \r
-           /*      DWORD read  EEPROM=0x80000000 and AMCC_OP_REG_MCSR */\r
-         \r
-           /************************************************************************/\r
\r
\r
-                  b_EepromBusy = inb(w_PCIBoardEepromAddress + 0x3F);             \r
-          b_EepromBusy = b_EepromBusy &0x80;\r
-\r
-        }\r
-       while(b_EepromBusy == 0x80);\r
\r
-\r
-\r
-       }\r
-\r
-\r
-\r
-\r
-\r
-\r
-/*\r
-\r
-+---------------------------------------------------------------------------------+\r
-\r
-| Function   Name   : VOID v_EepromClock76(DWORD dw_Address,                      |\r
-\r
-|                                         DWORD dw_RegisterValue)                                        |\r
-\r
-+---------------------------------------------------------------------------------+\r
-\r
-| Task              : This function sends the clocking sequence to the EEPROM.    |\r
-\r
-+---------------------------------------------------------------------------------+\r
-\r
-| Input Parameters  : DWORD dw_Address : PCI eeprom base address                  |\r
-\r
-|                    DWORD dw_RegisterValue : PCI eeprom register value to write.|\r
-\r
-+---------------------------------------------------------------------------------+\r
-\r
-| Output Parameters : -                                                           |\r
-\r
-+---------------------------------------------------------------------------------+\r
-\r
-| Return Value      : -                                                           |\r
-\r
-+---------------------------------------------------------------------------------+\r
-\r
-*/\r
-\r
-\r
-\r
-VOID v_EepromClock76(DWORD dw_Address,DWORD dw_RegisterValue)\r
-\r
-   {\r
-\r
-\r
-\r
-   /************************/\r
-\r
-   /* Set EEPROM clock Low */\r
-\r
-   /************************/\r
-\r
-  \r
-outl(dw_RegisterValue & 0x6,dw_Address);\r
-\r
-   /***************/\r
-\r
-   /* Wait 0.1 ms */\r
-\r
-   /***************/\r
-\r
-\r
-    udelay(100);\r
-   \r
-\r
-   /*************************/\r
-\r
-   /* Set EEPROM clock High */\r
-\r
-   /*************************/\r
-\r
-\r
-  outl(dw_RegisterValue | 0x1,dw_Address);\r
-\r
-\r
-   /***************/\r
-\r
-   /* Wait 0.1 ms */\r
-\r
-   /***************/\r
-\r
-\r
-   udelay(100);\r
-\r
-   }\r
-\r
-\r
-\r
-/*\r
-\r
-+---------------------------------------------------------------------------------+\r
-\r
-| Function   Name   : VOID v_EepromSendCommand76(DWORD dw_Address,                |\r
-\r
-|                                         DWORD   dw_EepromCommand,                              |\r
-\r
-|                                         BYTE    b_DataLengthInBits)                        |\r
-\r
-+---------------------------------------------------------------------------------+\r
-\r
-| Task              : This function sends a Command to the EEPROM 93C76.          |\r
-\r
-+---------------------------------------------------------------------------------+\r
-\r
-| Input Parameters  : DWORD dw_Address : PCI eeprom base address                  |\r
-\r
-|                    DWORD dw_EepromCommand : PCI eeprom command to write.       |\r
-\r
-|                    BYTE  b_DataLengthInBits : PCI eeprom command data length.  |\r
-\r
-+---------------------------------------------------------------------------------+\r
-\r
-| Output Parameters : -                                                           |\r
-\r
-+---------------------------------------------------------------------------------+\r
-\r
-| Return Value      : -                                                           |\r
-\r
-+---------------------------------------------------------------------------------+\r
-\r
-*/\r
-\r
-\r
-\r
-VOID v_EepromSendCommand76(DWORD dw_Address,DWORD   dw_EepromCommand,BYTE    b_DataLengthInBits)\r
-\r
-   {\r
-\r
-   CHAR  c_BitPos = 0;\r
-\r
-   DWORD dw_RegisterValue = 0;\r
-\r
-\r
-\r
\r
-\r
-   /*****************************/\r
-\r
-   /* Enable EEPROM Chip Select */\r
-\r
-   /*****************************/\r
-\r
-   dw_RegisterValue = 0x2;\r
-\r
-\r
-\r
-   /********************************************************************/\r
-\r
-   /* Toggle EEPROM's Chip select to get it out of Shift Register Mode */\r
-\r
-   /********************************************************************/\r
-\r
-   outl(dw_RegisterValue,dw_Address);\r
-\r
\r
-\r
-\r
-   /***************/\r
-\r
-   /* Wait 0.1 ms */\r
-\r
-   /***************/\r
-\r
-  \r
-udelay(100);\r
\r
-   \r
-\r
-   /*******************************************/\r
-\r
-   /* Send EEPROM command - one bit at a time */\r
-\r
-   /*******************************************/\r
-   \r
-\r
-   for (c_BitPos = (b_DataLengthInBits - 1); c_BitPos >= 0; c_BitPos--)\r
-\r
-      {\r
-\r
-\r
-      /**********************************/\r
-\r
-      /* Check if current bit is 0 or 1 */\r
-\r
-      /**********************************/\r
-\r
-\r
-      if (dw_EepromCommand & (1 << c_BitPos))\r
-\r
-        {\r
-\r
-        /***********/\r
-\r
-        /* Write 1 */\r
-\r
-        /***********/\r
-\r
-\r
-\r
-        dw_RegisterValue = dw_RegisterValue | 0x4;\r
-\r
-        }\r
-\r
-      else\r
-\r
-        {\r
-\r
-        /***********/\r
-\r
-        /* Write 0 */\r
-\r
-        /***********/\r
-\r
-\r
-\r
-        dw_RegisterValue = dw_RegisterValue & 0x3;\r
-\r
-        }\r
-\r
-\r
-\r
-      /*********************/\r
-\r
-      /* Write the command */\r
-\r
-      /*********************/\r
-\r
-\r
-      outl(dw_RegisterValue,dw_Address);\r
-  \r
-\r
-\r
-      /***************/\r
-\r
-      /* Wait 0.1 ms */\r
-\r
-      /***************/\r
-\r
-   \r
-  udelay(100);\r
-  \r
-   \r
-\r
-      /****************************/\r
-\r
-      /* Trigger the EEPROM clock */\r
-\r
-      /****************************/\r
-\r
-      v_EepromClock76(dw_Address, dw_RegisterValue);\r
-\r
-\r
-      }\r
-\r
-\r
-\r
-   }\r
-\r
-\r
-\r
-/*\r
-\r
-+---------------------------------------------------------------------------------+\r
-\r
-| Function   Name   : VOID v_EepromCs76Read(DWORD dw_Address,                     |\r
-\r
-|                                         WORD    w_offset,                                              |\r
-\r
-|                                         PWORD   pw_Value)                                              |\r
-\r
-+---------------------------------------------------------------------------------+\r
-\r
-| Task              : This function read a value from the EEPROM 93C76.           |\r
-\r
-+---------------------------------------------------------------------------------+\r
-\r
-| Input Parameters  : DWORD dw_Address : PCI eeprom base address                  |\r
-\r
-|                    WORD    w_offset : Offset of the adress to read             |\r
-\r
-|                    PWORD   pw_Value : PCI eeprom 16 bit read value.            |\r
-\r
-+---------------------------------------------------------------------------------+\r
-\r
-| Output Parameters : -                                                           |\r
-\r
-+---------------------------------------------------------------------------------+\r
-\r
-| Return Value      : -                                                           |\r
-\r
-+---------------------------------------------------------------------------------+\r
-\r
-*/\r
-\r
-\r
-\r
-VOID v_EepromCs76Read(DWORD dw_Address,WORD    w_offset,\r
-PWORD   pw_Value)\r
-\r
-   {\r
-\r
-   CHAR   c_BitPos = 0;\r
-\r
-   DWORD  dw_RegisterValue = 0;\r
-\r
-   DWORD  dw_RegisterValueRead = 0;\r
-\r
-\r
-\r
-\r
-\r
-   /*************************************************/\r
-\r
-   /* Send EEPROM read command and offset to EEPROM */\r
-\r
-   /*************************************************/\r
-\r
-   v_EepromSendCommand76(dw_Address, (EE_READ << 4) | (w_offset / 2), EE76_CMD_LEN);\r
-\r
-\r
-\r
-   /*******************************/\r
-\r
-   /* Get the last register value */\r
-\r
-   /*******************************/\r
-\r
-   dw_RegisterValue = (((w_offset / 2) & 0x1) << 2) | 0x2;\r
-\r
-   \r
-\r
-   /*****************************/\r
-\r
-   /* Set the 16-bit value of 0 */\r
-\r
-   /*****************************/\r
-\r
-\r
-   *pw_Value = 0;\r
-\r
-\r
-\r
-   /************************/\r
-\r
-   /* Get the 16-bit value */\r
-\r
-   /************************/\r
-\r
-   for (c_BitPos = 0; c_BitPos < 16; c_BitPos++)\r
-\r
-      {\r
-\r
-\r
-      /****************************/\r
-\r
-      /* Trigger the EEPROM clock */\r
-\r
-      /****************************/\r
-\r
-\r
-      v_EepromClock76(dw_Address, dw_RegisterValue);\r
-\r
-\r
-\r
-      /**********************/\r
-\r
-      /* Get the result bit */\r
-\r
-      /**********************/\r
-\r
-\r
-     dw_RegisterValueRead = inl(dw_Address);\r
-\r
-      /***************/\r
-\r
-      /* Wait 0.1 ms */\r
-\r
-      /***************/\r
-\r
-   \r
-  udelay(100);\r
-     \r
-\r
-      /***************************************/\r
-\r
-      /* Get bit value and shift into result */\r
-\r
-      /***************************************/\r
-\r
-\r
-      if (dw_RegisterValueRead & 0x8)\r
-\r
-        {\r
-\r
-\r
-        /**********/\r
-\r
-        /* Read 1 */\r
-\r
-        /**********/\r
-\r
-\r
-        *pw_Value = (*pw_Value << 1) | 0x1;\r
-\r
-        }\r
-\r
-      else\r
-\r
-        {\r
-\r
-        /**********/\r
-\r
-        /* Read 0 */\r
-\r
-        /**********/\r
-\r
-        *pw_Value = (*pw_Value << 1);\r
-\r
-        \r
-       }\r
-\r
-      }\r
-\r
-\r
-\r
-   /*************************/\r
-\r
-   /* Clear all EEPROM bits */\r
-\r
-   /*************************/\r
-\r
-\r
-   dw_RegisterValue = 0x0;\r
-\r
-\r
-\r
-   /********************************************************************/\r
-\r
-   /* Toggle EEPROM's Chip select to get it out of Shift Register Mode */\r
-\r
-   /********************************************************************/\r
-\r
-\r
-  outl(dw_RegisterValue,dw_Address);\r
-     \r
-   /***************/\r
-\r
-   /* Wait 0.1 ms */\r
-\r
-   /***************/\r
-\r
-   udelay(100);\r
-    \r
-   }\r
-\r
-\r
-\r
-\r
-\r
-       /******************************************/\r
-       /*      EEPROM HEADER READ FUNCTIONS      */\r
-       /******************************************/\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name  : INT i_EepromReadMainHeader(WORD w_PCIBoardEepromAddress,  |\r
-|                              PCHAR   pc_PCIChipInformation,comedi_device *dev)    |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Read from eeprom Main Header                           |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : WORD w_PCIBoardEepromAddress : PCI eeprom address      |\r
-|                                                                                                                                       |      \r
-|                    PCHAR pc_PCIChipInformation  : PCI Chip Type.          |\r
-|                                                                                                                                       |\r
-|                        comedi_device *dev               : comedi device structure |\r
-|                                                                                       pointer                                 |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : -                                                      |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      : 0                                                                                     |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-\r
-INT i_EepromReadMainHeader(WORD        w_PCIBoardEepromAddress,PCHAR   pc_PCIChipInformation,comedi_device *dev)\r
-{\r
-       WORD w_Temp,i,w_Count=0;\r
-        UINT ui_Temp;\r
-       str_MainHeader  s_MainHeader;\r
-       str_DigitalInputHeader  s_DigitalInputHeader;\r
-       str_DigitalOutputHeader s_DigitalOutputHeader;\r
-       //str_TimerMainHeader     s_TimerMainHeader,s_WatchdogMainHeader;\r
-       str_AnalogOutputHeader   s_AnalogOutputHeader;\r
-       str_AnalogInputHeader   s_AnalogInputHeader;\r
-\r
-        // Read size\r
-       s_MainHeader.w_HeaderSize = w_EepromReadWord(w_PCIBoardEepromAddress,pc_PCIChipInformation,0x100+8);\r
-                \r
-        // Read nbr of functionality\r
-       w_Temp = w_EepromReadWord(w_PCIBoardEepromAddress,pc_PCIChipInformation,0x100+10);\r
-        s_MainHeader.b_Nfunctions =(BYTE)w_Temp & 0x00FF;\r
-\r
-       // Read functionality details\r
-       for(i=0;i<s_MainHeader.b_Nfunctions;i++)\r
-       {\r
-         // Read Type\r
-         w_Temp = w_EepromReadWord(w_PCIBoardEepromAddress,pc_PCIChipInformation,0x100+12+w_Count);\r
-         s_MainHeader.s_Functions[i].b_Type    =(BYTE) w_Temp & 0x3F;\r
-         w_Count=w_Count+2;\r
-       //Read Address\r
-        s_MainHeader.s_Functions[i].w_Address= w_EepromReadWord(w_PCIBoardEepromAddress,pc_PCIChipInformation,0x100+12+w_Count);    \r
-        w_Count=w_Count+2;\r
-       }\r
-\r
-        // Display main header info        \r
-       for(i=0;i<s_MainHeader.b_Nfunctions;i++)\r
-       {\r
-       \r
-          switch(s_MainHeader.s_Functions[i].b_Type)\r
-         {\r
-           case EEPROM_DIGITALINPUT:               \r
-                i_EepromReadDigitalInputHeader(w_PCIBoardEepromAddress,pc_PCIChipInformation,\r
-                s_MainHeader.s_Functions[i].w_Address,&s_DigitalInputHeader);  \r
-                 this_board->i_NbrDiChannel=s_DigitalInputHeader.w_Nchannel;\r
-                break;\r
-\r
-           case EEPROM_DIGITALOUTPUT:                 \r
-                i_EepromReadDigitalOutputHeader(w_PCIBoardEepromAddress,pc_PCIChipInformation,\r
-                s_MainHeader.s_Functions[i].w_Address,&s_DigitalOutputHeader);          \r
-                 this_board->i_NbrDoChannel=s_DigitalOutputHeader.w_Nchannel;\r
-                 ui_Temp=0xffffffff;\r
-                 this_board->i_DoMaxdata= ui_Temp >>(32 - this_board->i_NbrDoChannel);\r
-                break;\r
-\r
-           case EEPROM_ANALOGINPUT:\r
-                i_EepromReadAnlogInputHeader(w_PCIBoardEepromAddress,pc_PCIChipInformation,\r
-                s_MainHeader.s_Functions[i].w_Address,&s_AnalogInputHeader); \r
-                if (!(strcmp(this_board->pc_DriverName, "apci3200")))  \r
-                   this_board->i_NbrAiChannel=s_AnalogInputHeader.w_Nchannel * 4;\r
-                else\r
-                   this_board->i_NbrAiChannel=s_AnalogInputHeader.w_Nchannel;\r
-                 this_board->i_Dma=s_AnalogInputHeader.b_HasDma;\r
-                 this_board->ui_MinAcquisitiontimeNs=(UINT)s_AnalogInputHeader.w_MinConvertTiming * 1000;\r
-                 this_board->ui_MinDelaytimeNs      =(UINT)s_AnalogInputHeader.w_MinDelayTiming * 1000;  \r
-                 ui_Temp=0xffff;\r
-                 this_board->i_AiMaxdata = ui_Temp >> (16 - s_AnalogInputHeader.b_Resolution);\r
-                break;\r
-\r
-            case EEPROM_ANALOGOUTPUT:                                \r
-                i_EepromReadAnlogOutputHeader(w_PCIBoardEepromAddress,pc_PCIChipInformation,\r
-                s_MainHeader.s_Functions[i].w_Address,&s_AnalogOutputHeader);                 \r
-                 this_board->i_NbrAoChannel=s_AnalogOutputHeader.w_Nchannel;\r
-                 ui_Temp=0xffff;\r
-                 this_board->i_AoMaxdata= ui_Temp >>(16 - s_AnalogOutputHeader.b_Resolution);\r
-                break;\r
-\r
-           case EEPROM_TIMER:\r
-                this_board->i_Timer=1;//Timer subdevice present                                        \r
-                break;\r
-\r
-           case EEPROM_WATCHDOG:        \r
-                this_board->i_Timer=1; //Timer subdevice present \r
-                 break;\r
-\r
-            case EEPROM_TIMER_WATCHDOG_COUNTER:         \r
-                this_board->i_Timer=1; //Timer subdevice present                               \r
-         } \r
-       }\r
-\r
-       return 0;\r
-}\r
-\r
-\r
-\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name  : INT i_EepromReadDigitalInputHeader(WORD                                      |\r
-|                      w_PCIBoardEepromAddress,PCHAR pc_PCIChipInformation,     |\r
-|                      WORD w_Address,str_DigitalInputHeader *s_Header)                 |\r
-|                                                                                                                                       |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Read Digital Input Header                              |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : WORD w_PCIBoardEepromAddress : PCI eeprom address      |\r
-|                                                                                                                                       |\r
-|                    PCHAR pc_PCIChipInformation  : PCI Chip Type.          |\r
-|                                                                                                                                       |\r
-|                       str_DigitalInputHeader *s_Header: Digita Input Header   |\r
-|                                                                                                 Pointer                       |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : -                                                      |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      : 0                                                                                     |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-INT i_EepromReadDigitalInputHeader(WORD w_PCIBoardEepromAddress,PCHAR pc_PCIChipInformation,WORD w_Address,str_DigitalInputHeader *s_Header)\r
-{\r
-  WORD w_Temp;\r
-\r
- // read nbr of channels\r
- s_Header->w_Nchannel=w_EepromReadWord(w_PCIBoardEepromAddress,pc_PCIChipInformation,0x100+w_Address+6);\r
-\r
- // interruptible or not\r
- w_Temp=w_EepromReadWord(w_PCIBoardEepromAddress,pc_PCIChipInformation,0x100+w_Address+8);\r
- s_Header->b_Interruptible=(BYTE) (w_Temp>>7)& 0x01;\r
-\r
-// How many interruptible logic\r
- s_Header->w_NinterruptLogic=w_EepromReadWord(w_PCIBoardEepromAddress,pc_PCIChipInformation,0x100+w_Address+10);\r
-\r
- return 0;\r
-}\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name  : INT i_EepromReadDigitalOutputHeader(WORD                             |\r
-|                      w_PCIBoardEepromAddress,PCHAR pc_PCIChipInformation,     |\r
-|                      WORD w_Address,str_DigitalOutputHeader *s_Header)            |\r
-|                                                                                                                                       |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Read Digital Output Header                             |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : WORD w_PCIBoardEepromAddress : PCI eeprom address      |\r
-|                                                                                                                                       |\r
-|                    PCHAR pc_PCIChipInformation  : PCI Chip Type.          |\r
-|                                                                                                                                       |\r
-|                       str_DigitalOutputHeader *s_Header: Digital Output Header|\r
-|                                                                                         Pointer                               |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : -                                                      |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      : 0                                                                                     |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-INT i_EepromReadDigitalOutputHeader(WORD w_PCIBoardEepromAddress,PCHAR pc_PCIChipInformation,WORD w_Address,str_DigitalOutputHeader *s_Header)\r
-{\r
-// Read Nbr channels\r
- s_Header->w_Nchannel=w_EepromReadWord(w_PCIBoardEepromAddress,pc_PCIChipInformation,0x100+w_Address+6);\r
-return 0;\r
-}\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name  : INT i_EepromReadTimerHeader(WORD w_PCIBoardEepromAddress, |\r
-|                      PCHAR pc_PCIChipInformation,WORD w_Address,                              |\r
-|                      str_TimerMainHeader *s_Header)                                                   | \r
-+----------------------------------------------------------------------------+\r
-| Task              : Read Timer or Watchdog Header                          |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : WORD w_PCIBoardEepromAddress : PCI eeprom address      |\r
-|                                                                                                                                       |      \r
-|                    PCHAR pc_PCIChipInformation  : PCI Chip Type.          |\r
-|                                                                                                                                       |      \r
-|                       str_TimerMainHeader *s_Header: Timer Header                     |\r
-|                                                                                         Pointer                               |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : -                                                      |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      : 0                                                                                     |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-INT i_EepromReadTimerHeader(WORD w_PCIBoardEepromAddress,PCHAR pc_PCIChipInformation,WORD w_Address,str_TimerMainHeader *s_Header)\r
-{\r
-\r
-WORD i,w_Size=0,w_Temp;\r
-  \r
-\r
-//Read No of Timer\r
-s_Header->w_Ntimer=w_EepromReadWord(w_PCIBoardEepromAddress,pc_PCIChipInformation,0x100+w_Address+6);\r
-//Read header size\r
-\r
-for(i=0;i<s_Header->w_Ntimer;i++)\r
-{\r
-  s_Header->s_TimerDetails[i].w_HeaderSize=w_EepromReadWord(w_PCIBoardEepromAddress,pc_PCIChipInformation,0x100+w_Address+8+w_Size+0);\r
-  w_Temp=w_EepromReadWord(w_PCIBoardEepromAddress,pc_PCIChipInformation,0x100+w_Address+8+w_Size+2) ;\r
-\r
-  //Read Resolution\r
-  s_Header->s_TimerDetails[i].b_Resolution=(BYTE)(w_Temp>>10)&0x3F;\r
-\r
-  //Read Mode\r
-  s_Header->s_TimerDetails[i].b_Mode           =(BYTE) (w_Temp>>4)&0x3F;\r
-\r
-  w_Temp=w_EepromReadWord(w_PCIBoardEepromAddress,pc_PCIChipInformation,0x100+w_Address+8+w_Size+4) ;\r
-\r
-  //Read MinTiming\r
-  s_Header->s_TimerDetails[i].w_MinTiming      =(w_Temp>>6)&0x3FF; \r
-\r
-  //Read Timebase\r
-  s_Header->s_TimerDetails[i].b_TimeBase       =(BYTE)(w_Temp)&0x3F; \r
-  w_Size += s_Header->s_TimerDetails[i].w_HeaderSize;\r
-}   \r
\r
-return 0;\r
-}\r
-\r
-\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name  : INT i_EepromReadAnlogOutputHeader(WORD                                       |\r
-|                      w_PCIBoardEepromAddress,PCHAR pc_PCIChipInformation,     |\r
-|                      WORD w_Address,str_AnalogOutputHeader *s_Header)         | \r
-+----------------------------------------------------------------------------+\r
-| Task              : Read Nalog Output  Header                              |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : WORD w_PCIBoardEepromAddress : PCI eeprom address      |\r
-|                                                                                                                                       |      \r
-|                    PCHAR pc_PCIChipInformation  : PCI Chip Type.          |\r
-|                                                                                                                                       |\r
-|                       str_AnalogOutputHeader *s_Header:Anlog Output Header    |\r
-|                                                                                         Pointer                               |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : -                                                      |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      : 0                                                                                     |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-INT i_EepromReadAnlogOutputHeader(WORD w_PCIBoardEepromAddress,PCHAR pc_PCIChipInformation,WORD w_Address,str_AnalogOutputHeader *s_Header)\r
-{\r
-  WORD w_Temp;\r
-  // No of channels for 1st hard component\r
-  w_Temp=w_EepromReadWord(w_PCIBoardEepromAddress,pc_PCIChipInformation,0x100+w_Address+10);\r
-  s_Header->w_Nchannel=(w_Temp>>4)& 0x03FF;\r
-  // Resolution for 1st hard component\r
-  w_Temp=w_EepromReadWord(w_PCIBoardEepromAddress,pc_PCIChipInformation,0x100+w_Address+16);\r
-  s_Header->b_Resolution=(BYTE)(w_Temp>>8) & 0xFF;\r
-  return 0;\r
-}\r
-\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name  : INT i_EepromReadAnlogInputHeader(WORD                                        |\r
-|                      w_PCIBoardEepromAddress,PCHAR pc_PCIChipInformation,     |\r
-|                      WORD w_Address,str_AnalogInputHeader *s_Header)          |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Read Nalog Output  Header                              |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : WORD w_PCIBoardEepromAddress : PCI eeprom address      |\r
-|                                                                                                                                       |\r
-|                    PCHAR pc_PCIChipInformation  : PCI Chip Type.          |\r
-|                                                                                                                                       |\r
-|                       str_AnalogInputHeader *s_Header:Anlog Input Header      |  \r
-|                                                                                         Pointer                               |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : -                                                      |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      : 0                                                                                     |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-// Reads only for ONE  hardware component\r
-INT i_EepromReadAnlogInputHeader(WORD w_PCIBoardEepromAddress,PCHAR pc_PCIChipInformation,WORD w_Address,str_AnalogInputHeader *s_Header)\r
-{\r
-  WORD w_Temp,w_Offset;\r
-  w_Temp=w_EepromReadWord(w_PCIBoardEepromAddress,pc_PCIChipInformation,0x100+w_Address+10);\r
-  s_Header->w_Nchannel=(w_Temp>>4)& 0x03FF;\r
-  s_Header->w_MinConvertTiming=w_EepromReadWord(w_PCIBoardEepromAddress,pc_PCIChipInformation,0x100+w_Address+16);\r
-s_Header->w_MinDelayTiming=w_EepromReadWord(w_PCIBoardEepromAddress,pc_PCIChipInformation,0x100+w_Address+30);\r
-w_Temp=w_EepromReadWord(w_PCIBoardEepromAddress,pc_PCIChipInformation,0x100+w_Address+20);\r
-s_Header->b_HasDma=(w_Temp>>13) & 0x01; // whether dma present or not\r
-\r
-w_Temp=w_EepromReadWord(w_PCIBoardEepromAddress,pc_PCIChipInformation,0x100+w_Address+72);// reading Y\r
-w_Temp=w_Temp & 0x00FF;\r
-if(w_Temp)//Y>0\r
-{\r
-w_Offset=74+(2*w_Temp)+(10*(1+(w_Temp/16)));// offset of first analog input single header\r
-w_Offset= w_Offset+2; // resolution\r
-}\r
-else//Y=0\r
-{ \r
-w_Offset=74; \r
-w_Offset= w_Offset+2; // resolution\r
-}\r
-\r
-// read Resolution\r
-w_Temp=w_EepromReadWord(w_PCIBoardEepromAddress,pc_PCIChipInformation,0x100+w_Address+w_Offset);\r
-s_Header->b_Resolution=w_Temp & 0x001F;// last 5 bits\r
-\r
-return 0;\r
-}\r
+/**
+@verbatim
+
+Copyright (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 USA
+
+You 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   : ADDI DATA         | Compiler : GCC                                   |
+  | Modulname : addi_eeprom.c     | Version  : 2.96                       |
+  +-------------------------------+---------------------------------------+
+  | Project manager: Eric Stolz   | Date     :  02/12/2002                |
+  +-----------------------------------------------------------------------+
+  | Description : ADDI EEPROM  Module                                     |
+  +-----------------------------------------------------------------------+
+  |                             UPDATE'S                                  |
+  +-----------------------------------------------------------------------+
+  |   Date   |   Author  |          Description of updates                |
+  +----------+-----------+------------------------------------------------+
+  |          |                  |                                                |
+  |          |           |                                               |
+  +----------+-----------+------------------------------------------------+
+*/
+
+
+
+
+
+
+
+
+#define NVCMD_BEGIN_READ       (0x7 << 5 ) // nvRam begin read command
+#define NVCMD_LOAD_LOW         (0x4 << 5 ) // nvRam load low command
+#define NVCMD_LOAD_HIGH        (0x5 << 5 ) // nvRam load high command
+#define EE76_CMD_LEN           13              // bits in instructions 
+#define EE_READ                0x0180          // 01 1000 0000 read instruction
+
+#define        WORD                            unsigned short
+#define PWORD                          unsigned short *
+#define PDWORD                         unsigned int  *
+
+#ifndef DWORD
+#define        DWORD                           unsigned int
+#endif
+
+
+
+#define EEPROM_DIGITALINPUT                    0
+#define EEPROM_DIGITALOUTPUT                   1
+#define EEPROM_ANALOGINPUT                             2
+#define EEPROM_ANALOGOUTPUT                            3
+#define EEPROM_TIMER                                   4
+#define EEPROM_WATCHDOG                                        5                       
+#define EEPROM_TIMER_WATCHDOG_COUNTER  10
+
+struct str_Functionality
+{
+       BYTE b_Type;
+       WORD w_Address;
+};
+
+
+typedef struct 
+{
+       WORD w_HeaderSize;
+       BYTE b_Nfunctions;
+       struct str_Functionality s_Functions[7];
+}str_MainHeader;
+
+
+
+typedef struct
+{
+ WORD w_Nchannel;
+ BYTE b_Interruptible;
+ WORD w_NinterruptLogic;
+}str_DigitalInputHeader;
+
+typedef struct
+{
+ WORD w_Nchannel;
+}str_DigitalOutputHeader;
+
+// used for timer as well as watchdog
+
+typedef struct
+{
+  WORD w_HeaderSize;
+  BYTE b_Resolution;
+  BYTE b_Mode;                // in case of Watchdog it is functionality 
+  WORD w_MinTiming;
+  BYTE b_TimeBase;
+}str_TimerDetails;
+typedef struct
+{
+
+  WORD w_Ntimer;
+  str_TimerDetails s_TimerDetails[4];  //  supports 4 timers
+}str_TimerMainHeader;  
+
+
+typedef struct
+{
+  WORD w_Nchannel;
+  BYTE b_Resolution;
+  }str_AnalogOutputHeader ;
+
+typedef struct
+{
+  WORD w_Nchannel;
+  WORD w_MinConvertTiming;
+  WORD w_MinDelayTiming;
+  BYTE b_HasDma;
+  BYTE b_Resolution;
+} str_AnalogInputHeader;
+
+               /*****************************************/
+               /*            Read Header Functions              */
+               /*****************************************/
+
+INT i_EepromReadMainHeader(WORD        w_PCIBoardEepromAddress,PCHAR   pc_PCIChipInformation,comedi_device *dev);
+
+INT i_EepromReadDigitalInputHeader(WORD w_PCIBoardEepromAddress,PCHAR pc_PCIChipInformation,WORD w_Address,str_DigitalInputHeader *s_Header);
+
+INT i_EepromReadDigitalOutputHeader(WORD w_PCIBoardEepromAddress,PCHAR pc_PCIChipInformation,WORD w_Address,str_DigitalOutputHeader *s_Header);
+
+INT i_EepromReadTimerHeader(WORD w_PCIBoardEepromAddress,PCHAR pc_PCIChipInformation,WORD w_Address,str_TimerMainHeader *s_Header);
+
+INT i_EepromReadAnlogOutputHeader(WORD w_PCIBoardEepromAddress,PCHAR pc_PCIChipInformation,WORD w_Address,str_AnalogOutputHeader *s_Header);
+
+INT i_EepromReadAnlogInputHeader(WORD w_PCIBoardEepromAddress,PCHAR pc_PCIChipInformation,WORD w_Address,str_AnalogInputHeader *s_Header);
+
+               /******************************************/
+               /*      Eeprom Specific Functions                         */
+               /******************************************/
+WORD w_EepromReadWord(WORD     w_PCIBoardEepromAddress,PCHAR   pc_PCIChipInformation,WORD   w_EepromStartAddress);
+VOID v_EepromWaitBusy(WORD     w_PCIBoardEepromAddress);
+VOID v_EepromClock76(DWORD dw_Address,DWORD dw_RegisterValue);
+VOID v_EepromWaitBusy(WORD     w_PCIBoardEepromAddress);
+VOID v_EepromSendCommand76(DWORD dw_Address,DWORD   dw_EepromCommand,BYTE    b_DataLengthInBits);
+VOID v_EepromCs76Read(DWORD dw_Address,WORD    w_offset,PWORD   pw_Value);
+
+
+
+/*
++----------------------------------------------------------------------------+
+| Function   Name   : WORD w_EepromReadWord                                  |
+|                              (WORD   w_PCIBoardEepromAddress,                         |
+|                               PCHAR  pc_PCIChipInformation,                           |
+|                               WORD   w_EepromStartAddress)                            |
++----------------------------------------------------------------------------+
+| Task              : Read from eepromn a word                               |
++----------------------------------------------------------------------------+
+| Input Parameters  : WORD w_PCIBoardEepromAddress : PCI eeprom address      |
+|                                                                                                                                       |
+|                    PCHAR pc_PCIChipInformation  : PCI Chip Type.          |
+|                                                                                                                                       |
+|                    WORD w_EepromStartAddress    : Selected eeprom address |
++----------------------------------------------------------------------------+
+| Output Parameters : -                                                      |
++----------------------------------------------------------------------------+
+| Return Value      : Read word value from eeprom                            |
++----------------------------------------------------------------------------+
+*/
+
+WORD   w_EepromReadWord(WORD   w_PCIBoardEepromAddress,PCHAR   pc_PCIChipInformation,WORD   w_EepromStartAddress)
+
+{
+
+       BYTE b_Counter = 0;
+
+       BYTE b_ReadByte = 0;
+
+       BYTE b_ReadLowByte = 0;
+
+       BYTE b_ReadHighByte = 0;
+
+       BYTE b_SelectedAddressLow = 0;
+
+       BYTE b_SelectedAddressHigh = 0;
+
+       WORD w_ReadWord = 0;
+
+       
+
+
+        /**************************/
+
+        /* Test the PCI chip type */
+
+        /**************************/
+
+
+
+
+        if ((!strcmp(pc_PCIChipInformation, "S5920")) || 
+
+            (!strcmp(pc_PCIChipInformation, "S5933")))
+
+        {
+
+               
+          for (b_Counter=0; b_Counter<2; b_Counter++)
+
+            {
+
+              b_SelectedAddressLow  = (w_EepromStartAddress + b_Counter) % 256; //Read the low 8 bit part
+
+              b_SelectedAddressHigh = (w_EepromStartAddress + b_Counter) / 256; //Read the high 8 bit part
+
+
+
+             /************************************/
+
+             /* Select the load low address mode */
+
+             /************************************/
+
+
+             outb(NVCMD_LOAD_LOW,w_PCIBoardEepromAddress + 0x3F);
+            
+
+             
+             /****************/
+
+             /* Wait on busy */
+
+             /****************/
+
+             v_EepromWaitBusy (w_PCIBoardEepromAddress);
+
+
+             /************************/
+
+             /* Load the low address */
+
+             /************************/
+
+
+             outb(b_SelectedAddressLow,w_PCIBoardEepromAddress + 0x3E);
+             
+
+     
+             /****************/
+
+             /* Wait on busy */
+
+             /****************/
+
+             v_EepromWaitBusy (w_PCIBoardEepromAddress);
+
+
+
+             /*************************************/
+
+             /* Select the load high address mode */
+
+             /*************************************/
+
+
+             outb(NVCMD_LOAD_HIGH,w_PCIBoardEepromAddress + 0x3F);
+            
+
+
+             /****************/
+
+             /* Wait on busy */
+
+             /****************/
+
+             v_EepromWaitBusy (w_PCIBoardEepromAddress);
+
+
+
+             /*************************/
+
+             /* Load the high address */
+
+             /*************************/
+
+
+             outb(b_SelectedAddressHigh,w_PCIBoardEepromAddress +0x3E);        
+            
+
+             /****************/
+
+             /* Wait on busy */
+
+             /****************/
+
+             v_EepromWaitBusy (w_PCIBoardEepromAddress);
+
+
+
+             /************************/
+
+             /* Select the READ mode */
+
+             /************************/
+
+
+             outb(NVCMD_BEGIN_READ,w_PCIBoardEepromAddress + 0x3F);  
+            
+
+             /****************/
+
+             /* Wait on busy */
+
+             /****************/
+
+
+             v_EepromWaitBusy (w_PCIBoardEepromAddress);
+
+
+
+             /*****************************/
+
+             /* Read data into the EEPROM */
+
+             /*****************************/
+
+              b_ReadByte = inb(w_PCIBoardEepromAddress + 0x3E);  
+
+            
+
+             
+             /****************/
+
+             /* Wait on busy */
+
+             /****************/
+
+
+
+             v_EepromWaitBusy (w_PCIBoardEepromAddress);
+
+
+
+             /*********************************/
+
+             /* Select the upper address part */
+
+             /*********************************/
+
+
+
+             if(b_Counter==0)
+
+                {
+
+                b_ReadLowByte=b_ReadByte;
+
+                } // if(b_Counter==0)
+
+             else
+
+                {
+
+                b_ReadHighByte=b_ReadByte;
+
+                } // if(b_Counter==0)
+
+           } // for (b_Counter=0; b_Counter<2; b_Counter++)
+
+
+
+          w_ReadWord=(b_ReadLowByte | (((WORD) b_ReadHighByte) * 256));
+
+        
+     
+           } // end of if ((!strcmp(pc_PCIChipInformation, "S5920")) || (!strcmp(pc_PCIChipInformation, "S5933"))) 
+
+        if (!strcmp(pc_PCIChipInformation, "93C76"))
+
+           {
+
+           /*************************************/
+
+           /* Read 16 bit from the EEPROM 93C76 */
+
+           /*************************************/
+
+
+         
+           v_EepromCs76Read(w_PCIBoardEepromAddress, w_EepromStartAddress, &w_ReadWord);
+
+           }
+
+             
+       return (w_ReadWord);
+
+       }
+
+
+
+
+
+
+
+/*
+
++----------------------------------------------------------------------------+
+
+| Function   Name   : VOID v_EepromWaitBusy                                  |
+
+|                      (WORD   w_PCIBoardEepromAddress)                         |
+
++----------------------------------------------------------------------------+
+
+| Task              : Wait the busy flag from PCI controller                 |
+
++----------------------------------------------------------------------------+
+
+| Input Parameters  : WORD w_PCIBoardEepromAddress : PCI eeprom base address |
+
++----------------------------------------------------------------------------+
+
+| Output Parameters : -                                                      |
+
++----------------------------------------------------------------------------+
+
+| Return Value      : -                                                      |
+
++----------------------------------------------------------------------------+
+
+*/
+
+
+
+VOID   v_EepromWaitBusy(WORD   w_PCIBoardEepromAddress)
+
+       {
+
+       BYTE b_EepromBusy = 0;
+
+
+
+       do
+
+         {
+
+          /*************/
+
+          /* IMPORTANT */
+
+          /*************/
+
+
+
+          /************************************************************************/
+
+          /* An error has been written in the AMCC 5933 book at the page B-13*/
+        
+           /* Ex: if you read a byte and look for the busy statusEEPROM=0x80 and   */
+          /*      the operator register is AMCC_OP_REG_MCSR+3*/
+          /*      WORD read  EEPROM=0x8000 andAMCC_OP_REG_MCSR+2                  */
+        
+           /*      DWORD read  EEPROM=0x80000000 and AMCC_OP_REG_MCSR */
+         
+           /************************************************************************/
+                  b_EepromBusy = inb(w_PCIBoardEepromAddress + 0x3F);             
+          b_EepromBusy = b_EepromBusy &0x80;
+
+        }
+       while(b_EepromBusy == 0x80);
+
+
+       }
+
+
+
+
+
+
+/*
+
++---------------------------------------------------------------------------------+
+
+| Function   Name   : VOID v_EepromClock76(DWORD dw_Address,                      |
+
+|                                         DWORD dw_RegisterValue)                                        |
+
++---------------------------------------------------------------------------------+
+
+| Task              : This function sends the clocking sequence to the EEPROM.    |
+
++---------------------------------------------------------------------------------+
+
+| Input Parameters  : DWORD dw_Address : PCI eeprom base address                  |
+
+|                    DWORD dw_RegisterValue : PCI eeprom register value to write.|
+
++---------------------------------------------------------------------------------+
+
+| Output Parameters : -                                                           |
+
++---------------------------------------------------------------------------------+
+
+| Return Value      : -                                                           |
+
++---------------------------------------------------------------------------------+
+
+*/
+
+
+
+VOID v_EepromClock76(DWORD dw_Address,DWORD dw_RegisterValue)
+
+   {
+
+
+
+   /************************/
+
+   /* Set EEPROM clock Low */
+
+   /************************/
+
+  
+outl(dw_RegisterValue & 0x6,dw_Address);
+
+   /***************/
+
+   /* Wait 0.1 ms */
+
+   /***************/
+
+
+    udelay(100);
+   
+
+   /*************************/
+
+   /* Set EEPROM clock High */
+
+   /*************************/
+
+
+  outl(dw_RegisterValue | 0x1,dw_Address);
+
+
+   /***************/
+
+   /* Wait 0.1 ms */
+
+   /***************/
+
+
+   udelay(100);
+
+   }
+
+
+
+/*
+
++---------------------------------------------------------------------------------+
+
+| Function   Name   : VOID v_EepromSendCommand76(DWORD dw_Address,                |
+
+|                                         DWORD   dw_EepromCommand,                              |
+
+|                                         BYTE    b_DataLengthInBits)                        |
+
++---------------------------------------------------------------------------------+
+
+| Task              : This function sends a Command to the EEPROM 93C76.          |
+
++---------------------------------------------------------------------------------+
+
+| Input Parameters  : DWORD dw_Address : PCI eeprom base address                  |
+
+|                    DWORD dw_EepromCommand : PCI eeprom command to write.       |
+
+|                    BYTE  b_DataLengthInBits : PCI eeprom command data length.  |
+
++---------------------------------------------------------------------------------+
+
+| Output Parameters : -                                                           |
+
++---------------------------------------------------------------------------------+
+
+| Return Value      : -                                                           |
+
++---------------------------------------------------------------------------------+
+
+*/
+
+
+
+VOID v_EepromSendCommand76(DWORD dw_Address,DWORD   dw_EepromCommand,BYTE    b_DataLengthInBits)
+
+   {
+
+   CHAR  c_BitPos = 0;
+
+   DWORD dw_RegisterValue = 0;
+
+
+
+
+   /*****************************/
+
+   /* Enable EEPROM Chip Select */
+
+   /*****************************/
+
+   dw_RegisterValue = 0x2;
+
+
+
+   /********************************************************************/
+
+   /* Toggle EEPROM's Chip select to get it out of Shift Register Mode */
+
+   /********************************************************************/
+
+   outl(dw_RegisterValue,dw_Address);
+
+
+
+   /***************/
+
+   /* Wait 0.1 ms */
+
+   /***************/
+
+  
+udelay(100);
+   
+
+   /*******************************************/
+
+   /* Send EEPROM command - one bit at a time */
+
+   /*******************************************/
+   
+
+   for (c_BitPos = (b_DataLengthInBits - 1); c_BitPos >= 0; c_BitPos--)
+
+      {
+
+
+      /**********************************/
+
+      /* Check if current bit is 0 or 1 */
+
+      /**********************************/
+
+
+      if (dw_EepromCommand & (1 << c_BitPos))
+
+        {
+
+        /***********/
+
+        /* Write 1 */
+
+        /***********/
+
+
+
+        dw_RegisterValue = dw_RegisterValue | 0x4;
+
+        }
+
+      else
+
+        {
+
+        /***********/
+
+        /* Write 0 */
+
+        /***********/
+
+
+
+        dw_RegisterValue = dw_RegisterValue & 0x3;
+
+        }
+
+
+
+      /*********************/
+
+      /* Write the command */
+
+      /*********************/
+
+
+      outl(dw_RegisterValue,dw_Address);
+  
+
+
+      /***************/
+
+      /* Wait 0.1 ms */
+
+      /***************/
+
+   
+  udelay(100);
+  
+   
+
+      /****************************/
+
+      /* Trigger the EEPROM clock */
+
+      /****************************/
+
+      v_EepromClock76(dw_Address, dw_RegisterValue);
+
+
+      }
+
+
+
+   }
+
+
+
+/*
+
++---------------------------------------------------------------------------------+
+
+| Function   Name   : VOID v_EepromCs76Read(DWORD dw_Address,                     |
+
+|                                         WORD    w_offset,                                              |
+
+|                                         PWORD   pw_Value)                                              |
+
++---------------------------------------------------------------------------------+
+
+| Task              : This function read a value from the EEPROM 93C76.           |
+
++---------------------------------------------------------------------------------+
+
+| Input Parameters  : DWORD dw_Address : PCI eeprom base address                  |
+
+|                    WORD    w_offset : Offset of the adress to read             |
+
+|                    PWORD   pw_Value : PCI eeprom 16 bit read value.            |
+
++---------------------------------------------------------------------------------+
+
+| Output Parameters : -                                                           |
+
++---------------------------------------------------------------------------------+
+
+| Return Value      : -                                                           |
+
++---------------------------------------------------------------------------------+
+
+*/
+
+
+
+VOID v_EepromCs76Read(DWORD dw_Address,WORD    w_offset,
+PWORD   pw_Value)
+
+   {
+
+   CHAR   c_BitPos = 0;
+
+   DWORD  dw_RegisterValue = 0;
+
+   DWORD  dw_RegisterValueRead = 0;
+
+
+
+
+
+   /*************************************************/
+
+   /* Send EEPROM read command and offset to EEPROM */
+
+   /*************************************************/
+
+   v_EepromSendCommand76(dw_Address, (EE_READ << 4) | (w_offset / 2), EE76_CMD_LEN);
+
+
+
+   /*******************************/
+
+   /* Get the last register value */
+
+   /*******************************/
+
+   dw_RegisterValue = (((w_offset / 2) & 0x1) << 2) | 0x2;
+
+   
+
+   /*****************************/
+
+   /* Set the 16-bit value of 0 */
+
+   /*****************************/
+
+
+   *pw_Value = 0;
+
+
+
+   /************************/
+
+   /* Get the 16-bit value */
+
+   /************************/
+
+   for (c_BitPos = 0; c_BitPos < 16; c_BitPos++)
+
+      {
+
+
+      /****************************/
+
+      /* Trigger the EEPROM clock */
+
+      /****************************/
+
+
+      v_EepromClock76(dw_Address, dw_RegisterValue);
+
+
+
+      /**********************/
+
+      /* Get the result bit */
+
+      /**********************/
+
+
+     dw_RegisterValueRead = inl(dw_Address);
+
+      /***************/
+
+      /* Wait 0.1 ms */
+
+      /***************/
+
+   
+  udelay(100);
+     
+
+      /***************************************/
+
+      /* Get bit value and shift into result */
+
+      /***************************************/
+
+
+      if (dw_RegisterValueRead & 0x8)
+
+        {
+
+
+        /**********/
+
+        /* Read 1 */
+
+        /**********/
+
+
+        *pw_Value = (*pw_Value << 1) | 0x1;
+
+        }
+
+      else
+
+        {
+
+        /**********/
+
+        /* Read 0 */
+
+        /**********/
+
+        *pw_Value = (*pw_Value << 1);
+
+        
+       }
+
+      }
+
+
+
+   /*************************/
+
+   /* Clear all EEPROM bits */
+
+   /*************************/
+
+
+   dw_RegisterValue = 0x0;
+
+
+
+   /********************************************************************/
+
+   /* Toggle EEPROM's Chip select to get it out of Shift Register Mode */
+
+   /********************************************************************/
+
+
+  outl(dw_RegisterValue,dw_Address);
+     
+   /***************/
+
+   /* Wait 0.1 ms */
+
+   /***************/
+
+   udelay(100);
+    
+   }
+
+
+
+
+
+       /******************************************/
+       /*      EEPROM HEADER READ FUNCTIONS      */
+       /******************************************/
+
+/*
++----------------------------------------------------------------------------+
+| Function Name  : INT i_EepromReadMainHeader(WORD w_PCIBoardEepromAddress,  |
+|                              PCHAR   pc_PCIChipInformation,comedi_device *dev)    |
++----------------------------------------------------------------------------+
+| Task              : Read from eeprom Main Header                           |
++----------------------------------------------------------------------------+
+| Input Parameters  : WORD w_PCIBoardEepromAddress : PCI eeprom address      |
+|                                                                                                                                       |      
+|                    PCHAR pc_PCIChipInformation  : PCI Chip Type.          |
+|                                                                                                                                       |
+|                        comedi_device *dev               : comedi device structure |
+|                                                                                       pointer                                 |
++----------------------------------------------------------------------------+
+| Output Parameters : -                                                      |
++----------------------------------------------------------------------------+
+| Return Value      : 0                                                                                     |
++----------------------------------------------------------------------------+
+*/
+
+
+INT i_EepromReadMainHeader(WORD        w_PCIBoardEepromAddress,PCHAR   pc_PCIChipInformation,comedi_device *dev)
+{
+       WORD w_Temp,i,w_Count=0;
+        UINT ui_Temp;
+       str_MainHeader  s_MainHeader;
+       str_DigitalInputHeader  s_DigitalInputHeader;
+       str_DigitalOutputHeader s_DigitalOutputHeader;
+       //str_TimerMainHeader     s_TimerMainHeader,s_WatchdogMainHeader;
+       str_AnalogOutputHeader   s_AnalogOutputHeader;
+       str_AnalogInputHeader   s_AnalogInputHeader;
+
+        // Read size
+       s_MainHeader.w_HeaderSize = w_EepromReadWord(w_PCIBoardEepromAddress,pc_PCIChipInformation,0x100+8);
+                
+        // Read nbr of functionality
+       w_Temp = w_EepromReadWord(w_PCIBoardEepromAddress,pc_PCIChipInformation,0x100+10);
+        s_MainHeader.b_Nfunctions =(BYTE)w_Temp & 0x00FF;
+
+       // Read functionality details
+       for(i=0;i<s_MainHeader.b_Nfunctions;i++)
+       {
+         // Read Type
+         w_Temp = w_EepromReadWord(w_PCIBoardEepromAddress,pc_PCIChipInformation,0x100+12+w_Count);
+         s_MainHeader.s_Functions[i].b_Type    =(BYTE) w_Temp & 0x3F;
+         w_Count=w_Count+2;
+       //Read Address
+        s_MainHeader.s_Functions[i].w_Address= w_EepromReadWord(w_PCIBoardEepromAddress,pc_PCIChipInformation,0x100+12+w_Count);    
+        w_Count=w_Count+2;
+       }
+
+        // Display main header info        
+       for(i=0;i<s_MainHeader.b_Nfunctions;i++)
+       {
+       
+          switch(s_MainHeader.s_Functions[i].b_Type)
+         {
+           case EEPROM_DIGITALINPUT:               
+                i_EepromReadDigitalInputHeader(w_PCIBoardEepromAddress,pc_PCIChipInformation,
+                s_MainHeader.s_Functions[i].w_Address,&s_DigitalInputHeader);  
+                 this_board->i_NbrDiChannel=s_DigitalInputHeader.w_Nchannel;
+                break;
+
+           case EEPROM_DIGITALOUTPUT:                 
+                i_EepromReadDigitalOutputHeader(w_PCIBoardEepromAddress,pc_PCIChipInformation,
+                s_MainHeader.s_Functions[i].w_Address,&s_DigitalOutputHeader);          
+                 this_board->i_NbrDoChannel=s_DigitalOutputHeader.w_Nchannel;
+                 ui_Temp=0xffffffff;
+                 this_board->i_DoMaxdata= ui_Temp >>(32 - this_board->i_NbrDoChannel);
+                break;
+
+           case EEPROM_ANALOGINPUT:
+                i_EepromReadAnlogInputHeader(w_PCIBoardEepromAddress,pc_PCIChipInformation,
+                s_MainHeader.s_Functions[i].w_Address,&s_AnalogInputHeader); 
+                if (!(strcmp(this_board->pc_DriverName, "apci3200")))  
+                   this_board->i_NbrAiChannel=s_AnalogInputHeader.w_Nchannel * 4;
+                else
+                   this_board->i_NbrAiChannel=s_AnalogInputHeader.w_Nchannel;
+                 this_board->i_Dma=s_AnalogInputHeader.b_HasDma;
+                 this_board->ui_MinAcquisitiontimeNs=(UINT)s_AnalogInputHeader.w_MinConvertTiming * 1000;
+                 this_board->ui_MinDelaytimeNs      =(UINT)s_AnalogInputHeader.w_MinDelayTiming * 1000;  
+                 ui_Temp=0xffff;
+                 this_board->i_AiMaxdata = ui_Temp >> (16 - s_AnalogInputHeader.b_Resolution);
+                break;
+
+            case EEPROM_ANALOGOUTPUT:                                
+                i_EepromReadAnlogOutputHeader(w_PCIBoardEepromAddress,pc_PCIChipInformation,
+                s_MainHeader.s_Functions[i].w_Address,&s_AnalogOutputHeader);                 
+                 this_board->i_NbrAoChannel=s_AnalogOutputHeader.w_Nchannel;
+                 ui_Temp=0xffff;
+                 this_board->i_AoMaxdata= ui_Temp >>(16 - s_AnalogOutputHeader.b_Resolution);
+                break;
+
+           case EEPROM_TIMER:
+                this_board->i_Timer=1;//Timer subdevice present                                        
+                break;
+
+           case EEPROM_WATCHDOG:        
+                this_board->i_Timer=1; //Timer subdevice present 
+                 break;
+
+            case EEPROM_TIMER_WATCHDOG_COUNTER:         
+                this_board->i_Timer=1; //Timer subdevice present                               
+         } 
+       }
+
+       return 0;
+}
+
+
+
+
+/*
++----------------------------------------------------------------------------+
+| Function Name  : INT i_EepromReadDigitalInputHeader(WORD                                      |
+|                      w_PCIBoardEepromAddress,PCHAR pc_PCIChipInformation,     |
+|                      WORD w_Address,str_DigitalInputHeader *s_Header)                 |
+|                                                                                                                                       |
++----------------------------------------------------------------------------+
+| Task              : Read Digital Input Header                              |
++----------------------------------------------------------------------------+
+| Input Parameters  : WORD w_PCIBoardEepromAddress : PCI eeprom address      |
+|                                                                                                                                       |
+|                    PCHAR pc_PCIChipInformation  : PCI Chip Type.          |
+|                                                                                                                                       |
+|                       str_DigitalInputHeader *s_Header: Digita Input Header   |
+|                                                                                                 Pointer                       |
++----------------------------------------------------------------------------+
+| Output Parameters : -                                                      |
++----------------------------------------------------------------------------+
+| Return Value      : 0                                                                                     |
++----------------------------------------------------------------------------+
+*/
+INT i_EepromReadDigitalInputHeader(WORD w_PCIBoardEepromAddress,PCHAR pc_PCIChipInformation,WORD w_Address,str_DigitalInputHeader *s_Header)
+{
+  WORD w_Temp;
+
+ // read nbr of channels
+ s_Header->w_Nchannel=w_EepromReadWord(w_PCIBoardEepromAddress,pc_PCIChipInformation,0x100+w_Address+6);
+
+ // interruptible or not
+ w_Temp=w_EepromReadWord(w_PCIBoardEepromAddress,pc_PCIChipInformation,0x100+w_Address+8);
+ s_Header->b_Interruptible=(BYTE) (w_Temp>>7)& 0x01;
+
+// How many interruptible logic
+ s_Header->w_NinterruptLogic=w_EepromReadWord(w_PCIBoardEepromAddress,pc_PCIChipInformation,0x100+w_Address+10);
+
+ return 0;
+}
+
+/*
++----------------------------------------------------------------------------+
+| Function Name  : INT i_EepromReadDigitalOutputHeader(WORD                             |
+|                      w_PCIBoardEepromAddress,PCHAR pc_PCIChipInformation,     |
+|                      WORD w_Address,str_DigitalOutputHeader *s_Header)            |
+|                                                                                                                                       |
++----------------------------------------------------------------------------+
+| Task              : Read Digital Output Header                             |
++----------------------------------------------------------------------------+
+| Input Parameters  : WORD w_PCIBoardEepromAddress : PCI eeprom address      |
+|                                                                                                                                       |
+|                    PCHAR pc_PCIChipInformation  : PCI Chip Type.          |
+|                                                                                                                                       |
+|                       str_DigitalOutputHeader *s_Header: Digital Output Header|
+|                                                                                         Pointer                               |
++----------------------------------------------------------------------------+
+| Output Parameters : -                                                      |
++----------------------------------------------------------------------------+
+| Return Value      : 0                                                                                     |
++----------------------------------------------------------------------------+
+*/
+INT i_EepromReadDigitalOutputHeader(WORD w_PCIBoardEepromAddress,PCHAR pc_PCIChipInformation,WORD w_Address,str_DigitalOutputHeader *s_Header)
+{
+// Read Nbr channels
+ s_Header->w_Nchannel=w_EepromReadWord(w_PCIBoardEepromAddress,pc_PCIChipInformation,0x100+w_Address+6);
+return 0;
+}
+
+/*
++----------------------------------------------------------------------------+
+| Function Name  : INT i_EepromReadTimerHeader(WORD w_PCIBoardEepromAddress, |
+|                      PCHAR pc_PCIChipInformation,WORD w_Address,                              |
+|                      str_TimerMainHeader *s_Header)                                                   | 
++----------------------------------------------------------------------------+
+| Task              : Read Timer or Watchdog Header                          |
++----------------------------------------------------------------------------+
+| Input Parameters  : WORD w_PCIBoardEepromAddress : PCI eeprom address      |
+|                                                                                                                                       |      
+|                    PCHAR pc_PCIChipInformation  : PCI Chip Type.          |
+|                                                                                                                                       |      
+|                       str_TimerMainHeader *s_Header: Timer Header                     |
+|                                                                                         Pointer                               |
++----------------------------------------------------------------------------+
+| Output Parameters : -                                                      |
++----------------------------------------------------------------------------+
+| Return Value      : 0                                                                                     |
++----------------------------------------------------------------------------+
+*/
+INT i_EepromReadTimerHeader(WORD w_PCIBoardEepromAddress,PCHAR pc_PCIChipInformation,WORD w_Address,str_TimerMainHeader *s_Header)
+{
+
+WORD i,w_Size=0,w_Temp;
+  
+
+//Read No of Timer
+s_Header->w_Ntimer=w_EepromReadWord(w_PCIBoardEepromAddress,pc_PCIChipInformation,0x100+w_Address+6);
+//Read header size
+
+for(i=0;i<s_Header->w_Ntimer;i++)
+{
+  s_Header->s_TimerDetails[i].w_HeaderSize=w_EepromReadWord(w_PCIBoardEepromAddress,pc_PCIChipInformation,0x100+w_Address+8+w_Size+0);
+  w_Temp=w_EepromReadWord(w_PCIBoardEepromAddress,pc_PCIChipInformation,0x100+w_Address+8+w_Size+2) ;
+
+  //Read Resolution
+  s_Header->s_TimerDetails[i].b_Resolution=(BYTE)(w_Temp>>10)&0x3F;
+
+  //Read Mode
+  s_Header->s_TimerDetails[i].b_Mode           =(BYTE) (w_Temp>>4)&0x3F;
+
+  w_Temp=w_EepromReadWord(w_PCIBoardEepromAddress,pc_PCIChipInformation,0x100+w_Address+8+w_Size+4) ;
+
+  //Read MinTiming
+  s_Header->s_TimerDetails[i].w_MinTiming      =(w_Temp>>6)&0x3FF; 
+
+  //Read Timebase
+  s_Header->s_TimerDetails[i].b_TimeBase       =(BYTE)(w_Temp)&0x3F; 
+  w_Size += s_Header->s_TimerDetails[i].w_HeaderSize;
+}   
+return 0;
+}
+
+
+
+/*
++----------------------------------------------------------------------------+
+| Function Name  : INT i_EepromReadAnlogOutputHeader(WORD                                       |
+|                      w_PCIBoardEepromAddress,PCHAR pc_PCIChipInformation,     |
+|                      WORD w_Address,str_AnalogOutputHeader *s_Header)         | 
++----------------------------------------------------------------------------+
+| Task              : Read Nalog Output  Header                              |
++----------------------------------------------------------------------------+
+| Input Parameters  : WORD w_PCIBoardEepromAddress : PCI eeprom address      |
+|                                                                                                                                       |      
+|                    PCHAR pc_PCIChipInformation  : PCI Chip Type.          |
+|                                                                                                                                       |
+|                       str_AnalogOutputHeader *s_Header:Anlog Output Header    |
+|                                                                                         Pointer                               |
++----------------------------------------------------------------------------+
+| Output Parameters : -                                                      |
++----------------------------------------------------------------------------+
+| Return Value      : 0                                                                                     |
++----------------------------------------------------------------------------+
+*/
+
+INT i_EepromReadAnlogOutputHeader(WORD w_PCIBoardEepromAddress,PCHAR pc_PCIChipInformation,WORD w_Address,str_AnalogOutputHeader *s_Header)
+{
+  WORD w_Temp;
+  // No of channels for 1st hard component
+  w_Temp=w_EepromReadWord(w_PCIBoardEepromAddress,pc_PCIChipInformation,0x100+w_Address+10);
+  s_Header->w_Nchannel=(w_Temp>>4)& 0x03FF;
+  // Resolution for 1st hard component
+  w_Temp=w_EepromReadWord(w_PCIBoardEepromAddress,pc_PCIChipInformation,0x100+w_Address+16);
+  s_Header->b_Resolution=(BYTE)(w_Temp>>8) & 0xFF;
+  return 0;
+}
+
+
+/*
++----------------------------------------------------------------------------+
+| Function Name  : INT i_EepromReadAnlogInputHeader(WORD                                        |
+|                      w_PCIBoardEepromAddress,PCHAR pc_PCIChipInformation,     |
+|                      WORD w_Address,str_AnalogInputHeader *s_Header)          |
++----------------------------------------------------------------------------+
+| Task              : Read Nalog Output  Header                              |
++----------------------------------------------------------------------------+
+| Input Parameters  : WORD w_PCIBoardEepromAddress : PCI eeprom address      |
+|                                                                                                                                       |
+|                    PCHAR pc_PCIChipInformation  : PCI Chip Type.          |
+|                                                                                                                                       |
+|                       str_AnalogInputHeader *s_Header:Anlog Input Header      |  
+|                                                                                         Pointer                               |
++----------------------------------------------------------------------------+
+| Output Parameters : -                                                      |
++----------------------------------------------------------------------------+
+| Return Value      : 0                                                                                     |
++----------------------------------------------------------------------------+
+*/
+
+// Reads only for ONE  hardware component
+INT i_EepromReadAnlogInputHeader(WORD w_PCIBoardEepromAddress,PCHAR pc_PCIChipInformation,WORD w_Address,str_AnalogInputHeader *s_Header)
+{
+  WORD w_Temp,w_Offset;
+  w_Temp=w_EepromReadWord(w_PCIBoardEepromAddress,pc_PCIChipInformation,0x100+w_Address+10);
+  s_Header->w_Nchannel=(w_Temp>>4)& 0x03FF;
+  s_Header->w_MinConvertTiming=w_EepromReadWord(w_PCIBoardEepromAddress,pc_PCIChipInformation,0x100+w_Address+16);
+s_Header->w_MinDelayTiming=w_EepromReadWord(w_PCIBoardEepromAddress,pc_PCIChipInformation,0x100+w_Address+30);
+w_Temp=w_EepromReadWord(w_PCIBoardEepromAddress,pc_PCIChipInformation,0x100+w_Address+20);
+s_Header->b_HasDma=(w_Temp>>13) & 0x01; // whether dma present or not
+
+w_Temp=w_EepromReadWord(w_PCIBoardEepromAddress,pc_PCIChipInformation,0x100+w_Address+72);// reading Y
+w_Temp=w_Temp & 0x00FF;
+if(w_Temp)//Y>0
+{
+w_Offset=74+(2*w_Temp)+(10*(1+(w_Temp/16)));// offset of first analog input single header
+w_Offset= w_Offset+2; // resolution
+}
+else//Y=0
+{ 
+w_Offset=74; 
+w_Offset= w_Offset+2; // resolution
+}
+
+// read Resolution
+w_Temp=w_EepromReadWord(w_PCIBoardEepromAddress,pc_PCIChipInformation,0x100+w_Address+w_Offset);
+s_Header->b_Resolution=w_Temp & 0x001F;// last 5 bits
+
+return 0;
+}
index 853565394583d644e426d961345cf7068d55794b..c0bfb18f335be007880250390467c3dd3b259a8c 100644 (file)
-/**\r
-@verbatim\r
-\r
-Copyright (C) 2004,2005  ADDI-DATA GmbH for the source code of this module. \r
-        \r
-        ADDI-DATA GmbH \r
-        Dieselstrasse 3 \r
-        D-77833 Ottersweier \r
-        Tel: +19(0)7223/9493-0 \r
-        Fax: +49(0)7223/9493-92 \r
-        http://www.addi-data-com \r
-        info@addi-data.com \r
-\r
-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.\r
-\r
-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.\r
-\r
-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 USA\r
-\r
-You shoud also find the complete GPL in the COPYING file accompanying this source code.\r
-\r
-@endverbatim\r
-*/\r
-/*\r
-  +-----------------------------------------------------------------------+\r
-  | (C) ADDI-DATA GmbH          Dieselstraße 3       D-77833 Ottersweier  |\r
-  +-----------------------------------------------------------------------+\r
-  | Tel : +49 (0) 7223/9493-0     | email    : info@addi-data.com         |\r
-  | Fax : +49 (0) 7223/9493-92    | Internet : http://www.addi-data.com   |\r
-  +-------------------------------+---------------------------------------+\r
-  | Project     : APCI-1710       | Compiler   : GCC                      |\r
-  | Module name : hwdrv_apci1710.c| Version    : 2.96                     |\r
-  +-------------------------------+---------------------------------------+\r
-  | Project manager: Eric Stolz   | Date       :  02/12/2002              |\r
-  +-------------------------------+---------------------------------------+\r
-  | Description :   Hardware Layer Acces For APCI-1710                    |\r
-  +-----------------------------------------------------------------------+\r
-  |                             UPDATES                                   |\r
-  +----------+-----------+------------------------------------------------+\r
-  |   Date   |   Author  |          Description of updates                |\r
-  +----------+-----------+------------------------------------------------+\r
-  |          |           |                                                |\r
-  |          |           |                                                |\r
-  |          |           |                                                |\r
-  +----------+-----------+------------------------------------------------+\r
-*/\r
- #include "hwdrv_APCI1710.h"\r
- #include "APCI1710_Inp_cpt.c"\r
\r
- #include "APCI1710_Ssi.c"\r
- #include "APCI1710_Tor.c"\r
- #include "APCI1710_Ttl.c"\r
- #include "APCI1710_Dig_io.c" \r
- #include "APCI1710_82x54.c"\r
- #include "APCI1710_Chrono.c"\r
- #include "APCI1710_Pwm.c"\r
- #include "APCI1710_INCCPT.c"\r
-\r
-\r
-void   i_ADDI_AttachPCI1710 (comedi_device *dev)\r
-       {\r
-       comedi_subdevice *s;\r
-       int ret          = 0;\r
-       int n_subdevices = 9;\r
-       \r
-       //Update-0.7.57->0.7.68dev->n_subdevices = 9;\r
-       if((ret=alloc_subdevices(dev,n_subdevices))<0)\r
-       return ret;\r
\r
-        // Allocate and Initialise Timer Subdevice Structures          \r
-       s = dev->subdevices + 0;\r
-        \r
-       s->type = COMEDI_SUBD_TIMER;\r
-       s->subdev_flags = SDF_WRITEABLE|SDF_RT|SDF_GROUND|SDF_COMMON; \r
-       s->n_chan = 3; \r
-       s->maxdata = 0; \r
-       s->len_chanlist = 3;\r
-       s->range_table = &range_digital;       \r
-        s->insn_write=i_APCI1710_InsnWriteEnableDisableTimer;\r
-       s->insn_read=i_APCI1710_InsnReadAllTimerValue;\r
-       s->insn_config=i_APCI1710_InsnConfigInitTimer;\r
-       s->insn_bits=i_APCI1710_InsnBitsTimer;\r
-       \r
-\r
-       // Allocate and Initialise DIO Subdevice Structures     \r
-       s = dev->subdevices + 1;\r
-        \r
-       s->type = COMEDI_SUBD_DIO;\r
-       s->subdev_flags = SDF_WRITEABLE|SDF_READABLE|SDF_RT|SDF_GROUND|SDF_COMMON;\r
-       s->n_chan = 7;\r
-       s->maxdata = 1;\r
-       s->len_chanlist = 7;\r
-       s->range_table = &range_digital;        \r
-               s->insn_config=i_APCI1710_InsnConfigDigitalIO;\r
-               s->insn_read= i_APCI1710_InsnReadDigitalIOChlValue;\r
-       s->insn_bits=i_APCI1710_InsnBitsDigitalIOPortOnOff;\r
-       s->insn_write=i_APCI1710_InsnWriteDigitalIOChlOnOff;\r
-        \r
-\r
-        // Allocate and Initialise Chrono Subdevice Structures         \r
-       s = dev->subdevices + 2;\r
-        \r
-       s->type = COMEDI_SUBD_CHRONO;\r
-       s->subdev_flags = SDF_WRITEABLE|SDF_RT|SDF_GROUND|SDF_COMMON; \r
-       s->n_chan = 4; \r
-       s->maxdata = 0; \r
-       s->len_chanlist = 4;\r
-       s->range_table = &range_digital;        \r
-        s->insn_write=i_APCI1710_InsnWriteEnableDisableChrono;\r
-       s->insn_read=i_APCI1710_InsnReadChrono;\r
-       s->insn_config=i_APCI1710_InsnConfigInitChrono;\r
-       s->insn_bits=i_APCI1710_InsnBitsChronoDigitalIO;\r
-       \r
-       \r
-       // Allocate and Initialise PWM Subdevice Structures                 \r
-       s = dev->subdevices + 3;\r
-       s->type = COMEDI_SUBD_PWM;\r
-       s->subdev_flags = SDF_WRITEABLE|SDF_READABLE|SDF_RT|SDF_GROUND|SDF_COMMON;\r
-       s->n_chan = 3;\r
-       s->maxdata = 1;\r
-       s->len_chanlist = 3;\r
-       s->range_table = &range_digital;\r
-       s->io_bits=0;           //all bits input        \r
-       s->insn_config = i_APCI1710_InsnConfigPWM;\r
-       s->insn_read   = i_APCI1710_InsnReadGetPWMStatus;\r
-       s->insn_write  = i_APCI1710_InsnWritePWM;\r
-        s->insn_bits   = i_APCI1710_InsnBitsReadPWMInterrupt;\r
-\r
-       // Allocate and Initialise TTLIO Subdevice Structures\r
-       s = dev->subdevices + 4;\r
-       s->type = COMEDI_SUBD_TTLIO;\r
-       s->subdev_flags = SDF_WRITEABLE|SDF_READABLE|SDF_RT|SDF_GROUND|SDF_COMMON;\r
-       s->n_chan = 8;\r
-       s->maxdata = 1;\r
-       s->len_chanlist = 8;\r
-       s->range_table = &range_apci1710_ttl; // to pass arguments in range     \r
-        s->insn_config         = i_APCI1710_InsnConfigInitTTLIO;\r
-       s->insn_bits    = i_APCI1710_InsnBitsReadTTLIO;\r
-       s->insn_write   = i_APCI1710_InsnWriteSetTTLIOChlOnOff;\r
-        s->insn_read   = i_APCI1710_InsnReadTTLIOAllPortValue;\r
-\r
-\r
-       // Allocate and Initialise TOR Subdevice Structures\r
-       s = dev->subdevices + 5;\r
-       s->type = COMEDI_SUBD_TOR;\r
-       s->subdev_flags = SDF_WRITEABLE|SDF_READABLE|SDF_RT|SDF_GROUND|SDF_COMMON;\r
-       s->n_chan = 8;\r
-       s->maxdata = 1;\r
-       s->len_chanlist = 8;\r
-       s->range_table = &range_digital;\r
-       s->io_bits=0;           //all bits input        \r
-        s->insn_config = i_APCI1710_InsnConfigInitTorCounter;\r
-       s->insn_read   = i_APCI1710_InsnReadGetTorCounterInitialisation;\r
-       s->insn_write  = i_APCI1710_InsnWriteEnableDisableTorCounter;\r
-       s->insn_bits   = i_APCI1710_InsnBitsGetTorCounterProgressStatusAndValue;\r
\r
-       // Allocate and Initialise SSI Subdevice Structures\r
-       s = dev->subdevices + 6;\r
-       s->type = COMEDI_SUBD_SSI;\r
-       s->subdev_flags = SDF_WRITEABLE|SDF_READABLE|SDF_RT|SDF_GROUND|SDF_COMMON;\r
-       s->n_chan =4;\r
-       s->maxdata = 1;\r
-       s->len_chanlist = 4;\r
-       s->range_table = &range_apci1710_ssi;   \r
-       s->insn_config = i_APCI1710_InsnConfigInitSSI;\r
-       s->insn_read   = i_APCI1710_InsnReadSSIValue;\r
-       s->insn_bits  = i_APCI1710_InsnBitsSSIDigitalIO;\r
\r
-       // Allocate and Initialise PULSEENCODER Subdevice Structures       \r
-       s                       = dev->subdevices + 7;\r
-       s->type                 = COMEDI_SUBD_PULSEENCODER;\r
-       s->subdev_flags = SDF_WRITEABLE|SDF_READABLE|SDF_RT|SDF_GROUND|SDF_COMMON;\r
-       s->n_chan               = 4;\r
-       s->maxdata              = 1;\r
-       s->len_chanlist = 4;\r
-       s->range_table  = &range_digital;       \r
-       s->insn_config  = i_APCI1710_InsnConfigInitPulseEncoder;\r
-       s->insn_write   = i_APCI1710_InsnWriteEnableDisablePulseEncoder;\r
-       s->insn_bits    = i_APCI1710_InsnBitsReadWritePulseEncoder;\r
-       s->insn_read    = i_APCI1710_InsnReadInterruptPulseEncoder;\r
-\r
-       // Allocate and Initialise INCREMENTALCOUNTER Subdevice Structures     \r
-       s                       = dev->subdevices + 8;\r
-       s->type                 = COMEDI_SUBD_INCREMENTALCOUNTER;\r
-       s->subdev_flags = SDF_WRITEABLE|SDF_READABLE|SDF_RT|SDF_GROUND|SDF_COMMON;\r
-       s->n_chan               = 500;\r
-       s->maxdata              = 1;\r
-       s->len_chanlist = 500;\r
-       s->range_table  = &range_apci1710_inccpt;       \r
-       s->insn_config  = i_APCI1710_InsnConfigINCCPT;\r
-       s->insn_write   = i_APCI1710_InsnWriteINCCPT;\r
-       s->insn_read    = i_APCI1710_InsnReadINCCPT;\r
-       s->insn_bits    = i_APCI1710_InsnBitsINCCPT;\r
-       }\r
\r
\r
\r
-int i_APCI1710_Reset(comedi_device *dev);\r
-VOID v_APCI1710_Interrupt(int irq, void *d, struct pt_regs *regs) ;\r
-//for 1710\r
-\r
- int i_APCI1710_Reset(comedi_device *dev)\r
-{\r
-    int ret;\r
-    DWORD dw_Dummy;    \r
-  \r
-       /*********************************/ \r
-       /* Read all module configuration */ \r
-       /*********************************/ \r
-        ret=inl(devpriv->s_BoardInfos.ui_Address+60);\r
-       devpriv->s_BoardInfos.dw_MolduleConfiguration [0]=ret;\r
-            \r
-        ret=inl(devpriv->s_BoardInfos.ui_Address+124);\r
-       devpriv->s_BoardInfos.dw_MolduleConfiguration [1]=ret;\r
-            \r
-        ret=inl(devpriv->s_BoardInfos.ui_Address+188);\r
-       devpriv->s_BoardInfos.dw_MolduleConfiguration [2]=ret;\r
-            \r
-        ret=inl(devpriv->s_BoardInfos.ui_Address+252);\r
-       devpriv->s_BoardInfos.dw_MolduleConfiguration [3]=ret;\r
-\r
-       // outl(0x80808082,devpriv->s_BoardInfos.ui_Address+0x60);\r
-       outl(0x83838383,devpriv->s_BoardInfos.ui_Address+0x60);  \r
-       \r
-       devpriv->s_BoardInfos.b_BoardVersion = 1;\r
-\r
-       // Enable the interrupt for the controler       \r
-       dw_Dummy =  inl(devpriv->s_BoardInfos.ui_Address+ 0x38);\r
-       outl(dw_Dummy | 0x2000,devpriv->s_BoardInfos.ui_Address+0x38);\r
-\r
-       return 0;\r
-}\r
-\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function's Name   : __VOID__ v_APCI1710_InterruptFunction                  |\r
-|                              (BYTE b_Interrupt, __CPPARGS)                |\r
-+----------------------------------------------------------------------------+\r
-| Task              : APCI-1710 interrupt function                           |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : BYTE b_Interrupt : Interrupt number                    |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : -                                                      |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      : 0 : OK                                                 |\r
-|                    -1 : Error                                              |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-\r
-       \r
-\r
-\r
-VOID v_APCI1710_Interrupt(int irq, void *d, struct pt_regs *regs)  \r
-{\r
-       comedi_device *dev = d;\r
-       BYTE   b_ModuleCpt       = 0;\r
-       BYTE   b_InterruptFlag   = 0;\r
-       BYTE   b_PWMCpt          = 0;\r
-       BYTE   b_TorCounterCpt   = 0;\r
-       BYTE   b_PulseIncoderCpt = 0;\r
-       UINT  ui_16BitValue;\r
-       ULONG ul_InterruptLatchReg = 0;\r
-       ULONG ul_LatchRegisterValue;\r
-       ULONG ul_82X54InterruptStatus;\r
-       ULONG ul_StatusRegister;\r
-\r
-       str_ModuleInfo  * ps_ModuleInfo;\r
-\r
-        printk("APCI1710 Interrupt\n");\r
-          for (b_ModuleCpt = 0; b_ModuleCpt < 4; b_ModuleCpt ++, ps_ModuleInfo ++)\r
-             {\r
-\r
-                /**************************/\r
-                /* 1199/0225 to 0100/0226 */\r
-                /**************************/\r
-                ps_ModuleInfo = &devpriv->s_ModuleInfo [b_ModuleCpt];\r
-\r
-\r
-                 /***********************/\r
-                /* Test if 82X54 timer */\r
-                /***********************/\r
-\r
-                if ((devpriv->\r
-                     s_BoardInfos.\r
-                     dw_MolduleConfiguration [b_ModuleCpt] & 0xFFFF0000UL) == APCI1710_82X54_TIMER)\r
-                   {\r
-                   \r
-                     //printk("TIMER Interrupt Occurred\n");\r
-                     ul_82X54InterruptStatus= inl(devpriv->s_BoardInfos.\r
-                              ui_Address + 12 + (64 * b_ModuleCpt));\r
-\r
-                   /***************************/\r
-                   /* Test if interrupt occur */\r
-                   /***************************/\r
-\r
-                   if ((ul_82X54InterruptStatus & ps_ModuleInfo->\r
-                                                  s_82X54ModuleInfo.\r
-                                                  b_InterruptMask) != 0)\r
-                      {\r
-                      devpriv->\r
-                      s_InterruptParameters.\r
-                      s_FIFOInterruptParameters [devpriv->\r
-                                                 s_InterruptParameters.\r
-                                                 ui_Write].\r
-                      ul_OldInterruptMask = (ul_82X54InterruptStatus & ps_ModuleInfo->\r
-                                                                       s_82X54ModuleInfo.\r
-                                                                       b_InterruptMask) << 4;\r
-\r
-                      devpriv->\r
-                      s_InterruptParameters.\r
-                      s_FIFOInterruptParameters [devpriv->\r
-                                                 s_InterruptParameters.\r
-                                                 ui_Write].\r
-                      b_OldModuleMask = 1 << b_ModuleCpt;\r
-\r
-                      devpriv->\r
-                      s_InterruptParameters.\r
-                      s_FIFOInterruptParameters [devpriv->\r
-                                                 s_InterruptParameters.\r
-                                                 ui_Write].\r
-                      ul_OldCounterLatchValue = 0;\r
-\r
-                      devpriv->\r
-                      s_InterruptParameters.\r
-                      ul_InterruptOccur ++;\r
-\r
-                      /****************************/\r
-                      /* Increment the write FIFO */\r
-                      /****************************/\r
-\r
-                      devpriv->\r
-                      s_InterruptParameters.\r
-                      ui_Write = (devpriv->\r
-                                  s_InterruptParameters.\r
-                                  ui_Write + 1) % APCI1710_SAVE_INTERRUPT;\r
-\r
-                      b_InterruptFlag = 1;\r
-\r
-                      \r
-                           \r
-                            /**********************/\r
-                            /* Call user function */\r
-                            /**********************/\r
-                         //Send a signal to from kernel to user space\r
-                            send_sig(SIGIO,devpriv->tsk_Current,0); \r
-                           \r
-                      } // if ((ul_82X54InterruptStatus & 0x7) != 0)\r
-                   } // 82X54 timer\r
-\r
-\r
-\r
-\r
-\r
-                /***************************/\r
-                /* Test if increm. counter */\r
-                /***************************/\r
-\r
-                if ((devpriv->\r
-                     s_BoardInfos.\r
-                     dw_MolduleConfiguration [b_ModuleCpt] & 0xFFFF0000UL) == APCI1710_INCREMENTAL_COUNTER)\r
-                   {\r
-\r
-                        ul_InterruptLatchReg=inl(devpriv->s_BoardInfos.\r
-                              ui_Address + (64 * b_ModuleCpt));\r
-\r
-                   /*********************/\r
-                   /* Test if interrupt */\r
-                   /*********************/\r
-\r
-                   if ((ul_InterruptLatchReg & 0x22) && (ps_ModuleInfo->\r
-                                                         s_SiemensCounterInfo.\r
-                                                         s_ModeRegister.\r
-                                                         s_ByteModeRegister.\r
-                                                         b_ModeRegister2 & 0x80))\r
-                      {\r
-                      /************************************/\r
-                      /* Test if strobe latch I interrupt */\r
-                      /************************************/\r
-\r
-                      if (ul_InterruptLatchReg & 2)\r
-                         {\r
-                               ul_LatchRegisterValue=inl(devpriv->s_BoardInfos.\r
-                                    ui_Address + 4 + (64 * b_ModuleCpt));\r
-\r
-                         devpriv->\r
-                         s_InterruptParameters.\r
-                         s_FIFOInterruptParameters [devpriv->\r
-                                                    s_InterruptParameters.\r
-                                                    ui_Write].\r
-                         ul_OldInterruptMask = 1UL;\r
-\r
-                         devpriv->\r
-                         s_InterruptParameters.\r
-                         s_FIFOInterruptParameters [devpriv->\r
-                                                    s_InterruptParameters.\r
-                                                    ui_Write].\r
-                         b_OldModuleMask = 1 << b_ModuleCpt;\r
-\r
-                         devpriv->\r
-                         s_InterruptParameters.\r
-                         s_FIFOInterruptParameters [devpriv->\r
-                                                    s_InterruptParameters.\r
-                                                    ui_Write].\r
-                         ul_OldCounterLatchValue = ul_LatchRegisterValue;\r
-\r
-                         devpriv->\r
-                         s_InterruptParameters.\r
-                         ul_InterruptOccur ++;\r
-\r
-                         /****************************/\r
-                         /* 0899/0224 to 1199/0225   */\r
-                         /****************************/\r
-                         /* Increment the write FIFO */\r
-                      /****************************/\r
-\r
-                         devpriv->\r
-                         s_InterruptParameters.\r
-                         ui_Write = (devpriv->\r
-                                     s_InterruptParameters.\r
-                                     ui_Write + 1) % APCI1710_SAVE_INTERRUPT;\r
-\r
-                         b_InterruptFlag = 1;\r
-\r
-                        \r
-                            \r
-                               /**********************/\r
-                               /* Call user function */\r
-                               /**********************/\r
-                        //Send a signal to from kernel to user space\r
-                            send_sig(SIGIO,devpriv->tsk_Current,0); \r
-                               \r
-                        \r
-                         }\r
-\r
-                      /*************************************/\r
-                      /* Test if strobe latch II interrupt */\r
-                      /*************************************/\r
-\r
-                      if (ul_InterruptLatchReg & 0x20)\r
-                         {\r
-                         \r
-                         ul_LatchRegisterValue=inl(devpriv->s_BoardInfos.\r
-                                    ui_Address + 8 + (64 * b_ModuleCpt));\r
-\r
-                         devpriv->\r
-                         s_InterruptParameters.\r
-                         s_FIFOInterruptParameters [devpriv->\r
-                                                    s_InterruptParameters.\r
-                                                    ui_Write].\r
-                         ul_OldInterruptMask = 2UL;\r
-\r
-                         devpriv->\r
-                         s_InterruptParameters.\r
-                         s_FIFOInterruptParameters [devpriv->\r
-                                                    s_InterruptParameters.\r
-                                                    ui_Write].\r
-                         b_OldModuleMask = 1 << b_ModuleCpt;\r
-\r
-                         devpriv->\r
-                         s_InterruptParameters.\r
-                         s_FIFOInterruptParameters [devpriv->\r
-                                                    s_InterruptParameters.\r
-                                                    ui_Write].\r
-                         ul_OldCounterLatchValue = ul_LatchRegisterValue;\r
-\r
-                         devpriv->\r
-                         s_InterruptParameters.\r
-                         ul_InterruptOccur ++;\r
-\r
-                         /****************************/\r
-                         /* 0899/0224 to 1199/0225   */\r
-                         /****************************/\r
-                         /* Increment the write FIFO */\r
-                         /****************************/\r
-\r
-                         devpriv->\r
-                         s_InterruptParameters.\r
-                         ui_Write = (devpriv->\r
-                                     s_InterruptParameters.\r
-                                     ui_Write + 1) % APCI1710_SAVE_INTERRUPT;\r
-\r
-                         b_InterruptFlag = 1;\r
-\r
-                         \r
-                           /**********************/\r
-                               /* Call user function */\r
-                               /**********************/\r
-                        //Send a signal to from kernel to user space\r
-                            send_sig(SIGIO,devpriv->tsk_Current,0); \r
-                               \r
-                                 }\r
-                      }\r
-\r
-                 \r
-                       ul_InterruptLatchReg=inl(devpriv-> s_BoardInfos.\r
-                              ui_Address + 24 + (64 * b_ModuleCpt));\r
-\r
-                   /***************************/\r
-                   /* Test if index interrupt */\r
-                   /***************************/\r
-\r
-                   if (ul_InterruptLatchReg & 0x8)\r
-                      {\r
-                      ps_ModuleInfo->\r
-                      s_SiemensCounterInfo.\r
-                      s_InitFlag.\r
-                      b_IndexInterruptOccur = 1;\r
-\r
-                      if (ps_ModuleInfo->\r
-                          s_SiemensCounterInfo.\r
-                          s_ModeRegister.\r
-                          s_ByteModeRegister.\r
-                          b_ModeRegister2 & APCI1710_INDEX_AUTO_MODE)\r
-                         {\r
-\r
-                       outl(ps_ModuleInfo->\r
-                                     s_SiemensCounterInfo.\r
-                                     s_ModeRegister.\r
-                                     dw_ModeRegister1_2_3_4,devpriv->\r
-                                     s_BoardInfos.\r
-                                     ui_Address + 20 + (64 * b_ModuleCpt));\r
-                         }\r
-\r
-                      /*****************************/\r
-                      /* Test if interrupt enabled */\r
-                      /*****************************/\r
-\r
-                      if ((ps_ModuleInfo->\r
-                           s_SiemensCounterInfo.\r
-                           s_ModeRegister.\r
-                           s_ByteModeRegister.\r
-                           b_ModeRegister3 & APCI1710_ENABLE_INDEX_INT) == APCI1710_ENABLE_INDEX_INT)\r
-                         {\r
-                         devpriv->\r
-                         s_InterruptParameters.\r
-                         s_FIFOInterruptParameters [devpriv->\r
-                                                    s_InterruptParameters.\r
-                                                    ui_Write].\r
-                         ul_OldInterruptMask = 4UL;\r
-\r
-                         devpriv->\r
-                         s_InterruptParameters.\r
-                         s_FIFOInterruptParameters [devpriv->\r
-                                                    s_InterruptParameters.\r
-                                                    ui_Write].\r
-                         b_OldModuleMask = 1 << b_ModuleCpt;\r
-\r
-                         devpriv->\r
-                         s_InterruptParameters.\r
-                         s_FIFOInterruptParameters [devpriv->\r
-                                                    s_InterruptParameters.\r
-                                                    ui_Write].\r
-                         ul_OldCounterLatchValue = ul_LatchRegisterValue;\r
-\r
-                         devpriv->\r
-                         s_InterruptParameters.\r
-                         ul_InterruptOccur ++;\r
-\r
-                         /****************************/\r
-                         /* 0899/0224 to 1199/0225   */\r
-                         /****************************/\r
-                         /* Increment the write FIFO */\r
-                         /****************************/\r
-\r
-                         devpriv->\r
-                         s_InterruptParameters.\r
-                         ui_Write = (devpriv->\r
-                                     s_InterruptParameters.\r
-                                     ui_Write + 1) % APCI1710_SAVE_INTERRUPT;\r
-\r
-                         b_InterruptFlag = 1;\r
-\r
-                         \r
-                           \r
-                               /**********************/\r
-                               /* Call user function */\r
-                               /**********************/\r
-                        //Send a signal to from kernel to user space\r
-                            send_sig(SIGIO,devpriv->tsk_Current,0); \r
-                               \r
-                               }\r
-                      }\r
-\r
-                   /*****************************/\r
-                   /* Test if compare interrupt */\r
-                   /*****************************/\r
-\r
-                   if (ul_InterruptLatchReg & 0x10)\r
-                      {\r
-                      /*****************************/\r
-                      /* Test if interrupt enabled */\r
-                      /*****************************/\r
-\r
-                      if ((ps_ModuleInfo->\r
-                           s_SiemensCounterInfo.\r
-                           s_ModeRegister.\r
-                           s_ByteModeRegister.\r
-                           b_ModeRegister3 & APCI1710_ENABLE_COMPARE_INT) == APCI1710_ENABLE_COMPARE_INT)\r
-                         {\r
-                         devpriv->\r
-                         s_InterruptParameters.\r
-                         s_FIFOInterruptParameters [devpriv->\r
-                                                    s_InterruptParameters.\r
-                                                    ui_Write].\r
-                         ul_OldInterruptMask = 8UL;\r
-\r
-                         devpriv->\r
-                         s_InterruptParameters.\r
-                         s_FIFOInterruptParameters [devpriv->\r
-                                                    s_InterruptParameters.\r
-                                                    ui_Write].\r
-                         b_OldModuleMask = 1 << b_ModuleCpt;\r
-\r
-                         devpriv->\r
-                         s_InterruptParameters.\r
-                         s_FIFOInterruptParameters [devpriv->\r
-                                                    s_InterruptParameters.\r
-                                                    ui_Write].\r
-                         ul_OldCounterLatchValue = ul_LatchRegisterValue;\r
-\r
-                         devpriv->\r
-                         s_InterruptParameters.\r
-                         ul_InterruptOccur ++;\r
-\r
-                         /****************************/\r
-                         /* 0899/0224 to 1199/0225   */\r
-                         /****************************/\r
-                         /* Increment the write FIFO */\r
-                      /****************************/\r
-\r
-                         devpriv->\r
-                         s_InterruptParameters.\r
-                         ui_Write = (devpriv->\r
-                                     s_InterruptParameters.\r
-                                     ui_Write + 1) % APCI1710_SAVE_INTERRUPT;\r
-\r
-                         b_InterruptFlag = 1;\r
-\r
-                         \r
-                           \r
-                               /**********************/\r
-                               /* Call user function */\r
-                               /**********************/\r
-                        //Send a signal to from kernel to user space\r
-                            send_sig(SIGIO,devpriv->tsk_Current,0); \r
-                               \r
-                         \r
-                         }\r
-                      }\r
-\r
-                   /*******************************************/\r
-                   /* Test if frequency measurement interrupt */\r
-                   /*******************************************/\r
-\r
-                   if (ul_InterruptLatchReg & 0x20)\r
-                      {\r
-                      /*******************/\r
-                      /* Read the status */\r
-                      /*******************/\r
-\r
-                         ul_StatusRegister=inl(devpriv->s_BoardInfos.\r
-                                 ui_Address + 32 + (64 * b_ModuleCpt));\r
-\r
-                      /******************/\r
-                      /* Read the value */\r
-                      /******************/\r
-\r
-\r
-                         ul_LatchRegisterValue=inl(devpriv->s_BoardInfos.\r
-                                 ui_Address + 28 + (64 * b_ModuleCpt));\r
-\r
-                      switch ((ul_StatusRegister >> 1) & 3)\r
-                         {\r
-                         case 0:\r
-                              /*************************/\r
-                              /* Test the counter mode */\r
-                              /*************************/\r
-\r
-                              if ((devpriv->\r
-                                   s_ModuleInfo [b_ModuleCpt].\r
-                                   s_SiemensCounterInfo.\r
-                                   s_ModeRegister.\r
-                                   s_ByteModeRegister.\r
-                                   b_ModeRegister1 & APCI1710_16BIT_COUNTER) == APCI1710_16BIT_COUNTER)\r
-                                 {\r
-                                 /****************************************/\r
-                                 /* Test if 16-bit counter 1 pulse occur */\r
-                                 /****************************************/\r
-\r
-                                 if ((ul_LatchRegisterValue & 0xFFFFU) != 0)\r
-                                    {\r
-                                    ui_16BitValue         = (UINT) ul_LatchRegisterValue & 0xFFFFU;\r
-                                    ul_LatchRegisterValue = (ul_LatchRegisterValue & 0xFFFF0000UL) | (0xFFFFU - ui_16BitValue);\r
-                                    }\r
-\r
-                                 /****************************************/\r
-                                 /* Test if 16-bit counter 2 pulse occur */\r
-                                 /****************************************/\r
-\r
-                                 if ((ul_LatchRegisterValue & 0xFFFF0000UL) != 0)\r
-                                    {\r
-                                    ui_16BitValue         = (UINT) ((ul_LatchRegisterValue >> 16) & 0xFFFFU);\r
-                                    ul_LatchRegisterValue = (ul_LatchRegisterValue & 0xFFFFUL) | ((0xFFFFU - ui_16BitValue) << 16);\r
-                                    }\r
-                                 }\r
-                              else\r
-                                 {\r
-                                 if (ul_LatchRegisterValue != 0)\r
-                                    {\r
-                                    ul_LatchRegisterValue = 0xFFFFFFFFUL - ul_LatchRegisterValue;\r
-                                    }\r
-                                 }\r
-                              break;\r
-\r
-                         case 1:\r
-                              /****************************************/\r
-                              /* Test if 16-bit counter 2 pulse occur */\r
-                              /****************************************/\r
-\r
-                              if ((ul_LatchRegisterValue & 0xFFFF0000UL) != 0)\r
-                                 {\r
-                                 ui_16BitValue         = (UINT) ((ul_LatchRegisterValue >> 16) & 0xFFFFU);\r
-                                 ul_LatchRegisterValue = (ul_LatchRegisterValue & 0xFFFFUL) | ((0xFFFFU - ui_16BitValue) << 16);\r
-                                 }\r
-                              break;\r
-\r
-                         case 2:\r
-                              /****************************************/\r
-                              /* Test if 16-bit counter 1 pulse occur */\r
-                              /****************************************/\r
-\r
-                              if ((ul_LatchRegisterValue & 0xFFFFU) != 0)\r
-                                 {\r
-                                 ui_16BitValue         = (UINT) ul_LatchRegisterValue & 0xFFFFU;\r
-                                 ul_LatchRegisterValue = (ul_LatchRegisterValue & 0xFFFF0000UL) | (0xFFFFU - ui_16BitValue);\r
-                                 }\r
-                              break;\r
-                         }\r
-\r
-                      devpriv->\r
-                      s_InterruptParameters.\r
-                      s_FIFOInterruptParameters [devpriv->\r
-                                                 s_InterruptParameters.\r
-                                                 ui_Write].\r
-                      ul_OldInterruptMask = 0x10000UL;\r
-\r
-                      devpriv->\r
-                      s_InterruptParameters.\r
-                      s_FIFOInterruptParameters [devpriv->\r
-                                                 s_InterruptParameters.\r
-                                                 ui_Write].\r
-                      b_OldModuleMask = 1 << b_ModuleCpt;\r
-\r
-                      devpriv->\r
-                      s_InterruptParameters.\r
-                      s_FIFOInterruptParameters [devpriv->\r
-                                                 s_InterruptParameters.\r
-                                                 ui_Write].\r
-                      ul_OldCounterLatchValue = ul_LatchRegisterValue;\r
-\r
-                      devpriv->\r
-                      s_InterruptParameters.\r
-                      ul_InterruptOccur ++;\r
-\r
-                      /****************************/\r
-                      /* 0899/0224 to 1199/0225   */\r
-                      /****************************/\r
-                      /* Increment the write FIFO */\r
-                      /****************************/\r
-\r
-                      devpriv->\r
-                      s_InterruptParameters.\r
-                      ui_Write = (devpriv->\r
-                                  s_InterruptParameters.\r
-                                  ui_Write + 1) % APCI1710_SAVE_INTERRUPT;\r
-\r
-                      b_InterruptFlag = 1;\r
-\r
-                      \r
-                           \r
-                            /**********************/\r
-                            /* Call user function */\r
-                            /**********************/\r
-                        //Send a signal to from kernel to user space\r
-                            send_sig(SIGIO,devpriv->tsk_Current,0); \r
-                           \r
-\r
-                      \r
-                      }\r
-                   } // Incremental counter\r
-\r
-\r
-\r
-\r
-\r
-\r
-                /***************/\r
-                /* Test if CDA */\r
-                /***************/\r
-\r
-                if ((devpriv->\r
-                     s_BoardInfos.\r
-                     dw_MolduleConfiguration [b_ModuleCpt] & 0xFFFF0000UL) == APCI1710_CDA)\r
-                   {\r
-                   /******************************************/\r
-                   /* Test if CDA enable and functionality 0 */\r
-                   /******************************************/\r
-\r
-                   if ((devpriv->\r
-                        s_ModuleInfo [b_ModuleCpt].\r
-                        s_CDAModuleInfo.\r
-                        b_CDAEnable == APCI1710_ENABLE) && (devpriv->\r
-                                                            s_ModuleInfo [b_ModuleCpt].\r
-                                                            s_CDAModuleInfo.\r
-                                                            b_FctSelection == 0))\r
-                      {\r
-                      /****************************/\r
-                      /* Get the interrupt status */\r
-                      /****************************/\r
-\r
-\r
-                       ul_StatusRegister=inl(devpriv->s_BoardInfos.\r
-                                 ui_Address + 16 + (64 * b_ModuleCpt));\r
-                      /***************************/\r
-                      /* Test if interrupt occur */\r
-                      /***************************/\r
-\r
-                      if (ul_StatusRegister & 1)\r
-                         {\r
-                         devpriv->\r
-                         s_InterruptParameters.\r
-                         s_FIFOInterruptParameters [devpriv->\r
-                                                    s_InterruptParameters.\r
-                                                    ui_Write].\r
-                         ul_OldInterruptMask = 0x80000UL;\r
-\r
-                         devpriv->\r
-                         s_InterruptParameters.\r
-                         s_FIFOInterruptParameters [devpriv->\r
-                                                    s_InterruptParameters.\r
-                                                    ui_Write].\r
-                         b_OldModuleMask = 1 << b_ModuleCpt;\r
-\r
-                         devpriv->\r
-                         s_InterruptParameters.\r
-                         s_FIFOInterruptParameters [devpriv->\r
-                                                    s_InterruptParameters.\r
-                                                    ui_Write].\r
-                         ul_OldCounterLatchValue = 0;\r
-\r
-                         devpriv->\r
-                         s_InterruptParameters.\r
-                         ul_InterruptOccur ++;\r
-\r
-                         \r
-                         /****************************/\r
-                         /* Increment the write FIFO */\r
-                         /****************************/\r
-\r
-                         devpriv->\r
-                         s_InterruptParameters.\r
-                         ui_Write = (devpriv->\r
-                                     s_InterruptParameters.\r
-                                     ui_Write + 1) % APCI1710_SAVE_INTERRUPT;\r
-\r
-                         b_InterruptFlag = 1;\r
-\r
-                         \r
-                          \r
-                               /**********************/\r
-                               /* Call user function */\r
-                               /**********************/\r
-\r
-                               //Send a signal to from kernel to user space\r
-                            send_sig(SIGIO,devpriv->tsk_Current,0);            \r
-\r
-                         } // if (ul_StatusRegister & 1)\r
-                     \r
-                        }\r
-                   } // CDA\r
-\r
-\r
-                /***********************/\r
-                /* Test if PWM counter */\r
-                /***********************/\r
-\r
-                if ((devpriv->\r
-                     s_BoardInfos.\r
-                     dw_MolduleConfiguration [b_ModuleCpt] & 0xFFFF0000UL) == APCI1710_PWM)\r
-                   {\r
-                   for (b_PWMCpt = 0; b_PWMCpt < 2; b_PWMCpt ++)\r
-                      {\r
-                      /*************************************/\r
-                      /* Test if PWM interrupt initialised */\r
-                      /*************************************/\r
-\r
-                      if (devpriv->\r
-                          s_ModuleInfo [b_ModuleCpt].\r
-                          s_PWMModuleInfo.\r
-                          s_PWMInfo [b_PWMCpt].\r
-                          b_InterruptEnable == APCI1710_ENABLE)\r
-                         {\r
-                         /*****************************/\r
-                         /* Read the interrupt status */\r
-                         /*****************************/\r
-\r
-                       ul_StatusRegister=inl(devpriv->s_BoardInfos.\r
-                                    ui_Address + 16 + (20 * b_PWMCpt) + (64 * b_ModuleCpt));\r
-\r
-\r
-                         /***************************/\r
-                         /* Test if interrupt occur */\r
-                         /***************************/\r
-\r
-                         if (ul_StatusRegister & 0x1)\r
-                            {\r
-                            devpriv->\r
-                            s_InterruptParameters.\r
-                            s_FIFOInterruptParameters [devpriv->\r
-                                                       s_InterruptParameters.\r
-                                                       ui_Write].\r
-                            ul_OldInterruptMask = 0x4000UL << b_PWMCpt;\r
-\r
-                            devpriv->\r
-                            s_InterruptParameters.\r
-                            s_FIFOInterruptParameters [devpriv->\r
-                                                       s_InterruptParameters.\r
-                                                       ui_Write].\r
-                            b_OldModuleMask = 1 << b_ModuleCpt;\r
-\r
-                            devpriv->\r
-                            s_InterruptParameters.\r
-                            ul_InterruptOccur ++;\r
-\r
-                            /****************************/\r
-                            /* Increment the write FIFO */\r
-                            /****************************/\r
-\r
-                            devpriv->\r
-                            s_InterruptParameters.\r
-                            ui_Write = (devpriv->\r
-                                        s_InterruptParameters.\r
-                                        ui_Write + 1) % APCI1710_SAVE_INTERRUPT;\r
-\r
-                            b_InterruptFlag = 1;\r
-\r
-                            \r
-                                  /**********************/\r
-                                  /* Call user function */\r
-                                  /**********************/\r
-                               //Send a signal to from kernel to user space\r
-                            send_sig(SIGIO,devpriv->tsk_Current,0); \r
-\r
-                            \r
-                            } // if (ul_StatusRegister & 0x1)\r
-                         } // if (APCI1710_ENABLE)\r
-                      } // for (b_PWMCpt == 0; b_PWMCpt < 0; b_PWMCpt ++)\r
-                   } // PWM counter\r
-\r
-\r
-\r
-                /***********************/\r
-                /* Test if tor counter */\r
-                /***********************/\r
-\r
-                if ((devpriv->\r
-                     s_BoardInfos.\r
-                     dw_MolduleConfiguration [b_ModuleCpt] & 0xFFFF0000UL) == APCI1710_TOR_COUNTER)\r
-                   {\r
-                   for (b_TorCounterCpt = 0; b_TorCounterCpt < 2; b_TorCounterCpt ++)\r
-                      {\r
-                      /*************************************/\r
-                      /* Test if tor interrupt initialised */\r
-                      /*************************************/\r
-\r
-                      if (devpriv->\r
-                          s_ModuleInfo [b_ModuleCpt].\r
-                          s_TorCounterModuleInfo.\r
-                          s_TorCounterInfo [b_TorCounterCpt].\r
-                          b_InterruptEnable == APCI1710_ENABLE)\r
-                         {\r
-                         /*****************************/\r
-                         /* Read the interrupt status */\r
-                         /*****************************/\r
-\r
-                       \r
-                               ul_StatusRegister=inl(devpriv->s_BoardInfos.\r
-                                    ui_Address + 12 + (16 * b_TorCounterCpt) + (64 * b_ModuleCpt));\r
-\r
-                         /***************************/\r
-                         /* Test if interrupt occur */\r
-                         /***************************/\r
-\r
-                         if (ul_StatusRegister & 0x1)\r
-                            {\r
-                            /******************************/\r
-                            /* Read the tor counter value */\r
-                            /******************************/\r
-\r
-                            \r
-                          ul_LatchRegisterValue=inl(devpriv->s_BoardInfos.\r
-                                       ui_Address + 0 + (16 * b_TorCounterCpt) + (64 * b_ModuleCpt));\r
-\r
-                            devpriv->\r
-                            s_InterruptParameters.\r
-                            s_FIFOInterruptParameters [devpriv->\r
-                                                       s_InterruptParameters.\r
-                                                       ui_Write].\r
-                            ul_OldInterruptMask = 0x1000UL << b_TorCounterCpt;\r
-\r
-                            devpriv->\r
-                            s_InterruptParameters.\r
-                            s_FIFOInterruptParameters [devpriv->\r
-                                                       s_InterruptParameters.\r
-                                                       ui_Write].\r
-                            b_OldModuleMask = 1 << b_ModuleCpt;\r
-\r
-                            devpriv->\r
-                            s_InterruptParameters.\r
-                            s_FIFOInterruptParameters [devpriv->\r
-                                                       s_InterruptParameters.\r
-                                                       ui_Write].\r
-                            ul_OldCounterLatchValue = ul_LatchRegisterValue;\r
-\r
-                            devpriv->\r
-                            s_InterruptParameters.\r
-                            ul_InterruptOccur ++;\r
-\r
-                            \r
-                            /****************************/\r
-                            /* Increment the write FIFO */\r
-                            /****************************/\r
-\r
-                            devpriv->\r
-                            s_InterruptParameters.\r
-                            ui_Write = (devpriv->\r
-                                        s_InterruptParameters.\r
-                                        ui_Write + 1) % APCI1710_SAVE_INTERRUPT;\r
-\r
-                            b_InterruptFlag = 1;\r
-\r
-       \r
-                                  /**********************/\r
-                                  /* Call user function */\r
-                                  /**********************/\r
-\r
-                            //Send a signal to from kernel to user space\r
-                            send_sig(SIGIO,devpriv->tsk_Current,0); \r
-                            } // if (ul_StatusRegister & 0x1)\r
-                         } // if (APCI1710_ENABLE)\r
-                      } // for (b_TorCounterCpt == 0; b_TorCounterCpt < 0; b_TorCounterCpt ++)\r
-                   } // Tor counter\r
-\r
-\r
-\r
-\r
-                /***********************/\r
-                /* Test if chronometer */\r
-                /***********************/\r
-\r
-                if ((devpriv->\r
-                     s_BoardInfos.\r
-                     dw_MolduleConfiguration [b_ModuleCpt] & 0xFFFF0000UL) == APCI1710_CHRONOMETER)\r
-                   {\r
-                    \r
-                       //printk("APCI1710 Chrono Interrupt\n");\r
-                   /*****************************/\r
-                   /* Read the interrupt status */\r
-                   /*****************************/\r
-\r
-                   \r
-                     ul_InterruptLatchReg=inl(devpriv->s_BoardInfos.\r
-                              ui_Address + 12 + (64 * b_ModuleCpt));\r
-\r
-                   /***************************/\r
-                   /* Test if interrupt occur */\r
-                   /***************************/\r
-\r
-                   if ((ul_InterruptLatchReg & 0x8) == 0x8)\r
-                      {\r
-                      /****************************/\r
-                      /* Clear the interrupt flag */\r
-                      /****************************/\r
-\r
-                     \r
-                               outl(0,devpriv->s_BoardInfos.\r
-                                  ui_Address + 32 + (64 * b_ModuleCpt));\r
-\r
-                      /***************************/\r
-                      /* Test if continuous mode */\r
-                      /***************************/\r
-\r
-                      if (ps_ModuleInfo->\r
-                          s_ChronoModuleInfo.\r
-                          b_CycleMode == APCI1710_ENABLE)\r
-                         {\r
-                         /********************/\r
-                         /* Clear the status */\r
-                         /********************/\r
-\r
-                         \r
-                       outl(0,devpriv->s_BoardInfos.\r
-                                     ui_Address + 36 + (64 * b_ModuleCpt));\r
-                         }\r
-\r
-                      /*************************/\r
-                      /* Read the timing value */\r
-                      /*************************/\r
-\r
-                      \r
-                               ul_LatchRegisterValue=inl(devpriv->s_BoardInfos.\r
-                                 ui_Address + 4 + (64 * b_ModuleCpt));\r
-\r
-                      /*****************************/\r
-                      /* Test if interrupt enabled */\r
-                      /*****************************/\r
-\r
-                      if (ps_ModuleInfo->\r
-                          s_ChronoModuleInfo.\r
-                          b_InterruptMask)\r
-                         {\r
-                         devpriv->\r
-                         s_InterruptParameters.\r
-                         s_FIFOInterruptParameters [devpriv->\r
-                                                    s_InterruptParameters.\r
-                                                    ui_Write].\r
-                         ul_OldInterruptMask = 0x80;\r
-\r
-                         devpriv->\r
-                         s_InterruptParameters.\r
-                         s_FIFOInterruptParameters [devpriv->\r
-                                                    s_InterruptParameters.\r
-                                                    ui_Write].\r
-                         b_OldModuleMask = 1 << b_ModuleCpt;\r
-\r
-                         devpriv->\r
-                         s_InterruptParameters.\r
-                         s_FIFOInterruptParameters [devpriv->\r
-                                                    s_InterruptParameters.\r
-                                                    ui_Write].\r
-                         ul_OldCounterLatchValue = ul_LatchRegisterValue;\r
-\r
-                         devpriv->\r
-                         s_InterruptParameters.\r
-                         ul_InterruptOccur ++;\r
-\r
-                         /****************************/\r
-                         /* Increment the write FIFO */\r
-                      /****************************/\r
-\r
-                         devpriv->\r
-                         s_InterruptParameters.\r
-                         ui_Write = (devpriv->\r
-                                     s_InterruptParameters.\r
-                                     ui_Write + 1) % APCI1710_SAVE_INTERRUPT;\r
-\r
-                         b_InterruptFlag = 1;\r
-\r
-                         \r
-                           \r
-                               /**********************/\r
-                               /* Call user function */\r
-                               /**********************/\r
-                               //Send a signal to from kernel to user space\r
-                            send_sig(SIGIO,devpriv->tsk_Current,0); \r
-                               \r
-                         }\r
-                  }\r
-                } // Chronometer\r
-\r
-\r
-\r
-                /*************************/\r
-                /* Test if pulse encoder */\r
-                /*************************/\r
-\r
-                if ((devpriv->\r
-                     s_BoardInfos.\r
-                     dw_MolduleConfiguration [b_ModuleCpt] & 0xFFFF0000UL) == APCI1710_PULSE_ENCODER)\r
-                   {\r
-                   /****************************/\r
-                   /* Read the status register */\r
-                   /****************************/\r
-\r
-                   \r
-                       ul_StatusRegister=inl(devpriv->s_BoardInfos.\r
-                              ui_Address + 20 + (64 * b_ModuleCpt));\r
-\r
-                   if (ul_StatusRegister & 0xF)\r
-                      {\r
-                      for (b_PulseIncoderCpt = 0; b_PulseIncoderCpt < 4; b_PulseIncoderCpt ++)\r
-                         {\r
-                         /*************************************/\r
-                         /* Test if pulse encoder initialised */\r
-                         /*************************************/\r
-\r
-                         if ((ps_ModuleInfo->\r
-                              s_PulseEncoderModuleInfo.\r
-                              s_PulseEncoderInfo [b_PulseIncoderCpt].\r
-                              b_PulseEncoderInit == 1) &&\r
-                             (((ps_ModuleInfo->\r
-                                s_PulseEncoderModuleInfo.\r
-                                dw_SetRegister >> b_PulseIncoderCpt) & 1) == 1) &&\r
-                             (((ul_StatusRegister >> (b_PulseIncoderCpt)) & 1) == 1))\r
-                            {\r
-                            devpriv->\r
-                            s_InterruptParameters.\r
-                            s_FIFOInterruptParameters [devpriv->\r
-                                                       s_InterruptParameters.\r
-                                                       ui_Write].\r
-                            ul_OldInterruptMask = 0x100UL << b_PulseIncoderCpt;\r
-\r
-                            devpriv->\r
-                            s_InterruptParameters.\r
-                            s_FIFOInterruptParameters [devpriv->\r
-                                                       s_InterruptParameters.\r
-                                                       ui_Write].\r
-                            b_OldModuleMask = 1 << b_ModuleCpt;\r
-\r
-                            devpriv->\r
-                            s_InterruptParameters.\r
-                            s_FIFOInterruptParameters [devpriv->\r
-                                                       s_InterruptParameters.\r
-                                                       ui_Write].\r
-                            ul_OldCounterLatchValue = ul_LatchRegisterValue;\r
-\r
-                            devpriv->\r
-                            s_InterruptParameters.\r
-                            ul_InterruptOccur ++;\r
-\r
-                            /****************************/\r
-                            /* 0899/0224 to 1199/0225   */\r
-                            /****************************/\r
-                            /* Increment the write FIFO */\r
-                            /****************************/\r
-\r
-                           devpriv->\r
-                            s_InterruptParameters.\r
-                            ui_Write = (devpriv->\r
-                                        s_InterruptParameters.\r
-                                        ui_Write + 1) % APCI1710_SAVE_INTERRUPT;\r
-\r
-                            b_InterruptFlag = 1;\r
-                           \r
-                                  /**********************/\r
-                                  /* Call user function */\r
-                                  /**********************/\r
-                            //Send a signal to from kernel to user space\r
-                            send_sig(SIGIO,devpriv->tsk_Current,0); \r
-                                  \r
-                \r
-                            }\r
-                               }\r
-                      }\r
-                   }//pulse encoder\r
-\r
-          }\r
-  return ; \r
-\r
-}\r
-\r
+/**
+@verbatim
+
+Copyright (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 USA
+
+You 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     : APCI-1710       | Compiler   : GCC                      |
+  | Module name : hwdrv_apci1710.c| Version    : 2.96                     |
+  +-------------------------------+---------------------------------------+
+  | Project manager: Eric Stolz   | Date       :  02/12/2002              |
+  +-------------------------------+---------------------------------------+
+  | Description :   Hardware Layer Acces For APCI-1710                    |
+  +-----------------------------------------------------------------------+
+  |                             UPDATES                                   |
+  +----------+-----------+------------------------------------------------+
+  |   Date   |   Author  |          Description of updates                |
+  +----------+-----------+------------------------------------------------+
+  |          |           |                                                |
+  |          |           |                                                |
+  |          |           |                                                |
+  +----------+-----------+------------------------------------------------+
+*/
+ #include "hwdrv_APCI1710.h"
+ #include "APCI1710_Inp_cpt.c"
+ #include "APCI1710_Ssi.c"
+ #include "APCI1710_Tor.c"
+ #include "APCI1710_Ttl.c"
+ #include "APCI1710_Dig_io.c" 
+ #include "APCI1710_82x54.c"
+ #include "APCI1710_Chrono.c"
+ #include "APCI1710_Pwm.c"
+ #include "APCI1710_INCCPT.c"
+
+
+void   i_ADDI_AttachPCI1710 (comedi_device *dev)
+       {
+       comedi_subdevice *s;
+       int ret          = 0;
+       int n_subdevices = 9;
+       
+       //Update-0.7.57->0.7.68dev->n_subdevices = 9;
+       if((ret=alloc_subdevices(dev,n_subdevices))<0)
+       return;
+        // Allocate and Initialise Timer Subdevice Structures          
+       s = dev->subdevices + 0;
+        
+       s->type = COMEDI_SUBD_TIMER;
+       s->subdev_flags = SDF_WRITEABLE|SDF_RT|SDF_GROUND|SDF_COMMON; 
+       s->n_chan = 3; 
+       s->maxdata = 0; 
+       s->len_chanlist = 3;
+       s->range_table = &range_digital;       
+        s->insn_write=i_APCI1710_InsnWriteEnableDisableTimer;
+       s->insn_read=i_APCI1710_InsnReadAllTimerValue;
+       s->insn_config=i_APCI1710_InsnConfigInitTimer;
+       s->insn_bits=i_APCI1710_InsnBitsTimer;
+       
+
+       // Allocate and Initialise DIO Subdevice Structures     
+       s = dev->subdevices + 1;
+        
+       s->type = COMEDI_SUBD_DIO;
+       s->subdev_flags = SDF_WRITEABLE|SDF_READABLE|SDF_RT|SDF_GROUND|SDF_COMMON;
+       s->n_chan = 7;
+       s->maxdata = 1;
+       s->len_chanlist = 7;
+       s->range_table = &range_digital;        
+               s->insn_config=i_APCI1710_InsnConfigDigitalIO;
+               s->insn_read= i_APCI1710_InsnReadDigitalIOChlValue;
+       s->insn_bits=i_APCI1710_InsnBitsDigitalIOPortOnOff;
+       s->insn_write=i_APCI1710_InsnWriteDigitalIOChlOnOff;
+        
+
+        // Allocate and Initialise Chrono Subdevice Structures         
+       s = dev->subdevices + 2;
+        
+       s->type = COMEDI_SUBD_CHRONO;
+       s->subdev_flags = SDF_WRITEABLE|SDF_RT|SDF_GROUND|SDF_COMMON; 
+       s->n_chan = 4; 
+       s->maxdata = 0; 
+       s->len_chanlist = 4;
+       s->range_table = &range_digital;        
+        s->insn_write=i_APCI1710_InsnWriteEnableDisableChrono;
+       s->insn_read=i_APCI1710_InsnReadChrono;
+       s->insn_config=i_APCI1710_InsnConfigInitChrono;
+       s->insn_bits=i_APCI1710_InsnBitsChronoDigitalIO;
+       
+       
+       // Allocate and Initialise PWM Subdevice Structures                 
+       s = dev->subdevices + 3;
+       s->type = COMEDI_SUBD_PWM;
+       s->subdev_flags = SDF_WRITEABLE|SDF_READABLE|SDF_RT|SDF_GROUND|SDF_COMMON;
+       s->n_chan = 3;
+       s->maxdata = 1;
+       s->len_chanlist = 3;
+       s->range_table = &range_digital;
+       s->io_bits=0;           //all bits input        
+       s->insn_config = i_APCI1710_InsnConfigPWM;
+       s->insn_read   = i_APCI1710_InsnReadGetPWMStatus;
+       s->insn_write  = i_APCI1710_InsnWritePWM;
+        s->insn_bits   = i_APCI1710_InsnBitsReadPWMInterrupt;
+
+       // Allocate and Initialise TTLIO Subdevice Structures
+       s = dev->subdevices + 4;
+       s->type = COMEDI_SUBD_TTLIO;
+       s->subdev_flags = SDF_WRITEABLE|SDF_READABLE|SDF_RT|SDF_GROUND|SDF_COMMON;
+       s->n_chan = 8;
+       s->maxdata = 1;
+       s->len_chanlist = 8;
+       s->range_table = &range_apci1710_ttl; // to pass arguments in range     
+        s->insn_config         = i_APCI1710_InsnConfigInitTTLIO;
+       s->insn_bits    = i_APCI1710_InsnBitsReadTTLIO;
+       s->insn_write   = i_APCI1710_InsnWriteSetTTLIOChlOnOff;
+        s->insn_read   = i_APCI1710_InsnReadTTLIOAllPortValue;
+
+
+       // Allocate and Initialise TOR Subdevice Structures
+       s = dev->subdevices + 5;
+       s->type = COMEDI_SUBD_TOR;
+       s->subdev_flags = SDF_WRITEABLE|SDF_READABLE|SDF_RT|SDF_GROUND|SDF_COMMON;
+       s->n_chan = 8;
+       s->maxdata = 1;
+       s->len_chanlist = 8;
+       s->range_table = &range_digital;
+       s->io_bits=0;           //all bits input        
+        s->insn_config = i_APCI1710_InsnConfigInitTorCounter;
+       s->insn_read   = i_APCI1710_InsnReadGetTorCounterInitialisation;
+       s->insn_write  = i_APCI1710_InsnWriteEnableDisableTorCounter;
+       s->insn_bits   = i_APCI1710_InsnBitsGetTorCounterProgressStatusAndValue;
+       // Allocate and Initialise SSI Subdevice Structures
+       s = dev->subdevices + 6;
+       s->type = COMEDI_SUBD_SSI;
+       s->subdev_flags = SDF_WRITEABLE|SDF_READABLE|SDF_RT|SDF_GROUND|SDF_COMMON;
+       s->n_chan =4;
+       s->maxdata = 1;
+       s->len_chanlist = 4;
+       s->range_table = &range_apci1710_ssi;   
+       s->insn_config = i_APCI1710_InsnConfigInitSSI;
+       s->insn_read   = i_APCI1710_InsnReadSSIValue;
+       s->insn_bits  = i_APCI1710_InsnBitsSSIDigitalIO;
+       // Allocate and Initialise PULSEENCODER Subdevice Structures       
+       s                       = dev->subdevices + 7;
+       s->type                 = COMEDI_SUBD_PULSEENCODER;
+       s->subdev_flags = SDF_WRITEABLE|SDF_READABLE|SDF_RT|SDF_GROUND|SDF_COMMON;
+       s->n_chan               = 4;
+       s->maxdata              = 1;
+       s->len_chanlist = 4;
+       s->range_table  = &range_digital;       
+       s->insn_config  = i_APCI1710_InsnConfigInitPulseEncoder;
+       s->insn_write   = i_APCI1710_InsnWriteEnableDisablePulseEncoder;
+       s->insn_bits    = i_APCI1710_InsnBitsReadWritePulseEncoder;
+       s->insn_read    = i_APCI1710_InsnReadInterruptPulseEncoder;
+
+       // Allocate and Initialise INCREMENTALCOUNTER Subdevice Structures     
+       s                       = dev->subdevices + 8;
+       s->type                 = COMEDI_SUBD_INCREMENTALCOUNTER;
+       s->subdev_flags = SDF_WRITEABLE|SDF_READABLE|SDF_RT|SDF_GROUND|SDF_COMMON;
+       s->n_chan               = 500;
+       s->maxdata              = 1;
+       s->len_chanlist = 500;
+       s->range_table  = &range_apci1710_inccpt;       
+       s->insn_config  = i_APCI1710_InsnConfigINCCPT;
+       s->insn_write   = i_APCI1710_InsnWriteINCCPT;
+       s->insn_read    = i_APCI1710_InsnReadINCCPT;
+       s->insn_bits    = i_APCI1710_InsnBitsINCCPT;
+       }
+int i_APCI1710_Reset(comedi_device *dev);
+VOID v_APCI1710_Interrupt(int irq, void *d, struct pt_regs *regs) ;
+//for 1710
+
+ int i_APCI1710_Reset(comedi_device *dev)
+{
+    int ret;
+    DWORD dw_Dummy;    
+  
+       /*********************************/ 
+       /* Read all module configuration */ 
+       /*********************************/ 
+        ret=inl(devpriv->s_BoardInfos.ui_Address+60);
+       devpriv->s_BoardInfos.dw_MolduleConfiguration [0]=ret;
+            
+        ret=inl(devpriv->s_BoardInfos.ui_Address+124);
+       devpriv->s_BoardInfos.dw_MolduleConfiguration [1]=ret;
+            
+        ret=inl(devpriv->s_BoardInfos.ui_Address+188);
+       devpriv->s_BoardInfos.dw_MolduleConfiguration [2]=ret;
+            
+        ret=inl(devpriv->s_BoardInfos.ui_Address+252);
+       devpriv->s_BoardInfos.dw_MolduleConfiguration [3]=ret;
+
+       // outl(0x80808082,devpriv->s_BoardInfos.ui_Address+0x60);
+       outl(0x83838383,devpriv->s_BoardInfos.ui_Address+0x60);  
+       
+       devpriv->s_BoardInfos.b_BoardVersion = 1;
+
+       // Enable the interrupt for the controler       
+       dw_Dummy =  inl(devpriv->s_BoardInfos.ui_Address+ 0x38);
+       outl(dw_Dummy | 0x2000,devpriv->s_BoardInfos.ui_Address+0x38);
+
+       return 0;
+}
+
+
+/*
++----------------------------------------------------------------------------+
+| Function's Name   : __VOID__ v_APCI1710_InterruptFunction                  |
+|                              (BYTE b_Interrupt, __CPPARGS)                |
++----------------------------------------------------------------------------+
+| Task              : APCI-1710 interrupt function                           |
++----------------------------------------------------------------------------+
+| Input Parameters  : BYTE b_Interrupt : Interrupt number                    |
++----------------------------------------------------------------------------+
+| Output Parameters : -                                                      |
++----------------------------------------------------------------------------+
+| Return Value      : 0 : OK                                                 |
+|                    -1 : Error                                              |
++----------------------------------------------------------------------------+
+*/
+
+
+       
+
+
+VOID v_APCI1710_Interrupt(int irq, void *d, struct pt_regs *regs)  
+{
+       comedi_device *dev = d;
+       BYTE   b_ModuleCpt       = 0;
+       BYTE   b_InterruptFlag   = 0;
+       BYTE   b_PWMCpt          = 0;
+       BYTE   b_TorCounterCpt   = 0;
+       BYTE   b_PulseIncoderCpt = 0;
+       UINT  ui_16BitValue;
+       ULONG ul_InterruptLatchReg = 0;
+       ULONG ul_LatchRegisterValue = 0;
+       ULONG ul_82X54InterruptStatus;
+       ULONG ul_StatusRegister;
+
+       str_ModuleInfo  * ps_ModuleInfo;
+
+        printk("APCI1710 Interrupt\n");
+          for (b_ModuleCpt = 0; b_ModuleCpt < 4; b_ModuleCpt ++, ps_ModuleInfo ++)
+             {
+
+                /**************************/
+                /* 1199/0225 to 0100/0226 */
+                /**************************/
+                ps_ModuleInfo = &devpriv->s_ModuleInfo [b_ModuleCpt];
+
+
+                 /***********************/
+                /* Test if 82X54 timer */
+                /***********************/
+
+                if ((devpriv->
+                     s_BoardInfos.
+                     dw_MolduleConfiguration [b_ModuleCpt] & 0xFFFF0000UL) == APCI1710_82X54_TIMER)
+                   {
+                   
+                     //printk("TIMER Interrupt Occurred\n");
+                     ul_82X54InterruptStatus= inl(devpriv->s_BoardInfos.
+                              ui_Address + 12 + (64 * b_ModuleCpt));
+
+                   /***************************/
+                   /* Test if interrupt occur */
+                   /***************************/
+
+                   if ((ul_82X54InterruptStatus & ps_ModuleInfo->
+                                                  s_82X54ModuleInfo.
+                                                  b_InterruptMask) != 0)
+                      {
+                      devpriv->
+                      s_InterruptParameters.
+                      s_FIFOInterruptParameters [devpriv->
+                                                 s_InterruptParameters.
+                                                 ui_Write].
+                      ul_OldInterruptMask = (ul_82X54InterruptStatus & ps_ModuleInfo->
+                                                                       s_82X54ModuleInfo.
+                                                                       b_InterruptMask) << 4;
+
+                      devpriv->
+                      s_InterruptParameters.
+                      s_FIFOInterruptParameters [devpriv->
+                                                 s_InterruptParameters.
+                                                 ui_Write].
+                      b_OldModuleMask = 1 << b_ModuleCpt;
+
+                      devpriv->
+                      s_InterruptParameters.
+                      s_FIFOInterruptParameters [devpriv->
+                                                 s_InterruptParameters.
+                                                 ui_Write].
+                      ul_OldCounterLatchValue = 0;
+
+                      devpriv->
+                      s_InterruptParameters.
+                      ul_InterruptOccur ++;
+
+                      /****************************/
+                      /* Increment the write FIFO */
+                      /****************************/
+
+                      devpriv->
+                      s_InterruptParameters.
+                      ui_Write = (devpriv->
+                                  s_InterruptParameters.
+                                  ui_Write + 1) % APCI1710_SAVE_INTERRUPT;
+
+                      b_InterruptFlag = 1;
+
+                      
+                           
+                            /**********************/
+                            /* Call user function */
+                            /**********************/
+                         //Send a signal to from kernel to user space
+                            send_sig(SIGIO,devpriv->tsk_Current,0); 
+                           
+                      } // if ((ul_82X54InterruptStatus & 0x7) != 0)
+                   } // 82X54 timer
+
+
+
+
+
+                /***************************/
+                /* Test if increm. counter */
+                /***************************/
+
+                if ((devpriv->
+                     s_BoardInfos.
+                     dw_MolduleConfiguration [b_ModuleCpt] & 0xFFFF0000UL) == APCI1710_INCREMENTAL_COUNTER)
+                   {
+
+                        ul_InterruptLatchReg=inl(devpriv->s_BoardInfos.
+                              ui_Address + (64 * b_ModuleCpt));
+
+                   /*********************/
+                   /* Test if interrupt */
+                   /*********************/
+
+                   if ((ul_InterruptLatchReg & 0x22) && (ps_ModuleInfo->
+                                                         s_SiemensCounterInfo.
+                                                         s_ModeRegister.
+                                                         s_ByteModeRegister.
+                                                         b_ModeRegister2 & 0x80))
+                      {
+                      /************************************/
+                      /* Test if strobe latch I interrupt */
+                      /************************************/
+
+                      if (ul_InterruptLatchReg & 2)
+                         {
+                               ul_LatchRegisterValue=inl(devpriv->s_BoardInfos.
+                                    ui_Address + 4 + (64 * b_ModuleCpt));
+
+                         devpriv->
+                         s_InterruptParameters.
+                         s_FIFOInterruptParameters [devpriv->
+                                                    s_InterruptParameters.
+                                                    ui_Write].
+                         ul_OldInterruptMask = 1UL;
+
+                         devpriv->
+                         s_InterruptParameters.
+                         s_FIFOInterruptParameters [devpriv->
+                                                    s_InterruptParameters.
+                                                    ui_Write].
+                         b_OldModuleMask = 1 << b_ModuleCpt;
+
+                         devpriv->
+                         s_InterruptParameters.
+                         s_FIFOInterruptParameters [devpriv->
+                                                    s_InterruptParameters.
+                                                    ui_Write].
+                         ul_OldCounterLatchValue = ul_LatchRegisterValue;
+
+                         devpriv->
+                         s_InterruptParameters.
+                         ul_InterruptOccur ++;
+
+                         /****************************/
+                         /* 0899/0224 to 1199/0225   */
+                         /****************************/
+                         /* Increment the write FIFO */
+                      /****************************/
+
+                         devpriv->
+                         s_InterruptParameters.
+                         ui_Write = (devpriv->
+                                     s_InterruptParameters.
+                                     ui_Write + 1) % APCI1710_SAVE_INTERRUPT;
+
+                         b_InterruptFlag = 1;
+
+                        
+                            
+                               /**********************/
+                               /* Call user function */
+                               /**********************/
+                        //Send a signal to from kernel to user space
+                            send_sig(SIGIO,devpriv->tsk_Current,0); 
+                               
+                        
+                         }
+
+                      /*************************************/
+                      /* Test if strobe latch II interrupt */
+                      /*************************************/
+
+                      if (ul_InterruptLatchReg & 0x20)
+                         {
+                         
+                         ul_LatchRegisterValue=inl(devpriv->s_BoardInfos.
+                                    ui_Address + 8 + (64 * b_ModuleCpt));
+
+                         devpriv->
+                         s_InterruptParameters.
+                         s_FIFOInterruptParameters [devpriv->
+                                                    s_InterruptParameters.
+                                                    ui_Write].
+                         ul_OldInterruptMask = 2UL;
+
+                         devpriv->
+                         s_InterruptParameters.
+                         s_FIFOInterruptParameters [devpriv->
+                                                    s_InterruptParameters.
+                                                    ui_Write].
+                         b_OldModuleMask = 1 << b_ModuleCpt;
+
+                         devpriv->
+                         s_InterruptParameters.
+                         s_FIFOInterruptParameters [devpriv->
+                                                    s_InterruptParameters.
+                                                    ui_Write].
+                         ul_OldCounterLatchValue = ul_LatchRegisterValue;
+
+                         devpriv->
+                         s_InterruptParameters.
+                         ul_InterruptOccur ++;
+
+                         /****************************/
+                         /* 0899/0224 to 1199/0225   */
+                         /****************************/
+                         /* Increment the write FIFO */
+                         /****************************/
+
+                         devpriv->
+                         s_InterruptParameters.
+                         ui_Write = (devpriv->
+                                     s_InterruptParameters.
+                                     ui_Write + 1) % APCI1710_SAVE_INTERRUPT;
+
+                         b_InterruptFlag = 1;
+
+                         
+                           /**********************/
+                               /* Call user function */
+                               /**********************/
+                        //Send a signal to from kernel to user space
+                            send_sig(SIGIO,devpriv->tsk_Current,0); 
+                               
+                                 }
+                      }
+
+                 
+                       ul_InterruptLatchReg=inl(devpriv-> s_BoardInfos.
+                              ui_Address + 24 + (64 * b_ModuleCpt));
+
+                   /***************************/
+                   /* Test if index interrupt */
+                   /***************************/
+
+                   if (ul_InterruptLatchReg & 0x8)
+                      {
+                      ps_ModuleInfo->
+                      s_SiemensCounterInfo.
+                      s_InitFlag.
+                      b_IndexInterruptOccur = 1;
+
+                      if (ps_ModuleInfo->
+                          s_SiemensCounterInfo.
+                          s_ModeRegister.
+                          s_ByteModeRegister.
+                          b_ModeRegister2 & APCI1710_INDEX_AUTO_MODE)
+                         {
+
+                       outl(ps_ModuleInfo->
+                                     s_SiemensCounterInfo.
+                                     s_ModeRegister.
+                                     dw_ModeRegister1_2_3_4,devpriv->
+                                     s_BoardInfos.
+                                     ui_Address + 20 + (64 * b_ModuleCpt));
+                         }
+
+                      /*****************************/
+                      /* Test if interrupt enabled */
+                      /*****************************/
+
+                      if ((ps_ModuleInfo->
+                           s_SiemensCounterInfo.
+                           s_ModeRegister.
+                           s_ByteModeRegister.
+                           b_ModeRegister3 & APCI1710_ENABLE_INDEX_INT) == APCI1710_ENABLE_INDEX_INT)
+                         {
+                         devpriv->
+                         s_InterruptParameters.
+                         s_FIFOInterruptParameters [devpriv->
+                                                    s_InterruptParameters.
+                                                    ui_Write].
+                         ul_OldInterruptMask = 4UL;
+
+                         devpriv->
+                         s_InterruptParameters.
+                         s_FIFOInterruptParameters [devpriv->
+                                                    s_InterruptParameters.
+                                                    ui_Write].
+                         b_OldModuleMask = 1 << b_ModuleCpt;
+
+                         devpriv->
+                         s_InterruptParameters.
+                         s_FIFOInterruptParameters [devpriv->
+                                                    s_InterruptParameters.
+                                                    ui_Write].
+                         ul_OldCounterLatchValue = ul_LatchRegisterValue;
+
+                         devpriv->
+                         s_InterruptParameters.
+                         ul_InterruptOccur ++;
+
+                         /****************************/
+                         /* 0899/0224 to 1199/0225   */
+                         /****************************/
+                         /* Increment the write FIFO */
+                         /****************************/
+
+                         devpriv->
+                         s_InterruptParameters.
+                         ui_Write = (devpriv->
+                                     s_InterruptParameters.
+                                     ui_Write + 1) % APCI1710_SAVE_INTERRUPT;
+
+                         b_InterruptFlag = 1;
+
+                         
+                           
+                               /**********************/
+                               /* Call user function */
+                               /**********************/
+                        //Send a signal to from kernel to user space
+                            send_sig(SIGIO,devpriv->tsk_Current,0); 
+                               
+                               }
+                      }
+
+                   /*****************************/
+                   /* Test if compare interrupt */
+                   /*****************************/
+
+                   if (ul_InterruptLatchReg & 0x10)
+                      {
+                      /*****************************/
+                      /* Test if interrupt enabled */
+                      /*****************************/
+
+                      if ((ps_ModuleInfo->
+                           s_SiemensCounterInfo.
+                           s_ModeRegister.
+                           s_ByteModeRegister.
+                           b_ModeRegister3 & APCI1710_ENABLE_COMPARE_INT) == APCI1710_ENABLE_COMPARE_INT)
+                         {
+                         devpriv->
+                         s_InterruptParameters.
+                         s_FIFOInterruptParameters [devpriv->
+                                                    s_InterruptParameters.
+                                                    ui_Write].
+                         ul_OldInterruptMask = 8UL;
+
+                         devpriv->
+                         s_InterruptParameters.
+                         s_FIFOInterruptParameters [devpriv->
+                                                    s_InterruptParameters.
+                                                    ui_Write].
+                         b_OldModuleMask = 1 << b_ModuleCpt;
+
+                         devpriv->
+                         s_InterruptParameters.
+                         s_FIFOInterruptParameters [devpriv->
+                                                    s_InterruptParameters.
+                                                    ui_Write].
+                         ul_OldCounterLatchValue = ul_LatchRegisterValue;
+
+                         devpriv->
+                         s_InterruptParameters.
+                         ul_InterruptOccur ++;
+
+                         /****************************/
+                         /* 0899/0224 to 1199/0225   */
+                         /****************************/
+                         /* Increment the write FIFO */
+                      /****************************/
+
+                         devpriv->
+                         s_InterruptParameters.
+                         ui_Write = (devpriv->
+                                     s_InterruptParameters.
+                                     ui_Write + 1) % APCI1710_SAVE_INTERRUPT;
+
+                         b_InterruptFlag = 1;
+
+                         
+                           
+                               /**********************/
+                               /* Call user function */
+                               /**********************/
+                        //Send a signal to from kernel to user space
+                            send_sig(SIGIO,devpriv->tsk_Current,0); 
+                               
+                         
+                         }
+                      }
+
+                   /*******************************************/
+                   /* Test if frequency measurement interrupt */
+                   /*******************************************/
+
+                   if (ul_InterruptLatchReg & 0x20)
+                      {
+                      /*******************/
+                      /* Read the status */
+                      /*******************/
+
+                         ul_StatusRegister=inl(devpriv->s_BoardInfos.
+                                 ui_Address + 32 + (64 * b_ModuleCpt));
+
+                      /******************/
+                      /* Read the value */
+                      /******************/
+
+
+                         ul_LatchRegisterValue=inl(devpriv->s_BoardInfos.
+                                 ui_Address + 28 + (64 * b_ModuleCpt));
+
+                      switch ((ul_StatusRegister >> 1) & 3)
+                         {
+                         case 0:
+                              /*************************/
+                              /* Test the counter mode */
+                              /*************************/
+
+                              if ((devpriv->
+                                   s_ModuleInfo [b_ModuleCpt].
+                                   s_SiemensCounterInfo.
+                                   s_ModeRegister.
+                                   s_ByteModeRegister.
+                                   b_ModeRegister1 & APCI1710_16BIT_COUNTER) == APCI1710_16BIT_COUNTER)
+                                 {
+                                 /****************************************/
+                                 /* Test if 16-bit counter 1 pulse occur */
+                                 /****************************************/
+
+                                 if ((ul_LatchRegisterValue & 0xFFFFU) != 0)
+                                    {
+                                    ui_16BitValue         = (UINT) ul_LatchRegisterValue & 0xFFFFU;
+                                    ul_LatchRegisterValue = (ul_LatchRegisterValue & 0xFFFF0000UL) | (0xFFFFU - ui_16BitValue);
+                                    }
+
+                                 /****************************************/
+                                 /* Test if 16-bit counter 2 pulse occur */
+                                 /****************************************/
+
+                                 if ((ul_LatchRegisterValue & 0xFFFF0000UL) != 0)
+                                    {
+                                    ui_16BitValue         = (UINT) ((ul_LatchRegisterValue >> 16) & 0xFFFFU);
+                                    ul_LatchRegisterValue = (ul_LatchRegisterValue & 0xFFFFUL) | ((0xFFFFU - ui_16BitValue) << 16);
+                                    }
+                                 }
+                              else
+                                 {
+                                 if (ul_LatchRegisterValue != 0)
+                                    {
+                                    ul_LatchRegisterValue = 0xFFFFFFFFUL - ul_LatchRegisterValue;
+                                    }
+                                 }
+                              break;
+
+                         case 1:
+                              /****************************************/
+                              /* Test if 16-bit counter 2 pulse occur */
+                              /****************************************/
+
+                              if ((ul_LatchRegisterValue & 0xFFFF0000UL) != 0)
+                                 {
+                                 ui_16BitValue         = (UINT) ((ul_LatchRegisterValue >> 16) & 0xFFFFU);
+                                 ul_LatchRegisterValue = (ul_LatchRegisterValue & 0xFFFFUL) | ((0xFFFFU - ui_16BitValue) << 16);
+                                 }
+                              break;
+
+                         case 2:
+                              /****************************************/
+                              /* Test if 16-bit counter 1 pulse occur */
+                              /****************************************/
+
+                              if ((ul_LatchRegisterValue & 0xFFFFU) != 0)
+                                 {
+                                 ui_16BitValue         = (UINT) ul_LatchRegisterValue & 0xFFFFU;
+                                 ul_LatchRegisterValue = (ul_LatchRegisterValue & 0xFFFF0000UL) | (0xFFFFU - ui_16BitValue);
+                                 }
+                              break;
+                         }
+
+                      devpriv->
+                      s_InterruptParameters.
+                      s_FIFOInterruptParameters [devpriv->
+                                                 s_InterruptParameters.
+                                                 ui_Write].
+                      ul_OldInterruptMask = 0x10000UL;
+
+                      devpriv->
+                      s_InterruptParameters.
+                      s_FIFOInterruptParameters [devpriv->
+                                                 s_InterruptParameters.
+                                                 ui_Write].
+                      b_OldModuleMask = 1 << b_ModuleCpt;
+
+                      devpriv->
+                      s_InterruptParameters.
+                      s_FIFOInterruptParameters [devpriv->
+                                                 s_InterruptParameters.
+                                                 ui_Write].
+                      ul_OldCounterLatchValue = ul_LatchRegisterValue;
+
+                      devpriv->
+                      s_InterruptParameters.
+                      ul_InterruptOccur ++;
+
+                      /****************************/
+                      /* 0899/0224 to 1199/0225   */
+                      /****************************/
+                      /* Increment the write FIFO */
+                      /****************************/
+
+                      devpriv->
+                      s_InterruptParameters.
+                      ui_Write = (devpriv->
+                                  s_InterruptParameters.
+                                  ui_Write + 1) % APCI1710_SAVE_INTERRUPT;
+
+                      b_InterruptFlag = 1;
+
+                      
+                           
+                            /**********************/
+                            /* Call user function */
+                            /**********************/
+                        //Send a signal to from kernel to user space
+                            send_sig(SIGIO,devpriv->tsk_Current,0); 
+                           
+
+                      
+                      }
+                   } // Incremental counter
+
+
+
+
+
+
+                /***************/
+                /* Test if CDA */
+                /***************/
+
+                if ((devpriv->
+                     s_BoardInfos.
+                     dw_MolduleConfiguration [b_ModuleCpt] & 0xFFFF0000UL) == APCI1710_CDA)
+                   {
+                   /******************************************/
+                   /* Test if CDA enable and functionality 0 */
+                   /******************************************/
+
+                   if ((devpriv->
+                        s_ModuleInfo [b_ModuleCpt].
+                        s_CDAModuleInfo.
+                        b_CDAEnable == APCI1710_ENABLE) && (devpriv->
+                                                            s_ModuleInfo [b_ModuleCpt].
+                                                            s_CDAModuleInfo.
+                                                            b_FctSelection == 0))
+                      {
+                      /****************************/
+                      /* Get the interrupt status */
+                      /****************************/
+
+
+                       ul_StatusRegister=inl(devpriv->s_BoardInfos.
+                                 ui_Address + 16 + (64 * b_ModuleCpt));
+                      /***************************/
+                      /* Test if interrupt occur */
+                      /***************************/
+
+                      if (ul_StatusRegister & 1)
+                         {
+                         devpriv->
+                         s_InterruptParameters.
+                         s_FIFOInterruptParameters [devpriv->
+                                                    s_InterruptParameters.
+                                                    ui_Write].
+                         ul_OldInterruptMask = 0x80000UL;
+
+                         devpriv->
+                         s_InterruptParameters.
+                         s_FIFOInterruptParameters [devpriv->
+                                                    s_InterruptParameters.
+                                                    ui_Write].
+                         b_OldModuleMask = 1 << b_ModuleCpt;
+
+                         devpriv->
+                         s_InterruptParameters.
+                         s_FIFOInterruptParameters [devpriv->
+                                                    s_InterruptParameters.
+                                                    ui_Write].
+                         ul_OldCounterLatchValue = 0;
+
+                         devpriv->
+                         s_InterruptParameters.
+                         ul_InterruptOccur ++;
+
+                         
+                         /****************************/
+                         /* Increment the write FIFO */
+                         /****************************/
+
+                         devpriv->
+                         s_InterruptParameters.
+                         ui_Write = (devpriv->
+                                     s_InterruptParameters.
+                                     ui_Write + 1) % APCI1710_SAVE_INTERRUPT;
+
+                         b_InterruptFlag = 1;
+
+                         
+                          
+                               /**********************/
+                               /* Call user function */
+                               /**********************/
+
+                               //Send a signal to from kernel to user space
+                            send_sig(SIGIO,devpriv->tsk_Current,0);            
+
+                         } // if (ul_StatusRegister & 1)
+                     
+                        }
+                   } // CDA
+
+
+                /***********************/
+                /* Test if PWM counter */
+                /***********************/
+
+                if ((devpriv->
+                     s_BoardInfos.
+                     dw_MolduleConfiguration [b_ModuleCpt] & 0xFFFF0000UL) == APCI1710_PWM)
+                   {
+                   for (b_PWMCpt = 0; b_PWMCpt < 2; b_PWMCpt ++)
+                      {
+                      /*************************************/
+                      /* Test if PWM interrupt initialised */
+                      /*************************************/
+
+                      if (devpriv->
+                          s_ModuleInfo [b_ModuleCpt].
+                          s_PWMModuleInfo.
+                          s_PWMInfo [b_PWMCpt].
+                          b_InterruptEnable == APCI1710_ENABLE)
+                         {
+                         /*****************************/
+                         /* Read the interrupt status */
+                         /*****************************/
+
+                       ul_StatusRegister=inl(devpriv->s_BoardInfos.
+                                    ui_Address + 16 + (20 * b_PWMCpt) + (64 * b_ModuleCpt));
+
+
+                         /***************************/
+                         /* Test if interrupt occur */
+                         /***************************/
+
+                         if (ul_StatusRegister & 0x1)
+                            {
+                            devpriv->
+                            s_InterruptParameters.
+                            s_FIFOInterruptParameters [devpriv->
+                                                       s_InterruptParameters.
+                                                       ui_Write].
+                            ul_OldInterruptMask = 0x4000UL << b_PWMCpt;
+
+                            devpriv->
+                            s_InterruptParameters.
+                            s_FIFOInterruptParameters [devpriv->
+                                                       s_InterruptParameters.
+                                                       ui_Write].
+                            b_OldModuleMask = 1 << b_ModuleCpt;
+
+                            devpriv->
+                            s_InterruptParameters.
+                            ul_InterruptOccur ++;
+
+                            /****************************/
+                            /* Increment the write FIFO */
+                            /****************************/
+
+                            devpriv->
+                            s_InterruptParameters.
+                            ui_Write = (devpriv->
+                                        s_InterruptParameters.
+                                        ui_Write + 1) % APCI1710_SAVE_INTERRUPT;
+
+                            b_InterruptFlag = 1;
+
+                            
+                                  /**********************/
+                                  /* Call user function */
+                                  /**********************/
+                               //Send a signal to from kernel to user space
+                            send_sig(SIGIO,devpriv->tsk_Current,0); 
+
+                            
+                            } // if (ul_StatusRegister & 0x1)
+                         } // if (APCI1710_ENABLE)
+                      } // for (b_PWMCpt == 0; b_PWMCpt < 0; b_PWMCpt ++)
+                   } // PWM counter
+
+
+
+                /***********************/
+                /* Test if tor counter */
+                /***********************/
+
+                if ((devpriv->
+                     s_BoardInfos.
+                     dw_MolduleConfiguration [b_ModuleCpt] & 0xFFFF0000UL) == APCI1710_TOR_COUNTER)
+                   {
+                   for (b_TorCounterCpt = 0; b_TorCounterCpt < 2; b_TorCounterCpt ++)
+                      {
+                      /*************************************/
+                      /* Test if tor interrupt initialised */
+                      /*************************************/
+
+                      if (devpriv->
+                          s_ModuleInfo [b_ModuleCpt].
+                          s_TorCounterModuleInfo.
+                          s_TorCounterInfo [b_TorCounterCpt].
+                          b_InterruptEnable == APCI1710_ENABLE)
+                         {
+                         /*****************************/
+                         /* Read the interrupt status */
+                         /*****************************/
+
+                       
+                               ul_StatusRegister=inl(devpriv->s_BoardInfos.
+                                    ui_Address + 12 + (16 * b_TorCounterCpt) + (64 * b_ModuleCpt));
+
+                         /***************************/
+                         /* Test if interrupt occur */
+                         /***************************/
+
+                         if (ul_StatusRegister & 0x1)
+                            {
+                            /******************************/
+                            /* Read the tor counter value */
+                            /******************************/
+
+                            
+                          ul_LatchRegisterValue=inl(devpriv->s_BoardInfos.
+                                       ui_Address + 0 + (16 * b_TorCounterCpt) + (64 * b_ModuleCpt));
+
+                            devpriv->
+                            s_InterruptParameters.
+                            s_FIFOInterruptParameters [devpriv->
+                                                       s_InterruptParameters.
+                                                       ui_Write].
+                            ul_OldInterruptMask = 0x1000UL << b_TorCounterCpt;
+
+                            devpriv->
+                            s_InterruptParameters.
+                            s_FIFOInterruptParameters [devpriv->
+                                                       s_InterruptParameters.
+                                                       ui_Write].
+                            b_OldModuleMask = 1 << b_ModuleCpt;
+
+                            devpriv->
+                            s_InterruptParameters.
+                            s_FIFOInterruptParameters [devpriv->
+                                                       s_InterruptParameters.
+                                                       ui_Write].
+                            ul_OldCounterLatchValue = ul_LatchRegisterValue;
+
+                            devpriv->
+                            s_InterruptParameters.
+                            ul_InterruptOccur ++;
+
+                            
+                            /****************************/
+                            /* Increment the write FIFO */
+                            /****************************/
+
+                            devpriv->
+                            s_InterruptParameters.
+                            ui_Write = (devpriv->
+                                        s_InterruptParameters.
+                                        ui_Write + 1) % APCI1710_SAVE_INTERRUPT;
+
+                            b_InterruptFlag = 1;
+
+       
+                                  /**********************/
+                                  /* Call user function */
+                                  /**********************/
+
+                            //Send a signal to from kernel to user space
+                            send_sig(SIGIO,devpriv->tsk_Current,0); 
+                            } // if (ul_StatusRegister & 0x1)
+                         } // if (APCI1710_ENABLE)
+                      } // for (b_TorCounterCpt == 0; b_TorCounterCpt < 0; b_TorCounterCpt ++)
+                   } // Tor counter
+
+
+
+
+                /***********************/
+                /* Test if chronometer */
+                /***********************/
+
+                if ((devpriv->
+                     s_BoardInfos.
+                     dw_MolduleConfiguration [b_ModuleCpt] & 0xFFFF0000UL) == APCI1710_CHRONOMETER)
+                   {
+                    
+                       //printk("APCI1710 Chrono Interrupt\n");
+                   /*****************************/
+                   /* Read the interrupt status */
+                   /*****************************/
+
+                   
+                     ul_InterruptLatchReg=inl(devpriv->s_BoardInfos.
+                              ui_Address + 12 + (64 * b_ModuleCpt));
+
+                   /***************************/
+                   /* Test if interrupt occur */
+                   /***************************/
+
+                   if ((ul_InterruptLatchReg & 0x8) == 0x8)
+                      {
+                      /****************************/
+                      /* Clear the interrupt flag */
+                      /****************************/
+
+                     
+                               outl(0,devpriv->s_BoardInfos.
+                                  ui_Address + 32 + (64 * b_ModuleCpt));
+
+                      /***************************/
+                      /* Test if continuous mode */
+                      /***************************/
+
+                      if (ps_ModuleInfo->
+                          s_ChronoModuleInfo.
+                          b_CycleMode == APCI1710_ENABLE)
+                         {
+                         /********************/
+                         /* Clear the status */
+                         /********************/
+
+                         
+                       outl(0,devpriv->s_BoardInfos.
+                                     ui_Address + 36 + (64 * b_ModuleCpt));
+                         }
+
+                      /*************************/
+                      /* Read the timing value */
+                      /*************************/
+
+                      
+                               ul_LatchRegisterValue=inl(devpriv->s_BoardInfos.
+                                 ui_Address + 4 + (64 * b_ModuleCpt));
+
+                      /*****************************/
+                      /* Test if interrupt enabled */
+                      /*****************************/
+
+                      if (ps_ModuleInfo->
+                          s_ChronoModuleInfo.
+                          b_InterruptMask)
+                         {
+                         devpriv->
+                         s_InterruptParameters.
+                         s_FIFOInterruptParameters [devpriv->
+                                                    s_InterruptParameters.
+                                                    ui_Write].
+                         ul_OldInterruptMask = 0x80;
+
+                         devpriv->
+                         s_InterruptParameters.
+                         s_FIFOInterruptParameters [devpriv->
+                                                    s_InterruptParameters.
+                                                    ui_Write].
+                         b_OldModuleMask = 1 << b_ModuleCpt;
+
+                         devpriv->
+                         s_InterruptParameters.
+                         s_FIFOInterruptParameters [devpriv->
+                                                    s_InterruptParameters.
+                                                    ui_Write].
+                         ul_OldCounterLatchValue = ul_LatchRegisterValue;
+
+                         devpriv->
+                         s_InterruptParameters.
+                         ul_InterruptOccur ++;
+
+                         /****************************/
+                         /* Increment the write FIFO */
+                      /****************************/
+
+                         devpriv->
+                         s_InterruptParameters.
+                         ui_Write = (devpriv->
+                                     s_InterruptParameters.
+                                     ui_Write + 1) % APCI1710_SAVE_INTERRUPT;
+
+                         b_InterruptFlag = 1;
+
+                         
+                           
+                               /**********************/
+                               /* Call user function */
+                               /**********************/
+                               //Send a signal to from kernel to user space
+                            send_sig(SIGIO,devpriv->tsk_Current,0); 
+                               
+                         }
+                  }
+                } // Chronometer
+
+
+
+                /*************************/
+                /* Test if pulse encoder */
+                /*************************/
+
+                if ((devpriv->
+                     s_BoardInfos.
+                     dw_MolduleConfiguration [b_ModuleCpt] & 0xFFFF0000UL) == APCI1710_PULSE_ENCODER)
+                   {
+                   /****************************/
+                   /* Read the status register */
+                   /****************************/
+
+                   
+                       ul_StatusRegister=inl(devpriv->s_BoardInfos.
+                              ui_Address + 20 + (64 * b_ModuleCpt));
+
+                   if (ul_StatusRegister & 0xF)
+                      {
+                      for (b_PulseIncoderCpt = 0; b_PulseIncoderCpt < 4; b_PulseIncoderCpt ++)
+                         {
+                         /*************************************/
+                         /* Test if pulse encoder initialised */
+                         /*************************************/
+
+                         if ((ps_ModuleInfo->
+                              s_PulseEncoderModuleInfo.
+                              s_PulseEncoderInfo [b_PulseIncoderCpt].
+                              b_PulseEncoderInit == 1) &&
+                             (((ps_ModuleInfo->
+                                s_PulseEncoderModuleInfo.
+                                dw_SetRegister >> b_PulseIncoderCpt) & 1) == 1) &&
+                             (((ul_StatusRegister >> (b_PulseIncoderCpt)) & 1) == 1))
+                            {
+                            devpriv->
+                            s_InterruptParameters.
+                            s_FIFOInterruptParameters [devpriv->
+                                                       s_InterruptParameters.
+                                                       ui_Write].
+                            ul_OldInterruptMask = 0x100UL << b_PulseIncoderCpt;
+
+                            devpriv->
+                            s_InterruptParameters.
+                            s_FIFOInterruptParameters [devpriv->
+                                                       s_InterruptParameters.
+                                                       ui_Write].
+                            b_OldModuleMask = 1 << b_ModuleCpt;
+
+                            devpriv->
+                            s_InterruptParameters.
+                            s_FIFOInterruptParameters [devpriv->
+                                                       s_InterruptParameters.
+                                                       ui_Write].
+                            ul_OldCounterLatchValue = ul_LatchRegisterValue;
+
+                            devpriv->
+                            s_InterruptParameters.
+                            ul_InterruptOccur ++;
+
+                            /****************************/
+                            /* 0899/0224 to 1199/0225   */
+                            /****************************/
+                            /* Increment the write FIFO */
+                            /****************************/
+
+                           devpriv->
+                            s_InterruptParameters.
+                            ui_Write = (devpriv->
+                                        s_InterruptParameters.
+                                        ui_Write + 1) % APCI1710_SAVE_INTERRUPT;
+
+                            b_InterruptFlag = 1;
+                           
+                                  /**********************/
+                                  /* Call user function */
+                                  /**********************/
+                            //Send a signal to from kernel to user space
+                            send_sig(SIGIO,devpriv->tsk_Current,0); 
+                                  
+                
+                            }
+                               }
+                      }
+                   }//pulse encoder
+
+          }
+  return ; 
+
+}
+
index 6d2f9409b8edb7e12f4806873a4b2fa1f72ca627..e7328616a35675b9e7e5764e5c24210d137176ad 100644 (file)
-/**\r
-@verbatim\r
-\r
-Copyright (C) 2004,2005  ADDI-DATA GmbH for the source code of this module. \r
-        \r
-        ADDI-DATA GmbH \r
-        Dieselstrasse 3 \r
-        D-77833 Ottersweier \r
-        Tel: +19(0)7223/9493-0 \r
-        Fax: +49(0)7223/9493-92 \r
-        http://www.addi-data-com \r
-        info@addi-data.com \r
-\r
-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.\r
-\r
-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.\r
-\r
-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 USA\r
-\r
-You shoud also find the complete GPL in the COPYING file accompanying this source code.\r
-\r
-@endverbatim\r
-*/\r
-\r
-\r
-\r
-\r
-#define COMEDI_SUBD_TTLIO                              11  /* Digital Input Output But TTL */\r
-#define COMEDI_SUBD_PWM                                        12  /* Pulse width Measurement */\r
-#define COMEDI_SUBD_SSI                                        13  /* Synchronous serial interface */\r
-#define COMEDI_SUBD_TOR                                        14  /* Tor counter */\r
-#define COMEDI_SUBD_CHRONO              15  /* Chrono meter*/\r
-#define COMEDI_SUBD_PULSEENCODER        16  /* Pulse Encoder INP CPT*/\r
-#define COMEDI_SUBD_INCREMENTALCOUNTER  17  /* Incremental Counter */\r
-\r
-\r
-   #define INT           int\r
-   #define UINT          unsigned int\r
-   #define BYTE          unsigned char\r
-   #define CHAR          char\r
-   #define LONG          long\r
-   #define ULONG         unsigned long\r
-   #define VOID          void\r
-   #define PINT          int *\r
-   #define PUINT         unsigned int *\r
-   #define PBYTE         unsigned char *\r
-   #define PCHAR         char *\r
-   #define PLONG         long *\r
-   #define PULONG        unsigned long *\r
-   #define DWORD         unsigned long\r
-   #define WORD          unsigned short\r
-\r
-   #define      APCI1710_BOARD_NAME                      "apci1710"\r
-   #define      APCI1710_BOARD_VENDOR_ID         0x10E8\r
-   #define      APCI1710_BOARD_DEVICE_ID         0x818F\r
-   #define      APCI1710_ADDRESS_RANGE        256\r
-   #define      APCI1710_CONFIG_ADDRESS_RANGE 8\r
-   #define      APCI1710_INCREMENTAL_COUNTER  0x53430000UL\r
-   #define      APCI1710_SSI_COUNTER          0x53490000UL\r
-   #define      APCI1710_TTL_IO               0x544C0000UL\r
-   #define      APCI1710_DIGITAL_IO           0x44490000UL\r
-   #define      APCI1710_82X54_TIMER          0x49430000UL\r
-   #define      APCI1710_CHRONOMETER          0x43480000UL\r
-   #define      APCI1710_PULSE_ENCODER       0x495A0000UL\r
-   #define      APCI1710_TOR_COUNTER         0x544F0000UL\r
-   #define      APCI1710_PWM                 0x50570000UL\r
-   #define      APCI1710_ETM                 0x45540000UL\r
-   #define      APCI1710_CDA                 0x43440000UL\r
-   #define      APCI1710_DISABLE              0\r
-   #define      APCI1710_ENABLE               1\r
-   #define      APCI1710_SYNCHRONOUS_MODE     1\r
-   #define      APCI1710_ASYNCHRONOUS_MODE    0\r
-\r
-\r
-//MODULE INFO STRUCTURE\r
-\r
-\r
-comedi_lrange range_apci1710_ttl={ 4, {\r
-               BIP_RANGE(10),\r
-               BIP_RANGE(5),\r
-               BIP_RANGE(2),\r
-               BIP_RANGE(1)            \r
-       }\r
-};\r
-\r
-\r
-\r
-comedi_lrange range_apci1710_ssi={ 4, {\r
-               BIP_RANGE(10),\r
-               BIP_RANGE(5),\r
-               BIP_RANGE(2),\r
-               BIP_RANGE(1)            \r
-       }\r
-};\r
-\r
-comedi_lrange range_apci1710_inccpt={ 4, {\r
-               BIP_RANGE(10),\r
-               BIP_RANGE(5),\r
-               BIP_RANGE(2),\r
-               BIP_RANGE(1)            \r
-       }\r
-};\r
+/**
+@verbatim
+
+Copyright (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 USA
+
+You shoud also find the complete GPL in the COPYING file accompanying this source code.
+
+@endverbatim
+*/
+
+
+
+
+#define COMEDI_SUBD_TTLIO                              11  /* Digital Input Output But TTL */
+#define COMEDI_SUBD_PWM                                        12  /* Pulse width Measurement */
+#define COMEDI_SUBD_SSI                                        13  /* Synchronous serial interface */
+#define COMEDI_SUBD_TOR                                        14  /* Tor counter */
+#define COMEDI_SUBD_CHRONO              15  /* Chrono meter*/
+#define COMEDI_SUBD_PULSEENCODER        16  /* Pulse Encoder INP CPT*/
+#define COMEDI_SUBD_INCREMENTALCOUNTER  17  /* Incremental Counter */
+
+
+   #define INT           int
+   #define UINT          unsigned int
+   #define BYTE          unsigned char
+   #define CHAR          char
+   #define LONG          long
+   #define ULONG         unsigned long
+   #define VOID          void
+   #define PINT          int *
+   #define PUINT         unsigned int *
+   #define PBYTE         unsigned char *
+   #define PCHAR         char *
+   #define PLONG         long *
+   #define PULONG        unsigned long *
+   #define DWORD         unsigned long
+   #define WORD          unsigned short
+
+   #define      APCI1710_BOARD_NAME                      "apci1710"
+   #define      APCI1710_BOARD_VENDOR_ID         0x10E8
+   #define      APCI1710_BOARD_DEVICE_ID         0x818F
+   #define      APCI1710_ADDRESS_RANGE        256
+   #define      APCI1710_CONFIG_ADDRESS_RANGE 8
+   #define      APCI1710_INCREMENTAL_COUNTER  0x53430000UL
+   #define      APCI1710_SSI_COUNTER          0x53490000UL
+   #define      APCI1710_TTL_IO               0x544C0000UL
+   #define      APCI1710_DIGITAL_IO           0x44490000UL
+   #define      APCI1710_82X54_TIMER          0x49430000UL
+   #define      APCI1710_CHRONOMETER          0x43480000UL
+   #define      APCI1710_PULSE_ENCODER       0x495A0000UL
+   #define      APCI1710_TOR_COUNTER         0x544F0000UL
+   #define      APCI1710_PWM                 0x50570000UL
+   #define      APCI1710_ETM                 0x45540000UL
+   #define      APCI1710_CDA                 0x43440000UL
+   #define      APCI1710_DISABLE              0
+   #define      APCI1710_ENABLE               1
+   #define      APCI1710_SYNCHRONOUS_MODE     1
+   #define      APCI1710_ASYNCHRONOUS_MODE    0
+
+
+//MODULE INFO STRUCTURE
+
+
+comedi_lrange range_apci1710_ttl={ 4, {
+               BIP_RANGE(10),
+               BIP_RANGE(5),
+               BIP_RANGE(2),
+               BIP_RANGE(1)            
+       }
+};
+
+
+
+comedi_lrange range_apci1710_ssi={ 4, {
+               BIP_RANGE(10),
+               BIP_RANGE(5),
+               BIP_RANGE(2),
+               BIP_RANGE(1)            
+       }
+};
+
+comedi_lrange range_apci1710_inccpt={ 4, {
+               BIP_RANGE(10),
+               BIP_RANGE(5),
+               BIP_RANGE(2),
+               BIP_RANGE(1)            
+       }
+};
index d6985372fe48b0d1bf9fcce697a0102b9750d885..7bec2903170862b88b64759627768ac634f5382c 100644 (file)
-/**\r
-@verbatim\r
-\r
-Copyright (C) 2004,2005  ADDI-DATA GmbH for the source code of this module. \r
-        \r
-        ADDI-DATA GmbH \r
-        Dieselstrasse 3 \r
-        D-77833 Ottersweier \r
-        Tel: +19(0)7223/9493-0 \r
-        Fax: +49(0)7223/9493-92 \r
-        http://www.addi-data-com \r
-        info@addi-data.com \r
-\r
-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.\r
-\r
-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.\r
-\r
-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 USA\r
-\r
-You shoud also find the complete GPL in the COPYING file accompanying this source code.\r
-\r
-@endverbatim\r
-*/\r
-/*\r
-    \r
-  +-----------------------------------------------------------------------+\r
-  | (C) ADDI-DATA GmbH          Dieselstraße 3       D-77833 Ottersweier  |\r
-  +-----------------------------------------------------------------------+\r
-  | Tel : +49 (0) 7223/9493-0     | email    : info@addi-data.com         |\r
-  | Fax : +49 (0) 7223/9493-92    | Internet : http://www.addi-data.com   |\r
-  +-------------------------------+---------------------------------------+\r
-  | Project     : APCI-035        | Compiler   : GCC                      |\r
-  | Module name : hwdrv_apci035.c | Version    : 2.96                     |\r
-  +-------------------------------+---------------------------------------+\r
-  | Project manager: Eric Stolz   | Date       :  02/12/2002              |\r
-  +-------------------------------+---------------------------------------+\r
-  | Description :   Hardware Layer Acces For APCI-035                     |\r
-  +-----------------------------------------------------------------------+\r
-  |                             UPDATES                                   |\r
-  +----------+-----------+------------------------------------------------+\r
-  |   Date   |   Author  |          Description of updates                |\r
-  +----------+-----------+------------------------------------------------+\r
-  |          |           |                                                |\r
-  |          |           |                                                |\r
-  |          |           |                                                |\r
-  +----------+-----------+------------------------------------------------+\r
-*/\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-|                               Included files                               |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-#include "hwdrv_apci035.h"\r
-INT i_WatchdogNbr=0;\r
-INT i_Temp=0;\r
-INT i_Flag=1;\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function   Name   : int i_APCI035_ConfigTimerWatchdog                      |\r
-|                        (comedi_device *dev,comedi_subdevice *s,               | \r
-|                      comedi_insn *insn,lsampl_t *data)                     |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Configures The Timer , Counter or Watchdog             |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : comedi_device *dev : Driver handle                     |\r
-|                     UINT *data         : Data Pointer contains             |\r
-|                                          configuration parameters as below |\r
-|                                                                            | \r
-|                                        data[0]            : 0 Configure As Timer      |      \r
-|                                                                                 1 Configure As Watchdog   | \r
-                              data[1]            : Watchdog number                                         \r
-|                                        data[2]            : Time base Unit            |\r
-|                                        data[3]                        : Reload Value                      | \r
-                              data[4]            : External Trigger          |\r
-                                                   1:Enable\r
-                                                   0:Disable                  \r
-                              data[5]            :External Trigger Level\r
-                                                  00 Trigger Disabled\r
-                                                  01 Trigger Enabled (Low level)\r
-                                                  10 Trigger Enabled (High Level)\r
-                                                  11 Trigger Enabled (High/Low level)   \r
-                              data[6]            : External Gate            |\r
-                                                   1:Enable\r
-                                                   0:Disable        \r
-                              data[7]            : External Gate level\r
-                                                  00 Gate Disabled\r
-                                                  01 Gate Enabled (Low level)\r
-                                                  10 Gate Enabled (High Level)\r
-                              data[8]            :Warning Relay\r
-                                                  1: ENABLE\r
-                                                  0: DISABLE  \r
-                              data[9]            :Warning Delay available\r
-                              data[10]           :Warning Relay Time unit\r
-                              data[11]           :Warning Relay Time Reload value\r
-                              data[12]           :Reset Relay\r
-                                                  1 : ENABLE\r
-                                                  0 : DISABLE  \r
-                              data[13]           :Interrupt\r
-                                                  1 : ENABLE\r
-                                                  0 : DISABLE  \r
-\r
-|                                      \r
-+----------------------------------------------------------------------------+\r
-| Output Parameters :  --                                                                                                       |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      : TRUE  : No error occur                                 |\r
-|                          : FALSE : Error occur. Return the error          |\r
-|                                                                               |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-INT i_APCI035_ConfigTimerWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data)\r
-{\r
-UINT ui_Status=0;\r
-UINT ui_Command=0;\r
-UINT ui_Mode=0;\r
-i_Temp=0;\r
-devpriv->tsk_Current=current;\r
-devpriv->b_TimerSelectMode=data[0];\r
-i_WatchdogNbr=data[1];\r
-if(data[0]==0)\r
-   {\r
-   ui_Mode=2;\r
-   }\r
-else\r
-   {\r
-   ui_Mode=0;\r
-   }  \r
-//ui_Command = inl(devpriv->iobase+((i_WatchdogNbr-1)*32)+12);\r
-ui_Command=0;\r
-//ui_Command = ui_Command & 0xFFFFF9FEUL;\r
-outl(ui_Command,devpriv->iobase+((i_WatchdogNbr-1)*32)+12);\r
-ui_Command=0;\r
-ui_Command = inl(devpriv->iobase+((i_WatchdogNbr-1)*32)+12);\r
-/************************/\r
-/* Set the reload value */\r
-/************************/\r
-outl( data[3],devpriv->iobase+((i_WatchdogNbr-1)*32) + 4);\r
-/*********************/\r
-/* Set the time unit */\r
-/*********************/ \r
-outl(data[2],devpriv->iobase+((i_WatchdogNbr-1)*32) + 8);\r
-if (data[0] == ADDIDATA_TIMER)\r
-   {\r
-                 \r
-\r
-                 /******************************/\r
-                 /* Set the mode :             */\r
-                 /* - Disable the hardware     */\r
-                 /* - Disable the counter mode */\r
-                 /* - Disable the warning      */\r
-                 /* - Disable the reset        */\r
-                 /* - Enable the timer mode    */\r
-                 /* - Set the timer mode       */\r
-                 /******************************/\r
-                \r
-\r
-    ui_Command = (ui_Command & 0xFFF719E2UL) | ui_Mode << 13UL | 0x10UL;\r
-\r
-   }//if (data[0] == ADDIDATA_TIMER)\r
- else\r
-   {\r
-      if(data[0]==ADDIDATA_WATCHDOG)\r
-         {           \r
-\r
-                 /******************************/\r
-                 /* Set the mode :             */\r
-                 /* - Disable the hardware     */\r
-                 /* - Disable the counter mode */\r
-                 /* - Disable the warning      */\r
-                 /* - Disable the reset        */\r
-                 /* - Disable the timer mode   */\r
-                 /******************************/\r
-                 \r
-\r
-            ui_Command = ui_Command & 0xFFF819E2UL;\r
-\r
-         } \r
-      else \r
-         {\r
-         printk("\n The parameter for Timer/watchdog selection is in error\n");\r
-         return -EINVAL;\r
-         }\r
-    }\r
-outl(ui_Command,devpriv->iobase+((i_WatchdogNbr-1)*32)+12);\r
-ui_Command=0;\r
-ui_Command = inl(devpriv->iobase+((i_WatchdogNbr-1)*32)+12);\r
-/********************************/\r
-/* Disable the hardware trigger */\r
-/********************************/\r
-ui_Command = ui_Command & 0xFFFFF89FUL;  \r
- if (data[4] == ADDIDATA_ENABLE)\r
-    {\r
-    /**********************************/\r
-    /* Set the hardware trigger level */\r
-    /**********************************/          \r
-     ui_Command = ui_Command |  ( data[5] << 5);\r
-    }           \r
-outl(ui_Command,devpriv->iobase+((i_WatchdogNbr-1)*32)+12);\r
-ui_Command=0;\r
-ui_Command = inl(devpriv->iobase+((i_WatchdogNbr-1)*32)+12); \r
-/*****************************/\r
-/* Disable the hardware gate */\r
-/*****************************/   \r
-ui_Command = ui_Command & 0xFFFFF87FUL; \r
-if (data[6] == ADDIDATA_ENABLE)\r
-   {\r
-/*******************************/\r
-/* Set the hardware gate level */\r
-/*******************************/             \r
-   ui_Command = ui_Command |( data[7] << 7);\r
-   }\r
-outl(ui_Command,devpriv->iobase+((i_WatchdogNbr-1)*32)+12);           \r
-ui_Command=0;\r
-ui_Command = inl(devpriv->iobase+((i_WatchdogNbr-1)*32)+12);             \r
-/*******************************/\r
-/* Disable the hardware output */\r
-/*******************************/\r
-ui_Command = ui_Command & 0xFFFFF9FBUL;           \r
-/*********************************/\r
-/* Set the hardware output level */\r
-/*********************************/\r
-ui_Command = ui_Command |( data[8] << 2);          \r
-outl(ui_Command,devpriv->iobase+((i_WatchdogNbr-1)*32)+12); \r
-if(data[9]==ADDIDATA_ENABLE)  \r
-   { \r
-   /************************/\r
-   /* Set the reload value */\r
-   /************************/         \r
-   outl (data[11],devpriv->iobase+((i_WatchdogNbr-1)*32) + 24);\r
-   /**********************/\r
-   /* Set the time unite */\r
-   /**********************/ \r
-   outl(data[10],devpriv->iobase+((i_WatchdogNbr-1)*32)+ 28);\r
-   }\r
-\r
-    ui_Command=0;\r
-    ui_Command = inl(devpriv->iobase+((i_WatchdogNbr-1)*32)+12);              \r
- /*******************************/\r
- /* Disable the hardware output */\r
- /*******************************/         \r
-   ui_Command = ui_Command & 0xFFFFF9F7UL;          \r
-   /*********************************/\r
-   /* Set the hardware output level */\r
-   /*********************************/\r
- ui_Command = ui_Command |( data[12] << 3);           \r
- outl(ui_Command,devpriv->iobase+((i_WatchdogNbr-1)*32)+12); \r
- /*************************************/\r
- /**  Enable the watchdog interrupt  **/\r
- /*************************************/ \r
-ui_Command=0;\r
-ui_Command = inl(devpriv->iobase+((i_WatchdogNbr-1)*32)+12);  \r
-/*******************************/\r
-/* Set the interrupt selection */\r
-/*******************************/\r
-ui_Status =inl(devpriv->iobase+((i_WatchdogNbr-1)*32) + 16);\r
-\r
-ui_Command = (ui_Command & 0xFFFFF9FDUL) |  ( data[13] << 1);\r
-outl(ui_Command,devpriv->iobase+((i_WatchdogNbr-1)*32)+12); \r
-\r
-return insn->n;\r
-}\r
-\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function   Name   : int i_APCI035_StartStopWriteTimerWatchdog              |\r
-|                        (comedi_device *dev,comedi_subdevice *s,               | \r
-|                      comedi_insn *insn,lsampl_t *data)                     |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Start / Stop The Selected Timer , or Watchdog  |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : comedi_device *dev : Driver handle                     |\r
-|                     UINT *data         : Data Pointer contains             |\r
-|                                          configuration parameters as below |\r
-|                                                                                       |\r
-|                                        data[0] : 0 - Stop Selected Timer/Watchdog     |\r
-|                                                  1 - Start Selected Timer/Watchdog    |\r
-|                                                  2 - Trigger Selected Timer/Watchdog  |\r
-|                                                  3 - Stop All Timer/Watchdog          |\r
-|                                                  4 - Start All Timer/Watchdog         |\r
-|                                                  5 - Trigger All Timer/Watchdog       |\r
-|                                                                                       |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters :  --                                                                                                       |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      : TRUE  : No error occur                                 |\r
-|                          : FALSE : Error occur. Return the error                      | \r
-|                                                                                       |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-INT i_APCI035_StartStopWriteTimerWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data)\r
-{\r
-   UINT  ui_Command = 0; \r
-   INT i_Count=0;\r
-      if  (data[0]==1) \r
-         { \r
-         ui_Command = inl(devpriv->iobase+((i_WatchdogNbr-1)*32)+12);\r
-         /**********************/\r
-         /* Start the hardware */\r
-         /**********************/\r
-         ui_Command = (ui_Command & 0xFFFFF9FFUL) | 0x1UL;\r
-         outl(ui_Command,devpriv->iobase+((i_WatchdogNbr-1)*32)+12); \r
-         } // if  (data[0]==1)\r
-      if(data[0]==2)\r
-         {\r
-         ui_Command = inl(devpriv->iobase+((i_WatchdogNbr-1)*32)+12); \r
-         /***************************/\r
-         /* Set the trigger command */\r
-         /***************************/\r
-         ui_Command = (ui_Command & 0xFFFFF9FFUL) | 0x200UL;\r
-         outl(ui_Command,devpriv->iobase+((i_WatchdogNbr-1)*32)+12);   \r
-         } \r
-           \r
-      if (data[0]==0) //Stop The Watchdog \r
-         {\r
-         //Stop The Watchdog\r
-         ui_Command=0;\r
-         //ui_Command = inl(devpriv->iobase+((i_WatchdogNbr-1)*32)+12); \r
-         //ui_Command = ui_Command & 0xFFFFF9FEUL;\r
-         outl(ui_Command,devpriv->iobase+((i_WatchdogNbr-1)*32)+12);   \r
-         } //  if (data[1]==0)\r
-      if(data[0]==3)//stop all Watchdogs\r
-        {\r
-         ui_Command=0; \r
-         for(i_Count=1;i_Count<=4;i_Count++)\r
-            {\r
-            if(devpriv->b_TimerSelectMode==ADDIDATA_WATCHDOG)\r
-              {\r
-               ui_Command=0x2UL;\r
-              }\r
-            else\r
-              {\r
-              ui_Command = 0x10UL; \r
-              } \r
-               i_WatchdogNbr=i_Count;\r
-               outl(ui_Command,devpriv->iobase+((i_WatchdogNbr-1)*32) + 0);\r
-             }\r
-\r
-         } \r
-      if(data[0]==4)//start all Watchdogs\r
-        {\r
-         ui_Command = 0;\r
-         for(i_Count=1;i_Count<=4;i_Count++)\r
-            {\r
-            if(devpriv->b_TimerSelectMode==ADDIDATA_WATCHDOG)\r
-              {\r
-               ui_Command = 0x1UL;\r
-              }\r
-            else\r
-               {\r
-               ui_Command = 0x8UL;\r
-               } \r
-               i_WatchdogNbr=i_Count;\r
-              outl(ui_Command,devpriv->iobase+((i_WatchdogNbr-1)*32) + 0);             \r
-             } \r
-          }\r
-      if(data[0]==5)//trigger all Watchdogs\r
-        {\r
-         ui_Command =0;\r
-         for(i_Count=1;i_Count<=4;i_Count++)\r
-            {\r
-            if(devpriv->b_TimerSelectMode==ADDIDATA_WATCHDOG)\r
-               {\r
-               ui_Command=0x4UL;\r
-               }\r
-            else\r
-              {\r
-              ui_Command = 0x20UL; \r
-              } \r
-   \r
-          i_WatchdogNbr=i_Count;\r
-             outl(ui_Command,devpriv->iobase+((i_WatchdogNbr-1)*32) + 0);\r
-           }\r
-         i_Temp=1;\r
-         }\r
-   return insn->n;\r
-}\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function   Name   : int i_APCI035_ReadTimerWatchdog                        |\r
-|                        (comedi_device *dev,comedi_subdevice *s,               | \r
-|                      comedi_insn *insn,lsampl_t *data)                     |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Read The Selected Timer , Counter or Watchdog          |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : comedi_device *dev : Driver handle                     |\r
-|                     UINT *data         : Data Pointer contains             |\r
-|                                          configuration parameters as below |\r
-|                                                                            | \r
-|                                                                                                                                       |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters :  data[0]            : software trigger status                                                                                            \r
-              data[1]            : hardware trigger status  \r
-|                              data[2]            : Software clear status      \r
-                        data[3]            : Overflow status                                                                                            \r
-                     data[4]            : Timer actual value   \r
-                       \r
-\r
-+----------------------------------------------------------------------------+\r
-| Return Value      : TRUE  : No error occur                                 |\r
-|                          : FALSE : Error occur. Return the error          |\r
-|                                                                               |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-INT i_APCI035_ReadTimerWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data)\r
-{\r
-UINT ui_Status = 0;   // Status register \r
- i_WatchdogNbr=insn->unused[0]; \r
-              /******************/\r
-              /* Get the status */\r
-              /******************/  \r
-      ui_Status =inl(devpriv->iobase+((i_WatchdogNbr-1)*32) + 16);\r
-      /***********************************/\r
-      /* Get the software trigger status */\r
-      /***********************************/\r
-      data[0] = ((ui_Status >> 1) & 1); \r
-      /***********************************/\r
-      /* Get the hardware trigger status */\r
-      /***********************************/\r
-      data[1] =  ((ui_Status >> 2) & 1); \r
-      /*********************************/\r
-      /* Get the software clear status */\r
-      /*********************************/ \r
-      data[2] = ((ui_Status >> 3) & 1);\r
-      /***************************/\r
-      /* Get the overflow status */\r
-      /***************************/\r
-      data[3] = ((ui_Status >> 0) & 1);\r
-    if  (devpriv->b_TimerSelectMode==ADDIDATA_TIMER) \r
-      {\r
-      data[4]=inl(devpriv->iobase+((i_WatchdogNbr-1)*32) + 0);\r
-      \r
-      } //  if  (devpriv->b_TimerSelectMode==ADDIDATA_TIMER) \r
-  \r
-      \r
-   return insn->n;\r
-}\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function   Name   : INT i_APCI035_ConfigAnalogInput                        |\r
-|                        (comedi_device *dev,comedi_subdevice *s,               | \r
-|                      comedi_insn *insn,lsampl_t *data)                     |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Configures The Analog Input Subdevice                  |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : comedi_device *dev      : Driver handle                |\r
-|                     comedi_subdevice *s     : Subdevice Pointer            |  \r
-|                     comedi_insn *insn       : Insn Structure Pointer       |  \r
-|                     lsampl_t *data          : Data Pointer contains        |\r
-|                                          configuration parameters as below |\r
-|                     data[0]                  : Warning delay value                                                              \r
-|                                                                            |         \r
-+----------------------------------------------------------------------------+\r
-| Output Parameters :  --                                                                                                       |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      : TRUE  : No error occur                                 |\r
-|                          : FALSE : Error occur. Return the error          |\r
-|                                                                               |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-INT i_APCI035_ConfigAnalogInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) \r
-{\r
-devpriv->tsk_Current=current;\r
-outl(0x200 | 0, devpriv->iobase+128 + 0x4);\r
-outl(0, devpriv->iobase+128 + 0);\r
-/********************************/\r
-/* Initialise the warning value */\r
-/********************************/\r
-outl(0x300 | 0, devpriv->iobase+128 + 0x4);\r
-outl((data[0] << 8), devpriv->iobase+128 + 0);\r
-outl(0x200000UL , devpriv->iobase+128 + 12);\r
-\r
-return insn->n;\r
-} \r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function   Name   : int i_APCI035_ReadAnalogInput                          |\r
-|                                (comedi_device *dev,comedi_subdevice *s,       | \r
-|                     comedi_insn *insn,lsampl_t *data)                      |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Read  value  of the selected channel                              |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : comedi_device *dev      : Driver handle                |\r
-|                     UINT ui_NoOfChannels    : No Of Channels To read       |\r
-|                     UINT *data              : Data Pointer to read status  |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters :  --                                                                                                       |\r
-|                                data[0]  : Digital Value Of Input              |\r
-|                                                                               |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      : TRUE  : No error occur                                 |\r
-|                          : FALSE : Error occur. Return the error          |\r
-|                                                                               |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-INT i_APCI035_ReadAnalogInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) \r
-{ \r
-UINT ui_CommandRegister=0;\r
-/******************/\r
-/*  Set the start */\r
-/******************/\r
-ui_CommandRegister =0x80000;  \r
- /******************************/\r
- /* Write the command register */\r
- /******************************/\r
-outl(ui_CommandRegister, devpriv->iobase+128 + 8);\r
-              \r
-/***************************************/\r
-/* Read the digital value of the input */\r
-/***************************************/\r
-data[0] = inl (devpriv->iobase+ 128 + 28);                           \r
-return insn->n;\r
-}\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function   Name   :  int i_APCI035_Reset(comedi_device *dev)                      |\r
-|                                                                                               |\r
-+----------------------------------------------------------------------------+\r
-| Task              :Resets the registers of the card                        |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  :                                                        |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters :  --                                                                                                       |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      :                                                        |\r
-|                                                                                       |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-INT i_APCI035_Reset(comedi_device *dev)\r
-{\r
-INT i_Count=0;\r
-for(i_Count=1;i_Count<=4;i_Count++)\r
-    {\r
-     i_WatchdogNbr=i_Count;\r
-     outl(0x0,devpriv->iobase+((i_WatchdogNbr-1)*32) + 0);//stop all timers\r
-    }\r
-outl(0x0 , devpriv->iobase+128 + 12);//Disable the warning delay\r
-\r
- return 0;\r
-}\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function   Name   : static void v_APCI035_Interrupt                                       |\r
-|                                        (int irq , void *d, struct pt_regs *regs)      |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Interrupt processing Routine                           |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : int irq                 : irq number                   |\r
-|                     void *d                 : void pointer                 |\r
-|                     struct pt_regs *regs    : structure pointer            |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters :  --                                                                                                       |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      : TRUE  : No error occur                                 |\r
-|                          : FALSE : Error occur. Return the error          |\r
-|                                                                               |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-static void v_APCI035_Interrupt(int irq, void *d, struct pt_regs *regs) \r
-{      \r
-   comedi_device *dev = d;\r
-   UINT ui_StatusRegister1 = 0;\r
-   UINT ui_StatusRegister2=0;\r
-   UINT ui_ReadCommand =0;\r
-   UINT ui_ChannelNumber=0;\r
-   UINT ui_DigitalTemperature=0;\r
-   if(i_Temp==1)\r
-       {\r
-        i_WatchdogNbr=i_Flag;  \r
-        i_Flag=i_Flag+1;  \r
-       }     \r
-  /**************************************/\r
-  /* Read the interrupt status register of temperature Warning */\r
-  /**************************************/\r
-   ui_StatusRegister1 = inl(devpriv->iobase+128 + 16);  \r
-  /**************************************/\r
-   /* Read the interrupt status register for Watchdog/timer */ \r
-   /**************************************/\r
-  \r
-   ui_StatusRegister2 = inl (devpriv->iobase+((i_WatchdogNbr-1)*32) + 20);\r
-   \r
-   if ((((ui_StatusRegister1 ) & 0x8) == 0x8))//Test if warning relay interrupt\r
-        {\r
-        /**********************************/\r
-        /* Disable the temperature warning */\r
-        /**********************************/\r
-         ui_ReadCommand = inl (devpriv->iobase+128 + 12);\r
-         ui_ReadCommand = ui_ReadCommand & 0xFFDF0000UL;\r
-         outl(ui_ReadCommand , devpriv->iobase+128 + 12);     \r
-      /***************************/\r
-      /* Read the channel number */\r
-      /***************************/   \r
-        ui_ChannelNumber  = inl(devpriv->iobase+128 + 60);\r
-        /**************************************/\r
-        /* Read the digital temperature value */\r
-        /**************************************/\r
-         ui_DigitalTemperature = inl(devpriv->iobase+128 + 60);  \r
-         send_sig(SIGIO,devpriv->tsk_Current,0); // send signal to the sample\r
-        }//if (((ui_StatusRegister1 & 0x8) == 0x8)) \r
-           \r
-   else\r
-       {\r
-       if((ui_StatusRegister2 & 0x1) == 0x1)       \r
-          {\r
-           send_sig(SIGIO,devpriv->tsk_Current,0); // send signal to the sample     \r
-          }\r
-        }//else if (((ui_StatusRegister1 & 0x8) == 0x8))       \r
-        \r
-    \r
-return;\r
-}\r
-\r
-\r
-\r
-\r
-\r
+/**
+@verbatim
+
+Copyright (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 USA
+
+You 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     : APCI-035        | Compiler   : GCC                      |
+  | Module name : hwdrv_apci035.c | Version    : 2.96                     |
+  +-------------------------------+---------------------------------------+
+  | Project manager: Eric Stolz   | Date       :  02/12/2002              |
+  +-------------------------------+---------------------------------------+
+  | Description :   Hardware Layer Acces For APCI-035                     |
+  +-----------------------------------------------------------------------+
+  |                             UPDATES                                   |
+  +----------+-----------+------------------------------------------------+
+  |   Date   |   Author  |          Description of updates                |
+  +----------+-----------+------------------------------------------------+
+  |          |           |                                                |
+  |          |           |                                                |
+  |          |           |                                                |
+  +----------+-----------+------------------------------------------------+
+*/
+
+/*
++----------------------------------------------------------------------------+
+|                               Included files                               |
++----------------------------------------------------------------------------+
+*/
+#include "hwdrv_apci035.h"
+INT i_WatchdogNbr=0;
+INT i_Temp=0;
+INT i_Flag=1;
+/*
++----------------------------------------------------------------------------+
+| Function   Name   : int i_APCI035_ConfigTimerWatchdog                      |
+|                        (comedi_device *dev,comedi_subdevice *s,               | 
+|                      comedi_insn *insn,lsampl_t *data)                     |
++----------------------------------------------------------------------------+
+| Task              : Configures The Timer , Counter or Watchdog             |
++----------------------------------------------------------------------------+
+| Input Parameters  : comedi_device *dev : Driver handle                     |
+|                     UINT *data         : Data Pointer contains             |
+|                                          configuration parameters as below |
+|                                                                            | 
+|                                        data[0]            : 0 Configure As Timer      |      
+|                                                                                 1 Configure As Watchdog   | 
+                              data[1]            : Watchdog number                                         
+|                                        data[2]            : Time base Unit            |
+|                                        data[3]                        : Reload Value                      | 
+                              data[4]            : External Trigger          |
+                                                   1:Enable
+                                                   0:Disable                  
+                              data[5]            :External Trigger Level
+                                                  00 Trigger Disabled
+                                                  01 Trigger Enabled (Low level)
+                                                  10 Trigger Enabled (High Level)
+                                                  11 Trigger Enabled (High/Low level)   
+                              data[6]            : External Gate            |
+                                                   1:Enable
+                                                   0:Disable        
+                              data[7]            : External Gate level
+                                                  00 Gate Disabled
+                                                  01 Gate Enabled (Low level)
+                                                  10 Gate Enabled (High Level)
+                              data[8]            :Warning Relay
+                                                  1: ENABLE
+                                                  0: DISABLE  
+                              data[9]            :Warning Delay available
+                              data[10]           :Warning Relay Time unit
+                              data[11]           :Warning Relay Time Reload value
+                              data[12]           :Reset Relay
+                                                  1 : ENABLE
+                                                  0 : DISABLE  
+                              data[13]           :Interrupt
+                                                  1 : ENABLE
+                                                  0 : DISABLE  
+
+|                                      
++----------------------------------------------------------------------------+
+| Output Parameters :  --                                                                                                       |
++----------------------------------------------------------------------------+
+| Return Value      : TRUE  : No error occur                                 |
+|                          : FALSE : Error occur. Return the error          |
+|                                                                               |
++----------------------------------------------------------------------------+
+*/
+INT i_APCI035_ConfigTimerWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data)
+{
+UINT ui_Status=0;
+UINT ui_Command=0;
+UINT ui_Mode=0;
+i_Temp=0;
+devpriv->tsk_Current=current;
+devpriv->b_TimerSelectMode=data[0];
+i_WatchdogNbr=data[1];
+if(data[0]==0)
+   {
+   ui_Mode=2;
+   }
+else
+   {
+   ui_Mode=0;
+   }  
+//ui_Command = inl(devpriv->iobase+((i_WatchdogNbr-1)*32)+12);
+ui_Command=0;
+//ui_Command = ui_Command & 0xFFFFF9FEUL;
+outl(ui_Command,devpriv->iobase+((i_WatchdogNbr-1)*32)+12);
+ui_Command=0;
+ui_Command = inl(devpriv->iobase+((i_WatchdogNbr-1)*32)+12);
+/************************/
+/* Set the reload value */
+/************************/
+outl( data[3],devpriv->iobase+((i_WatchdogNbr-1)*32) + 4);
+/*********************/
+/* Set the time unit */
+/*********************/ 
+outl(data[2],devpriv->iobase+((i_WatchdogNbr-1)*32) + 8);
+if (data[0] == ADDIDATA_TIMER)
+   {
+                 
+
+                 /******************************/
+                 /* Set the mode :             */
+                 /* - Disable the hardware     */
+                 /* - Disable the counter mode */
+                 /* - Disable the warning      */
+                 /* - Disable the reset        */
+                 /* - Enable the timer mode    */
+                 /* - Set the timer mode       */
+                 /******************************/
+                
+
+    ui_Command = (ui_Command & 0xFFF719E2UL) | ui_Mode << 13UL | 0x10UL;
+
+   }//if (data[0] == ADDIDATA_TIMER)
+ else
+   {
+      if(data[0]==ADDIDATA_WATCHDOG)
+         {           
+
+                 /******************************/
+                 /* Set the mode :             */
+                 /* - Disable the hardware     */
+                 /* - Disable the counter mode */
+                 /* - Disable the warning      */
+                 /* - Disable the reset        */
+                 /* - Disable the timer mode   */
+                 /******************************/
+                 
+
+            ui_Command = ui_Command & 0xFFF819E2UL;
+
+         } 
+      else 
+         {
+         printk("\n The parameter for Timer/watchdog selection is in error\n");
+         return -EINVAL;
+         }
+    }
+outl(ui_Command,devpriv->iobase+((i_WatchdogNbr-1)*32)+12);
+ui_Command=0;
+ui_Command = inl(devpriv->iobase+((i_WatchdogNbr-1)*32)+12);
+/********************************/
+/* Disable the hardware trigger */
+/********************************/
+ui_Command = ui_Command & 0xFFFFF89FUL;  
+ if (data[4] == ADDIDATA_ENABLE)
+    {
+    /**********************************/
+    /* Set the hardware trigger level */
+    /**********************************/          
+     ui_Command = ui_Command |  ( data[5] << 5);
+    }           
+outl(ui_Command,devpriv->iobase+((i_WatchdogNbr-1)*32)+12);
+ui_Command=0;
+ui_Command = inl(devpriv->iobase+((i_WatchdogNbr-1)*32)+12); 
+/*****************************/
+/* Disable the hardware gate */
+/*****************************/   
+ui_Command = ui_Command & 0xFFFFF87FUL; 
+if (data[6] == ADDIDATA_ENABLE)
+   {
+/*******************************/
+/* Set the hardware gate level */
+/*******************************/             
+   ui_Command = ui_Command |( data[7] << 7);
+   }
+outl(ui_Command,devpriv->iobase+((i_WatchdogNbr-1)*32)+12);           
+ui_Command=0;
+ui_Command = inl(devpriv->iobase+((i_WatchdogNbr-1)*32)+12);             
+/*******************************/
+/* Disable the hardware output */
+/*******************************/
+ui_Command = ui_Command & 0xFFFFF9FBUL;           
+/*********************************/
+/* Set the hardware output level */
+/*********************************/
+ui_Command = ui_Command |( data[8] << 2);          
+outl(ui_Command,devpriv->iobase+((i_WatchdogNbr-1)*32)+12); 
+if(data[9]==ADDIDATA_ENABLE)  
+   { 
+   /************************/
+   /* Set the reload value */
+   /************************/         
+   outl (data[11],devpriv->iobase+((i_WatchdogNbr-1)*32) + 24);
+   /**********************/
+   /* Set the time unite */
+   /**********************/ 
+   outl(data[10],devpriv->iobase+((i_WatchdogNbr-1)*32)+ 28);
+   }
+
+    ui_Command=0;
+    ui_Command = inl(devpriv->iobase+((i_WatchdogNbr-1)*32)+12);              
+ /*******************************/
+ /* Disable the hardware output */
+ /*******************************/         
+   ui_Command = ui_Command & 0xFFFFF9F7UL;          
+   /*********************************/
+   /* Set the hardware output level */
+   /*********************************/
+ ui_Command = ui_Command |( data[12] << 3);           
+ outl(ui_Command,devpriv->iobase+((i_WatchdogNbr-1)*32)+12); 
+ /*************************************/
+ /**  Enable the watchdog interrupt  **/
+ /*************************************/ 
+ui_Command=0;
+ui_Command = inl(devpriv->iobase+((i_WatchdogNbr-1)*32)+12);  
+/*******************************/
+/* Set the interrupt selection */
+/*******************************/
+ui_Status =inl(devpriv->iobase+((i_WatchdogNbr-1)*32) + 16);
+
+ui_Command = (ui_Command & 0xFFFFF9FDUL) |  ( data[13] << 1);
+outl(ui_Command,devpriv->iobase+((i_WatchdogNbr-1)*32)+12); 
+
+return insn->n;
+}
+
+
+/*
++----------------------------------------------------------------------------+
+| Function   Name   : int i_APCI035_StartStopWriteTimerWatchdog              |
+|                        (comedi_device *dev,comedi_subdevice *s,               | 
+|                      comedi_insn *insn,lsampl_t *data)                     |
++----------------------------------------------------------------------------+
+| Task              : Start / Stop The Selected Timer , or Watchdog  |
++----------------------------------------------------------------------------+
+| Input Parameters  : comedi_device *dev : Driver handle                     |
+|                     UINT *data         : Data Pointer contains             |
+|                                          configuration parameters as below |
+|                                                                                       |
+|                                        data[0] : 0 - Stop Selected Timer/Watchdog     |
+|                                                  1 - Start Selected Timer/Watchdog    |
+|                                                  2 - Trigger Selected Timer/Watchdog  |
+|                                                  3 - Stop All Timer/Watchdog          |
+|                                                  4 - Start All Timer/Watchdog         |
+|                                                  5 - Trigger All Timer/Watchdog       |
+|                                                                                       |
++----------------------------------------------------------------------------+
+| Output Parameters :  --                                                                                                       |
++----------------------------------------------------------------------------+
+| Return Value      : TRUE  : No error occur                                 |
+|                          : FALSE : Error occur. Return the error                      | 
+|                                                                                       |
++----------------------------------------------------------------------------+
+*/
+INT i_APCI035_StartStopWriteTimerWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data)
+{
+   UINT  ui_Command = 0; 
+   INT i_Count=0;
+      if  (data[0]==1) 
+         { 
+         ui_Command = inl(devpriv->iobase+((i_WatchdogNbr-1)*32)+12);
+         /**********************/
+         /* Start the hardware */
+         /**********************/
+         ui_Command = (ui_Command & 0xFFFFF9FFUL) | 0x1UL;
+         outl(ui_Command,devpriv->iobase+((i_WatchdogNbr-1)*32)+12); 
+         } // if  (data[0]==1)
+      if(data[0]==2)
+         {
+         ui_Command = inl(devpriv->iobase+((i_WatchdogNbr-1)*32)+12); 
+         /***************************/
+         /* Set the trigger command */
+         /***************************/
+         ui_Command = (ui_Command & 0xFFFFF9FFUL) | 0x200UL;
+         outl(ui_Command,devpriv->iobase+((i_WatchdogNbr-1)*32)+12);   
+         } 
+           
+      if (data[0]==0) //Stop The Watchdog 
+         {
+         //Stop The Watchdog
+         ui_Command=0;
+         //ui_Command = inl(devpriv->iobase+((i_WatchdogNbr-1)*32)+12); 
+         //ui_Command = ui_Command & 0xFFFFF9FEUL;
+         outl(ui_Command,devpriv->iobase+((i_WatchdogNbr-1)*32)+12);   
+         } //  if (data[1]==0)
+      if(data[0]==3)//stop all Watchdogs
+        {
+         ui_Command=0; 
+         for(i_Count=1;i_Count<=4;i_Count++)
+            {
+            if(devpriv->b_TimerSelectMode==ADDIDATA_WATCHDOG)
+              {
+               ui_Command=0x2UL;
+              }
+            else
+              {
+              ui_Command = 0x10UL; 
+              } 
+               i_WatchdogNbr=i_Count;
+               outl(ui_Command,devpriv->iobase+((i_WatchdogNbr-1)*32) + 0);
+             }
+
+         } 
+      if(data[0]==4)//start all Watchdogs
+        {
+         ui_Command = 0;
+         for(i_Count=1;i_Count<=4;i_Count++)
+            {
+            if(devpriv->b_TimerSelectMode==ADDIDATA_WATCHDOG)
+              {
+               ui_Command = 0x1UL;
+              }
+            else
+               {
+               ui_Command = 0x8UL;
+               } 
+               i_WatchdogNbr=i_Count;
+              outl(ui_Command,devpriv->iobase+((i_WatchdogNbr-1)*32) + 0);             
+             } 
+          }
+      if(data[0]==5)//trigger all Watchdogs
+        {
+         ui_Command =0;
+         for(i_Count=1;i_Count<=4;i_Count++)
+            {
+            if(devpriv->b_TimerSelectMode==ADDIDATA_WATCHDOG)
+               {
+               ui_Command=0x4UL;
+               }
+            else
+              {
+              ui_Command = 0x20UL; 
+              } 
+   
+          i_WatchdogNbr=i_Count;
+             outl(ui_Command,devpriv->iobase+((i_WatchdogNbr-1)*32) + 0);
+           }
+         i_Temp=1;
+         }
+   return insn->n;
+}
+
+/*
++----------------------------------------------------------------------------+
+| Function   Name   : int i_APCI035_ReadTimerWatchdog                        |
+|                        (comedi_device *dev,comedi_subdevice *s,               | 
+|                      comedi_insn *insn,lsampl_t *data)                     |
++----------------------------------------------------------------------------+
+| Task              : Read The Selected Timer , Counter or Watchdog          |
++----------------------------------------------------------------------------+
+| Input Parameters  : comedi_device *dev : Driver handle                     |
+|                     UINT *data         : Data Pointer contains             |
+|                                          configuration parameters as below |
+|                                                                            | 
+|                                                                                                                                       |
++----------------------------------------------------------------------------+
+| Output Parameters :  data[0]            : software trigger status                                                                                            
+              data[1]            : hardware trigger status  
+|                              data[2]            : Software clear status      
+                        data[3]            : Overflow status                                                                                            
+                     data[4]            : Timer actual value   
+                       
+
++----------------------------------------------------------------------------+
+| Return Value      : TRUE  : No error occur                                 |
+|                          : FALSE : Error occur. Return the error          |
+|                                                                               |
++----------------------------------------------------------------------------+
+*/
+INT i_APCI035_ReadTimerWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data)
+{
+UINT ui_Status = 0;   // Status register 
+ i_WatchdogNbr=insn->unused[0]; 
+              /******************/
+              /* Get the status */
+              /******************/  
+      ui_Status =inl(devpriv->iobase+((i_WatchdogNbr-1)*32) + 16);
+      /***********************************/
+      /* Get the software trigger status */
+      /***********************************/
+      data[0] = ((ui_Status >> 1) & 1); 
+      /***********************************/
+      /* Get the hardware trigger status */
+      /***********************************/
+      data[1] =  ((ui_Status >> 2) & 1); 
+      /*********************************/
+      /* Get the software clear status */
+      /*********************************/ 
+      data[2] = ((ui_Status >> 3) & 1);
+      /***************************/
+      /* Get the overflow status */
+      /***************************/
+      data[3] = ((ui_Status >> 0) & 1);
+    if  (devpriv->b_TimerSelectMode==ADDIDATA_TIMER) 
+      {
+      data[4]=inl(devpriv->iobase+((i_WatchdogNbr-1)*32) + 0);
+      
+      } //  if  (devpriv->b_TimerSelectMode==ADDIDATA_TIMER) 
+  
+      
+   return insn->n;
+}
+
+/*
++----------------------------------------------------------------------------+
+| Function   Name   : INT i_APCI035_ConfigAnalogInput                        |
+|                        (comedi_device *dev,comedi_subdevice *s,               | 
+|                      comedi_insn *insn,lsampl_t *data)                     |
++----------------------------------------------------------------------------+
+| Task              : Configures The Analog Input Subdevice                  |
++----------------------------------------------------------------------------+
+| Input Parameters  : comedi_device *dev      : Driver handle                |
+|                     comedi_subdevice *s     : Subdevice Pointer            |  
+|                     comedi_insn *insn       : Insn Structure Pointer       |  
+|                     lsampl_t *data          : Data Pointer contains        |
+|                                          configuration parameters as below |
+|                     data[0]                  : Warning delay value                                                              
+|                                                                            |         
++----------------------------------------------------------------------------+
+| Output Parameters :  --                                                                                                       |
++----------------------------------------------------------------------------+
+| Return Value      : TRUE  : No error occur                                 |
+|                          : FALSE : Error occur. Return the error          |
+|                                                                               |
++----------------------------------------------------------------------------+
+*/
+INT i_APCI035_ConfigAnalogInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) 
+{
+devpriv->tsk_Current=current;
+outl(0x200 | 0, devpriv->iobase+128 + 0x4);
+outl(0, devpriv->iobase+128 + 0);
+/********************************/
+/* Initialise the warning value */
+/********************************/
+outl(0x300 | 0, devpriv->iobase+128 + 0x4);
+outl((data[0] << 8), devpriv->iobase+128 + 0);
+outl(0x200000UL , devpriv->iobase+128 + 12);
+
+return insn->n;
+} 
+
+/*
++----------------------------------------------------------------------------+
+| Function   Name   : int i_APCI035_ReadAnalogInput                          |
+|                                (comedi_device *dev,comedi_subdevice *s,       | 
+|                     comedi_insn *insn,lsampl_t *data)                      |
++----------------------------------------------------------------------------+
+| Task              : Read  value  of the selected channel                              |
++----------------------------------------------------------------------------+
+| Input Parameters  : comedi_device *dev      : Driver handle                |
+|                     UINT ui_NoOfChannels    : No Of Channels To read       |
+|                     UINT *data              : Data Pointer to read status  |
++----------------------------------------------------------------------------+
+| Output Parameters :  --                                                                                                       |
+|                                data[0]  : Digital Value Of Input              |
+|                                                                               |
++----------------------------------------------------------------------------+
+| Return Value      : TRUE  : No error occur                                 |
+|                          : FALSE : Error occur. Return the error          |
+|                                                                               |
++----------------------------------------------------------------------------+
+*/
+INT i_APCI035_ReadAnalogInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) 
+{ 
+UINT ui_CommandRegister=0;
+/******************/
+/*  Set the start */
+/******************/
+ui_CommandRegister =0x80000;  
+ /******************************/
+ /* Write the command register */
+ /******************************/
+outl(ui_CommandRegister, devpriv->iobase+128 + 8);
+              
+/***************************************/
+/* Read the digital value of the input */
+/***************************************/
+data[0] = inl (devpriv->iobase+ 128 + 28);                           
+return insn->n;
+}
+
+
+
+
+
+
+
+/*
++----------------------------------------------------------------------------+
+| Function   Name   :  int i_APCI035_Reset(comedi_device *dev)                      |
+|                                                                                               |
++----------------------------------------------------------------------------+
+| Task              :Resets the registers of the card                        |
++----------------------------------------------------------------------------+
+| Input Parameters  :                                                        |
++----------------------------------------------------------------------------+
+| Output Parameters :  --                                                                                                       |
++----------------------------------------------------------------------------+
+| Return Value      :                                                        |
+|                                                                                       |
++----------------------------------------------------------------------------+
+*/
+INT i_APCI035_Reset(comedi_device *dev)
+{
+INT i_Count=0;
+for(i_Count=1;i_Count<=4;i_Count++)
+    {
+     i_WatchdogNbr=i_Count;
+     outl(0x0,devpriv->iobase+((i_WatchdogNbr-1)*32) + 0);//stop all timers
+    }
+outl(0x0 , devpriv->iobase+128 + 12);//Disable the warning delay
+
+ return 0;
+}
+
+/*
++----------------------------------------------------------------------------+
+| Function   Name   : static void v_APCI035_Interrupt                                       |
+|                                        (int irq , void *d, struct pt_regs *regs)      |
++----------------------------------------------------------------------------+
+| Task              : Interrupt processing Routine                           |
++----------------------------------------------------------------------------+
+| Input Parameters  : int irq                 : irq number                   |
+|                     void *d                 : void pointer                 |
+|                     struct pt_regs *regs    : structure pointer            |
++----------------------------------------------------------------------------+
+| Output Parameters :  --                                                                                                       |
++----------------------------------------------------------------------------+
+| Return Value      : TRUE  : No error occur                                 |
+|                          : FALSE : Error occur. Return the error          |
+|                                                                               |
++----------------------------------------------------------------------------+
+*/
+static void v_APCI035_Interrupt(int irq, void *d, struct pt_regs *regs) 
+{      
+   comedi_device *dev = d;
+   UINT ui_StatusRegister1 = 0;
+   UINT ui_StatusRegister2=0;
+   UINT ui_ReadCommand =0;
+   UINT ui_ChannelNumber=0;
+   UINT ui_DigitalTemperature=0;
+   if(i_Temp==1)
+       {
+        i_WatchdogNbr=i_Flag;  
+        i_Flag=i_Flag+1;  
+       }     
+  /**************************************/
+  /* Read the interrupt status register of temperature Warning */
+  /**************************************/
+   ui_StatusRegister1 = inl(devpriv->iobase+128 + 16);  
+  /**************************************/
+   /* Read the interrupt status register for Watchdog/timer */ 
+   /**************************************/
+  
+   ui_StatusRegister2 = inl (devpriv->iobase+((i_WatchdogNbr-1)*32) + 20);
+   
+   if ((((ui_StatusRegister1 ) & 0x8) == 0x8))//Test if warning relay interrupt
+        {
+        /**********************************/
+        /* Disable the temperature warning */
+        /**********************************/
+         ui_ReadCommand = inl (devpriv->iobase+128 + 12);
+         ui_ReadCommand = ui_ReadCommand & 0xFFDF0000UL;
+         outl(ui_ReadCommand , devpriv->iobase+128 + 12);     
+      /***************************/
+      /* Read the channel number */
+      /***************************/   
+        ui_ChannelNumber  = inl(devpriv->iobase+128 + 60);
+        /**************************************/
+        /* Read the digital temperature value */
+        /**************************************/
+         ui_DigitalTemperature = inl(devpriv->iobase+128 + 60);  
+         send_sig(SIGIO,devpriv->tsk_Current,0); // send signal to the sample
+        }//if (((ui_StatusRegister1 & 0x8) == 0x8)) 
+           
+   else
+       {
+       if((ui_StatusRegister2 & 0x1) == 0x1)       
+          {
+           send_sig(SIGIO,devpriv->tsk_Current,0); // send signal to the sample     
+          }
+        }//else if (((ui_StatusRegister1 & 0x8) == 0x8))       
+        
+    
+return;
+}
+
+
+
+
+
index 4b7b90e1989f5641a12481925851add1f89fbec4..c473bf14764a555ccb7f92ed79a646ce7d7159fc 100644 (file)
-/**\r
-@verbatim\r
-\r
-Copyright (C) 2004,2005  ADDI-DATA GmbH for the source code of this module. \r
-        \r
-        ADDI-DATA GmbH \r
-        Dieselstrasse 3 \r
-        D-77833 Ottersweier \r
-        Tel: +19(0)7223/9493-0 \r
-        Fax: +49(0)7223/9493-92 \r
-        http://www.addi-data-com \r
-        info@addi-data.com \r
-\r
-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.\r
-\r
-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.\r
-\r
-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 USA\r
-\r
-You shoud also find the complete GPL in the COPYING file accompanying this source code.\r
-\r
-@endverbatim\r
-*/\r
-// Card Specific information\r
-#define APCI035_BOARD_VENDOR_ID                 0x15B8\r
-#define APCI035_ADDRESS_RANGE                   255\r
-\r
-INT i_TW_Number;\r
-struct \r
-{                              \r
- INT i_Gain ;\r
- INT i_Polarity;\r
- INT i_OffsetRange;\r
- INT i_Coupling;\r
- INT i_SingleDiff;\r
- INT i_AutoCalibration;\r
- UINT ui_ReloadValue;\r
- UINT ui_TimeUnitReloadVal;\r
- INT i_Interrupt;\r
- INT i_ModuleSelection;\r
-}Config_Parameters_Main;\r
-\r
-\r
-\r
-//ANALOG INPUT RANGE \r
-comedi_lrange range_apci035_ai={ 8, {\r
-               BIP_RANGE(10),\r
-               BIP_RANGE(5),\r
-               BIP_RANGE(2),\r
-               BIP_RANGE(1),\r
-               UNI_RANGE(10),\r
-               UNI_RANGE(5),\r
-               UNI_RANGE(2),\r
-               UNI_RANGE(1)\r
-       }\r
-};\r
-\r
-// Timer / Watchdog Related Defines \r
-\r
-#define APCI035_TCW_SYNC_ENABLEDISABLE           0\r
-#define APCI035_TCW_RELOAD_VALUE                 4\r
-#define APCI035_TCW_TIMEBASE                     8\r
-#define APCI035_TCW_PROG                         12\r
-#define APCI035_TCW_TRIG_STATUS                  16\r
-#define APCI035_TCW_IRQ                          20\r
-#define APCI035_TCW_WARN_TIMEVAL                 24\r
-#define APCI035_TCW_WARN_TIMEBASE                28\r
-\r
-#define ADDIDATA_TIMER                            0\r
-#define ADDIDATA_WATCHDOG                         1\r
-\r
-#define APCI035_TW1                               0\r
-#define APCI035_TW2                               32\r
-#define APCI035_TW3                               64\r
-#define APCI035_TW4                               96\r
-\r
-#define APCI035_AI_OFFSET                        0\r
-#define APCI035_TEMP                             128\r
-#define APCI035_ALR_SEQ                          4\r
-#define APCI035_START_STOP_INDEX                 8\r
-#define APCI035_ALR_START_STOP                   12\r
-#define APCI035_ALR_IRQ                          16\r
-#define APCI035_EOS                              20\r
-#define APCI035_CHAN_NO                          24\r
-#define APCI035_CHAN_VAL                         28\r
-#define APCI035_CONV_TIME_TIME_BASE              36\r
-#define APCI035_RELOAD_CONV_TIME_VAL             32\r
-#define APCI035_DELAY_TIME_TIME_BASE             44\r
-#define APCI035_RELOAD_DELAY_TIME_VAL            40\r
-#define ENABLE_EXT_TRIG                          1\r
-#define ENABLE_EXT_GATE                          2\r
-#define ENABLE_EXT_TRIG_GATE                     3\r
-\r
-#define ANALOG_INPUT                             0\r
-#define TEMPERATURE                              1\r
-#define RESISTANCE                               2\r
-\r
-#define ADDIDATA_GREATER_THAN_TEST               0\r
-#define ADDIDATA_LESS_THAN_TEST                  1\r
-\r
-\r
-#define APCI035_MAXVOLT                         2.5\r
-\r
-#define ADDIDATA_UNIPOLAR                        1\r
-#define ADDIDATA_BIPOLAR                         2\r
-\r
-//ADDIDATA Enable Disable\r
-#define ADDIDATA_ENABLE                            1\r
-#define ADDIDATA_DISABLE                           0\r
-\r
-\r
-\r
-\r
-\r
-\r
-// Hardware Layer  functions for Apci035\r
-\r
-\r
-\r
-// TIMER  \r
-// timer value is passed as u seconds\r
-INT i_APCI035_ConfigTimerWatchdog (comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);\r
-INT i_APCI035_StartStopWriteTimerWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);\r
-INT i_APCI035_ReadTimerWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);\r
-\r
-\r
-//Temperature Related Defines (Analog Input Subdevice)\r
-\r
-INT i_APCI035_ConfigAnalogInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);\r
-INT i_APCI035_ReadAnalogInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);\r
-\r
-\r
-//Interrupt\r
-static void v_APCI035_Interrupt(int irq, void *d, struct pt_regs *regs) ;\r
-\r
-//Reset functions\r
-INT i_APCI035_Reset(comedi_device *dev);       \r
+/**
+@verbatim
+
+Copyright (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 USA
+
+You shoud also find the complete GPL in the COPYING file accompanying this source code.
+
+@endverbatim
+*/
+// Card Specific information
+#define APCI035_BOARD_VENDOR_ID                 0x15B8
+#define APCI035_ADDRESS_RANGE                   255
+
+INT i_TW_Number;
+struct 
+{                              
+ INT i_Gain ;
+ INT i_Polarity;
+ INT i_OffsetRange;
+ INT i_Coupling;
+ INT i_SingleDiff;
+ INT i_AutoCalibration;
+ UINT ui_ReloadValue;
+ UINT ui_TimeUnitReloadVal;
+ INT i_Interrupt;
+ INT i_ModuleSelection;
+}Config_Parameters_Main;
+
+
+
+//ANALOG INPUT RANGE 
+comedi_lrange range_apci035_ai={ 8, {
+               BIP_RANGE(10),
+               BIP_RANGE(5),
+               BIP_RANGE(2),
+               BIP_RANGE(1),
+               UNI_RANGE(10),
+               UNI_RANGE(5),
+               UNI_RANGE(2),
+               UNI_RANGE(1)
+       }
+};
+
+// Timer / Watchdog Related Defines 
+
+#define APCI035_TCW_SYNC_ENABLEDISABLE           0
+#define APCI035_TCW_RELOAD_VALUE                 4
+#define APCI035_TCW_TIMEBASE                     8
+#define APCI035_TCW_PROG                         12
+#define APCI035_TCW_TRIG_STATUS                  16
+#define APCI035_TCW_IRQ                          20
+#define APCI035_TCW_WARN_TIMEVAL                 24
+#define APCI035_TCW_WARN_TIMEBASE                28
+
+#define ADDIDATA_TIMER                            0
+//#define ADDIDATA_WATCHDOG                         1
+
+#define APCI035_TW1                               0
+#define APCI035_TW2                               32
+#define APCI035_TW3                               64
+#define APCI035_TW4                               96
+
+#define APCI035_AI_OFFSET                        0
+#define APCI035_TEMP                             128
+#define APCI035_ALR_SEQ                          4
+#define APCI035_START_STOP_INDEX                 8
+#define APCI035_ALR_START_STOP                   12
+#define APCI035_ALR_IRQ                          16
+#define APCI035_EOS                              20
+#define APCI035_CHAN_NO                          24
+#define APCI035_CHAN_VAL                         28
+#define APCI035_CONV_TIME_TIME_BASE              36
+#define APCI035_RELOAD_CONV_TIME_VAL             32
+#define APCI035_DELAY_TIME_TIME_BASE             44
+#define APCI035_RELOAD_DELAY_TIME_VAL            40
+#define ENABLE_EXT_TRIG                          1
+#define ENABLE_EXT_GATE                          2
+#define ENABLE_EXT_TRIG_GATE                     3
+
+#define ANALOG_INPUT                             0
+#define TEMPERATURE                              1
+#define RESISTANCE                               2
+
+#define ADDIDATA_GREATER_THAN_TEST               0
+#define ADDIDATA_LESS_THAN_TEST                  1
+
+
+#define APCI035_MAXVOLT                         2.5
+
+#define ADDIDATA_UNIPOLAR                        1
+#define ADDIDATA_BIPOLAR                         2
+
+//ADDIDATA Enable Disable
+#define ADDIDATA_ENABLE                            1
+#define ADDIDATA_DISABLE                           0
+
+
+
+
+
+
+// Hardware Layer  functions for Apci035
+
+
+
+// TIMER  
+// timer value is passed as u seconds
+INT i_APCI035_ConfigTimerWatchdog (comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);
+INT i_APCI035_StartStopWriteTimerWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);
+INT i_APCI035_ReadTimerWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);
+
+
+//Temperature Related Defines (Analog Input Subdevice)
+
+INT i_APCI035_ConfigAnalogInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);
+INT i_APCI035_ReadAnalogInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);
+
+
+//Interrupt
+static void v_APCI035_Interrupt(int irq, void *d, struct pt_regs *regs) ;
+
+//Reset functions
+INT i_APCI035_Reset(comedi_device *dev);       
index f1de6f3dccab59cd11512f807118d586d03b86bb..8e692d79b7686a6af5a7fa24724cf03cc4c3b396 100644 (file)
@@ -24,7 +24,7 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc
 /*
     
   +-----------------------------------------------------------------------+
-  | (C) ADDI-DATA GmbH          Dieselstraße 3       D-77833 Ottersweier  |
+  | (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   |
index 5ac61a46fc68b78c8a92d529ddda8cfeb1ddc348..d896d0569cbdab0ea8142f0f409cd78cee9bad18 100644 (file)
@@ -24,7 +24,7 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc
 /*
     
   +-----------------------------------------------------------------------+
-  | (C) ADDI-DATA GmbH          Dieselstraße 3       D-77833 Ottersweier  |
+  | (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   |
index a0ebb57c6e322128279c91d6f7fa07c13f3917f8..9db945ee959d6d7012ee420f98701f9c439b0ebb 100644 (file)
-/**\r
-@verbatim\r
-\r
-Copyright (C) 2004,2005  ADDI-DATA GmbH for the source code of this module. \r
-        \r
-        ADDI-DATA GmbH \r
-        Dieselstrasse 3 \r
-        D-77833 Ottersweier \r
-        Tel: +19(0)7223/9493-0 \r
-        Fax: +49(0)7223/9493-92 \r
-        http://www.addi-data-com \r
-        info@addi-data.com \r
-\r
-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.\r
-\r
-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.\r
-\r
-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 USA\r
-\r
-You shoud also find the complete GPL in the COPYING file accompanying this source code.\r
-\r
-@endverbatim\r
-*/\r
-/*\r
-    \r
-  +-----------------------------------------------------------------------+\r
-  | (C) ADDI-DATA GmbH          Dieselstraße 3       D-77833 Ottersweier  |\r
-  +-----------------------------------------------------------------------+\r
-  | Tel : +49 (0) 7223/9493-0     | email    : info@addi-data.com         |\r
-  | Fax : +49 (0) 7223/9493-92    | Internet : http://www.addi-data.com   |\r
-  +-------------------------------+---------------------------------------+\r
-  | Project     : APCI-1516       | Compiler   : GCC                      |\r
-  | Module name : hwdrv_apci1516.c| Version    : 2.96                     |\r
-  +-------------------------------+---------------------------------------+\r
-  | Project manager: Eric Stolz   | Date       :  02/12/2002              |\r
-  +-------------------------------+---------------------------------------+\r
-  | Description :   Hardware Layer Acces For APCI-1516                    |\r
-  +-----------------------------------------------------------------------+\r
-  |                             UPDATES                                   |\r
-  +----------+-----------+------------------------------------------------+\r
-  |   Date   |   Author  |          Description of updates                |\r
-  +----------+-----------+------------------------------------------------+\r
-  |          |           |                                                |\r
-  |          |           |                                                |\r
-  |          |           |                                                |\r
-  +----------+-----------+------------------------------------------------+\r
-*/\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-|                               Included files                               |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-#include "hwdrv_apci1516.h"\r
-\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function   Name   : int i_APCI1516_Read1DigitalInput                       |\r
-|                        (comedi_device *dev,comedi_subdevice *s,               |\r
-|                      comedi_insn *insn,lsampl_t *data)                     |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Return the status of the digital input                 |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : comedi_device *dev      : Driver handle                |\r
-|                     comedi_subdevice *s,   :pointer to subdevice structure\r
-                       comedi_insn *insn      :pointer to insn structure     |\r
-|                     lsampl_t *data          : Data Pointer to read status  |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters :  --                                                                                                       |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      : TRUE  : No error occur                                 |\r
-|                          : FALSE : Error occur. Return the error          |\r
-|                                                                               |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-INT i_APCI1516_Read1DigitalInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data)\r
-{\r
-   UINT ui_TmpValue=0;\r
-   UINT ui_Channel;\r
-   ui_Channel=CR_CHAN(insn->chanspec);\r
-   if  (ui_Channel >= 0 && ui_Channel <=7)\r
-      {\r
-      ui_TmpValue=(UINT) inw(devpriv->iobase + APCI1516_DIGITAL_IP);\r
-      //  since only 1 channel reqd  to bring it to last bit it is rotated \r
-      //  8 +(chan - 1) times then ANDed with 1 for last bit. \r
-      *data = (ui_TmpValue >> ui_Channel)&0x1 ;\r
-      }//if(ui_Channel >= 0 && ui_Channel <=7)\r
-   else \r
-      {\r
-      //comedi_error(dev," \n chan spec wrong\n");\r
-      return -EINVAL;   // "sorry channel spec wrong "\r
-      }//else if(ui_Channel >= 0 && ui_Channel <=7)\r
-\r
-  return insn->n;\r
-}\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function   Name   : int i_APCI1516_ReadMoreDigitalInput                    |\r
-|                        (comedi_device *dev,comedi_subdevice *s,               |\r
-|                     comedi_insn *insn,lsampl_t *data)                      |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Return the status of the Requested digital inputs      |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : comedi_device *dev      : Driver handle                |\r
-|                      comedi_subdevice *s,   :pointer to subdevice structure\r
-                       comedi_insn *insn      :pointer to insn structure     |\r
-|                      lsampl_t *data         : Data Pointer to read status  |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters :  --                                                                                                       |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      : TRUE  : No error occur                                 |\r
-|                          : FALSE : Error occur. Return the error          |\r
-|                                                                               |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-INT i_APCI1516_ReadMoreDigitalInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data)\r
-{\r
\r
-   UINT ui_PortValue=data[0];\r
-   UINT ui_Mask=0;\r
-   UINT ui_NoOfChannels;\r
-   \r
-   ui_NoOfChannels=CR_CHAN(insn->chanspec);\r
-   \r
-      *data=(UINT)inw(devpriv->iobase + APCI1516_DIGITAL_IP );\r
-      switch (ui_NoOfChannels)\r
-       {\r
-        case 2:ui_Mask=3;\r
-               *data=(*data >>(2*ui_PortValue))&ui_Mask; \r
-               break;\r
-        case 4:ui_Mask=15;\r
-               *data=(*data >>(4*ui_PortValue))&ui_Mask; \r
-              break;\r
-        case 7:break;\r
-        \r
-        default:\r
-               printk("\nWrong parameters\n");\r
-               return -EINVAL;   // "sorry channel spec wrong "  \r
-                break;\r
-        }//switch(ui_NoOfChannels)\r
-      \r
-  \r
-   return insn->n;\r
-}\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function   Name   : int i_APCI1516_ConfigDigitalOutput (comedi_device *dev,\r
-                    comedi_subdevice *s comedi_insn *insn,lsampl_t *data)    |\r
-|                                                                                   |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Configures The Digital Output Subdevice.               |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : comedi_device *dev : Driver handle                     |\r
-|                     lsampl_t *data         : Data Pointer contains         |\r
-|                                          configuration parameters as below |\r
-|                      comedi_subdevice *s,   :pointer to subdevice structure\r
-                       comedi_insn *insn      :pointer to insn structure                                                           | \r
-|                                        data[0]  :1:Memory on                          | \r
-|                                                  0:Memory off                         |      \r
-|                                                                                                           | \r
-|                                                                                                                                       |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters :  --                                                                                                       |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      : TRUE  : No error occur                                 |\r
-|                          : FALSE : Error occur. Return the error          |\r
-|                                                                               |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-int i_APCI1516_ConfigDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data){\r
- devpriv->b_OutputMemoryStatus=data[0];\r
-return insn->n;\r
-}\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function   Name   : int i_APCI1516_WriteDigitalOutput                      |\r
-|                      (comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,\r
-                     lsampl_t *data)                                         |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Writes port value  To the selected port                |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : comedi_device *dev      : Driver handle                |\r
-|                     comedi_subdevice *s,   :pointer to subdevice structure\r
-                      comedi_insn *insn      :pointer to insn structure      |\r
-|                    lsampl_t *data           : Data Pointer to read status  |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters :  --                                                                                                       |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      : TRUE  : No error occur                                 |\r
-|                          : FALSE : Error occur. Return the error          |\r
-|                                                                               |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-INT i_APCI1516_WriteDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) \r
-{\r
-UINT ui_Temp,ui_Temp1;\r
-UINT ui_NoOfChannel = CR_CHAN(insn->chanspec); // get the channel\r
-\r
-printk("EL311003 : @=%x\n",devpriv->iobase+APCI1516_DIGITAL_OP); \r
-\r
- if(devpriv->b_OutputMemoryStatus )\r
-   {\r
-   ui_Temp=inw(devpriv->iobase+APCI1516_DIGITAL_OP);\r
\r
-   }//if(devpriv->b_OutputMemoryStatus )\r
- else\r
-   {\r
-   ui_Temp=0;\r
-    }//if(devpriv->b_OutputMemoryStatus )\r
-if(data[3]==0)\r
-  { \r
-  if(data[1]==0)\r
-    {\r
-     data[0]=(data[0] << ui_NoOfChannel)|ui_Temp;\r
-     outw(data[0],devpriv->iobase+APCI1516_DIGITAL_OP); \r
-     \r
-     printk("EL311003 : d=%d @=%x\n",data[0],devpriv->iobase+APCI1516_DIGITAL_OP); \r
-     \r
-    }//if(data[1]==0) \r
-  else\r
-    {\r
-    if(data[1]==1)\r
-       { \r
-       switch( ui_NoOfChannel)\r
-        {\r
-\r
-        case 2: data[0]=(data[0] << (2*data[2]))|ui_Temp; \r
-              break;\r
-\r
-\r
-        case 4:data[0]=(data[0] << (4*data[2]))|ui_Temp;\r
-              break;\r
-\r
-        case 7:data[0]=data[0]|ui_Temp; \r
-              break;\r
-\r
-         default:\r
-                 comedi_error(dev," chan spec wrong");\r
-                 return -EINVAL;   // "sorry channel spec wrong "  \r
-                \r
-\r
-         }//switch(ui_NoOfChannels)\r
-   \r
-     outw(data[0],devpriv->iobase+APCI1516_DIGITAL_OP);\r
-     \r
-     printk("EL311003 : d=%d @=%x\n",data[0],devpriv->iobase+APCI1516_DIGITAL_OP); \r
-     }// if(data[1]==1)\r
-   else\r
-     {\r
-     printk("\nSpecified channel not supported\n");\r
-     }//else if(data[1]==1)\r
-   }//elseif(data[1]==0)\r
- }//if(data[3]==0)\r
-else\r
-   {\r
-    if(data[3]==1)\r
-       {\r
-        if(data[1]==0)\r
-          {\r
-          data[0]=~data[0]&0x1;\r
-          ui_Temp1=1;\r
-          ui_Temp1=ui_Temp1<<ui_NoOfChannel;\r
-          ui_Temp=ui_Temp|ui_Temp1;  \r
-          data[0]=(data[0] << ui_NoOfChannel)^0xff;\r
-          data[0]=data[0]& ui_Temp; \r
-          outw(data[0],devpriv->iobase+APCI1516_DIGITAL_OP); \r
-          \r
-          printk("EL311003 : d=%d @=%x\n",data[0],devpriv->iobase+APCI1516_DIGITAL_OP); \r
-          \r
-          }//if(data[1]==0) \r
-        else\r
-          {\r
-          if(data[1]==1)\r
-             { \r
-             switch( ui_NoOfChannel)\r
-              {\r
-\r
-              case 2: data[0]=~data[0]&0x3; \r
-                       ui_Temp1=3;\r
-                       ui_Temp1=ui_Temp1<<2*data[2];\r
-                       ui_Temp=ui_Temp|ui_Temp1;   \r
-                       data[0]=((data[0] << (2*data[2]))^0xff)& ui_Temp; \r
-                      break;\r
-\r
-\r
-              case 4:data[0]=~data[0]&0xf;\r
-                      ui_Temp1=15;\r
-                      ui_Temp1=ui_Temp1<<4*data[2];\r
-                      ui_Temp=ui_Temp|ui_Temp1;    \r
-                      data[0]=((data[0] << (4*data[2]))^0xff)&ui_Temp;\r
-                     break;\r
-\r
-              case 7: break;\r
-\r
-               default:\r
-                     comedi_error(dev," chan spec wrong");\r
-                     return -EINVAL;   // "sorry channel spec wrong "  \r
-                \r
-\r
-              }//switch(ui_NoOfChannels)\r
-   \r
-            outw(data[0],devpriv->iobase+APCI1516_DIGITAL_OP);\r
-            \r
-            printk("EL311003 : d=%d @=%x\n",data[0],devpriv->iobase+APCI1516_DIGITAL_OP); \r
-            }// if(data[1]==1)\r
-         else\r
-           {\r
-            printk("\nSpecified channel not supported\n");\r
-           }//else if(data[1]==1)\r
-         }//elseif(data[1]==0)\r
-      }//if(data[3]==1);\r
-   else\r
-      {\r
-       printk("\nSpecified functionality does not exist\n");\r
-       return -EINVAL;\r
-      }//if else data[3]==1)\r
-   }//if else data[3]==0) \r
-    return (insn->n);;\r
-}\r
-\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function   Name   : int i_APCI1516_ReadDigitalOutput                       |\r
-|                      (comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,\r
-                    lsampl_t *data)                                         |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Read  value  of the selected channel or port           |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : comedi_device *dev      : Driver handle                |\r
-|                     comedi_subdevice *s,   :pointer to subdevice structure\r
-                      comedi_insn *insn      :pointer to insn structure      |\r
-|                     lsampl_t *data          : Data Pointer to read status  |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters :  --                                                                                                       |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      : TRUE  : No error occur                                 |\r
-|                          : FALSE : Error occur. Return the error          |\r
-|                                                                               |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-INT i_APCI1516_ReadDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) \r
-{\r
-\r
-UINT ui_Temp;\r
-UINT ui_NoOfChannel = CR_CHAN(insn->chanspec); // get the channel\r
-ui_Temp=data[0];\r
-*data=inw(devpriv->iobase+APCI1516_DIGITAL_OP_RW);\r
-if(ui_Temp==0)\r
-   {\r
-   *data=(*data >> ui_NoOfChannel)&0x1; \r
-   }//if(ui_Temp==0)\r
-else\r
-   {\r
-    if(ui_Temp==1)\r
-       {\r
-       switch( ui_NoOfChannel)\r
-        {\r
-\r
-        case 2:*data=(*data >>(2*data[1]))&3; \r
-               break;\r
-\r
\r
-        case 4:*data=(*data >>(4*data[1]))&15; \r
-              break;\r
-\r
-        case 7: break;\r
\r
-         default:\r
-                 comedi_error(dev," chan spec wrong");\r
-                 return -EINVAL;   // "sorry channel spec wrong "  \r
-          \r
-\r
-         }//switch(ui_NoOfChannels)    \r
-       }//if(ui_Temp==1)\r
-   else\r
-     {\r
-     printk("\nSpecified channel not supported \n");\r
-     }//elseif(ui_Temp==1)\r
-  }//elseif(ui_Temp==0)\r
-return insn->n;\r
-}\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function   Name   : int i_APCI1516_ConfigWatchdog(comedi_device *dev,\r
-                      comedi_subdevice *s,comedi_insn *insn,lsampl_t *data)  |\r
-|                                                                                   |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Configures The Watchdog                                |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  :   comedi_device *dev      : Driver handle              |\r
-|                     comedi_subdevice *s,   :pointer to subdevice structure\r
-                      comedi_insn *insn      :pointer to insn structure      |\r
-|                     lsampl_t *data          : Data Pointer to read status                                                     |  \r
-+----------------------------------------------------------------------------+\r
-| Output Parameters :  --                                                                                                       |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      : TRUE  : No error occur                                 |\r
-|                          : FALSE : Error occur. Return the error          |\r
-|                                                                               |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-int i_APCI1516_ConfigWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data)\r
-{\r
-if(data[0]==0)\r
-   {\r
-   //Disable the watchdog\r
-   outw(0x0,devpriv->i_IobaseAddon+ APCI1516_WATCHDOG_ENABLEDISABLE);\r
-   //Loading the Reload value\r
-   outw(data[1],devpriv->i_IobaseAddon+APCI1516_WATCHDOG_RELOAD_VALUE);\r
-   data[1]=data[1]>>16;\r
-   outw(data[1],devpriv->i_IobaseAddon+APCI1516_WATCHDOG_RELOAD_VALUE+2);\r
-   }//if(data[0]==0)\r
-else\r
-   {\r
-     printk("\nThe input parameters are wrong\n");\r
-     return -EINVAL; \r
-   }//elseif(data[0]==0)\r
-\r
-return insn->n;\r
-}\r
-\r
- /*\r
-+----------------------------------------------------------------------------+\r
-| Function   Name   : int i_APCI1516_StartStopWriteWatchdog                  |\r
-|                              (comedi_device *dev,comedi_subdevice *s,\r
-                     comedi_insn *insn,lsampl_t *data);                      |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Start / Stop The Watchdog                              |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : comedi_device *dev      : Driver handle                |\r
-|                     comedi_subdevice *s,   :pointer to subdevice structure\r
-                      comedi_insn *insn      :pointer to insn structure      |\r
-|                     lsampl_t *data          : Data Pointer to read status  |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters :  --                                                                                                       |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      : TRUE  : No error occur                                 |\r
-|                          : FALSE : Error occur. Return the error          |\r
-|                                                                               |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-int i_APCI1516_StartStopWriteWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) \r
-{\r
-   switch(data[0])\r
-      {\r
-       case 0://stop the watchdog\r
-                outw(0x0,devpriv->i_IobaseAddon+ APCI1516_WATCHDOG_ENABLEDISABLE);//disable the watchdog\r
-                break;\r
-       case 1://start the watchdog\r
-               outw(0x0001,devpriv->i_IobaseAddon+ APCI1516_WATCHDOG_ENABLEDISABLE);\r
-               break;\r
-       case 2://Software trigger  \r
-              outw(0x0201,devpriv->i_IobaseAddon+ APCI1516_WATCHDOG_ENABLEDISABLE);\r
-              break;\r
-       default:printk("\nSpecified functionality does not exist\n");\r
-              return -EINVAL;\r
-       }// switch(data[0])        \r
-return insn->n;\r
-}\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function   Name   : int i_APCI1516_ReadWatchdog                            |\r
-|                      (comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,\r
-                    lsampl_t *data);                                        |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Read The Watchdog                                      |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  :   comedi_device *dev      : Driver handle              |\r
-|                     comedi_subdevice *s,   :pointer to subdevice structure\r
-                      comedi_insn *insn      :pointer to insn structure      |\r
-|                     lsampl_t *data          : Data Pointer to read status  |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters :  --                                                                                                       |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      : TRUE  : No error occur                                 |\r
-|                          : FALSE : Error occur. Return the error          |\r
-|                                                                               |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-int i_APCI1516_ReadWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data)\r
- {\r
- data[0]= inw(devpriv->i_IobaseAddon+APCI1516_WATCHDOG_STATUS)&0x1; \r
-return insn->n;\r
-}\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function   Name   : int i_APCI1516_Reset(comedi_device *dev)               |                                                                                                          |\r
-+----------------------------------------------------------------------------+\r
-| Task              :resets all the registers                                |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : comedi_device *dev\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters :  --                                                                                                       |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      :                                                        |\r
-|                                                                               |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-         \r
-INT i_APCI1516_Reset(comedi_device *dev) \r
-{\r
-  outw(0x0 ,devpriv->iobase+APCI1516_DIGITAL_OP);//RESETS THE DIGITAL OUTPUTS\r
-  outw(0x0,devpriv->i_IobaseAddon+ APCI1516_WATCHDOG_ENABLEDISABLE);\r
- outw(0x0,devpriv->i_IobaseAddon+APCI1516_WATCHDOG_RELOAD_VALUE);\r
- outw(0x0,devpriv->i_IobaseAddon+APCI1516_WATCHDOG_RELOAD_VALUE+2);\r
-  return 0;\r
-}        \r
-\r
-\r
+/**
+@verbatim
+
+Copyright (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 USA
+
+You 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     : APCI-1516       | Compiler   : GCC                      |
+  | Module name : hwdrv_apci1516.c| Version    : 2.96                     |
+  +-------------------------------+---------------------------------------+
+  | Project manager: Eric Stolz   | Date       :  02/12/2002              |
+  +-------------------------------+---------------------------------------+
+  | Description :   Hardware Layer Acces For APCI-1516                    |
+  +-----------------------------------------------------------------------+
+  |                             UPDATES                                   |
+  +----------+-----------+------------------------------------------------+
+  |   Date   |   Author  |          Description of updates                |
+  +----------+-----------+------------------------------------------------+
+  |          |           |                                                |
+  |          |           |                                                |
+  |          |           |                                                |
+  +----------+-----------+------------------------------------------------+
+*/
+
+/*
++----------------------------------------------------------------------------+
+|                               Included files                               |
++----------------------------------------------------------------------------+
+*/
+#include "hwdrv_apci1516.h"
+
+
+/*
++----------------------------------------------------------------------------+
+| Function   Name   : int i_APCI1516_Read1DigitalInput                       |
+|                        (comedi_device *dev,comedi_subdevice *s,               |
+|                      comedi_insn *insn,lsampl_t *data)                     |
++----------------------------------------------------------------------------+
+| Task              : Return the status of the digital input                 |
++----------------------------------------------------------------------------+
+| Input Parameters  : comedi_device *dev      : Driver handle                |
+|                     comedi_subdevice *s,   :pointer to subdevice structure
+                       comedi_insn *insn      :pointer to insn structure     |
+|                     lsampl_t *data          : Data Pointer to read status  |
++----------------------------------------------------------------------------+
+| Output Parameters :  --                                                                                                       |
++----------------------------------------------------------------------------+
+| Return Value      : TRUE  : No error occur                                 |
+|                          : FALSE : Error occur. Return the error          |
+|                                                                               |
++----------------------------------------------------------------------------+
+*/
+INT i_APCI1516_Read1DigitalInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data)
+{
+   UINT ui_TmpValue=0;
+   UINT ui_Channel;
+   ui_Channel=CR_CHAN(insn->chanspec);
+   if  (ui_Channel >= 0 && ui_Channel <=7)
+      {
+      ui_TmpValue=(UINT) inw(devpriv->iobase + APCI1516_DIGITAL_IP);
+      //  since only 1 channel reqd  to bring it to last bit it is rotated 
+      //  8 +(chan - 1) times then ANDed with 1 for last bit. 
+      *data = (ui_TmpValue >> ui_Channel)&0x1 ;
+      }//if(ui_Channel >= 0 && ui_Channel <=7)
+   else 
+      {
+      //comedi_error(dev," \n chan spec wrong\n");
+      return -EINVAL;   // "sorry channel spec wrong "
+      }//else if(ui_Channel >= 0 && ui_Channel <=7)
+
+  return insn->n;
+}
+
+/*
++----------------------------------------------------------------------------+
+| Function   Name   : int i_APCI1516_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                |
+|                      comedi_subdevice *s,   :pointer to subdevice structure
+                       comedi_insn *insn      :pointer to insn structure     |
+|                      lsampl_t *data         : Data Pointer to read status  |
++----------------------------------------------------------------------------+
+| Output Parameters :  --                                                                                                       |
++----------------------------------------------------------------------------+
+| Return Value      : TRUE  : No error occur                                 |
+|                          : FALSE : Error occur. Return the error          |
+|                                                                               |
++----------------------------------------------------------------------------+
+*/
+
+INT i_APCI1516_ReadMoreDigitalInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data)
+{
+   UINT ui_PortValue=data[0];
+   UINT ui_Mask=0;
+   UINT ui_NoOfChannels;
+   
+   ui_NoOfChannels=CR_CHAN(insn->chanspec);
+   
+      *data=(UINT)inw(devpriv->iobase + APCI1516_DIGITAL_IP );
+      switch (ui_NoOfChannels)
+       {
+        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 7:break;
+        
+        default:
+               printk("\nWrong parameters\n");
+               return -EINVAL;   // "sorry channel spec wrong "  
+                break;
+        }//switch(ui_NoOfChannels)
+      
+  
+   return insn->n;
+}
+
+/*
++----------------------------------------------------------------------------+
+| Function   Name   : int i_APCI1516_ConfigDigitalOutput (comedi_device *dev,
+                    comedi_subdevice *s comedi_insn *insn,lsampl_t *data)    |
+|                                                                                   |
++----------------------------------------------------------------------------+
+| Task              : Configures The Digital Output Subdevice.               |
++----------------------------------------------------------------------------+
+| 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                         |      
+|                                                                                                           | 
+|                                                                                                                                       |
++----------------------------------------------------------------------------+
+| Output Parameters :  --                                                                                                       |
++----------------------------------------------------------------------------+
+| Return Value      : TRUE  : No error occur                                 |
+|                          : FALSE : Error occur. Return the error          |
+|                                                                               |
++----------------------------------------------------------------------------+
+*/
+int i_APCI1516_ConfigDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data){
+ devpriv->b_OutputMemoryStatus=data[0];
+return insn->n;
+}
+
+/*
++----------------------------------------------------------------------------+
+| Function   Name   : int i_APCI1516_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                |
+|                     comedi_subdevice *s,   :pointer to subdevice structure
+                      comedi_insn *insn      :pointer to insn structure      |
+|                    lsampl_t *data           : Data Pointer to read status  |
++----------------------------------------------------------------------------+
+| Output Parameters :  --                                                                                                       |
++----------------------------------------------------------------------------+
+| Return Value      : TRUE  : No error occur                                 |
+|                          : FALSE : Error occur. Return the error          |
+|                                                                               |
++----------------------------------------------------------------------------+
+*/
+
+INT i_APCI1516_WriteDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) 
+{
+UINT ui_Temp,ui_Temp1;
+UINT ui_NoOfChannel = CR_CHAN(insn->chanspec); // get the channel
+
+printk("EL311003 : @=%x\n",devpriv->iobase+APCI1516_DIGITAL_OP); 
+
+ if(devpriv->b_OutputMemoryStatus )
+   {
+   ui_Temp=inw(devpriv->iobase+APCI1516_DIGITAL_OP);
+   }//if(devpriv->b_OutputMemoryStatus )
+ else
+   {
+   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->iobase+APCI1516_DIGITAL_OP); 
+     
+     printk("EL311003 : d=%d @=%x\n",data[0],devpriv->iobase+APCI1516_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 7:data[0]=data[0]|ui_Temp; 
+              break;
+
+         default:
+                 comedi_error(dev," chan spec wrong");
+                 return -EINVAL;   // "sorry channel spec wrong "  
+                
+
+         }//switch(ui_NoOfChannels)
+   
+     outw(data[0],devpriv->iobase+APCI1516_DIGITAL_OP);
+     
+     printk("EL311003 : d=%d @=%x\n",data[0],devpriv->iobase+APCI1516_DIGITAL_OP); 
+     }// if(data[1]==1)
+   else
+     {
+     printk("\nSpecified channel not supported\n");
+     }//else if(data[1]==1)
+   }//elseif(data[1]==0)
+ }//if(data[3]==0)
+else
+   {
+    if(data[3]==1)
+       {
+        if(data[1]==0)
+          {
+          data[0]=~data[0]&0x1;
+          ui_Temp1=1;
+          ui_Temp1=ui_Temp1<<ui_NoOfChannel;
+          ui_Temp=ui_Temp|ui_Temp1;  
+          data[0]=(data[0] << ui_NoOfChannel)^0xff;
+          data[0]=data[0]& ui_Temp; 
+          outw(data[0],devpriv->iobase+APCI1516_DIGITAL_OP); 
+          
+          printk("EL311003 : d=%d @=%x\n",data[0],devpriv->iobase+APCI1516_DIGITAL_OP); 
+          
+          }//if(data[1]==0) 
+        else
+          {
+          if(data[1]==1)
+             { 
+             switch( ui_NoOfChannel)
+              {
+
+              case 2: data[0]=~data[0]&0x3; 
+                       ui_Temp1=3;
+                       ui_Temp1=ui_Temp1<<2*data[2];
+                       ui_Temp=ui_Temp|ui_Temp1;   
+                       data[0]=((data[0] << (2*data[2]))^0xff)& ui_Temp; 
+                      break;
+
+
+              case 4:data[0]=~data[0]&0xf;
+                      ui_Temp1=15;
+                      ui_Temp1=ui_Temp1<<4*data[2];
+                      ui_Temp=ui_Temp|ui_Temp1;    
+                      data[0]=((data[0] << (4*data[2]))^0xff)&ui_Temp;
+                     break;
+
+              case 7: break;
+
+               default:
+                     comedi_error(dev," chan spec wrong");
+                     return -EINVAL;   // "sorry channel spec wrong "  
+                
+
+              }//switch(ui_NoOfChannels)
+   
+            outw(data[0],devpriv->iobase+APCI1516_DIGITAL_OP);
+            
+            printk("EL311003 : d=%d @=%x\n",data[0],devpriv->iobase+APCI1516_DIGITAL_OP); 
+            }// if(data[1]==1)
+         else
+           {
+            printk("\nSpecified channel not supported\n");
+           }//else if(data[1]==1)
+         }//elseif(data[1]==0)
+      }//if(data[3]==1);
+   else
+      {
+       printk("\nSpecified functionality does not exist\n");
+       return -EINVAL;
+      }//if else data[3]==1)
+   }//if else data[3]==0) 
+    return (insn->n);;
+}
+
+
+/*
++----------------------------------------------------------------------------+
+| Function   Name   : int i_APCI1516_ReadDigitalOutput                       |
+|                      (comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,
+                    lsampl_t *data)                                         |
++----------------------------------------------------------------------------+
+| Task              : Read  value  of the selected channel or port           |
++----------------------------------------------------------------------------+
+| Input Parameters  : comedi_device *dev      : Driver handle                |
+|                     comedi_subdevice *s,   :pointer to subdevice structure
+                      comedi_insn *insn      :pointer to insn structure      |
+|                     lsampl_t *data          : Data Pointer to read status  |
++----------------------------------------------------------------------------+
+| Output Parameters :  --                                                                                                       |
++----------------------------------------------------------------------------+
+| Return Value      : TRUE  : No error occur                                 |
+|                          : FALSE : Error occur. Return the error          |
+|                                                                               |
++----------------------------------------------------------------------------+
+*/
+
+INT i_APCI1516_ReadDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) 
+{
+
+UINT ui_Temp;
+UINT ui_NoOfChannel = CR_CHAN(insn->chanspec); // get the channel
+ui_Temp=data[0];
+*data=inw(devpriv->iobase+APCI1516_DIGITAL_OP_RW);
+if(ui_Temp==0)
+   {
+   *data=(*data >> ui_NoOfChannel)&0x1; 
+   }//if(ui_Temp==0)
+else
+   {
+    if(ui_Temp==1)
+       {
+       switch( ui_NoOfChannel)
+        {
+
+        case 2:*data=(*data >>(2*data[1]))&3; 
+               break;
+
+        case 4:*data=(*data >>(4*data[1]))&15; 
+              break;
+
+        case 7: break;
+         default:
+                 comedi_error(dev," chan spec wrong");
+                 return -EINVAL;   // "sorry channel spec wrong "  
+          
+
+         }//switch(ui_NoOfChannels)    
+       }//if(ui_Temp==1)
+   else
+     {
+     printk("\nSpecified channel not supported \n");
+     }//elseif(ui_Temp==1)
+  }//elseif(ui_Temp==0)
+return insn->n;
+}
+
+/*
++----------------------------------------------------------------------------+
+| Function   Name   : int i_APCI1516_ConfigWatchdog(comedi_device *dev,
+                      comedi_subdevice *s,comedi_insn *insn,lsampl_t *data)  |
+|                                                                                   |
++----------------------------------------------------------------------------+
+| Task              : Configures The Watchdog                                |
++----------------------------------------------------------------------------+
+| Input Parameters  :   comedi_device *dev      : Driver handle              |
+|                     comedi_subdevice *s,   :pointer to subdevice structure
+                      comedi_insn *insn      :pointer to insn structure      |
+|                     lsampl_t *data          : Data Pointer to read status                                                     |  
++----------------------------------------------------------------------------+
+| Output Parameters :  --                                                                                                       |
++----------------------------------------------------------------------------+
+| Return Value      : TRUE  : No error occur                                 |
+|                          : FALSE : Error occur. Return the error          |
+|                                                                               |
++----------------------------------------------------------------------------+
+*/
+
+int i_APCI1516_ConfigWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data)
+{
+if(data[0]==0)
+   {
+   //Disable the watchdog
+   outw(0x0,devpriv->i_IobaseAddon+ APCI1516_WATCHDOG_ENABLEDISABLE);
+   //Loading the Reload value
+   outw(data[1],devpriv->i_IobaseAddon+APCI1516_WATCHDOG_RELOAD_VALUE);
+   data[1]=data[1]>>16;
+   outw(data[1],devpriv->i_IobaseAddon+APCI1516_WATCHDOG_RELOAD_VALUE+2);
+   }//if(data[0]==0)
+else
+   {
+     printk("\nThe input parameters are wrong\n");
+     return -EINVAL; 
+   }//elseif(data[0]==0)
+
+return insn->n;
+}
+
+ /*
++----------------------------------------------------------------------------+
+| Function   Name   : int i_APCI1516_StartStopWriteWatchdog                  |
+|                              (comedi_device *dev,comedi_subdevice *s,
+                     comedi_insn *insn,lsampl_t *data);                      |
++----------------------------------------------------------------------------+
+| Task              : Start / Stop The Watchdog                              |
++----------------------------------------------------------------------------+
+| Input Parameters  : comedi_device *dev      : Driver handle                |
+|                     comedi_subdevice *s,   :pointer to subdevice structure
+                      comedi_insn *insn      :pointer to insn structure      |
+|                     lsampl_t *data          : Data Pointer to read status  |
++----------------------------------------------------------------------------+
+| Output Parameters :  --                                                                                                       |
++----------------------------------------------------------------------------+
+| Return Value      : TRUE  : No error occur                                 |
+|                          : FALSE : Error occur. Return the error          |
+|                                                                               |
++----------------------------------------------------------------------------+
+*/
+
+int i_APCI1516_StartStopWriteWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) 
+{
+   switch(data[0])
+      {
+       case 0://stop the watchdog
+                outw(0x0,devpriv->i_IobaseAddon+ APCI1516_WATCHDOG_ENABLEDISABLE);//disable the watchdog
+                break;
+       case 1://start the watchdog
+               outw(0x0001,devpriv->i_IobaseAddon+ APCI1516_WATCHDOG_ENABLEDISABLE);
+               break;
+       case 2://Software trigger  
+              outw(0x0201,devpriv->i_IobaseAddon+ APCI1516_WATCHDOG_ENABLEDISABLE);
+              break;
+       default:printk("\nSpecified functionality does not exist\n");
+              return -EINVAL;
+       }// switch(data[0])        
+return insn->n;
+}
+/*
++----------------------------------------------------------------------------+
+| Function   Name   : int i_APCI1516_ReadWatchdog                            |
+|                      (comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,
+                    lsampl_t *data);                                        |
++----------------------------------------------------------------------------+
+| Task              : Read The Watchdog                                      |
++----------------------------------------------------------------------------+
+| Input Parameters  :   comedi_device *dev      : Driver handle              |
+|                     comedi_subdevice *s,   :pointer to subdevice structure
+                      comedi_insn *insn      :pointer to insn structure      |
+|                     lsampl_t *data          : Data Pointer to read status  |
++----------------------------------------------------------------------------+
+| Output Parameters :  --                                                                                                       |
++----------------------------------------------------------------------------+
+| Return Value      : TRUE  : No error occur                                 |
+|                          : FALSE : Error occur. Return the error          |
+|                                                                               |
++----------------------------------------------------------------------------+
+*/
+
+int i_APCI1516_ReadWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data)
+ {
+ data[0]= inw(devpriv->i_IobaseAddon+APCI1516_WATCHDOG_STATUS)&0x1; 
+return insn->n;
+}
+/*
++----------------------------------------------------------------------------+
+| Function   Name   : int i_APCI1516_Reset(comedi_device *dev)               |                                                                                                          |
++----------------------------------------------------------------------------+
+| Task              :resets all the registers                                |
++----------------------------------------------------------------------------+
+| Input Parameters  : comedi_device *dev
++----------------------------------------------------------------------------+
+| Output Parameters :  --                                                                                                       |
++----------------------------------------------------------------------------+
+| Return Value      :                                                        |
+|                                                                               |
++----------------------------------------------------------------------------+
+*/
+         
+INT i_APCI1516_Reset(comedi_device *dev) 
+{
+  outw(0x0 ,devpriv->iobase+APCI1516_DIGITAL_OP);//RESETS THE DIGITAL OUTPUTS
+  outw(0x0,devpriv->i_IobaseAddon+ APCI1516_WATCHDOG_ENABLEDISABLE);
+ outw(0x0,devpriv->i_IobaseAddon+APCI1516_WATCHDOG_RELOAD_VALUE);
+ outw(0x0,devpriv->i_IobaseAddon+APCI1516_WATCHDOG_RELOAD_VALUE+2);
+  return 0;
+}        
+
+
index e2888605d548acf32c6a6633c53531c32322efa4..26f9440d92cb6b915375ecc6f6c8c5818050e291 100644 (file)
@@ -1,75 +1,75 @@
-/**\r
-@verbatim\r
-\r
-Copyright (C) 2004,2005  ADDI-DATA GmbH for the source code of this module. \r
-        \r
-        ADDI-DATA GmbH \r
-        Dieselstrasse 3 \r
-        D-77833 Ottersweier \r
-        Tel: +19(0)7223/9493-0 \r
-        Fax: +49(0)7223/9493-92 \r
-        http://www.addi-data-com \r
-        info@addi-data.com \r
-\r
-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.\r
-\r
-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.\r
-\r
-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 USA\r
-\r
-You shoud also find the complete GPL in the COPYING file accompanying this source code.\r
-\r
-@endverbatim\r
-*/\r
-\r
-/*********      Definitions for APCI-1516 card  *****/\r
-\r
-// Card Specific information\r
-#define APCI1516_BOARD_VENDOR_ID                 0x15B8\r
-#define APCI1516_ADDRESS_RANGE                   8\r
-\r
-\r
-//DIGITAL INPUT-OUTPUT DEFINE   \r
-\r
-#define APCI1516_DIGITAL_OP                    4 \r
-#define APCI1516_DIGITAL_OP_RW                         4 \r
-#define APCI1516_DIGITAL_IP                     0  \r
-\r
-\r
-\r
-\r
-// TIMER COUNTER WATCHDOG DEFINES  \r
-\r
-#define ADDIDATA_WATCHDOG                          2\r
-#define APCI1516_DIGITAL_OP_WATCHDOG               0\r
-#define APCI1516_WATCHDOG_ENABLEDISABLE            12\r
-#define APCI1516_WATCHDOG_RELOAD_VALUE             4\r
-#define APCI1516_WATCHDOG_STATUS                   16\r
-\r
-\r
-// Hardware Layer  functions for Apci1516\r
-\r
-\r
-//Digital Input\r
-INT i_APCI1516_ReadMoreDigitalInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);\r
-INT i_APCI1516_Read1DigitalInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);\r
-\r
-\r
-\r
-\r
-//Digital Output\r
-int i_APCI1516_ConfigDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);\r
-INT i_APCI1516_WriteDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);\r
-INT i_APCI1516_ReadDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) ;\r
-\r
-\r
-// TIMER  \r
-// timer value is passed as u seconds\r
-int i_APCI1516_ConfigWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); \r
-int i_APCI1516_StartStopWriteWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); \r
-int i_APCI1516_ReadWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);\r
-\r
-\r
-//reset\r
-INT i_APCI1516_Reset(comedi_device *dev); \r
-\r
+/**
+@verbatim
+
+Copyright (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 USA
+
+You shoud also find the complete GPL in the COPYING file accompanying this source code.
+
+@endverbatim
+*/
+
+/*********      Definitions for APCI-1516 card  *****/
+
+// Card Specific information
+#define APCI1516_BOARD_VENDOR_ID                 0x15B8
+#define APCI1516_ADDRESS_RANGE                   8
+
+
+//DIGITAL INPUT-OUTPUT DEFINE   
+
+#define APCI1516_DIGITAL_OP                    4 
+#define APCI1516_DIGITAL_OP_RW                         4 
+#define APCI1516_DIGITAL_IP                     0  
+
+
+
+
+// TIMER COUNTER WATCHDOG DEFINES  
+
+#define ADDIDATA_WATCHDOG                          2
+#define APCI1516_DIGITAL_OP_WATCHDOG               0
+#define APCI1516_WATCHDOG_ENABLEDISABLE            12
+#define APCI1516_WATCHDOG_RELOAD_VALUE             4
+#define APCI1516_WATCHDOG_STATUS                   16
+
+
+// Hardware Layer  functions for Apci1516
+
+
+//Digital Input
+INT i_APCI1516_ReadMoreDigitalInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);
+INT i_APCI1516_Read1DigitalInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);
+
+
+
+
+//Digital Output
+int i_APCI1516_ConfigDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);
+INT i_APCI1516_WriteDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);
+INT i_APCI1516_ReadDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) ;
+
+
+// TIMER  
+// timer value is passed as u seconds
+int i_APCI1516_ConfigWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); 
+int i_APCI1516_StartStopWriteWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); 
+int i_APCI1516_ReadWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);
+
+
+//reset
+INT i_APCI1516_Reset(comedi_device *dev); 
+
index 28a62e7aee5519a0592373b86b0a4d46a2e9f5ba..b18b17a1de563e75405cfd12a80167c430df47f3 100644 (file)
-/**\r
-@verbatim\r
-\r
-Copyright (C) 2004,2005  ADDI-DATA GmbH for the source code of this module. \r
-        \r
-        ADDI-DATA GmbH \r
-        Dieselstrasse 3 \r
-        D-77833 Ottersweier \r
-        Tel: +19(0)7223/9493-0 \r
-        Fax: +49(0)7223/9493-92 \r
-        http://www.addi-data-com \r
-        info@addi-data.com \r
-\r
-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.\r
-\r
-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.\r
-\r
-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 USA\r
-\r
-You shoud also find the complete GPL in the COPYING file accompanying this source code.\r
-\r
-@endverbatim\r
-*/\r
-/*\r
-    \r
-  +-----------------------------------------------------------------------+\r
-  | (C) ADDI-DATA GmbH          Dieselstraße 3       D-77833 Ottersweier  |\r
-  +-----------------------------------------------------------------------+\r
-  | Tel : +49 (0) 7223/9493-0     | email    : info@addi-data.com         |\r
-  | Fax : +49 (0) 7223/9493-92    | Internet : http://www.addi-data.com   |\r
-  +-------------------------------+---------------------------------------+\r
-  | Project     : APCI-1564       | Compiler   : GCC                      |\r
-  | Module name : hwdrv_apci1564.c| Version    : 2.96                     |\r
-  +-------------------------------+---------------------------------------+\r
-  | Project manager: Eric Stolz   | Date       :  02/12/2002              |\r
-  +-------------------------------+---------------------------------------+\r
-  | Description :   Hardware Layer Acces For APCI-1564                    |\r
-  +-----------------------------------------------------------------------+\r
-  |                             UPDATES                                   |\r
-  +----------+-----------+------------------------------------------------+\r
-  |   Date   |   Author  |          Description of updates                |\r
-  +----------+-----------+------------------------------------------------+\r
-  |          |           |                                                |\r
-  |          |           |                                                |\r
-  |          |           |                                                |\r
-  +----------+-----------+------------------------------------------------+\r
-*/\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-|                               Included files                               |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-#include <linux/delay.h>\r
-#include "hwdrv_apci1564.h"\r
-\r
-//Global variables\r
-UINT ui_InterruptStatus_1564=0 ;\r
-UINT ui_InterruptData,ui_Type;\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function   Name   : int i_APCI1564_ConfigDigitalInput                      |\r
-|                        (comedi_device *dev,comedi_subdevice *s,               | \r
-|                      comedi_insn *insn,lsampl_t *data)                     |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Configures the digital input Subdevice                 |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : comedi_device *dev : Driver handle                     |\r
-|                     lsampl_t *data         : Data Pointer contains         |\r
-|                                          configuration parameters as below |\r
-|                                                                            | \r
-|                        data[0]            : 1 Enable  Digital Input Interrupt |      \r
-|                                                                 0 Disable Digital Input Interrupt | \r
-|                        data[1]            : 0 ADDIDATA Interrupt OR LOGIC     | \r
-|                                                               : 1 ADDIDATA Interrupt AND LOGIC    | \r
-|                        data[2]                        : Interrupt mask for the mode 1         | \r
-|                        data[3]                        : Interrupt mask for the mode 2         |\r
-|                                                                                                                                       |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters :  --                                                                                                       |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      : TRUE  : No error occur                                 |\r
-|                          : FALSE : Error occur. Return the error          |\r
-|                                                                               |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-INT i_APCI1564_ConfigDigitalInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) \r
-{\r
-   devpriv->tsk_Current=current;\r
-   /*******************************/\r
-   /* Set the digital input logic */\r
-   /*******************************/\r
-   if  ( data[0] == ADDIDATA_ENABLE)\r
-      {\r
-      data[2]=data[2]<<4;\r
-      data[3]=data[3]<<4;\r
-      outl (data[2] , devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP + APCI1564_DIGITAL_IP_INTERRUPT_MODE1);\r
-      outl (data[3] , devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP + APCI1564_DIGITAL_IP_INTERRUPT_MODE2);\r
-      if  (data[1] == ADDIDATA_OR)\r
-         {\r
-         outl(0x4 ,devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP + APCI1564_DIGITAL_IP_IRQ);\r
-         } // if  (data[1] == ADDIDATA_OR)\r
-      else\r
-         { \r
-         outl(0x6 ,devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP + APCI1564_DIGITAL_IP_IRQ);\r
-         } // else if  (data[1] == ADDIDATA_OR)\r
-      } // if  (data[0] == ADDIDATA_ENABLE)\r
-   else\r
-      {\r
-      outl (0x0, devpriv->i_IobaseAmcc +APCI1564_DIGITAL_IP +APCI1564_DIGITAL_IP_INTERRUPT_MODE1);\r
-      outl (0x0, devpriv->i_IobaseAmcc +APCI1564_DIGITAL_IP +APCI1564_DIGITAL_IP_INTERRUPT_MODE2);\r
-      outl(0x0 ,devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP +APCI1564_DIGITAL_IP_IRQ);\r
-      } // else if  (data[0] == ADDIDATA_ENABLE)\r
-  \r
-   return insn->n;\r
-}\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function   Name   : int i_APCI1564_Read1DigitalInput                       |\r
-|                        (comedi_device *dev,comedi_subdevice *s,               |\r
-|                      comedi_insn *insn,lsampl_t *data)                     |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Return the status of the digital input                 |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : comedi_device *dev      : Driver handle                |\r
-|                            UINT ui_Channel : Channel number to read       |\r
-|                     lsampl_t *data          : Data Pointer to read status  |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters :  --                                                                                                       |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      : TRUE  : No error occur                                 |\r
-|                          : FALSE : Error occur. Return the error          |\r
-|                                                                               |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-INT i_APCI1564_Read1DigitalInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data)\r
-{\r
-   UINT ui_TmpValue=0;\r
-   UINT ui_Channel;\r
-   \r
-   ui_Channel=CR_CHAN(insn->chanspec);\r
-   if  (ui_Channel >= 0 && ui_Channel <=31)\r
-      {\r
-      ui_TmpValue=(UINT) inl(devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP );\r
-      //  since only 1 channel reqd  to bring it to last bit it is rotated \r
-      //  8 +(chan - 1) times then ANDed with 1 for last bit. \r
-      *data = (ui_TmpValue >> ui_Channel)&0x1 ;\r
-      } // if  (ui_Channel >= 0 && ui_Channel <=31)\r
-   else \r
-      {\r
-      comedi_error(dev,"Not a valid channel number !!! \n");  \r
-      return -EINVAL;   // "sorry channel spec wrong "\r
-      }  //else if  (ui_Channel >= 0 && ui_Channel <=31)\r
-   return insn->n;\r
-}\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function   Name   : int i_APCI1564_ReadMoreDigitalInput                    |\r
-|                        (comedi_device *dev,comedi_subdevice *s,               |\r
-|                     comedi_insn *insn,lsampl_t *data)                      |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Return the status of the Requested digital inputs      |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : comedi_device *dev      : Driver handle                |\r
-|                     UINT ui_NoOfChannels    : No Of Channels To be Read    |\r
-|                      UINT *data             : Data Pointer to read status  |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters :  --                                                                                                       |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      : TRUE  : No error occur                                 |\r
-|                          : FALSE : Error occur. Return the error          |\r
-|                                                                               |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-INT i_APCI1564_ReadMoreDigitalInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data)\r
-{\r
-   UINT ui_PortValue=data[0];\r
-   UINT ui_Mask=0;\r
-   UINT ui_NoOfChannels;\r
-   \r
-   ui_NoOfChannels=CR_CHAN(insn->chanspec);\r
-   if  (data[1]==0)\r
-      {\r
-      *data=(UINT)inl(devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP );\r
-      switch (ui_NoOfChannels)\r
-        {\r
-        case 2: ui_Mask=3;\r
-                 *data=(*data >>(2*ui_PortValue))&ui_Mask; \r
-                 break;\r
-        case 4: ui_Mask=15;\r
-                 *data=(*data >>(4*ui_PortValue))&ui_Mask; \r
-                break;\r
-        case 8: ui_Mask=255;\r
-                *data=(*data >>(8*ui_PortValue))&ui_Mask;  \r
-                 break;\r
-         case 16:ui_Mask=65535;\r
-                 *data=(*data >>(16*ui_PortValue))&ui_Mask;\r
-                 break;\r
-         case 31:break;\r
-         default:\r
-                comedi_error(dev,"Not a valid Channel number !!!\n");  \r
-               return -EINVAL;   // "sorry channel spec wrong "  \r
-                break;\r
-         } // switch  (ui_NoOfChannels)\r
-      } // if  (data[1]==0)\r
-   else\r
-      {\r
-      if  (data[1]==1)\r
-         {\r
-         *data=ui_InterruptStatus_1564;\r
-         } // if  (data[1]==1)\r
-      } // else if  (data[1]==0)   \r
-   return insn->n;\r
-}\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function   Name   : int i_APCI1564_ConfigDigitalOutput                     |\r
-|                        (comedi_device *dev,comedi_subdevice *s,               | \r
-|                      comedi_insn *insn,lsampl_t *data)                     |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Configures The Digital Output Subdevice.               |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : comedi_device *dev : Driver handle                     |\r
-|                     UINT *data         : Data Pointer contains             |\r
-|                                          configuration parameters as below |\r
-|                                                                            | \r
-|                                        data[1]            : 1 Enable  VCC  Interrupt  |      \r
-|                                                                                 0 Disable VCC  Interrupt  | \r
-|                                        data[2]            : 1 Enable  CC  Interrupt   |      \r
-|                                                                                 0 Disable CC  Interrupt   | \r
-|                                                                                                                                       |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters :  --                                                                                                       |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      : TRUE  : No error occur                                 |\r
-|                          : FALSE : Error occur. Return the error          |\r
-|                                                                               |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-INT i_APCI1564_ConfigDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data)\r
-{\r
-   ULONG  ul_Command = 0; \r
-  \r
-   if  ((data[0]!=0) && (data[0]!=1)) \r
-      {   \r
-      comedi_error(dev,"Not a valid Data !!! ,Data should be 1 or 0\n");  \r
-      return -EINVAL;\r
-      } // if  ((data[0]!=0) && (data[0]!=1)) \r
-   if  (data[0])\r
-      {\r
-      devpriv->b_OutputMemoryStatus = ADDIDATA_ENABLE ; \r
-      } // if  (data[0])\r
-   else\r
-      {\r
-      devpriv->b_OutputMemoryStatus = ADDIDATA_DISABLE;\r
-      } // else if  (data[0])\r
-   if  (data[1] == ADDIDATA_ENABLE)\r
-      {\r
-      ul_Command = ul_Command | 0x1;\r
-      } // if  (data[1] == ADDIDATA_ENABLE)\r
-   else\r
-      {\r
-      ul_Command = ul_Command & 0xFFFFFFFE;\r
-      } // else if  (data[1] == ADDIDATA_ENABLE)\r
-   if  (data[2] == ADDIDATA_ENABLE)\r
-      {\r
-      ul_Command = ul_Command | 0x2;\r
-      } // if  (data[2] == ADDIDATA_ENABLE)\r
-   else\r
-      {\r
-      ul_Command = ul_Command & 0xFFFFFFFD;\r
-      } // else if  (data[2] == ADDIDATA_ENABLE)\r
-   outl( ul_Command , devpriv->i_IobaseAmcc+APCI1564_DIGITAL_OP+APCI1564_DIGITAL_OP_INTERRUPT);\r
-   ui_InterruptData=inl( devpriv->i_IobaseAmcc+APCI1564_DIGITAL_OP+APCI1564_DIGITAL_OP_INTERRUPT); \r
-   devpriv->tsk_Current=current;  \r
-   return insn->n;\r
-}\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function   Name   : int i_APCI1564_WriteDigitalOutput                      |\r
-|                        (comedi_device *dev,comedi_subdevice *s,               | \r
-|                      comedi_insn *insn,lsampl_t *data)                     |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Writes port value  To the selected port                |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : comedi_device *dev      : Driver handle                |\r
-|                     UINT ui_NoOfChannels    : No Of Channels To Write      |\r
-|                     UINT *data              : Data Pointer to read status  |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters :  --                                                                                                       |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      : TRUE  : No error occur                                 |\r
-|                          : FALSE : Error occur. Return the error          |\r
-|                                                                               |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-INT i_APCI1564_WriteDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) {\r
-   UINT ui_Temp,ui_Temp1;\r
-   UINT ui_NoOfChannel;\r
-   \r
-   ui_NoOfChannel=CR_CHAN(insn->chanspec);\r
-   if  (devpriv->b_OutputMemoryStatus )\r
-      {\r
-      ui_Temp=inl(devpriv->i_IobaseAmcc + APCI1564_DIGITAL_OP + APCI1564_DIGITAL_OP_RW);\r
-      } // if  (devpriv->b_OutputMemoryStatus )\r
-   else\r
-      {\r
-      ui_Temp=0;\r
-      } // else if  (devpriv->b_OutputMemoryStatus )\r
-   if  (data[3]==0)\r
-      { \r
-      if  (data[1]==0)\r
-         {\r
-         data[0]=(data[0] << ui_NoOfChannel)|ui_Temp;\r
-         outl(data[0],devpriv->i_IobaseAmcc + APCI1564_DIGITAL_OP + APCI1564_DIGITAL_OP_RW);  \r
-         } // if  (data[1]==0) \r
-      else\r
-         {\r
-         if  (data[1]==1)\r
-            { \r
-            switch (ui_NoOfChannel)\r
-              {\r
-               case 2: data[0]=(data[0] << (2*data[2]))|ui_Temp; \r
-                      break;\r
-               case 4: data[0]=(data[0] << (4*data[2]))|ui_Temp;\r
-                      break;\r
-               case 8: data[0]=(data[0] <<(8*data[2]))|ui_Temp;  \r
-                       break;\r
-               case 16: data[0]=(data[0] <<(16*data[2]))|ui_Temp;\r
-                        break;\r
-               case 31: data[0]=data[0]|ui_Temp; \r
-                        break;\r
-               default: comedi_error(dev," chan spec wrong");\r
-                        return -EINVAL;   // "sorry channel spec wrong "  \r
-               } // switch (ui_NoOfChannels)\r
-            outl(data[0],devpriv->i_IobaseAmcc + APCI1564_DIGITAL_OP + APCI1564_DIGITAL_OP_RW);\r
-            } // if  (data[1]==1)\r
-         else\r
-            {\r
-            printk("\nSpecified channel not supported\n");\r
-            } // else if  (data[1]==1)\r
-         } // else if (data[1]==0)\r
-      }//if(data[3]==0)\r
-   else\r
-      {\r
-      if  (data[3]==1)\r
-         {\r
-         if  (data[1]==0)\r
-            {\r
-            data[0]=~data[0]&0x1;\r
-            ui_Temp1=1;\r
-            ui_Temp1=ui_Temp1<<ui_NoOfChannel;\r
-            ui_Temp=ui_Temp|ui_Temp1;  \r
-            data[0]=(data[0] << ui_NoOfChannel)^0xffffffff;\r
-            data[0]=data[0]& ui_Temp; \r
-            outl(data[0],devpriv->i_IobaseAmcc + APCI1564_DIGITAL_OP + APCI1564_DIGITAL_OP_RW);  \r
-            } // if  (data[1]==0) \r
-         else\r
-            {\r
-            if  (data[1]==1)\r
-               { \r
-               switch (ui_NoOfChannel)\r
-                 {\r
-                 case 2: data[0]=~data[0]&0x3; \r
-                          ui_Temp1=3;\r
-                          ui_Temp1=ui_Temp1<<2*data[2];\r
-                          ui_Temp=ui_Temp|ui_Temp1;   \r
-                          data[0]=((data[0] << (2*data[2]))^0xffffffff)& ui_Temp; \r
-                         break;\r
-                 case 4: data[0]=~data[0]&0xf;\r
-                          ui_Temp1=15;\r
-                          ui_Temp1=ui_Temp1<<4*data[2];\r
-                          ui_Temp=ui_Temp|ui_Temp1;    \r
-                          data[0]=((data[0] << (4*data[2]))^0xffffffff)&ui_Temp;\r
-                         break;\r
-                  case 8: data[0]=~data[0]&0xff;\r
-                          ui_Temp1=255;\r
-                          ui_Temp1=ui_Temp1<<8*data[2];\r
-                          ui_Temp=ui_Temp|ui_Temp1;    \r
-                          data[0]=((data[0] << (8*data[2]))^0xffffffff)&ui_Temp;  \r
-                         break;\r
-                  case 16: data[0]=~data[0]&0xffff;\r
-                           ui_Temp1=65535;\r
-                           ui_Temp1=ui_Temp1<<16*data[2];\r
-                           ui_Temp=ui_Temp|ui_Temp1;    \r
-                           data[0]=((data[0] << (16*data[2]))^0xffffffff)&ui_Temp;  \r
-                          break;\r
-                  case 31: break;\r
-                  default: comedi_error(dev," chan spec wrong");\r
-                           return -EINVAL;   // "sorry channel spec wrong "  \r
-                  }//switch(ui_NoOfChannels)\r
-               outl(data[0],devpriv->i_IobaseAmcc + APCI1564_DIGITAL_OP + APCI1564_DIGITAL_OP_RW);\r
-               } // if  (data[1]==1)\r
-            else\r
-               {\r
-               printk("\nSpecified channel not supported\n");\r
-               } // else if  (data[1]==1)\r
-            } // else if  (data[1]==0)\r
-         } // if  (data[3]==1);\r
-      else\r
-         {\r
-         printk("\nSpecified functionality does not exist\n");\r
-         return -EINVAL;\r
-         } // else if (data[3]==1)\r
-      } // else if (data[3]==0) \r
-   return insn->n;\r
-}\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function   Name   : int i_APCI1564_ReadDigitalOutput                       |\r
-|                        (comedi_device *dev,comedi_subdevice *s,               | \r
-|                      comedi_insn *insn,lsampl_t *data)                     |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Read  value  of the selected channel or port           |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : comedi_device *dev      : Driver handle                |\r
-|                     UINT ui_NoOfChannels    : No Of Channels To read       |\r
-|                     UINT *data              : Data Pointer to read status  |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters :  --                                                                                                       |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      : TRUE  : No error occur                                 |\r
-|                          : FALSE : Error occur. Return the error          |\r
-|                                                                               |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-INT i_APCI1564_ReadDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) \r
-{\r
-   UINT ui_Temp;\r
-   UINT ui_NoOfChannel;\r
-\r
-   ui_NoOfChannel=CR_CHAN(insn->chanspec);\r
-   ui_Temp=data[0];\r
-   *data=inl(devpriv->i_IobaseAmcc+APCI1564_DIGITAL_OP+APCI1564_DIGITAL_OP_RW);\r
-   if  (ui_Temp==0)\r
-      {\r
-      *data=(*data >> ui_NoOfChannel)&0x1; \r
-      } // if  (ui_Temp==0)\r
-   else\r
-      {\r
-      if  (ui_Temp==1)\r
-         {\r
-         switch (ui_NoOfChannel)\r
-          {\r
-           case 2: \r
-                    *data=(*data >>(2*data[1]))&3; \r
-                    break;\r
-\r
-           case 4: \r
-                    *data=(*data >>(4*data[1]))&15; \r
-                   break;\r
\r
-          case 8:  \r
-                   *data=(*data >>(8*data[1]))&255;  \r
-                    break;\r
\r
-           case 16: \r
-                    *data=(*data >>(16*data[1]))&65535;\r
-                    break;\r
-\r
-           case 31: break;\r
-\r
-           default:\r
-                   comedi_error(dev," chan spec wrong");\r
-                   return -EINVAL;   // "sorry channel spec wrong "  \r
-                    break;\r
-           } // switch(ui_NoOfChannels)    \r
-        } // if  (ui_Temp==1)\r
-     else\r
-        {\r
-        printk("\nSpecified channel not supported \n");\r
-        } // else if (ui_Temp==1)\r
-     } // else if  (ui_Temp==0)\r
-   return insn->n;\r
-}\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function   Name   : int i_APCI1564_ConfigTimerCounterWatchdog              |\r
-|                        (comedi_device *dev,comedi_subdevice *s,               | \r
-|                      comedi_insn *insn,lsampl_t *data)                     |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Configures The Timer , Counter or Watchdog             |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : comedi_device *dev : Driver handle                     |\r
-|                     UINT *data         : Data Pointer contains             |\r
-|                                          configuration parameters as below |\r
-|                                                                            | \r
-|                                        data[0]            : 0 Configure As Timer      |      \r
-|                                                                                 1 Configure As Counter    |                            \r
-|                                                                                 2 Configure As Watchdog   |                            \r
-|                                        data[1]            : 1 Enable  Interrupt       |      \r
-|                                                                                 0 Disable Interrupt       |                           \r
-|                                        data[2]            : Time Unit                 |\r
-|                                        data[3]                        : Reload Value                      |                            \r
-|                                        data[4]            : Timer Mode                |                            \r
-|                                        data[5]                        : Timer Counter Watchdog Number|     \r
-                              data[6]            :  Counter Direction \r
-+----------------------------------------------------------------------------+\r
-| Output Parameters :  --                                                                                                       |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      : TRUE  : No error occur                                 |\r
-|                          : FALSE : Error occur. Return the error          |\r
-|                                                                               |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-INT i_APCI1564_ConfigTimerCounterWatchdog (comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) \r
-{\r
-   ULONG  ul_Command1 = 0; \r
-   devpriv->tsk_Current=current;\r
-   if  (data[0]==ADDIDATA_WATCHDOG)\r
-      {\r
-      devpriv->b_TimerSelectMode = ADDIDATA_WATCHDOG;   \r
-     \r
-      //Disable the watchdog\r
-      outl(0x0,devpriv->i_IobaseAmcc+ APCI1564_DIGITAL_OP_WATCHDOG+ APCI1564_TCW_PROG); \r
-     //Loading the Reload value\r
-      outl(data[3],devpriv->i_IobaseAmcc+APCI1564_DIGITAL_OP_WATCHDOG+APCI1564_TCW_RELOAD_VALUE);  \r
-      } // if  (data[0]==ADDIDATA_WATCHDOG)\r
-   else if  (data[0]==ADDIDATA_TIMER)\r
-      {\r
-      //First Stop The Timer \r
-      ul_Command1 =inl(devpriv->i_IobaseAmcc+ APCI1564_TIMER+ APCI1564_TCW_PROG);\r
-      ul_Command1 =ul_Command1 & 0xFFFFF9FEUL;\r
-      outl(ul_Command1,devpriv->i_IobaseAmcc+ APCI1564_TIMER+ APCI1564_TCW_PROG);//Stop The Timer\r
-\r
-      devpriv->b_TimerSelectMode =ADDIDATA_TIMER;\r
-      if  (data[1]==1)\r
-         { \r
-         outl(0x02,devpriv->i_IobaseAmcc+ APCI1564_TIMER+ APCI1564_TCW_PROG);//Enable TIMER int & DISABLE ALL THE OTHER int SOURCES\r
-         outl(0x0,devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP + APCI1564_DIGITAL_IP_IRQ);\r
-         outl(0x0,devpriv->i_IobaseAmcc + APCI1564_DIGITAL_OP + APCI1564_DIGITAL_OP_IRQ); \r
-         outl(0x0,devpriv->i_IobaseAmcc + APCI1564_DIGITAL_OP_WATCHDOG + APCI1564_TCW_IRQ);\r
-         outl(0x0,devpriv->iobase+APCI1564_COUNTER1 + APCI1564_TCW_IRQ);\r
-         outl(0x0,devpriv->iobase+APCI1564_COUNTER2 + APCI1564_TCW_IRQ);\r
-         outl(0x0,devpriv->iobase+APCI1564_COUNTER3 + APCI1564_TCW_IRQ);\r
-         outl(0x0,devpriv->iobase+APCI1564_COUNTER4 + APCI1564_TCW_IRQ);\r
-         } // if  (data[1]==1)\r
-      else\r
-         { \r
-         outl(0x0,devpriv->i_IobaseAmcc+ APCI1564_TIMER+ APCI1564_TCW_PROG);//disable Timer interrupt\r
-         } // else if  (data[1]==1)\r
-    \r
-      // Loading Timebase\r
-     \r
-         outl(data[2],devpriv->i_IobaseAmcc+APCI1564_TIMER+APCI1564_TCW_TIMEBASE);\r
-        \r
-      //Loading the Reload value\r
-      outl(data[3],devpriv->i_IobaseAmcc+APCI1564_TIMER+APCI1564_TCW_RELOAD_VALUE);\r
-    \r
-      ul_Command1 =inl(devpriv->i_IobaseAmcc+ APCI1564_TIMER+ APCI1564_TCW_PROG);\r
-      ul_Command1 = (ul_Command1 & 0xFFF719E2UL) |  2UL << 13UL | 0x10UL;\r
-      outl(ul_Command1,devpriv->i_IobaseAmcc+ APCI1564_TIMER+ APCI1564_TCW_PROG);//mode 2\r
-      } // else if  (data[0]==ADDIDATA_TIMER)\r
-   else if  (data[0]==ADDIDATA_COUNTER)\r
-      {\r
-      devpriv->b_TimerSelectMode =ADDIDATA_COUNTER;\r
-      devpriv->b_ModeSelectRegister=data[5];\r
-\r
-      //First Stop The Counter\r
-      ul_Command1 =inl(devpriv->iobase+((data[5]-1)*0x20)+APCI1564_TCW_PROG); \r
-      ul_Command1 =ul_Command1 & 0xFFFFF9FEUL;\r
-      outl(ul_Command1,devpriv->iobase+((data[5]-1)*0x20)+APCI1564_TCW_PROG);//Stop The Timer\r
-\r
-      /************************/\r
-      /* Set the reload value */\r
-      /************************/\r
-      outl(data[3] , devpriv->iobase+((data[5]-1)*0x20)+APCI1564_TCW_RELOAD_VALUE);\r
\r
-      /******************************/\r
-      /* Set the mode :             */\r
-      /* - Disable the hardware     */\r
-      /* - Disable the counter mode */\r
-      /* - Disable the warning      */\r
-      /* - Disable the reset        */\r
-      /* - Disable the timer mode   */\r
-      /* - Enable the counter mode  */\r
-      /******************************/\r
-      ul_Command1 = (ul_Command1 & 0xFFFC19E2UL) | 0x80000UL | (ULONG) ((ULONG) data[4] << 16UL);\r
-      outl(ul_Command1 , devpriv->iobase+((data[5]-1)*0x20)+APCI1564_TCW_PROG); \r
-\r
-      // Enable or Disable Interrupt \r
-      ul_Command1= (ul_Command1 & 0xFFFFF9FD) | (data[1] << 1);                 \r
-      outl(ul_Command1 , devpriv->iobase+((data[5]-1)*0x20)+APCI1564_TCW_PROG);\r
\r
-      /*****************************/\r
-      /* Set the Up/Down selection */\r
-      /*****************************/\r
-      ul_Command1 = (ul_Command1 & 0xFFFBF9FFUL) |  (data[6] << 18);\r
-      outl(ul_Command1 , devpriv->iobase+((data[5]-1)*0x20)+APCI1564_TCW_PROG);  \r
-      } // else if  (data[0]==ADDIDATA_COUNTER)\r
-   else   \r
-      {\r
-      printk(" Invalid subdevice.");\r
-      } // else if  (data[0]==ADDIDATA_WATCHDOG) \r
-   \r
-   return insn->n;\r
-}\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function   Name   : int i_APCI1564_StartStopWriteTimerCounterWatchdog      |\r
-|                        (comedi_device *dev,comedi_subdevice *s,               | \r
-|                      comedi_insn *insn,lsampl_t *data)                     |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Start / Stop The Selected Timer , Counter or Watchdog  |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : comedi_device *dev : Driver handle                     |\r
-|                     UINT *data         : Data Pointer contains             |\r
-|                                          configuration parameters as below |\r
-|                                                                            | \r
-|                                        data[0]            : 0 Timer                   |\r
-|                                                                                 1 Counter                 |  \r
-|                                                                                 2 Watchdog                    |                             |                                                 data[1]            : 1 Start                   |       \r
-|                                                                                 0 Stop                    |       \r
-|                                                  2 Trigger                    |      \r
-|                                                    Clear (Only Counter)    |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters :  --                                                                                                       |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      : TRUE  : No error occur                                 |\r
-|                          : FALSE : Error occur. Return the error          |\r
-|                                                                               |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-INT i_APCI1564_StartStopWriteTimerCounterWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data)\r
-{\r
-   ULONG  ul_Command1 = 0; \r
-   if  (devpriv->b_TimerSelectMode==ADDIDATA_WATCHDOG)\r
-      {\r
-      switch (data[1])\r
-         {\r
-         case 0:  //stop the watchdog\r
-                  outl(0x0,devpriv->i_IobaseAmcc+ APCI1564_DIGITAL_OP_WATCHDOG+ APCI1564_TCW_PROG );//disable the watchdog\r
-                  break;\r
-         case 1:  //start the watchdog\r
-                  outl(0x0001,devpriv->i_IobaseAmcc+ APCI1564_DIGITAL_OP_WATCHDOG+ APCI1564_TCW_PROG);\r
-                  break;\r
-         case 2:  //Software trigger  \r
-                  outl(0x0201,devpriv->i_IobaseAmcc+ APCI1564_DIGITAL_OP_WATCHDOG+ APCI1564_TCW_PROG);\r
-                  break;\r
-         default: printk("\nSpecified functionality does not exist\n");\r
-                 return -EINVAL;\r
-         }  // switch (data[1])        \r
-      } // if  (devpriv->b_TimerSelectMode==ADDIDATA_WATCHDOG)   \r
-   if  (devpriv->b_TimerSelectMode==ADDIDATA_TIMER)\r
-      {\r
-      if  (data[1]==1) \r
-         { \r
-         ul_Command1=inl(devpriv->i_IobaseAmcc+ APCI1564_TIMER+ APCI1564_TCW_PROG);\r
-         ul_Command1=(ul_Command1& 0xFFFFF9FFUL) | 0x1UL;\r
-       \r
-         //Enable the Timer\r
-         outl(ul_Command1,devpriv->i_IobaseAmcc+ APCI1564_TIMER+ APCI1564_TCW_PROG);\r
-         } // if  (data[1]==1)\r
-      else if(data[1]==0)\r
-         {\r
-         //Stop The Timer\r
-          \r
-         ul_Command1=inl(devpriv->i_IobaseAmcc+ APCI1564_TIMER+ APCI1564_TCW_PROG);\r
-         ul_Command1 =ul_Command1 & 0xFFFFF9FEUL;\r
-         outl(ul_Command1,devpriv->i_IobaseAmcc+ APCI1564_TIMER+ APCI1564_TCW_PROG);\r
-         } // else if(data[1]==0)\r
-      } // if  (devpriv->b_TimerSelectMode==ADDIDATA_TIMER)\r
-   if  (devpriv->b_TimerSelectMode==ADDIDATA_COUNTER)\r
-      {\r
-      ul_Command1=inl(devpriv->iobase+((devpriv->b_ModeSelectRegister-1)*0x20)+APCI1564_TCW_PROG);\r
-      if  (data[1] == 1) \r
-         {\r
-         //Start the Counter subdevice \r
-         ul_Command1= (ul_Command1 & 0xFFFFF9FFUL) | 0x1UL;\r
-         } // if  (data[1] == 1)\r
-      else if (data[1] == 0)\r
-         {\r
-         // Stops the Counter subdevice \r
-        ul_Command1 = 0;\r
-         \r
-         } // else if  (data[1] == 0)\r
-      else if (data[1] == 2)\r
-         {\r
-         // Clears the Counter subdevice\r
-         ul_Command1= (ul_Command1 & 0xFFFFF9FFUL)|0x400;\r
-         } // else if  (data[1] == 3)\r
-      outl(ul_Command1 , devpriv->iobase+((devpriv->b_ModeSelectRegister-1)*0x20)+APCI1564_TCW_PROG);\r
-      } // if (devpriv->b_TimerSelectMode==ADDIDATA_COUNTER)\r
-   return insn->n;\r
-}\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function   Name   : int i_APCI1564_ReadTimerCounterWatchdog                |\r
-|                        (comedi_device *dev,comedi_subdevice *s,               | \r
-|                      comedi_insn *insn,lsampl_t *data)                     |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Read The Selected Timer , Counter or Watchdog          |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : comedi_device *dev : Driver handle                     |\r
-|                     UINT *data         : Data Pointer contains             |\r
-|                                          configuration parameters as below |\r
-|                                                                            | \r
-                                       \r
-+----------------------------------------------------------------------------+\r
-| Output Parameters :  --                                                                                                       |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      : TRUE  : No error occur                                 |\r
-|                          : FALSE : Error occur. Return the error          |\r
-|                                                                               |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-INT i_APCI1564_ReadTimerCounterWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data)\r
-{\r
-   ULONG  ul_Command1 = 0; \r
-\r
-   if  (devpriv->b_TimerSelectMode==ADDIDATA_WATCHDOG)\r
-      { \r
-      // Stores the status of the Watchdog \r
-      data[0]= inl(devpriv->i_IobaseAmcc + APCI1564_DIGITAL_OP_WATCHDOG + APCI1564_TCW_TRIG_STATUS)&0x1;\r
-      data[1]= inl(devpriv->i_IobaseAmcc + APCI1564_DIGITAL_OP_WATCHDOG);\r
-      } // if  (devpriv->b_TimerSelectMode==ADDIDATA_WATCHDOG)\r
-   else if  (devpriv->b_TimerSelectMode==ADDIDATA_TIMER) \r
-      {\r
-      // Stores the status of the Timer \r
-      data[0]= inl(devpriv->i_IobaseAmcc+APCI1564_TIMER+APCI1564_TCW_TRIG_STATUS)&0x1; \r
-\r
-      // Stores the Actual value of the Timer \r
-      data[1]= inl(devpriv->i_IobaseAmcc + APCI1564_TIMER); \r
-      }  // else if  (devpriv->b_TimerSelectMode==ADDIDATA_TIMER)\r
-   else  if  (devpriv->b_TimerSelectMode==ADDIDATA_COUNTER) \r
-      {\r
-      // Read the Counter Actual Value. \r
-      data[0] = inl(devpriv->iobase+((devpriv->b_ModeSelectRegister-1)*0x20)+APCI1564_TCW_SYNC_ENABLEDISABLE);\r
-      ul_Command1 =  inl(devpriv->iobase+((devpriv->b_ModeSelectRegister-1)*0x20)+APCI1564_TCW_TRIG_STATUS);\r
-\r
-      /***********************************/\r
-      /* Get the software trigger status */\r
-      /***********************************/\r
-      data[1]= (BYTE) ((ul_Command1 >> 1) & 1);\r
-\r
-      /***********************************/\r
-      /* Get the hardware trigger status */\r
-      /***********************************/\r
-      data[2]= (BYTE) ((ul_Command1 >> 2) & 1);\r
-\r
-      /*********************************/\r
-      /* Get the software clear status */\r
-      /*********************************/\r
-      data[3]= (BYTE) ((ul_Command1 >> 3) & 1);\r
-\r
-      /***************************/\r
-      /* Get the overflow status */\r
-      /***************************/\r
-      data[4]= (BYTE) ((ul_Command1 >> 0) & 1);\r
-      } // else  if  (devpriv->b_TimerSelectMode==ADDIDATA_COUNTER) \r
-  else if ((devpriv->b_TimerSelectMode!=ADDIDATA_TIMER) && (devpriv->b_TimerSelectMode!=ADDIDATA_WATCHDOG)&& (devpriv->b_TimerSelectMode!=ADDIDATA_COUNTER))\r
-     {\r
-     printk ("\n Invalid Subdevice !!!\n");\r
-     } // else if ((devpriv->b_TimerSelectMode!=ADDIDATA_TIMER) && (devpriv->b_TimerSelectMode!=ADDIDATA_WATCHDOG)&& (devpriv->b_TimerSelectMode!=ADDIDATA_COUNTER))\r
-   return insn->n;\r
-}\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function   Name   :  int i_APCI1564_ReadInterruptStatus                    |\r
-|                        (comedi_device *dev,comedi_subdevice *s,               | \r
-|                      comedi_insn *insn,lsampl_t *data)                     |\r
-+----------------------------------------------------------------------------+\r
-| Task              :Reads the interrupt status register                     |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  :                                                        |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters :  --                                                                                                       |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      :                                                        |\r
-|                                                                               |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-int i_APCI1564_ReadInterruptStatus(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data)\r
-{  \r
-    *data=ui_Type;\r
-    return insn->n;\r
-} \r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function   Name   : static void v_APCI1564_Interrupt                                      |\r
-|                                        (int irq , void *d, struct pt_regs *regs)      |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Interrupt handler for the interruptible digital inputs |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : int irq                 : irq number                   |\r
-|                     void *d                 : void pointer                 |\r
-|                     struct pt_regs *regs    : structure pointer            |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters :  --                                                                                                       |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      : TRUE  : No error occur                                 |\r
-|                          : FALSE : Error occur. Return the error          |\r
-|                                                                               |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-static VOID v_APCI1564_Interrupt(int irq,void* d, struct pt_regs *regs) \r
-{\r
-   comedi_device *dev =d;      \r
-   UINT ui_DO, ui_DI;\r
-   UINT ui_Timer;\r
-   UINT ui_C1, ui_C2, ui_C3, ui_C4;\r
-   ULONG ul_Command2=0; \r
-   ui_DI       = inl(devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP + APCI1564_DIGITAL_IP_IRQ) & 0x01;\r
-   ui_DO       = inl(devpriv->i_IobaseAmcc + APCI1564_DIGITAL_OP + APCI1564_DIGITAL_OP_IRQ) & 0x01;\r
-   ui_Timer    = inl(devpriv->i_IobaseAmcc + APCI1564_TIMER+ APCI1564_TCW_IRQ) & 0x01; \r
-   ui_C1=inl(devpriv->iobase + APCI1564_COUNTER1 + APCI1564_TCW_IRQ ) & 0x1;\r
-   ui_C2=inl(devpriv->iobase + APCI1564_COUNTER2 + APCI1564_TCW_IRQ ) & 0x1;\r
-   ui_C3=inl(devpriv->iobase + APCI1564_COUNTER3 + APCI1564_TCW_IRQ ) & 0x1;\r
-   ui_C4=inl(devpriv->iobase + APCI1564_COUNTER4 + APCI1564_TCW_IRQ ) & 0x1;\r
-  if(ui_DI==0 && ui_DO==0 && ui_Timer==0 && ui_C1==0 && ui_C2==0 && ui_C3==0 && ui_C4==0)\r
-      {\r
-       printk("\nInterrupt from unknown source\n");\r
-      }// if(ui_DI==0 && ui_DO==0 && ui_Timer==0 && ui_C1==0 && ui_C2==0 && ui_C3==0 && ui_C4==0)\r
-      \r
-   if  (ui_DI == 1)\r
-      {\r
-      ui_DI = inl(devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP + APCI1564_DIGITAL_IP_IRQ);\r
-      outl(0x0 ,devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP + APCI1564_DIGITAL_IP_IRQ);\r
-      ui_InterruptStatus_1564=inl(devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP + APCI1564_DIGITAL_IP_INTERRUPT_STATUS);\r
-      ui_InterruptStatus_1564=ui_InterruptStatus_1564 & 0X000FFFF0;\r
-      send_sig(SIGIO,devpriv->tsk_Current,0); // send signal to the sample   \r
-      outl(ui_DI ,devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP + APCI1564_DIGITAL_IP_IRQ);//enable the interrupt\r
-      return;\r
-      }\r
-\r
-   if  (ui_DO == 1)\r
-      {\r
-      // Check for Digital Output interrupt Type - 1: Vcc interrupt 2: CC interrupt.\r
-      ui_Type=inl(devpriv->i_IobaseAmcc + APCI1564_DIGITAL_OP + APCI1564_DIGITAL_OP_INTERRUPT_STATUS) & 0x3;     \r
-       //Disable the  Interrupt \r
-      outl(0x0,devpriv->i_IobaseAmcc + APCI1564_DIGITAL_OP + APCI1564_DIGITAL_OP_INTERRUPT);\r
-     \r
-         //Sends signal to user space \r
-        send_sig(SIGIO,devpriv->tsk_Current,0);\r
-      \r
-      }  // if  (ui_DO)\r
-\r
-   if  ((ui_Timer == 1) && (devpriv->b_TimerSelectMode =ADDIDATA_TIMER))\r
-      {\r
-      // Disable Timer Interrupt \r
-      ul_Command2=inl(devpriv->i_IobaseAmcc + APCI1564_TIMER + APCI1564_TCW_PROG);  \r
-      outl(0x0 , devpriv->i_IobaseAmcc + APCI1564_TIMER + APCI1564_TCW_PROG);\r
-\r
-      //Send a signal to from kernel to user space\r
-      send_sig(SIGIO,devpriv->tsk_Current,0); \r
-\r
-      // Enable Timer Interrupt \r
-     \r
-      outl(ul_Command2 , devpriv->i_IobaseAmcc + APCI1564_TIMER + APCI1564_TCW_PROG);\r
-      } // if  ((ui_Timer == 1) && (devpriv->b_TimerSelectMode =ADDIDATA_TIMER))\r
-\r
\r
-   if  ((ui_C1 == 1) && (devpriv->b_TimerSelectMode = ADDIDATA_COUNTER))\r
-      {\r
-      // Disable Counter Interrupt \r
-      ul_Command2=inl(devpriv->iobase + APCI1564_COUNTER1 + APCI1564_TCW_PROG);\r
-      outl(0x0 , devpriv->iobase + APCI1564_COUNTER1 + APCI1564_TCW_PROG);\r
-\r
-      //Send a signal to from kernel to user space\r
-      send_sig(SIGIO,devpriv->tsk_Current,0); \r
-\r
-      // Enable Counter Interrupt \r
-      outl(ul_Command2 , devpriv->iobase + APCI1564_COUNTER1 + APCI1564_TCW_PROG);\r
-      } // if  ((ui_C1 == 1) && (devpriv->b_TimerSelectMode = ADDIDATA_COUNTER))  \r
-\r
-   if  ((ui_C2 == 1) && (devpriv->b_TimerSelectMode =ADDIDATA_COUNTER))\r
-      {\r
-      // Disable Counter Interrupt\r
-      ul_Command2=inl(devpriv->iobase + APCI1564_COUNTER2 + APCI1564_TCW_PROG); \r
-      outl(0x0 , devpriv->iobase + APCI1564_COUNTER2 + APCI1564_TCW_PROG);\r
-\r
-      //Send a signal to from kernel to user space\r
-      send_sig(SIGIO,devpriv->tsk_Current,0); \r
-\r
-      // Enable Counter Interrupt \r
-      outl(ul_Command2 , devpriv->iobase + APCI1564_COUNTER2 + APCI1564_TCW_PROG);\r
-      } // if  ((ui_C2 == 1) && (devpriv->b_TimerSelectMode =ADDIDATA_COUNTER)) \r
-\r
-   if  ((ui_C3 == 1) && (devpriv->b_TimerSelectMode =ADDIDATA_COUNTER))\r
-      {\r
-      // Disable Counter Interrupt \r
-      ul_Command2=inl(devpriv->iobase + APCI1564_COUNTER3 + APCI1564_TCW_PROG); \r
-      outl(0x0 , devpriv->iobase + APCI1564_COUNTER3 + APCI1564_TCW_PROG);\r
-\r
-      //Send a signal to from kernel to user space\r
-      send_sig(SIGIO,devpriv->tsk_Current,0); \r
-\r
-      // Enable Counter Interrupt \r
-      outl(ul_Command2 , devpriv->iobase + APCI1564_COUNTER3 + APCI1564_TCW_PROG);\r
-      } // if ((ui_C3 == 1) && (devpriv->b_TimerSelectMode =ADDIDATA_COUNTER))\r
-\r
-    if ((ui_C4 == 1) && (devpriv->b_TimerSelectMode =ADDIDATA_COUNTER))\r
-      {\r
-      // Disable Counter Interrupt \r
-      ul_Command2=inl(devpriv->iobase + APCI1564_COUNTER4 + APCI1564_TCW_PROG);   \r
-      outl(0x0 , devpriv->iobase + APCI1564_COUNTER4 + APCI1564_TCW_PROG);\r
-\r
-      //Send a signal to from kernel to user space\r
-      send_sig(SIGIO,devpriv->tsk_Current,0); \r
-\r
-      // Enable Counter Interrupt \r
-      outl(ul_Command2 , devpriv->iobase + APCI1564_COUNTER4 + APCI1564_TCW_PROG);\r
-      } // if ((ui_C4 == 1) && (devpriv->b_TimerSelectMode =ADDIDATA_COUNTER))\r
-   return;\r
-}        \r
-         \r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function   Name   : int i_APCI1564_Reset(comedi_device *dev)               |                                                       |\r
-+----------------------------------------------------------------------------+\r
-| Task              :resets all the registers                                |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : comedi_device *dev\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters :  --                                                                                                       |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      :                                                        |\r
-|                                                                               |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-         \r
-INT i_APCI1564_Reset(comedi_device *dev) \r
-{\r
-   outl(0x0 ,devpriv->i_IobaseAmcc+APCI1564_DIGITAL_IP_IRQ);//disable the interrupts\r
-   inl(devpriv->i_IobaseAmcc+APCI1564_DIGITAL_IP_INTERRUPT_STATUS);//Reset the interrupt status register         \r
-   outl (0x0 , devpriv->i_IobaseAmcc+APCI1564_DIGITAL_IP_INTERRUPT_MODE1);//Disable the and/or interrupt\r
-   outl (0x0 , devpriv->i_IobaseAmcc+APCI1564_DIGITAL_IP_INTERRUPT_MODE2);\r
-   devpriv->b_DigitalOutputRegister=0;\r
-   ui_Type=0;\r
-   outl(0x0,devpriv->i_IobaseAmcc+APCI1564_DIGITAL_OP);//Resets the output channels\r
-   outl(0x0,devpriv->i_IobaseAmcc+APCI1564_DIGITAL_OP_INTERRUPT);//Disables the interrupt.\r
-   outl(0x0,devpriv->i_IobaseAmcc+APCI1564_DIGITAL_OP_WATCHDOG+APCI1564_TCW_RELOAD_VALUE);  \r
-   outl(0x0,devpriv->i_IobaseAmcc+APCI1564_TIMER);\r
-   outl(0x0 , devpriv->i_IobaseAmcc + APCI1564_TIMER + APCI1564_TCW_PROG);\r
-\r
-   outl(0x0 , devpriv->iobase + APCI1564_COUNTER1 + APCI1564_TCW_PROG);\r
-   outl(0x0 , devpriv->iobase + APCI1564_COUNTER2 + APCI1564_TCW_PROG);\r
-   outl(0x0 , devpriv->iobase + APCI1564_COUNTER3 + APCI1564_TCW_PROG);\r
-   outl(0x0 , devpriv->iobase + APCI1564_COUNTER4 + APCI1564_TCW_PROG);\r
-   return 0;\r
-}        \r
+/**
+@verbatim
+
+Copyright (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 USA
+
+You 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     : APCI-1564       | Compiler   : GCC                      |
+  | Module name : hwdrv_apci1564.c| Version    : 2.96                     |
+  +-------------------------------+---------------------------------------+
+  | Project manager: Eric Stolz   | Date       :  02/12/2002              |
+  +-------------------------------+---------------------------------------+
+  | Description :   Hardware Layer Acces For APCI-1564                    |
+  +-----------------------------------------------------------------------+
+  |                             UPDATES                                   |
+  +----------+-----------+------------------------------------------------+
+  |   Date   |   Author  |          Description of updates                |
+  +----------+-----------+------------------------------------------------+
+  |          |           |                                                |
+  |          |           |                                                |
+  |          |           |                                                |
+  +----------+-----------+------------------------------------------------+
+*/
+
+/*
++----------------------------------------------------------------------------+
+|                               Included files                               |
++----------------------------------------------------------------------------+
+*/
+
+#include <linux/delay.h>
+#include "hwdrv_apci1564.h"
+
+//Global variables
+UINT ui_InterruptStatus_1564=0 ;
+UINT ui_InterruptData,ui_Type;
+
+/*
++----------------------------------------------------------------------------+
+| Function   Name   : int i_APCI1564_ConfigDigitalInput                      |
+|                        (comedi_device *dev,comedi_subdevice *s,               | 
+|                      comedi_insn *insn,lsampl_t *data)                     |
++----------------------------------------------------------------------------+
+| Task              : Configures the digital input Subdevice                 |
++----------------------------------------------------------------------------+
+| Input Parameters  : comedi_device *dev : Driver handle                     |
+|                     lsampl_t *data         : Data Pointer contains         |
+|                                          configuration parameters as below |
+|                                                                            | 
+|                        data[0]            : 1 Enable  Digital Input Interrupt |      
+|                                                                 0 Disable Digital Input Interrupt | 
+|                        data[1]            : 0 ADDIDATA Interrupt OR LOGIC     | 
+|                                                               : 1 ADDIDATA Interrupt AND LOGIC    | 
+|                        data[2]                        : Interrupt mask for the mode 1         | 
+|                        data[3]                        : Interrupt mask for the mode 2         |
+|                                                                                                                                       |
++----------------------------------------------------------------------------+
+| Output Parameters :  --                                                                                                       |
++----------------------------------------------------------------------------+
+| Return Value      : TRUE  : No error occur                                 |
+|                          : FALSE : Error occur. Return the error          |
+|                                                                               |
++----------------------------------------------------------------------------+
+*/
+INT i_APCI1564_ConfigDigitalInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) 
+{
+   devpriv->tsk_Current=current;
+   /*******************************/
+   /* Set the digital input logic */
+   /*******************************/
+   if  ( data[0] == ADDIDATA_ENABLE)
+      {
+      data[2]=data[2]<<4;
+      data[3]=data[3]<<4;
+      outl (data[2] , devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP + APCI1564_DIGITAL_IP_INTERRUPT_MODE1);
+      outl (data[3] , devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP + APCI1564_DIGITAL_IP_INTERRUPT_MODE2);
+      if  (data[1] == ADDIDATA_OR)
+         {
+         outl(0x4 ,devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP + APCI1564_DIGITAL_IP_IRQ);
+         } // if  (data[1] == ADDIDATA_OR)
+      else
+         { 
+         outl(0x6 ,devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP + APCI1564_DIGITAL_IP_IRQ);
+         } // else if  (data[1] == ADDIDATA_OR)
+      } // if  (data[0] == ADDIDATA_ENABLE)
+   else
+      {
+      outl (0x0, devpriv->i_IobaseAmcc +APCI1564_DIGITAL_IP +APCI1564_DIGITAL_IP_INTERRUPT_MODE1);
+      outl (0x0, devpriv->i_IobaseAmcc +APCI1564_DIGITAL_IP +APCI1564_DIGITAL_IP_INTERRUPT_MODE2);
+      outl(0x0 ,devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP +APCI1564_DIGITAL_IP_IRQ);
+      } // else if  (data[0] == ADDIDATA_ENABLE)
+  
+   return insn->n;
+}
+
+/*
++----------------------------------------------------------------------------+
+| Function   Name   : int i_APCI1564_Read1DigitalInput                       |
+|                        (comedi_device *dev,comedi_subdevice *s,               |
+|                      comedi_insn *insn,lsampl_t *data)                     |
++----------------------------------------------------------------------------+
+| Task              : Return the status of the digital input                 |
++----------------------------------------------------------------------------+
+| Input Parameters  : comedi_device *dev      : Driver handle                |
+|                            UINT ui_Channel : Channel number to read       |
+|                     lsampl_t *data          : Data Pointer to read status  |
++----------------------------------------------------------------------------+
+| Output Parameters :  --                                                                                                       |
++----------------------------------------------------------------------------+
+| Return Value      : TRUE  : No error occur                                 |
+|                          : FALSE : Error occur. Return the error          |
+|                                                                               |
++----------------------------------------------------------------------------+
+*/
+INT i_APCI1564_Read1DigitalInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data)
+{
+   UINT ui_TmpValue=0;
+   UINT ui_Channel;
+   
+   ui_Channel=CR_CHAN(insn->chanspec);
+   if  (ui_Channel >= 0 && ui_Channel <=31)
+      {
+      ui_TmpValue=(UINT) inl(devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP );
+      //  since only 1 channel reqd  to bring it to last bit it is rotated 
+      //  8 +(chan - 1) times then ANDed with 1 for last bit. 
+      *data = (ui_TmpValue >> ui_Channel)&0x1 ;
+      } // if  (ui_Channel >= 0 && ui_Channel <=31)
+   else 
+      {
+      comedi_error(dev,"Not a valid channel number !!! \n");  
+      return -EINVAL;   // "sorry channel spec wrong "
+      }  //else if  (ui_Channel >= 0 && ui_Channel <=31)
+   return insn->n;
+}
+
+/*
++----------------------------------------------------------------------------+
+| Function   Name   : int i_APCI1564_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 to read status  |
++----------------------------------------------------------------------------+
+| Output Parameters :  --                                                                                                       |
++----------------------------------------------------------------------------+
+| Return Value      : TRUE  : No error occur                                 |
+|                          : FALSE : Error occur. Return the error          |
+|                                                                               |
++----------------------------------------------------------------------------+
+*/
+INT i_APCI1564_ReadMoreDigitalInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data)
+{
+   UINT ui_PortValue=data[0];
+   UINT ui_Mask=0;
+   UINT ui_NoOfChannels;
+   
+   ui_NoOfChannels=CR_CHAN(insn->chanspec);
+   if  (data[1]==0)
+      {
+      *data=(UINT)inl(devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP );
+      switch (ui_NoOfChannels)
+        {
+        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 16:ui_Mask=65535;
+                 *data=(*data >>(16*ui_PortValue))&ui_Mask;
+                 break;
+         case 31:break;
+         default:
+                comedi_error(dev,"Not a valid Channel number !!!\n");  
+               return -EINVAL;   // "sorry channel spec wrong "  
+                break;
+         } // switch  (ui_NoOfChannels)
+      } // if  (data[1]==0)
+   else
+      {
+      if  (data[1]==1)
+         {
+         *data=ui_InterruptStatus_1564;
+         } // if  (data[1]==1)
+      } // else if  (data[1]==0)   
+   return insn->n;
+}
+
+/*
++----------------------------------------------------------------------------+
+| Function   Name   : int i_APCI1564_ConfigDigitalOutput                     |
+|                        (comedi_device *dev,comedi_subdevice *s,               | 
+|                      comedi_insn *insn,lsampl_t *data)                     |
++----------------------------------------------------------------------------+
+| Task              : Configures The Digital Output Subdevice.               |
++----------------------------------------------------------------------------+
+| Input Parameters  : comedi_device *dev : Driver handle                     |
+|                     UINT *data         : Data Pointer contains             |
+|                                          configuration parameters as below |
+|                                                                            | 
+|                                        data[1]            : 1 Enable  VCC  Interrupt  |      
+|                                                                                 0 Disable VCC  Interrupt  | 
+|                                        data[2]            : 1 Enable  CC  Interrupt   |      
+|                                                                                 0 Disable CC  Interrupt   | 
+|                                                                                                                                       |
++----------------------------------------------------------------------------+
+| Output Parameters :  --                                                                                                       |
++----------------------------------------------------------------------------+
+| Return Value      : TRUE  : No error occur                                 |
+|                          : FALSE : Error occur. Return the error          |
+|                                                                               |
++----------------------------------------------------------------------------+
+*/
+INT i_APCI1564_ConfigDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data)
+{
+   ULONG  ul_Command = 0; 
+  
+   if  ((data[0]!=0) && (data[0]!=1)) 
+      {   
+      comedi_error(dev,"Not a valid Data !!! ,Data should be 1 or 0\n");  
+      return -EINVAL;
+      } // if  ((data[0]!=0) && (data[0]!=1)) 
+   if  (data[0])
+      {
+      devpriv->b_OutputMemoryStatus = ADDIDATA_ENABLE ; 
+      } // if  (data[0])
+   else
+      {
+      devpriv->b_OutputMemoryStatus = ADDIDATA_DISABLE;
+      } // else if  (data[0])
+   if  (data[1] == ADDIDATA_ENABLE)
+      {
+      ul_Command = ul_Command | 0x1;
+      } // if  (data[1] == ADDIDATA_ENABLE)
+   else
+      {
+      ul_Command = ul_Command & 0xFFFFFFFE;
+      } // else if  (data[1] == ADDIDATA_ENABLE)
+   if  (data[2] == ADDIDATA_ENABLE)
+      {
+      ul_Command = ul_Command | 0x2;
+      } // if  (data[2] == ADDIDATA_ENABLE)
+   else
+      {
+      ul_Command = ul_Command & 0xFFFFFFFD;
+      } // else if  (data[2] == ADDIDATA_ENABLE)
+   outl( ul_Command , devpriv->i_IobaseAmcc+APCI1564_DIGITAL_OP+APCI1564_DIGITAL_OP_INTERRUPT);
+   ui_InterruptData=inl( devpriv->i_IobaseAmcc+APCI1564_DIGITAL_OP+APCI1564_DIGITAL_OP_INTERRUPT); 
+   devpriv->tsk_Current=current;  
+   return insn->n;
+}
+
+/*
++----------------------------------------------------------------------------+
+| Function   Name   : int i_APCI1564_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_APCI1564_WriteDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) {
+   UINT ui_Temp,ui_Temp1;
+   UINT ui_NoOfChannel;
+   
+   ui_NoOfChannel=CR_CHAN(insn->chanspec);
+   if  (devpriv->b_OutputMemoryStatus )
+      {
+      ui_Temp=inl(devpriv->i_IobaseAmcc + APCI1564_DIGITAL_OP + APCI1564_DIGITAL_OP_RW);
+      } // if  (devpriv->b_OutputMemoryStatus )
+   else
+      {
+      ui_Temp=0;
+      } // else if  (devpriv->b_OutputMemoryStatus )
+   if  (data[3]==0)
+      { 
+      if  (data[1]==0)
+         {
+         data[0]=(data[0] << ui_NoOfChannel)|ui_Temp;
+         outl(data[0],devpriv->i_IobaseAmcc + APCI1564_DIGITAL_OP + APCI1564_DIGITAL_OP_RW);  
+         } // 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 16: data[0]=(data[0] <<(16*data[2]))|ui_Temp;
+                        break;
+               case 31: data[0]=data[0]|ui_Temp; 
+                        break;
+               default: comedi_error(dev," chan spec wrong");
+                        return -EINVAL;   // "sorry channel spec wrong "  
+               } // switch (ui_NoOfChannels)
+            outl(data[0],devpriv->i_IobaseAmcc + APCI1564_DIGITAL_OP + APCI1564_DIGITAL_OP_RW);
+            } // if  (data[1]==1)
+         else
+            {
+            printk("\nSpecified channel not supported\n");
+            } // else if  (data[1]==1)
+         } // else if (data[1]==0)
+      }//if(data[3]==0)
+   else
+      {
+      if  (data[3]==1)
+         {
+         if  (data[1]==0)
+            {
+            data[0]=~data[0]&0x1;
+            ui_Temp1=1;
+            ui_Temp1=ui_Temp1<<ui_NoOfChannel;
+            ui_Temp=ui_Temp|ui_Temp1;  
+            data[0]=(data[0] << ui_NoOfChannel)^0xffffffff;
+            data[0]=data[0]& ui_Temp; 
+            outl(data[0],devpriv->i_IobaseAmcc + APCI1564_DIGITAL_OP + APCI1564_DIGITAL_OP_RW);  
+            } // if  (data[1]==0) 
+         else
+            {
+            if  (data[1]==1)
+               { 
+               switch (ui_NoOfChannel)
+                 {
+                 case 2: data[0]=~data[0]&0x3; 
+                          ui_Temp1=3;
+                          ui_Temp1=ui_Temp1<<2*data[2];
+                          ui_Temp=ui_Temp|ui_Temp1;   
+                          data[0]=((data[0] << (2*data[2]))^0xffffffff)& ui_Temp; 
+                         break;
+                 case 4: data[0]=~data[0]&0xf;
+                          ui_Temp1=15;
+                          ui_Temp1=ui_Temp1<<4*data[2];
+                          ui_Temp=ui_Temp|ui_Temp1;    
+                          data[0]=((data[0] << (4*data[2]))^0xffffffff)&ui_Temp;
+                         break;
+                  case 8: data[0]=~data[0]&0xff;
+                          ui_Temp1=255;
+                          ui_Temp1=ui_Temp1<<8*data[2];
+                          ui_Temp=ui_Temp|ui_Temp1;    
+                          data[0]=((data[0] << (8*data[2]))^0xffffffff)&ui_Temp;  
+                         break;
+                  case 16: data[0]=~data[0]&0xffff;
+                           ui_Temp1=65535;
+                           ui_Temp1=ui_Temp1<<16*data[2];
+                           ui_Temp=ui_Temp|ui_Temp1;    
+                           data[0]=((data[0] << (16*data[2]))^0xffffffff)&ui_Temp;  
+                          break;
+                  case 31: break;
+                  default: comedi_error(dev," chan spec wrong");
+                           return -EINVAL;   // "sorry channel spec wrong "  
+                  }//switch(ui_NoOfChannels)
+               outl(data[0],devpriv->i_IobaseAmcc + APCI1564_DIGITAL_OP + APCI1564_DIGITAL_OP_RW);
+               } // if  (data[1]==1)
+            else
+               {
+               printk("\nSpecified channel not supported\n");
+               } // else if  (data[1]==1)
+            } // else if  (data[1]==0)
+         } // if  (data[3]==1);
+      else
+         {
+         printk("\nSpecified functionality does not exist\n");
+         return -EINVAL;
+         } // else if (data[3]==1)
+      } // else if (data[3]==0) 
+   return insn->n;
+}
+
+/*
++----------------------------------------------------------------------------+
+| Function   Name   : int i_APCI1564_ReadDigitalOutput                       |
+|                        (comedi_device *dev,comedi_subdevice *s,               | 
+|                      comedi_insn *insn,lsampl_t *data)                     |
++----------------------------------------------------------------------------+
+| Task              : Read  value  of the selected channel or port           |
++----------------------------------------------------------------------------+
+| Input Parameters  : comedi_device *dev      : Driver handle                |
+|                     UINT ui_NoOfChannels    : No Of Channels To read       |
+|                     UINT *data              : Data Pointer to read status  |
++----------------------------------------------------------------------------+
+| Output Parameters :  --                                                                                                       |
++----------------------------------------------------------------------------+
+| Return Value      : TRUE  : No error occur                                 |
+|                          : FALSE : Error occur. Return the error          |
+|                                                                               |
++----------------------------------------------------------------------------+
+*/
+INT i_APCI1564_ReadDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) 
+{
+   UINT ui_Temp;
+   UINT ui_NoOfChannel;
+
+   ui_NoOfChannel=CR_CHAN(insn->chanspec);
+   ui_Temp=data[0];
+   *data=inl(devpriv->i_IobaseAmcc+APCI1564_DIGITAL_OP+APCI1564_DIGITAL_OP_RW);
+   if  (ui_Temp==0)
+      {
+      *data=(*data >> ui_NoOfChannel)&0x1; 
+      } // if  (ui_Temp==0)
+   else
+      {
+      if  (ui_Temp==1)
+         {
+         switch (ui_NoOfChannel)
+          {
+           case 2: 
+                    *data=(*data >>(2*data[1]))&3; 
+                    break;
+
+           case 4: 
+                    *data=(*data >>(4*data[1]))&15; 
+                   break;
+          case 8:  
+                   *data=(*data >>(8*data[1]))&255;  
+                    break;
+           case 16: 
+                    *data=(*data >>(16*data[1]))&65535;
+                    break;
+
+           case 31: break;
+
+           default:
+                   comedi_error(dev," chan spec wrong");
+                   return -EINVAL;   // "sorry channel spec wrong "  
+                    break;
+           } // switch(ui_NoOfChannels)    
+        } // if  (ui_Temp==1)
+     else
+        {
+        printk("\nSpecified channel not supported \n");
+        } // else if (ui_Temp==1)
+     } // else if  (ui_Temp==0)
+   return insn->n;
+}
+
+/*
++----------------------------------------------------------------------------+
+| Function   Name   : int i_APCI1564_ConfigTimerCounterWatchdog              |
+|                        (comedi_device *dev,comedi_subdevice *s,               | 
+|                      comedi_insn *insn,lsampl_t *data)                     |
++----------------------------------------------------------------------------+
+| Task              : Configures The Timer , Counter or Watchdog             |
++----------------------------------------------------------------------------+
+| Input Parameters  : comedi_device *dev : Driver handle                     |
+|                     UINT *data         : Data Pointer contains             |
+|                                          configuration parameters as below |
+|                                                                            | 
+|                                        data[0]            : 0 Configure As Timer      |      
+|                                                                                 1 Configure As Counter    |                            
+|                                                                                 2 Configure As Watchdog   |                            
+|                                        data[1]            : 1 Enable  Interrupt       |      
+|                                                                                 0 Disable Interrupt       |                           
+|                                        data[2]            : Time Unit                 |
+|                                        data[3]                        : Reload Value                      |                            
+|                                        data[4]            : Timer Mode                |                            
+|                                        data[5]                        : Timer Counter Watchdog Number|     
+                              data[6]            :  Counter Direction 
++----------------------------------------------------------------------------+
+| Output Parameters :  --                                                                                                       |
++----------------------------------------------------------------------------+
+| Return Value      : TRUE  : No error occur                                 |
+|                          : FALSE : Error occur. Return the error          |
+|                                                                               |
++----------------------------------------------------------------------------+
+*/
+INT i_APCI1564_ConfigTimerCounterWatchdog (comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) 
+{
+   ULONG  ul_Command1 = 0; 
+   devpriv->tsk_Current=current;
+   if  (data[0]==ADDIDATA_WATCHDOG)
+      {
+      devpriv->b_TimerSelectMode = ADDIDATA_WATCHDOG;   
+     
+      //Disable the watchdog
+      outl(0x0,devpriv->i_IobaseAmcc+ APCI1564_DIGITAL_OP_WATCHDOG+ APCI1564_TCW_PROG); 
+     //Loading the Reload value
+      outl(data[3],devpriv->i_IobaseAmcc+APCI1564_DIGITAL_OP_WATCHDOG+APCI1564_TCW_RELOAD_VALUE);  
+      } // if  (data[0]==ADDIDATA_WATCHDOG)
+   else if  (data[0]==ADDIDATA_TIMER)
+      {
+      //First Stop The Timer 
+      ul_Command1 =inl(devpriv->i_IobaseAmcc+ APCI1564_TIMER+ APCI1564_TCW_PROG);
+      ul_Command1 =ul_Command1 & 0xFFFFF9FEUL;
+      outl(ul_Command1,devpriv->i_IobaseAmcc+ APCI1564_TIMER+ APCI1564_TCW_PROG);//Stop The Timer
+
+      devpriv->b_TimerSelectMode =ADDIDATA_TIMER;
+      if  (data[1]==1)
+         { 
+         outl(0x02,devpriv->i_IobaseAmcc+ APCI1564_TIMER+ APCI1564_TCW_PROG);//Enable TIMER int & DISABLE ALL THE OTHER int SOURCES
+         outl(0x0,devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP + APCI1564_DIGITAL_IP_IRQ);
+         outl(0x0,devpriv->i_IobaseAmcc + APCI1564_DIGITAL_OP + APCI1564_DIGITAL_OP_IRQ); 
+         outl(0x0,devpriv->i_IobaseAmcc + APCI1564_DIGITAL_OP_WATCHDOG + APCI1564_TCW_IRQ);
+         outl(0x0,devpriv->iobase+APCI1564_COUNTER1 + APCI1564_TCW_IRQ);
+         outl(0x0,devpriv->iobase+APCI1564_COUNTER2 + APCI1564_TCW_IRQ);
+         outl(0x0,devpriv->iobase+APCI1564_COUNTER3 + APCI1564_TCW_IRQ);
+         outl(0x0,devpriv->iobase+APCI1564_COUNTER4 + APCI1564_TCW_IRQ);
+         } // if  (data[1]==1)
+      else
+         { 
+         outl(0x0,devpriv->i_IobaseAmcc+ APCI1564_TIMER+ APCI1564_TCW_PROG);//disable Timer interrupt
+         } // else if  (data[1]==1)
+    
+      // Loading Timebase
+     
+         outl(data[2],devpriv->i_IobaseAmcc+APCI1564_TIMER+APCI1564_TCW_TIMEBASE);
+        
+      //Loading the Reload value
+      outl(data[3],devpriv->i_IobaseAmcc+APCI1564_TIMER+APCI1564_TCW_RELOAD_VALUE);
+    
+      ul_Command1 =inl(devpriv->i_IobaseAmcc+ APCI1564_TIMER+ APCI1564_TCW_PROG);
+      ul_Command1 = (ul_Command1 & 0xFFF719E2UL) |  2UL << 13UL | 0x10UL;
+      outl(ul_Command1,devpriv->i_IobaseAmcc+ APCI1564_TIMER+ APCI1564_TCW_PROG);//mode 2
+      } // else if  (data[0]==ADDIDATA_TIMER)
+   else if  (data[0]==ADDIDATA_COUNTER)
+      {
+      devpriv->b_TimerSelectMode =ADDIDATA_COUNTER;
+      devpriv->b_ModeSelectRegister=data[5];
+
+      //First Stop The Counter
+      ul_Command1 =inl(devpriv->iobase+((data[5]-1)*0x20)+APCI1564_TCW_PROG); 
+      ul_Command1 =ul_Command1 & 0xFFFFF9FEUL;
+      outl(ul_Command1,devpriv->iobase+((data[5]-1)*0x20)+APCI1564_TCW_PROG);//Stop The Timer
+
+      /************************/
+      /* Set the reload value */
+      /************************/
+      outl(data[3] , devpriv->iobase+((data[5]-1)*0x20)+APCI1564_TCW_RELOAD_VALUE);
+      /******************************/
+      /* Set the mode :             */
+      /* - Disable the hardware     */
+      /* - Disable the counter mode */
+      /* - Disable the warning      */
+      /* - Disable the reset        */
+      /* - Disable the timer mode   */
+      /* - Enable the counter mode  */
+      /******************************/
+      ul_Command1 = (ul_Command1 & 0xFFFC19E2UL) | 0x80000UL | (ULONG) ((ULONG) data[4] << 16UL);
+      outl(ul_Command1 , devpriv->iobase+((data[5]-1)*0x20)+APCI1564_TCW_PROG); 
+
+      // Enable or Disable Interrupt 
+      ul_Command1= (ul_Command1 & 0xFFFFF9FD) | (data[1] << 1);                 
+      outl(ul_Command1 , devpriv->iobase+((data[5]-1)*0x20)+APCI1564_TCW_PROG);
+      /*****************************/
+      /* Set the Up/Down selection */
+      /*****************************/
+      ul_Command1 = (ul_Command1 & 0xFFFBF9FFUL) |  (data[6] << 18);
+      outl(ul_Command1 , devpriv->iobase+((data[5]-1)*0x20)+APCI1564_TCW_PROG);  
+      } // else if  (data[0]==ADDIDATA_COUNTER)
+   else   
+      {
+      printk(" Invalid subdevice.");
+      } // else if  (data[0]==ADDIDATA_WATCHDOG) 
+   
+   return insn->n;
+}
+
+/*
++----------------------------------------------------------------------------+
+| Function   Name   : int i_APCI1564_StartStopWriteTimerCounterWatchdog      |
+|                        (comedi_device *dev,comedi_subdevice *s,               | 
+|                      comedi_insn *insn,lsampl_t *data)                     |
++----------------------------------------------------------------------------+
+| Task              : Start / Stop The Selected Timer , Counter or Watchdog  |
++----------------------------------------------------------------------------+
+| Input Parameters  : comedi_device *dev : Driver handle                     |
+|                     UINT *data         : Data Pointer contains             |
+|                                          configuration parameters as below |
+|                                                                            | 
+|                                        data[0]            : 0 Timer                   |
+|                                                                                 1 Counter                 |  
+|                                                                                 2 Watchdog                    |                             |                                                 data[1]            : 1 Start                   |       
+|                                                                                 0 Stop                    |       
+|                                                  2 Trigger                    |      
+|                                                    Clear (Only Counter)    |
++----------------------------------------------------------------------------+
+| Output Parameters :  --                                                                                                       |
++----------------------------------------------------------------------------+
+| Return Value      : TRUE  : No error occur                                 |
+|                          : FALSE : Error occur. Return the error          |
+|                                                                               |
++----------------------------------------------------------------------------+
+*/
+INT i_APCI1564_StartStopWriteTimerCounterWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data)
+{
+   ULONG  ul_Command1 = 0; 
+   if  (devpriv->b_TimerSelectMode==ADDIDATA_WATCHDOG)
+      {
+      switch (data[1])
+         {
+         case 0:  //stop the watchdog
+                  outl(0x0,devpriv->i_IobaseAmcc+ APCI1564_DIGITAL_OP_WATCHDOG+ APCI1564_TCW_PROG );//disable the watchdog
+                  break;
+         case 1:  //start the watchdog
+                  outl(0x0001,devpriv->i_IobaseAmcc+ APCI1564_DIGITAL_OP_WATCHDOG+ APCI1564_TCW_PROG);
+                  break;
+         case 2:  //Software trigger  
+                  outl(0x0201,devpriv->i_IobaseAmcc+ APCI1564_DIGITAL_OP_WATCHDOG+ APCI1564_TCW_PROG);
+                  break;
+         default: printk("\nSpecified functionality does not exist\n");
+                 return -EINVAL;
+         }  // switch (data[1])        
+      } // if  (devpriv->b_TimerSelectMode==ADDIDATA_WATCHDOG)   
+   if  (devpriv->b_TimerSelectMode==ADDIDATA_TIMER)
+      {
+      if  (data[1]==1) 
+         { 
+         ul_Command1=inl(devpriv->i_IobaseAmcc+ APCI1564_TIMER+ APCI1564_TCW_PROG);
+         ul_Command1=(ul_Command1& 0xFFFFF9FFUL) | 0x1UL;
+       
+         //Enable the Timer
+         outl(ul_Command1,devpriv->i_IobaseAmcc+ APCI1564_TIMER+ APCI1564_TCW_PROG);
+         } // if  (data[1]==1)
+      else if(data[1]==0)
+         {
+         //Stop The Timer
+          
+         ul_Command1=inl(devpriv->i_IobaseAmcc+ APCI1564_TIMER+ APCI1564_TCW_PROG);
+         ul_Command1 =ul_Command1 & 0xFFFFF9FEUL;
+         outl(ul_Command1,devpriv->i_IobaseAmcc+ APCI1564_TIMER+ APCI1564_TCW_PROG);
+         } // else if(data[1]==0)
+      } // if  (devpriv->b_TimerSelectMode==ADDIDATA_TIMER)
+   if  (devpriv->b_TimerSelectMode==ADDIDATA_COUNTER)
+      {
+      ul_Command1=inl(devpriv->iobase+((devpriv->b_ModeSelectRegister-1)*0x20)+APCI1564_TCW_PROG);
+      if  (data[1] == 1) 
+         {
+         //Start the Counter subdevice 
+         ul_Command1= (ul_Command1 & 0xFFFFF9FFUL) | 0x1UL;
+         } // if  (data[1] == 1)
+      else if (data[1] == 0)
+         {
+         // Stops the Counter subdevice 
+        ul_Command1 = 0;
+         
+         } // else if  (data[1] == 0)
+      else if (data[1] == 2)
+         {
+         // Clears the Counter subdevice
+         ul_Command1= (ul_Command1 & 0xFFFFF9FFUL)|0x400;
+         } // else if  (data[1] == 3)
+      outl(ul_Command1 , devpriv->iobase+((devpriv->b_ModeSelectRegister-1)*0x20)+APCI1564_TCW_PROG);
+      } // if (devpriv->b_TimerSelectMode==ADDIDATA_COUNTER)
+   return insn->n;
+}
+
+/*
++----------------------------------------------------------------------------+
+| Function   Name   : int i_APCI1564_ReadTimerCounterWatchdog                |
+|                        (comedi_device *dev,comedi_subdevice *s,               | 
+|                      comedi_insn *insn,lsampl_t *data)                     |
++----------------------------------------------------------------------------+
+| Task              : Read The Selected Timer , Counter or Watchdog          |
++----------------------------------------------------------------------------+
+| Input Parameters  : comedi_device *dev : Driver handle                     |
+|                     UINT *data         : Data Pointer contains             |
+|                                          configuration parameters as below |
+|                                                                            | 
+                                       
++----------------------------------------------------------------------------+
+| Output Parameters :  --                                                                                                       |
++----------------------------------------------------------------------------+
+| Return Value      : TRUE  : No error occur                                 |
+|                          : FALSE : Error occur. Return the error          |
+|                                                                               |
++----------------------------------------------------------------------------+
+*/
+INT i_APCI1564_ReadTimerCounterWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data)
+{
+   ULONG  ul_Command1 = 0; 
+
+   if  (devpriv->b_TimerSelectMode==ADDIDATA_WATCHDOG)
+      { 
+      // Stores the status of the Watchdog 
+      data[0]= inl(devpriv->i_IobaseAmcc + APCI1564_DIGITAL_OP_WATCHDOG + APCI1564_TCW_TRIG_STATUS)&0x1;
+      data[1]= inl(devpriv->i_IobaseAmcc + APCI1564_DIGITAL_OP_WATCHDOG);
+      } // if  (devpriv->b_TimerSelectMode==ADDIDATA_WATCHDOG)
+   else if  (devpriv->b_TimerSelectMode==ADDIDATA_TIMER) 
+      {
+      // Stores the status of the Timer 
+      data[0]= inl(devpriv->i_IobaseAmcc+APCI1564_TIMER+APCI1564_TCW_TRIG_STATUS)&0x1; 
+
+      // Stores the Actual value of the Timer 
+      data[1]= inl(devpriv->i_IobaseAmcc + APCI1564_TIMER); 
+      }  // else if  (devpriv->b_TimerSelectMode==ADDIDATA_TIMER)
+   else  if  (devpriv->b_TimerSelectMode==ADDIDATA_COUNTER) 
+      {
+      // Read the Counter Actual Value. 
+      data[0] = inl(devpriv->iobase+((devpriv->b_ModeSelectRegister-1)*0x20)+APCI1564_TCW_SYNC_ENABLEDISABLE);
+      ul_Command1 =  inl(devpriv->iobase+((devpriv->b_ModeSelectRegister-1)*0x20)+APCI1564_TCW_TRIG_STATUS);
+
+      /***********************************/
+      /* Get the software trigger status */
+      /***********************************/
+      data[1]= (BYTE) ((ul_Command1 >> 1) & 1);
+
+      /***********************************/
+      /* Get the hardware trigger status */
+      /***********************************/
+      data[2]= (BYTE) ((ul_Command1 >> 2) & 1);
+
+      /*********************************/
+      /* Get the software clear status */
+      /*********************************/
+      data[3]= (BYTE) ((ul_Command1 >> 3) & 1);
+
+      /***************************/
+      /* Get the overflow status */
+      /***************************/
+      data[4]= (BYTE) ((ul_Command1 >> 0) & 1);
+      } // else  if  (devpriv->b_TimerSelectMode==ADDIDATA_COUNTER) 
+  else if ((devpriv->b_TimerSelectMode!=ADDIDATA_TIMER) && (devpriv->b_TimerSelectMode!=ADDIDATA_WATCHDOG)&& (devpriv->b_TimerSelectMode!=ADDIDATA_COUNTER))
+     {
+     printk ("\n Invalid Subdevice !!!\n");
+     } // else if ((devpriv->b_TimerSelectMode!=ADDIDATA_TIMER) && (devpriv->b_TimerSelectMode!=ADDIDATA_WATCHDOG)&& (devpriv->b_TimerSelectMode!=ADDIDATA_COUNTER))
+   return insn->n;
+}
+
+/*
++----------------------------------------------------------------------------+
+| Function   Name   :  int i_APCI1564_ReadInterruptStatus                    |
+|                        (comedi_device *dev,comedi_subdevice *s,               | 
+|                      comedi_insn *insn,lsampl_t *data)                     |
++----------------------------------------------------------------------------+
+| Task              :Reads the interrupt status register                     |
++----------------------------------------------------------------------------+
+| Input Parameters  :                                                        |
++----------------------------------------------------------------------------+
+| Output Parameters :  --                                                                                                       |
++----------------------------------------------------------------------------+
+| Return Value      :                                                        |
+|                                                                               |
++----------------------------------------------------------------------------+
+*/
+
+int i_APCI1564_ReadInterruptStatus(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data)
+{  
+    *data=ui_Type;
+    return insn->n;
+} 
+
+/*
++----------------------------------------------------------------------------+
+| Function   Name   : static void v_APCI1564_Interrupt                                      |
+|                                        (int irq , void *d, struct pt_regs *regs)      |
++----------------------------------------------------------------------------+
+| Task              : Interrupt handler for the interruptible digital inputs |
++----------------------------------------------------------------------------+
+| Input Parameters  : int irq                 : irq number                   |
+|                     void *d                 : void pointer                 |
+|                     struct pt_regs *regs    : structure pointer            |
++----------------------------------------------------------------------------+
+| Output Parameters :  --                                                                                                       |
++----------------------------------------------------------------------------+
+| Return Value      : TRUE  : No error occur                                 |
+|                          : FALSE : Error occur. Return the error          |
+|                                                                               |
++----------------------------------------------------------------------------+
+*/
+static VOID v_APCI1564_Interrupt(int irq,void* d, struct pt_regs *regs) 
+{
+   comedi_device *dev =d;      
+   UINT ui_DO, ui_DI;
+   UINT ui_Timer;
+   UINT ui_C1, ui_C2, ui_C3, ui_C4;
+   ULONG ul_Command2=0; 
+   ui_DI       = inl(devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP + APCI1564_DIGITAL_IP_IRQ) & 0x01;
+   ui_DO       = inl(devpriv->i_IobaseAmcc + APCI1564_DIGITAL_OP + APCI1564_DIGITAL_OP_IRQ) & 0x01;
+   ui_Timer    = inl(devpriv->i_IobaseAmcc + APCI1564_TIMER+ APCI1564_TCW_IRQ) & 0x01; 
+   ui_C1=inl(devpriv->iobase + APCI1564_COUNTER1 + APCI1564_TCW_IRQ ) & 0x1;
+   ui_C2=inl(devpriv->iobase + APCI1564_COUNTER2 + APCI1564_TCW_IRQ ) & 0x1;
+   ui_C3=inl(devpriv->iobase + APCI1564_COUNTER3 + APCI1564_TCW_IRQ ) & 0x1;
+   ui_C4=inl(devpriv->iobase + APCI1564_COUNTER4 + APCI1564_TCW_IRQ ) & 0x1;
+  if(ui_DI==0 && ui_DO==0 && ui_Timer==0 && ui_C1==0 && ui_C2==0 && ui_C3==0 && ui_C4==0)
+      {
+       printk("\nInterrupt from unknown source\n");
+      }// if(ui_DI==0 && ui_DO==0 && ui_Timer==0 && ui_C1==0 && ui_C2==0 && ui_C3==0 && ui_C4==0)
+      
+   if  (ui_DI == 1)
+      {
+      ui_DI = inl(devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP + APCI1564_DIGITAL_IP_IRQ);
+      outl(0x0 ,devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP + APCI1564_DIGITAL_IP_IRQ);
+      ui_InterruptStatus_1564=inl(devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP + APCI1564_DIGITAL_IP_INTERRUPT_STATUS);
+      ui_InterruptStatus_1564=ui_InterruptStatus_1564 & 0X000FFFF0;
+      send_sig(SIGIO,devpriv->tsk_Current,0); // send signal to the sample   
+      outl(ui_DI ,devpriv->i_IobaseAmcc + APCI1564_DIGITAL_IP + APCI1564_DIGITAL_IP_IRQ);//enable the interrupt
+      return;
+      }
+
+   if  (ui_DO == 1)
+      {
+      // Check for Digital Output interrupt Type - 1: Vcc interrupt 2: CC interrupt.
+      ui_Type=inl(devpriv->i_IobaseAmcc + APCI1564_DIGITAL_OP + APCI1564_DIGITAL_OP_INTERRUPT_STATUS) & 0x3;     
+       //Disable the  Interrupt 
+      outl(0x0,devpriv->i_IobaseAmcc + APCI1564_DIGITAL_OP + APCI1564_DIGITAL_OP_INTERRUPT);
+     
+         //Sends signal to user space 
+        send_sig(SIGIO,devpriv->tsk_Current,0);
+      
+      }  // if  (ui_DO)
+
+   if  ((ui_Timer == 1) && (devpriv->b_TimerSelectMode =ADDIDATA_TIMER))
+      {
+      // Disable Timer Interrupt 
+      ul_Command2=inl(devpriv->i_IobaseAmcc + APCI1564_TIMER + APCI1564_TCW_PROG);  
+      outl(0x0 , devpriv->i_IobaseAmcc + APCI1564_TIMER + APCI1564_TCW_PROG);
+
+      //Send a signal to from kernel to user space
+      send_sig(SIGIO,devpriv->tsk_Current,0); 
+
+      // Enable Timer Interrupt 
+     
+      outl(ul_Command2 , devpriv->i_IobaseAmcc + APCI1564_TIMER + APCI1564_TCW_PROG);
+      } // if  ((ui_Timer == 1) && (devpriv->b_TimerSelectMode =ADDIDATA_TIMER))
+
+   if  ((ui_C1 == 1) && (devpriv->b_TimerSelectMode = ADDIDATA_COUNTER))
+      {
+      // Disable Counter Interrupt 
+      ul_Command2=inl(devpriv->iobase + APCI1564_COUNTER1 + APCI1564_TCW_PROG);
+      outl(0x0 , devpriv->iobase + APCI1564_COUNTER1 + APCI1564_TCW_PROG);
+
+      //Send a signal to from kernel to user space
+      send_sig(SIGIO,devpriv->tsk_Current,0); 
+
+      // Enable Counter Interrupt 
+      outl(ul_Command2 , devpriv->iobase + APCI1564_COUNTER1 + APCI1564_TCW_PROG);
+      } // if  ((ui_C1 == 1) && (devpriv->b_TimerSelectMode = ADDIDATA_COUNTER))  
+
+   if  ((ui_C2 == 1) && (devpriv->b_TimerSelectMode =ADDIDATA_COUNTER))
+      {
+      // Disable Counter Interrupt
+      ul_Command2=inl(devpriv->iobase + APCI1564_COUNTER2 + APCI1564_TCW_PROG); 
+      outl(0x0 , devpriv->iobase + APCI1564_COUNTER2 + APCI1564_TCW_PROG);
+
+      //Send a signal to from kernel to user space
+      send_sig(SIGIO,devpriv->tsk_Current,0); 
+
+      // Enable Counter Interrupt 
+      outl(ul_Command2 , devpriv->iobase + APCI1564_COUNTER2 + APCI1564_TCW_PROG);
+      } // if  ((ui_C2 == 1) && (devpriv->b_TimerSelectMode =ADDIDATA_COUNTER)) 
+
+   if  ((ui_C3 == 1) && (devpriv->b_TimerSelectMode =ADDIDATA_COUNTER))
+      {
+      // Disable Counter Interrupt 
+      ul_Command2=inl(devpriv->iobase + APCI1564_COUNTER3 + APCI1564_TCW_PROG); 
+      outl(0x0 , devpriv->iobase + APCI1564_COUNTER3 + APCI1564_TCW_PROG);
+
+      //Send a signal to from kernel to user space
+      send_sig(SIGIO,devpriv->tsk_Current,0); 
+
+      // Enable Counter Interrupt 
+      outl(ul_Command2 , devpriv->iobase + APCI1564_COUNTER3 + APCI1564_TCW_PROG);
+      } // if ((ui_C3 == 1) && (devpriv->b_TimerSelectMode =ADDIDATA_COUNTER))
+
+    if ((ui_C4 == 1) && (devpriv->b_TimerSelectMode =ADDIDATA_COUNTER))
+      {
+      // Disable Counter Interrupt 
+      ul_Command2=inl(devpriv->iobase + APCI1564_COUNTER4 + APCI1564_TCW_PROG);   
+      outl(0x0 , devpriv->iobase + APCI1564_COUNTER4 + APCI1564_TCW_PROG);
+
+      //Send a signal to from kernel to user space
+      send_sig(SIGIO,devpriv->tsk_Current,0); 
+
+      // Enable Counter Interrupt 
+      outl(ul_Command2 , devpriv->iobase + APCI1564_COUNTER4 + APCI1564_TCW_PROG);
+      } // if ((ui_C4 == 1) && (devpriv->b_TimerSelectMode =ADDIDATA_COUNTER))
+   return;
+}        
+         
+/*
++----------------------------------------------------------------------------+
+| Function   Name   : int i_APCI1564_Reset(comedi_device *dev)               |                                                       |
++----------------------------------------------------------------------------+
+| Task              :resets all the registers                                |
++----------------------------------------------------------------------------+
+| Input Parameters  : comedi_device *dev
++----------------------------------------------------------------------------+
+| Output Parameters :  --                                                                                                       |
++----------------------------------------------------------------------------+
+| Return Value      :                                                        |
+|                                                                               |
++----------------------------------------------------------------------------+
+*/
+         
+INT i_APCI1564_Reset(comedi_device *dev) 
+{
+   outl(0x0 ,devpriv->i_IobaseAmcc+APCI1564_DIGITAL_IP_IRQ);//disable the interrupts
+   inl(devpriv->i_IobaseAmcc+APCI1564_DIGITAL_IP_INTERRUPT_STATUS);//Reset the interrupt status register         
+   outl (0x0 , devpriv->i_IobaseAmcc+APCI1564_DIGITAL_IP_INTERRUPT_MODE1);//Disable the and/or interrupt
+   outl (0x0 , devpriv->i_IobaseAmcc+APCI1564_DIGITAL_IP_INTERRUPT_MODE2);
+   devpriv->b_DigitalOutputRegister=0;
+   ui_Type=0;
+   outl(0x0,devpriv->i_IobaseAmcc+APCI1564_DIGITAL_OP);//Resets the output channels
+   outl(0x0,devpriv->i_IobaseAmcc+APCI1564_DIGITAL_OP_INTERRUPT);//Disables the interrupt.
+   outl(0x0,devpriv->i_IobaseAmcc+APCI1564_DIGITAL_OP_WATCHDOG+APCI1564_TCW_RELOAD_VALUE);  
+   outl(0x0,devpriv->i_IobaseAmcc+APCI1564_TIMER);
+   outl(0x0 , devpriv->i_IobaseAmcc + APCI1564_TIMER + APCI1564_TCW_PROG);
+
+   outl(0x0 , devpriv->iobase + APCI1564_COUNTER1 + APCI1564_TCW_PROG);
+   outl(0x0 , devpriv->iobase + APCI1564_COUNTER2 + APCI1564_TCW_PROG);
+   outl(0x0 , devpriv->iobase + APCI1564_COUNTER3 + APCI1564_TCW_PROG);
+   outl(0x0 , devpriv->iobase + APCI1564_COUNTER4 + APCI1564_TCW_PROG);
+   return 0;
+}        
index 89c3614fa3fe2e1c0d098f484af13ca031a9ae54..ffb81f169110de63de0bafa547bd3d4560fe3e3a 100644 (file)
-/**\r
-@verbatim\r
-\r
-Copyright (C) 2004,2005  ADDI-DATA GmbH for the source code of this module. \r
-        \r
-        ADDI-DATA GmbH \r
-        Dieselstrasse 3 \r
-        D-77833 Ottersweier \r
-        Tel: +19(0)7223/9493-0 \r
-        Fax: +49(0)7223/9493-92 \r
-        http://www.addi-data-com \r
-        info@addi-data.com \r
-\r
-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.\r
-\r
-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.\r
-\r
-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 USA\r
-\r
-You shoud also find the complete GPL in the COPYING file accompanying this source code.\r
-\r
-@endverbatim\r
-*/\r
-\r
-/*********      Definitions for APCI-1564 card  *****/\r
-\r
-#define APCI1564_BOARD_VENDOR_ID                0x15B8\r
-#define APCI1564_ADDRESS_RANGE                  128\r
-\r
-//DIGITAL INPUT-OUTPUT DEFINE  \r
-// Input defines\r
-#define APCI1564_DIGITAL_IP                     0x04  \r
-#define APCI1564_DIGITAL_IP_INTERRUPT_MODE1     4\r
-#define APCI1564_DIGITAL_IP_INTERRUPT_MODE2     8\r
-#define APCI1564_DIGITAL_IP_IRQ                 16\r
-\r
-// Output defines\r
-#define APCI1564_DIGITAL_OP                    0x18\r
-#define APCI1564_DIGITAL_OP_RW                 0    \r
-#define APCI1564_DIGITAL_OP_INTERRUPT           4   \r
-#define APCI1564_DIGITAL_OP_IRQ                 12  \r
-\r
-\r
-//Digital Input IRQ Function Selection\r
-#define ADDIDATA_OR                             0\r
-#define ADDIDATA_AND                            1\r
-\r
-//Digital Input Interrupt Status\r
-#define APCI1564_DIGITAL_IP_INTERRUPT_STATUS    12\r
-\r
-//Digital Output Interrupt Status\r
-#define APCI1564_DIGITAL_OP_INTERRUPT_STATUS    8  \r
-\r
-//Digital Input Interrupt Enable Disable. \r
-#define APCI1564_DIGITAL_IP_INTERRUPT_ENABLE    0x4 \r
-#define APCI1564_DIGITAL_IP_INTERRUPT_DISABLE   0xFFFFFFFB\r
-\r
-//Digital Output Interrupt Enable Disable.\r
-#define APCI1564_DIGITAL_OP_VCC_INTERRUPT_ENABLE   0x1\r
-#define APCI1564_DIGITAL_OP_VCC_INTERRUPT_DISABLE  0xFFFFFFFE\r
-#define APCI1564_DIGITAL_OP_CC_INTERRUPT_ENABLE    0x2\r
-#define APCI1564_DIGITAL_OP_CC_INTERRUPT_DISABLE   0xFFFFFFFD\r
-\r
-//ADDIDATA Enable Disable\r
-\r
-#define ADDIDATA_ENABLE                            1\r
-#define ADDIDATA_DISABLE                           0\r
-\r
-// TIMER COUNTER WATCHDOG DEFINES  \r
-\r
-#define ADDIDATA_TIMER                             0\r
-#define ADDIDATA_COUNTER                           1\r
-#define ADDIDATA_WATCHDOG                          2\r
-#define APCI1564_DIGITAL_OP_WATCHDOG               0x28\r
-#define APCI1564_TIMER                             0x48\r
-#define APCI1564_COUNTER1                          0x0\r
-#define APCI1564_COUNTER2                          0x20\r
-#define APCI1564_COUNTER3                          0x40\r
-#define APCI1564_COUNTER4                          0x60 \r
-#define APCI1564_TCW_SYNC_ENABLEDISABLE            0\r
-#define APCI1564_TCW_RELOAD_VALUE                  4\r
-#define APCI1564_TCW_TIMEBASE                      8\r
-#define APCI1564_TCW_PROG                          12\r
-#define APCI1564_TCW_TRIG_STATUS                   16\r
-#define APCI1564_TCW_IRQ                           20\r
-#define APCI1564_TCW_WARN_TIMEVAL                  24\r
-#define APCI1564_TCW_WARN_TIMEBASE                 28\r
-\r
-\r
-// Hardware Layer  functions for Apci1564\r
-\r
-\r
-//DI\r
-// for di read\r
-INT i_APCI1564_ConfigDigitalInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);\r
-INT i_APCI1564_Read1DigitalInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);\r
-INT i_APCI1564_ReadMoreDigitalInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);\r
-\r
-//DO\r
-int i_APCI1564_ConfigDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);\r
-INT i_APCI1564_WriteDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);\r
-INT i_APCI1564_ReadDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);\r
-int i_APCI1564_ReadInterruptStatus(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);  \r
-\r
-\r
-// TIMER  \r
-// timer value is passed as u seconds\r
-INT i_APCI1564_ConfigTimerCounterWatchdog (comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);\r
-int i_APCI1564_StartStopWriteTimerCounterWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);\r
-int i_APCI1564_ReadTimerCounterWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);\r
-\r
-// INTERRUPT\r
-static VOID v_APCI1564_Interrupt(int irq, void *d, struct pt_regs *regs) ;\r
-\r
-// RESET\r
-INT i_APCI1564_Reset(comedi_device *dev);\r
+/**
+@verbatim
+
+Copyright (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 USA
+
+You shoud also find the complete GPL in the COPYING file accompanying this source code.
+
+@endverbatim
+*/
+
+/*********      Definitions for APCI-1564 card  *****/
+
+#define APCI1564_BOARD_VENDOR_ID                0x15B8
+#define APCI1564_ADDRESS_RANGE                  128
+
+//DIGITAL INPUT-OUTPUT DEFINE  
+// Input defines
+#define APCI1564_DIGITAL_IP                     0x04  
+#define APCI1564_DIGITAL_IP_INTERRUPT_MODE1     4
+#define APCI1564_DIGITAL_IP_INTERRUPT_MODE2     8
+#define APCI1564_DIGITAL_IP_IRQ                 16
+
+// Output defines
+#define APCI1564_DIGITAL_OP                    0x18
+#define APCI1564_DIGITAL_OP_RW                 0    
+#define APCI1564_DIGITAL_OP_INTERRUPT           4   
+#define APCI1564_DIGITAL_OP_IRQ                 12  
+
+
+//Digital Input IRQ Function Selection
+#define ADDIDATA_OR                             0
+#define ADDIDATA_AND                            1
+
+//Digital Input Interrupt Status
+#define APCI1564_DIGITAL_IP_INTERRUPT_STATUS    12
+
+//Digital Output Interrupt Status
+#define APCI1564_DIGITAL_OP_INTERRUPT_STATUS    8  
+
+//Digital Input Interrupt Enable Disable. 
+#define APCI1564_DIGITAL_IP_INTERRUPT_ENABLE    0x4 
+#define APCI1564_DIGITAL_IP_INTERRUPT_DISABLE   0xFFFFFFFB
+
+//Digital Output Interrupt Enable Disable.
+#define APCI1564_DIGITAL_OP_VCC_INTERRUPT_ENABLE   0x1
+#define APCI1564_DIGITAL_OP_VCC_INTERRUPT_DISABLE  0xFFFFFFFE
+#define APCI1564_DIGITAL_OP_CC_INTERRUPT_ENABLE    0x2
+#define APCI1564_DIGITAL_OP_CC_INTERRUPT_DISABLE   0xFFFFFFFD
+
+//ADDIDATA Enable Disable
+
+#define ADDIDATA_ENABLE                            1
+#define ADDIDATA_DISABLE                           0
+
+// TIMER COUNTER WATCHDOG DEFINES  
+
+#define ADDIDATA_TIMER                             0
+#define ADDIDATA_COUNTER                           1
+#define ADDIDATA_WATCHDOG                          2
+#define APCI1564_DIGITAL_OP_WATCHDOG               0x28
+#define APCI1564_TIMER                             0x48
+#define APCI1564_COUNTER1                          0x0
+#define APCI1564_COUNTER2                          0x20
+#define APCI1564_COUNTER3                          0x40
+#define APCI1564_COUNTER4                          0x60 
+#define APCI1564_TCW_SYNC_ENABLEDISABLE            0
+#define APCI1564_TCW_RELOAD_VALUE                  4
+#define APCI1564_TCW_TIMEBASE                      8
+#define APCI1564_TCW_PROG                          12
+#define APCI1564_TCW_TRIG_STATUS                   16
+#define APCI1564_TCW_IRQ                           20
+#define APCI1564_TCW_WARN_TIMEVAL                  24
+#define APCI1564_TCW_WARN_TIMEBASE                 28
+
+
+// Hardware Layer  functions for Apci1564
+
+
+//DI
+// for di read
+INT i_APCI1564_ConfigDigitalInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);
+INT i_APCI1564_Read1DigitalInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);
+INT i_APCI1564_ReadMoreDigitalInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);
+
+//DO
+int i_APCI1564_ConfigDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);
+INT i_APCI1564_WriteDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);
+INT i_APCI1564_ReadDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);
+int i_APCI1564_ReadInterruptStatus(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);  
+
+
+// TIMER  
+// timer value is passed as u seconds
+INT i_APCI1564_ConfigTimerCounterWatchdog (comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);
+int i_APCI1564_StartStopWriteTimerCounterWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);
+int i_APCI1564_ReadTimerCounterWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);
+
+// INTERRUPT
+static VOID v_APCI1564_Interrupt(int irq, void *d, struct pt_regs *regs) ;
+
+// RESET
+INT i_APCI1564_Reset(comedi_device *dev);
index b4b737d7d3510a4ab5eb720292de6cec9bbdddc1..63e3bbeae6984eadc9cd2d9e9a84c33fc78ecbee 100755 (executable)
-/**\r
-@verbatim\r
-\r
-Copyright (C) 2004,2005  ADDI-DATA GmbH for the source code of this module. \r
-        \r
-        ADDI-DATA GmbH \r
-        Dieselstrasse 3 \r
-        D-77833 Ottersweier \r
-        Tel: +19(0)7223/9493-0 \r
-        Fax: +49(0)7223/9493-92 \r
-        http://www.addi-data-com \r
-        info@addi-data.com \r
-\r
-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.\r
-\r
-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.\r
-\r
-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 USA\r
-\r
-You shoud also find the complete GPL in the COPYING file accompanying this source code.\r
-\r
-@endverbatim\r
-*/\r
-/*\r
-    \r
-  +-----------------------------------------------------------------------+\r
-  | (C) ADDI-DATA GmbH          Dieselstraße 3       D-77833 Ottersweier  |\r
-  +-----------------------------------------------------------------------+\r
-  | Tel : +49 (0) 7223/9493-0     | email    : info@addi-data.com         |\r
-  | Fax : +49 (0) 7223/9493-92    | Internet : http://www.addi-data.com   |\r
-  +-----------------------------------------------------------------------+\r
-  | Project     : API APCI1648    | Compiler : gcc                        |\r
-  | Module name : TTL.C           | Version  : 2.96                       |\r
-  +-------------------------------+---------------------------------------+\r
-  | Project manager: S. Weber     | Date     :  25/05/2005                |\r
-  +-----------------------------------------------------------------------+\r
-  | Description :   APCI-16XX TTL I/O module                              |\r
-  |                                                                       |\r
-  |                                                                       |\r
-  +-----------------------------------------------------------------------+\r
-  |                             UPDATES                                   |\r
-  +-----------------------------------------------------------------------+\r
-  |   Date   |   Author  |          Description of updates                |\r
-  +----------+-----------+------------------------------------------------+\r
-  |25.05.2005| S.Weber   | Creation                                       |\r
-  |          |           |                                                |\r
-  +-----------------------------------------------------------------------+\r
-*/\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-|                               Included files                               |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-#include "hwdrv_apci16xx.h"\r
-\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : INT   i_APCI16XX_InsnConfigInitTTLIO                   |\r
-|                          (comedi_device    *dev,                           |\r
-|                           comedi_subdevice *s,                             |\r
-|                           comedi_insn      *insn,                          |\r
-|                           lsampl_t         *data)                          |\r
-+----------------------------------------------------------------------------+\r
-| Task           APCI16XX_TTL_INIT (using defaults)   :                      |\r
-|                Configure the TTL I/O operating mode from all ports         |\r
-|                You must calling this function be                           |\r
-|                for you call any other function witch access of TTL.        |\r
-|                APCI16XX_TTL_INITDIRECTION(user inputs for direction)       |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : b_InitType    = (BYTE) data[0];                        |\r
-|                     b_Port0Mode   = (BYTE) data[1];                        |\r
-|                     b_Port1Mode   = (BYTE) data[2];                        |\r
-|                     b_Port2Mode   = (BYTE) data[3];                        |\r
-|                     b_Port3Mode   = (BYTE) data[4];                        |\r
-|                     ........                                               |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : -                                                      |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      :>0: No error                                            |\r
-|                    -1: Port 0 mode selection is wrong                      |\r
-|                    -2: Port 1 mode selection is wrong                      |\r
-|                    -3: Port 2 mode selection is wrong                      |\r
-|                    -4: Port 3 mode selection is wrong                      |\r
-|                    -X: Port X-1 mode selection is wrong                    |\r
-|                    ....                                                    |\r
-|                    -100 : Config command error                             |\r
-|                    -101 : Data size error                                  |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-\r
-int   i_APCI16XX_InsnConfigInitTTLIO(comedi_device    *dev,\r
-                                     comedi_subdevice *s,\r
-                                     comedi_insn      *insn,\r
-                                     lsampl_t         *data) \r
-       {\r
-       INT        i_ReturnValue            = insn->n;\r
-       BYTE       b_Command                = 0;\r
-       BYTE       b_Cpt                    = 0;\r
-       BYTE       b_NumberOfPort           = (BYTE) (devpriv->ps_BoardInfo->i_NbrTTLChannel / 8);\r
-       \r
-       \r
-       /************************/\r
-       /* Test the buffer size */\r
-       /************************/\r
-       \r
-       if (insn->n >= 1)\r
-          {\r
-          /*******************/\r
-          /* Get the command */\r
-          /* *****************/\r
-          \r
-          b_Command = (BYTE) data[0];\r
-          \r
-          /********************/\r
-          /* Test the command */\r
-          /********************/\r
-          \r
-          if ((b_Command == APCI16XX_TTL_INIT)          || \r
-              (b_Command == APCI16XX_TTL_INITDIRECTION) || \r
-              (b_Command == APCI16XX_TTL_OUTPUTMEMORY))\r
-             {\r
-             /***************************************/\r
-             /* Test the initialisation buffer size */\r
-             /***************************************/\r
-             \r
-             if ((b_Command == APCI16XX_TTL_INITDIRECTION) && ((BYTE) (insn->n - 1) != b_NumberOfPort))\r
-                {\r
-                /*******************/\r
-                /* Data size error */\r
-                /*******************/\r
-                \r
-                 printk("\nBuffer size error");\r
-                i_ReturnValue = -101;\r
-                }\r
-\r
-             if ((b_Command == APCI16XX_TTL_OUTPUTMEMORY) && ((BYTE) (insn->n) != 2))\r
-                {\r
-                /*******************/\r
-                /* Data size error */\r
-                /*******************/\r
-                \r
-                 printk("\nBuffer size error");\r
-                i_ReturnValue = -101;\r
-                }\r
-             }\r
-          else\r
-             {\r
-             /************************/\r
-             /* Config command error */\r
-             /************************/\r
-             \r
-             printk("\nCommand selection error");\r
-             i_ReturnValue = -100;\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /*******************/\r
-          /* Data size error */\r
-          /*******************/\r
-              \r
-          printk("\nBuffer size error");\r
-          i_ReturnValue = -101;\r
-          }\r
-          \r
-          \r
-       /**************************************************************************/\r
-       /* Test if no error occur and APCI16XX_TTL_INITDIRECTION command selected */\r
-       /**************************************************************************/\r
-       \r
-       if ((i_ReturnValue >= 0) && (b_Command == APCI16XX_TTL_INITDIRECTION))\r
-          {\r
-          memset (devpriv->ul_TTLPortConfiguration, 0, sizeof(devpriv->ul_TTLPortConfiguration));\r
-\r
-          /*************************************/\r
-          /* Test the port direction selection */\r
-          /*************************************/\r
-          \r
-          for (b_Cpt = 1; (b_Cpt <= b_NumberOfPort) && (i_ReturnValue >= 0); b_Cpt ++)\r
-             {\r
-             /**********************/\r
-             /* Test the direction */\r
-             /**********************/\r
-             \r
-             if ((data[b_Cpt] != 0) && (data[b_Cpt] != 0xFF))\r
-                {\r
-                /************************/\r
-                 /* Port direction error */\r
-                 /************************/\r
-                 \r
-                printk("\nPort %d direction selection error", (INT) b_Cpt);\r
-                i_ReturnValue = - (INT) b_Cpt;\r
-                }\r
-             \r
-              /**************************/\r
-              /* Save the configuration */\r
-              /**************************/\r
-\r
-\r
-              devpriv->ul_TTLPortConfiguration[(b_Cpt - 1) / 4] = devpriv->ul_TTLPortConfiguration[(b_Cpt - 1) / 4] |\r
-                                                                  (data[b_Cpt] << (8 * ((b_Cpt - 1) % 4)));\r
-             }\r
-          }\r
-          \r
-       /**************************/\r
-       /* Test if no error occur */\r
-       /**************************/\r
-       \r
-       if (i_ReturnValue >= 0)\r
-          {\r
-          /***********************************/\r
-          /* Test if TTL port initilaisation */\r
-          /***********************************/\r
-          \r
-          if ((b_Command == APCI16XX_TTL_INIT) || (b_Command == APCI16XX_TTL_INITDIRECTION))\r
-             {\r
-             /******************************/\r
-             /* Set all port configuration */\r
-             /******************************/\r
-          \r
-             for (b_Cpt = 0; b_Cpt <= b_NumberOfPort; b_Cpt ++)\r
-                {\r
-                if ((b_Cpt % 4) == 0)\r
-                   {\r
-                   /*************************/\r
-                   /* Set the configuration */\r
-                   /*************************/\r
-\r
-                    outl(devpriv->ul_TTLPortConfiguration[b_Cpt / 4],devpriv->iobase + 32 + b_Cpt);\r
-                    }\r
-                 }\r
-              }\r
-          }\r
-       \r
-       /************************************************/\r
-       /* Test if output memory initialisation command */\r
-       /************************************************/\r
-          \r
-       if (b_Command == APCI16XX_TTL_OUTPUTMEMORY)\r
-          {\r
-           if  (data[1])\r
-              {\r
-              devpriv->b_OutputMemoryStatus = ADDIDATA_ENABLE; \r
-              }\r
-           else\r
-              {\r
-              devpriv->b_OutputMemoryStatus = ADDIDATA_DISABLE;\r
-              }\r
-          }\r
-\r
-       return (i_ReturnValue);\r
-       }\r
-\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-|                            INPUT FUNCTIONS                                 |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : INT     i_APCI16XX_InsnBitsReadTTLIO                   |\r
-|                          (comedi_device    *dev,                           |\r
-|                           comedi_subdevice *s,                             |\r
-|                           comedi_insn      *insn,                          |\r
-|                           lsampl_t         *data)                          |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Read the status from selected TTL digital input        |\r
-|                     (b_InputChannel)                                       |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Read the status from digital input port                |\r
-|                     (b_SelectedPort)                                       |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  :                                                        |\r
-|              APCI16XX_TTL_READCHANNEL                                      |\r
-|                    b_SelectedPort= CR_RANGE(insn->chanspec);               |\r
-|                    b_InputChannel= CR_CHAN(insn->chanspec);                |\r
-|                    b_ReadType          = (BYTE) data[0];                          |\r
-|                                                                            |\r
-|              APCI16XX_TTL_READPORT                                         |\r
-|                    b_SelectedPort= CR_RANGE(insn->chanspec);               |\r
-|                    b_ReadType          = (BYTE) data[0];                          |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : data[0]    0 : Channle is not active                   | \r
-|                                1 : Channle is active                       |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      : >0  : No error                                         |\r
-|                    -100 : Config command error                             |\r
-|                    -101 : Data size error                                  |\r
-|                    -102 : The selected TTL input port is wrong             |\r
-|                    -103 : The selected TTL digital input is wrong          |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-\r
-int  i_APCI16XX_InsnBitsReadTTLIO   (comedi_device    *dev,\r
-                                     comedi_subdevice *s,\r
-                                    comedi_insn      *insn,\r
-                                    lsampl_t         *data)\r
-       {\r
-       INT        i_ReturnValue            = insn->n;\r
-       BYTE       b_Command                = 0;\r
-       BYTE       b_NumberOfPort           = (BYTE) (devpriv->ps_BoardInfo->i_NbrTTLChannel / 8);\r
-       BYTE       b_SelectedPort           = CR_RANGE(insn->chanspec);\r
-       BYTE       b_InputChannel           = CR_CHAN(insn->chanspec);\r
-       BYTE *    pb_Status;\r
-       DWORD     dw_Status;\r
-       \r
-       /************************/\r
-       /* Test the buffer size */\r
-       /************************/\r
-       \r
-       if (insn->n >= 1)\r
-          {\r
-          /*******************/\r
-          /* Get the command */\r
-          /* *****************/\r
-          \r
-          b_Command = (BYTE) data[0];\r
-          \r
-          /********************/\r
-          /* Test the command */\r
-          /********************/\r
-          \r
-          if ((b_Command == APCI16XX_TTL_READCHANNEL) || (b_Command == APCI16XX_TTL_READPORT))\r
-             {\r
-             /**************************/\r
-             /* Test the selected port */\r
-             /**************************/\r
-             \r
-             if (b_SelectedPort < b_NumberOfPort)\r
-                {\r
-                 /**********************/\r
-                 /* Test if input port */\r
-                 /**********************/\r
-\r
-                 if (((devpriv->ul_TTLPortConfiguration[b_SelectedPort / 4] >> (8 * (b_SelectedPort % 4))) & 0xFF) == 0)\r
-                    {\r
-                    /***************************/\r
-                    /* Test the channel number */\r
-                    /***************************/\r
-\r
-                   if ((b_Command == APCI16XX_TTL_READCHANNEL) && (b_InputChannel > 7))\r
-                      {\r
-                      /*******************************************/\r
-                      /* The selected TTL digital input is wrong */\r
-                      /*******************************************/\r
-                   \r
-                       printk("\nChannel selection error");\r
-                      i_ReturnValue = -103;\r
-                      }\r
-                    }\r
-                 else\r
-                    {\r
-                   /****************************************/\r
-                    /* The selected TTL input port is wrong */\r
-                    /****************************************/\r
-                 \r
-                    printk("\nPort selection error");\r
-                    i_ReturnValue = -102;\r
-                    }\r
-                }\r
-             else\r
-                {\r
-                /****************************************/\r
-                 /* The selected TTL input port is wrong */\r
-                 /****************************************/\r
-                 \r
-                 printk("\nPort selection error");\r
-                 i_ReturnValue = -102;\r
-                 }\r
-              }\r
-          else\r
-             {\r
-             /************************/\r
-             /* Config command error */\r
-             /************************/\r
-             \r
-             printk("\nCommand selection error");\r
-             i_ReturnValue = -100;\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /*******************/\r
-          /* Data size error */\r
-          /*******************/\r
-              \r
-          printk("\nBuffer size error");\r
-          i_ReturnValue = -101;\r
-          }\r
-          \r
-          \r
-       /**************************/\r
-       /* Test if no error occur */\r
-       /**************************/\r
-       \r
-       if (i_ReturnValue >= 0)\r
-          {\r
-           pb_Status = (PBYTE) &data[0];\r
-           \r
-           /*******************************/\r
-          /* Get the digital inpu status */\r
-           /*******************************/\r
-           \r
-          dw_Status = inl(devpriv->iobase + 8 + ((b_SelectedPort / 4) * 4));\r
-          dw_Status = (dw_Status >> (8 * (b_SelectedPort % 4))) & 0xFF;\r
-          \r
-          /***********************/\r
-          /* Save the port value */\r
-          /***********************/\r
-          \r
-          *pb_Status = (BYTE) dw_Status;\r
-          \r
-          /***************************************/\r
-          /* Test if read channel status command */\r
-          /***************************************/\r
-          \r
-          if (b_Command == APCI16XX_TTL_READCHANNEL)\r
-             {\r
-             *pb_Status = (*pb_Status >> b_InputChannel) & 1;\r
-             }\r
-          }\r
-\r
-       return (i_ReturnValue);\r
-       }\r
-\r
-\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : INT i_APCI16XX_InsnReadTTLIOAllPortValue               |\r
-|                          (comedi_device    *dev,                           |\r
-|                           comedi_subdevice *s,                             |\r
-|                           comedi_insn      *insn,                          |\r
-|                           lsampl_t         *data)                          |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Read the status from all digital input ports           |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : -                                                      |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : data[0] : Port 0 to 3 data                             |\r
-|                     data[1] : Port 4 to 7 data                             |\r
-|                     ....                                                   |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      : 0: No error                                            |\r
-|                    -100 : Read command error                               |\r
-|                    -101 : Data size error                                  |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-int i_APCI16XX_InsnReadTTLIOAllPortValue (comedi_device    *dev,\r
-                                          comedi_subdevice *s,\r
-                                          comedi_insn      *insn,\r
-                                          lsampl_t         *data)\r
-       {\r
-       BYTE         b_Command              = (BYTE) CR_AREF(insn->chanspec);\r
-       INT          i_ReturnValue          = insn->n;\r
-       BYTE         b_Cpt                  = 0;\r
-       BYTE         b_NumberOfPort         = 0;\r
-       lsampl_t * pls_ReadData             = data;\r
-       \r
-       /********************/\r
-       /* Test the command */\r
-       /********************/\r
-          \r
-       if ((b_Command == APCI16XX_TTL_READ_ALL_INPUTS) || (b_Command == APCI16XX_TTL_READ_ALL_OUTPUTS))\r
-          {\r
-          /**********************************/\r
-          /* Get the number of 32-Bit ports */\r
-          /**********************************/\r
-       \r
-          b_NumberOfPort = (BYTE) (devpriv->ps_BoardInfo->i_NbrTTLChannel / 32);\r
-          if ((b_NumberOfPort * 32) < devpriv->ps_BoardInfo->i_NbrTTLChannel)\r
-             {\r
-             b_NumberOfPort = b_NumberOfPort + 1;\r
-             }\r
-       \r
-          /************************/\r
-          /* Test the buffer size */\r
-          /************************/\r
-       \r
-          if (insn->n >= b_NumberOfPort)\r
-             {\r
-              if (b_Command == APCI16XX_TTL_READ_ALL_INPUTS)\r
-                 {\r
-                 /**************************/\r
-                 /* Read all digital input */\r
-                 /**************************/\r
-          \r
-                for (b_Cpt = 0; b_Cpt < b_NumberOfPort; b_Cpt ++)\r
-                   {\r
-                   /************************/\r
-                   /* Read the 32-Bit port */\r
-                   /************************/\r
-             \r
-                   pls_ReadData [b_Cpt]  = inl(devpriv->iobase + 8 + (b_Cpt * 4));\r
-           \r
-                   /**************************************/\r
-                   /* Mask all channels used als outputs */\r
-                   /**************************************/\r
-            \r
-                   pls_ReadData [b_Cpt]  = pls_ReadData [b_Cpt]  & (~devpriv->ul_TTLPortConfiguration[b_Cpt]);\r
-                   }\r
-                }\r
-             else\r
-                 {\r
-                 /****************************/\r
-                 /* Read all digital outputs */\r
-                 /****************************/\r
-          \r
-                for (b_Cpt = 0; b_Cpt < b_NumberOfPort; b_Cpt ++)\r
-                   {\r
-                   /************************/\r
-                   /* Read the 32-Bit port */\r
-                   /************************/\r
-             \r
-                   pls_ReadData [b_Cpt] = inl(devpriv->iobase + 20 + (b_Cpt * 4));\r
-            \r
-                   /**************************************/\r
-                   /* Mask all channels used als outputs */\r
-                   /**************************************/\r
-             \r
-                   pls_ReadData [b_Cpt]  = pls_ReadData [b_Cpt]  & devpriv->ul_TTLPortConfiguration[b_Cpt];\r
-                   }\r
-                }\r
-             }\r
-          else\r
-             {\r
-             /*******************/\r
-             /* Data size error */\r
-             /*******************/\r
-              \r
-             printk("\nBuffer size error");\r
-             i_ReturnValue = -101;\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /*****************/\r
-          /* Command error */\r
-          /*****************/\r
-             \r
-          printk("\nCommand selection error");\r
-          i_ReturnValue = -100;\r
-          }\r
-\r
-       return (i_ReturnValue);\r
-       }\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-|                            OUTPUT FUNCTIONS                                |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function Name     : INT     i_APCI16XX_InsnBitsWriteTTLIO                  |\r
-|                          (comedi_device    *dev,                           |\r
-|                           comedi_subdevice *s,                             |\r
-|                           comedi_insn      *insn,                          |\r
-|                           lsampl_t         *data)                          |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Set the state from selected TTL digital output         |\r
-|                     (b_OutputChannel)                                      |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Set the state from digital output port                 |\r
-|                     (b_SelectedPort)                                       |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  :                                                        |\r
-|              APCI16XX_TTL_WRITECHANNEL_ON | APCI16XX_TTL_WRITECHANNEL_OFF  |\r
-|                    b_SelectedPort = CR_RANGE(insn->chanspec);              |\r
-|                    b_OutputChannel= CR_CHAN(insn->chanspec);               |\r
-|                    b_Command      = (BYTE) data[0];                        |\r
-|                                                                            |\r
-|              APCI16XX_TTL_WRITEPORT_ON | APCI16XX_TTL_WRITEPORT_OFF        |\r
-|                    b_SelectedPort = CR_RANGE(insn->chanspec);              |\r
-|                    b_Command      = (BYTE) data[0];                        |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : data[0] : TTL output port 0 to 3 data                  |\r
-|                     data[1] : TTL output port 4 to 7 data                  |\r
-|                     ....                                                   |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      : >0  : No error                                         |\r
-|                    -100 : Command error                                    |\r
-|                    -101 : Data size error                                  |\r
-|                    -102 : The selected TTL output port is wrong            |\r
-|                    -103 : The selected TTL digital output is wrong         |\r
-|                    -104 : Output memory disabled                           |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-\r
-int  i_APCI16XX_InsnBitsWriteTTLIO   (comedi_device    *dev,\r
-                                      comedi_subdevice *s,\r
-                                      comedi_insn      *insn,\r
-                                      lsampl_t         *data)\r
-       {\r
-       INT          i_ReturnValue          = insn->n;\r
-       BYTE         b_Command              = 0;\r
-       BYTE         b_NumberOfPort         = (BYTE) (devpriv->ps_BoardInfo->i_NbrTTLChannel / 8);\r
-       BYTE         b_SelectedPort         = CR_RANGE(insn->chanspec);\r
-       BYTE         b_OutputChannel        = CR_CHAN(insn->chanspec);\r
-       DWORD       dw_Status               = 0;\r
-\r
-       \r
-       /************************/\r
-       /* Test the buffer size */\r
-       /************************/\r
-       \r
-       if (insn->n >= 1)\r
-          {\r
-          /*******************/\r
-          /* Get the command */\r
-          /* *****************/\r
-          \r
-          b_Command = (BYTE) data[0];\r
-          \r
-          /********************/\r
-          /* Test the command */\r
-          /********************/\r
-          \r
-          if ((b_Command == APCI16XX_TTL_WRITECHANNEL_ON)  || \r
-              (b_Command == APCI16XX_TTL_WRITEPORT_ON)     ||\r
-              (b_Command == APCI16XX_TTL_WRITECHANNEL_OFF) ||\r
-              (b_Command == APCI16XX_TTL_WRITEPORT_OFF))\r
-             {\r
-             /**************************/\r
-             /* Test the selected port */\r
-             /**************************/\r
-             \r
-             if (b_SelectedPort < b_NumberOfPort)\r
-                {\r
-                 /***********************/\r
-                 /* Test if output port */\r
-                 /***********************/\r
-\r
-                 if (((devpriv->ul_TTLPortConfiguration[b_SelectedPort / 4] >> (8 * (b_SelectedPort % 4))) & 0xFF) == 0xFF)\r
-                    {\r
-                    /***************************/\r
-                    /* Test the channel number */\r
-                    /***************************/\r
-\r
-                    if (((b_Command == APCI16XX_TTL_WRITECHANNEL_ON) || \r
-                         (b_Command == APCI16XX_TTL_WRITECHANNEL_OFF)) && (b_OutputChannel > 7))\r
-                      {\r
-                      /********************************************/\r
-                      /* The selected TTL digital output is wrong */\r
-                      /********************************************/\r
-                   \r
-                       printk("\nChannel selection error");\r
-                      i_ReturnValue = -103;\r
-                      }\r
-                    \r
-                    if (((b_Command == APCI16XX_TTL_WRITECHANNEL_OFF) ||\r
-                        (b_Command == APCI16XX_TTL_WRITEPORT_OFF)) && (devpriv->b_OutputMemoryStatus == ADDIDATA_DISABLE))\r
-                      {\r
-                      /********************************************/\r
-                      /* The selected TTL digital output is wrong */\r
-                      /********************************************/\r
-                   \r
-                       printk("\nOutput memory disabled");\r
-                      i_ReturnValue = -104;\r
-                      }\r
-\r
-                   /************************/\r
-                   /* Test the buffer size */\r
-                   /************************/\r
-\r
-                    if (((b_Command == APCI16XX_TTL_WRITEPORT_ON) ||\r
-                        (b_Command == APCI16XX_TTL_WRITEPORT_OFF)) && (insn->n < 2))\r
-                      {\r
-                      /*******************/\r
-                      /* Data size error */\r
-                      /*******************/\r
-              \r
-                      printk("\nBuffer size error");\r
-                      i_ReturnValue = -101;\r
-                      }\r
-                   }\r
-                 else\r
-                    {\r
-                   /*****************************************/\r
-                    /* The selected TTL output port is wrong */\r
-                    /*****************************************/\r
-                 \r
-                    printk("\nPort selection error %lX", devpriv->ul_TTLPortConfiguration[0]);\r
-                    i_ReturnValue = -102;\r
-                    }\r
-                }\r
-             else\r
-                {\r
-                /****************************************/\r
-                 /* The selected TTL output port is wrong */\r
-                 /****************************************/\r
-                 \r
-                 printk("\nPort selection error %d %d",b_SelectedPort , b_NumberOfPort);\r
-                 i_ReturnValue = -102;\r
-                 }\r
-              }\r
-          else\r
-             {\r
-             /************************/\r
-             /* Config command error */\r
-             /************************/\r
-             \r
-             printk("\nCommand selection error");\r
-             i_ReturnValue = -100;\r
-             }\r
-          }\r
-       else\r
-          {\r
-          /*******************/\r
-          /* Data size error */\r
-          /*******************/\r
-              \r
-          printk("\nBuffer size error");\r
-          i_ReturnValue = -101;\r
-          }\r
-          \r
-          \r
-       /**************************/\r
-       /* Test if no error occur */\r
-       /**************************/\r
-       \r
-       if (i_ReturnValue >= 0)\r
-          {\r
-           /********************************/\r
-          /* Get the digital output state */\r
-           /********************************/\r
-             \r
-          dw_Status = inl(devpriv->iobase + 20 + ((b_SelectedPort / 4) * 4));\r
-\r
-          /**********************************/\r
-          /* Test if output memory not used */\r
-          /**********************************/\r
-           \r
-          if (devpriv->b_OutputMemoryStatus == ADDIDATA_DISABLE)\r
-             {\r
-             /*********************************/\r
-             /* Clear the selected port value */\r
-             /*********************************/\r
-             \r
-             dw_Status = dw_Status & (0xFFFFFFFFUL - (0xFFUL << (8 * (b_SelectedPort % 4))));\r
-             }\r
-            \r
-          /******************************/\r
-          /* Test if setting channel ON */\r
-          /******************************/ \r
-          \r
-          if (b_Command == APCI16XX_TTL_WRITECHANNEL_ON)\r
-             {\r
-             dw_Status = dw_Status | (1UL << ((8 * (b_SelectedPort % 4)) + b_OutputChannel));\r
-             }\r
-\r
-          /***************************/\r
-          /* Test if setting port ON */\r
-          /***************************/ \r
-             \r
-          if (b_Command == APCI16XX_TTL_WRITEPORT_ON)\r
-             {\r
-             dw_Status = dw_Status | ((data[1] & 0xFF) << (8 * (b_SelectedPort % 4)));\r
-             }\r
-\r
-          /*******************************/\r
-          /* Test if setting channel OFF */\r
-          /*******************************/ \r
-          \r
-          if (b_Command == APCI16XX_TTL_WRITECHANNEL_OFF)\r
-             {\r
-             dw_Status = dw_Status & (0xFFFFFFFFUL - (1UL << ((8 * (b_SelectedPort % 4)) + b_OutputChannel)));\r
-             }\r
-                   \r
-          /****************************/\r
-          /* Test if setting port OFF */\r
-          /****************************/ \r
-             \r
-          if (b_Command == APCI16XX_TTL_WRITEPORT_OFF)\r
-             {\r
-             dw_Status = dw_Status & (0xFFFFFFFFUL - ((data[1] & 0xFF) << (8 * (b_SelectedPort % 4))));\r
-             }\r
-          \r
-          \r
-           outl(dw_Status, devpriv->iobase + 20 + ((b_SelectedPort / 4) * 4));\r
-          }\r
-\r
-       return (i_ReturnValue);\r
-       }\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function   Name   : int i_APCI2200_Reset(comedi_device *dev)               |                                                         +----------------------------------------------------------------------------+\r
-| Task              :resets all the registers                                |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : comedi_device *dev                                     |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters : -                                                      |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      : -                                                      |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-         \r
-int  i_APCI16XX_Reset(comedi_device *dev) \r
-       {\r
-       return 0;\r
-       }        \r
+/**
+@verbatim
+
+Copyright (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 USA
+
+You 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 APCI1648    | Compiler : gcc                        |
+  | Module name : TTL.C           | Version  : 2.96                       |
+  +-------------------------------+---------------------------------------+
+  | Project manager: S. Weber     | Date     :  25/05/2005                |
+  +-----------------------------------------------------------------------+
+  | Description :   APCI-16XX TTL I/O module                              |
+  |                                                                       |
+  |                                                                       |
+  +-----------------------------------------------------------------------+
+  |                             UPDATES                                   |
+  +-----------------------------------------------------------------------+
+  |   Date   |   Author  |          Description of updates                |
+  +----------+-----------+------------------------------------------------+
+  |25.05.2005| S.Weber   | Creation                                       |
+  |          |           |                                                |
+  +-----------------------------------------------------------------------+
+*/
+
+/*
++----------------------------------------------------------------------------+
+|                               Included files                               |
++----------------------------------------------------------------------------+
+*/
+
+#include "hwdrv_apci16xx.h"
+
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     : INT   i_APCI16XX_InsnConfigInitTTLIO                   |
+|                          (comedi_device    *dev,                           |
+|                           comedi_subdevice *s,                             |
+|                           comedi_insn      *insn,                          |
+|                           lsampl_t         *data)                          |
++----------------------------------------------------------------------------+
+| Task           APCI16XX_TTL_INIT (using defaults)   :                      |
+|                Configure the TTL I/O operating mode from all ports         |
+|                You must calling this function be                           |
+|                for you call any other function witch access of TTL.        |
+|                APCI16XX_TTL_INITDIRECTION(user inputs for direction)       |
++----------------------------------------------------------------------------+
+| Input Parameters  : b_InitType    = (BYTE) data[0];                        |
+|                     b_Port0Mode   = (BYTE) data[1];                        |
+|                     b_Port1Mode   = (BYTE) data[2];                        |
+|                     b_Port2Mode   = (BYTE) data[3];                        |
+|                     b_Port3Mode   = (BYTE) data[4];                        |
+|                     ........                                               |
++----------------------------------------------------------------------------+
+| Output Parameters : -                                                      |
++----------------------------------------------------------------------------+
+| Return Value      :>0: No error                                            |
+|                    -1: Port 0 mode selection is wrong                      |
+|                    -2: Port 1 mode selection is wrong                      |
+|                    -3: Port 2 mode selection is wrong                      |
+|                    -4: Port 3 mode selection is wrong                      |
+|                    -X: Port X-1 mode selection is wrong                    |
+|                    ....                                                    |
+|                    -100 : Config command error                             |
+|                    -101 : Data size error                                  |
++----------------------------------------------------------------------------+
+*/
+
+
+int   i_APCI16XX_InsnConfigInitTTLIO(comedi_device    *dev,
+                                     comedi_subdevice *s,
+                                     comedi_insn      *insn,
+                                     lsampl_t         *data) 
+       {
+       INT        i_ReturnValue            = insn->n;
+       BYTE       b_Command                = 0;
+       BYTE       b_Cpt                    = 0;
+       BYTE       b_NumberOfPort           = (BYTE) (devpriv->ps_BoardInfo->i_NbrTTLChannel / 8);
+       
+       
+       /************************/
+       /* Test the buffer size */
+       /************************/
+       
+       if (insn->n >= 1)
+          {
+          /*******************/
+          /* Get the command */
+          /* *****************/
+          
+          b_Command = (BYTE) data[0];
+          
+          /********************/
+          /* Test the command */
+          /********************/
+          
+          if ((b_Command == APCI16XX_TTL_INIT)          || 
+              (b_Command == APCI16XX_TTL_INITDIRECTION) || 
+              (b_Command == APCI16XX_TTL_OUTPUTMEMORY))
+             {
+             /***************************************/
+             /* Test the initialisation buffer size */
+             /***************************************/
+             
+             if ((b_Command == APCI16XX_TTL_INITDIRECTION) && ((BYTE) (insn->n - 1) != b_NumberOfPort))
+                {
+                /*******************/
+                /* Data size error */
+                /*******************/
+                
+                 printk("\nBuffer size error");
+                i_ReturnValue = -101;
+                }
+
+             if ((b_Command == APCI16XX_TTL_OUTPUTMEMORY) && ((BYTE) (insn->n) != 2))
+                {
+                /*******************/
+                /* Data size error */
+                /*******************/
+                
+                 printk("\nBuffer size error");
+                i_ReturnValue = -101;
+                }
+             }
+          else
+             {
+             /************************/
+             /* Config command error */
+             /************************/
+             
+             printk("\nCommand selection error");
+             i_ReturnValue = -100;
+             }
+          }
+       else
+          {
+          /*******************/
+          /* Data size error */
+          /*******************/
+              
+          printk("\nBuffer size error");
+          i_ReturnValue = -101;
+          }
+          
+          
+       /**************************************************************************/
+       /* Test if no error occur and APCI16XX_TTL_INITDIRECTION command selected */
+       /**************************************************************************/
+       
+       if ((i_ReturnValue >= 0) && (b_Command == APCI16XX_TTL_INITDIRECTION))
+          {
+          memset (devpriv->ul_TTLPortConfiguration, 0, sizeof(devpriv->ul_TTLPortConfiguration));
+
+          /*************************************/
+          /* Test the port direction selection */
+          /*************************************/
+          
+          for (b_Cpt = 1; (b_Cpt <= b_NumberOfPort) && (i_ReturnValue >= 0); b_Cpt ++)
+             {
+             /**********************/
+             /* Test the direction */
+             /**********************/
+             
+             if ((data[b_Cpt] != 0) && (data[b_Cpt] != 0xFF))
+                {
+                /************************/
+                 /* Port direction error */
+                 /************************/
+                 
+                printk("\nPort %d direction selection error", (INT) b_Cpt);
+                i_ReturnValue = - (INT) b_Cpt;
+                }
+             
+              /**************************/
+              /* Save the configuration */
+              /**************************/
+
+
+              devpriv->ul_TTLPortConfiguration[(b_Cpt - 1) / 4] = devpriv->ul_TTLPortConfiguration[(b_Cpt - 1) / 4] |
+                                                                  (data[b_Cpt] << (8 * ((b_Cpt - 1) % 4)));
+             }
+          }
+          
+       /**************************/
+       /* Test if no error occur */
+       /**************************/
+       
+       if (i_ReturnValue >= 0)
+          {
+          /***********************************/
+          /* Test if TTL port initilaisation */
+          /***********************************/
+          
+          if ((b_Command == APCI16XX_TTL_INIT) || (b_Command == APCI16XX_TTL_INITDIRECTION))
+             {
+             /******************************/
+             /* Set all port configuration */
+             /******************************/
+          
+             for (b_Cpt = 0; b_Cpt <= b_NumberOfPort; b_Cpt ++)
+                {
+                if ((b_Cpt % 4) == 0)
+                   {
+                   /*************************/
+                   /* Set the configuration */
+                   /*************************/
+
+                    outl(devpriv->ul_TTLPortConfiguration[b_Cpt / 4],devpriv->iobase + 32 + b_Cpt);
+                    }
+                 }
+              }
+          }
+       
+       /************************************************/
+       /* Test if output memory initialisation command */
+       /************************************************/
+          
+       if (b_Command == APCI16XX_TTL_OUTPUTMEMORY)
+          {
+           if  (data[1])
+              {
+              devpriv->b_OutputMemoryStatus = ADDIDATA_ENABLE; 
+              }
+           else
+              {
+              devpriv->b_OutputMemoryStatus = ADDIDATA_DISABLE;
+              }
+          }
+
+       return (i_ReturnValue);
+       }
+
+
+/*
++----------------------------------------------------------------------------+
+|                            INPUT FUNCTIONS                                 |
++----------------------------------------------------------------------------+
+*/
+
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     : INT     i_APCI16XX_InsnBitsReadTTLIO                   |
+|                          (comedi_device    *dev,                           |
+|                           comedi_subdevice *s,                             |
+|                           comedi_insn      *insn,                          |
+|                           lsampl_t         *data)                          |
++----------------------------------------------------------------------------+
+| Task              : Read the status from selected TTL digital input        |
+|                     (b_InputChannel)                                       |
++----------------------------------------------------------------------------+
+| Task              : Read the status from digital input port                |
+|                     (b_SelectedPort)                                       |
++----------------------------------------------------------------------------+
+| Input Parameters  :                                                        |
+|              APCI16XX_TTL_READCHANNEL                                      |
+|                    b_SelectedPort= CR_RANGE(insn->chanspec);               |
+|                    b_InputChannel= CR_CHAN(insn->chanspec);                |
+|                    b_ReadType          = (BYTE) data[0];                          |
+|                                                                            |
+|              APCI16XX_TTL_READPORT                                         |
+|                    b_SelectedPort= CR_RANGE(insn->chanspec);               |
+|                    b_ReadType          = (BYTE) data[0];                          |
++----------------------------------------------------------------------------+
+| Output Parameters : data[0]    0 : Channle is not active                   | 
+|                                1 : Channle is active                       |
++----------------------------------------------------------------------------+
+| Return Value      : >0  : No error                                         |
+|                    -100 : Config command error                             |
+|                    -101 : Data size error                                  |
+|                    -102 : The selected TTL input port is wrong             |
+|                    -103 : The selected TTL digital input is wrong          |
++----------------------------------------------------------------------------+
+*/
+
+
+int  i_APCI16XX_InsnBitsReadTTLIO   (comedi_device    *dev,
+                                     comedi_subdevice *s,
+                                    comedi_insn      *insn,
+                                    lsampl_t         *data)
+       {
+       INT        i_ReturnValue            = insn->n;
+       BYTE       b_Command                = 0;
+       BYTE       b_NumberOfPort           = (BYTE) (devpriv->ps_BoardInfo->i_NbrTTLChannel / 8);
+       BYTE       b_SelectedPort           = CR_RANGE(insn->chanspec);
+       BYTE       b_InputChannel           = CR_CHAN(insn->chanspec);
+       BYTE *    pb_Status;
+       DWORD     dw_Status;
+       
+       /************************/
+       /* Test the buffer size */
+       /************************/
+       
+       if (insn->n >= 1)
+          {
+          /*******************/
+          /* Get the command */
+          /* *****************/
+          
+          b_Command = (BYTE) data[0];
+          
+          /********************/
+          /* Test the command */
+          /********************/
+          
+          if ((b_Command == APCI16XX_TTL_READCHANNEL) || (b_Command == APCI16XX_TTL_READPORT))
+             {
+             /**************************/
+             /* Test the selected port */
+             /**************************/
+             
+             if (b_SelectedPort < b_NumberOfPort)
+                {
+                 /**********************/
+                 /* Test if input port */
+                 /**********************/
+
+                 if (((devpriv->ul_TTLPortConfiguration[b_SelectedPort / 4] >> (8 * (b_SelectedPort % 4))) & 0xFF) == 0)
+                    {
+                    /***************************/
+                    /* Test the channel number */
+                    /***************************/
+
+                   if ((b_Command == APCI16XX_TTL_READCHANNEL) && (b_InputChannel > 7))
+                      {
+                      /*******************************************/
+                      /* The selected TTL digital input is wrong */
+                      /*******************************************/
+                   
+                       printk("\nChannel selection error");
+                      i_ReturnValue = -103;
+                      }
+                    }
+                 else
+                    {
+                   /****************************************/
+                    /* The selected TTL input port is wrong */
+                    /****************************************/
+                 
+                    printk("\nPort selection error");
+                    i_ReturnValue = -102;
+                    }
+                }
+             else
+                {
+                /****************************************/
+                 /* The selected TTL input port is wrong */
+                 /****************************************/
+                 
+                 printk("\nPort selection error");
+                 i_ReturnValue = -102;
+                 }
+              }
+          else
+             {
+             /************************/
+             /* Config command error */
+             /************************/
+             
+             printk("\nCommand selection error");
+             i_ReturnValue = -100;
+             }
+          }
+       else
+          {
+          /*******************/
+          /* Data size error */
+          /*******************/
+              
+          printk("\nBuffer size error");
+          i_ReturnValue = -101;
+          }
+          
+          
+       /**************************/
+       /* Test if no error occur */
+       /**************************/
+       
+       if (i_ReturnValue >= 0)
+          {
+           pb_Status = (PBYTE) &data[0];
+           
+           /*******************************/
+          /* Get the digital inpu status */
+           /*******************************/
+           
+          dw_Status = inl(devpriv->iobase + 8 + ((b_SelectedPort / 4) * 4));
+          dw_Status = (dw_Status >> (8 * (b_SelectedPort % 4))) & 0xFF;
+          
+          /***********************/
+          /* Save the port value */
+          /***********************/
+          
+          *pb_Status = (BYTE) dw_Status;
+          
+          /***************************************/
+          /* Test if read channel status command */
+          /***************************************/
+          
+          if (b_Command == APCI16XX_TTL_READCHANNEL)
+             {
+             *pb_Status = (*pb_Status >> b_InputChannel) & 1;
+             }
+          }
+
+       return (i_ReturnValue);
+       }
+
+
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     : INT i_APCI16XX_InsnReadTTLIOAllPortValue               |
+|                          (comedi_device    *dev,                           |
+|                           comedi_subdevice *s,                             |
+|                           comedi_insn      *insn,                          |
+|                           lsampl_t         *data)                          |
++----------------------------------------------------------------------------+
+| Task              : Read the status from all digital input ports           |
++----------------------------------------------------------------------------+
+| Input Parameters  : -                                                      |
++----------------------------------------------------------------------------+
+| Output Parameters : data[0] : Port 0 to 3 data                             |
+|                     data[1] : Port 4 to 7 data                             |
+|                     ....                                                   |
++----------------------------------------------------------------------------+
+| Return Value      : 0: No error                                            |
+|                    -100 : Read command error                               |
+|                    -101 : Data size error                                  |
++----------------------------------------------------------------------------+
+*/
+
+int i_APCI16XX_InsnReadTTLIOAllPortValue (comedi_device    *dev,
+                                          comedi_subdevice *s,
+                                          comedi_insn      *insn,
+                                          lsampl_t         *data)
+       {
+       BYTE         b_Command              = (BYTE) CR_AREF(insn->chanspec);
+       INT          i_ReturnValue          = insn->n;
+       BYTE         b_Cpt                  = 0;
+       BYTE         b_NumberOfPort         = 0;
+       lsampl_t * pls_ReadData             = data;
+       
+       /********************/
+       /* Test the command */
+       /********************/
+          
+       if ((b_Command == APCI16XX_TTL_READ_ALL_INPUTS) || (b_Command == APCI16XX_TTL_READ_ALL_OUTPUTS))
+          {
+          /**********************************/
+          /* Get the number of 32-Bit ports */
+          /**********************************/
+       
+          b_NumberOfPort = (BYTE) (devpriv->ps_BoardInfo->i_NbrTTLChannel / 32);
+          if ((b_NumberOfPort * 32) < devpriv->ps_BoardInfo->i_NbrTTLChannel)
+             {
+             b_NumberOfPort = b_NumberOfPort + 1;
+             }
+       
+          /************************/
+          /* Test the buffer size */
+          /************************/
+       
+          if (insn->n >= b_NumberOfPort)
+             {
+              if (b_Command == APCI16XX_TTL_READ_ALL_INPUTS)
+                 {
+                 /**************************/
+                 /* Read all digital input */
+                 /**************************/
+          
+                for (b_Cpt = 0; b_Cpt < b_NumberOfPort; b_Cpt ++)
+                   {
+                   /************************/
+                   /* Read the 32-Bit port */
+                   /************************/
+             
+                   pls_ReadData [b_Cpt]  = inl(devpriv->iobase + 8 + (b_Cpt * 4));
+           
+                   /**************************************/
+                   /* Mask all channels used als outputs */
+                   /**************************************/
+            
+                   pls_ReadData [b_Cpt]  = pls_ReadData [b_Cpt]  & (~devpriv->ul_TTLPortConfiguration[b_Cpt]);
+                   }
+                }
+             else
+                 {
+                 /****************************/
+                 /* Read all digital outputs */
+                 /****************************/
+          
+                for (b_Cpt = 0; b_Cpt < b_NumberOfPort; b_Cpt ++)
+                   {
+                   /************************/
+                   /* Read the 32-Bit port */
+                   /************************/
+             
+                   pls_ReadData [b_Cpt] = inl(devpriv->iobase + 20 + (b_Cpt * 4));
+            
+                   /**************************************/
+                   /* Mask all channels used als outputs */
+                   /**************************************/
+             
+                   pls_ReadData [b_Cpt]  = pls_ReadData [b_Cpt]  & devpriv->ul_TTLPortConfiguration[b_Cpt];
+                   }
+                }
+             }
+          else
+             {
+             /*******************/
+             /* Data size error */
+             /*******************/
+              
+             printk("\nBuffer size error");
+             i_ReturnValue = -101;
+             }
+          }
+       else
+          {
+          /*****************/
+          /* Command error */
+          /*****************/
+             
+          printk("\nCommand selection error");
+          i_ReturnValue = -100;
+          }
+
+       return (i_ReturnValue);
+       }
+
+/*
++----------------------------------------------------------------------------+
+|                            OUTPUT FUNCTIONS                                |
++----------------------------------------------------------------------------+
+*/
+
+/*
++----------------------------------------------------------------------------+
+| Function Name     : INT     i_APCI16XX_InsnBitsWriteTTLIO                  |
+|                          (comedi_device    *dev,                           |
+|                           comedi_subdevice *s,                             |
+|                           comedi_insn      *insn,                          |
+|                           lsampl_t         *data)                          |
++----------------------------------------------------------------------------+
+| Task              : Set the state from selected TTL digital output         |
+|                     (b_OutputChannel)                                      |
++----------------------------------------------------------------------------+
+| Task              : Set the state from digital output port                 |
+|                     (b_SelectedPort)                                       |
++----------------------------------------------------------------------------+
+| Input Parameters  :                                                        |
+|              APCI16XX_TTL_WRITECHANNEL_ON | APCI16XX_TTL_WRITECHANNEL_OFF  |
+|                    b_SelectedPort = CR_RANGE(insn->chanspec);              |
+|                    b_OutputChannel= CR_CHAN(insn->chanspec);               |
+|                    b_Command      = (BYTE) data[0];                        |
+|                                                                            |
+|              APCI16XX_TTL_WRITEPORT_ON | APCI16XX_TTL_WRITEPORT_OFF        |
+|                    b_SelectedPort = CR_RANGE(insn->chanspec);              |
+|                    b_Command      = (BYTE) data[0];                        |
++----------------------------------------------------------------------------+
+| Output Parameters : data[0] : TTL output port 0 to 3 data                  |
+|                     data[1] : TTL output port 4 to 7 data                  |
+|                     ....                                                   |
++----------------------------------------------------------------------------+
+| Return Value      : >0  : No error                                         |
+|                    -100 : Command error                                    |
+|                    -101 : Data size error                                  |
+|                    -102 : The selected TTL output port is wrong            |
+|                    -103 : The selected TTL digital output is wrong         |
+|                    -104 : Output memory disabled                           |
++----------------------------------------------------------------------------+
+*/
+
+
+int  i_APCI16XX_InsnBitsWriteTTLIO   (comedi_device    *dev,
+                                      comedi_subdevice *s,
+                                      comedi_insn      *insn,
+                                      lsampl_t         *data)
+       {
+       INT          i_ReturnValue          = insn->n;
+       BYTE         b_Command              = 0;
+       BYTE         b_NumberOfPort         = (BYTE) (devpriv->ps_BoardInfo->i_NbrTTLChannel / 8);
+       BYTE         b_SelectedPort         = CR_RANGE(insn->chanspec);
+       BYTE         b_OutputChannel        = CR_CHAN(insn->chanspec);
+       DWORD       dw_Status               = 0;
+
+       
+       /************************/
+       /* Test the buffer size */
+       /************************/
+       
+       if (insn->n >= 1)
+          {
+          /*******************/
+          /* Get the command */
+          /* *****************/
+          
+          b_Command = (BYTE) data[0];
+          
+          /********************/
+          /* Test the command */
+          /********************/
+          
+          if ((b_Command == APCI16XX_TTL_WRITECHANNEL_ON)  || 
+              (b_Command == APCI16XX_TTL_WRITEPORT_ON)     ||
+              (b_Command == APCI16XX_TTL_WRITECHANNEL_OFF) ||
+              (b_Command == APCI16XX_TTL_WRITEPORT_OFF))
+             {
+             /**************************/
+             /* Test the selected port */
+             /**************************/
+             
+             if (b_SelectedPort < b_NumberOfPort)
+                {
+                 /***********************/
+                 /* Test if output port */
+                 /***********************/
+
+                 if (((devpriv->ul_TTLPortConfiguration[b_SelectedPort / 4] >> (8 * (b_SelectedPort % 4))) & 0xFF) == 0xFF)
+                    {
+                    /***************************/
+                    /* Test the channel number */
+                    /***************************/
+
+                    if (((b_Command == APCI16XX_TTL_WRITECHANNEL_ON) || 
+                         (b_Command == APCI16XX_TTL_WRITECHANNEL_OFF)) && (b_OutputChannel > 7))
+                      {
+                      /********************************************/
+                      /* The selected TTL digital output is wrong */
+                      /********************************************/
+                   
+                       printk("\nChannel selection error");
+                      i_ReturnValue = -103;
+                      }
+                    
+                    if (((b_Command == APCI16XX_TTL_WRITECHANNEL_OFF) ||
+                        (b_Command == APCI16XX_TTL_WRITEPORT_OFF)) && (devpriv->b_OutputMemoryStatus == ADDIDATA_DISABLE))
+                      {
+                      /********************************************/
+                      /* The selected TTL digital output is wrong */
+                      /********************************************/
+                   
+                       printk("\nOutput memory disabled");
+                      i_ReturnValue = -104;
+                      }
+
+                   /************************/
+                   /* Test the buffer size */
+                   /************************/
+
+                    if (((b_Command == APCI16XX_TTL_WRITEPORT_ON) ||
+                        (b_Command == APCI16XX_TTL_WRITEPORT_OFF)) && (insn->n < 2))
+                      {
+                      /*******************/
+                      /* Data size error */
+                      /*******************/
+              
+                      printk("\nBuffer size error");
+                      i_ReturnValue = -101;
+                      }
+                   }
+                 else
+                    {
+                   /*****************************************/
+                    /* The selected TTL output port is wrong */
+                    /*****************************************/
+                 
+                    printk("\nPort selection error %lX", devpriv->ul_TTLPortConfiguration[0]);
+                    i_ReturnValue = -102;
+                    }
+                }
+             else
+                {
+                /****************************************/
+                 /* The selected TTL output port is wrong */
+                 /****************************************/
+                 
+                 printk("\nPort selection error %d %d",b_SelectedPort , b_NumberOfPort);
+                 i_ReturnValue = -102;
+                 }
+              }
+          else
+             {
+             /************************/
+             /* Config command error */
+             /************************/
+             
+             printk("\nCommand selection error");
+             i_ReturnValue = -100;
+             }
+          }
+       else
+          {
+          /*******************/
+          /* Data size error */
+          /*******************/
+              
+          printk("\nBuffer size error");
+          i_ReturnValue = -101;
+          }
+          
+          
+       /**************************/
+       /* Test if no error occur */
+       /**************************/
+       
+       if (i_ReturnValue >= 0)
+          {
+           /********************************/
+          /* Get the digital output state */
+           /********************************/
+             
+          dw_Status = inl(devpriv->iobase + 20 + ((b_SelectedPort / 4) * 4));
+
+          /**********************************/
+          /* Test if output memory not used */
+          /**********************************/
+           
+          if (devpriv->b_OutputMemoryStatus == ADDIDATA_DISABLE)
+             {
+             /*********************************/
+             /* Clear the selected port value */
+             /*********************************/
+             
+             dw_Status = dw_Status & (0xFFFFFFFFUL - (0xFFUL << (8 * (b_SelectedPort % 4))));
+             }
+            
+          /******************************/
+          /* Test if setting channel ON */
+          /******************************/ 
+          
+          if (b_Command == APCI16XX_TTL_WRITECHANNEL_ON)
+             {
+             dw_Status = dw_Status | (1UL << ((8 * (b_SelectedPort % 4)) + b_OutputChannel));
+             }
+
+          /***************************/
+          /* Test if setting port ON */
+          /***************************/ 
+             
+          if (b_Command == APCI16XX_TTL_WRITEPORT_ON)
+             {
+             dw_Status = dw_Status | ((data[1] & 0xFF) << (8 * (b_SelectedPort % 4)));
+             }
+
+          /*******************************/
+          /* Test if setting channel OFF */
+          /*******************************/ 
+          
+          if (b_Command == APCI16XX_TTL_WRITECHANNEL_OFF)
+             {
+             dw_Status = dw_Status & (0xFFFFFFFFUL - (1UL << ((8 * (b_SelectedPort % 4)) + b_OutputChannel)));
+             }
+                   
+          /****************************/
+          /* Test if setting port OFF */
+          /****************************/ 
+             
+          if (b_Command == APCI16XX_TTL_WRITEPORT_OFF)
+             {
+             dw_Status = dw_Status & (0xFFFFFFFFUL - ((data[1] & 0xFF) << (8 * (b_SelectedPort % 4))));
+             }
+          
+          
+           outl(dw_Status, devpriv->iobase + 20 + ((b_SelectedPort / 4) * 4));
+          }
+
+       return (i_ReturnValue);
+       }
+
+/*
++----------------------------------------------------------------------------+
+| Function   Name   : int i_APCI2200_Reset(comedi_device *dev)               |                                                         +----------------------------------------------------------------------------+
+| Task              :resets all the registers                                |
++----------------------------------------------------------------------------+
+| Input Parameters  : comedi_device *dev                                     |
++----------------------------------------------------------------------------+
+| Output Parameters : -                                                      |
++----------------------------------------------------------------------------+
+| Return Value      : -                                                      |
++----------------------------------------------------------------------------+
+*/
+         
+int  i_APCI16XX_Reset(comedi_device *dev) 
+       {
+       return 0;
+       }        
index 4f1517c02db8a28966747163ff5d939beadbdd08..e25c94fb7cfcbf2465bd79bd2c31fa77a8978f6e 100755 (executable)
-/**\r
-@verbatim\r
-\r
-Copyright (C) 2004,2005  ADDI-DATA GmbH for the source code of this module. \r
-        \r
-        ADDI-DATA GmbH \r
-        Dieselstrasse 3 \r
-        D-77833 Ottersweier \r
-        Tel: +19(0)7223/9493-0 \r
-        Fax: +49(0)7223/9493-92 \r
-        http://www.addi-data-com \r
-        info@addi-data.com \r
-\r
-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.\r
-\r
-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.\r
-\r
-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 USA\r
-\r
-You shoud also find the complete GPL in the COPYING file accompanying this source code.\r
-\r
-@endverbatim\r
-*/\r
-\r
-\r
-\r
-#ifndef COMEDI_SUBD_TTLIO\r
-   #define COMEDI_SUBD_TTLIO   11  /* Digital Input Output But TTL */\r
-#endif\r
-\r
-#ifndef ADDIDATA_ENABLE\r
-   #define ADDIDATA_ENABLE  1\r
-   #define ADDIDATA_DISABLE 0\r
-#endif\r
-\r
-#define APCI16XX_TTL_INIT           0\r
-#define APCI16XX_TTL_INITDIRECTION  1\r
-#define APCI16XX_TTL_OUTPUTMEMORY   2\r
-\r
-\r
-#define APCI16XX_TTL_READCHANNEL            0\r
-#define APCI16XX_TTL_READPORT               1\r
-\r
-#define APCI16XX_TTL_WRITECHANNEL_ON        0\r
-#define APCI16XX_TTL_WRITECHANNEL_OFF       1\r
-#define APCI16XX_TTL_WRITEPORT_ON           2\r
-#define APCI16XX_TTL_WRITEPORT_OFF          3\r
-\r
-#define APCI16XX_TTL_READ_ALL_INPUTS        0\r
-#define APCI16XX_TTL_READ_ALL_OUTPUTS       1\r
-\r
-#ifdef __KERNEL__\r
-\r
-\r
-comedi_lrange range_apci16xx_ttl=\r
-              {12, \r
-               {BIP_RANGE(1),\r
-                BIP_RANGE(1),\r
-                BIP_RANGE(1),\r
-                BIP_RANGE(1),\r
-                BIP_RANGE(1),\r
-                BIP_RANGE(1),\r
-                BIP_RANGE(1),\r
-                BIP_RANGE(1),\r
-                BIP_RANGE(1),\r
-                BIP_RANGE(1),\r
-                BIP_RANGE(1),\r
-                BIP_RANGE(1)}};\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-|                       TTL INISIALISATION FUNCTION                          |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-int   i_APCI16XX_InsnConfigInitTTLIO(comedi_device    *dev,\r
-                                     comedi_subdevice *s,\r
-                                     comedi_insn      *insn,\r
-                                     lsampl_t         *data);\r
-\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-|                       TTL INPUT FUNCTION                                   |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-\r
-int  i_APCI16XX_InsnBitsReadTTLIO   (comedi_device    *dev,\r
-                                     comedi_subdevice *s,\r
-                                     comedi_insn      *insn,\r
-                                     lsampl_t         *data);\r
-\r
-int i_APCI16XX_InsnReadTTLIOAllPortValue (comedi_device    *dev,\r
-                                          comedi_subdevice *s,\r
-                                          comedi_insn      *insn,\r
-                                          lsampl_t         *data);\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-|                            TTL OUTPUT FUNCTIONS                            |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-int  i_APCI16XX_InsnBitsWriteTTLIO   (comedi_device    *dev,\r
-                                      comedi_subdevice *s,\r
-                                      comedi_insn      *insn,\r
-                                      lsampl_t         *data);\r
-                                      \r
-int  i_APCI16XX_Reset(comedi_device *dev) ;                                      \r
-#endif\r
+/**
+@verbatim
+
+Copyright (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 USA
+
+You shoud also find the complete GPL in the COPYING file accompanying this source code.
+
+@endverbatim
+*/
+
+
+
+#ifndef COMEDI_SUBD_TTLIO
+   #define COMEDI_SUBD_TTLIO   11  /* Digital Input Output But TTL */
+#endif
+
+#ifndef ADDIDATA_ENABLE
+   #define ADDIDATA_ENABLE  1
+   #define ADDIDATA_DISABLE 0
+#endif
+
+#define APCI16XX_TTL_INIT           0
+#define APCI16XX_TTL_INITDIRECTION  1
+#define APCI16XX_TTL_OUTPUTMEMORY   2
+
+
+#define APCI16XX_TTL_READCHANNEL            0
+#define APCI16XX_TTL_READPORT               1
+
+#define APCI16XX_TTL_WRITECHANNEL_ON        0
+#define APCI16XX_TTL_WRITECHANNEL_OFF       1
+#define APCI16XX_TTL_WRITEPORT_ON           2
+#define APCI16XX_TTL_WRITEPORT_OFF          3
+
+#define APCI16XX_TTL_READ_ALL_INPUTS        0
+#define APCI16XX_TTL_READ_ALL_OUTPUTS       1
+
+#ifdef __KERNEL__
+
+
+comedi_lrange range_apci16xx_ttl=
+              {12, 
+               {BIP_RANGE(1),
+                BIP_RANGE(1),
+                BIP_RANGE(1),
+                BIP_RANGE(1),
+                BIP_RANGE(1),
+                BIP_RANGE(1),
+                BIP_RANGE(1),
+                BIP_RANGE(1),
+                BIP_RANGE(1),
+                BIP_RANGE(1),
+                BIP_RANGE(1),
+                BIP_RANGE(1)}};
+
+/*
++----------------------------------------------------------------------------+
+|                       TTL INISIALISATION FUNCTION                          |
++----------------------------------------------------------------------------+
+*/
+
+int   i_APCI16XX_InsnConfigInitTTLIO(comedi_device    *dev,
+                                     comedi_subdevice *s,
+                                     comedi_insn      *insn,
+                                     lsampl_t         *data);
+
+
+/*
++----------------------------------------------------------------------------+
+|                       TTL INPUT FUNCTION                                   |
++----------------------------------------------------------------------------+
+*/
+
+
+int  i_APCI16XX_InsnBitsReadTTLIO   (comedi_device    *dev,
+                                     comedi_subdevice *s,
+                                     comedi_insn      *insn,
+                                     lsampl_t         *data);
+
+int i_APCI16XX_InsnReadTTLIOAllPortValue (comedi_device    *dev,
+                                          comedi_subdevice *s,
+                                          comedi_insn      *insn,
+                                          lsampl_t         *data);
+
+/*
++----------------------------------------------------------------------------+
+|                            TTL OUTPUT FUNCTIONS                            |
++----------------------------------------------------------------------------+
+*/
+
+int  i_APCI16XX_InsnBitsWriteTTLIO   (comedi_device    *dev,
+                                      comedi_subdevice *s,
+                                      comedi_insn      *insn,
+                                      lsampl_t         *data);
+                                      
+int  i_APCI16XX_Reset(comedi_device *dev) ;                                      
+#endif
index 69a81ee2b48f61c3d29ad324bc0f565774fb1708..f1eada49477aa6e8ff6318d079a8505cb5bc7120 100644 (file)
-/**\r
-@verbatim\r
-\r
-Copyright (C) 2004,2005  ADDI-DATA GmbH for the source code of this module. \r
-        \r
-        ADDI-DATA GmbH \r
-        Dieselstrasse 3 \r
-        D-77833 Ottersweier \r
-        Tel: +19(0)7223/9493-0 \r
-        Fax: +49(0)7223/9493-92 \r
-        http://www.addi-data-com \r
-        info@addi-data.com \r
-\r
-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.\r
-\r
-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.\r
-\r
-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 USA\r
-\r
-You shoud also find the complete GPL in the COPYING file accompanying this source code.\r
-\r
-@endverbatim\r
-*/\r
-/*\r
-    \r
-  +-----------------------------------------------------------------------+\r
-  | (C) ADDI-DATA GmbH          Dieselstraße 3       D-77833 Ottersweier  |\r
-  +-----------------------------------------------------------------------+\r
-  | Tel : +49 (0) 7223/9493-0     | email    : info@addi-data.com         |\r
-  | Fax : +49 (0) 7223/9493-92    | Internet : http://www.addi-data.com   |\r
-  +-------------------------------+---------------------------------------+\r
-  | Project     : APCI-2016       | Compiler   : GCC                      |\r
-  | Module name : hwdrv_apci2016.c| Version    : 2.96                     |\r
-  +-------------------------------+---------------------------------------+\r
-  | Project manager: Eric Stolz   | Date       :  02/12/2002              |\r
-  +-------------------------------+---------------------------------------+\r
-  | Description :   Hardware Layer Acces For APCI-2016                    |\r
-  +-----------------------------------------------------------------------+\r
-  |                             UPDATES                                   |\r
-  +----------+-----------+------------------------------------------------+\r
-  |   Date   |   Author  |          Description of updates                |\r
-  +----------+-----------+------------------------------------------------+\r
-  |          |           |                                                |\r
-  |          |           |                                                |\r
-  |          |           |                                                |\r
-  +----------+-----------+------------------------------------------------+\r
-*/\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-|                               Included files                               |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-#include "hwdrv_apci2016.h"\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function   Name   : int i_APCI2016_ConfigDigitalOutput                     |\r
-|                        (comedi_device *dev,comedi_subdevice *s,               | \r
-|                      comedi_insn *insn,lsampl_t *data)                     |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Configures The Digital Output Subdevice.               |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : comedi_device *dev : Driver handle                     |\r
-|                     UINT *data         : Data Pointer contains             |\r
-|                                          configuration parameters as below |\r
-|                                                                            | \r
-|                        data[0]            : 1 Digital Memory On               |      \r
-|                                                         0 Digital Memory Off              | \r
-+----------------------------------------------------------------------------+\r
-| Output Parameters :  --                                                                                                       |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      : TRUE  : No error occur                                 |\r
-|                          : FALSE : Error occur. Return the error          |\r
-|                                                                               |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-int i_APCI2016_ConfigDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) \r
-{\r
-  if  ((data[0]!=0) && (data[0]!=1)) \r
-     {   \r
-     comedi_error(dev,"Not a valid Data !!! ,Data should be 1 or 0\n");  \r
-     return -EINVAL;\r
-     } // if  ((data[0]!=0) && (data[0]!=1)) \r
-  if  (data[0])\r
-     {\r
-     devpriv->b_OutputMemoryStatus = ADDIDATA_ENABLE ; \r
-     } // if  (data[0]\r
-  else\r
-     {\r
-     devpriv->b_OutputMemoryStatus = ADDIDATA_DISABLE;\r
-     } // else if  (data[0]\r
-  return insn->n;\r
-}\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function   Name   : int i_APCI2016_WriteDigitalOutput                      |\r
-|                        (comedi_device *dev,comedi_subdevice *s,               |\r
-|                      comedi_insn *insn,lsampl_t *data)                     |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Writes port value  To the selected port                |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : comedi_device *dev      : Driver handle                |\r
-|                     UINT ui_NoOfChannels    : No Of Channels To Write      |\r
-|                     UINT *data              : Data Pointer to read status  |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters :  --                                                                                                       |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      : TRUE  : No error occur                                 |\r
-|                          : FALSE : Error occur. Return the error          |\r
-|                                                                               |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-int i_APCI2016_WriteDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data)  \r
-{\r
-   UINT  ui_NoOfChannel;\r
-   UINT ui_Temp,ui_Temp1;\r
-   ui_NoOfChannel=CR_CHAN(insn->chanspec);\r
-   if  ((ui_NoOfChannel<0) || (ui_NoOfChannel>15)) \r
-      {   \r
-      comedi_error(dev,"Invalid Channel Numbers !!!, Channel Numbers must be between 0 and 15\n");  \r
-      return -EINVAL;\r
-      } // if  ((ui_NoOfChannel<0) || (ui_NoOfChannel>15))\r
-   if  (devpriv->b_OutputMemoryStatus )\r
-      {\r
-      ui_Temp=inw(devpriv->iobase+APCI2016_DIGITAL_OP);\r
-      } // if  (devpriv->b_OutputMemoryStatus )\r
-   else\r
-      { \r
-      ui_Temp=0;\r
-      } // else if  (devpriv->b_OutputMemoryStatus )\r
-   if  ((data[1]!=0) && (data[1]!=1)) \r
-      {   \r
-      comedi_error(dev,"Invalid Data[1] value !!!, Data[1] should be 0 or 1\n");  \r
-      return -EINVAL;\r
-      } // if  ((data[1]!=0) && (data[1]!=1))\r
-  \r
-   if  (data[3]==0)\r
-      { \r
-      if  (data[1]==0)\r
-         {\r
-         data[0]=(data[0] << ui_NoOfChannel)|ui_Temp;\r
-         outw(data[0],devpriv->iobase+APCI2016_DIGITAL_OP); \r
-         } // if (data[1]==0) \r
-      else\r
-         {\r
-         if  (data[1]==1)\r
-            {   \r
-            switch (ui_NoOfChannel)\r
-              {\r
-               case 2:  data[0]=(data[0] << (2*data[2]))|ui_Temp; \r
-                       break;\r
-               case 4:  data[0]=(data[0] << (4*data[2]))|ui_Temp;\r
-                       break;\r
-               case 8:  data[0]=(data[0] << (8*data[2]))|ui_Temp;\r
-                       break;\r
-               case 15: data[0]=data[0]|ui_Temp; \r
-                        break;\r
-               default: comedi_error(dev," chan spec wrong");\r
-                        return -EINVAL;   // "sorry channel spec wrong "  \r
-               }//switch(ui_NoOfChannels)\r
-            outw(data[0],devpriv->iobase+APCI2016_DIGITAL_OP);\r
-            }// if  (data[1]==1)\r
-         else\r
-            {\r
-            printk("\nSpecified channel not supported\n");\r
-            } // else if  (data[1]==1)\r
-         } // else if (data[1]==0)\r
-      } // if (data[3]==0)\r
-   else\r
-      {\r
-      if  (data[3]==1)\r
-         {\r
-         if  (data[1]==0)\r
-            {\r
-            data[0]=~data[0]&0x1;\r
-            ui_Temp1=1;\r
-            ui_Temp1=ui_Temp1<<ui_NoOfChannel;\r
-            ui_Temp=ui_Temp|ui_Temp1;  \r
-            data[0]=(data[0] << ui_NoOfChannel)^0xffff;\r
-            data[0]=data[0]& ui_Temp; \r
-            outw(data[0],devpriv->iobase+APCI2016_DIGITAL_OP); \r
-            } // if  (data[1]==0) \r
-         else\r
-            {\r
-            if  (data[1]==1)\r
-               { \r
-               switch (ui_NoOfChannel)\r
-                 {\r
-                  case 2: data[0]=~data[0]&0x3; \r
-                          ui_Temp1=3;\r
-                          ui_Temp1=ui_Temp1<<2*data[2];\r
-                          ui_Temp=ui_Temp|ui_Temp1;   \r
-                          data[0]=((data[0] << (2*data[2]))^0xffff)& ui_Temp; \r
-                         break;\r
-                  case 4: data[0]=~data[0]&0xf;\r
-                          ui_Temp1=15;\r
-                          ui_Temp1=ui_Temp1<<4*data[2];\r
-                          ui_Temp=ui_Temp|ui_Temp1;    \r
-                          data[0]=((data[0] << (4*data[2]))^0xffff)&ui_Temp;\r
-                         break;\r
-                  case 8: data[0]=~data[0]&0xff;\r
-                          ui_Temp1=255;\r
-                          ui_Temp1=ui_Temp1<<8*data[2];\r
-                          ui_Temp=ui_Temp|ui_Temp1;    \r
-                          data[0]=((data[0] << (8*data[2]))^0xffff)&ui_Temp;\r
-                          break;\r
-                 case 15: break;\r
-                 default: comedi_error(dev," chan spec wrong");\r
-                             return -EINVAL;   // "sorry channel spec wrong "  \r
-                 }//switch(ui_NoOfChannels)\r
-              outw(data[0],devpriv->iobase+APCI2016_DIGITAL_OP);\r
-              }// if(data[1]==1)\r
-           else\r
-              {\r
-              printk("\nSpecified channel not supported\n");\r
-              }//else if(data[1]==1)\r
-           }//elseif(data[1]==0)\r
-        }//if(data[3]==1);\r
-     else\r
-        {\r
-        printk("\nSpecified functionality does not exist\n");\r
-        return -EINVAL;\r
-        }//if else data[3]==1)\r
-     }//if else data[3]==0) \r
-  return insn->n;\r
-}\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function   Name   : int i_APCI2016_BitsDigitalOutput                       |\r
-|                        (comedi_device *dev,comedi_subdevice *s,               |\r
-|                      comedi_insn *insn,lsampl_t *data)                     |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Read  value  of the selected channel or port           |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : comedi_device *dev      : Driver handle                |\r
-|                     UINT ui_NoOfChannels    : No Of Channels To read       |\r
-|                     UINT *data              : Data Pointer to read status  |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters :  --                                                                                                       |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      : TRUE  : No error occur                                 |\r
-|                          : FALSE : Error occur. Return the error          |\r
-|                                                                               |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-int i_APCI2016_BitsDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) \r
-{\r
-   UINT ui_Temp;\r
-   UINT ui_NoOfChannel;\r
-   ui_NoOfChannel=CR_CHAN(insn->chanspec);\r
-   if  ((ui_NoOfChannel<0) || (ui_NoOfChannel>15)) \r
-      {   \r
-      comedi_error(dev,"Invalid Channel Numbers !!!, Channel Numbers must be between 0 and 15\n");  \r
-      return -EINVAL;\r
-      } // if  ((ui_NoOfChannel<0) || (ui_NoOfChannel>15))\r
-   if  ((data[0]!=0) && (data[0]!=1)) \r
-      {   \r
-      comedi_error(dev,"Invalid Data[0] value !!!, Data[0] should be 0 or 1\n");  \r
-      return -EINVAL;\r
-      }  // if  ((data[0]!=0) && (data[0]!=1))\r
-   ui_Temp=data[0];\r
-   *data=inw(devpriv->iobase+APCI2016_DIGITAL_OP_RW);\r
-   if  (ui_Temp==0)\r
-      {\r
-       *data=(*data >> ui_NoOfChannel)&0x1;\r
-      } // if  (ui_Temp==0)\r
-   else\r
-      {\r
-      if  (ui_Temp==1)\r
-         {\r
-         switch (ui_NoOfChannel)\r
-          {\r
-           case 2: *data=(*data >>(2*data[1]))&3; \r
-                  break;\r
-       \r
-           case 4: *data=(*data >>(4*data[1]))&15; \r
-                  break;\r
-\r
-           case 8: *data=(*data >>(8*data[1]))&255;  \r
-                   break;\r
\r
-          case 15: break;\r
-\r
-          default:\r
-                 comedi_error(dev," chan spec wrong");\r
-                 return -EINVAL;   // "sorry channel spec wrong "  \r
-          }//switch(ui_NoOfChannel)    \r
-       } // if  (ui_Temp==1)\r
-    else\r
-       {\r
-       printk("\nSpecified channel not supported \n");\r
-       } // else if  (ui_Temp==1)\r
-    } // if  (ui_Temp==0)\r
-    return insn->n;\r
-}\r
-\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function   Name   : int i_APCI2016_ConfigWatchdog                          |\r
-|                        (comedi_device *dev,comedi_subdevice *s,               |\r
-|                      comedi_insn *insn,lsampl_t *data)                     |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Configures The Watchdog                                |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  :   comedi_device *dev      : Driver handle              |\r
-|                     comedi_subdevice *s,   :pointer to subdevice structure |\r
-|                     comedi_insn *insn      :pointer to insn structure      |\r
-|                     lsampl_t *data          : Data Pointer to read status  |    \r
-+----------------------------------------------------------------------------+\r
-| Output Parameters :  --                                                                                                       |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      : TRUE  : No error occur                                 |\r
-|                          : FALSE : Error occur. Return the error          |\r
-|                                                                               |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-int i_APCI2016_ConfigWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) \r
-{ \r
-  \r
-   if  (data[0]==0)\r
-      {\r
-      //Disable the watchdog\r
-      outw(0x0,devpriv->i_IobaseAddon+ APCI2016_WATCHDOG_ENABLEDISABLE);\r
-      //Loading the Reload value\r
-      outw(data[1],devpriv->i_IobaseAddon+APCI2016_WATCHDOG_RELOAD_VALUE);\r
-      data[1]=data[1]>>16;\r
-      outw(data[1],devpriv->i_IobaseAddon+APCI2016_WATCHDOG_RELOAD_VALUE+2);\r
-      }\r
-   else\r
-      {\r
-      printk("\nThe input parameters are wrong\n");\r
-      }\r
-   return insn->n;\r
-}\r
-\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function   Name   : int i_APCI2016_StartStopWriteWatchdog                  |\r
-|                        (comedi_device *dev,comedi_subdevice *s,               |\r
-|                      comedi_insn *insn,lsampl_t *data)                     |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Start / Stop The Watchdog                              |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : comedi_device *dev      : Driver handle                |\r
-|                     comedi_subdevice *s,   :pointer to subdevice structure |\r
-|                     comedi_insn *insn      :pointer to insn structure      |\r
-|                     lsampl_t *data          : Data Pointer to read status  |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters :  --                                                                                                       |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      : TRUE  : No error occur                                 |\r
-|                          : FALSE : Error occur. Return the error          |\r
-|                                                                               |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-int i_APCI2016_StartStopWriteWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data)\r
-{\r
-\r
-   switch(data[0])\r
-      {\r
-       case 0://stop the watchdog\r
-                outw(0x0,devpriv->i_IobaseAddon+ APCI2016_WATCHDOG_ENABLEDISABLE);//disable the watchdog \r
-                break;\r
-       case 1://start the watchdog\r
-               outw(0x0001,devpriv->i_IobaseAddon+ APCI2016_WATCHDOG_ENABLEDISABLE);\r
-               break;\r
-       case 2://Software trigger  \r
-              outw(0x0201,devpriv->i_IobaseAddon+ APCI2016_WATCHDOG_ENABLEDISABLE);\r
-              break;\r
-       default:printk("\nSpecified functionality does not exist\n");\r
-              return -EINVAL;\r
-       }// switch(data[0])  \r
-\r
-  return insn->n;\r
-}\r
-\r
\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function   Name   : int i_APCI2016_ReadWatchdog                            |\r
-|                        (comedi_device *dev,comedi_subdevice *s,               |\r
-|                      comedi_insn *insn,lsampl_t *data)                     |\r
-+----------------------------------------------------------------------------+\r
-| Task              : Read The Watchdog                                      |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : comedi_device *dev      : Driver handle                |\r
-|                     comedi_subdevice *s,   :pointer to subdevice structure | \r
-|                     comedi_insn *insn      :pointer to insn structure      |\r
-|                     lsampl_t *data          : Data Pointer to read status  |\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters :  --                                                                                                       |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      : TRUE  : No error occur                                 |\r
-|                          : FALSE : Error occur. Return the error          |\r
-|                                                                               |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-\r
-int i_APCI2016_ReadWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data)\r
-{  \r
-   udelay(5);   \r
-   data[0]= inw(devpriv->i_IobaseAddon+APCI2016_WATCHDOG_STATUS)&0x1; \r
-   return insn->n;\r
-}\r
-\r
-/*\r
-+----------------------------------------------------------------------------+\r
-| Function   Name   : int i_APCI2016_Reset(comedi_device *dev)               |                                                       |\r
-+----------------------------------------------------------------------------+\r
-| Task              :resets all the registers                                |\r
-+----------------------------------------------------------------------------+\r
-| Input Parameters  : comedi_device *dev\r
-+----------------------------------------------------------------------------+\r
-| Output Parameters :  --                                                                                                       |\r
-+----------------------------------------------------------------------------+\r
-| Return Value      :                                                        |\r
-|                                                                               |\r
-+----------------------------------------------------------------------------+\r
-*/\r
-         \r
-INT i_APCI2016_Reset(comedi_device *dev) \r
-{\r
-  outw(0x0,devpriv->iobase+APCI2016_DIGITAL_OP);   // Resets the digital output channels\r
-  outw(0x0,devpriv->i_IobaseAddon+ APCI2016_WATCHDOG_ENABLEDISABLE);\r
-  outw(0x0,devpriv->i_IobaseAddon+APCI2016_WATCHDOG_RELOAD_VALUE);\r
-  outw(0x0,devpriv->i_IobaseAddon+APCI2016_WATCHDOG_RELOAD_VALUE+2);\r
-  return 0;\r
-}\r
+/**
+@verbatim
+
+Copyright (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 USA
+
+You 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     : APCI-2016       | Compiler   : GCC                      |
+  | Module name : hwdrv_apci2016.c| Version    : 2.96                     |
+  +-------------------------------+---------------------------------------+
+  | Project manager: Eric Stolz   | Date       :  02/12/2002              |
+  +-------------------------------+---------------------------------------+
+  | Description :   Hardware Layer Acces For APCI-2016                    |
+  +-----------------------------------------------------------------------+
+  |                             UPDATES                                   |
+  +----------+-----------+------------------------------------------------+
+  |   Date   |   Author  |          Description of updates                |
+  +----------+-----------+------------------------------------------------+
+  |          |           |                                                |
+  |          |           |                                                |
+  |          |           |                                                |
+  +----------+-----------+------------------------------------------------+
+*/
+
+/*
++----------------------------------------------------------------------------+
+|                               Included files                               |
++----------------------------------------------------------------------------+
+*/
+#include "hwdrv_apci2016.h"
+
+/*
++----------------------------------------------------------------------------+
+| Function   Name   : int i_APCI2016_ConfigDigitalOutput                     |
+|                        (comedi_device *dev,comedi_subdevice *s,               | 
+|                      comedi_insn *insn,lsampl_t *data)                     |
++----------------------------------------------------------------------------+
+| Task              : Configures The Digital Output Subdevice.               |
++----------------------------------------------------------------------------+
+| Input Parameters  : comedi_device *dev : Driver handle                     |
+|                     UINT *data         : Data Pointer contains             |
+|                                          configuration parameters as below |
+|                                                                            | 
+|                        data[0]            : 1 Digital Memory On               |      
+|                                                         0 Digital Memory Off              | 
++----------------------------------------------------------------------------+
+| Output Parameters :  --                                                                                                       |
++----------------------------------------------------------------------------+
+| Return Value      : TRUE  : No error occur                                 |
+|                          : FALSE : Error occur. Return the error          |
+|                                                                               |
++----------------------------------------------------------------------------+
+*/
+int i_APCI2016_ConfigDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) 
+{
+  if  ((data[0]!=0) && (data[0]!=1)) 
+     {   
+     comedi_error(dev,"Not a valid Data !!! ,Data should be 1 or 0\n");  
+     return -EINVAL;
+     } // if  ((data[0]!=0) && (data[0]!=1)) 
+  if  (data[0])
+     {
+     devpriv->b_OutputMemoryStatus = ADDIDATA_ENABLE ; 
+     } // if  (data[0]
+  else
+     {
+     devpriv->b_OutputMemoryStatus = ADDIDATA_DISABLE;
+     } // else if  (data[0]
+  return insn->n;
+}
+
+/*
++----------------------------------------------------------------------------+
+| Function   Name   : int i_APCI2016_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_APCI2016_WriteDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data)  
+{
+   UINT  ui_NoOfChannel;
+   UINT ui_Temp,ui_Temp1;
+   ui_NoOfChannel=CR_CHAN(insn->chanspec);
+   if  ((ui_NoOfChannel<0) || (ui_NoOfChannel>15)) 
+      {   
+      comedi_error(dev,"Invalid Channel Numbers !!!, Channel Numbers must be between 0 and 15\n");  
+      return -EINVAL;
+      } // if  ((ui_NoOfChannel<0) || (ui_NoOfChannel>15))
+   if  (devpriv->b_OutputMemoryStatus )
+      {
+      ui_Temp=inw(devpriv->iobase+APCI2016_DIGITAL_OP);
+      } // if  (devpriv->b_OutputMemoryStatus )
+   else
+      { 
+      ui_Temp=0;
+      } // else if  (devpriv->b_OutputMemoryStatus )
+   if  ((data[1]!=0) && (data[1]!=1)) 
+      {   
+      comedi_error(dev,"Invalid Data[1] value !!!, Data[1] should be 0 or 1\n");  
+      return -EINVAL;
+      } // if  ((data[1]!=0) && (data[1]!=1))
+  
+   if  (data[3]==0)
+      { 
+      if  (data[1]==0)
+         {
+         data[0]=(data[0] << ui_NoOfChannel)|ui_Temp;
+         outw(data[0],devpriv->iobase+APCI2016_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 "  
+               }//switch(ui_NoOfChannels)
+            outw(data[0],devpriv->iobase+APCI2016_DIGITAL_OP);
+            }// if  (data[1]==1)
+         else
+            {
+            printk("\nSpecified channel not supported\n");
+            } // else if  (data[1]==1)
+         } // else if (data[1]==0)
+      } // if (data[3]==0)
+   else
+      {
+      if  (data[3]==1)
+         {
+         if  (data[1]==0)
+            {
+            data[0]=~data[0]&0x1;
+            ui_Temp1=1;
+            ui_Temp1=ui_Temp1<<ui_NoOfChannel;
+            ui_Temp=ui_Temp|ui_Temp1;  
+            data[0]=(data[0] << ui_NoOfChannel)^0xffff;
+            data[0]=data[0]& ui_Temp; 
+            outw(data[0],devpriv->iobase+APCI2016_DIGITAL_OP); 
+            } // if  (data[1]==0) 
+         else
+            {
+            if  (data[1]==1)
+               { 
+               switch (ui_NoOfChannel)
+                 {
+                  case 2: data[0]=~data[0]&0x3; 
+                          ui_Temp1=3;
+                          ui_Temp1=ui_Temp1<<2*data[2];
+                          ui_Temp=ui_Temp|ui_Temp1;   
+                          data[0]=((data[0] << (2*data[2]))^0xffff)& ui_Temp; 
+                         break;
+                  case 4: data[0]=~data[0]&0xf;
+                          ui_Temp1=15;
+                          ui_Temp1=ui_Temp1<<4*data[2];
+                          ui_Temp=ui_Temp|ui_Temp1;    
+                          data[0]=((data[0] << (4*data[2]))^0xffff)&ui_Temp;
+                         break;
+                  case 8: data[0]=~data[0]&0xff;
+                          ui_Temp1=255;
+                          ui_Temp1=ui_Temp1<<8*data[2];
+                          ui_Temp=ui_Temp|ui_Temp1;    
+                          data[0]=((data[0] << (8*data[2]))^0xffff)&ui_Temp;
+                          break;
+                 case 15: break;
+                 default: comedi_error(dev," chan spec wrong");
+                             return -EINVAL;   // "sorry channel spec wrong "  
+                 }//switch(ui_NoOfChannels)
+              outw(data[0],devpriv->iobase+APCI2016_DIGITAL_OP);
+              }// if(data[1]==1)
+           else
+              {
+              printk("\nSpecified channel not supported\n");
+              }//else if(data[1]==1)
+           }//elseif(data[1]==0)
+        }//if(data[3]==1);
+     else
+        {
+        printk("\nSpecified functionality does not exist\n");
+        return -EINVAL;
+        }//if else data[3]==1)
+     }//if else data[3]==0) 
+  return insn->n;
+}
+
+/*
++----------------------------------------------------------------------------+
+| Function   Name   : int i_APCI2016_BitsDigitalOutput                       |
+|                        (comedi_device *dev,comedi_subdevice *s,               |
+|                      comedi_insn *insn,lsampl_t *data)                     |
++----------------------------------------------------------------------------+
+| Task              : Read  value  of the selected channel or port           |
++----------------------------------------------------------------------------+
+| Input Parameters  : comedi_device *dev      : Driver handle                |
+|                     UINT ui_NoOfChannels    : No Of Channels To read       |
+|                     UINT *data              : Data Pointer to read status  |
++----------------------------------------------------------------------------+
+| Output Parameters :  --                                                                                                       |
++----------------------------------------------------------------------------+
+| Return Value      : TRUE  : No error occur                                 |
+|                          : FALSE : Error occur. Return the error          |
+|                                                                               |
++----------------------------------------------------------------------------+
+*/
+int i_APCI2016_BitsDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) 
+{
+   UINT ui_Temp;
+   UINT ui_NoOfChannel;
+   ui_NoOfChannel=CR_CHAN(insn->chanspec);
+   if  ((ui_NoOfChannel<0) || (ui_NoOfChannel>15)) 
+      {   
+      comedi_error(dev,"Invalid Channel Numbers !!!, Channel Numbers must be between 0 and 15\n");  
+      return -EINVAL;
+      } // if  ((ui_NoOfChannel<0) || (ui_NoOfChannel>15))
+   if  ((data[0]!=0) && (data[0]!=1)) 
+      {   
+      comedi_error(dev,"Invalid Data[0] value !!!, Data[0] should be 0 or 1\n");  
+      return -EINVAL;
+      }  // if  ((data[0]!=0) && (data[0]!=1))
+   ui_Temp=data[0];
+   *data=inw(devpriv->iobase+APCI2016_DIGITAL_OP_RW);
+   if  (ui_Temp==0)
+      {
+       *data=(*data >> ui_NoOfChannel)&0x1;
+      } // if  (ui_Temp==0)
+   else
+      {
+      if  (ui_Temp==1)
+         {
+         switch (ui_NoOfChannel)
+          {
+           case 2: *data=(*data >>(2*data[1]))&3; 
+                  break;
+       
+           case 4: *data=(*data >>(4*data[1]))&15; 
+                  break;
+
+           case 8: *data=(*data >>(8*data[1]))&255;  
+                   break;
+          case 15: break;
+
+          default:
+                 comedi_error(dev," chan spec wrong");
+                 return -EINVAL;   // "sorry channel spec wrong "  
+          }//switch(ui_NoOfChannel)    
+       } // if  (ui_Temp==1)
+    else
+       {
+       printk("\nSpecified channel not supported \n");
+       } // else if  (ui_Temp==1)
+    } // if  (ui_Temp==0)
+    return insn->n;
+}
+
+
+/*
++----------------------------------------------------------------------------+
+| Function   Name   : int i_APCI2016_ConfigWatchdog                          |
+|                        (comedi_device *dev,comedi_subdevice *s,               |
+|                      comedi_insn *insn,lsampl_t *data)                     |
++----------------------------------------------------------------------------+
+| Task              : Configures The Watchdog                                |
++----------------------------------------------------------------------------+
+| Input Parameters  :   comedi_device *dev      : Driver handle              |
+|                     comedi_subdevice *s,   :pointer to subdevice structure |
+|                     comedi_insn *insn      :pointer to insn structure      |
+|                     lsampl_t *data          : Data Pointer to read status  |    
++----------------------------------------------------------------------------+
+| Output Parameters :  --                                                                                                       |
++----------------------------------------------------------------------------+
+| Return Value      : TRUE  : No error occur                                 |
+|                          : FALSE : Error occur. Return the error          |
+|                                                                               |
++----------------------------------------------------------------------------+
+*/
+int i_APCI2016_ConfigWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) 
+{ 
+  
+   if  (data[0]==0)
+      {
+      //Disable the watchdog
+      outw(0x0,devpriv->i_IobaseAddon+ APCI2016_WATCHDOG_ENABLEDISABLE);
+      //Loading the Reload value
+      outw(data[1],devpriv->i_IobaseAddon+APCI2016_WATCHDOG_RELOAD_VALUE);
+      data[1]=data[1]>>16;
+      outw(data[1],devpriv->i_IobaseAddon+APCI2016_WATCHDOG_RELOAD_VALUE+2);
+      }
+   else
+      {
+      printk("\nThe input parameters are wrong\n");
+      }
+   return insn->n;
+}
+
+
+/*
++----------------------------------------------------------------------------+
+| Function   Name   : int i_APCI2016_StartStopWriteWatchdog                  |
+|                        (comedi_device *dev,comedi_subdevice *s,               |
+|                      comedi_insn *insn,lsampl_t *data)                     |
++----------------------------------------------------------------------------+
+| Task              : Start / Stop The Watchdog                              |
++----------------------------------------------------------------------------+
+| Input Parameters  : comedi_device *dev      : Driver handle                |
+|                     comedi_subdevice *s,   :pointer to subdevice structure |
+|                     comedi_insn *insn      :pointer to insn structure      |
+|                     lsampl_t *data          : Data Pointer to read status  |
++----------------------------------------------------------------------------+
+| Output Parameters :  --                                                                                                       |
++----------------------------------------------------------------------------+
+| Return Value      : TRUE  : No error occur                                 |
+|                          : FALSE : Error occur. Return the error          |
+|                                                                               |
++----------------------------------------------------------------------------+
+*/
+int i_APCI2016_StartStopWriteWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data)
+{
+
+   switch(data[0])
+      {
+       case 0://stop the watchdog
+                outw(0x0,devpriv->i_IobaseAddon+ APCI2016_WATCHDOG_ENABLEDISABLE);//disable the watchdog 
+                break;
+       case 1://start the watchdog
+               outw(0x0001,devpriv->i_IobaseAddon+ APCI2016_WATCHDOG_ENABLEDISABLE);
+               break;
+       case 2://Software trigger  
+              outw(0x0201,devpriv->i_IobaseAddon+ APCI2016_WATCHDOG_ENABLEDISABLE);
+              break;
+       default:printk("\nSpecified functionality does not exist\n");
+              return -EINVAL;
+       }// switch(data[0])  
+
+  return insn->n;
+}
+
+/*
++----------------------------------------------------------------------------+
+| Function   Name   : int i_APCI2016_ReadWatchdog                            |
+|                        (comedi_device *dev,comedi_subdevice *s,               |
+|                      comedi_insn *insn,lsampl_t *data)                     |
++----------------------------------------------------------------------------+
+| Task              : Read The Watchdog                                      |
++----------------------------------------------------------------------------+
+| Input Parameters  : comedi_device *dev      : Driver handle                |
+|                     comedi_subdevice *s,   :pointer to subdevice structure | 
+|                     comedi_insn *insn      :pointer to insn structure      |
+|                     lsampl_t *data          : Data Pointer to read status  |
++----------------------------------------------------------------------------+
+| Output Parameters :  --                                                                                                       |
++----------------------------------------------------------------------------+
+| Return Value      : TRUE  : No error occur                                 |
+|                          : FALSE : Error occur. Return the error          |
+|                                                                               |
++----------------------------------------------------------------------------+
+*/
+
+int i_APCI2016_ReadWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data)
+{  
+   udelay(5);   
+   data[0]= inw(devpriv->i_IobaseAddon+APCI2016_WATCHDOG_STATUS)&0x1; 
+   return insn->n;
+}
+
+/*
++----------------------------------------------------------------------------+
+| Function   Name   : int i_APCI2016_Reset(comedi_device *dev)               |                                                       |
++----------------------------------------------------------------------------+
+| Task              :resets all the registers                                |
++----------------------------------------------------------------------------+
+| Input Parameters  : comedi_device *dev
++----------------------------------------------------------------------------+
+| Output Parameters :  --                                                                                                       |
++----------------------------------------------------------------------------+
+| Return Value      :                                                        |
+|                                                                               |
++----------------------------------------------------------------------------+
+*/
+         
+INT i_APCI2016_Reset(comedi_device *dev) 
+{
+  outw(0x0,devpriv->iobase+APCI2016_DIGITAL_OP);   // Resets the digital output channels
+  outw(0x0,devpriv->i_IobaseAddon+ APCI2016_WATCHDOG_ENABLEDISABLE);
+  outw(0x0,devpriv->i_IobaseAddon+APCI2016_WATCHDOG_RELOAD_VALUE);
+  outw(0x0,devpriv->i_IobaseAddon+APCI2016_WATCHDOG_RELOAD_VALUE+2);
+  return 0;
+}
index 3659aa033b3b8954264264e7987d5cdc856d7893..cf1992099297ed5f6366ceb08110bc11afe1de1c 100644 (file)
@@ -1,76 +1,76 @@
-/**\r
-@verbatim\r
-\r
-Copyright (C) 2004,2005  ADDI-DATA GmbH for the source code of this module. \r
-        \r
-        ADDI-DATA GmbH \r
-        Dieselstrasse 3 \r
-        D-77833 Ottersweier \r
-        Tel: +19(0)7223/9493-0 \r
-        Fax: +49(0)7223/9493-92 \r
-        http://www.addi-data-com \r
-        info@addi-data.com \r
-\r
-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.\r
-\r
-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.\r
-\r
-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 USA\r
-\r
-You shoud also find the complete GPL in the COPYING file accompanying this source code.\r
-\r
-@endverbatim\r
-*/\r
-/*********      Definitions for APCI-2016 card  *****/\r
-\r
-#define APCI2016_BOARD_VENDOR_ID 0x15B8\r
-#define APCI2016_ADDRESS_RANGE   8\r
-\r
-\r
-//DIGITAL INPUT-OUTPUT DEFINE   \r
-\r
-#define APCI2016_DIGITAL_OP                    0x04 \r
-#define APCI2016_DIGITAL_OP_RW                         4 \r
-\r
-//ADDIDATA Enable Disable\r
-\r
-#define ADDIDATA_ENABLE                            1\r
-#define ADDIDATA_DISABLE                           0\r
-\r
-// TIMER COUNTER WATCHDOG DEFINES  \r
-\r
-#define ADDIDATA_WATCHDOG                          2\r
-#define APCI2016_DIGITAL_OP_WATCHDOG               0\r
-#define APCI2016_WATCHDOG_ENABLEDISABLE            12\r
-#define APCI2016_WATCHDOG_RELOAD_VALUE             4\r
-#define APCI2016_WATCHDOG_STATUS                   16\r
-\r
-\r
-// Hardware Layer  functions for Apci2016\r
-\r
-//DO\r
-int i_APCI2016_ConfigDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) ;\r
-\r
-int i_APCI2016_WriteDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);  \r
-\r
-int i_APCI2016_BitsDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);\r
-\r
-\r
-// TIMER  \r
-// timer value is passed as u seconds\r
-\r
-\r
-int i_APCI2016_ConfigWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) ;\r
-\r
-int i_APCI2016_StartStopWriteWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);\r
-\r
-int i_APCI2016_ReadWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);\r
-\r
-\r
-// Interrupt functions.....\r
-\r
-// VOID v_APCI2016_Interrupt(int irq, void *d, struct pt_regs *regs) ;\r
-\r
- //VOID v_APCI2016_Interrupt(int irq, void *d, struct pt_regs *regs);\r
-// RESET\r
-INT i_APCI2016_Reset(comedi_device *dev);\r
+/**
+@verbatim
+
+Copyright (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 USA
+
+You shoud also find the complete GPL in the COPYING file accompanying this source code.
+
+@endverbatim
+*/
+/*********      Definitions for APCI-2016 card  *****/
+
+#define APCI2016_BOARD_VENDOR_ID 0x15B8
+#define APCI2016_ADDRESS_RANGE   8
+
+
+//DIGITAL INPUT-OUTPUT DEFINE   
+
+#define APCI2016_DIGITAL_OP                    0x04 
+#define APCI2016_DIGITAL_OP_RW                         4 
+
+//ADDIDATA Enable Disable
+
+#define ADDIDATA_ENABLE                            1
+#define ADDIDATA_DISABLE                           0
+
+// TIMER COUNTER WATCHDOG DEFINES  
+
+#define ADDIDATA_WATCHDOG                          2
+#define APCI2016_DIGITAL_OP_WATCHDOG               0
+#define APCI2016_WATCHDOG_ENABLEDISABLE            12
+#define APCI2016_WATCHDOG_RELOAD_VALUE             4
+#define APCI2016_WATCHDOG_STATUS                   16
+
+
+// Hardware Layer  functions for Apci2016
+
+//DO
+int i_APCI2016_ConfigDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) ;
+
+int i_APCI2016_WriteDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);  
+
+int i_APCI2016_BitsDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);
+
+
+// TIMER  
+// timer value is passed as u seconds
+
+
+int i_APCI2016_ConfigWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) ;
+
+int i_APCI2016_StartStopWriteWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);
+
+int i_APCI2016_ReadWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);
+
+
+// Interrupt functions.....
+
+// VOID v_APCI2016_Interrupt(int irq, void *d, struct pt_regs *regs) ;
+
+ //VOID v_APCI2016_Interrupt(int irq, void *d, struct pt_regs *regs);
+// RESET
+INT i_APCI2016_Reset(comedi_device *dev);
index 1b1535ab6eeec948cb0fe6d4cd2a28f560ef5f3e..6d1a5730d788b4aa1d3e780cc8d7427f71075ca2 100644 (file)
@@ -24,7 +24,7 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc
 /*
     
   +-----------------------------------------------------------------------+
-  | (C) ADDI-DATA GmbH          Dieselstraße 3       D-77833 Ottersweier  |
+  | (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   |
index 839c84cbf7bd32173a988a64d0cb0bea06899629..6d67796d5b62e0f895eb2f28dffb3b88c84bfc00 100644 (file)
@@ -1,85 +1,85 @@
-/**\r
-@verbatim\r
-\r
-Copyright (C) 2004,2005  ADDI-DATA GmbH for the source code of this module. \r
-        \r
-        ADDI-DATA GmbH \r
-        Dieselstrasse 3 \r
-        D-77833 Ottersweier \r
-        Tel: +19(0)7223/9493-0 \r
-        Fax: +49(0)7223/9493-92 \r
-        http://www.addi-data-com \r
-        info@addi-data.com \r
-\r
-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.\r
-\r
-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.\r
-\r
-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 USA\r
-\r
-You shoud also find the complete GPL in the COPYING file accompanying this source code.\r
-\r
-@endverbatim\r
-*/\r
-/*********      Definitions for APCI-2032 card  *****/\r
-\r
-// Card Specific information\r
-#define APCI2032_BOARD_VENDOR_ID                 0x15B8\r
-#define APCI2032_ADDRESS_RANGE                   63\r
-\r
-\r
-//DIGITAL INPUT-OUTPUT DEFINE   \r
-\r
-#define APCI2032_DIGITAL_OP                    0 \r
-#define APCI2032_DIGITAL_OP_RW                         0 \r
-#define APCI2032_DIGITAL_OP_INTERRUPT           4\r
-#define APCI2032_DIGITAL_OP_IRQ                 12\r
-\r
-//Digital Output Interrupt Status\r
-#define APCI2032_DIGITAL_OP_INTERRUPT_STATUS    8\r
-\r
-//Digital Output Interrupt Enable Disable.\r
-#define APCI2032_DIGITAL_OP_VCC_INTERRUPT_ENABLE   0x1\r
-#define APCI2032_DIGITAL_OP_VCC_INTERRUPT_DISABLE  0xFFFFFFFE\r
-#define APCI2032_DIGITAL_OP_CC_INTERRUPT_ENABLE    0x2\r
-#define APCI2032_DIGITAL_OP_CC_INTERRUPT_DISABLE   0xFFFFFFFD\r
-\r
-//ADDIDATA Enable Disable\r
-\r
-#define ADDIDATA_ENABLE                            1\r
-#define ADDIDATA_DISABLE                           0\r
-\r
-// TIMER COUNTER WATCHDOG DEFINES  \r
-\r
-#define ADDIDATA_WATCHDOG                          2\r
-#define APCI2032_DIGITAL_OP_WATCHDOG               16\r
-#define APCI2032_TCW_RELOAD_VALUE                  4\r
-#define APCI2032_TCW_TIMEBASE                      8\r
-#define APCI2032_TCW_PROG                          12\r
-#define APCI2032_TCW_TRIG_STATUS                   16\r
-#define APCI2032_TCW_IRQ                           20\r
-\r
-\r
-\r
-\r
-// Hardware Layer  functions for Apci2032\r
-\r
-\r
-//DO\r
-int i_APCI2032_ConfigDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);\r
-INT i_APCI2032_WriteDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);\r
-INT i_APCI2032_ReadDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);\r
-int i_APCI2032_ReadInterruptStatus(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);\r
-\r
-// TIMER  \r
-// timer value is passed as u seconds\r
-INT i_APCI2032_ConfigWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);\r
-int i_APCI2032_StartStopWriteWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); \r
-int i_APCI2032_ReadWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);\r
\r
-// Interrupt functions.....\r
-\r
-void v_APCI2032_Interrupt(int irq, void *d, struct pt_regs *regs) ;\r
-\r
-//Reset functions\r
- int i_APCI2032_Reset(comedi_device *dev);     \r
+/**
+@verbatim
+
+Copyright (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 USA
+
+You shoud also find the complete GPL in the COPYING file accompanying this source code.
+
+@endverbatim
+*/
+/*********      Definitions for APCI-2032 card  *****/
+
+// Card Specific information
+#define APCI2032_BOARD_VENDOR_ID                 0x15B8
+#define APCI2032_ADDRESS_RANGE                   63
+
+
+//DIGITAL INPUT-OUTPUT DEFINE   
+
+#define APCI2032_DIGITAL_OP                    0 
+#define APCI2032_DIGITAL_OP_RW                         0 
+#define APCI2032_DIGITAL_OP_INTERRUPT           4
+#define APCI2032_DIGITAL_OP_IRQ                 12
+
+//Digital Output Interrupt Status
+#define APCI2032_DIGITAL_OP_INTERRUPT_STATUS    8
+
+//Digital Output Interrupt Enable Disable.
+#define APCI2032_DIGITAL_OP_VCC_INTERRUPT_ENABLE   0x1
+#define APCI2032_DIGITAL_OP_VCC_INTERRUPT_DISABLE  0xFFFFFFFE
+#define APCI2032_DIGITAL_OP_CC_INTERRUPT_ENABLE    0x2
+#define APCI2032_DIGITAL_OP_CC_INTERRUPT_DISABLE   0xFFFFFFFD
+
+//ADDIDATA Enable Disable
+
+#define ADDIDATA_ENABLE                            1
+#define ADDIDATA_DISABLE                           0
+
+// TIMER COUNTER WATCHDOG DEFINES  
+
+#define ADDIDATA_WATCHDOG                          2
+#define APCI2032_DIGITAL_OP_WATCHDOG               16
+#define APCI2032_TCW_RELOAD_VALUE                  4
+#define APCI2032_TCW_TIMEBASE                      8
+#define APCI2032_TCW_PROG                          12
+#define APCI2032_TCW_TRIG_STATUS                   16
+#define APCI2032_TCW_IRQ                           20
+
+
+
+
+// Hardware Layer  functions for Apci2032
+
+
+//DO
+int i_APCI2032_ConfigDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);
+INT i_APCI2032_WriteDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);
+INT i_APCI2032_ReadDigitalOutput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);
+int i_APCI2032_ReadInterruptStatus(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);
+
+// TIMER  
+// timer value is passed as u seconds
+INT i_APCI2032_ConfigWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);
+int i_APCI2032_StartStopWriteWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); 
+int i_APCI2032_ReadWatchdog(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);
+// Interrupt functions.....
+
+void v_APCI2032_Interrupt(int irq, void *d, struct pt_regs *regs) ;
+
+//Reset functions
+ int i_APCI2032_Reset(comedi_device *dev);     
index 46024efbf24ad8cc5cb98dbc579a70cc3d472028..44fcf10643c0c3b46aabe342d5ec70455296776c 100644 (file)
@@ -24,7 +24,7 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc
 /*
     
   +-----------------------------------------------------------------------+
-  | (C) ADDI-DATA GmbH          Dieselstraße 3       D-77833 Ottersweier  |
+  | (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   |
index 59a8b57517faf8ac2ae7dfb1466f9a6ed089fc0c..dce0a6d771ecda866b0e37c152ecd3e49ed6dd18 100644 (file)
@@ -24,7 +24,7 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc
 /*
     
   +-----------------------------------------------------------------------+
-  | (C) ADDI-DATA GmbH          Dieselstraße 3       D-77833 Ottersweier  |
+  | (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   |
index 50e6f2683aff0adb2d3cbc2832bc3ff4aec6ae78..82b608c3e8550f596e668795775eb6b9b4be57e4 100644 (file)
-/**\r
-@verbatim\r
-\r
-Copyright (C) 2004,2005  ADDI-DATA GmbH for the source code of this module. \r
-        \r
-        ADDI-DATA GmbH \r
-        Dieselstrasse 3 \r
-        D-77833 Ottersweier \r
-        Tel: +19(0)7223/9493-0 \r
-        Fax: +49(0)7223/9493-92 \r
-        http://www.addi-data-com \r
-        info@addi-data.com \r
-\r
-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.\r
-\r
-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.\r
-\r
-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 USA\r
-\r
-You shoud also find the complete GPL in the COPYING file accompanying this source code.\r
-\r
-@endverbatim\r
-*/\r
-\r
-// Card Specific information\r
-#define APCI3200_BOARD_VENDOR_ID                 0x15B8\r
-//#define APCI3200_ADDRESS_RANGE                   264\r
-\r
-\r
-\r
-int MODULE_NO ;\r
- struct \r
-{                              \r
- INT i_Gain ;\r
- INT i_Polarity;\r
- INT i_OffsetRange;\r
- INT i_Coupling;\r
- INT i_SingleDiff;\r
- INT i_AutoCalibration;\r
- UINT ui_ReloadValue;\r
- UINT ui_TimeUnitReloadVal;\r
- INT i_Interrupt;\r
- INT i_ModuleSelection;\r
-}Config_Parameters_Module1,Config_Parameters_Module2,Config_Parameters_Module3,Config_Parameters_Module4;\r
-\r
-\r
-\r
-//ANALOG INPUT RANGE \r
-comedi_lrange range_apci3200_ai={ 8, {\r
-               BIP_RANGE(10),\r
-               BIP_RANGE(5),\r
-               BIP_RANGE(2),\r
-               BIP_RANGE(1),\r
-               UNI_RANGE(10),\r
-               UNI_RANGE(5),\r
-               UNI_RANGE(2),\r
-               UNI_RANGE(1)\r
-       }\r
-};\r
-\r
-comedi_lrange range_apci3300_ai={ 4, {\r
-               UNI_RANGE(10),\r
-               UNI_RANGE(5),\r
-               UNI_RANGE(2),\r
-               UNI_RANGE(1)\r
-       }\r
-};\r
-\r
-//Analog Input related Defines\r
-#define APCI3200_AI_OFFSET_GAIN                  0\r
-#define APCI3200_AI_SC_TEST                      4\r
-#define APCI3200_AI_IRQ                          8\r
-#define APCI3200_AI_AUTOCAL                      12\r
-#define APCI3200_RELOAD_CONV_TIME_VAL            32\r
-#define APCI3200_CONV_TIME_TIME_BASE             36\r
-#define APCI3200_RELOAD_DELAY_TIME_VAL           40\r
-#define APCI3200_DELAY_TIME_TIME_BASE            44\r
-#define APCI3200_AI_MODULE1                      0\r
-#define APCI3200_AI_MODULE2                      64\r
-#define APCI3200_AI_MODULE3                      128\r
-#define APCI3200_AI_MODULE4                      192\r
-#define TRUE                                     1\r
-#define FALSE                                    0\r
-#define APCI3200_AI_EOSIRQ                       16\r
-#define APCI3200_AI_EOS                          20\r
-#define APCI3200_AI_CHAN_ID                      24\r
-#define APCI3200_AI_CHAN_VAL                     28\r
-#define ANALOG_INPUT                             0\r
-#define TEMPERATURE                              1\r
-#define RESISTANCE                               2\r
-\r
-#define ENABLE_EXT_TRIG                          1\r
-#define ENABLE_EXT_GATE                          2\r
-#define ENABLE_EXT_TRIG_GATE                     3\r
-\r
-\r
-#define APCI3200_MAXVOLT                         2.5\r
-#define ADDIDATA_GREATER_THAN_TEST               0\r
-#define ADDIDATA_LESS_THAN_TEST                  1\r
-\r
-#define ADDIDATA_UNIPOLAR                        1\r
-#define ADDIDATA_BIPOLAR                         2\r
-\r
-//ADDIDATA Enable Disable\r
-#define ADDIDATA_ENABLE                            1\r
-#define ADDIDATA_DISABLE                           0\r
-\r
-//BEGIN JK 21.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values\r
-#define MAX_MODULE                             4\r
-//END JK 21.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values\r
-\r
-typedef struct\r
-   {\r
-   ULONG ul_NumberOfValue;\r
-   ULONG *pul_ResistanceValue;\r
-   ULONG *pul_TemperatureValue;\r
-   }str_ADDIDATA_RTDStruct,*pstr_ADDIDATA_RTDStruct;\r
-\r
-//BEGIN JK 21.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values\r
-typedef struct\r
-   {\r
-   // Begin JK 05/08/2003 change for Linux    \r
-   unsigned long ul_CurrentSourceCJC;\r
-   unsigned long ul_CurrentSource [5];\r
-   // End JK 05/08/2003 change for Linux\r
-\r
-   // Begin CG 15/02/02 Rev 1.0 -> Rev 1.1 : Add Header Type 1\r
-   unsigned long  ul_GainFactor [8]; // Gain Factor \r
-   unsigned int w_GainValue [10];\r
-   // End CG 15/02/02 Rev 1.0 -> Rev 1.1 : Add Header Type 1\r
-   }str_Module;\r
-//END JK 21.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values\r
-   \r
-//BEGIN JK 06.07.04: Management of sevrals boards\r
-typedef struct \r
-   {\r
-   INT i_CJCAvailable; \r
-   INT i_CJCPolarity;\r
-   INT i_CJCGain;\r
-   INT i_InterruptFlag;\r
-   INT i_ADDIDATAPolarity;\r
-   INT i_ADDIDATAGain;                  \r
-   INT i_AutoCalibration;\r
-   INT i_ADDIDATAConversionTime;\r
-   INT i_ADDIDATAConversionTimeUnit; \r
-   INT i_ADDIDATAType;\r
-   INT i_ChannelNo;\r
-   INT i_ChannelCount;\r
-   INT i_ScanType;\r
-   INT i_FirstChannel;\r
-   INT i_LastChannel;\r
-   INT i_Sum;\r
-   INT i_Offset;\r
-   UINT ui_Channel_num;\r
-   INT i_Count;\r
-   INT i_Initialised;\r
-   //UINT ui_InterruptChannelValue[96]; //Buffer\r
-   UINT ui_InterruptChannelValue[144]; //Buffer\r
-   BYTE b_StructInitialized;\r
-   //Begin JK 19.10.2004: APCI-3200 Driver update 0.7.57 -> 0.7.68\r
-   lsampl_t ui_ScanValueArray [7+12]; // 7 is the maximal number of channels\r
-   //End JK 19.10.2004: APCI-3200 Driver update 0.7.57 -> 0.7.68\r
-   \r
-   //Begin JK 21.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values   \r
-   INT i_ConnectionType;\r
-   INT     i_NbrOfModule;\r
-   str_Module s_Module [MAX_MODULE];\r
-   //End JK 21.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values\r
-   } str_BoardInfos;\r
-//END JK 06.07.04: Management of sevrals boards\r
-\r
-\r
-// Hardware Layer  functions for Apci3200\r
-\r
-//AI\r
-\r
-INT i_APCI3200_ConfigAnalogInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);\r
-INT i_APCI3200_ReadAnalogInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);\r
-INT i_APCI3200_InsnWriteReleaseAnalogInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);\r
-INT i_APCI3200_InsnBits_AnalogInput_Test(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); \r
-INT i_APCI3200_StopCyclicAcquisition(comedi_device *dev,comedi_subdevice *s);\r
-INT i_APCI3200_InterruptHandleEos(comedi_device *dev);\r
-INT i_APCI3200_CommandTestAnalogInput(comedi_device *dev,comedi_subdevice *s,comedi_cmd *cmd) ;\r
-INT i_APCI3200_CommandAnalogInput(comedi_device *dev,comedi_subdevice *s);\r
-INT i_APCI3200_ReadDigitalInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);\r
-//Interrupt\r
-void v_APCI3200_Interrupt(int irq, void *d, struct pt_regs *regs) ;\r
-int i_APCI3200_InterruptHandleEos(comedi_device *dev);\r
-//Reset functions\r
-INT i_APCI3200_Reset(comedi_device *dev);      \r
-\r
-\r
-int i_APCI3200_ReadCJCCalOffset(comedi_device *dev,lsampl_t *data);\r
-int i_APCI3200_ReadCJCValue(comedi_device *dev,lsampl_t *data);\r
-int i_APCI3200_ReadCalibrationGainValue(comedi_device *dev,UINT *data);\r
-int i_APCI3200_ReadCalibrationOffsetValue(comedi_device *dev,UINT *data);\r
-int i_APCI3200_Read1AnalogInputChannel(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);\r
-int i_APCI3200_ReadCJCCalGain(comedi_device *dev,lsampl_t *data);\r
+/**
+@verbatim
+
+Copyright (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 USA
+
+You shoud also find the complete GPL in the COPYING file accompanying this source code.
+
+@endverbatim
+*/
+
+// Card Specific information
+#define APCI3200_BOARD_VENDOR_ID                 0x15B8
+//#define APCI3200_ADDRESS_RANGE                   264
+
+
+
+int MODULE_NO ;
+ struct 
+{                              
+ INT i_Gain ;
+ INT i_Polarity;
+ INT i_OffsetRange;
+ INT i_Coupling;
+ INT i_SingleDiff;
+ INT i_AutoCalibration;
+ UINT ui_ReloadValue;
+ UINT ui_TimeUnitReloadVal;
+ INT i_Interrupt;
+ INT i_ModuleSelection;
+}Config_Parameters_Module1,Config_Parameters_Module2,Config_Parameters_Module3,Config_Parameters_Module4;
+
+
+
+//ANALOG INPUT RANGE 
+comedi_lrange range_apci3200_ai={ 8, {
+               BIP_RANGE(10),
+               BIP_RANGE(5),
+               BIP_RANGE(2),
+               BIP_RANGE(1),
+               UNI_RANGE(10),
+               UNI_RANGE(5),
+               UNI_RANGE(2),
+               UNI_RANGE(1)
+       }
+};
+
+comedi_lrange range_apci3300_ai={ 4, {
+               UNI_RANGE(10),
+               UNI_RANGE(5),
+               UNI_RANGE(2),
+               UNI_RANGE(1)
+       }
+};
+
+//Analog Input related Defines
+#define APCI3200_AI_OFFSET_GAIN                  0
+#define APCI3200_AI_SC_TEST                      4
+#define APCI3200_AI_IRQ                          8
+#define APCI3200_AI_AUTOCAL                      12
+#define APCI3200_RELOAD_CONV_TIME_VAL            32
+#define APCI3200_CONV_TIME_TIME_BASE             36
+#define APCI3200_RELOAD_DELAY_TIME_VAL           40
+#define APCI3200_DELAY_TIME_TIME_BASE            44
+#define APCI3200_AI_MODULE1                      0
+#define APCI3200_AI_MODULE2                      64
+#define APCI3200_AI_MODULE3                      128
+#define APCI3200_AI_MODULE4                      192
+#define TRUE                                     1
+#define FALSE                                    0
+#define APCI3200_AI_EOSIRQ                       16
+#define APCI3200_AI_EOS                          20
+#define APCI3200_AI_CHAN_ID                      24
+#define APCI3200_AI_CHAN_VAL                     28
+#define ANALOG_INPUT                             0
+#define TEMPERATURE                              1
+#define RESISTANCE                               2
+
+#define ENABLE_EXT_TRIG                          1
+#define ENABLE_EXT_GATE                          2
+#define ENABLE_EXT_TRIG_GATE                     3
+
+
+#define APCI3200_MAXVOLT                         2.5
+#define ADDIDATA_GREATER_THAN_TEST               0
+#define ADDIDATA_LESS_THAN_TEST                  1
+
+#define ADDIDATA_UNIPOLAR                        1
+#define ADDIDATA_BIPOLAR                         2
+
+//ADDIDATA Enable Disable
+#define ADDIDATA_ENABLE                            1
+#define ADDIDATA_DISABLE                           0
+
+//BEGIN JK 21.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values
+#define MAX_MODULE                             4
+//END JK 21.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values
+
+typedef struct
+   {
+   ULONG ul_NumberOfValue;
+   ULONG *pul_ResistanceValue;
+   ULONG *pul_TemperatureValue;
+   }str_ADDIDATA_RTDStruct,*pstr_ADDIDATA_RTDStruct;
+
+//BEGIN JK 21.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values
+typedef struct
+   {
+   // Begin JK 05/08/2003 change for Linux    
+   unsigned long ul_CurrentSourceCJC;
+   unsigned long ul_CurrentSource [5];
+   // End JK 05/08/2003 change for Linux
+
+   // Begin CG 15/02/02 Rev 1.0 -> Rev 1.1 : Add Header Type 1
+   unsigned long  ul_GainFactor [8]; // Gain Factor 
+   unsigned int w_GainValue [10];
+   // End CG 15/02/02 Rev 1.0 -> Rev 1.1 : Add Header Type 1
+   }str_Module;
+//END JK 21.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values
+   
+//BEGIN JK 06.07.04: Management of sevrals boards
+typedef struct 
+   {
+   INT i_CJCAvailable; 
+   INT i_CJCPolarity;
+   INT i_CJCGain;
+   INT i_InterruptFlag;
+   INT i_ADDIDATAPolarity;
+   INT i_ADDIDATAGain;                  
+   INT i_AutoCalibration;
+   INT i_ADDIDATAConversionTime;
+   INT i_ADDIDATAConversionTimeUnit; 
+   INT i_ADDIDATAType;
+   INT i_ChannelNo;
+   INT i_ChannelCount;
+   INT i_ScanType;
+   INT i_FirstChannel;
+   INT i_LastChannel;
+   INT i_Sum;
+   INT i_Offset;
+   UINT ui_Channel_num;
+   INT i_Count;
+   INT i_Initialised;
+   //UINT ui_InterruptChannelValue[96]; //Buffer
+   UINT ui_InterruptChannelValue[144]; //Buffer
+   BYTE b_StructInitialized;
+   //Begin JK 19.10.2004: APCI-3200 Driver update 0.7.57 -> 0.7.68
+   lsampl_t ui_ScanValueArray [7+12]; // 7 is the maximal number of channels
+   //End JK 19.10.2004: APCI-3200 Driver update 0.7.57 -> 0.7.68
+   
+   //Begin JK 21.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values   
+   INT i_ConnectionType;
+   INT     i_NbrOfModule;
+   str_Module s_Module [MAX_MODULE];
+   //End JK 21.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values
+   } str_BoardInfos;
+//END JK 06.07.04: Management of sevrals boards
+
+
+// Hardware Layer  functions for Apci3200
+
+//AI
+
+INT i_APCI3200_ConfigAnalogInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);
+INT i_APCI3200_ReadAnalogInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);
+INT i_APCI3200_InsnWriteReleaseAnalogInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);
+INT i_APCI3200_InsnBits_AnalogInput_Test(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); 
+INT i_APCI3200_StopCyclicAcquisition(comedi_device *dev,comedi_subdevice *s);
+INT i_APCI3200_InterruptHandleEos(comedi_device *dev);
+INT i_APCI3200_CommandTestAnalogInput(comedi_device *dev,comedi_subdevice *s,comedi_cmd *cmd) ;
+INT i_APCI3200_CommandAnalogInput(comedi_device *dev,comedi_subdevice *s);
+INT i_APCI3200_ReadDigitalInput(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);
+//Interrupt
+void v_APCI3200_Interrupt(int irq, void *d, struct pt_regs *regs) ;
+int i_APCI3200_InterruptHandleEos(comedi_device *dev);
+//Reset functions
+INT i_APCI3200_Reset(comedi_device *dev);      
+
+
+int i_APCI3200_ReadCJCCalOffset(comedi_device *dev,lsampl_t *data);
+int i_APCI3200_ReadCJCValue(comedi_device *dev,lsampl_t *data);
+int i_APCI3200_ReadCalibrationGainValue(comedi_device *dev,UINT *data);
+int i_APCI3200_ReadCalibrationOffsetValue(comedi_device *dev,UINT *data);
+int i_APCI3200_Read1AnalogInputChannel(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);
+int i_APCI3200_ReadCJCCalGain(comedi_device *dev,lsampl_t *data);
index eed480e179a07ff2a45a1f7549b83acdf8f9e203..44f53f46c21e71f3c3953a5234d27ff176dd6bb7 100644 (file)
@@ -24,7 +24,7 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc
 /*.
     
   +-----------------------------------------------------------------------+
-  | (C) ADDI-DATA GmbH          Dieselstraße 3       D-77833 Ottersweier  |
+  | (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   |
index 1f670e92cf2463bef57cd2f298d5877bf6393c1b..58d573404fafc20d88dbeba5b50df790024a593a 100755 (executable)
@@ -1,70 +1,70 @@
-/**\r
-@verbatim\r
-\r
-Copyright (C) 2004,2005  ADDI-DATA GmbH for the source code of this module. \r
-        \r
-        ADDI-DATA GmbH \r
-        Dieselstrasse 3 \r
-        D-77833 Ottersweier \r
-        Tel: +19(0)7223/9493-0 \r
-        Fax: +49(0)7223/9493-92 \r
-        http://www.addi-data-com \r
-        info@addi-data.com \r
-\r
-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.\r
-\r
-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.\r
-\r
-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 USA\r
-\r
-You shoud also find the complete GPL in the COPYING file accompanying this source code.\r
-\r
-@endverbatim\r
-*/\r
-\r
-\r
-\r
-#ifndef COMEDI_SUBD_TTLIO\r
-   #define COMEDI_SUBD_TTLIO   11  /* Digital Input Output But TTL */\r
-#endif\r
-\r
-#ifndef ADDIDATA_ENABLE\r
-   #define ADDIDATA_ENABLE  1\r
-   #define ADDIDATA_DISABLE 0\r
-#endif\r
-\r
-#define APCI3XXX_SINGLE                              0\r
-#define APCI3XXX_DIFF                                1\r
-#define APCI3XXX_CONFIGURATION                       0\r
-\r
-\r
-#define APCI3XXX_TTL_INIT_DIRECTION_PORT2   0\r
-\r
-#ifdef __KERNEL__\r
-\r
-\r
-comedi_lrange range_apci3XXX_ai={ 8, {BIP_RANGE(10),\r
-                                      BIP_RANGE(5),\r
-                                      BIP_RANGE(2),\r
-                                      BIP_RANGE(1),\r
-                                      UNI_RANGE(10),\r
-                                      UNI_RANGE(5),\r
-                                      UNI_RANGE(2),\r
-                                      UNI_RANGE(1)}};\r
-                                     \r
-comedi_lrange range_apci3XXX_ttl= {12, {BIP_RANGE(1),\r
-                                        BIP_RANGE(1),\r
-                                        BIP_RANGE(1),\r
-                                        BIP_RANGE(1),\r
-                                        BIP_RANGE(1),\r
-                                        BIP_RANGE(1),\r
-                                        BIP_RANGE(1),\r
-                                        BIP_RANGE(1),\r
-                                        BIP_RANGE(1),\r
-                                        BIP_RANGE(1),\r
-                                        BIP_RANGE(1),\r
-                                        BIP_RANGE(1)}};\r
-\r
-comedi_lrange range_apci3XXX_ao= { 2, {BIP_RANGE(10),\r
-                                       UNI_RANGE(10)}};\r
-#endif\r
+/**
+@verbatim
+
+Copyright (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 USA
+
+You shoud also find the complete GPL in the COPYING file accompanying this source code.
+
+@endverbatim
+*/
+
+
+
+#ifndef COMEDI_SUBD_TTLIO
+   #define COMEDI_SUBD_TTLIO   11  /* Digital Input Output But TTL */
+#endif
+
+#ifndef ADDIDATA_ENABLE
+   #define ADDIDATA_ENABLE  1
+   #define ADDIDATA_DISABLE 0
+#endif
+
+#define APCI3XXX_SINGLE                              0
+#define APCI3XXX_DIFF                                1
+#define APCI3XXX_CONFIGURATION                       0
+
+
+#define APCI3XXX_TTL_INIT_DIRECTION_PORT2   0
+
+#ifdef __KERNEL__
+
+
+comedi_lrange range_apci3XXX_ai={ 8, {BIP_RANGE(10),
+                                      BIP_RANGE(5),
+                                      BIP_RANGE(2),
+                                      BIP_RANGE(1),
+                                      UNI_RANGE(10),
+                                      UNI_RANGE(5),
+                                      UNI_RANGE(2),
+                                      UNI_RANGE(1)}};
+                                     
+comedi_lrange range_apci3XXX_ttl= {12, {BIP_RANGE(1),
+                                        BIP_RANGE(1),
+                                        BIP_RANGE(1),
+                                        BIP_RANGE(1),
+                                        BIP_RANGE(1),
+                                        BIP_RANGE(1),
+                                        BIP_RANGE(1),
+                                        BIP_RANGE(1),
+                                        BIP_RANGE(1),
+                                        BIP_RANGE(1),
+                                        BIP_RANGE(1),
+                                        BIP_RANGE(1)}};
+
+comedi_lrange range_apci3XXX_ao= { 2, {BIP_RANGE(10),
+                                       UNI_RANGE(10)}};
+#endif