RTXI 1.3
comedi/comedi/drivers/addi-data/APCI1710_Tor.c
Go to the documentation of this file.
00001 
00024 /*
00025     
00026   +-----------------------------------------------------------------------+
00027   | (C) ADDI-DATA GmbH          Dieselstraße 3       D-77833 Ottersweier  |
00028   +-----------------------------------------------------------------------+
00029   | Tel : +49 (0) 7223/9493-0     | email    : info@addi-data.com         |
00030   | Fax : +49 (0) 7223/9493-92    | Internet : http://www.addi-data.com   |
00031   +-----------------------------------------------------------------------+
00032   | Project     : API APCI1710    | Compiler : gcc                        |
00033   | Module name : TOR.C           | Version  : 2.96                       |
00034   +-------------------------------+---------------------------------------+
00035   | Project manager: Eric Stolz   | Date     :  02/12/2002                |
00036   +-----------------------------------------------------------------------+
00037   | Description :   APCI-1710 tor counter module                          |
00038   |                                                                       |
00039   |                                                                       |
00040   +-----------------------------------------------------------------------+
00041   |                             UPDATES                                   |
00042   +-----------------------------------------------------------------------+
00043   |   Date   |   Author  |          Description of updates                |
00044   +----------+-----------+------------------------------------------------+
00045   | 27/01/99 | S. Weber  | 40 MHz implementation                          |
00046   +-----------------------------------------------------------------------+
00047   | 28/04/00 | S. Weber  | Simple,double and quadruple mode implementation|
00048   |          |           | Extern clock implementation                    |
00049   +-----------------------------------------------------------------------+
00050   | 08/05/00 | Guinot C  | - 0400/0228 All Function in RING 0             |
00051   |          |           |   available                                    |
00052   +-----------------------------------------------------------------------+
00053 */
00054 
00055 /*
00056 +----------------------------------------------------------------------------+
00057 |                               Included files                               |
00058 +----------------------------------------------------------------------------+
00059 */
00060 
00061 #include "APCI1710_Tor.h"
00062 
00063 /*
00064 +----------------------------------------------------------------------------+
00065 | Function Name     : _INT_     i_APCI1710_InitTorCounter                    |
00066 |                                       (BYTE_     b_BoardHandle,            |
00067 |                                        BYTE_     b_ModulNbr,               |
00068 |                                        BYTE_     b_TorCounter,             |
00069 |                                        BYTE_     b_PCIInputClock,          |
00070 |                                        BYTE_     b_TimingUnit,             |
00071 |                                        ULONG_   ul_TimingInterval,         |
00072 |                                        PULONG_ pul_RealTimingInterval)     |
00073 +----------------------------------------------------------------------------+
00074 | Task              : Configure the selected tor counter (b_TorCounter)      |
00075 |                     from selected module (b_ModulNbr).                     |
00076 |                     The ul_TimingInterval and ul_TimingUnit determine the  |
00077 |                     timing base for the measurement.                       |
00078 |                     The pul_RealTimingInterval return the real timing      |
00079 |                     value. You must calling this function be for you call  |
00080 |                     any other function witch access of the tor counter.    |
00081 |                                                                            |
00082 +----------------------------------------------------------------------------+
00083 | Input Parameters  :    |
00084 |                     
00085                 CR_AREF BYTE_   b_ModulNbr       : Module number to configure  |
00086 |                                                (0 to 3)                    |
00087 |           data[0] BYTE_   b_TorCounter     : Tor counter selection       |
00088 |                                                (0 or 1).                   |
00089 |           data[1] BYTE_   b_PCIInputClock  : Selection from PCI bus clock|
00090 |                                                - APCI1710_30MHZ :          |
00091 |                                                  The PC have a PCI bus     |
00092 |                                                  clock from 30 MHz         |
00093 |                                                - APCI1710_33MHZ :          |
00094 |                                                  The PC have a PCI bus     |
00095 |                                                  clock from 33 MHz         |
00096 |                                                - APCI1710_40MHZ            |
00097 |                                                  The APCI-1710 have a      |
00098 |                                                  integrated 40Mhz          |
00099 |                                                  quartz.                   |
00100 |                                                - APCI1710_GATE_INPUT       |
00101 |                                                  Used the gate input for   |
00102 |                                                  the base clock. If you    |
00103 |                                                  have selected this option,|
00104 |                                                  than it is not possibl to |
00105 |                                                  used the gate input for   |
00106 |                                                  enabled the acquisition   |
00107 |           data[2] BYTE_   b_TimingUnit    : Base timing unit (0 to 4)    |
00108 |                                                 0 : ns                     |
00109 |                                                 1 : µs                     |
00110 |                                                 2 : ms                     |
00111 |                                                 3 : s                      |
00112 |                                                 4 : mn                     |
00113 |           data[3]          ULONG_ ul_TimingInterval : Base timing value.          |
00114 +----------------------------------------------------------------------------+
00115 | Output Parameters : PULONG_  pul_RealTimingInterval : Real  base timing    |
00116 |                     data[0]                                  value.               |
00117 +----------------------------------------------------------------------------+
00118 | Return Value      :  0: No error                                           |
00119 |                     -1: The handle parameter of the board is wrong         |
00120 |                     -2: Module selection wrong                             |
00121 |                     -3: The module is not a tor counter module             |
00122 |                     -4: Tor counter selection is wrong                     |
00123 |                     -5: The selected PCI input clock is wrong              |
00124 |                     -6: Timing unit selection is wrong                     |
00125 |                     -7: Base timing selection is wrong                     |
00126 |                     -8: You can not used the 40MHz clock selection wich    |
00127 |                         this board                                         |
00128 |                     -9: You can not used the 40MHz clock selection wich    |
00129 |                         this TOR version                                   |
00130 +----------------------------------------------------------------------------+
00131 */
00132 
00133 INT i_APCI1710_InsnConfigInitTorCounter(comedi_device * dev,
00134         comedi_subdevice * s, comedi_insn * insn, lsampl_t * data)
00135 {
00136         INT i_ReturnValue = 0;
00137         ULONG ul_TimerValue = 0;
00138         DWORD dw_Command;
00139         double d_RealTimingInterval = 0;
00140         BYTE b_ModulNbr;
00141         BYTE b_TorCounter;
00142         BYTE b_PCIInputClock;
00143         BYTE b_TimingUnit;
00144         ULONG ul_TimingInterval;
00145         ULONG ul_RealTimingInterval = 0;
00146 
00147         i_ReturnValue = insn->n;
00148         b_ModulNbr = (BYTE) CR_AREF(insn->chanspec);
00149 
00150         b_TorCounter = (BYTE) data[0];
00151         b_PCIInputClock = (BYTE) data[1];
00152         b_TimingUnit = (BYTE) data[2];
00153         ul_TimingInterval = (ULONG) data[3];
00154         printk("INPUT clock %d\n", b_PCIInputClock);
00155 
00156                 /**************************/
00157         /* Test the module number */
00158                 /**************************/
00159 
00160         if (b_ModulNbr < 4) {
00161                 /***********************/
00162                 /* Test if tor counter */
00163                 /***********************/
00164 
00165                 if ((devpriv->s_BoardInfos.
00166                                 dw_MolduleConfiguration[b_ModulNbr] &
00167                                 0xFFFF0000UL) == APCI1710_TOR_COUNTER) {
00168               /**********************************/
00169                         /* Test the tor counter selection */
00170               /**********************************/
00171 
00172                         if (b_TorCounter <= 1) {
00173                  /**************************/
00174                                 /* Test the PCI bus clock */
00175                  /**************************/
00176 
00177                                 if ((b_PCIInputClock == APCI1710_30MHZ) ||
00178                                         (b_PCIInputClock == APCI1710_33MHZ) ||
00179                                         (b_PCIInputClock == APCI1710_40MHZ) ||
00180                                         (b_PCIInputClock ==
00181                                                 APCI1710_GATE_INPUT)) {
00182                     /************************/
00183                                         /* Test the timing unit */
00184                     /************************/
00185 
00186                                         if ((b_TimingUnit <= 4)
00187                                                 || (b_PCIInputClock ==
00188                                                         APCI1710_GATE_INPUT)) {
00189                        /**********************************/
00190                                                 /* Test the base timing selection */
00191                        /**********************************/
00192 
00193                                                 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))) {
00194                                 /**************************/
00195                                                         /* Test the board version */
00196                                 /**************************/
00197 
00198                                                         if (((b_PCIInputClock == APCI1710_40MHZ) && (devpriv->s_BoardInfos.b_BoardVersion > 0)) || (b_PCIInputClock != APCI1710_40MHZ)) {
00199                              /************************/
00200                                                                 /* Test the TOR version */
00201                              /************************/
00202 
00203                                                                 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)) {
00204                                 /*********************************/
00205                                                                         /* Test if not extern clock used */
00206                                 /*********************************/
00207 
00208                                                                         if (b_PCIInputClock != APCI1710_GATE_INPUT) {
00209                                                                                 fpu_begin
00210                                                                                         ();
00211                                    /****************************************/
00212                                                                                 /* Calculate the timer 0 division fator */
00213                                    /****************************************/
00214 
00215                                                                                 switch (b_TimingUnit) {
00216                                       /******/
00217                                                                                         /* ns */
00218                                       /******/
00219 
00220                                                                                 case 0:
00221 
00222                                               /******************/
00223                                                                                         /* Timer 0 factor */
00224                                               /******************/
00225 
00226                                                                                         ul_TimerValue
00227                                                                                                 =
00228                                                                                                 (ULONG)
00229                                                                                                 (ul_TimingInterval
00230                                                                                                 *
00231                                                                                                 (0.00025 * b_PCIInputClock));
00232 
00233                                               /*******************/
00234                                                                                         /* Round the value */
00235                                               /*******************/
00236 
00237                                                                                         if ((double)((double)ul_TimingInterval * (0.00025 * (double)b_PCIInputClock)) >= ((double)((double)ul_TimerValue + 0.5))) {
00238                                                                                                 ul_TimerValue
00239                                                                                                         =
00240                                                                                                         ul_TimerValue
00241                                                                                                         +
00242                                                                                                         1;
00243                                                                                         }
00244 
00245                                               /*****************************/
00246                                                                                         /* Calculate the real timing */
00247                                               /*****************************/
00248 
00249                                                                                         ul_RealTimingInterval
00250                                                                                                 =
00251                                                                                                 (ULONG)
00252                                                                                                 (ul_TimerValue
00253                                                                                                 /
00254                                                                                                 (0.00025 * (double)b_PCIInputClock));
00255                                                                                         d_RealTimingInterval
00256                                                                                                 =
00257                                                                                                 (double)
00258                                                                                                 ul_TimerValue
00259                                                                                                 /
00260                                                                                                 (0.00025
00261                                                                                                 *
00262                                                                                                 (double)
00263                                                                                                 b_PCIInputClock);
00264 
00265                                                                                         if ((double)((double)ul_TimerValue / (0.00025 * (double)b_PCIInputClock)) >= (double)((double)ul_RealTimingInterval + 0.5)) {
00266                                                                                                 ul_RealTimingInterval
00267                                                                                                         =
00268                                                                                                         ul_RealTimingInterval
00269                                                                                                         +
00270                                                                                                         1;
00271                                                                                         }
00272 
00273                                                                                         ul_TimingInterval
00274                                                                                                 =
00275                                                                                                 ul_TimingInterval
00276                                                                                                 -
00277                                                                                                 1;
00278                                                                                         ul_TimerValue
00279                                                                                                 =
00280                                                                                                 ul_TimerValue
00281                                                                                                 -
00282                                                                                                 2;
00283 
00284                                                                                         if (b_PCIInputClock != APCI1710_40MHZ) {
00285                                                                                                 ul_TimerValue
00286                                                                                                         =
00287                                                                                                         (ULONG)
00288                                                                                                         (
00289                                                                                                         (double)
00290                                                                                                         (ul_TimerValue)
00291                                                                                                         *
00292                                                                                                         1.007752288);
00293                                                                                         }
00294 
00295                                                                                         break;
00296 
00297                                       /******/
00298                                                                                         /* æs */
00299                                       /******/
00300 
00301                                                                                 case 1:
00302 
00303                                               /******************/
00304                                                                                         /* Timer 0 factor */
00305                                               /******************/
00306 
00307                                                                                         ul_TimerValue
00308                                                                                                 =
00309                                                                                                 (ULONG)
00310                                                                                                 (ul_TimingInterval
00311                                                                                                 *
00312                                                                                                 (0.25 * b_PCIInputClock));
00313 
00314                                               /*******************/
00315                                                                                         /* Round the value */
00316                                               /*******************/
00317 
00318                                                                                         if ((double)((double)ul_TimingInterval * (0.25 * (double)b_PCIInputClock)) >= ((double)((double)ul_TimerValue + 0.5))) {
00319                                                                                                 ul_TimerValue
00320                                                                                                         =
00321                                                                                                         ul_TimerValue
00322                                                                                                         +
00323                                                                                                         1;
00324                                                                                         }
00325 
00326                                               /*****************************/
00327                                                                                         /* Calculate the real timing */
00328                                               /*****************************/
00329 
00330                                                                                         ul_RealTimingInterval
00331                                                                                                 =
00332                                                                                                 (ULONG)
00333                                                                                                 (ul_TimerValue
00334                                                                                                 /
00335                                                                                                 (0.25 * (double)b_PCIInputClock));
00336                                                                                         d_RealTimingInterval
00337                                                                                                 =
00338                                                                                                 (double)
00339                                                                                                 ul_TimerValue
00340                                                                                                 /
00341                                                                                                 (
00342                                                                                                 (double)
00343                                                                                                 0.25
00344                                                                                                 *
00345                                                                                                 (double)
00346                                                                                                 b_PCIInputClock);
00347 
00348                                                                                         if ((double)((double)ul_TimerValue / (0.25 * (double)b_PCIInputClock)) >= (double)((double)ul_RealTimingInterval + 0.5)) {
00349                                                                                                 ul_RealTimingInterval
00350                                                                                                         =
00351                                                                                                         ul_RealTimingInterval
00352                                                                                                         +
00353                                                                                                         1;
00354                                                                                         }
00355 
00356                                                                                         ul_TimingInterval
00357                                                                                                 =
00358                                                                                                 ul_TimingInterval
00359                                                                                                 -
00360                                                                                                 1;
00361                                                                                         ul_TimerValue
00362                                                                                                 =
00363                                                                                                 ul_TimerValue
00364                                                                                                 -
00365                                                                                                 2;
00366 
00367                                                                                         if (b_PCIInputClock != APCI1710_40MHZ) {
00368                                                                                                 ul_TimerValue
00369                                                                                                         =
00370                                                                                                         (ULONG)
00371                                                                                                         (
00372                                                                                                         (double)
00373                                                                                                         (ul_TimerValue)
00374                                                                                                         *
00375                                                                                                         1.007752288);
00376                                                                                         }
00377 
00378                                                                                         break;
00379 
00380                                       /******/
00381                                                                                         /* ms */
00382                                       /******/
00383 
00384                                                                                 case 2:
00385 
00386                                               /******************/
00387                                                                                         /* Timer 0 factor */
00388                                               /******************/
00389 
00390                                                                                         ul_TimerValue
00391                                                                                                 =
00392                                                                                                 ul_TimingInterval
00393                                                                                                 *
00394                                                                                                 (250.0
00395                                                                                                 *
00396                                                                                                 b_PCIInputClock);
00397 
00398                                               /*******************/
00399                                                                                         /* Round the value */
00400                                               /*******************/
00401 
00402                                                                                         if ((double)((double)ul_TimingInterval * (250.0 * (double)b_PCIInputClock)) >= ((double)((double)ul_TimerValue + 0.5))) {
00403                                                                                                 ul_TimerValue
00404                                                                                                         =
00405                                                                                                         ul_TimerValue
00406                                                                                                         +
00407                                                                                                         1;
00408                                                                                         }
00409 
00410                                               /*****************************/
00411                                                                                         /* Calculate the real timing */
00412                                               /*****************************/
00413 
00414                                                                                         ul_RealTimingInterval
00415                                                                                                 =
00416                                                                                                 (ULONG)
00417                                                                                                 (ul_TimerValue
00418                                                                                                 /
00419                                                                                                 (250.0 * (double)b_PCIInputClock));
00420                                                                                         d_RealTimingInterval
00421                                                                                                 =
00422                                                                                                 (double)
00423                                                                                                 ul_TimerValue
00424                                                                                                 /
00425                                                                                                 (250.0
00426                                                                                                 *
00427                                                                                                 (double)
00428                                                                                                 b_PCIInputClock);
00429 
00430                                                                                         if ((double)((double)ul_TimerValue / (250.0 * (double)b_PCIInputClock)) >= (double)((double)ul_RealTimingInterval + 0.5)) {
00431                                                                                                 ul_RealTimingInterval
00432                                                                                                         =
00433                                                                                                         ul_RealTimingInterval
00434                                                                                                         +
00435                                                                                                         1;
00436                                                                                         }
00437 
00438                                                                                         ul_TimingInterval
00439                                                                                                 =
00440                                                                                                 ul_TimingInterval
00441                                                                                                 -
00442                                                                                                 1;
00443                                                                                         ul_TimerValue
00444                                                                                                 =
00445                                                                                                 ul_TimerValue
00446                                                                                                 -
00447                                                                                                 2;
00448 
00449                                                                                         if (b_PCIInputClock != APCI1710_40MHZ) {
00450                                                                                                 ul_TimerValue
00451                                                                                                         =
00452                                                                                                         (ULONG)
00453                                                                                                         (
00454                                                                                                         (double)
00455                                                                                                         (ul_TimerValue)
00456                                                                                                         *
00457                                                                                                         1.007752288);
00458                                                                                         }
00459 
00460                                                                                         break;
00461 
00462                                       /*****/
00463                                                                                         /* s */
00464                                       /*****/
00465 
00466                                                                                 case 3:
00467 
00468                                               /******************/
00469                                                                                         /* Timer 0 factor */
00470                                               /******************/
00471 
00472                                                                                         ul_TimerValue
00473                                                                                                 =
00474                                                                                                 (ULONG)
00475                                                                                                 (ul_TimingInterval
00476                                                                                                 *
00477                                                                                                 (250000.0
00478                                                                                                         *
00479                                                                                                         b_PCIInputClock));
00480 
00481                                               /*******************/
00482                                                                                         /* Round the value */
00483                                               /*******************/
00484 
00485                                                                                         if ((double)((double)ul_TimingInterval * (250000.0 * (double)b_PCIInputClock)) >= ((double)((double)ul_TimerValue + 0.5))) {
00486                                                                                                 ul_TimerValue
00487                                                                                                         =
00488                                                                                                         ul_TimerValue
00489                                                                                                         +
00490                                                                                                         1;
00491                                                                                         }
00492 
00493                                               /*****************************/
00494                                                                                         /* Calculate the real timing */
00495                                               /*****************************/
00496 
00497                                                                                         ul_RealTimingInterval
00498                                                                                                 =
00499                                                                                                 (ULONG)
00500                                                                                                 (ul_TimerValue
00501                                                                                                 /
00502                                                                                                 (250000.0
00503                                                                                                         *
00504                                                                                                         (double)
00505                                                                                                         b_PCIInputClock));
00506                                                                                         d_RealTimingInterval
00507                                                                                                 =
00508                                                                                                 (double)
00509                                                                                                 ul_TimerValue
00510                                                                                                 /
00511                                                                                                 (250000.0
00512                                                                                                 *
00513                                                                                                 (double)
00514                                                                                                 b_PCIInputClock);
00515 
00516                                                                                         if ((double)((double)ul_TimerValue / (250000.0 * (double)b_PCIInputClock)) >= (double)((double)ul_RealTimingInterval + 0.5)) {
00517                                                                                                 ul_RealTimingInterval
00518                                                                                                         =
00519                                                                                                         ul_RealTimingInterval
00520                                                                                                         +
00521                                                                                                         1;
00522                                                                                         }
00523 
00524                                                                                         ul_TimingInterval
00525                                                                                                 =
00526                                                                                                 ul_TimingInterval
00527                                                                                                 -
00528                                                                                                 1;
00529                                                                                         ul_TimerValue
00530                                                                                                 =
00531                                                                                                 ul_TimerValue
00532                                                                                                 -
00533                                                                                                 2;
00534 
00535                                                                                         if (b_PCIInputClock != APCI1710_40MHZ) {
00536                                                                                                 ul_TimerValue
00537                                                                                                         =
00538                                                                                                         (ULONG)
00539                                                                                                         (
00540                                                                                                         (double)
00541                                                                                                         (ul_TimerValue)
00542                                                                                                         *
00543                                                                                                         1.007752288);
00544                                                                                         }
00545 
00546                                                                                         break;
00547 
00548                                       /******/
00549                                                                                         /* mn */
00550                                       /******/
00551 
00552                                                                                 case 4:
00553 
00554                                               /******************/
00555                                                                                         /* Timer 0 factor */
00556                                               /******************/
00557 
00558                                                                                         ul_TimerValue
00559                                                                                                 =
00560                                                                                                 (ULONG)
00561                                                                                                 (
00562                                                                                                 (ul_TimingInterval
00563                                                                                                         *
00564                                                                                                         60)
00565                                                                                                 *
00566                                                                                                 (250000.0
00567                                                                                                         *
00568                                                                                                         b_PCIInputClock));
00569 
00570                                               /*******************/
00571                                                                                         /* Round the value */
00572                                               /*******************/
00573 
00574                                                                                         if ((double)((double)(ul_TimingInterval * 60.0) * (250000.0 * (double)b_PCIInputClock)) >= ((double)((double)ul_TimerValue + 0.5))) {
00575                                                                                                 ul_TimerValue
00576                                                                                                         =
00577                                                                                                         ul_TimerValue
00578                                                                                                         +
00579                                                                                                         1;
00580                                                                                         }
00581 
00582                                               /*****************************/
00583                                                                                         /* Calculate the real timing */
00584                                               /*****************************/
00585 
00586                                                                                         ul_RealTimingInterval
00587                                                                                                 =
00588                                                                                                 (ULONG)
00589                                                                                                 (ul_TimerValue
00590                                                                                                 /
00591                                                                                                 (250000.0
00592                                                                                                         *
00593                                                                                                         (double)
00594                                                                                                         b_PCIInputClock))
00595                                                                                                 /
00596                                                                                                 60;
00597                                                                                         d_RealTimingInterval
00598                                                                                                 =
00599                                                                                                 (
00600                                                                                                 (double)
00601                                                                                                 ul_TimerValue
00602                                                                                                 /
00603                                                                                                 (250000.0
00604                                                                                                         *
00605                                                                                                         (double)
00606                                                                                                         b_PCIInputClock))
00607                                                                                                 /
00608                                                                                                 60.0;
00609 
00610                                                                                         if ((double)(((double)ul_TimerValue / (250000.0 * (double)b_PCIInputClock)) / 60.0) >= (double)((double)ul_RealTimingInterval + 0.5)) {
00611                                                                                                 ul_RealTimingInterval
00612                                                                                                         =
00613                                                                                                         ul_RealTimingInterval
00614                                                                                                         +
00615                                                                                                         1;
00616                                                                                         }
00617 
00618                                                                                         ul_TimingInterval
00619                                                                                                 =
00620                                                                                                 ul_TimingInterval
00621                                                                                                 -
00622                                                                                                 1;
00623                                                                                         ul_TimerValue
00624                                                                                                 =
00625                                                                                                 ul_TimerValue
00626                                                                                                 -
00627                                                                                                 2;
00628 
00629                                                                                         if (b_PCIInputClock != APCI1710_40MHZ) {
00630                                                                                                 ul_TimerValue
00631                                                                                                         =
00632                                                                                                         (ULONG)
00633                                                                                                         (
00634                                                                                                         (double)
00635                                                                                                         (ul_TimerValue)
00636                                                                                                         *
00637                                                                                                         1.007752288);
00638                                                                                         }
00639 
00640                                                                                         break;
00641                                                                                 }
00642 
00643                                                                                 fpu_end();
00644                                                                         }       // if (b_PCIInputClock != APCI1710_GATE_INPUT)
00645                                                                         else {
00646                                    /*************************************************************/
00647                                                                                 /* 2 Clock used for the overflow and the reload from counter */
00648                                    /*************************************************************/
00649 
00650                                                                                 ul_TimerValue
00651                                                                                         =
00652                                                                                         ul_TimingInterval
00653                                                                                         -
00654                                                                                         2;
00655                                                                         }       // if (b_PCIInputClock != APCI1710_GATE_INPUT)
00656 
00657                                 /****************************/
00658                                                                         /* Save the PCI input clock */
00659                                 /****************************/
00660                                                                         devpriv->
00661                                                                                 s_ModuleInfo
00662                                                                                 [b_ModulNbr].
00663                                                                                 s_TorCounterModuleInfo.
00664                                                                                 b_PCIInputClock
00665                                                                                 =
00666                                                                                 b_PCIInputClock;
00667 
00668                                 /************************/
00669                                                                         /* Save the timing unit */
00670                                 /************************/
00671 
00672                                                                         devpriv->
00673                                                                                 s_ModuleInfo
00674                                                                                 [b_ModulNbr].
00675                                                                                 s_TorCounterModuleInfo.
00676                                                                                 s_TorCounterInfo
00677                                                                                 [b_TorCounter].
00678                                                                                 b_TimingUnit
00679                                                                                 =
00680                                                                                 b_TimingUnit;
00681 
00682                                 /************************/
00683                                                                         /* Save the base timing */
00684                                 /************************/
00685                                                                         devpriv->
00686                                                                                 s_ModuleInfo
00687                                                                                 [b_ModulNbr].
00688                                                                                 s_TorCounterModuleInfo.
00689                                                                                 s_TorCounterInfo
00690                                                                                 [b_TorCounter].
00691                                                                                 d_TimingInterval
00692                                                                                 =
00693                                                                                 d_RealTimingInterval;
00694 
00695                                                                         devpriv->
00696                                                                                 s_ModuleInfo
00697                                                                                 [b_ModulNbr].
00698                                                                                 s_TorCounterModuleInfo.
00699                                                                                 s_TorCounterInfo
00700                                                                                 [b_TorCounter].
00701                                                                                 ul_RealTimingInterval
00702                                                                                 =
00703                                                                                 ul_RealTimingInterval;
00704 
00705                                 /*******************/
00706                                                                         /* Get the command */
00707                                 /*******************/
00708 
00709                                                                         dw_Command
00710                                                                                 =
00711                                                                                 inl
00712                                                                                 (devpriv->
00713                                                                                 s_BoardInfos.
00714                                                                                 ui_Address
00715                                                                                 +
00716                                                                                 4
00717                                                                                 +
00718                                                                                 (16 * b_TorCounter) + (64 * b_ModulNbr));
00719 
00720                                                                         dw_Command
00721                                                                                 =
00722                                                                                 (dw_Command
00723                                                                                 >>
00724                                                                                 4)
00725                                                                                 &
00726                                                                                 0xF;
00727 
00728                                 /******************/
00729                                                                         /* Test if 40 MHz */
00730                                 /******************/
00731 
00732                                                                         if (b_PCIInputClock == APCI1710_40MHZ) {
00733                                    /****************************/
00734                                                                                 /* Set the 40 MHz selection */
00735                                    /****************************/
00736 
00737                                                                                 dw_Command
00738                                                                                         =
00739                                                                                         dw_Command
00740                                                                                         |
00741                                                                                         0x10;
00742                                                                         }
00743 
00744                                 /*****************************/
00745                                                                         /* Test if extern clock used */
00746                                 /*****************************/
00747 
00748                                                                         if (b_PCIInputClock == APCI1710_GATE_INPUT) {
00749                                    /****************************/
00750                                                                                 /* Set the 40 MHz selection */
00751                                    /****************************/
00752 
00753                                                                                 dw_Command
00754                                                                                         =
00755                                                                                         dw_Command
00756                                                                                         |
00757                                                                                         0x20;
00758                                                                         }
00759 
00760                                 /*************************/
00761                                                                         /* Write the new command */
00762                                 /*************************/
00763 
00764                                                                         outl(dw_Command, devpriv->s_BoardInfos.ui_Address + 4 + (16 * b_TorCounter) + (64 * b_ModulNbr));
00765 
00766                                 /*******************/
00767                                                                         /* Disable the tor */
00768                                 /*******************/
00769 
00770                                                                         outl(0, devpriv->s_BoardInfos.ui_Address + 8 + (16 * b_TorCounter) + (64 * b_ModulNbr));
00771                                 /*************************/
00772                                                                         /* Set the timer 1 value */
00773                                 /*************************/
00774 
00775                                                                         outl(ul_TimerValue, devpriv->s_BoardInfos.ui_Address + 0 + (16 * b_TorCounter) + (64 * b_ModulNbr));
00776 
00777                                 /*********************/
00778                                                                         /* Tor counter init. */
00779                                 /*********************/
00780 
00781                                                                         devpriv->
00782                                                                                 s_ModuleInfo
00783                                                                                 [b_ModulNbr].
00784                                                                                 s_TorCounterModuleInfo.
00785                                                                                 s_TorCounterInfo
00786                                                                                 [b_TorCounter].
00787                                                                                 b_TorCounterInit
00788                                                                                 =
00789                                                                                 1;
00790                                                                 } else {
00791                                 /***********************************************/
00792                                                                         /* TOR version error for 40MHz clock selection */
00793                                 /***********************************************/
00794 
00795                                                                         DPRINTK("TOR version error for 40MHz clock selection\n");
00796                                                                         i_ReturnValue
00797                                                                                 =
00798                                                                                 -9;
00799                                                                 }
00800                                                         } else {
00801                              /**************************************************************/
00802                                                                 /* You can not used the 40MHz clock selection wich this board */
00803                              /**************************************************************/
00804 
00805                                                                 DPRINTK("You can not used the 40MHz clock selection wich this board\n");
00806                                                                 i_ReturnValue =
00807                                                                         -8;
00808                                                         }
00809                                                 } else {
00810                           /**********************************/
00811                                                         /* Base timing selection is wrong */
00812                           /**********************************/
00813 
00814                                                         DPRINTK("Base timing selection is wrong\n");
00815                                                         i_ReturnValue = -7;
00816                                                 }
00817                                         }       // if ((b_TimingUnit >= 0) && (b_TimingUnit <= 4))
00818                                         else {
00819                        /**********************************/
00820                                                 /* Timing unit selection is wrong */
00821                        /**********************************/
00822 
00823                                                 DPRINTK("Timing unit selection is wrong\n");
00824                                                 i_ReturnValue = -6;
00825                                         }       // if ((b_TimingUnit >= 0) && (b_TimingUnit <= 4))
00826                                 }       // if ((b_PCIInputClock == APCI1710_30MHZ) || (b_PCIInputClock == APCI1710_33MHZ))
00827                                 else {
00828                     /*****************************************/
00829                                         /* The selected PCI input clock is wrong */
00830                     /*****************************************/
00831 
00832                                         DPRINTK("The selected PCI input clock is wrong\n");
00833                                         i_ReturnValue = -5;
00834                                 }       // if ((b_PCIInputClock == APCI1710_30MHZ) || (b_PCIInputClock == APCI1710_33MHZ))
00835                         }       // if (b_TorCounterMode >= 0 && b_TorCounterMode <= 7)
00836                         else {
00837                  /**********************************/
00838                                 /* Tor Counter selection is wrong */
00839                  /**********************************/
00840 
00841                                 DPRINTK("Tor Counter selection is wrong\n");
00842                                 i_ReturnValue = -4;
00843                         }       // if (b_TorCounterMode >= 0 && b_TorCounterMode <= 7)
00844                 } else {
00845               /******************************************/
00846                         /* The module is not a tor counter module */
00847               /******************************************/
00848 
00849                         DPRINTK("The module is not a tor counter module\n");
00850                         i_ReturnValue = -3;
00851                 }
00852         } else {
00853            /***********************/
00854                 /* Module number error */
00855            /***********************/
00856 
00857                 DPRINTK("Module number error\n");
00858                 i_ReturnValue = -2;
00859         }
00860         data[0] = (UINT) ul_RealTimingInterval;
00861         return (i_ReturnValue);
00862 }
00863 
00864 /*
00865 +----------------------------------------------------------------------------+
00866 | Function Name     : _INT_ i_APCI1710_EnableTorCounter                      |
00867 |                                               (BYTE_ b_BoardHandle,        |
00868 |                                                BYTE_ b_ModulNbr,           |
00869 |                                                BYTE_ b_TorCounter,         |
00870 |                                                BYTE_ b_InputMode,          |
00871 |                                                BYTE_ b_ExternGate,         |
00872 |                                                BYTE_ b_CycleMode,          |
00873 |                                                BYTE_ b_InterruptEnable)    |
00874 +----------------------------------------------------------------------------+
00875 | Task              : Enable the tor counter (b_TorCounter) from selected    |
00876 |                     module (b_ModulNbr). You must calling the              |
00877 |                     "i_APCI1710_InitTorCounter" function be for you call   |
00878 |                     this function.                                         |
00879 |                     If you enable the tor counter interrupt, the           |
00880 |                     tor counter generate a interrupt after the timing cycle|
00881 |                     See function "i_APCI1710_SetBoardIntRoutineX" and the  |
00882 |                     Interrupt mask description chapter from this manual.   |
00883 |                     The b_CycleMode parameter determine if you will        |
00884 |                     measured a single or more cycle.                       |
00885 +----------------------------------------------------------------------------+
00886 | Input Parameters  : BYTE_ b_BoardHandle  : Handle of board APCI-1710       |
00887 |                     BYTE_ b_ModulNbr     : Selected module number (0 to 3) |
00888 |                     BYTE_ b_TorCounter   : Tor counter selection (0 or 1). |
00889 |                     BYTE_ b_InputMode    : Input signal level selection    |
00890 |                                               0 : Tor count each low level |
00891 |                                               1 : Tor count each high level|
00892 |                     BYTE_ b_ExternGate   : Extern gate action selection    |
00893 |                                               0 : Extern gate signal not   |
00894 |                                                   used                     |
00895 |                                               1 : Extern gate signal used. |
00896 |                                                   If you selected the      |
00897 |                                                   single mode, each high   |
00898 |                                                   level signal start the   |
00899 |                                                   counter.                 |
00900 |                                                   If you selected the      |
00901 |                                                   continuous mode, the     |
00902 |                                                   first high level signal  |
00903 |                                                   start the tor counter    |
00904 |                                                                            |
00905 |                                             APCI1710_TOR_QUADRUPLE _MODE : |
00906 |                                             In the quadruple mode, the edge|
00907 |                                             analysis circuit generates a   |
00908 |                                             counting pulse from each edge  |
00909 |                                             of 2 signals which are phase   |
00910 |                                             shifted in relation to each    |
00911 |                                             other.                         |
00912 |                                             The gate input is used for the |
00913 |                                             signal B                       |
00914 |                                                                            |
00915 |                                             APCI1710_TOR_DOUBLE_MODE:      |
00916 |                                             Functions in the same way as   |
00917 |                                             the quadruple mode, except that|
00918 |                                             only two of the four edges are |
00919 |                                             analysed per period.           |
00920 |                                             The gate input is used for the |
00921 |                                             signal B                       |
00922 |                                                                            |
00923 |                                             APCI1710_TOR_SIMPLE_MODE:      |
00924 |                                             Functions in the same way as   |
00925 |                                             the quadruple mode, except that|
00926 |                                             only one of the four edges is  |
00927 |                                             analysed per period.           |
00928 |                                             The gate input is used for the |
00929 |                                             signal B                       |
00930 |                                                                            |
00931 |                     BYTE_ b_CycleMode    : Selected the tor counter        |
00932 |                                            acquisition mode                |
00933 |                     BYTE_ b_InterruptEnable : Enable or disable the        |
00934 |                                               tor counter interrupt.       |
00935 |                                               APCI1710_ENABLE:             |
00936 |                                               Enable the tor counter       |
00937 |                                               interrupt                    |
00938 |                                               APCI1710_DISABLE:            |
00939 |                                               Disable the tor counter      |
00940 |                                               interrupt                    |
00941 +----------------------------------------------------------------------------+
00942 | Output Parameters : -                                                      |
00943 +----------------------------------------------------------------------------+
00944 | Return Value      :  0: No error                                           |
00945 |                     -1: The handle parameter of the board is wrong         |
00946 |                     -2: Module selection wrong                             |
00947 |                     -3: The module is not a tor counter module             |
00948 |                     -4: Tor counter selection is wrong                     |
00949 |                     -5: Tor counter not initialised see function           |
00950 |                         "i_APCI1710_InitTorCounter"                        |
00951 |                     -6: Tor input signal selection is wrong                |
00952 |                     -7: Extern gate signal mode is wrong                   |
00953 |                     -8: Tor counter acquisition mode cycle is wrong        |
00954 |                     -9: Interrupt parameter is wrong                       |
00955 |                     -10:Interrupt function not initialised.                |
00956 |                         See function "i_APCI1710_SetBoardIntRoutineX"      |
00957 +----------------------------------------------------------------------------+
00958 */
00959 /*
00960 +----------------------------------------------------------------------------+
00961 | Function Name     : _INT_ i_APCI1710_DisableTorCounter                     |
00962 |                                               (BYTE_  b_BoardHandle,       |
00963 |                                                BYTE_  b_ModulNbr,          |
00964 |                                                BYTE_  b_TorCounter)        |
00965 +----------------------------------------------------------------------------+
00966 | Task              : Disable the tor counter (b_TorCounter) from selected   |
00967 |                     module (b_ModulNbr). If you disable the tor counter    |
00968 |                     after a start cycle occur and you restart the tor      |
00969 |                     counter witch the " i_APCI1710_EnableTorCounter"       |
00970 |                     function, the status register is cleared               |
00971 +----------------------------------------------------------------------------+
00972 | Input Parameters  : BYTE_ b_BoardHandle  : Handle of board APCI-1710       |
00973 |                     BYTE_ b_ModulNbr     : Selected module number (0 to 3) |
00974 |                     BYTE_ b_TorCounter   : Tor counter selection (0 or 1). |
00975 +----------------------------------------------------------------------------+
00976 | Output Parameters : -                                                      |
00977 +----------------------------------------------------------------------------+
00978 | Return Value      :  0: No error                                           |
00979 |                     -1: The handle parameter of the board is wrong         |
00980 |                     -2: Module selection wrong                             |
00981 |                     -3: The module is not a tor counter module             |
00982 |                     -4: Tor counter selection is wrong                     |
00983 |                     -5: Tor counter not initialised see function           |
00984 |                         "i_APCI1710_InitTorCounter"                        |
00985 |                     -6: Tor counter not enabled see function               |
00986 |                         "i_APCI1710_EnableTorCounter"                      |
00987 +----------------------------------------------------------------------------+
00988 */
00989 
00990 INT i_APCI1710_InsnWriteEnableDisableTorCounter(comedi_device * dev,
00991         comedi_subdevice * s, comedi_insn * insn, lsampl_t * data)
00992 {
00993         INT i_ReturnValue = 0;
00994         DWORD dw_Status;
00995         DWORD dw_DummyRead;
00996         DWORD dw_ConfigReg;
00997         BYTE b_ModulNbr, b_Action;
00998         BYTE b_TorCounter;
00999         BYTE b_InputMode;
01000         BYTE b_ExternGate;
01001         BYTE b_CycleMode;
01002         BYTE b_InterruptEnable;
01003 
01004         b_ModulNbr = (BYTE) CR_AREF(insn->chanspec);
01005         b_Action = (BYTE) data[0];      // enable or disable
01006         b_TorCounter = (BYTE) data[1];
01007         b_InputMode = (BYTE) data[2];
01008         b_ExternGate = (BYTE) data[3];
01009         b_CycleMode = (BYTE) data[4];
01010         b_InterruptEnable = (BYTE) data[5];
01011         i_ReturnValue = insn->n;;
01012         devpriv->tsk_Current = current; // Save the current process task structure
01013         /**************************/
01014         /* Test the module number */
01015         /**************************/
01016 
01017         if (b_ModulNbr < 4) {
01018            /***********************/
01019                 /* Test if tor counter */
01020            /***********************/
01021 
01022                 if ((devpriv->s_BoardInfos.
01023                                 dw_MolduleConfiguration[b_ModulNbr] &
01024                                 0xFFFF0000UL) == APCI1710_TOR_COUNTER) {
01025               /**********************************/
01026                         /* Test the tor counter selection */
01027               /**********************************/
01028 
01029                         if (b_TorCounter <= 1) {
01030                                 switch (b_Action)       // Enable or Disable
01031                                 {
01032                                 case APCI1710_ENABLE:
01033                  /***********************************/
01034                                         /* Test if tor counter initialised */
01035                  /***********************************/
01036 
01037                                         dw_Status =
01038                                                 inl(devpriv->s_BoardInfos.
01039                                                 ui_Address + 8 +
01040                                                 (16 * b_TorCounter) +
01041                                                 (64 * b_ModulNbr));
01042 
01043                                         if (dw_Status & 0x10) {
01044                     /******************************/
01045                                                 /* Test the input signal mode */
01046                     /******************************/
01047 
01048                                                 if (b_InputMode == 0 ||
01049                                                         b_InputMode == 1 ||
01050                                                         b_InputMode ==
01051                                                         APCI1710_TOR_SIMPLE_MODE
01052                                                         || b_InputMode ==
01053                                                         APCI1710_TOR_DOUBLE_MODE
01054                                                         || b_InputMode ==
01055                                                         APCI1710_TOR_QUADRUPLE_MODE)
01056                                                 {
01057                        /************************************/
01058                                                         /* Test the extern gate signal mode */
01059                        /************************************/
01060 
01061                                                         if (b_ExternGate == 0
01062                                                                 || b_ExternGate
01063                                                                 == 1
01064                                                                 || b_InputMode >
01065                                                                 1) {
01066                           /*********************************/
01067                                                                 /* Test the cycle mode parameter */
01068                           /*********************************/
01069 
01070                                                                 if ((b_CycleMode == APCI1710_SINGLE) || (b_CycleMode == APCI1710_CONTINUOUS)) {
01071                              /***************************/
01072                                                                         /* Test the interrupt flag */
01073                              /***************************/
01074 
01075                                                                         if ((b_InterruptEnable == APCI1710_ENABLE) || (b_InterruptEnable == APCI1710_DISABLE)) {
01076 
01077                                    /***************************/
01078                                                                                 /* Save the interrupt mode */
01079                                    /***************************/
01080 
01081                                                                                 devpriv->
01082                                                                                         s_ModuleInfo
01083                                                                                         [b_ModulNbr].
01084                                                                                         s_TorCounterModuleInfo.
01085                                                                                         s_TorCounterInfo
01086                                                                                         [b_TorCounter].
01087                                                                                         b_InterruptEnable
01088                                                                                         =
01089                                                                                         b_InterruptEnable;
01090 
01091                                    /*******************/
01092                                                                                 /* Get the command */
01093                                    /*******************/
01094 
01095                                                                                 dw_ConfigReg
01096                                                                                         =
01097                                                                                         inl
01098                                                                                         (devpriv->
01099                                                                                         s_BoardInfos.
01100                                                                                         ui_Address
01101                                                                                         +
01102                                                                                         4
01103                                                                                         +
01104                                                                                         (16 * b_TorCounter) + (64 * b_ModulNbr));
01105 
01106                                                                                 dw_ConfigReg
01107                                                                                         =
01108                                                                                         (dw_ConfigReg
01109                                                                                         >>
01110                                                                                         4)
01111                                                                                         &
01112                                                                                         0x30;
01113 
01114                                    /********************************/
01115                                                                                 /* Test if not direct mode used */
01116                                    /********************************/
01117 
01118                                                                                 if (b_InputMode > 1) {
01119                                       /*******************************/
01120                                                                                         /* Extern gate can not be used */
01121                                       /*******************************/
01122 
01123                                                                                         b_ExternGate
01124                                                                                                 =
01125                                                                                                 0;
01126 
01127                                       /*******************************************/
01128                                                                                         /* Enable the extern gate for the Signal B */
01129                                       /*******************************************/
01130 
01131                                                                                         dw_ConfigReg
01132                                                                                                 =
01133                                                                                                 dw_ConfigReg
01134                                                                                                 |
01135                                                                                                 0x40;
01136 
01137                                       /***********************/
01138                                                                                         /* Test if simple mode */
01139                                       /***********************/
01140 
01141                                                                                         if (b_InputMode == APCI1710_TOR_SIMPLE_MODE) {
01142                                          /**************************/
01143                                                                                                 /* Enable the sinple mode */
01144                                          /**************************/
01145 
01146                                                                                                 dw_ConfigReg
01147                                                                                                         =
01148                                                                                                         dw_ConfigReg
01149                                                                                                         |
01150                                                                                                         0x780;
01151 
01152                                                                                         }       // if (b_InputMode == APCI1710_TOR_SIMPLE_MODE)
01153 
01154                                       /***********************/
01155                                                                                         /* Test if double mode */
01156                                       /***********************/
01157 
01158                                                                                         if (b_InputMode == APCI1710_TOR_DOUBLE_MODE) {
01159                                          /**************************/
01160                                                                                                 /* Enable the double mode */
01161                                          /**************************/
01162 
01163                                                                                                 dw_ConfigReg
01164                                                                                                         =
01165                                                                                                         dw_ConfigReg
01166                                                                                                         |
01167                                                                                                         0x180;
01168 
01169                                                                                         }       // if (b_InputMode == APCI1710_TOR_DOUBLE_MODE)
01170 
01171                                                                                         b_InputMode
01172                                                                                                 =
01173                                                                                                 0;
01174                                                                                 }       // if (b_InputMode > 1)
01175 
01176                                    /*******************/
01177                                                                                 /* Set the command */
01178                                    /*******************/
01179 
01180                                                                                 dw_ConfigReg
01181                                                                                         =
01182                                                                                         dw_ConfigReg
01183                                                                                         |
01184                                                                                         b_CycleMode
01185                                                                                         |
01186                                                                                         (b_InterruptEnable
01187                                                                                         *
01188                                                                                         2)
01189                                                                                         |
01190                                                                                         (b_InputMode
01191                                                                                         *
01192                                                                                         4)
01193                                                                                         |
01194                                                                                         (b_ExternGate
01195                                                                                         *
01196                                                                                         8);
01197 
01198                                    /*****************************/
01199                                                                                 /* Clear the status register */
01200                                    /*****************************/
01201 
01202                                                                                 dw_DummyRead
01203                                                                                         =
01204                                                                                         inl
01205                                                                                         (devpriv->
01206                                                                                         s_BoardInfos.
01207                                                                                         ui_Address
01208                                                                                         +
01209                                                                                         0
01210                                                                                         +
01211                                                                                         (16 * b_TorCounter) + (64 * b_ModulNbr));
01212 
01213                                    /***************************************/
01214                                                                                 /* Clear the interrupt status register */
01215                                    /***************************************/
01216 
01217                                                                                 dw_DummyRead
01218                                                                                         =
01219                                                                                         inl
01220                                                                                         (devpriv->
01221                                                                                         s_BoardInfos.
01222                                                                                         ui_Address
01223                                                                                         +
01224                                                                                         12
01225                                                                                         +
01226                                                                                         (16 * b_TorCounter) + (64 * b_ModulNbr));
01227 
01228                                    /********************/
01229                                                                                 /* Set the commando */
01230                                    /********************/
01231 
01232                                                                                 outl(dw_ConfigReg, devpriv->s_BoardInfos.ui_Address + 4 + (16 * b_TorCounter) + (64 * b_ModulNbr));
01233 
01234                                    /****************/
01235                                                                                 /* Set the gate */
01236                                    /****************/
01237 
01238                                                                                 outl(1, devpriv->s_BoardInfos.ui_Address + 8 + (16 * b_TorCounter) + (64 * b_ModulNbr));
01239 
01240                                                                         }       // if ((b_InterruptEnable == APCI1710_ENABLE) || (b_InterruptEnable == APCI1710_DISABLE))
01241                                                                         else {
01242                                 /********************************/
01243                                                                                 /* Interrupt parameter is wrong */
01244                                 /********************************/
01245 
01246                                                                                 DPRINTK("Interrupt parameter is wrong\n");
01247                                                                                 i_ReturnValue
01248                                                                                         =
01249                                                                                         -9;
01250                                                                         }       // if ((b_InterruptEnable == APCI1710_ENABLE) || (b_InterruptEnable == APCI1710_DISABLE))
01251                                                                 }       // if ((b_CycleMode == APCI1710_SINGLE) || (b_CycleMode == APCI1710_CONTINUOUS))
01252                                                                 else {
01253                              /***********************************************/
01254                                                                         /* Tor counter acquisition mode cycle is wrong */
01255                              /***********************************************/
01256 
01257                                                                         DPRINTK("Tor counter acquisition mode cycle is wrong\n");
01258                                                                         i_ReturnValue
01259                                                                                 =
01260                                                                                 -8;
01261                                                                 }       // if ((b_CycleMode == APCI1710_SINGLE) || (b_CycleMode == APCI1710_CONTINUOUS))
01262                                                         }       // if (b_ExternGate >= 0 && b_ExternGate <= 1)
01263                                                         else {
01264                           /***********************************/
01265                                                                 /* Extern gate input mode is wrong */
01266                           /***********************************/
01267 
01268                                                                 DPRINTK("Extern gate input mode is wrong\n");
01269                                                                 i_ReturnValue =
01270                                                                         -7;
01271                                                         }       // if (b_ExternGate >= 0 && b_ExternGate <= 1)
01272                                                 }       // if (b_InputMode >= 0 && b_InputMode <= 1)
01273                                                 else {
01274                        /***************************************/
01275                                                         /* Tor input signal selection is wrong */
01276                        /***************************************/
01277 
01278                                                         DPRINTK("Tor input signal selection is wrong\n");
01279                                                         i_ReturnValue = -6;
01280                                                 }
01281                                         } else {
01282                     /*******************************/
01283                                                 /* Tor counter not initialised */
01284                     /*******************************/
01285 
01286                                                 DPRINTK("Tor counter not initialised\n");
01287                                                 i_ReturnValue = -5;
01288                                         }
01289                                         break;
01290 
01291                                 case APCI1710_DISABLE:
01292                          /***********************************/
01293                                         /* Test if tor counter initialised */
01294                  /***********************************/
01295 
01296                                         dw_Status = inl(devpriv->s_BoardInfos.
01297                                                 ui_Address + 8 +
01298                                                 (16 * b_TorCounter) +
01299                                                 (64 * b_ModulNbr));
01300 
01301                  /*******************************/
01302                                         /* Test if counter initialised */
01303                  /*******************************/
01304 
01305                                         if (dw_Status & 0x10) {
01306                     /***************************/
01307                                                 /* Test if counter enabled */
01308                     /***************************/
01309 
01310                                                 if (dw_Status & 0x1) {
01311                        /****************************/
01312                                                         /* Clear the interrupt mode */
01313                        /****************************/
01314                                                         devpriv->
01315                                                                 s_ModuleInfo
01316                                                                 [b_ModulNbr].
01317                                                                 s_TorCounterModuleInfo.
01318                                                                 s_TorCounterInfo
01319                                                                 [b_TorCounter].
01320                                                                 b_InterruptEnable
01321                                                                 =
01322                                                                 APCI1710_DISABLE;
01323 
01324                        /******************/
01325                                                         /* Clear the gate */
01326                        /******************/
01327 
01328                                                         outl(0, devpriv->
01329                                                                 s_BoardInfos.
01330                                                                 ui_Address + 8 +
01331                                                                 (16 * b_TorCounter) + (64 * b_ModulNbr));
01332                                                 }       // if (dw_Status & 0x1)
01333                                                 else {
01334                        /***************************/
01335                                                         /* Tor counter not enabled */
01336                        /***************************/
01337 
01338                                                         DPRINTK("Tor counter not enabled \n");
01339                                                         i_ReturnValue = -6;
01340                                                 }       // if (dw_Status & 0x1)
01341                                         }       // if (dw_Status & 0x10)
01342                                         else {
01343                     /*******************************/
01344                                                 /* Tor counter not initialised */
01345                     /*******************************/
01346 
01347                                                 DPRINTK("Tor counter not initialised\n");
01348                                                 i_ReturnValue = -5;
01349                                         }       // // if (dw_Status & 0x10)
01350 
01351                                 }       // switch
01352                         }       // if (b_TorCounter <= 1)
01353                         else {
01354                  /**********************************/
01355                                 /* Tor counter selection is wrong */
01356                  /**********************************/
01357 
01358                                 DPRINTK("Tor counter selection is wrong\n");
01359                                 i_ReturnValue = -4;
01360                         }       // if (b_TorCounter <= 1)
01361                 } else {
01362               /******************************************/
01363                         /* The module is not a tor counter module */
01364               /******************************************/
01365 
01366                         DPRINTK("The module is not a tor counter module \n");
01367                         i_ReturnValue = -3;
01368                 }
01369         } else {
01370            /***********************/
01371                 /* Module number error */
01372            /***********************/
01373 
01374                 DPRINTK("Module number error \n");
01375                 i_ReturnValue = -2;
01376         }
01377 
01378         return (i_ReturnValue);
01379 }
01380 
01381 /*
01382 +----------------------------------------------------------------------------+
01383 | Function Name     : _INT_ i_APCI1710_GetTorCounterInitialisation           |
01384 |                                               (BYTE_     b_BoardHandle,    |
01385 |                                                BYTE_     b_ModulNbr,       |
01386 |                                                BYTE_     b_TorCounter,     |
01387 |                                                PBYTE_   pb_TimingUnit,     |
01388 |                                                PULONG_ pul_TimingInterval, |
01389 |                                                PBYTE_   pb_InputMode,      |
01390 |                                                PBYTE_   pb_ExternGate,     |
01391 |                                                PBYTE_   pb_CycleMode,      |
01392 |                                                PBYTE_   pb_Enable,         |
01393 |                                                PBYTE_   pb_InterruptEnable)|
01394 +----------------------------------------------------------------------------+
01395 | Task              : Enable the tor counter (b_TorCounter) from selected    |
01396 |                     module (b_ModulNbr). You must calling the              |
01397 |                     "i_APCI1710_InitTorCounter" function be for you call   |
01398 |                     this function.                                         |
01399 |                     If you enable the tor counter interrupt, the           |
01400 |                     tor counter generate a interrupt after the timing cycle|
01401 |                     See function "i_APCI1710_SetBoardIntRoutineX" and the  |
01402 |                     Interrupt mask description chapter from this manual.   |
01403 |                     The b_CycleMode parameter determine if you will        |
01404 |                     measured a single or more cycle.                       |
01405 +----------------------------------------------------------------------------+
01406 | Input Parameters  : BYTE_ b_BoardHandle  : Handle of board APCI-1710       |
01407 |                     BYTE_ b_ModulNbr     : Selected module number (0 to 3) |
01408 |                     BYTE_ b_TorCounter   : Tor counter selection (0 or 1)
01409 
01410         b_ModulNbr                      =       CR_AREF(insn->chanspec);
01411         b_TorCounter            =       CR_CHAN(insn->chanspec);
01412 . |
01413 +----------------------------------------------------------------------------+
01414 | Output Parameters : PBYTE_  pb_TimingUnit    : Base timing unit (0 to 4)   |
01415 |                                                 0 : ns                     |
01416 |                                                 1 : µs                     |
01417 |                                                 2 : ms                     |
01418 |                                                 3 : s                      |
01419 |                                                 4 : mn                     |
01420 |                     PULONG_ pul_TimingInterval : Base timing value.        |
01421 |                     PBYTE_ pb_InputMode        : Input signal level        |
01422 |                                                  selection                 |
01423 |                                               0 : Tor count each low level |
01424 |                                               1 : Tor count each high level|
01425 |                     PBYTE_ pb_ExternGate      : Extern gate action         |
01426 |                                                 selection                  |
01427 |                                                 0 : Extern gate signal not |
01428 |                                                     used                   |
01429 |                                                 1 : Extern gate signal used|
01430 |                     PBYTE_ pb_CycleMode       : Tor counter acquisition    |
01431 |                                                 mode                       |
01432 |                     PBYTE_ pb_Enable          : Indicate if the tor counter|
01433 |                                                 is enabled or no           |
01434 |                                                 0 : Tor counter disabled   |
01435 |                                                 1 : Tor counter enabled    |
01436 |                     PBYTE_ pb_InterruptEnable : Enable or disable the      |
01437 |                                                 tor counter interrupt.     |
01438 |                                                 APCI1710_ENABLE:           |
01439 |                                                 Enable the tor counter     |
01440 |                                                 interrupt                  |
01441 |                                                 APCI1710_DISABLE:          |
01442 |                                                 Disable the tor counter    |
01443 |                                                 interrupt 
01444         pb_TimingUnit           =       (PBYTE) &data[0];
01445         pul_TimingInterval      =  (PULONG) &data[1];
01446         pb_InputMode            =       (PBYTE) &data[2];
01447         pb_ExternGate           =       (PBYTE) &data[3];
01448         pb_CycleMode            =       (PBYTE) &data[4];
01449         pb_Enable                       =       (PBYTE) &data[5];
01450         pb_InterruptEnable      =       (PBYTE) &data[6];
01451                  |
01452 +----------------------------------------------------------------------------+
01453 | Return Value      :  0: No error                                           |
01454 |                     -1: The handle parameter of the board is wrong         |
01455 |                     -2: Module selection wrong                             |
01456 |                     -3: The module is not a tor counter module             |
01457 |                     -4: Tor counter selection is wrong                     |
01458 |                     -5: Tor counter not initialised see function           |
01459 |                         "i_APCI1710_InitTorCounter"                        |
01460 +----------------------------------------------------------------------------+
01461 */
01462 
01463 INT i_APCI1710_InsnReadGetTorCounterInitialisation(comedi_device * dev,
01464         comedi_subdevice * s, comedi_insn * insn, lsampl_t * data)
01465 {
01466         INT i_ReturnValue = 0;
01467         DWORD dw_Status;
01468         BYTE b_ModulNbr;
01469         BYTE b_TorCounter;
01470         PBYTE pb_TimingUnit;
01471         PULONG pul_TimingInterval;
01472         PBYTE pb_InputMode;
01473         PBYTE pb_ExternGate;
01474         PBYTE pb_CycleMode;
01475         PBYTE pb_Enable;
01476         PBYTE pb_InterruptEnable;
01477 
01478         i_ReturnValue = insn->n;
01479         b_ModulNbr = CR_AREF(insn->chanspec);
01480         b_TorCounter = CR_CHAN(insn->chanspec);
01481 
01482         pb_TimingUnit = (PBYTE) & data[0];
01483         pul_TimingInterval = (PULONG) & data[1];
01484         pb_InputMode = (PBYTE) & data[2];
01485         pb_ExternGate = (PBYTE) & data[3];
01486         pb_CycleMode = (PBYTE) & data[4];
01487         pb_Enable = (PBYTE) & data[5];
01488         pb_InterruptEnable = (PBYTE) & data[6];
01489 
01490         /**************************/
01491         /* Test the module number */
01492         /**************************/
01493 
01494         if (b_ModulNbr < 4) {
01495            /***********************/
01496                 /* Test if tor counter */
01497            /***********************/
01498 
01499                 if ((devpriv->s_BoardInfos.
01500                                 dw_MolduleConfiguration[b_ModulNbr] &
01501                                 0xFFFF0000UL) == APCI1710_TOR_COUNTER) {
01502               /**********************************/
01503                         /* Test the tor counter selection */
01504               /**********************************/
01505 
01506                         if (b_TorCounter <= 1) {
01507 
01508                  /***********************************/
01509                                 /* Test if tor counter initialised */
01510                  /***********************************/
01511 
01512                                 dw_Status = inl(devpriv->s_BoardInfos.
01513                                         ui_Address + 8 + (16 * b_TorCounter) +
01514                                         (64 * b_ModulNbr));
01515 
01516                                 if (dw_Status & 0x10) {
01517                                         *pb_Enable = dw_Status & 1;
01518 
01519                     /********************/
01520                                         /* Get the commando */
01521                     /********************/
01522 
01523                                         dw_Status = inl(devpriv->s_BoardInfos.
01524                                                 ui_Address + 4 +
01525                                                 (16 * b_TorCounter) +
01526                                                 (64 * b_ModulNbr));
01527 
01528                                         *pb_CycleMode =
01529                                                 (BYTE) ((dw_Status >> 4) & 1);
01530                                         *pb_InterruptEnable =
01531                                                 (BYTE) ((dw_Status >> 5) & 1);
01532 
01533                     /******************************************************/
01534                                         /* Test if extern gate used for clock or for signal B */
01535                     /******************************************************/
01536 
01537                                         if (dw_Status & 0x600) {
01538                        /*****************************************/
01539                                                 /* Test if extern gate used for signal B */
01540                        /*****************************************/
01541 
01542                                                 if (dw_Status & 0x400) {
01543                           /***********************/
01544                                                         /* Test if simple mode */
01545                           /***********************/
01546 
01547                                                         if ((dw_Status & 0x7800)
01548                                                                 == 0x7800) {
01549                                                                 *pb_InputMode =
01550                                                                         APCI1710_TOR_SIMPLE_MODE;
01551                                                         }
01552 
01553                           /***********************/
01554                                                         /* Test if double mode */
01555                           /***********************/
01556 
01557                                                         if ((dw_Status & 0x7800)
01558                                                                 == 0x1800) {
01559                                                                 *pb_InputMode =
01560                                                                         APCI1710_TOR_DOUBLE_MODE;
01561                                                         }
01562 
01563                           /**************************/
01564                                                         /* Test if quadruple mode */
01565                           /**************************/
01566 
01567                                                         if ((dw_Status & 0x7800)
01568                                                                 == 0x0000) {
01569                                                                 *pb_InputMode =
01570                                                                         APCI1710_TOR_QUADRUPLE_MODE;
01571                                                         }
01572                                                 }       // if (dw_Status & 0x400)
01573                                                 else {
01574                                                         *pb_InputMode = 1;
01575                                                 }       // // if (dw_Status & 0x400)
01576 
01577                        /************************/
01578                                                 /* Extern gate not used */
01579                        /************************/
01580 
01581                                                 *pb_ExternGate = 0;
01582                                         }       // if (dw_Status & 0x600)
01583                                         else {
01584                                                 *pb_InputMode =
01585                                                         (BYTE) ((dw_Status >> 6)
01586                                                         & 1);
01587                                                 *pb_ExternGate =
01588                                                         (BYTE) ((dw_Status >> 7)
01589                                                         & 1);
01590                                         }       // if (dw_Status & 0x600)
01591 
01592                                         *pb_TimingUnit =
01593                                                 devpriv->
01594                                                 s_ModuleInfo[b_ModulNbr].
01595                                                 s_TorCounterModuleInfo.
01596                                                 s_TorCounterInfo[b_TorCounter].
01597                                                 b_TimingUnit;
01598 
01599                                         *pul_TimingInterval =
01600                                                 devpriv->
01601                                                 s_ModuleInfo[b_ModulNbr].
01602                                                 s_TorCounterModuleInfo.
01603                                                 s_TorCounterInfo[b_TorCounter].
01604                                                 ul_RealTimingInterval;
01605                                 } else {
01606                     /*******************************/
01607                                         /* Tor counter not initialised */
01608                     /*******************************/
01609 
01610                                         DPRINTK("Tor counter not initialised\n");
01611                                         i_ReturnValue = -5;
01612                                 }
01613 
01614                         }       // if (b_TorCounter <= 1)
01615                         else {
01616                  /**********************************/
01617                                 /* Tor counter selection is wrong */
01618                  /**********************************/
01619 
01620                                 DPRINTK("Tor counter selection is wrong \n");
01621                                 i_ReturnValue = -4;
01622                         }       // if (b_TorCounter <= 1)
01623                 } else {
01624               /******************************************/
01625                         /* The module is not a tor counter module */
01626               /******************************************/
01627 
01628                         DPRINTK("The module is not a tor counter module\n");
01629                         i_ReturnValue = -3;
01630                 }
01631         } else {
01632            /***********************/
01633                 /* Module number error */
01634            /***********************/
01635 
01636                 DPRINTK("Module number error\n");
01637                 i_ReturnValue = -2;
01638         }
01639 
01640         return (i_ReturnValue);
01641 }
01642 
01643 /*
01644 +----------------------------------------------------------------------------+
01645 | Function Name     : _INT_ i_APCI1710_ReadTorCounterValue                   |
01646 |                               (BYTE_     b_BoardHandle,                    |
01647 |                                BYTE_     b_ModulNbr,                       |
01648 |                                BYTE_     b_TorCounter,                     |
01649 |                                UINT_    ui_TimeOut,                        |
01650 |                                PBYTE_   pb_TorCounterStatus,               |
01651 |                                PULONG_ pul_TorCounterValue)                |
01652 +----------------------------------------------------------------------------+
01653 | Task          case APCI1710_TOR_GETPROGRESSSTATUS: Return the tor counter 
01654 (b_TorCounter) status (pb_TorCounterStatus) from selected tor counter        |
01655 |                     module (b_ModulNbr). 
01656                 
01657                                  case APCI1710_TOR_GETCOUNTERVALUE :
01658   Return the tor counter (b_TorCounter) status           |
01659 |                     (pb_TorCounterStatus) and the timing value             |
01660 |                     (pul_TorCounterValue) after a conting cycle stop       |
01661 |                     from selected tor counter module (b_ModulNbr).         |
01662 +----------------------------------------------------------------------------+
01663 | Input Parameters  : BYTE_ b_BoardHandle  : Handle of board APCI-1710       |
01664 |                     BYTE_ b_ModulNbr     : Selected module number (0 to 3) |
01665 |                     BYTE_ b_TorCounter   : Tor counter selection (0 or 1).
01666         b_ModulNbr    = CR_AREF(insn->chanspec);
01667         b_ReadType    = (BYTE) data[0]; 
01668         b_TorCounter  = (BYTE) data[1];
01669         ui_TimeOut        = (UINT) data[2]; |
01670 +----------------------------------------------------------------------------+
01671 | Output Parameters : PBYTE_  pb_TorCounterStatus : Return the tor counter   |
01672 |                                                    status.                 |
01673 |                                               0 : Conting cycle not started|
01674 |                                                   Software gate not set.   |
01675 |                                               1 : Conting cycle started.   |
01676 |                                                   Software gate set.       |
01677 |                                               2 : Conting cycle stopped.   |
01678 |                                                   The conting cycle is     |
01679 |                                                   terminate.               |
01680 |                                               3 : A overflow occur. You    |
01681 |                                                   must change the base     |
01682 |                                                   timing witch the         |
01683 |                                                   function                 |
01684 |                                                 "i_APCI1710_InitTorCounter"|
01685 |                                               4 : Timeeout occur           |
01686 |                     PULONG  pul_TorCounterValue  : Tor counter value.  
01687         pb_TorCounterStatus=(PBYTE) &data[0];
01688         pul_TorCounterValue=(PULONG) &data[1];    |
01689 +----------------------------------------------------------------------------+
01690 | Return Value      :  0: No error                                           |
01691 |                     -1: The handle parameter of the board is wrong         |
01692 |                     -2: Module selection wrong                             |
01693 |                     -3: The module is not a tor counter module             |
01694 |                     -4: Tor counter selection is wrong                     |
01695 |                     -5: Tor counter not initialised see function           |
01696 |                         "i_APCI1710_InitTorCounter"                        |
01697 |                     -6: Tor counter not enabled see function               |
01698 |                         "i_APCI1710_EnableTorCounter"                      |
01699 |                     -7: Timeout parameter is wrong (0 to 65535)            |
01700 +----------------------------------------------------------------------------+
01701 */
01702 
01703 INT i_APCI1710_InsnBitsGetTorCounterProgressStatusAndValue(comedi_device * dev,
01704         comedi_subdevice * s, comedi_insn * insn, lsampl_t * data)
01705 {
01706         INT i_ReturnValue = 0;
01707         DWORD dw_Status;
01708         DWORD dw_TimeOut = 0;
01709 
01710         BYTE b_ModulNbr;
01711         BYTE b_TorCounter;
01712         BYTE b_ReadType;
01713         UINT ui_TimeOut;
01714         PBYTE pb_TorCounterStatus;
01715         PULONG pul_TorCounterValue;
01716 
01717         i_ReturnValue = insn->n;
01718         b_ModulNbr = CR_AREF(insn->chanspec);
01719         b_ReadType = (BYTE) data[0];
01720         b_TorCounter = (BYTE) data[1];
01721         ui_TimeOut = (UINT) data[2];
01722         pb_TorCounterStatus = (PBYTE) & data[0];
01723         pul_TorCounterValue = (PULONG) & data[1];
01724 
01725         /**************************/
01726         /* Test the module number */
01727         /**************************/
01728 
01729         if (b_ReadType == APCI1710_TOR_READINTERRUPT) {
01730 
01731                 data[0] = devpriv->s_InterruptParameters.
01732                         s_FIFOInterruptParameters[devpriv->
01733                         s_InterruptParameters.ui_Read].b_OldModuleMask;
01734                 data[1] = devpriv->s_InterruptParameters.
01735                         s_FIFOInterruptParameters[devpriv->
01736                         s_InterruptParameters.ui_Read].ul_OldInterruptMask;
01737                 data[2] = devpriv->s_InterruptParameters.
01738                         s_FIFOInterruptParameters[devpriv->
01739                         s_InterruptParameters.ui_Read].ul_OldCounterLatchValue;
01740 
01741                            /**************************/
01742                 /* Increment the read FIFO */
01743                            /***************************/
01744 
01745                 devpriv->
01746                         s_InterruptParameters.
01747                         ui_Read = (devpriv->
01748                         s_InterruptParameters.
01749                         ui_Read + 1) % APCI1710_SAVE_INTERRUPT;
01750 
01751                 return insn->n;
01752         }
01753 
01754         if (b_ModulNbr < 4) {
01755            /***********************/
01756                 /* Test if tor counter */
01757            /***********************/
01758 
01759                 if ((devpriv->s_BoardInfos.
01760                                 dw_MolduleConfiguration[b_ModulNbr] &
01761                                 0xFFFF0000UL) == APCI1710_TOR_COUNTER) {
01762               /**********************************/
01763                         /* Test the tor counter selection */
01764               /**********************************/
01765 
01766                         if (b_TorCounter <= 1) {
01767                  /***********************************/
01768                                 /* Test if tor counter initialised */
01769                  /***********************************/
01770 
01771                                 dw_Status = inl(devpriv->s_BoardInfos.
01772                                         ui_Address + 8 + (16 * b_TorCounter) +
01773                                         (64 * b_ModulNbr));
01774 
01775                  /*******************************/
01776                                 /* Test if counter initialised */
01777                  /*******************************/
01778 
01779                                 if (dw_Status & 0x10) {
01780                     /***************************/
01781                                         /* Test if counter enabled */
01782                     /***************************/
01783 
01784                                         if (dw_Status & 0x1) {
01785 
01786                                                 switch (b_ReadType) {
01787 
01788                                                 case APCI1710_TOR_GETPROGRESSSTATUS:
01789                        /*******************/
01790                                                         /* Read the status */
01791                        /*******************/
01792 
01793                                                         dw_Status =
01794                                                                 inl(devpriv->
01795                                                                 s_BoardInfos.
01796                                                                 ui_Address + 4 +
01797                                                                 (16 * b_TorCounter) + (64 * b_ModulNbr));
01798 
01799                                                         dw_Status =
01800                                                                 dw_Status & 0xF;
01801 
01802                        /*****************/
01803                                                         /* Test if start */
01804                        /*****************/
01805 
01806                                                         if (dw_Status & 1) {
01807                                                                 if (dw_Status &
01808                                                                         2) {
01809                                                                         if (dw_Status & 4) {
01810                                 /************************/
01811                                                                                 /* Tor counter owerflow */
01812                                 /************************/
01813 
01814                                                                                 *pb_TorCounterStatus
01815                                                                                         =
01816                                                                                         3;
01817                                                                         } else {
01818                                 /***********************/
01819                                                                                 /* Tor counter started */
01820                                 /***********************/
01821 
01822                                                                                 *pb_TorCounterStatus
01823                                                                                         =
01824                                                                                         2;
01825                                                                         }
01826                                                                 } else {
01827                              /***********************/
01828                                                                         /* Tor counter started */
01829                              /***********************/
01830 
01831                                                                         *pb_TorCounterStatus
01832                                                                                 =
01833                                                                                 1;
01834                                                                 }
01835                                                         } else {
01836                           /***************************/
01837                                                                 /* Tor counter not started */
01838                           /***************************/
01839 
01840                                                                 *pb_TorCounterStatus
01841                                                                         = 0;
01842                                                         }
01843                                                         break;
01844 
01845                                                 case APCI1710_TOR_GETCOUNTERVALUE:
01846 
01847                        /*****************************/
01848                                                         /* Test the timout parameter */
01849                        /*****************************/
01850 
01851                                                         if ((ui_TimeOut >= 0)
01852                                                                 && (ui_TimeOut
01853                                                                         <=
01854                                                                         65535UL))
01855                                                         {
01856                                                                 for (;;) {
01857                              /*******************/
01858                                                                         /* Read the status */
01859                              /*******************/
01860 
01861                                                                         dw_Status
01862                                                                                 =
01863                                                                                 inl
01864                                                                                 (devpriv->
01865                                                                                 s_BoardInfos.
01866                                                                                 ui_Address
01867                                                                                 +
01868                                                                                 4
01869                                                                                 +
01870                                                                                 (16 * b_TorCounter) + (64 * b_ModulNbr));
01871                              /********************/
01872                                                                         /* Test if overflow */
01873                              /********************/
01874 
01875                                                                         if ((dw_Status & 4) == 4) {
01876                                 /******************/
01877                                                                                 /* Overflow occur */
01878                                 /******************/
01879 
01880                                                                                 *pb_TorCounterStatus
01881                                                                                         =
01882                                                                                         3;
01883 
01884                                 /******************/
01885                                                                                 /* Read the value */
01886                                 /******************/
01887 
01888                                                                                 *pul_TorCounterValue
01889                                                                                         =
01890                                                                                         inl
01891                                                                                         (devpriv->
01892                                                                                         s_BoardInfos.
01893                                                                                         ui_Address
01894                                                                                         +
01895                                                                                         0
01896                                                                                         +
01897                                                                                         (16 * b_TorCounter) + (64 * b_ModulNbr));
01898                                                                                 break;
01899                                                                         }       // if ((dw_Status & 4) == 4)
01900                                                                         else {
01901                                 /*******************************/
01902                                                                                 /* Test if measurement stopped */
01903                                 /*******************************/
01904 
01905                                                                                 if ((dw_Status & 2) == 2) {
01906                                    /***********************/
01907                                                                                         /* A stop signal occur */
01908                                    /***********************/
01909 
01910                                                                                         *pb_TorCounterStatus
01911                                                                                                 =
01912                                                                                                 2;
01913 
01914                                    /******************/
01915                                                                                         /* Read the value */
01916                                    /******************/
01917 
01918                                                                                         *pul_TorCounterValue
01919                                                                                                 =
01920                                                                                                 inl
01921                                                                                                 (devpriv->
01922                                                                                                 s_BoardInfos.
01923                                                                                                 ui_Address
01924                                                                                                 +
01925                                                                                                 0
01926                                                                                                 +
01927                                                                                                 (16 * b_TorCounter) + (64 * b_ModulNbr));
01928 
01929                                                                                         break;
01930                                                                                 }       // if ((dw_Status & 2) == 2)
01931                                                                                 else {
01932                                    /*******************************/
01933                                                                                         /* Test if measurement started */
01934                                    /*******************************/
01935 
01936                                                                                         if ((dw_Status & 1) == 1) {
01937                                       /************************/
01938                                                                                                 /* A start signal occur */
01939                                       /************************/
01940 
01941                                                                                                 *pb_TorCounterStatus
01942                                                                                                         =
01943                                                                                                         1;
01944                                                                                         }       // if ((dw_Status & 1) == 1)
01945                                                                                         else {
01946                                       /***************************/
01947                                                                                                 /* Measurement not started */
01948                                       /***************************/
01949 
01950                                                                                                 *pb_TorCounterStatus
01951                                                                                                         =
01952                                                                                                         0;
01953                                                                                         }       // if ((dw_Status & 1) == 1)
01954                                                                                 }       // if ((dw_Status & 2) == 2)
01955                                                                         }       // if ((dw_Status & 8) == 8)
01956 
01957                                                                         if (dw_TimeOut == ui_TimeOut) {
01958                                 /*****************/
01959                                                                                 /* Timeout occur */
01960                                 /*****************/
01961 
01962                                                                                 break;
01963                                                                         } else {
01964                                 /*************************/
01965                                                                                 /* Increment the timeout */
01966                                 /*************************/
01967 
01968                                                                                 dw_TimeOut
01969                                                                                         =
01970                                                                                         dw_TimeOut
01971                                                                                         +
01972                                                                                         1;
01973 
01974                                                                                 mdelay(1000);
01975                                                                         }
01976                                                                 }       // for (;;)
01977 
01978                           /*************************/
01979                                                                 /* Test if timeout occur */
01980                           /*************************/
01981 
01982                                                                 if ((*pb_TorCounterStatus != 3) && (dw_TimeOut == ui_TimeOut) && (ui_TimeOut != 0)) {
01983                              /*****************/
01984                                                                         /* Timeout occur */
01985                              /*****************/
01986 
01987                                                                         *pb_TorCounterStatus
01988                                                                                 =
01989                                                                                 4;
01990                                                                 }
01991                                                         } else {
01992                           /******************************/
01993                                                                 /* Timeout parameter is wrong */
01994                           /******************************/
01995 
01996                                                                 DPRINTK("Timeout parameter is wrong\n");
01997                                                                 i_ReturnValue =
01998                                                                         -7;
01999                                                         }
02000                                                         break;
02001 
02002                                                 default:
02003                                                         printk("Inputs wrong\n");
02004                                                 }       // switch end
02005                                         }       // if (dw_Status & 0x1)
02006                                         else {
02007                        /***************************/
02008                                                 /* Tor counter not enabled */
02009                        /***************************/
02010 
02011                                                 DPRINTK("Tor counter not enabled\n");
02012                                                 i_ReturnValue = -6;
02013                                         }       // if (dw_Status & 0x1)
02014                                 } else {
02015                     /*******************************/
02016                                         /* Tor counter not initialised */
02017                     /*******************************/
02018 
02019                                         DPRINTK("Tor counter not initialised\n");
02020                                         i_ReturnValue = -5;
02021                                 }
02022                         }       // if (b_TorCounter <= 1)
02023                         else {
02024                  /**********************************/
02025                                 /* Tor counter selection is wrong */
02026                  /**********************************/
02027 
02028                                 DPRINTK("Tor counter selection is wrong\n");
02029                                 i_ReturnValue = -4;
02030                         }       // if (b_TorCounter <= 1)
02031                 } else {
02032               /******************************************/
02033                         /* The module is not a tor counter module */
02034               /******************************************/
02035 
02036                         DPRINTK("The module is not a tor counter module\n");
02037                         i_ReturnValue = -3;
02038                 }
02039         } else {
02040            /***********************/
02041                 /* Module number error */
02042            /***********************/
02043 
02044                 DPRINTK("Module number error\n");
02045                 i_ReturnValue = -2;
02046         }
02047 
02048         return (i_ReturnValue);
02049 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines