staging: comedi: drivers: use comedi_fc.h cmdtest helpers
authorH Hartley Sweeten <hartleys@visionengravers.com>
Wed, 26 Sep 2012 21:11:10 +0000 (14:11 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 26 Sep 2012 21:24:05 +0000 (14:24 -0700)
Use the cfc_check_trigger_src() helper for Step 1 in all the
driver cmdtest functions.

Use the cfc_check_trigger_is_unique() helper for Step 2 in all
the driver cmdtest functions. Note that single source triggers
do not need to be checked, they are already unique if they pass
Step 1.

For aesthetic reasons, change the comments in the cmdtest
functions for steps 1 and 2 so that they are all the same.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
46 files changed:
drivers/staging/comedi/drivers/8255.c
drivers/staging/comedi/drivers/addi-data/hwdrv_apci3120.c
drivers/staging/comedi/drivers/addi-data/hwdrv_apci3200.c
drivers/staging/comedi/drivers/adl_pci9111.c
drivers/staging/comedi/drivers/adl_pci9118.c
drivers/staging/comedi/drivers/adv_pci1710.c
drivers/staging/comedi/drivers/amplc_dio200.c
drivers/staging/comedi/drivers/amplc_pc236.c
drivers/staging/comedi/drivers/amplc_pci224.c
drivers/staging/comedi/drivers/amplc_pci230.c
drivers/staging/comedi/drivers/cb_das16_cs.c
drivers/staging/comedi/drivers/cb_pcidas.c
drivers/staging/comedi/drivers/cb_pcidas64.c
drivers/staging/comedi/drivers/cb_pcidda.c
drivers/staging/comedi/drivers/comedi_parport.c
drivers/staging/comedi/drivers/comedi_test.c
drivers/staging/comedi/drivers/das16.c
drivers/staging/comedi/drivers/das16m1.c
drivers/staging/comedi/drivers/das1800.c
drivers/staging/comedi/drivers/das800.c
drivers/staging/comedi/drivers/dmm32at.c
drivers/staging/comedi/drivers/dt2814.c
drivers/staging/comedi/drivers/dt282x.c
drivers/staging/comedi/drivers/dt3000.c
drivers/staging/comedi/drivers/gsc_hpdi.c
drivers/staging/comedi/drivers/me4000.c
drivers/staging/comedi/drivers/ni_6527.c
drivers/staging/comedi/drivers/ni_65xx.c
drivers/staging/comedi/drivers/ni_at_a2150.c
drivers/staging/comedi/drivers/ni_atmio16d.c
drivers/staging/comedi/drivers/ni_labpc.c
drivers/staging/comedi/drivers/ni_mio_common.c
drivers/staging/comedi/drivers/ni_pcidio.c
drivers/staging/comedi/drivers/ni_tiocmd.c
drivers/staging/comedi/drivers/pcl711.c
drivers/staging/comedi/drivers/pcl812.c
drivers/staging/comedi/drivers/pcl816.c
drivers/staging/comedi/drivers/pcl818.c
drivers/staging/comedi/drivers/pcm_common.c
drivers/staging/comedi/drivers/quatech_daqp_cs.c
drivers/staging/comedi/drivers/rtd520.c
drivers/staging/comedi/drivers/s626.c
drivers/staging/comedi/drivers/skel.c
drivers/staging/comedi/drivers/usbdux.c
drivers/staging/comedi/drivers/usbduxfast.c
drivers/staging/comedi/drivers/usbduxsigma.c

index e2506dd253055d94d73ef37e2576b616e1977d97..a256622e2dd76d8800bf0e1c12f27fbfe7d11d05 100644 (file)
@@ -82,6 +82,8 @@ I/O port base address can be found in the output of 'lspci -v'.
 
 #include <linux/ioport.h>
 #include <linux/slab.h>
+
+#include "comedi_fc.h"
 #include "8255.h"
 
 #define _8255_SIZE     4
@@ -229,39 +231,20 @@ static int subdev_8255_cmdtest(struct comedi_device *dev,
                               struct comedi_cmd *cmd)
 {
        int err = 0;
-       unsigned int tmp;
-
-       /* step 1 */
-
-       tmp = cmd->start_src;
-       cmd->start_src &= TRIG_NOW;
-       if (!cmd->start_src || tmp != cmd->start_src)
-               err++;
-
-       tmp = cmd->scan_begin_src;
-       cmd->scan_begin_src &= TRIG_EXT;
-       if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src)
-               err++;
 
-       tmp = cmd->convert_src;
-       cmd->convert_src &= TRIG_FOLLOW;
-       if (!cmd->convert_src || tmp != cmd->convert_src)
-               err++;
+       /* Step 1 : check if triggers are trivially valid */
 
-       tmp = cmd->scan_end_src;
-       cmd->scan_end_src &= TRIG_COUNT;
-       if (!cmd->scan_end_src || tmp != cmd->scan_end_src)
-               err++;
-
-       tmp = cmd->stop_src;
-       cmd->stop_src &= TRIG_NONE;
-       if (!cmd->stop_src || tmp != cmd->stop_src)
-               err++;
+       err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW);
+       err |= cfc_check_trigger_src(&cmd->scan_begin_src, TRIG_EXT);
+       err |= cfc_check_trigger_src(&cmd->convert_src, TRIG_FOLLOW);
+       err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
+       err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_NONE);
 
        if (err)
                return 1;
 
-       /* step 2 */
+       /* Step 2a : make sure trigger sources are unique */
+       /* Step 2b : and mutually compatible */
 
        if (err)
                return 2;
index d61fce081c1489c109f5dd44985ee4d31acb5071..f406dfb2a677d80d2ba24554e1e5e8b7d8623680 100644 (file)
@@ -479,57 +479,26 @@ int i_APCI3120_CommandTestAnalogInput(struct comedi_device *dev, struct comedi_s
        struct comedi_cmd *cmd)
 {
        int err = 0;
-       int tmp;                /*  divisor1,divisor2; */
 
-       /*  step 1: make sure trigger sources are trivially valid */
+       /* Step 1 : check if triggers are trivially valid */
 
-       tmp = cmd->start_src;
-       cmd->start_src &= TRIG_NOW | TRIG_EXT;
-       if (!cmd->start_src || tmp != cmd->start_src)
-               err++;
-
-       tmp = cmd->scan_begin_src;
-       cmd->scan_begin_src &= TRIG_TIMER | TRIG_FOLLOW;
-       if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src)
-               err++;
-
-       tmp = cmd->convert_src;
-       cmd->convert_src &= TRIG_TIMER;
-       if (!cmd->convert_src || tmp != cmd->convert_src)
-               err++;
-
-       tmp = cmd->scan_end_src;
-       cmd->scan_end_src &= TRIG_COUNT;
-       if (!cmd->scan_end_src || tmp != cmd->scan_end_src)
-               err++;
-
-       tmp = cmd->stop_src;
-       cmd->stop_src &= TRIG_COUNT | TRIG_NONE;
-       if (!cmd->stop_src || tmp != cmd->stop_src)
-               err++;
+       err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW | TRIG_EXT);
+       err |= cfc_check_trigger_src(&cmd->scan_begin_src,
+                                       TRIG_TIMER | TRIG_FOLLOW);
+       err |= cfc_check_trigger_src(&cmd->convert_src, TRIG_TIMER);
+       err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
+       err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE);
 
        if (err)
                return 1;
 
-       /* step 2: make sure trigger sources are unique and mutually compatible */
+       /* Step 2a : make sure trigger sources are unique */
 
-       if (cmd->start_src != TRIG_NOW && cmd->start_src != TRIG_EXT)
-               err++;
-
-       if (cmd->scan_begin_src != TRIG_TIMER &&
-               cmd->scan_begin_src != TRIG_FOLLOW)
-               err++;
-
-       if (cmd->convert_src != TRIG_TIMER)
-               err++;
+       err |= cfc_check_trigger_is_unique(cmd->start_src);
+       err |= cfc_check_trigger_is_unique(cmd->scan_begin_src);
+       err |= cfc_check_trigger_is_unique(cmd->stop_src);
 
-       if (cmd->scan_end_src != TRIG_COUNT) {
-               cmd->scan_end_src = TRIG_COUNT;
-               err++;
-       }
-
-       if (cmd->stop_src != TRIG_NONE && cmd->stop_src != TRIG_COUNT)
-               err++;
+       /* Step 2b : and mutually compatible */
 
        if (err)
                return 2;
index f6f50923fa146d0a568cd8419e255d44703e9840..38ab49917d7e39a85903319c28b1ed679125b931 100644 (file)
@@ -2560,7 +2560,6 @@ int i_APCI3200_CommandTestAnalogInput(struct comedi_device *dev, struct comedi_s
 {
 
        int err = 0;
-       int tmp;                /*  divisor1,divisor2; */
        unsigned int ui_ConvertTime = 0;
        unsigned int ui_ConvertTimeBase = 0;
        unsigned int ui_DelayTime = 0;
@@ -2571,41 +2570,32 @@ int i_APCI3200_CommandTestAnalogInput(struct comedi_device *dev, struct comedi_s
        int i_Cpt = 0;
        double d_ConversionTimeForAllChannels = 0.0;
        double d_SCANTimeNewUnit = 0.0;
-       /*  step 1: make sure trigger sources are trivially valid */
-
-       tmp = cmd->start_src;
-       cmd->start_src &= TRIG_NOW | TRIG_EXT;
-       if (!cmd->start_src || tmp != cmd->start_src)
-               err++;
-       tmp = cmd->scan_begin_src;
-       cmd->scan_begin_src &= TRIG_TIMER | TRIG_FOLLOW;
-       if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src)
-               err++;
-       tmp = cmd->convert_src;
-       cmd->convert_src &= TRIG_TIMER;
-       if (!cmd->convert_src || tmp != cmd->convert_src)
-               err++;
-       tmp = cmd->scan_end_src;
-       cmd->scan_end_src &= TRIG_COUNT;
-       if (!cmd->scan_end_src || tmp != cmd->scan_end_src)
-               err++;
-       tmp = cmd->stop_src;
-       cmd->stop_src &= TRIG_COUNT | TRIG_NONE;
-       if (!cmd->stop_src || tmp != cmd->stop_src)
-               err++;
-       /* if(i_InterruptFlag==0) */
-       if (s_BoardInfos[dev->minor].i_InterruptFlag == 0) {
-               err++;
-               /*           printk("\nThe interrupt should be enabled\n"); */
-       }
+
+       /* Step 1 : check if triggers are trivially valid */
+
+       err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW | TRIG_EXT);
+       err |= cfc_check_trigger_src(&cmd->scan_begin_src,
+                                       TRIG_TIMER | TRIG_FOLLOW);
+       err |= cfc_check_trigger_src(&cmd->convert_src, TRIG_TIMER);
+       err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
+       err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE);
+
+       if (s_BoardInfos[dev->minor].i_InterruptFlag == 0)
+               err |= -EINVAL;
+
        if (err) {
                i_APCI3200_Reset(dev);
                return 1;
        }
 
-       if (cmd->start_src != TRIG_NOW && cmd->start_src != TRIG_EXT) {
-               err++;
-       }
+       /* Step 2a : make sure trigger sources are unique */
+
+       err |= cfc_check_trigger_is_unique(&cmd->start_src);
+       err |= cfc_check_trigger_is_unique(&cmd->scan_begin_src);
+       err |= cfc_check_trigger_is_unique(&cmd->stop_src);
+
+       /* Step 2b : and mutually compatible */
+
        if (cmd->start_src == TRIG_EXT) {
                i_TriggerEdge = cmd->start_arg & 0xFFFF;
                i_Triggermode = cmd->start_arg >> 16;
@@ -2619,21 +2609,6 @@ int i_APCI3200_CommandTestAnalogInput(struct comedi_device *dev, struct comedi_s
                }
        }
 
-       if (cmd->scan_begin_src != TRIG_TIMER &&
-               cmd->scan_begin_src != TRIG_FOLLOW)
-               err++;
-
-       if (cmd->convert_src != TRIG_TIMER)
-               err++;
-
-       if (cmd->scan_end_src != TRIG_COUNT) {
-               cmd->scan_end_src = TRIG_COUNT;
-               err++;
-       }
-
-       if (cmd->stop_src != TRIG_NONE && cmd->stop_src != TRIG_COUNT)
-               err++;
-
        if (err) {
                i_APCI3200_Reset(dev);
                return 2;
index 91efaa4caadb82ae97c6ec057be3de2a52859f45..a87192ac2846d939957176eca026801db860f3a5 100644 (file)
@@ -332,7 +332,7 @@ static int pci9111_ai_do_cmd_test(struct comedi_device *dev,
        int range, reference;
        int i;
 
-       /* Step 1 : check if trigger are trivialy valid */
+       /* Step 1 : check if triggers are trivially valid */
 
        error |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW);
        error |= cfc_check_trigger_src(&cmd->scan_begin_src,
index f7b254d004dc65684787e75ab217d3ae2606bc4a..06ff65c85c9fa36dbdfa8ec3af651db6b7bac7c0 100644 (file)
@@ -1102,7 +1102,7 @@ static int pci9118_ai_cmdtest(struct comedi_device *dev,
        int tmp;
        unsigned int divisor1 = 0, divisor2 = 0;
 
-       /* step 1: make sure trigger sources are trivially valid */
+       /* Step 1 : check if triggers are trivially valid */
 
        err |= cfc_check_trigger_src(&cmd->start_src,
                                        TRIG_NOW | TRIG_EXT | TRIG_INT);
@@ -1124,70 +1124,31 @@ static int pci9118_ai_cmdtest(struct comedi_device *dev,
        if (err)
                return 1;
 
-       /*
-        * step 2:
-        * make sure trigger sources are
-        * unique and mutually compatible
-        */
+       /* Step 2a : make sure trigger sources are unique */
 
-       if (cmd->start_src != TRIG_NOW &&
-           cmd->start_src != TRIG_INT && cmd->start_src != TRIG_EXT) {
-               cmd->start_src = TRIG_NOW;
-               err++;
-       }
-
-       if (cmd->scan_begin_src != TRIG_TIMER &&
-           cmd->scan_begin_src != TRIG_EXT &&
-           cmd->scan_begin_src != TRIG_INT &&
-           cmd->scan_begin_src != TRIG_FOLLOW) {
-               cmd->scan_begin_src = TRIG_FOLLOW;
-               err++;
-       }
-
-       if (cmd->convert_src != TRIG_TIMER &&
-           cmd->convert_src != TRIG_EXT && cmd->convert_src != TRIG_NOW) {
-               cmd->convert_src = TRIG_TIMER;
-               err++;
-       }
-
-       if (cmd->scan_end_src != TRIG_COUNT) {
-               cmd->scan_end_src = TRIG_COUNT;
-               err++;
-       }
+       err |= cfc_check_trigger_is_unique(cmd->start_src);
+       err |= cfc_check_trigger_is_unique(cmd->scan_begin_src);
+       err |= cfc_check_trigger_is_unique(cmd->convert_src);
+       err |= cfc_check_trigger_is_unique(cmd->stop_src);
 
-       if (cmd->stop_src != TRIG_NONE &&
-           cmd->stop_src != TRIG_COUNT &&
-           cmd->stop_src != TRIG_INT && cmd->stop_src != TRIG_EXT) {
-               cmd->stop_src = TRIG_COUNT;
-               err++;
-       }
+       /* Step 2b : and mutually compatible */
 
-       if (cmd->start_src == TRIG_EXT && cmd->scan_begin_src == TRIG_EXT) {
-               cmd->start_src = TRIG_NOW;
-               err++;
-       }
+       if (cmd->start_src == TRIG_EXT && cmd->scan_begin_src == TRIG_EXT)
+               err |= -EINVAL;
 
-       if (cmd->start_src == TRIG_INT && cmd->scan_begin_src == TRIG_INT) {
-               cmd->start_src = TRIG_NOW;
-               err++;
-       }
+       if (cmd->start_src == TRIG_INT && cmd->scan_begin_src == TRIG_INT)
+               err |= -EINVAL;
 
        if ((cmd->scan_begin_src & (TRIG_TIMER | TRIG_EXT)) &&
-           (!(cmd->convert_src & (TRIG_TIMER | TRIG_NOW)))) {
-               cmd->convert_src = TRIG_TIMER;
-               err++;
-       }
+           (!(cmd->convert_src & (TRIG_TIMER | TRIG_NOW))))
+               err |= -EINVAL;
 
        if ((cmd->scan_begin_src == TRIG_FOLLOW) &&
-           (!(cmd->convert_src & (TRIG_TIMER | TRIG_EXT)))) {
-               cmd->convert_src = TRIG_TIMER;
-               err++;
-       }
+           (!(cmd->convert_src & (TRIG_TIMER | TRIG_EXT))))
+               err |= -EINVAL;
 
-       if (cmd->stop_src == TRIG_EXT && cmd->scan_begin_src == TRIG_EXT) {
-               cmd->stop_src = TRIG_COUNT;
-               err++;
-       }
+       if (cmd->stop_src == TRIG_EXT && cmd->scan_begin_src == TRIG_EXT)
+               err |= -EINVAL;
 
        if (err)
                return 2;
index 0fd0210625f608ecb1c663b16b32bcab06f80971..def37bcc2a66bb2f624c665f4e8ade8038f25d72 100644 (file)
@@ -1046,7 +1046,7 @@ static int pci171x_ai_cmdtest(struct comedi_device *dev,
        int tmp;
        unsigned int divisor1 = 0, divisor2 = 0;
 
-       /* step 1: make sure trigger sources are trivially valid */
+       /* Step 1 : check if triggers are trivially valid */
 
        err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW | TRIG_EXT);
        err |= cfc_check_trigger_src(&cmd->scan_begin_src, TRIG_FOLLOW);
index b7cfc13a951f1081a14013b759b57628cb72338d..08f305210a695d57e1ef2c8181ec3d47b2f62c53 100644 (file)
@@ -210,6 +210,7 @@ order they appear in the channel list.
 
 #include "../comedidev.h"
 
+#include "comedi_fc.h"
 #include "8255.h"
 #include "8253.h"
 
@@ -771,52 +772,24 @@ dio200_subdev_intr_cmdtest(struct comedi_device *dev,
                           struct comedi_subdevice *s, struct comedi_cmd *cmd)
 {
        int err = 0;
-       unsigned int tmp;
 
-       /* step 1: make sure trigger sources are trivially valid */
+       /* Step 1 : check if triggers are trivially valid */
 
-       tmp = cmd->start_src;
-       cmd->start_src &= (TRIG_NOW | TRIG_INT);
-       if (!cmd->start_src || tmp != cmd->start_src)
-               err++;
-
-       tmp = cmd->scan_begin_src;
-       cmd->scan_begin_src &= TRIG_EXT;
-       if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src)
-               err++;
-
-       tmp = cmd->convert_src;
-       cmd->convert_src &= TRIG_NOW;
-       if (!cmd->convert_src || tmp != cmd->convert_src)
-               err++;
-
-       tmp = cmd->scan_end_src;
-       cmd->scan_end_src &= TRIG_COUNT;
-       if (!cmd->scan_end_src || tmp != cmd->scan_end_src)
-               err++;
-
-       tmp = cmd->stop_src;
-       cmd->stop_src &= (TRIG_COUNT | TRIG_NONE);
-       if (!cmd->stop_src || tmp != cmd->stop_src)
-               err++;
+       err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW | TRIG_INT);
+       err |= cfc_check_trigger_src(&cmd->scan_begin_src, TRIG_EXT);
+       err |= cfc_check_trigger_src(&cmd->convert_src, TRIG_NOW);
+       err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
+       err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE);
 
        if (err)
                return 1;
 
-       /* step 2: make sure trigger sources are unique and mutually
-                  compatible */
+       /* Step 2a : make sure trigger sources are unique */
 
-       /* these tests are true if more than one _src bit is set */
-       if ((cmd->start_src & (cmd->start_src - 1)) != 0)
-               err++;
-       if ((cmd->scan_begin_src & (cmd->scan_begin_src - 1)) != 0)
-               err++;
-       if ((cmd->convert_src & (cmd->convert_src - 1)) != 0)
-               err++;
-       if ((cmd->scan_end_src & (cmd->scan_end_src - 1)) != 0)
-               err++;
-       if ((cmd->stop_src & (cmd->stop_src - 1)) != 0)
-               err++;
+       err |= cfc_check_trigger_is_unique(cmd->start_src);
+       err |= cfc_check_trigger_is_unique(cmd->stop_src);
+
+       /* Step 2b : and mutually compatible */
 
        if (err)
                return 2;
index a957cd846088861b3a696fb50aa1d2a9c18f2ad3..eacb5e4735d7df0a3ccf7e794bb0744ab936f71a 100644 (file)
@@ -56,6 +56,7 @@ unused.
 
 #include "../comedidev.h"
 
+#include "comedi_fc.h"
 #include "8255.h"
 #include "plx9052.h"
 
@@ -313,39 +314,20 @@ static int pc236_intr_cmdtest(struct comedi_device *dev,
                              struct comedi_cmd *cmd)
 {
        int err = 0;
-       int tmp;
 
-       /* step 1 */
+       /* Step 1 : check if triggers are trivially valid */
 
-       tmp = cmd->start_src;
-       cmd->start_src &= TRIG_NOW;
-       if (!cmd->start_src || tmp != cmd->start_src)
-               err++;
-
-       tmp = cmd->scan_begin_src;
-       cmd->scan_begin_src &= TRIG_EXT;
-       if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src)
-               err++;
-
-       tmp = cmd->convert_src;
-       cmd->convert_src &= TRIG_FOLLOW;
-       if (!cmd->convert_src || tmp != cmd->convert_src)
-               err++;
-
-       tmp = cmd->scan_end_src;
-       cmd->scan_end_src &= TRIG_COUNT;
-       if (!cmd->scan_end_src || tmp != cmd->scan_end_src)
-               err++;
-
-       tmp = cmd->stop_src;
-       cmd->stop_src &= TRIG_NONE;
-       if (!cmd->stop_src || tmp != cmd->stop_src)
-               err++;
+       err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW);
+       err |= cfc_check_trigger_src(&cmd->scan_begin_src, TRIG_EXT);
+       err |= cfc_check_trigger_src(&cmd->convert_src, TRIG_FOLLOW);
+       err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
+       err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_NONE);
 
        if (err)
                return 1;
 
-       /* step 2: ignored */
+       /* Step 2a : make sure trigger sources are unique */
+       /* Step 2b : and mutually compatible */
 
        if (err)
                return 2;
index 365f911b9b0ecb83ea438d3c987c52a65333c9dc..1f65ec4d261e7bb1f73e55e15a0ff450fe731e4c 100644 (file)
@@ -720,53 +720,31 @@ pci224_ao_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s,
        int err = 0;
        unsigned int tmp;
 
-       /* Step 1: make sure trigger sources are trivially valid. */
+       /* Step 1 : check if triggers are trivially valid */
 
-       tmp = cmd->start_src;
-       cmd->start_src &= TRIG_INT | TRIG_EXT;
-       if (!cmd->start_src || tmp != cmd->start_src)
-               err++;
-
-       tmp = cmd->scan_begin_src;
-       cmd->scan_begin_src &= TRIG_EXT | TRIG_TIMER;
-       if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src)
-               err++;
-
-       tmp = cmd->convert_src;
-       cmd->convert_src &= TRIG_NOW;
-       if (!cmd->convert_src || tmp != cmd->convert_src)
-               err++;
-
-       tmp = cmd->scan_end_src;
-       cmd->scan_end_src &= TRIG_COUNT;
-       if (!cmd->scan_end_src || tmp != cmd->scan_end_src)
-               err++;
-
-       tmp = cmd->stop_src;
-       cmd->stop_src &= TRIG_COUNT | TRIG_EXT | TRIG_NONE;
-       if (!cmd->stop_src || tmp != cmd->stop_src)
-               err++;
+       err |= cfc_check_trigger_src(&cmd->start_src, TRIG_INT | TRIG_EXT);
+       err |= cfc_check_trigger_src(&cmd->scan_begin_src,
+                                       TRIG_EXT | TRIG_TIMER);
+       err |= cfc_check_trigger_src(&cmd->convert_src, TRIG_NOW);
+       err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
+       err |= cfc_check_trigger_src(&cmd->stop_src,
+                                       TRIG_COUNT | TRIG_EXT | TRIG_NONE);
 
        if (err)
                return 1;
 
-       /* Step 2: make sure trigger sources are unique and mutually
-        * compatible. */
+       /* Step 2a : make sure trigger sources are unique */
 
-       /* these tests are true if more than one _src bit is set */
-       if ((cmd->start_src & (cmd->start_src - 1)) != 0)
-               err++;
-       if ((cmd->scan_begin_src & (cmd->scan_begin_src - 1)) != 0)
-               err++;
-       if ((cmd->convert_src & (cmd->convert_src - 1)) != 0)
-               err++;
-       if ((cmd->scan_end_src & (cmd->scan_end_src - 1)) != 0)
-               err++;
-       if ((cmd->stop_src & (cmd->stop_src - 1)) != 0)
-               err++;
+       err |= cfc_check_trigger_is_unique(cmd->start_src);
+       err |= cfc_check_trigger_is_unique(cmd->scan_begin_src);
+       err |= cfc_check_trigger_is_unique(cmd->stop_src);
 
-       /* There's only one external trigger signal (which makes these
-        * tests easier).  Only one thing can use it. */
+       /* Step 2b : and mutually compatible */
+
+       /*
+        * There's only one external trigger signal (which makes these
+        * tests easier).  Only one thing can use it.
+        */
        tmp = 0;
        if (cmd->start_src & TRIG_EXT)
                tmp++;
@@ -775,7 +753,7 @@ pci224_ao_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s,
        if (cmd->stop_src & TRIG_EXT)
                tmp++;
        if (tmp > 1)
-               err++;
+               err |= -EINVAL;
 
        if (err)
                return 2;
index 4c9f1314ea1dec5c80887d274b715c49baec47e4..bd8fb876ce2ed7878e95408defd0c6b212391ad7 100644 (file)
@@ -193,6 +193,7 @@ for (or detection of) various hardware problems added by Ian Abbott.
 #include <linux/delay.h>
 #include <linux/interrupt.h>
 
+#include "comedi_fc.h"
 #include "8253.h"
 #include "8255.h"
 
@@ -958,23 +959,11 @@ static int pci230_ao_cmdtest(struct comedi_device *dev,
        int err = 0;
        unsigned int tmp;
 
-       /* cmdtest tests a particular command to see if it is valid.
-        * Using the cmdtest ioctl, a user can create a valid cmd
-        * and then have it executes by the cmd ioctl.
-        *
-        * cmdtest returns 1,2,3,4 or 0, depending on which tests
-        * the command passes. */
+       /* Step 1 : check if triggers are trivially valid */
 
-       /* Step 1: make sure trigger sources are trivially valid.
-        * "invalid source" returned by comedilib to user mode process
-        * if this fails. */
-
-       tmp = cmd->start_src;
-       cmd->start_src &= TRIG_INT;
-       if (!cmd->start_src || tmp != cmd->start_src)
-               err++;
+       err |= cfc_check_trigger_src(&cmd->start_src, TRIG_INT);
 
-       tmp = cmd->scan_begin_src;
+       tmp = TRIG_TIMER | TRIG_INT;
        if ((thisboard->min_hwver > 0) && (devpriv->hwver >= 2)) {
                /*
                 * For PCI230+ hardware version 2 onwards, allow external
@@ -990,46 +979,23 @@ static int pci230_ao_cmdtest(struct comedi_device *dev,
                 * scan_begin_src==TRIG_EXT support to be a bonus rather than a
                 * guarantee!
                 */
-               cmd->scan_begin_src &= TRIG_TIMER | TRIG_INT | TRIG_EXT;
-       } else {
-               cmd->scan_begin_src &= TRIG_TIMER | TRIG_INT;
+               tmp |= TRIG_EXT;
        }
-       if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src)
-               err++;
+       err |= cfc_check_trigger_src(&cmd->scan_begin_src, tmp);
 
-       tmp = cmd->convert_src;
-       cmd->convert_src &= TRIG_NOW;
-       if (!cmd->convert_src || tmp != cmd->convert_src)
-               err++;
-
-       tmp = cmd->scan_end_src;
-       cmd->scan_end_src &= TRIG_COUNT;
-       if (!cmd->scan_end_src || tmp != cmd->scan_end_src)
-               err++;
-
-       tmp = cmd->stop_src;
-       cmd->stop_src &= TRIG_COUNT | TRIG_NONE;
-       if (!cmd->stop_src || tmp != cmd->stop_src)
-               err++;
+       err |= cfc_check_trigger_src(&cmd->convert_src, TRIG_NOW);
+       err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
+       err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE);
 
        if (err)
                return 1;
 
-       /* Step 2: make sure trigger sources are unique and mutually compatible
-        * "source conflict" returned by comedilib to user mode process
-        * if this fails. */
+       /* Step 2a : make sure trigger sources are unique */
 
-       /* these tests are true if more than one _src bit is set */
-       if ((cmd->start_src & (cmd->start_src - 1)) != 0)
-               err++;
-       if ((cmd->scan_begin_src & (cmd->scan_begin_src - 1)) != 0)
-               err++;
-       if ((cmd->convert_src & (cmd->convert_src - 1)) != 0)
-               err++;
-       if ((cmd->scan_end_src & (cmd->scan_end_src - 1)) != 0)
-               err++;
-       if ((cmd->stop_src & (cmd->stop_src - 1)) != 0)
-               err++;
+       err |= cfc_check_trigger_is_unique(cmd->scan_begin_src);
+       err |= cfc_check_trigger_is_unique(cmd->stop_src);
+
+       /* Step 2b : and mutually compatible */
 
        if (err)
                return 2;
@@ -1610,75 +1576,45 @@ static int pci230_ai_cmdtest(struct comedi_device *dev,
        int err = 0;
        unsigned int tmp;
 
-       /* cmdtest tests a particular command to see if it is valid.
-        * Using the cmdtest ioctl, a user can create a valid cmd
-        * and then have it executes by the cmd ioctl.
-        *
-        * cmdtest returns 1,2,3,4,5 or 0, depending on which tests
-        * the command passes. */
+       /* Step 1 : check if triggers are trivially valid */
 
-       /* Step 1: make sure trigger sources are trivially valid.
-        * "invalid source" returned by comedilib to user mode process
-        * if this fails. */
-
-       tmp = cmd->start_src;
-       cmd->start_src &= TRIG_NOW | TRIG_INT;
-       if (!cmd->start_src || tmp != cmd->start_src)
-               err++;
+       err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW | TRIG_INT);
 
-       tmp = cmd->scan_begin_src;
-       /* Unfortunately, we cannot trigger a scan off an external source
-        * on the PCI260 board, since it uses the PPIC0 (DIO) input, which
-        * isn't present on the PCI260.  For PCI260+ we can use the
-        * EXTTRIG/EXTCONVCLK input on pin 17 instead. */
+       tmp = TRIG_FOLLOW | TRIG_TIMER | TRIG_INT;
        if ((thisboard->have_dio) || (thisboard->min_hwver > 0)) {
-               cmd->scan_begin_src &= TRIG_FOLLOW | TRIG_TIMER | TRIG_INT
-                   | TRIG_EXT;
-       } else {
-               cmd->scan_begin_src &= TRIG_FOLLOW | TRIG_TIMER | TRIG_INT;
+               /*
+                * Unfortunately, we cannot trigger a scan off an external
+                * source on the PCI260 board, since it uses the PPIC0 (DIO)
+                * input, which isn't present on the PCI260.  For PCI260+
+                * we can use the EXTTRIG/EXTCONVCLK input on pin 17 instead.
+                */
+               tmp |= TRIG_EXT;
        }
-       if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src)
-               err++;
-
-       tmp = cmd->convert_src;
-       cmd->convert_src &= TRIG_TIMER | TRIG_INT | TRIG_EXT;
-       if (!cmd->convert_src || tmp != cmd->convert_src)
-               err++;
-
-       tmp = cmd->scan_end_src;
-       cmd->scan_end_src &= TRIG_COUNT;
-       if (!cmd->scan_end_src || tmp != cmd->scan_end_src)
-               err++;
-
-       tmp = cmd->stop_src;
-       cmd->stop_src &= TRIG_COUNT | TRIG_NONE;
-       if (!cmd->stop_src || tmp != cmd->stop_src)
-               err++;
+       err |= cfc_check_trigger_src(&cmd->scan_begin_src, tmp);
+       err |= cfc_check_trigger_src(&cmd->convert_src,
+                                       TRIG_TIMER | TRIG_INT | TRIG_EXT);
+       err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
+       err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE);
 
        if (err)
                return 1;
 
-       /* Step 2: make sure trigger sources are unique and mutually compatible
-        * "source conflict" returned by comedilib to user mode process
-        * if this fails. */
+       /* Step 2a : make sure trigger sources are unique */
 
-       /* these tests are true if more than one _src bit is set */
-       if ((cmd->start_src & (cmd->start_src - 1)) != 0)
-               err++;
-       if ((cmd->scan_begin_src & (cmd->scan_begin_src - 1)) != 0)
-               err++;
-       if ((cmd->convert_src & (cmd->convert_src - 1)) != 0)
-               err++;
-       if ((cmd->scan_end_src & (cmd->scan_end_src - 1)) != 0)
-               err++;
-       if ((cmd->stop_src & (cmd->stop_src - 1)) != 0)
-               err++;
+       err |= cfc_check_trigger_is_unique(cmd->start_src);
+       err |= cfc_check_trigger_is_unique(cmd->scan_begin_src);
+       err |= cfc_check_trigger_is_unique(cmd->convert_src);
+       err |= cfc_check_trigger_is_unique(cmd->stop_src);
+
+       /* Step 2b : and mutually compatible */
 
-       /* If scan_begin_src is not TRIG_FOLLOW, then a monostable will be
-        * set up to generate a fixed number of timed conversion pulses. */
+       /*
+        * If scan_begin_src is not TRIG_FOLLOW, then a monostable will be
+        * set up to generate a fixed number of timed conversion pulses.
+        */
        if ((cmd->scan_begin_src != TRIG_FOLLOW)
            && (cmd->convert_src != TRIG_TIMER))
-               err++;
+               err |= -EINVAL;
 
        if (err)
                return 2;
index a3d53babe137c442e846f67b62b212e2901f6481..6d81d8b40ccca8a20e5f5649c413fc7090070734 100644 (file)
@@ -46,6 +46,7 @@ Status: experimental
 #include <pcmcia/cistpl.h>
 #include <pcmcia/ds.h>
 
+#include "comedi_fc.h"
 #include "8253.h"
 
 #define DAS16CS_SIZE                   18
@@ -169,47 +170,26 @@ static int das16cs_ai_cmdtest(struct comedi_device *dev,
        int err = 0;
        int tmp;
 
-       /* step 1: make sure trigger sources are trivially valid */
+       /* Step 1 : check if triggers are trivially valid */
 
-       tmp = cmd->start_src;
-       cmd->start_src &= TRIG_NOW;
-       if (!cmd->start_src || tmp != cmd->start_src)
-               err++;
-
-       tmp = cmd->scan_begin_src;
-       cmd->scan_begin_src &= TRIG_TIMER | TRIG_EXT;
-       if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src)
-               err++;
-
-       tmp = cmd->convert_src;
-       cmd->convert_src &= TRIG_TIMER | TRIG_EXT;
-       if (!cmd->convert_src || tmp != cmd->convert_src)
-               err++;
-
-       tmp = cmd->scan_end_src;
-       cmd->scan_end_src &= TRIG_COUNT;
-       if (!cmd->scan_end_src || tmp != cmd->scan_end_src)
-               err++;
-
-       tmp = cmd->stop_src;
-       cmd->stop_src &= TRIG_COUNT | TRIG_NONE;
-       if (!cmd->stop_src || tmp != cmd->stop_src)
-               err++;
+       err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW);
+       err |= cfc_check_trigger_src(&cmd->scan_begin_src,
+                                       TRIG_TIMER | TRIG_EXT);
+       err |= cfc_check_trigger_src(&cmd->convert_src,
+                                       TRIG_TIMER | TRIG_EXT);
+       err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
+       err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE);
 
        if (err)
                return 1;
 
-       /* step 2: make sure trigger sources are unique and
-        * mutually compatible */
+       /* Step 2a : make sure trigger sources are unique */
 
-       /* note that mutual compatibility is not an issue here */
-       if (cmd->scan_begin_src != TRIG_TIMER &&
-           cmd->scan_begin_src != TRIG_EXT)
-               err++;
-       if (cmd->convert_src != TRIG_TIMER && cmd->convert_src != TRIG_EXT)
-               err++;
-       if (cmd->stop_src != TRIG_COUNT && cmd->stop_src != TRIG_NONE)
-               err++;
+       err |= cfc_check_trigger_is_unique(cmd->scan_begin_src);
+       err |= cfc_check_trigger_is_unique(cmd->convert_src);
+       err |= cfc_check_trigger_is_unique(cmd->stop_src);
+
+       /* Step 2b : and mutually compatible */
 
        if (err)
                return 2;
index 4dd87c28ca20f8eed2a851453aec804cabee40e5..de21a261ff453b9db06ebfe4ac99617d68204408 100644 (file)
@@ -803,58 +803,35 @@ static int cb_pcidas_ai_cmdtest(struct comedi_device *dev,
        int tmp;
        int i, gain, start_chan;
 
-       /* step 1: trigger sources are trivially valid */
+       /* Step 1 : check if triggers are trivially valid */
 
-       tmp = cmd->start_src;
-       cmd->start_src &= TRIG_NOW | TRIG_EXT;
-       if (!cmd->start_src || tmp != cmd->start_src)
-               err++;
-
-       tmp = cmd->scan_begin_src;
-       cmd->scan_begin_src &= TRIG_FOLLOW | TRIG_TIMER | TRIG_EXT;
-       if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src)
-               err++;
-
-       tmp = cmd->convert_src;
-       cmd->convert_src &= TRIG_TIMER | TRIG_NOW | TRIG_EXT;
-       if (!cmd->convert_src || tmp != cmd->convert_src)
-               err++;
-
-       tmp = cmd->scan_end_src;
-       cmd->scan_end_src &= TRIG_COUNT;
-       if (!cmd->scan_end_src || tmp != cmd->scan_end_src)
-               err++;
-
-       tmp = cmd->stop_src;
-       cmd->stop_src &= TRIG_COUNT | TRIG_NONE;
-       if (!cmd->stop_src || tmp != cmd->stop_src)
-               err++;
+       err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW | TRIG_EXT);
+       err |= cfc_check_trigger_src(&cmd->scan_begin_src,
+                                       TRIG_FOLLOW | TRIG_TIMER | TRIG_EXT);
+       err |= cfc_check_trigger_src(&cmd->convert_src,
+                                       TRIG_TIMER | TRIG_NOW | TRIG_EXT);
+       err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
+       err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE);
 
        if (err)
                return 1;
 
-       /* step 2: trigger sources are unique and mutually compatible */
+       /* Step 2a : make sure trigger sources are unique */
 
-       if (cmd->start_src != TRIG_NOW && cmd->start_src != TRIG_EXT)
-               err++;
-       if (cmd->scan_begin_src != TRIG_FOLLOW &&
-           cmd->scan_begin_src != TRIG_TIMER &&
-           cmd->scan_begin_src != TRIG_EXT)
-               err++;
-       if (cmd->convert_src != TRIG_TIMER &&
-           cmd->convert_src != TRIG_EXT && cmd->convert_src != TRIG_NOW)
-               err++;
-       if (cmd->stop_src != TRIG_COUNT && cmd->stop_src != TRIG_NONE)
-               err++;
+       err |= cfc_check_trigger_is_unique(cmd->start_src);
+       err |= cfc_check_trigger_is_unique(cmd->scan_begin_src);
+       err |= cfc_check_trigger_is_unique(cmd->convert_src);
+       err |= cfc_check_trigger_is_unique(cmd->stop_src);
+
+       /* Step 2b : and mutually compatible */
 
-       /*  make sure trigger sources are compatible with each other */
        if (cmd->scan_begin_src == TRIG_FOLLOW && cmd->convert_src == TRIG_NOW)
-               err++;
+               err |= -EINVAL;
        if (cmd->scan_begin_src != TRIG_FOLLOW && cmd->convert_src != TRIG_NOW)
-               err++;
+               err |= -EINVAL;
        if (cmd->start_src == TRIG_EXT &&
            (cmd->convert_src == TRIG_EXT || cmd->scan_begin_src == TRIG_EXT))
-               err++;
+               err |= -EINVAL;
 
        if (err)
                return 2;
@@ -1079,43 +1056,24 @@ static int cb_pcidas_ao_cmdtest(struct comedi_device *dev,
        int err = 0;
        int tmp;
 
-       /* step 1: trigger sources are trivially valid */
-
-       tmp = cmd->start_src;
-       cmd->start_src &= TRIG_INT;
-       if (!cmd->start_src || tmp != cmd->start_src)
-               err++;
-
-       tmp = cmd->scan_begin_src;
-       cmd->scan_begin_src &= TRIG_TIMER | TRIG_EXT;
-       if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src)
-               err++;
-
-       tmp = cmd->convert_src;
-       cmd->convert_src &= TRIG_NOW;
-       if (!cmd->convert_src || tmp != cmd->convert_src)
-               err++;
-
-       tmp = cmd->scan_end_src;
-       cmd->scan_end_src &= TRIG_COUNT;
-       if (!cmd->scan_end_src || tmp != cmd->scan_end_src)
-               err++;
+       /* Step 1 : check if triggers are trivially valid */
 
-       tmp = cmd->stop_src;
-       cmd->stop_src &= TRIG_COUNT | TRIG_NONE;
-       if (!cmd->stop_src || tmp != cmd->stop_src)
-               err++;
+       err |= cfc_check_trigger_src(&cmd->start_src, TRIG_INT);
+       err |= cfc_check_trigger_src(&cmd->scan_begin_src,
+                                       TRIG_TIMER | TRIG_EXT);
+       err |= cfc_check_trigger_src(&cmd->convert_src, TRIG_NOW);
+       err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
+       err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE);
 
        if (err)
                return 1;
 
-       /* step 2: trigger sources are unique and mutually compatible */
+       /* Step 2a : make sure trigger sources are unique */
 
-       if (cmd->scan_begin_src != TRIG_TIMER &&
-           cmd->scan_begin_src != TRIG_EXT)
-               err++;
-       if (cmd->stop_src != TRIG_COUNT && cmd->stop_src != TRIG_NONE)
-               err++;
+       err |= cfc_check_trigger_is_unique(cmd->scan_begin_src);
+       err |= cfc_check_trigger_is_unique(cmd->stop_src);
+
+       /* Step 2b : and mutually compatible */
 
        if (err)
                return 2;
index 7168883eed41195f439ac4abead96c39ceed0fac..0472a9088abe3603b68a3e603432c4fc9840057b 100644 (file)
@@ -2108,74 +2108,50 @@ static int ai_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s,
                      struct comedi_cmd *cmd)
 {
        int err = 0;
-       int tmp;
        unsigned int tmp_arg, tmp_arg2;
        int i;
        int aref;
        unsigned int triggers;
 
-       /* step 1: make sure trigger sources are trivially valid */
+       /* Step 1 : check if triggers are trivially valid */
 
-       tmp = cmd->start_src;
-       cmd->start_src &= TRIG_NOW | TRIG_EXT;
-       if (!cmd->start_src || tmp != cmd->start_src)
-               err++;
+       err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW | TRIG_EXT);
 
-       tmp = cmd->scan_begin_src;
        triggers = TRIG_TIMER;
        if (board(dev)->layout == LAYOUT_4020)
                triggers |= TRIG_OTHER;
        else
                triggers |= TRIG_FOLLOW;
-       cmd->scan_begin_src &= triggers;
-       if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src)
-               err++;
+       err |= cfc_check_trigger_src(&cmd->scan_begin_src, triggers);
 
-       tmp = cmd->convert_src;
        triggers = TRIG_TIMER;
        if (board(dev)->layout == LAYOUT_4020)
                triggers |= TRIG_NOW;
        else
                triggers |= TRIG_EXT;
-       cmd->convert_src &= triggers;
-       if (!cmd->convert_src || tmp != cmd->convert_src)
-               err++;
-
-       tmp = cmd->scan_end_src;
-       cmd->scan_end_src &= TRIG_COUNT;
-       if (!cmd->scan_end_src || tmp != cmd->scan_end_src)
-               err++;
+       err |= cfc_check_trigger_src(&cmd->convert_src, triggers);
 
-       tmp = cmd->stop_src;
-       cmd->stop_src &= TRIG_COUNT | TRIG_EXT | TRIG_NONE;
-       if (!cmd->stop_src || tmp != cmd->stop_src)
-               err++;
+       err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
+       err |= cfc_check_trigger_src(&cmd->stop_src,
+                                       TRIG_COUNT | TRIG_EXT | TRIG_NONE);
 
        if (err)
                return 1;
 
-       /* step 2: make sure trigger sources are unique and mutually compatible */
+       /* Step 2a : make sure trigger sources are unique */
 
-       /*  uniqueness check */
-       if (cmd->start_src != TRIG_NOW && cmd->start_src != TRIG_EXT)
-               err++;
-       if (cmd->scan_begin_src != TRIG_TIMER &&
-           cmd->scan_begin_src != TRIG_OTHER &&
-           cmd->scan_begin_src != TRIG_FOLLOW)
-               err++;
-       if (cmd->convert_src != TRIG_TIMER &&
-           cmd->convert_src != TRIG_EXT && cmd->convert_src != TRIG_NOW)
-               err++;
-       if (cmd->stop_src != TRIG_COUNT &&
-           cmd->stop_src != TRIG_NONE && cmd->stop_src != TRIG_EXT)
-               err++;
+       err |= cfc_check_trigger_is_unique(cmd->start_src);
+       err |= cfc_check_trigger_is_unique(cmd->scan_begin_src);
+       err |= cfc_check_trigger_is_unique(cmd->convert_src);
+       err |= cfc_check_trigger_is_unique(cmd->stop_src);
+
+       /* Step 2b : and mutually compatible */
 
-       /*  compatibility check */
        if (cmd->convert_src == TRIG_EXT && cmd->scan_begin_src == TRIG_TIMER)
-               err++;
+               err |= -EINVAL;
        if (cmd->stop_src != TRIG_COUNT &&
            cmd->stop_src != TRIG_NONE && cmd->stop_src != TRIG_EXT)
-               err++;
+               err |= -EINVAL;
 
        if (err)
                return 2;
@@ -3466,55 +3442,33 @@ static int ao_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s,
                      struct comedi_cmd *cmd)
 {
        int err = 0;
-       int tmp;
        unsigned int tmp_arg;
        int i;
 
-       /* step 1: make sure trigger sources are trivially valid */
+       /* Step 1 : check if triggers are trivially valid */
 
-       tmp = cmd->start_src;
-       cmd->start_src &= TRIG_INT | TRIG_EXT;
-       if (!cmd->start_src || tmp != cmd->start_src)
-               err++;
-
-       tmp = cmd->scan_begin_src;
-       cmd->scan_begin_src &= TRIG_TIMER | TRIG_EXT;
-       if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src)
-               err++;
-
-       tmp = cmd->convert_src;
-       cmd->convert_src &= TRIG_NOW;
-       if (!cmd->convert_src || tmp != cmd->convert_src)
-               err++;
-
-       tmp = cmd->scan_end_src;
-       cmd->scan_end_src &= TRIG_COUNT;
-       if (!cmd->scan_end_src || tmp != cmd->scan_end_src)
-               err++;
-
-       tmp = cmd->stop_src;
-       cmd->stop_src &= TRIG_NONE;
-       if (!cmd->stop_src || tmp != cmd->stop_src)
-               err++;
+       err |= cfc_check_trigger_src(&cmd->start_src, TRIG_INT | TRIG_EXT);
+       err |= cfc_check_trigger_src(&cmd->scan_begin_src,
+                                       TRIG_TIMER | TRIG_EXT);
+       err |= cfc_check_trigger_src(&cmd->convert_src, TRIG_NOW);
+       err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
+       err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_NONE);
 
        if (err)
                return 1;
 
-       /* step 2: make sure trigger sources are unique and mutually compatible */
+       /* Step 2a : make sure trigger sources are unique */
 
-       /*  uniqueness check */
-       if (cmd->start_src != TRIG_INT && cmd->start_src != TRIG_EXT)
-               err++;
-       if (cmd->scan_begin_src != TRIG_TIMER &&
-           cmd->scan_begin_src != TRIG_EXT)
-               err++;
+       err |= cfc_check_trigger_is_unique(cmd->start_src);
+       err |= cfc_check_trigger_is_unique(cmd->scan_begin_src);
+
+       /* Step 2b : and mutually compatible */
 
-       /*  compatibility check */
        if (cmd->convert_src == TRIG_EXT && cmd->scan_begin_src == TRIG_TIMER)
-               err++;
+               err |= -EINVAL;
        if (cmd->stop_src != TRIG_COUNT &&
            cmd->stop_src != TRIG_NONE && cmd->stop_src != TRIG_EXT)
-               err++;
+               err |= -EINVAL;
 
        if (err)
                return 2;
index ad9f3a3075a06c879bf12663703264bdc8fc51fc..aef946df27e2f22ba85c48e3072ffbc6866d7431 100644 (file)
@@ -48,6 +48,7 @@ Please report success/failure with other different cards to
 
 #include "../comedidev.h"
 
+#include "comedi_fc.h"
 #include "8255.h"
 
 /* PCI vendor number of ComputerBoards */
@@ -247,56 +248,26 @@ static int cb_pcidda_ai_cmdtest(struct comedi_device *dev,
        int err = 0;
        int tmp;
 
-       /* cmdtest tests a particular command to see if it is valid.
-        * Using the cmdtest ioctl, a user can create a valid cmd
-        * and then have it executes by the cmd ioctl.
-        *
-        * cmdtest returns 1,2,3,4 or 0, depending on which tests
-        * the command passes. */
+       /* Step 1 : check if triggers are trivially valid */
 
-       /* step 1: make sure trigger sources are trivially valid */
-
-       tmp = cmd->start_src;
-       cmd->start_src &= TRIG_NOW;
-       if (!cmd->start_src || tmp != cmd->start_src)
-               err++;
-
-       tmp = cmd->scan_begin_src;
-       cmd->scan_begin_src &= TRIG_TIMER | TRIG_EXT;
-       if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src)
-               err++;
-
-       tmp = cmd->convert_src;
-       cmd->convert_src &= TRIG_TIMER | TRIG_EXT;
-       if (!cmd->convert_src || tmp != cmd->convert_src)
-               err++;
-
-       tmp = cmd->scan_end_src;
-       cmd->scan_end_src &= TRIG_COUNT;
-       if (!cmd->scan_end_src || tmp != cmd->scan_end_src)
-               err++;
-
-       tmp = cmd->stop_src;
-       cmd->stop_src &= TRIG_COUNT | TRIG_NONE;
-       if (!cmd->stop_src || tmp != cmd->stop_src)
-               err++;
+       err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW);
+       err |= cfc_check_trigger_src(&cmd->scan_begin_src,
+                                       TRIG_TIMER | TRIG_EXT);
+       err |= cfc_check_trigger_src(&cmd->convert_src,
+                                       TRIG_TIMER | TRIG_EXT);
+       err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
+       err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE);
 
        if (err)
                return 1;
 
-       /*
-        * step 2: make sure trigger sources are unique and mutually
-        * compatible
-        */
+       /* Step 2a : make sure trigger sources are unique */
 
-       /* note that mutual compatibility is not an issue here */
-       if (cmd->scan_begin_src != TRIG_TIMER
-           && cmd->scan_begin_src != TRIG_EXT)
-               err++;
-       if (cmd->convert_src != TRIG_TIMER && cmd->convert_src != TRIG_EXT)
-               err++;
-       if (cmd->stop_src != TRIG_TIMER && cmd->stop_src != TRIG_EXT)
-               err++;
+       err |= cfc_check_trigger_is_unique(cmd->scan_begin_src);
+       err |= cfc_check_trigger_is_unique(cmd->convert_src);
+       err |= cfc_check_trigger_is_unique(cmd->stop_src);
+
+       /* Step 2b : and mutually compatible */
 
        if (err)
                return 2;
index c9e40a9fea05b127f889ed618de711b06dadecec..22ef94242590e9ca640303ef3c83455f876383c3 100644 (file)
@@ -85,6 +85,8 @@ pin, which can be used to wake up tasks.
 #include <linux/interrupt.h>
 #include <linux/ioport.h>
 
+#include "comedi_fc.h"
+
 #define PARPORT_SIZE 3
 
 #define PARPORT_A 0
@@ -176,39 +178,20 @@ static int parport_intr_cmdtest(struct comedi_device *dev,
                                struct comedi_cmd *cmd)
 {
        int err = 0;
-       int tmp;
-
-       /* step 1 */
-
-       tmp = cmd->start_src;
-       cmd->start_src &= TRIG_NOW;
-       if (!cmd->start_src || tmp != cmd->start_src)
-               err++;
-
-       tmp = cmd->scan_begin_src;
-       cmd->scan_begin_src &= TRIG_EXT;
-       if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src)
-               err++;
 
-       tmp = cmd->convert_src;
-       cmd->convert_src &= TRIG_FOLLOW;
-       if (!cmd->convert_src || tmp != cmd->convert_src)
-               err++;
+       /* Step 1 : check if triggers are trivially valid */
 
-       tmp = cmd->scan_end_src;
-       cmd->scan_end_src &= TRIG_COUNT;
-       if (!cmd->scan_end_src || tmp != cmd->scan_end_src)
-               err++;
-
-       tmp = cmd->stop_src;
-       cmd->stop_src &= TRIG_NONE;
-       if (!cmd->stop_src || tmp != cmd->stop_src)
-               err++;
+       err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW);
+       err |= cfc_check_trigger_src(&cmd->scan_begin_src, TRIG_EXT);
+       err |= cfc_check_trigger_src(&cmd->convert_src, TRIG_FOLLOW);
+       err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
+       err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_NONE);
 
        if (err)
                return 1;
 
-       /* step 2: ignored */
+       /* Step 2a : make sure trigger sources are unique */
+       /* Step 2b : and mutually compatible */
 
        if (err)
                return 2;
index b0f0ec58dfedb1671ccf836ee9edc2635027e185..7817def1556cd3ed09c4a8ead9bfb99c0b380714 100644 (file)
@@ -231,44 +231,23 @@ static int waveform_ai_cmdtest(struct comedi_device *dev,
        int err = 0;
        int tmp;
 
-       /* step 1: make sure trigger sources are trivially valid */
+       /* Step 1 : check if triggers are trivially valid */
 
-       tmp = cmd->start_src;
-       cmd->start_src &= TRIG_NOW;
-       if (!cmd->start_src || tmp != cmd->start_src)
-               err++;
-
-       tmp = cmd->scan_begin_src;
-       cmd->scan_begin_src &= TRIG_TIMER;
-       if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src)
-               err++;
-
-       tmp = cmd->convert_src;
-       cmd->convert_src &= TRIG_NOW | TRIG_TIMER;
-       if (!cmd->convert_src || tmp != cmd->convert_src)
-               err++;
-
-       tmp = cmd->scan_end_src;
-       cmd->scan_end_src &= TRIG_COUNT;
-       if (!cmd->scan_end_src || tmp != cmd->scan_end_src)
-               err++;
-
-       tmp = cmd->stop_src;
-       cmd->stop_src &= TRIG_COUNT | TRIG_NONE;
-       if (!cmd->stop_src || tmp != cmd->stop_src)
-               err++;
+       err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW);
+       err |= cfc_check_trigger_src(&cmd->scan_begin_src, TRIG_TIMER);
+       err |= cfc_check_trigger_src(&cmd->convert_src, TRIG_NOW | TRIG_TIMER);
+       err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
+       err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE);
 
        if (err)
                return 1;
 
-       /*
-        * step 2: make sure trigger sources are unique and mutually compatible
-        */
+       /* Step 2a : make sure trigger sources are unique */
 
-       if (cmd->convert_src != TRIG_NOW && cmd->convert_src != TRIG_TIMER)
-               err++;
-       if (cmd->stop_src != TRIG_COUNT && cmd->stop_src != TRIG_NONE)
-               err++;
+       err |= cfc_check_trigger_is_unique(cmd->convert_src);
+       err |= cfc_check_trigger_is_unique(cmd->stop_src);
+
+       /* Step 2b : and mutually compatible */
 
        if (err)
                return 2;
index 744376a49d082942fe80b794e3660791452d9721..fcb8a32adb2fa4a969ab7408c3b7443814ba3c7a 100644 (file)
@@ -402,62 +402,42 @@ static int das16_cmd_test(struct comedi_device *dev, struct comedi_subdevice *s,
        int gain, start_chan, i;
        int mask;
 
-       /* make sure triggers are valid */
-       tmp = cmd->start_src;
-       cmd->start_src &= TRIG_NOW;
-       if (!cmd->start_src || tmp != cmd->start_src)
-               err++;
+       /* Step 1 : check if triggers are trivially valid */
+
+       err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW);
 
-       tmp = cmd->scan_begin_src;
        mask = TRIG_FOLLOW;
        /*  if board supports burst mode */
        if (board->size > 0x400)
                mask |= TRIG_TIMER | TRIG_EXT;
-       cmd->scan_begin_src &= mask;
-       if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src)
-               err++;
+       err |= cfc_check_trigger_src(&cmd->scan_begin_src, mask);
 
        tmp = cmd->convert_src;
        mask = TRIG_TIMER | TRIG_EXT;
        /*  if board supports burst mode */
        if (board->size > 0x400)
                mask |= TRIG_NOW;
-       cmd->convert_src &= mask;
-       if (!cmd->convert_src || tmp != cmd->convert_src)
-               err++;
+       err |= cfc_check_trigger_src(&cmd->convert_src, mask);
 
-       tmp = cmd->scan_end_src;
-       cmd->scan_end_src &= TRIG_COUNT;
-       if (!cmd->scan_end_src || tmp != cmd->scan_end_src)
-               err++;
-
-       tmp = cmd->stop_src;
-       cmd->stop_src &= TRIG_COUNT | TRIG_NONE;
-       if (!cmd->stop_src || tmp != cmd->stop_src)
-               err++;
+       err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
+       err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE);
 
        if (err)
                return 1;
 
-       /**
-        * step 2: make sure trigger sources are unique and
-        * mutually compatible
-        */
-       if (cmd->scan_begin_src != TRIG_TIMER &&
-           cmd->scan_begin_src != TRIG_EXT &&
-           cmd->scan_begin_src != TRIG_FOLLOW)
-               err++;
-       if (cmd->convert_src != TRIG_TIMER &&
-           cmd->convert_src != TRIG_EXT && cmd->convert_src != TRIG_NOW)
-               err++;
-       if (cmd->stop_src != TRIG_NONE && cmd->stop_src != TRIG_COUNT)
-               err++;
+       /* Step 2a : make sure trigger sources are unique */
+
+       err |= cfc_check_trigger_is_unique(cmd->scan_begin_src);
+       err |= cfc_check_trigger_is_unique(cmd->convert_src);
+       err |= cfc_check_trigger_is_unique(cmd->stop_src);
+
+       /* Step 2b : and mutually compatible */
 
        /*  make sure scan_begin_src and convert_src dont conflict */
        if (cmd->scan_begin_src == TRIG_FOLLOW && cmd->convert_src == TRIG_NOW)
-               err++;
+               err |= -EINVAL;
        if (cmd->scan_begin_src != TRIG_FOLLOW && cmd->convert_src != TRIG_NOW)
-               err++;
+               err |= -EINVAL;
 
        if (err)
                return 2;
index 7f0668f8ed83cddc7ccf2eacf7fbc41186527d25..3f87d7598e5bd29d419b47a5ff9e79fe26871150 100644 (file)
@@ -170,42 +170,24 @@ static int das16m1_cmd_test(struct comedi_device *dev,
        const struct das16m1_board *board = comedi_board(dev);
        unsigned int err = 0, tmp, i;
 
-       /* make sure triggers are valid */
-       tmp = cmd->start_src;
-       cmd->start_src &= TRIG_NOW | TRIG_EXT;
-       if (!cmd->start_src || tmp != cmd->start_src)
-               err++;
-
-       tmp = cmd->scan_begin_src;
-       cmd->scan_begin_src &= TRIG_FOLLOW;
-       if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src)
-               err++;
+       /* Step 1 : check if triggers are trivially valid */
 
-       tmp = cmd->convert_src;
-       cmd->convert_src &= TRIG_TIMER | TRIG_EXT;
-       if (!cmd->convert_src || tmp != cmd->convert_src)
-               err++;
-
-       tmp = cmd->scan_end_src;
-       cmd->scan_end_src &= TRIG_COUNT;
-       if (!cmd->scan_end_src || tmp != cmd->scan_end_src)
-               err++;
-
-       tmp = cmd->stop_src;
-       cmd->stop_src &= TRIG_COUNT | TRIG_NONE;
-       if (!cmd->stop_src || tmp != cmd->stop_src)
-               err++;
+       err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW | TRIG_EXT);
+       err |= cfc_check_trigger_src(&cmd->scan_begin_src, TRIG_FOLLOW);
+       err |= cfc_check_trigger_src(&cmd->convert_src, TRIG_TIMER | TRIG_EXT);
+       err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
+       err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE);
 
        if (err)
                return 1;
 
-       /* step 2: make sure trigger sources are unique and mutually compatible */
-       if (cmd->stop_src != TRIG_COUNT && cmd->stop_src != TRIG_NONE)
-               err++;
-       if (cmd->start_src != TRIG_NOW && cmd->start_src != TRIG_EXT)
-               err++;
-       if (cmd->convert_src != TRIG_TIMER && cmd->convert_src != TRIG_EXT)
-               err++;
+       /* Step 2a : make sure trigger sources are unique */
+
+       err |= cfc_check_trigger_is_unique(cmd->start_src);
+       err |= cfc_check_trigger_is_unique(cmd->convert_src);
+       err |= cfc_check_trigger_is_unique(cmd->stop_src);
+
+       /* Step 2b : and mutually compatible */
 
        if (err)
                return 2;
index 711d4e243b88cacefd196c2040ac0749349cc514..2555f3297d7b3021be330340e7cac9065f5179d6 100644 (file)
@@ -784,59 +784,35 @@ static int das1800_ai_do_cmdtest(struct comedi_device *dev,
                                 struct comedi_cmd *cmd)
 {
        int err = 0;
-       int tmp;
        unsigned int tmp_arg;
        int i;
        int unipolar;
 
-       /* step 1: make sure trigger sources are trivially valid */
+       /* Step 1 : check if triggers are trivially valid */
 
-       tmp = cmd->start_src;
-       cmd->start_src &= TRIG_NOW | TRIG_EXT;
-       if (!cmd->start_src || tmp != cmd->start_src)
-               err++;
-
-       tmp = cmd->scan_begin_src;
-       cmd->scan_begin_src &= TRIG_FOLLOW | TRIG_TIMER | TRIG_EXT;
-       if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src)
-               err++;
-
-       tmp = cmd->convert_src;
-       cmd->convert_src &= TRIG_TIMER | TRIG_EXT;
-       if (!cmd->convert_src || tmp != cmd->convert_src)
-               err++;
-
-       tmp = cmd->scan_end_src;
-       cmd->scan_end_src &= TRIG_COUNT;
-       if (!cmd->scan_end_src || tmp != cmd->scan_end_src)
-               err++;
-
-       tmp = cmd->stop_src;
-       cmd->stop_src &= TRIG_COUNT | TRIG_EXT | TRIG_NONE;
-       if (!cmd->stop_src || tmp != cmd->stop_src)
-               err++;
+       err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW | TRIG_EXT);
+       err |= cfc_check_trigger_src(&cmd->scan_begin_src,
+                                       TRIG_FOLLOW | TRIG_TIMER | TRIG_EXT);
+       err |= cfc_check_trigger_src(&cmd->convert_src, TRIG_TIMER | TRIG_EXT);
+       err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
+       err |= cfc_check_trigger_src(&cmd->stop_src,
+                                       TRIG_COUNT | TRIG_EXT | TRIG_NONE);
 
        if (err)
                return 1;
 
-       /* step 2: make sure trigger sources are unique and mutually compatible */
+       /* Step 2a : make sure trigger sources are unique */
+
+       err |= cfc_check_trigger_is_unique(cmd->start_src);
+       err |= cfc_check_trigger_is_unique(cmd->scan_begin_src);
+       err |= cfc_check_trigger_is_unique(cmd->convert_src);
+       err |= cfc_check_trigger_is_unique(cmd->stop_src);
+
+       /* Step 2b : and mutually compatible */
 
-       /*  uniqueness check */
-       if (cmd->start_src != TRIG_NOW && cmd->start_src != TRIG_EXT)
-               err++;
-       if (cmd->scan_begin_src != TRIG_FOLLOW &&
-           cmd->scan_begin_src != TRIG_TIMER &&
-           cmd->scan_begin_src != TRIG_EXT)
-               err++;
-       if (cmd->convert_src != TRIG_TIMER && cmd->convert_src != TRIG_EXT)
-               err++;
-       if (cmd->stop_src != TRIG_COUNT &&
-           cmd->stop_src != TRIG_NONE && cmd->stop_src != TRIG_EXT)
-               err++;
-       /* compatibility check */
        if (cmd->scan_begin_src != TRIG_FOLLOW &&
            cmd->convert_src != TRIG_TIMER)
-               err++;
+               err |= -EINVAL;
 
        if (err)
                return 2;
index 8e89101ad3a272d9d94a1e16def8fc0e779be884..215deac0a396a1c36c06815f6133511e2a03c33a 100644 (file)
@@ -609,44 +609,24 @@ static int das800_ai_do_cmdtest(struct comedi_device *dev,
        int gain, startChan;
        int i;
 
-       /* step 1: make sure trigger sources are trivially valid */
+       /* Step 1 : check if triggers are trivially valid */
 
-       tmp = cmd->start_src;
-       cmd->start_src &= TRIG_NOW | TRIG_EXT;
-       if (!cmd->start_src || tmp != cmd->start_src)
-               err++;
-
-       tmp = cmd->scan_begin_src;
-       cmd->scan_begin_src &= TRIG_FOLLOW;
-       if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src)
-               err++;
-
-       tmp = cmd->convert_src;
-       cmd->convert_src &= TRIG_TIMER | TRIG_EXT;
-       if (!cmd->convert_src || tmp != cmd->convert_src)
-               err++;
-
-       tmp = cmd->scan_end_src;
-       cmd->scan_end_src &= TRIG_COUNT;
-       if (!cmd->scan_end_src || tmp != cmd->scan_end_src)
-               err++;
-
-       tmp = cmd->stop_src;
-       cmd->stop_src &= TRIG_COUNT | TRIG_NONE;
-       if (!cmd->stop_src || tmp != cmd->stop_src)
-               err++;
+       err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW | TRIG_EXT);
+       err |= cfc_check_trigger_src(&cmd->scan_begin_src, TRIG_FOLLOW);
+       err |= cfc_check_trigger_src(&cmd->convert_src, TRIG_TIMER | TRIG_EXT);
+       err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
+       err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE);
 
        if (err)
                return 1;
 
-       /* step 2: make sure trigger sources are unique and mutually compatible */
+       /* Step 2a : make sure trigger sources are unique */
 
-       if (cmd->start_src != TRIG_NOW && cmd->start_src != TRIG_EXT)
-               err++;
-       if (cmd->convert_src != TRIG_TIMER && cmd->convert_src != TRIG_EXT)
-               err++;
-       if (cmd->stop_src != TRIG_COUNT && cmd->stop_src != TRIG_NONE)
-               err++;
+       err |= cfc_check_trigger_is_unique(cmd->start_src);
+       err |= cfc_check_trigger_is_unique(cmd->convert_src);
+       err |= cfc_check_trigger_is_unique(cmd->stop_src);
+
+       /* Step 2b : and mutually compatible */
 
        if (err)
                return 2;
index 0703ca5d8cb72cd9adce22d872c12dddfefcd9a2..4d5c33c4750f4c9936c4eeba726129072e0b78da 100644 (file)
@@ -41,6 +41,8 @@ Configuration Options:
 #include "../comedidev.h"
 #include <linux/ioport.h>
 
+#include "comedi_fc.h"
+
 /* Board register addresses */
 
 #define DMM32AT_MEMSIZE 0x10
@@ -258,47 +260,26 @@ static int dmm32at_ai_cmdtest(struct comedi_device *dev,
        int tmp;
        int start_chan, gain, i;
 
-       /* step 1: make sure trigger sources are trivially valid */
-
-       tmp = cmd->start_src;
-       cmd->start_src &= TRIG_NOW;
-       if (!cmd->start_src || tmp != cmd->start_src)
-               err++;
-
-       tmp = cmd->scan_begin_src;
-       cmd->scan_begin_src &= TRIG_TIMER /*| TRIG_EXT */ ;
-       if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src)
-               err++;
-
-       tmp = cmd->convert_src;
-       cmd->convert_src &= TRIG_TIMER /*| TRIG_EXT */ ;
-       if (!cmd->convert_src || tmp != cmd->convert_src)
-               err++;
-
-       tmp = cmd->scan_end_src;
-       cmd->scan_end_src &= TRIG_COUNT;
-       if (!cmd->scan_end_src || tmp != cmd->scan_end_src)
-               err++;
+       /* Step 1 : check if triggers are trivially valid */
 
-       tmp = cmd->stop_src;
-       cmd->stop_src &= TRIG_COUNT | TRIG_NONE;
-       if (!cmd->stop_src || tmp != cmd->stop_src)
-               err++;
+       err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW);
+       err |= cfc_check_trigger_src(&cmd->scan_begin_src,
+                                       TRIG_TIMER /*| TRIG_EXT */);
+       err |= cfc_check_trigger_src(&cmd->convert_src,
+                                       TRIG_TIMER /*| TRIG_EXT */);
+       err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
+       err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE);
 
        if (err)
                return 1;
 
-       /* step 2: make sure trigger sources are unique and mutually
-        * compatible */
+       /* Step 2a : make sure trigger sources are unique */
 
-       /* note that mutual compatibility is not an issue here */
-       if (cmd->scan_begin_src != TRIG_TIMER &&
-           cmd->scan_begin_src != TRIG_EXT)
-               err++;
-       if (cmd->convert_src != TRIG_TIMER && cmd->convert_src != TRIG_EXT)
-               err++;
-       if (cmd->stop_src != TRIG_COUNT && cmd->stop_src != TRIG_NONE)
-               err++;
+       err |= cfc_check_trigger_is_unique(cmd->scan_begin_src);
+       err |= cfc_check_trigger_is_unique(cmd->convert_src);
+       err |= cfc_check_trigger_is_unique(cmd->stop_src);
+
+       /* Step 2b : and mutually compatible */
 
        if (err)
                return 2;
index ce5d83768d4ec8fc46d15ddd5614084415e8b4ba..064a8f215e4df4ab15ed96e49d74fc5f596b72a5 100644 (file)
@@ -45,6 +45,8 @@ addition, the clock does not seem to be very accurate.
 #include <linux/ioport.h>
 #include <linux/delay.h>
 
+#include "comedi_fc.h"
+
 #define DT2814_SIZE 2
 
 #define DT2814_CSR 0
@@ -129,42 +131,22 @@ static int dt2814_ai_cmdtest(struct comedi_device *dev,
        int err = 0;
        int tmp;
 
-       /* step 1: make sure trigger sources are trivially valid */
-
-       tmp = cmd->start_src;
-       cmd->start_src &= TRIG_NOW;
-       if (!cmd->start_src || tmp != cmd->start_src)
-               err++;
-
-       tmp = cmd->scan_begin_src;
-       cmd->scan_begin_src &= TRIG_TIMER;
-       if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src)
-               err++;
-
-       tmp = cmd->convert_src;
-       cmd->convert_src &= TRIG_NOW;
-       if (!cmd->convert_src || tmp != cmd->convert_src)
-               err++;
-
-       tmp = cmd->scan_end_src;
-       cmd->scan_end_src &= TRIG_COUNT;
-       if (!cmd->scan_end_src || tmp != cmd->scan_end_src)
-               err++;
+       /* Step 1 : check if triggers are trivially valid */
 
-       tmp = cmd->stop_src;
-       cmd->stop_src &= TRIG_COUNT | TRIG_NONE;
-       if (!cmd->stop_src || tmp != cmd->stop_src)
-               err++;
+       err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW);
+       err |= cfc_check_trigger_src(&cmd->scan_begin_src, TRIG_TIMER);
+       err |= cfc_check_trigger_src(&cmd->convert_src, TRIG_NOW);
+       err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
+       err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE);
 
        if (err)
                return 1;
 
-       /* step 2: make sure trigger sources are
-        * unique and mutually compatible */
+       /* Step 2a : make sure trigger sources are unique */
 
-       /* note that mutual compatibility is not an issue here */
-       if (cmd->stop_src != TRIG_TIMER && cmd->stop_src != TRIG_EXT)
-               err++;
+       err |= cfc_check_trigger_is_unique(cmd->stop_src);
+
+       /* Step 2b : and mutually compatible */
 
        if (err)
                return 2;
index b7c43c84d949e981aa2e602225fde76fbf6d810c..78d340716d1e792ddb0a154c19f78eb4cade364e 100644 (file)
@@ -582,47 +582,24 @@ static int dt282x_ai_cmdtest(struct comedi_device *dev,
        int err = 0;
        int tmp;
 
-       /* step 1: make sure trigger sources are trivially valid */
+       /* Step 1 : check if triggers are trivially valid */
 
-       tmp = cmd->start_src;
-       cmd->start_src &= TRIG_NOW;
-       if (!cmd->start_src || tmp != cmd->start_src)
-               err++;
-
-       tmp = cmd->scan_begin_src;
-       cmd->scan_begin_src &= TRIG_FOLLOW | TRIG_EXT;
-       if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src)
-               err++;
-
-       tmp = cmd->convert_src;
-       cmd->convert_src &= TRIG_TIMER;
-       if (!cmd->convert_src || tmp != cmd->convert_src)
-               err++;
-
-       tmp = cmd->scan_end_src;
-       cmd->scan_end_src &= TRIG_COUNT;
-       if (!cmd->scan_end_src || tmp != cmd->scan_end_src)
-               err++;
-
-       tmp = cmd->stop_src;
-       cmd->stop_src &= TRIG_COUNT | TRIG_NONE;
-       if (!cmd->stop_src || tmp != cmd->stop_src)
-               err++;
+       err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW);
+       err |= cfc_check_trigger_src(&cmd->scan_begin_src,
+                                       TRIG_FOLLOW | TRIG_EXT);
+       err |= cfc_check_trigger_src(&cmd->convert_src, TRIG_TIMER);
+       err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
+       err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE);
 
        if (err)
                return 1;
 
-       /*
-        * step 2: make sure trigger sources are unique
-        * and mutually compatible
-        */
+       /* Step 2a : make sure trigger sources are unique */
 
-       /* note that mutual compatibility is not an issue here */
-       if (cmd->scan_begin_src != TRIG_FOLLOW &&
-           cmd->scan_begin_src != TRIG_EXT)
-               err++;
-       if (cmd->stop_src != TRIG_COUNT && cmd->stop_src != TRIG_NONE)
-               err++;
+       err |= cfc_check_trigger_is_unique(cmd->scan_begin_src);
+       err |= cfc_check_trigger_is_unique(cmd->stop_src);
+
+       /* Step 2b : and mutually compatible */
 
        if (err)
                return 2;
@@ -862,44 +839,22 @@ static int dt282x_ao_cmdtest(struct comedi_device *dev,
        int err = 0;
        int tmp;
 
-       /* step 1: make sure trigger sources are trivially valid */
+       /* Step 1 : check if triggers are trivially valid */
 
-       tmp = cmd->start_src;
-       cmd->start_src &= TRIG_INT;
-       if (!cmd->start_src || tmp != cmd->start_src)
-               err++;
-
-       tmp = cmd->scan_begin_src;
-       cmd->scan_begin_src &= TRIG_TIMER;
-       if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src)
-               err++;
-
-       tmp = cmd->convert_src;
-       cmd->convert_src &= TRIG_NOW;
-       if (!cmd->convert_src || tmp != cmd->convert_src)
-               err++;
-
-       tmp = cmd->scan_end_src;
-       cmd->scan_end_src &= TRIG_COUNT;
-       if (!cmd->scan_end_src || tmp != cmd->scan_end_src)
-               err++;
-
-       tmp = cmd->stop_src;
-       cmd->stop_src &= TRIG_NONE;
-       if (!cmd->stop_src || tmp != cmd->stop_src)
-               err++;
+       err |= cfc_check_trigger_src(&cmd->start_src, TRIG_INT);
+       err |= cfc_check_trigger_src(&cmd->scan_begin_src, TRIG_TIMER);
+       err |= cfc_check_trigger_src(&cmd->convert_src, TRIG_NOW);
+       err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
+       err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE);
 
        if (err)
                return 1;
 
-       /*
-        * step 2: make sure trigger sources are unique
-        * and mutually compatible
-        */
+       /* Step 2a : make sure trigger sources are unique */
 
-       /* note that mutual compatibility is not an issue here */
-       if (cmd->stop_src != TRIG_COUNT && cmd->stop_src != TRIG_NONE)
-               err++;
+       err |= cfc_check_trigger_is_unique(cmd->stop_src);
+
+       /* Step 2b : and mutually compatible */
 
        if (err)
                return 2;
index 3a940a2f000e4e62bb1e5e6dadd0a3da44606118..43d05ef971573c27a4e1fbdfb523ebd99827cfb6 100644 (file)
@@ -63,6 +63,8 @@ AO commands are not supported.
 #include "../comedidev.h"
 #include <linux/delay.h>
 
+#include "comedi_fc.h"
+
 #define PCI_VENDOR_ID_DT       0x1116
 
 static const struct comedi_lrange range_dt3000_ai = { 4, {
@@ -408,37 +410,19 @@ static int dt3k_ai_cmdtest(struct comedi_device *dev,
        int err = 0;
        int tmp;
 
-       /* step 1: make sure trigger sources are trivially valid */
-
-       tmp = cmd->start_src;
-       cmd->start_src &= TRIG_NOW;
-       if (!cmd->start_src || tmp != cmd->start_src)
-               err++;
-
-       tmp = cmd->scan_begin_src;
-       cmd->scan_begin_src &= TRIG_TIMER;
-       if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src)
-               err++;
-
-       tmp = cmd->convert_src;
-       cmd->convert_src &= TRIG_TIMER;
-       if (!cmd->convert_src || tmp != cmd->convert_src)
-               err++;
+       /* Step 1 : check if triggers are trivially valid */
 
-       tmp = cmd->scan_end_src;
-       cmd->scan_end_src &= TRIG_COUNT;
-       if (!cmd->scan_end_src || tmp != cmd->scan_end_src)
-               err++;
-
-       tmp = cmd->stop_src;
-       cmd->stop_src &= TRIG_COUNT;
-       if (!cmd->stop_src || tmp != cmd->stop_src)
-               err++;
+       err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW);
+       err |= cfc_check_trigger_src(&cmd->scan_begin_src, TRIG_TIMER);
+       err |= cfc_check_trigger_src(&cmd->convert_src, TRIG_TIMER);
+       err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
+       err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT);
 
        if (err)
                return 1;
 
-       /* step 2: make sure trigger sources are unique and mutually compatible */
+       /* Step 2a : make sure trigger sources are unique */
+       /* Step 2b : and mutually compatible */
 
        if (err)
                return 2;
index 5d3fa711a5156a04b64576334b9223f2bcb8f66d..abff6603952a78afbd386efccb1297770b44d1c8 100644 (file)
@@ -723,45 +723,24 @@ static int di_cmd_test(struct comedi_device *dev, struct comedi_subdevice *s,
                       struct comedi_cmd *cmd)
 {
        int err = 0;
-       int tmp;
        int i;
 
-       /* step 1: make sure trigger sources are trivially valid */
+       /* Step 1 : check if triggers are trivially valid */
 
-       tmp = cmd->start_src;
-       cmd->start_src &= TRIG_NOW;
-       if (!cmd->start_src || tmp != cmd->start_src)
-               err++;
-
-       tmp = cmd->scan_begin_src;
-       cmd->scan_begin_src &= TRIG_EXT;
-       if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src)
-               err++;
-
-       tmp = cmd->convert_src;
-       cmd->convert_src &= TRIG_NOW;
-       if (!cmd->convert_src || tmp != cmd->convert_src)
-               err++;
-
-       tmp = cmd->scan_end_src;
-       cmd->scan_end_src &= TRIG_COUNT;
-       if (!cmd->scan_end_src || tmp != cmd->scan_end_src)
-               err++;
-
-       tmp = cmd->stop_src;
-       cmd->stop_src &= TRIG_COUNT | TRIG_NONE;
-       if (!cmd->stop_src || tmp != cmd->stop_src)
-               err++;
+       err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW);
+       err |= cfc_check_trigger_src(&cmd->scan_begin_src, TRIG_EXT);
+       err |= cfc_check_trigger_src(&cmd->convert_src, TRIG_NOW);
+       err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
+       err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE);
 
        if (err)
                return 1;
 
-       /* step 2: make sure trigger sources are unique and mutually
-        * compatible */
+       /* Step 2a : make sure trigger sources are unique */
 
-       /*  uniqueness check */
-       if (cmd->stop_src != TRIG_COUNT && cmd->stop_src != TRIG_NONE)
-               err++;
+       err |= cfc_check_trigger_is_unique(cmd->stop_src);
+
+       /* Step 2b : and mutually compatible */
 
        if (err)
                return 2;
index d7c5146b41e33566e2151aaa871b9ee039f9490e..22db35d091f89e600d9853e96ada2799e3314fa1 100644 (file)
@@ -52,6 +52,7 @@ broken.
 #include <linux/list.h>
 #include <linux/spinlock.h>
 
+#include "comedi_fc.h"
 #include "8253.h"
 
 #if 0
@@ -895,18 +896,6 @@ static int me4000_ai_do_cmd(struct comedi_device *dev,
        return 0;
 }
 
-/*
- * me4000_ai_do_cmd_test():
- *
- * The demo cmd.c in ./comedilib/demo specifies 6 return values:
- * - success
- * - invalid source
- * - source conflict
- * - invalid argument
- * - argument conflict
- * - invalid chanlist
- * So I tried to adopt this scheme.
- */
 static int me4000_ai_do_cmd_test(struct comedi_device *dev,
                                 struct comedi_subdevice *s,
                                 struct comedi_cmd *cmd)
@@ -923,81 +912,29 @@ static int me4000_ai_do_cmd_test(struct comedi_device *dev,
        /* Round the timer arguments */
        ai_round_cmd_args(dev, s, cmd, &init_ticks, &scan_ticks, &chan_ticks);
 
-       /*
-        * Stage 1. Check if the trigger sources are generally valid.
-        */
-       switch (cmd->start_src) {
-       case TRIG_NOW:
-       case TRIG_EXT:
-               break;
-       case TRIG_ANY:
-               cmd->start_src &= TRIG_NOW | TRIG_EXT;
-               err++;
-               break;
-       default:
-               dev_err(dev->class_dev, "Invalid start source\n");
-               cmd->start_src = TRIG_NOW;
-               err++;
-       }
-       switch (cmd->scan_begin_src) {
-       case TRIG_FOLLOW:
-       case TRIG_TIMER:
-       case TRIG_EXT:
-               break;
-       case TRIG_ANY:
-               cmd->scan_begin_src &= TRIG_FOLLOW | TRIG_TIMER | TRIG_EXT;
-               err++;
-               break;
-       default:
-               dev_err(dev->class_dev, "Invalid scan begin source\n");
-               cmd->scan_begin_src = TRIG_FOLLOW;
-               err++;
-       }
-       switch (cmd->convert_src) {
-       case TRIG_TIMER:
-       case TRIG_EXT:
-               break;
-       case TRIG_ANY:
-               cmd->convert_src &= TRIG_TIMER | TRIG_EXT;
-               err++;
-               break;
-       default:
-               dev_err(dev->class_dev, "Invalid convert source\n");
-               cmd->convert_src = TRIG_TIMER;
-               err++;
-       }
-       switch (cmd->scan_end_src) {
-       case TRIG_NONE:
-       case TRIG_COUNT:
-               break;
-       case TRIG_ANY:
-               cmd->scan_end_src &= TRIG_NONE | TRIG_COUNT;
-               err++;
-               break;
-       default:
-               dev_err(dev->class_dev, "Invalid scan end source\n");
-               cmd->scan_end_src = TRIG_NONE;
-               err++;
-       }
-       switch (cmd->stop_src) {
-       case TRIG_NONE:
-       case TRIG_COUNT:
-               break;
-       case TRIG_ANY:
-               cmd->stop_src &= TRIG_NONE | TRIG_COUNT;
-               err++;
-               break;
-       default:
-               dev_err(dev->class_dev, "Invalid stop source\n");
-               cmd->stop_src = TRIG_NONE;
-               err++;
-       }
+       /* Step 1 : check if triggers are trivially valid */
+
+       err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW | TRIG_EXT);
+       err |= cfc_check_trigger_src(&cmd->scan_begin_src,
+                                       TRIG_FOLLOW | TRIG_TIMER | TRIG_EXT);
+       err |= cfc_check_trigger_src(&cmd->convert_src, TRIG_TIMER | TRIG_EXT);
+       err |= cfc_check_trigger_src(&cmd->scan_end_src,
+                                       TRIG_NONE | TRIG_COUNT);
+       err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_NONE | TRIG_COUNT);
+
        if (err)
                return 1;
 
-       /*
-        * Stage 2. Check for trigger source conflicts.
-        */
+       /* Step 2a : make sure trigger sources are unique */
+
+       err |= cfc_check_trigger_is_unique(cmd->start_src);
+       err |= cfc_check_trigger_is_unique(cmd->scan_begin_src);
+       err |= cfc_check_trigger_is_unique(cmd->convert_src);
+       err |= cfc_check_trigger_is_unique(cmd->scan_end_src);
+       err |= cfc_check_trigger_is_unique(cmd->stop_src);
+
+       /* Step 2b : and mutually compatible */
+
        if (cmd->start_src == TRIG_NOW &&
            cmd->scan_begin_src == TRIG_TIMER &&
            cmd->convert_src == TRIG_TIMER) {
@@ -1017,11 +954,7 @@ static int me4000_ai_do_cmd_test(struct comedi_device *dev,
                   cmd->scan_begin_src == TRIG_EXT &&
                   cmd->convert_src == TRIG_EXT) {
        } else {
-               dev_err(dev->class_dev, "Invalid start trigger combination\n");
-               cmd->start_src = TRIG_NOW;
-               cmd->scan_begin_src = TRIG_FOLLOW;
-               cmd->convert_src = TRIG_TIMER;
-               err++;
+               err |= -EINVAL;
        }
 
        if (cmd->stop_src == TRIG_NONE && cmd->scan_end_src == TRIG_NONE) {
@@ -1032,11 +965,9 @@ static int me4000_ai_do_cmd_test(struct comedi_device *dev,
        } else if (cmd->stop_src == TRIG_COUNT &&
                   cmd->scan_end_src == TRIG_COUNT) {
        } else {
-               dev_err(dev->class_dev, "Invalid stop trigger combination\n");
-               cmd->stop_src = TRIG_NONE;
-               cmd->scan_end_src = TRIG_NONE;
-               err++;
+               err |= -EINVAL;
        }
+
        if (err)
                return 2;
 
index 8125d50698993b0e46e00f0163a293a995e8d3ab..51295f32ee895a5123b1e4a04a1a8ff96e9f33b4 100644 (file)
@@ -44,6 +44,7 @@ Updated: Sat, 25 Jan 2003 13:24:40 -0800
 #include <linux/interrupt.h>
 #include "../comedidev.h"
 
+#include "comedi_fc.h"
 #include "mite.h"
 
 #define DRIVER_NAME "ni_6527"
@@ -224,40 +225,20 @@ static int ni6527_intr_cmdtest(struct comedi_device *dev,
                               struct comedi_cmd *cmd)
 {
        int err = 0;
-       int tmp;
 
-       /* step 1: make sure trigger sources are trivially valid */
+       /* Step 1 : check if triggers are trivially valid */
 
-       tmp = cmd->start_src;
-       cmd->start_src &= TRIG_NOW;
-       if (!cmd->start_src || tmp != cmd->start_src)
-               err++;
-
-       tmp = cmd->scan_begin_src;
-       cmd->scan_begin_src &= TRIG_OTHER;
-       if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src)
-               err++;
-
-       tmp = cmd->convert_src;
-       cmd->convert_src &= TRIG_FOLLOW;
-       if (!cmd->convert_src || tmp != cmd->convert_src)
-               err++;
-
-       tmp = cmd->scan_end_src;
-       cmd->scan_end_src &= TRIG_COUNT;
-       if (!cmd->scan_end_src || tmp != cmd->scan_end_src)
-               err++;
-
-       tmp = cmd->stop_src;
-       cmd->stop_src &= TRIG_COUNT;
-       if (!cmd->stop_src || tmp != cmd->stop_src)
-               err++;
+       err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW);
+       err |= cfc_check_trigger_src(&cmd->scan_begin_src, TRIG_OTHER);
+       err |= cfc_check_trigger_src(&cmd->convert_src, TRIG_FOLLOW);
+       err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
+       err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT);
 
        if (err)
                return 1;
 
-       /* step 2: make sure trigger sources are unique and */
-       /*         are mutually compatible */
+       /* Step 2a : make sure trigger sources are unique */
+       /* Step 2b : and mutually compatible */
 
        if (err)
                return 2;
index aab2b065cd5418b98f8fdbc15d9fa63dd27068ac..2a73ff57a2fb84fb7159e98e5e3d17c80be2a2ab 100644 (file)
@@ -55,6 +55,7 @@ except maybe the 6514.
 #include <linux/slab.h>
 #include "../comedidev.h"
 
+#include "comedi_fc.h"
 #include "mite.h"
 
 #define NI6514_DIO_SIZE 4096
@@ -486,40 +487,20 @@ static int ni_65xx_intr_cmdtest(struct comedi_device *dev,
                                struct comedi_cmd *cmd)
 {
        int err = 0;
-       int tmp;
 
-       /* step 1: make sure trigger sources are trivially valid */
+       /* Step 1 : check if triggers are trivially valid */
 
-       tmp = cmd->start_src;
-       cmd->start_src &= TRIG_NOW;
-       if (!cmd->start_src || tmp != cmd->start_src)
-               err++;
-
-       tmp = cmd->scan_begin_src;
-       cmd->scan_begin_src &= TRIG_OTHER;
-       if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src)
-               err++;
-
-       tmp = cmd->convert_src;
-       cmd->convert_src &= TRIG_FOLLOW;
-       if (!cmd->convert_src || tmp != cmd->convert_src)
-               err++;
-
-       tmp = cmd->scan_end_src;
-       cmd->scan_end_src &= TRIG_COUNT;
-       if (!cmd->scan_end_src || tmp != cmd->scan_end_src)
-               err++;
-
-       tmp = cmd->stop_src;
-       cmd->stop_src &= TRIG_COUNT;
-       if (!cmd->stop_src || tmp != cmd->stop_src)
-               err++;
+       err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW);
+       err |= cfc_check_trigger_src(&cmd->scan_begin_src, TRIG_OTHER);
+       err |= cfc_check_trigger_src(&cmd->convert_src, TRIG_FOLLOW);
+       err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
+       err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT);
 
        if (err)
                return 1;
 
-       /* step 2: make sure trigger sources are unique and mutually
-       compatible */
+       /* Step 2a : make sure trigger sources are unique */
+       /* Step 2b : and mutually compatible */
 
        if (err)
                return 2;
index 5895d4dce30f558f36e1fa42d6cb4094d67f8346..83950807b672a4bcbe08a3f0a957ad49a4e6352c 100644 (file)
@@ -321,45 +321,23 @@ static int a2150_ai_cmdtest(struct comedi_device *dev,
        int startChan;
        int i;
 
-       /* step 1: make sure trigger sources are trivially valid */
+       /* Step 1 : check if triggers are trivially valid */
 
-       tmp = cmd->start_src;
-       cmd->start_src &= TRIG_NOW | TRIG_EXT;
-       if (!cmd->start_src || tmp != cmd->start_src)
-               err++;
-
-       tmp = cmd->scan_begin_src;
-       cmd->scan_begin_src &= TRIG_TIMER;
-       if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src)
-               err++;
-
-       tmp = cmd->convert_src;
-       cmd->convert_src &= TRIG_NOW;
-       if (!cmd->convert_src || tmp != cmd->convert_src)
-               err++;
-
-       tmp = cmd->scan_end_src;
-       cmd->scan_end_src &= TRIG_COUNT;
-       if (!cmd->scan_end_src || tmp != cmd->scan_end_src)
-               err++;
-
-       tmp = cmd->stop_src;
-       cmd->stop_src &= TRIG_COUNT | TRIG_NONE;
-       if (!cmd->stop_src || tmp != cmd->stop_src)
-               err++;
+       err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW | TRIG_EXT);
+       err |= cfc_check_trigger_src(&cmd->scan_begin_src, TRIG_TIMER);
+       err |= cfc_check_trigger_src(&cmd->convert_src, TRIG_NOW);
+       err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
+       err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE);
 
        if (err)
                return 1;
 
-       /*
-        * step 2: make sure trigger sources are unique and mutually
-        * compatible
-        */
+       /* Step 2a : make sure trigger sources are unique */
 
-       if (cmd->start_src != TRIG_NOW && cmd->start_src != TRIG_EXT)
-               err++;
-       if (cmd->stop_src != TRIG_COUNT && cmd->stop_src != TRIG_NONE)
-               err++;
+       err |= cfc_check_trigger_is_unique(cmd->start_src);
+       err |= cfc_check_trigger_is_unique(cmd->stop_src);
+
+       /* Step 2b : and mutually compatible */
 
        if (err)
                return 2;
index 4108cbfaf29bee128c61b27ace17cf4ab083e9c6..e91a620f9db314d3864170c8033351e958b868d1 100644 (file)
@@ -40,6 +40,7 @@ Devices: [National Instruments] AT-MIO-16 (atmio16), AT-MIO-16D (atmio16d)
 
 #include <linux/ioport.h>
 
+#include "comedi_fc.h"
 #include "8255.h"
 
 /* Configuration and Status Registers */
@@ -246,45 +247,26 @@ static int atmio16d_ai_cmdtest(struct comedi_device *dev,
                               struct comedi_subdevice *s,
                               struct comedi_cmd *cmd)
 {
-       int err = 0, tmp;
+       int err = 0;
 
-       /* make sure triggers are valid */
-       tmp = cmd->start_src;
-       cmd->start_src &= TRIG_NOW;
-       if (!cmd->start_src || tmp != cmd->start_src)
-               err++;
-
-       tmp = cmd->scan_begin_src;
-       cmd->scan_begin_src &= TRIG_FOLLOW | TRIG_TIMER;
-       if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src)
-               err++;
-
-       tmp = cmd->convert_src;
-       cmd->convert_src &= TRIG_TIMER;
-       if (!cmd->convert_src || tmp != cmd->convert_src)
-               err++;
-
-       tmp = cmd->scan_end_src;
-       cmd->scan_end_src &= TRIG_COUNT;
-       if (!cmd->scan_end_src || tmp != cmd->scan_end_src)
-               err++;
+       /* Step 1 : check if triggers are trivially valid */
 
-       tmp = cmd->stop_src;
-       cmd->stop_src &= TRIG_COUNT | TRIG_NONE;
-       if (!cmd->stop_src || tmp != cmd->stop_src)
-               err++;
+       err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW);
+       err |= cfc_check_trigger_src(&cmd->scan_begin_src,
+                                       TRIG_FOLLOW | TRIG_TIMER);
+       err |= cfc_check_trigger_src(&cmd->convert_src, TRIG_TIMER);
+       err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
+       err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE);
 
        if (err)
                return 1;
 
-       /* step 2: make sure trigger sources are unique & mutually compatible */
-       /* note that mutual compatibility is not an issue here */
-       if (cmd->scan_begin_src != TRIG_FOLLOW &&
-           cmd->scan_begin_src != TRIG_EXT &&
-           cmd->scan_begin_src != TRIG_TIMER)
-               err++;
-       if (cmd->stop_src != TRIG_COUNT && cmd->stop_src != TRIG_NONE)
-               err++;
+       /* Step 2a : make sure trigger sources are unique */
+
+       err |= cfc_check_trigger_is_unique(cmd->scan_begin_src);
+       err |= cfc_check_trigger_is_unique(cmd->stop_src);
+
+       /* Step 2b : and mutually compatible */
 
        if (err)
                return 2;
index d534e63d886e03e715be49d8265e3df48f2cbc53..28b91a6c378908ba2f30b01b88a11d819b3dd9f7 100644 (file)
@@ -979,55 +979,33 @@ static int labpc_ai_cmdtest(struct comedi_device *dev,
 {
        int err = 0;
        int tmp, tmp2;
-       int stop_mask;
+       unsigned int stop_mask;
        enum scan_mode mode;
 
-       /* step 1: make sure trigger sources are trivially valid */
+       /* Step 1 : check if triggers are trivially valid */
 
-       tmp = cmd->start_src;
-       cmd->start_src &= TRIG_NOW | TRIG_EXT;
-       if (!cmd->start_src || tmp != cmd->start_src)
-               err++;
-
-       tmp = cmd->scan_begin_src;
-       cmd->scan_begin_src &= TRIG_TIMER | TRIG_FOLLOW | TRIG_EXT;
-       if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src)
-               err++;
-
-       tmp = cmd->convert_src;
-       cmd->convert_src &= TRIG_TIMER | TRIG_EXT;
-       if (!cmd->convert_src || tmp != cmd->convert_src)
-               err++;
-
-       tmp = cmd->scan_end_src;
-       cmd->scan_end_src &= TRIG_COUNT;
-       if (!cmd->scan_end_src || tmp != cmd->scan_end_src)
-               err++;
+       err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW | TRIG_EXT);
+       err |= cfc_check_trigger_src(&cmd->scan_begin_src,
+                                       TRIG_TIMER | TRIG_FOLLOW | TRIG_EXT);
+       err |= cfc_check_trigger_src(&cmd->convert_src, TRIG_TIMER | TRIG_EXT);
+       err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
 
-       tmp = cmd->stop_src;
        stop_mask = TRIG_COUNT | TRIG_NONE;
        if (thisboard->register_layout == labpc_1200_layout)
                stop_mask |= TRIG_EXT;
-       cmd->stop_src &= stop_mask;
-       if (!cmd->stop_src || tmp != cmd->stop_src)
-               err++;
+       err |= cfc_check_trigger_src(&cmd->stop_src, stop_mask);
 
        if (err)
                return 1;
 
-       /* step 2: make sure trigger sources are unique and mutually compatible */
+       /* Step 2a : make sure trigger sources are unique */
 
-       if (cmd->start_src != TRIG_NOW && cmd->start_src != TRIG_EXT)
-               err++;
-       if (cmd->scan_begin_src != TRIG_TIMER &&
-           cmd->scan_begin_src != TRIG_FOLLOW &&
-           cmd->scan_begin_src != TRIG_EXT)
-               err++;
-       if (cmd->convert_src != TRIG_TIMER && cmd->convert_src != TRIG_EXT)
-               err++;
-       if (cmd->stop_src != TRIG_COUNT &&
-           cmd->stop_src != TRIG_EXT && cmd->stop_src != TRIG_NONE)
-               err++;
+       err |= cfc_check_trigger_is_unique(cmd->start_src);
+       err |= cfc_check_trigger_is_unique(cmd->scan_begin_src);
+       err |= cfc_check_trigger_is_unique(cmd->convert_src);
+       err |= cfc_check_trigger_is_unique(cmd->stop_src);
+
+       /* Step 2b : and mutually compatible */
 
        /* can't have external stop and start triggers at once */
        if (cmd->start_src == TRIG_EXT && cmd->stop_src == TRIG_EXT)
index 4bbb9798af7e3e20877719c99699120124d0c7d1..3e5fdae93163b16c525cc2a591fc0faabd3e96ad 100644 (file)
@@ -2164,61 +2164,38 @@ static int ni_ai_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s,
 {
        int err = 0;
        int tmp;
-       int sources;
+       unsigned int sources;
 
-       /* step 1: make sure trigger sources are trivially valid */
+       /* Step 1 : check if triggers are trivially valid */
 
-       if ((cmd->flags & CMDF_WRITE)) {
+       if ((cmd->flags & CMDF_WRITE))
                cmd->flags &= ~CMDF_WRITE;
-       }
 
-       tmp = cmd->start_src;
-       cmd->start_src &= TRIG_NOW | TRIG_INT | TRIG_EXT;
-       if (!cmd->start_src || tmp != cmd->start_src)
-               err++;
+       err |= cfc_check_trigger_src(&cmd->start_src,
+                                       TRIG_NOW | TRIG_INT | TRIG_EXT);
+       err |= cfc_check_trigger_src(&cmd->scan_begin_src,
+                                       TRIG_TIMER | TRIG_EXT);
 
-       tmp = cmd->scan_begin_src;
-       cmd->scan_begin_src &= TRIG_TIMER | TRIG_EXT;
-       if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src)
-               err++;
-
-       tmp = cmd->convert_src;
        sources = TRIG_TIMER | TRIG_EXT;
-       if ((boardtype.reg_type == ni_reg_611x)
-           || (boardtype.reg_type == ni_reg_6143))
+       if (boardtype.reg_type == ni_reg_611x ||
+           boardtype.reg_type == ni_reg_6143)
                sources |= TRIG_NOW;
-       cmd->convert_src &= sources;
-       if (!cmd->convert_src || tmp != cmd->convert_src)
-               err++;
+       err |= cfc_check_trigger_src(&cmd->convert_src, sources);
 
-       tmp = cmd->scan_end_src;
-       cmd->scan_end_src &= TRIG_COUNT;
-       if (!cmd->scan_end_src || tmp != cmd->scan_end_src)
-               err++;
-
-       tmp = cmd->stop_src;
-       cmd->stop_src &= TRIG_COUNT | TRIG_NONE;
-       if (!cmd->stop_src || tmp != cmd->stop_src)
-               err++;
+       err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
+       err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE);
 
        if (err)
                return 1;
 
-       /* step 2: make sure trigger sources are unique and mutually compatible */
+       /* Step 2a : make sure trigger sources are unique */
 
-       /* note that mutual compatibility is not an issue here */
-       if (cmd->start_src != TRIG_NOW &&
-           cmd->start_src != TRIG_INT && cmd->start_src != TRIG_EXT)
-               err++;
-       if (cmd->scan_begin_src != TRIG_TIMER &&
-           cmd->scan_begin_src != TRIG_EXT &&
-           cmd->scan_begin_src != TRIG_OTHER)
-               err++;
-       if (cmd->convert_src != TRIG_TIMER &&
-           cmd->convert_src != TRIG_EXT && cmd->convert_src != TRIG_NOW)
-               err++;
-       if (cmd->stop_src != TRIG_COUNT && cmd->stop_src != TRIG_NONE)
-               err++;
+       err |= cfc_check_trigger_is_unique(cmd->start_src);
+       err |= cfc_check_trigger_is_unique(cmd->scan_begin_src);
+       err |= cfc_check_trigger_is_unique(cmd->convert_src);
+       err |= cfc_check_trigger_is_unique(cmd->stop_src);
+
+       /* Step 2b : and mutually compatible */
 
        if (err)
                return 2;
@@ -3356,44 +3333,28 @@ static int ni_ao_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s,
        int err = 0;
        int tmp;
 
-       /* step 1: make sure trigger sources are trivially valid */
+       /* Step 1 : check if triggers are trivially valid */
 
-       if ((cmd->flags & CMDF_WRITE) == 0) {
+       if ((cmd->flags & CMDF_WRITE) == 0)
                cmd->flags |= CMDF_WRITE;
-       }
-
-       tmp = cmd->start_src;
-       cmd->start_src &= TRIG_INT | TRIG_EXT;
-       if (!cmd->start_src || tmp != cmd->start_src)
-               err++;
 
-       tmp = cmd->scan_begin_src;
-       cmd->scan_begin_src &= TRIG_TIMER | TRIG_EXT;
-       if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src)
-               err++;
-
-       tmp = cmd->convert_src;
-       cmd->convert_src &= TRIG_NOW;
-       if (!cmd->convert_src || tmp != cmd->convert_src)
-               err++;
-
-       tmp = cmd->scan_end_src;
-       cmd->scan_end_src &= TRIG_COUNT;
-       if (!cmd->scan_end_src || tmp != cmd->scan_end_src)
-               err++;
-
-       tmp = cmd->stop_src;
-       cmd->stop_src &= TRIG_COUNT | TRIG_NONE;
-       if (!cmd->stop_src || tmp != cmd->stop_src)
-               err++;
+       err |= cfc_check_trigger_src(&cmd->start_src, TRIG_INT | TRIG_EXT);
+       err |= cfc_check_trigger_src(&cmd->scan_begin_src,
+                                       TRIG_TIMER | TRIG_EXT);
+       err |= cfc_check_trigger_src(&cmd->convert_src, TRIG_NOW);
+       err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
+       err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE);
 
        if (err)
                return 1;
 
-       /* step 2: make sure trigger sources are unique and mutually compatible */
+       /* Step 2a : make sure trigger sources are unique */
 
-       if (cmd->stop_src != TRIG_COUNT && cmd->stop_src != TRIG_NONE)
-               err++;
+       err |= cfc_check_trigger_is_unique(cmd->start_src);
+       err |= cfc_check_trigger_is_unique(cmd->scan_begin_src);
+       err |= cfc_check_trigger_is_unique(cmd->stop_src);
+
+       /* Step 2b : and mutually compatible */
 
        if (err)
                return 2;
@@ -3643,51 +3604,21 @@ static int ni_cdio_cmdtest(struct comedi_device *dev,
 {
        int err = 0;
        int tmp;
-       int sources;
        unsigned i;
 
-       /* step 1: make sure trigger sources are trivially valid */
+       /* Step 1 : check if triggers are trivially valid */
 
-       tmp = cmd->start_src;
-       sources = TRIG_INT;
-       cmd->start_src &= sources;
-       if (!cmd->start_src || tmp != cmd->start_src)
-               err++;
-
-       tmp = cmd->scan_begin_src;
-       cmd->scan_begin_src &= TRIG_EXT;
-       if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src)
-               err++;
-
-       tmp = cmd->convert_src;
-       cmd->convert_src &= TRIG_NOW;
-       if (!cmd->convert_src || tmp != cmd->convert_src)
-               err++;
-
-       tmp = cmd->scan_end_src;
-       cmd->scan_end_src &= TRIG_COUNT;
-       if (!cmd->scan_end_src || tmp != cmd->scan_end_src)
-               err++;
-
-       tmp = cmd->stop_src;
-       cmd->stop_src &= TRIG_NONE;
-       if (!cmd->stop_src || tmp != cmd->stop_src)
-               err++;
+       err |= cfc_check_trigger_src(&cmd->start_src, TRIG_INT);
+       err |= cfc_check_trigger_src(&cmd->scan_begin_src, TRIG_EXT);
+       err |= cfc_check_trigger_src(&cmd->convert_src, TRIG_NOW);
+       err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
+       err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_NONE);
 
        if (err)
                return 1;
 
-       /* step 2: make sure trigger sources are unique... */
-
-       if (cmd->start_src != TRIG_INT)
-               err++;
-       if (cmd->scan_begin_src != TRIG_EXT)
-               err++;
-       if (cmd->convert_src != TRIG_NOW)
-               err++;
-       if (cmd->stop_src != TRIG_NONE)
-               err++;
-       /* ... and mutually compatible */
+       /* Step 2a : make sure trigger sources are unique */
+       /* Step 2b : and mutually compatible */
 
        if (err)
                return 2;
index 6a70e266b1a30f04c9600e35477f367cdd14e319..bc9313ec985c9c8d90bec2bf5ad74387167f730a 100644 (file)
@@ -60,6 +60,7 @@ comedi_nonfree_firmware tarball available from http://www.comedi.org
 #include <linux/firmware.h>
 #include "../comedidev.h"
 
+#include "comedi_fc.h"
 #include "mite.h"
 
 #undef DPRINTK
@@ -683,45 +684,25 @@ static int ni_pcidio_cmdtest(struct comedi_device *dev,
        int err = 0;
        int tmp;
 
-       /* step 1: make sure trigger sources are trivially valid */
+       /* Step 1 : check if triggers are trivially valid */
 
-       tmp = cmd->start_src;
-       cmd->start_src &= TRIG_NOW | TRIG_INT;
-       if (!cmd->start_src || tmp != cmd->start_src)
-               err++;
-
-       tmp = cmd->scan_begin_src;
-       cmd->scan_begin_src &= TRIG_TIMER | TRIG_EXT;
-       if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src)
-               err++;
-
-       tmp = cmd->convert_src;
-       cmd->convert_src &= TRIG_NOW;
-       if (!cmd->convert_src || tmp != cmd->convert_src)
-               err++;
-
-       tmp = cmd->scan_end_src;
-       cmd->scan_end_src &= TRIG_COUNT;
-       if (!cmd->scan_end_src || tmp != cmd->scan_end_src)
-               err++;
-
-       tmp = cmd->stop_src;
-       cmd->stop_src &= TRIG_COUNT | TRIG_NONE;
-       if (!cmd->stop_src || tmp != cmd->stop_src)
-               err++;
+       err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW | TRIG_INT);
+       err |= cfc_check_trigger_src(&cmd->scan_begin_src,
+                                       TRIG_TIMER | TRIG_EXT);
+       err |= cfc_check_trigger_src(&cmd->convert_src, TRIG_NOW);
+       err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
+       err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE);
 
        if (err)
                return 1;
 
-       /* step 2: make sure trigger sources are unique and mutually
-       compatible */
+       /* Step 2a : make sure trigger sources are unique */
 
-       /* note that mutual compatibility is not an issue here */
-       if (cmd->start_src != TRIG_NOW && cmd->start_src != TRIG_INT)
-               err++;
-       if (cmd->scan_begin_src != TRIG_TIMER &&
-           cmd->scan_begin_src != TRIG_EXT)
-               err++;
+       err |= cfc_check_trigger_is_unique(cmd->start_src);
+       err |= cfc_check_trigger_is_unique(cmd->scan_begin_src);
+       err |= cfc_check_trigger_is_unique(cmd->stop_src);
+
+       /* Step 2b : and mutually compatible */
 
        if (err)
                return 2;
index a9611587460aa3b36860e90c9df740eb065a468b..8ee93d359bed875c475ea34eae7f12531824cd19 100644 (file)
@@ -48,6 +48,7 @@ TODO:
        Support use of both banks X and Y
 */
 
+#include "comedi_fc.h"
 #include "ni_tio_internal.h"
 #include "mite.h"
 
@@ -237,61 +238,35 @@ EXPORT_SYMBOL_GPL(ni_tio_cmd);
 int ni_tio_cmdtest(struct ni_gpct *counter, struct comedi_cmd *cmd)
 {
        int err = 0;
-       int tmp;
-       int sources;
+       unsigned int sources;
 
-       /* step 1: make sure trigger sources are trivially valid */
+       /* Step 1 : check if triggers are trivially valid */
 
-       tmp = cmd->start_src;
        sources = TRIG_NOW | TRIG_INT | TRIG_OTHER;
        if (ni_tio_counting_mode_registers_present(counter->counter_dev))
                sources |= TRIG_EXT;
-       cmd->start_src &= sources;
-       if (!cmd->start_src || tmp != cmd->start_src)
-               err++;
-
-       tmp = cmd->scan_begin_src;
-       cmd->scan_begin_src &= TRIG_FOLLOW | TRIG_EXT | TRIG_OTHER;
-       if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src)
-               err++;
-
-       tmp = cmd->convert_src;
-       sources = TRIG_NOW | TRIG_EXT | TRIG_OTHER;
-       cmd->convert_src &= sources;
-       if (!cmd->convert_src || tmp != cmd->convert_src)
-               err++;
-
-       tmp = cmd->scan_end_src;
-       cmd->scan_end_src &= TRIG_COUNT;
-       if (!cmd->scan_end_src || tmp != cmd->scan_end_src)
-               err++;
+       err |= cfc_check_trigger_src(&cmd->start_src, sources);
 
-       tmp = cmd->stop_src;
-       cmd->stop_src &= TRIG_NONE;
-       if (!cmd->stop_src || tmp != cmd->stop_src)
-               err++;
+       err |= cfc_check_trigger_src(&cmd->scan_begin_src,
+                                       TRIG_FOLLOW | TRIG_EXT | TRIG_OTHER);
+       err |= cfc_check_trigger_src(&cmd->convert_src,
+                                       TRIG_NOW | TRIG_EXT | TRIG_OTHER);
+       err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
+       err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_NONE);
 
        if (err)
                return 1;
 
-       /* step 2: make sure trigger sources are unique... */
+       /* Step 2a : make sure trigger sources are unique */
+
+       err |= cfc_check_trigger_is_unique(cmd->start_src);
+       err |= cfc_check_trigger_is_unique(cmd->scan_begin_src);
+       err |= cfc_check_trigger_is_unique(cmd->convert_src);
+
+       /* Step 2b : and mutually compatible */
 
-       if (cmd->start_src != TRIG_NOW &&
-           cmd->start_src != TRIG_INT &&
-           cmd->start_src != TRIG_EXT && cmd->start_src != TRIG_OTHER)
-               err++;
-       if (cmd->scan_begin_src != TRIG_FOLLOW &&
-           cmd->scan_begin_src != TRIG_EXT &&
-           cmd->scan_begin_src != TRIG_OTHER)
-               err++;
-       if (cmd->convert_src != TRIG_OTHER &&
-           cmd->convert_src != TRIG_EXT && cmd->convert_src != TRIG_NOW)
-               err++;
-       if (cmd->stop_src != TRIG_NONE)
-               err++;
-       /* ... and mutually compatible */
        if (cmd->convert_src != TRIG_NOW && cmd->scan_begin_src != TRIG_FOLLOW)
-               err++;
+               err |= -EINVAL;
 
        if (err)
                return 2;
index ef77b15f19f7979d1072f82df114278fff69d6b6..89305a14eb5c0cbb9fc06519443e2218b162f8eb 100644 (file)
@@ -64,6 +64,7 @@ supported.
 #include <linux/ioport.h>
 #include <linux/delay.h>
 
+#include "comedi_fc.h"
 #include "8253.h"
 
 #define PCL711_SIZE 16
@@ -266,42 +267,24 @@ static int pcl711_ai_cmdtest(struct comedi_device *dev,
        int tmp;
        int err = 0;
 
-       /* step 1 */
-       tmp = cmd->start_src;
-       cmd->start_src &= TRIG_NOW;
-       if (!cmd->start_src || tmp != cmd->start_src)
-               err++;
-
-       tmp = cmd->scan_begin_src;
-       cmd->scan_begin_src &= TRIG_TIMER | TRIG_EXT;
-       if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src)
-               err++;
+       /* Step 1 : check if triggers are trivially valid */
 
-       tmp = cmd->convert_src;
-       cmd->convert_src &= TRIG_NOW;
-       if (!cmd->convert_src || tmp != cmd->convert_src)
-               err++;
-
-       tmp = cmd->scan_end_src;
-       cmd->scan_end_src &= TRIG_COUNT;
-       if (!cmd->scan_end_src || tmp != cmd->scan_end_src)
-               err++;
-
-       tmp = cmd->stop_src;
-       cmd->stop_src &= TRIG_COUNT | TRIG_NONE;
-       if (!cmd->stop_src || tmp != cmd->stop_src)
-               err++;
+       err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW);
+       err |= cfc_check_trigger_src(&cmd->scan_begin_src,
+                                       TRIG_TIMER | TRIG_EXT);
+       err |= cfc_check_trigger_src(&cmd->convert_src, TRIG_NOW);
+       err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
+       err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE);
 
        if (err)
                return 1;
 
-       /* step 2 */
+       /* Step 2a : make sure trigger sources are unique */
 
-       if (cmd->scan_begin_src != TRIG_TIMER &&
-           cmd->scan_begin_src != TRIG_EXT)
-               err++;
-       if (cmd->stop_src != TRIG_COUNT && cmd->stop_src != TRIG_NONE)
-               err++;
+       err |= cfc_check_trigger_is_unique(cmd->scan_begin_src);
+       err |= cfc_check_trigger_is_unique(cmd->stop_src);
+
+       /* Step 2b : and mutually compatible */
 
        if (err)
                return 2;
index d196343adb08b53fd96a0b0d7b24ffc21aefcf47..3cf55ff9308383f07c8032b67222c05b4acc934f 100644 (file)
 #include <linux/io.h>
 #include <asm/dma.h>
 
+#include "comedi_fc.h"
 #include "8253.h"
 
 /* hardware types of the cards */
@@ -533,49 +534,31 @@ static int pcl812_ai_cmdtest(struct comedi_device *dev,
 {
        const struct pcl812_board *board = comedi_board(dev);
        int err = 0;
+       unsigned int flags;
        int tmp, divisor1, divisor2;
 
-       /* step 1: make sure trigger sources are trivially valid */
+       /* Step 1 : check if triggers are trivially valid */
 
-       tmp = cmd->start_src;
-       cmd->start_src &= TRIG_NOW;
-       if (!cmd->start_src || tmp != cmd->start_src)
-               err++;
-
-       tmp = cmd->scan_begin_src;
-       cmd->scan_begin_src &= TRIG_FOLLOW;
-       if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src)
-               err++;
+       err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW);
+       err |= cfc_check_trigger_src(&cmd->scan_begin_src, TRIG_FOLLOW);
 
-       tmp = cmd->convert_src;
        if (devpriv->use_ext_trg)
-               cmd->convert_src &= TRIG_EXT;
+               flags = TRIG_EXT;
        else
-               cmd->convert_src &= TRIG_TIMER;
-
-       if (!cmd->convert_src || tmp != cmd->convert_src)
-               err++;
+               flags = TRIG_TIMER;
+       err |= cfc_check_trigger_src(&cmd->convert_src, flags);
 
-       tmp = cmd->scan_end_src;
-       cmd->scan_end_src &= TRIG_COUNT;
-       if (!cmd->scan_end_src || tmp != cmd->scan_end_src)
-               err++;
-
-       tmp = cmd->stop_src;
-       cmd->stop_src &= TRIG_COUNT | TRIG_NONE;
-       if (!cmd->stop_src || tmp != cmd->stop_src)
-               err++;
+       err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
+       err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE);
 
        if (err)
                return 1;
 
-       /*
-        * step 2: make sure trigger sources are
-        * unique and mutually compatible
-        */
+       /* Step 2a : make sure trigger sources are unique */
 
-       if (cmd->stop_src != TRIG_NONE && cmd->stop_src != TRIG_COUNT)
-               err++;
+       err |= cfc_check_trigger_is_unique(cmd->stop_src);
+
+       /* Step 2b : and mutually compatible */
 
        if (err)
                return 2;
index f65fd66cc8a24ff520afb98f2705d7d7c049b56d..0822de058e4d7fdb819f88ae91c08d14bfb07ead 100644 (file)
@@ -41,6 +41,7 @@ Configuration Options:
 #include <linux/io.h>
 #include <asm/dma.h>
 
+#include "comedi_fc.h"
 #include "8253.h"
 
 #define DEBUG(x) x
@@ -458,48 +459,23 @@ static int pcl816_ai_cmdtest(struct comedi_device *dev,
              pcl816_cmdtest_out(-1, cmd);
             );
 
-       /* step 1: make sure trigger sources are trivially valid */
-       tmp = cmd->start_src;
-       cmd->start_src &= TRIG_NOW;
-       if (!cmd->start_src || tmp != cmd->start_src)
-               err++;
-
-       tmp = cmd->scan_begin_src;
-       cmd->scan_begin_src &= TRIG_FOLLOW;
-       if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src)
-               err++;
-
-       tmp = cmd->convert_src;
-       cmd->convert_src &= TRIG_EXT | TRIG_TIMER;
-       if (!cmd->convert_src || tmp != cmd->convert_src)
-               err++;
-
-       tmp = cmd->scan_end_src;
-       cmd->scan_end_src &= TRIG_COUNT;
-       if (!cmd->scan_end_src || tmp != cmd->scan_end_src)
-               err++;
+       /* Step 1 : check if triggers are trivially valid */
 
-       tmp = cmd->stop_src;
-       cmd->stop_src &= TRIG_COUNT | TRIG_NONE;
-       if (!cmd->stop_src || tmp != cmd->stop_src)
-               err++;
+       err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW);
+       err |= cfc_check_trigger_src(&cmd->scan_begin_src, TRIG_FOLLOW);
+       err |= cfc_check_trigger_src(&cmd->convert_src, TRIG_EXT | TRIG_TIMER);
+       err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
+       err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE);
 
        if (err)
                return 1;
 
+       /* Step 2a : make sure trigger sources are unique */
 
-       /*
-        * step 2: make sure trigger sources
-        * are unique and mutually compatible
-        */
-
-       if (cmd->convert_src != TRIG_EXT && cmd->convert_src != TRIG_TIMER) {
-               cmd->convert_src = TRIG_TIMER;
-               err++;
-       }
+       err |= cfc_check_trigger_is_unique(cmd->convert_src);
+       err |= cfc_check_trigger_is_unique(cmd->stop_src);
 
-       if (cmd->stop_src != TRIG_NONE && cmd->stop_src != TRIG_COUNT)
-               err++;
+       /* Step 2b : and mutually compatible */
 
        if (err)
                return 2;
index 023a27df0d290c3ba59fce1775f86dad2297cbcc..d4b0859d81f216d6772a0fa02a89ac8aca7b5e76 100644 (file)
@@ -107,6 +107,7 @@ A word or two about DMA. Driver support DMA operations at two ways:
 #include <linux/io.h>
 #include <asm/dma.h>
 
+#include "comedi_fc.h"
 #include "8253.h"
 
 /* #define PCL818_MODE13_AO 1 */
@@ -1261,43 +1262,23 @@ static int ai_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s,
        int err = 0;
        int tmp, divisor1 = 0, divisor2 = 0;
 
-       /* step 1: make sure trigger sources are trivially valid */
+       /* Step 1 : check if triggers are trivially valid */
 
-       tmp = cmd->start_src;
-       cmd->start_src &= TRIG_NOW;
-       if (!cmd->start_src || tmp != cmd->start_src)
-               err++;
-
-       tmp = cmd->scan_begin_src;
-       cmd->scan_begin_src &= TRIG_FOLLOW;
-       if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src)
-               err++;
-
-       tmp = cmd->convert_src;
-       cmd->convert_src &= TRIG_TIMER | TRIG_EXT;
-       if (!cmd->convert_src || tmp != cmd->convert_src)
-               err++;
-
-       tmp = cmd->scan_end_src;
-       cmd->scan_end_src &= TRIG_COUNT;
-       if (!cmd->scan_end_src || tmp != cmd->scan_end_src)
-               err++;
-
-       tmp = cmd->stop_src;
-       cmd->stop_src &= TRIG_COUNT | TRIG_NONE;
-       if (!cmd->stop_src || tmp != cmd->stop_src)
-               err++;
+       err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW);
+       err |= cfc_check_trigger_src(&cmd->scan_begin_src, TRIG_FOLLOW);
+       err |= cfc_check_trigger_src(&cmd->convert_src, TRIG_TIMER | TRIG_EXT);
+       err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
+       err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE);
 
        if (err)
                return 1;
 
-       /* step 2: make sure trigger sources are unique and mutually compatible */
+       /* Step 2a : make sure trigger sources are unique */
 
-       if (cmd->convert_src != TRIG_TIMER && cmd->convert_src != TRIG_EXT)
-               err++;
+       err |= cfc_check_trigger_is_unique(cmd->convert_src);
+       err |= cfc_check_trigger_is_unique(cmd->stop_src);
 
-       if (cmd->stop_src != TRIG_NONE && cmd->stop_src != TRIG_COUNT)
-               err++;
+       /* Step 2b : and mutually compatible */
 
        if (err)
                return 2;
index 474af7bc6c8bfe6f593533b33ca202bada8a7d50..85ee05ece9c8cc8e7605910e80e695929874bb9b 100644 (file)
@@ -1,60 +1,30 @@
 #include "../comedidev.h"
+
+#include "comedi_fc.h"
 #include "pcm_common.h"
 
-/*
- * 'do_cmdtest' function for an 'INTERRUPT' subdevice.  This is for
- * the PCM drivers.
- */
 int comedi_pcm_cmdtest(struct comedi_device *dev,
                       struct comedi_subdevice *s, struct comedi_cmd *cmd)
 {
        int err = 0;
-       unsigned int tmp;
-
-       /* step 1: make sure trigger sources are trivially valid */
-
-       tmp = cmd->start_src;
-       cmd->start_src &= (TRIG_NOW | TRIG_INT);
-       if (!cmd->start_src || tmp != cmd->start_src)
-               err++;
-
-       tmp = cmd->scan_begin_src;
-       cmd->scan_begin_src &= TRIG_EXT;
-       if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src)
-               err++;
-
-       tmp = cmd->convert_src;
-       cmd->convert_src &= TRIG_NOW;
-       if (!cmd->convert_src || tmp != cmd->convert_src)
-               err++;
 
-       tmp = cmd->scan_end_src;
-       cmd->scan_end_src &= TRIG_COUNT;
-       if (!cmd->scan_end_src || tmp != cmd->scan_end_src)
-               err++;
+       /* Step 1 : check if triggers are trivially valid */
 
-       tmp = cmd->stop_src;
-       cmd->stop_src &= (TRIG_COUNT | TRIG_NONE);
-       if (!cmd->stop_src || tmp != cmd->stop_src)
-               err++;
+       err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW | TRIG_INT);
+       err |= cfc_check_trigger_src(&cmd->scan_begin_src, TRIG_EXT);
+       err |= cfc_check_trigger_src(&cmd->convert_src, TRIG_NOW);
+       err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
+       err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE);
 
        if (err)
                return 1;
 
-       /* step 2: make sure trigger sources are unique and
-        * mutually compatible */
+       /* Step 2a : make sure trigger sources are unique */
 
-       /* these tests are true if more than one _src bit is set */
-       if ((cmd->start_src & (cmd->start_src - 1)) != 0)
-               err++;
-       if ((cmd->scan_begin_src & (cmd->scan_begin_src - 1)) != 0)
-               err++;
-       if ((cmd->convert_src & (cmd->convert_src - 1)) != 0)
-               err++;
-       if ((cmd->scan_end_src & (cmd->scan_end_src - 1)) != 0)
-               err++;
-       if ((cmd->stop_src & (cmd->stop_src - 1)) != 0)
-               err++;
+       err |= cfc_check_trigger_is_unique(cmd->start_src);
+       err |= cfc_check_trigger_is_unique(cmd->stop_src);
+
+       /* Step 2b : and mutually compatible */
 
        if (err)
                return 2;
index e95a4eb0a67d436cb1f7101da6d380d471329e44..3e276f7a33806d788c25fd0db6532f826529048a 100644 (file)
@@ -56,6 +56,8 @@ Devices: [Quatech] DAQP-208 (daqp), DAQP-308
 
 #include <linux/completion.h>
 
+#include "comedi_fc.h"
+
 /* Maximum number of separate DAQP devices we'll allow */
 #define MAX_DEV         4
 
@@ -456,51 +458,26 @@ static int daqp_ai_cmdtest(struct comedi_device *dev,
        int err = 0;
        int tmp;
 
-       /* step 1: make sure trigger sources are trivially valid */
-
-       tmp = cmd->start_src;
-       cmd->start_src &= TRIG_NOW;
-       if (!cmd->start_src || tmp != cmd->start_src)
-               err++;
-
-       tmp = cmd->scan_begin_src;
-       cmd->scan_begin_src &= TRIG_TIMER | TRIG_FOLLOW;
-       if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src)
-               err++;
-
-       tmp = cmd->convert_src;
-       cmd->convert_src &= TRIG_TIMER | TRIG_NOW;
-       if (!cmd->convert_src || tmp != cmd->convert_src)
-               err++;
-
-       tmp = cmd->scan_end_src;
-       cmd->scan_end_src &= TRIG_COUNT;
-       if (!cmd->scan_end_src || tmp != cmd->scan_end_src)
-               err++;
+       /* Step 1 : check if triggers are trivially valid */
 
-       tmp = cmd->stop_src;
-       cmd->stop_src &= TRIG_COUNT | TRIG_NONE;
-       if (!cmd->stop_src || tmp != cmd->stop_src)
-               err++;
+       err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW);
+       err |= cfc_check_trigger_src(&cmd->scan_begin_src,
+                                       TRIG_TIMER | TRIG_FOLLOW);
+       err |= cfc_check_trigger_src(&cmd->convert_src,
+                                       TRIG_TIMER | TRIG_NOW);
+       err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
+       err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE);
 
        if (err)
                return 1;
 
-       /*
-        * step 2: make sure trigger sources
-        * are unique and mutually compatible
-        */
+       /* Step 2a : make sure trigger sources are unique */
 
-       /* note that mutual compatibility is not an issue here */
-       if (cmd->scan_begin_src != TRIG_TIMER &&
-           cmd->scan_begin_src != TRIG_FOLLOW)
-               err++;
-       if (cmd->convert_src != TRIG_NOW && cmd->convert_src != TRIG_TIMER)
-               err++;
-       if (cmd->scan_begin_src == TRIG_FOLLOW && cmd->convert_src == TRIG_NOW)
-               err++;
-       if (cmd->stop_src != TRIG_COUNT && cmd->stop_src != TRIG_NONE)
-               err++;
+       err |= cfc_check_trigger_is_unique(cmd->scan_begin_src);
+       err |= cfc_check_trigger_is_unique(cmd->convert_src);
+       err |= cfc_check_trigger_is_unique(cmd->stop_src);
+
+       /* Step 2b : and mutually compatible */
 
        if (err)
                return 2;
index d0e4844e5248c6a863eec16d5162aa3c20f64f04..41d24b08913b8c70f381c3fa19813e2c0fb6748d 100644 (file)
@@ -106,6 +106,8 @@ Configuration options:
 
 #include "../comedidev.h"
 
+#include "comedi_fc.h"
+
 #define DRV_NAME "rtd520"
 
 /*======================================================================
@@ -976,52 +978,25 @@ static int rtd_ai_cmdtest(struct comedi_device *dev,
        int err = 0;
        int tmp;
 
-       /* step 1: make sure trigger sources are trivially valid */
-
-       tmp = cmd->start_src;
-       cmd->start_src &= TRIG_NOW;
-       if (!cmd->start_src || tmp != cmd->start_src)
-               err++;
-
-       tmp = cmd->scan_begin_src;
-       cmd->scan_begin_src &= TRIG_TIMER | TRIG_EXT;
-       if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src)
-               err++;
-
-
-       tmp = cmd->convert_src;
-       cmd->convert_src &= TRIG_TIMER | TRIG_EXT;
-       if (!cmd->convert_src || tmp != cmd->convert_src)
-               err++;
-
-
-       tmp = cmd->scan_end_src;
-       cmd->scan_end_src &= TRIG_COUNT;
-       if (!cmd->scan_end_src || tmp != cmd->scan_end_src)
-               err++;
-
-
-       tmp = cmd->stop_src;
-       cmd->stop_src &= TRIG_COUNT | TRIG_NONE;
-       if (!cmd->stop_src || tmp != cmd->stop_src)
-               err++;
+       /* Step 1 : check if triggers are trivially valid */
 
+       err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW);
+       err |= cfc_check_trigger_src(&cmd->scan_begin_src,
+                                       TRIG_TIMER | TRIG_EXT);
+       err |= cfc_check_trigger_src(&cmd->convert_src, TRIG_TIMER | TRIG_EXT);
+       err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
+       err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE);
 
        if (err)
                return 1;
 
-       /* step 2: make sure trigger sources are unique
-          and mutually compatible */
-       /* note that mutual compatibility is not an issue here */
-       if (cmd->scan_begin_src != TRIG_TIMER &&
-           cmd->scan_begin_src != TRIG_EXT) {
-               err++;
-       }
-       if (cmd->convert_src != TRIG_TIMER && cmd->convert_src != TRIG_EXT)
-               err++;
+       /* Step 2a : make sure trigger sources are unique */
 
-       if (cmd->stop_src != TRIG_COUNT && cmd->stop_src != TRIG_NONE)
-               err++;
+       err |= cfc_check_trigger_is_unique(cmd->scan_begin_src);
+       err |= cfc_check_trigger_is_unique(cmd->convert_src);
+       err |= cfc_check_trigger_is_unique(cmd->stop_src);
+
+       /* Step 2b : and mutually compatible */
 
        if (err)
                return 2;
index 24878c815fd74d04283bd525394e7ee70ec55281..551d68b7837cde3bd9e43229d06cec23c0f57582 100644 (file)
@@ -1505,56 +1505,28 @@ static int s626_ai_cmdtest(struct comedi_device *dev,
        int err = 0;
        int tmp;
 
-       /* cmdtest tests a particular command to see if it is valid.  Using
-        * the cmdtest ioctl, a user can create a valid cmd and then have it
-        * executes by the cmd ioctl.
-        *
-        * cmdtest returns 1,2,3,4 or 0, depending on which tests the
-        * command passes. */
-
-       /* step 1: make sure trigger sources are trivially valid */
-
-       tmp = cmd->start_src;
-       cmd->start_src &= TRIG_NOW | TRIG_INT | TRIG_EXT;
-       if (!cmd->start_src || tmp != cmd->start_src)
-               err++;
+       /* Step 1 : check if triggers are trivially valid */
 
-       tmp = cmd->scan_begin_src;
-       cmd->scan_begin_src &= TRIG_TIMER | TRIG_EXT | TRIG_FOLLOW;
-       if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src)
-               err++;
-
-       tmp = cmd->convert_src;
-       cmd->convert_src &= TRIG_TIMER | TRIG_EXT | TRIG_NOW;
-       if (!cmd->convert_src || tmp != cmd->convert_src)
-               err++;
-
-       tmp = cmd->scan_end_src;
-       cmd->scan_end_src &= TRIG_COUNT;
-       if (!cmd->scan_end_src || tmp != cmd->scan_end_src)
-               err++;
-
-       tmp = cmd->stop_src;
-       cmd->stop_src &= TRIG_COUNT | TRIG_NONE;
-       if (!cmd->stop_src || tmp != cmd->stop_src)
-               err++;
+       err |= cfc_check_trigger_src(&cmd->start_src,
+                                       TRIG_NOW | TRIG_INT | TRIG_EXT);
+       err |= cfc_check_trigger_src(&cmd->scan_begin_src,
+                                       TRIG_TIMER | TRIG_EXT | TRIG_FOLLOW);
+       err |= cfc_check_trigger_src(&cmd->convert_src,
+                                       TRIG_TIMER | TRIG_EXT | TRIG_NOW);
+       err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
+       err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE);
 
        if (err)
                return 1;
 
-       /* step 2: make sure trigger sources are unique and mutually
-          compatible */
+       /* Step 2a : make sure trigger sources are unique */
 
-       /* note that mutual compatibility is not an issue here */
-       if (cmd->scan_begin_src != TRIG_TIMER &&
-           cmd->scan_begin_src != TRIG_EXT
-           && cmd->scan_begin_src != TRIG_FOLLOW)
-               err++;
-       if (cmd->convert_src != TRIG_TIMER &&
-           cmd->convert_src != TRIG_EXT && cmd->convert_src != TRIG_NOW)
-               err++;
-       if (cmd->stop_src != TRIG_COUNT && cmd->stop_src != TRIG_NONE)
-               err++;
+       err |= cfc_check_trigger_is_unique(cmd->start_src);
+       err |= cfc_check_trigger_is_unique(cmd->scan_begin_src);
+       err |= cfc_check_trigger_is_unique(cmd->convert_src);
+       err |= cfc_check_trigger_is_unique(cmd->stop_src);
+
+       /* Step 2b : and mutually compatible */
 
        if (err)
                return 2;
index eb70baca49d87630ff545407524525126bdd139c..b70cdf300bbd74244eb1432e31db9dd44971e20e 100644 (file)
@@ -76,6 +76,8 @@ Configuration Options:
 
 #include <linux/pci.h>         /* for PCI devices */
 
+#include "comedi_fc.h"
+
 /* Imaginary registers for the imaginary board */
 
 #define SKEL_SIZE 0
@@ -349,60 +351,40 @@ static int skel_ai_rinsn(struct comedi_device *dev, struct comedi_subdevice *s,
        return n;
 }
 
+/*
+ * cmdtest tests a particular command to see if it is valid.
+ * Using the cmdtest ioctl, a user can create a valid cmd
+ * and then have it executes by the cmd ioctl.
+ *
+ * cmdtest returns 1,2,3,4 or 0, depending on which tests
+ * the command passes.
+ */
 static int skel_ai_cmdtest(struct comedi_device *dev,
-                          struct comedi_subdevice *s, struct comedi_cmd *cmd)
+                          struct comedi_subdevice *s,
+                          struct comedi_cmd *cmd)
 {
        int err = 0;
        int tmp;
 
-       /* cmdtest tests a particular command to see if it is valid.
-        * Using the cmdtest ioctl, a user can create a valid cmd
-        * and then have it executes by the cmd ioctl.
-        *
-        * cmdtest returns 1,2,3,4 or 0, depending on which tests
-        * the command passes. */
-
-       /* step 1: make sure trigger sources are trivially valid */
+       /* Step 1 : check if triggers are trivially valid */
 
-       tmp = cmd->start_src;
-       cmd->start_src &= TRIG_NOW;
-       if (!cmd->start_src || tmp != cmd->start_src)
-               err++;
-
-       tmp = cmd->scan_begin_src;
-       cmd->scan_begin_src &= TRIG_TIMER | TRIG_EXT;
-       if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src)
-               err++;
-
-       tmp = cmd->convert_src;
-       cmd->convert_src &= TRIG_TIMER | TRIG_EXT;
-       if (!cmd->convert_src || tmp != cmd->convert_src)
-               err++;
-
-       tmp = cmd->scan_end_src;
-       cmd->scan_end_src &= TRIG_COUNT;
-       if (!cmd->scan_end_src || tmp != cmd->scan_end_src)
-               err++;
-
-       tmp = cmd->stop_src;
-       cmd->stop_src &= TRIG_COUNT | TRIG_NONE;
-       if (!cmd->stop_src || tmp != cmd->stop_src)
-               err++;
+       err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW);
+       err |= cfc_check_trigger_src(&cmd->scan_begin_src,
+                                       TRIG_TIMER | TRIG_EXT);
+       err |= cfc_check_trigger_src(&cmd->convert_src, TRIG_TIMER | TRIG_EXT);
+       err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
+       err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE);
 
        if (err)
                return 1;
 
-       /* step 2: make sure trigger sources are unique and mutually compatible
-     */
+       /* Step 2a : make sure trigger sources are unique */
 
-       /* note that mutual compatibility is not an issue here */
-       if (cmd->scan_begin_src != TRIG_TIMER &&
-           cmd->scan_begin_src != TRIG_EXT)
-               err++;
-       if (cmd->convert_src != TRIG_TIMER && cmd->convert_src != TRIG_EXT)
-               err++;
-       if (cmd->stop_src != TRIG_COUNT && cmd->stop_src != TRIG_NONE)
-               err++;
+       err |= cfc_check_trigger_is_unique(cmd->scan_begin_src);
+       err |= cfc_check_trigger_is_unique(cmd->convert_src);
+       err |= cfc_check_trigger_is_unique(cmd->stop_src);
+
+       /* Step 2b : and mutually compatible */
 
        if (err)
                return 2;
index bc5fc5cc4641aebd2f2a10e7fc8cf8be47afa911..b536bba74351178f6ae939f666ab4b7c4781bb78 100644 (file)
@@ -98,6 +98,8 @@ sampling rate. If you sample two channels you get 4kHz and so on.
 
 #include "../comedidev.h"
 
+#include "comedi_fc.h"
+
 /* timeout for the USB-transfer in ms*/
 #define BULK_TIMEOUT 1000
 
@@ -929,9 +931,9 @@ static int usbduxsub_submit_OutURBs(struct usbduxsub *usbduxsub)
 static int usbdux_ai_cmdtest(struct comedi_device *dev,
                             struct comedi_subdevice *s, struct comedi_cmd *cmd)
 {
-       int err = 0, tmp, i;
-       unsigned int tmpTimer;
        struct usbduxsub *this_usbduxsub = dev->private;
+       int err = 0, i;
+       unsigned int tmpTimer;
 
        if (!(this_usbduxsub->probed))
                return -ENODEV;
@@ -939,51 +941,23 @@ static int usbdux_ai_cmdtest(struct comedi_device *dev,
        dev_dbg(&this_usbduxsub->interface->dev,
                "comedi%d: usbdux_ai_cmdtest\n", dev->minor);
 
-       /* make sure triggers are valid */
-       /* Only immediate triggers are allowed */
-       tmp = cmd->start_src;
-       cmd->start_src &= TRIG_NOW | TRIG_INT;
-       if (!cmd->start_src || tmp != cmd->start_src)
-               err++;
+       /* Step 1 : check if triggers are trivially valid */
 
-       /* trigger should happen timed */
-       tmp = cmd->scan_begin_src;
-       /* start a new _scan_ with a timer */
-       cmd->scan_begin_src &= TRIG_TIMER;
-       if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src)
-               err++;
-
-       /* scanning is continuous */
-       tmp = cmd->convert_src;
-       cmd->convert_src &= TRIG_NOW;
-       if (!cmd->convert_src || tmp != cmd->convert_src)
-               err++;
-
-       /* issue a trigger when scan is finished and start a new scan */
-       tmp = cmd->scan_end_src;
-       cmd->scan_end_src &= TRIG_COUNT;
-       if (!cmd->scan_end_src || tmp != cmd->scan_end_src)
-               err++;
-
-       /* trigger at the end of count events or not, stop condition or not */
-       tmp = cmd->stop_src;
-       cmd->stop_src &= TRIG_COUNT | TRIG_NONE;
-       if (!cmd->stop_src || tmp != cmd->stop_src)
-               err++;
+       err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW | TRIG_INT);
+       err |= cfc_check_trigger_src(&cmd->scan_begin_src, TRIG_TIMER);
+       err |= cfc_check_trigger_src(&cmd->convert_src, TRIG_NOW);
+       err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
+       err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE);
 
        if (err)
                return 1;
 
-       /*
-        * step 2: make sure trigger sources are unique and mutually compatible
-        * note that mutual compatibility is not an issue here
-        */
-       if (cmd->scan_begin_src != TRIG_FOLLOW &&
-           cmd->scan_begin_src != TRIG_EXT &&
-           cmd->scan_begin_src != TRIG_TIMER)
-               err++;
-       if (cmd->stop_src != TRIG_COUNT && cmd->stop_src != TRIG_NONE)
-               err++;
+       /* Step 2a : make sure trigger sources are unique */
+
+       err |= cfc_check_trigger_is_unique(cmd->start_src);
+       err |= cfc_check_trigger_is_unique(cmd->stop_src);
+
+       /* Step 2b : and mutually compatible */
 
        if (err)
                return 2;
@@ -1488,8 +1462,9 @@ static int usbdux_ao_inttrig(struct comedi_device *dev,
 static int usbdux_ao_cmdtest(struct comedi_device *dev,
                             struct comedi_subdevice *s, struct comedi_cmd *cmd)
 {
-       int err = 0, tmp;
        struct usbduxsub *this_usbduxsub = dev->private;
+       int err = 0;
+       unsigned int flags;
 
        if (!this_usbduxsub)
                return -EFAULT;
@@ -1500,69 +1475,46 @@ static int usbdux_ao_cmdtest(struct comedi_device *dev,
        dev_dbg(&this_usbduxsub->interface->dev,
                "comedi%d: usbdux_ao_cmdtest\n", dev->minor);
 
-       /* make sure triggers are valid */
-       /* Only immediate triggers are allowed */
-       tmp = cmd->start_src;
-       cmd->start_src &= TRIG_NOW | TRIG_INT;
-       if (!cmd->start_src || tmp != cmd->start_src)
-               err++;
+       /* Step 1 : check if triggers are trivially valid */
+
+       err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW | TRIG_INT);
 
-       /* trigger should happen timed */
-       tmp = cmd->scan_begin_src;
-       /* just now we scan also in the high speed mode every frame */
-       /* this is due to ehci driver limitations */
        if (0) {                /* (this_usbduxsub->high_speed) */
-               /* start immediately a new scan */
                /* the sampling rate is set by the coversion rate */
-               cmd->scan_begin_src &= TRIG_FOLLOW;
+               flags = TRIG_FOLLOW;
        } else {
                /* start a new scan (output at once) with a timer */
-               cmd->scan_begin_src &= TRIG_TIMER;
+               flags = TRIG_TIMER;
        }
-       if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src)
-               err++;
+       err |= cfc_check_trigger_src(&cmd->scan_begin_src, flags);
 
-       /* scanning is continuous */
-       tmp = cmd->convert_src;
-       /* we always output at 1kHz just now all channels at once */
        if (0) {                /* (this_usbduxsub->high_speed) */
                /*
-                * in usb-2.0 only one conversion it transmitted but with 8kHz/n
+                * in usb-2.0 only one conversion it transmitted
+                * but with 8kHz/n
                 */
-               cmd->convert_src &= TRIG_TIMER;
+               flags = TRIG_TIMER;
        } else {
-               /* all conversion events happen simultaneously with a rate of
-                * 1kHz/n */
-               cmd->convert_src &= TRIG_NOW;
+               /*
+                * all conversion events happen simultaneously with
+                * a rate of 1kHz/n
+                */
+               flags = TRIG_NOW;
        }
-       if (!cmd->convert_src || tmp != cmd->convert_src)
-               err++;
-
-       /* issue a trigger when scan is finished and start a new scan */
-       tmp = cmd->scan_end_src;
-       cmd->scan_end_src &= TRIG_COUNT;
-       if (!cmd->scan_end_src || tmp != cmd->scan_end_src)
-               err++;
+       err |= cfc_check_trigger_src(&cmd->convert_src, flags);
 
-       /* trigger at the end of count events or not, stop condition or not */
-       tmp = cmd->stop_src;
-       cmd->stop_src &= TRIG_COUNT | TRIG_NONE;
-       if (!cmd->stop_src || tmp != cmd->stop_src)
-               err++;
+       err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
+       err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE);
 
        if (err)
                return 1;
 
-       /*
-        * step 2: make sure trigger sources are unique and mutually compatible
-        * note that mutual compatibility is not an issue here
-        */
-       if (cmd->scan_begin_src != TRIG_FOLLOW &&
-           cmd->scan_begin_src != TRIG_EXT &&
-           cmd->scan_begin_src != TRIG_TIMER)
-               err++;
-       if (cmd->stop_src != TRIG_COUNT && cmd->stop_src != TRIG_NONE)
-               err++;
+       /* Step 2a : make sure trigger sources are unique */
+
+       err |= cfc_check_trigger_is_unique(cmd->start_src);
+       err |= cfc_check_trigger_is_unique(cmd->stop_src);
+
+       /* Step 2b : and mutually compatible */
 
        if (err)
                return 2;
index 0f6c1392f6ce5ab8aef48dd9c1c789e708b4d8db..1154a7e2895d5aa944f7ca0befe5aa029d812ca1 100644 (file)
@@ -549,10 +549,10 @@ static int usbduxfast_ai_cmdtest(struct comedi_device *dev,
                                 struct comedi_subdevice *s,
                                 struct comedi_cmd *cmd)
 {
-       int err = 0, stop_mask = 0;
+       struct usbduxfastsub_s *udfs = dev->private;
+       int err = 0;
        long int steps, tmp;
        int minSamplPer;
-       struct usbduxfastsub_s *udfs = dev->private;
 
        if (!udfs->probed)
                return -ENODEV;
@@ -563,57 +563,31 @@ static int usbduxfast_ai_cmdtest(struct comedi_device *dev,
               "scan_begin_arg=%u\n",
               dev->minor, cmd->convert_arg, cmd->scan_begin_arg);
 #endif
-       /* step 1: make sure trigger sources are trivially valid */
-
-       tmp = cmd->start_src;
-       cmd->start_src &= TRIG_NOW | TRIG_EXT | TRIG_INT;
-       if (!cmd->start_src || tmp != cmd->start_src)
-               err++;
-
-       tmp = cmd->scan_begin_src;
-       cmd->scan_begin_src &= TRIG_TIMER | TRIG_FOLLOW | TRIG_EXT;
-       if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src)
-               err++;
-
-       tmp = cmd->convert_src;
-       cmd->convert_src &= TRIG_TIMER | TRIG_EXT;
-       if (!cmd->convert_src || tmp != cmd->convert_src)
-               err++;
-
-       tmp = cmd->scan_end_src;
-       cmd->scan_end_src &= TRIG_COUNT;
-       if (!cmd->scan_end_src || tmp != cmd->scan_end_src)
-               err++;
+       /* Step 1 : check if triggers are trivially valid */
 
-       tmp = cmd->stop_src;
-       stop_mask = TRIG_COUNT | TRIG_NONE;
-       cmd->stop_src &= stop_mask;
-       if (!cmd->stop_src || tmp != cmd->stop_src)
-               err++;
+       err |= cfc_check_trigger_src(&cmd->start_src,
+                                       TRIG_NOW | TRIG_EXT | TRIG_INT);
+       err |= cfc_check_trigger_src(&cmd->scan_begin_src,
+                                       TRIG_TIMER | TRIG_FOLLOW | TRIG_EXT);
+       err |= cfc_check_trigger_src(&cmd->convert_src, TRIG_TIMER | TRIG_EXT);
+       err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
+       err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE);
 
        if (err)
                return 1;
 
-       /*
-        * step 2: make sure trigger sources are unique and mutually compatible
-        */
+       /* Step 2a : make sure trigger sources are unique */
 
-       if (cmd->start_src != TRIG_NOW &&
-           cmd->start_src != TRIG_EXT && cmd->start_src != TRIG_INT)
-               err++;
-       if (cmd->scan_begin_src != TRIG_TIMER &&
-           cmd->scan_begin_src != TRIG_FOLLOW &&
-           cmd->scan_begin_src != TRIG_EXT)
-               err++;
-       if (cmd->convert_src != TRIG_TIMER && cmd->convert_src != TRIG_EXT)
-               err++;
-       if (cmd->stop_src != TRIG_COUNT &&
-           cmd->stop_src != TRIG_EXT && cmd->stop_src != TRIG_NONE)
-               err++;
+       err |= cfc_check_trigger_is_unique(cmd->start_src);
+       err |= cfc_check_trigger_is_unique(cmd->scan_begin_src);
+       err |= cfc_check_trigger_is_unique(cmd->convert_src);
+       err |= cfc_check_trigger_is_unique(cmd->stop_src);
+
+       /* Step 2b : and mutually compatible */
 
        /* can't have external stop and start triggers at once */
        if (cmd->start_src == TRIG_EXT && cmd->stop_src == TRIG_EXT)
-               err++;
+               err |= -EINVAL;
 
        if (err)
                return 2;
index b4ab83f1215f89a8abc9219dba296462e4319a16..b1694121f8450acc2275174d7e8119d4f4c77f39 100644 (file)
@@ -897,9 +897,9 @@ static int usbdux_ai_cmdtest(struct comedi_device *dev,
                             struct comedi_subdevice *s,
                             struct comedi_cmd *cmd)
 {
-       int err = 0, tmp, i;
-       unsigned int tmpTimer;
        struct usbduxsub *this_usbduxsub = dev->private;
+       int err = 0, i;
+       unsigned int tmpTimer;
 
        if (!(this_usbduxsub->probed))
                return -ENODEV;
@@ -907,51 +907,23 @@ static int usbdux_ai_cmdtest(struct comedi_device *dev,
        dev_dbg(&this_usbduxsub->interface->dev,
                "comedi%d: usbdux_ai_cmdtest\n", dev->minor);
 
-       /* make sure triggers are valid */
-       /* Only immediate triggers are allowed */
-       tmp = cmd->start_src;
-       cmd->start_src &= TRIG_NOW | TRIG_INT;
-       if (!cmd->start_src || tmp != cmd->start_src)
-               err++;
-
-       /* trigger should happen timed */
-       tmp = cmd->scan_begin_src;
-       /* start a new _scan_ with a timer */
-       cmd->scan_begin_src &= TRIG_TIMER;
-       if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src)
-               err++;
-
-       /* scanning is continuous */
-       tmp = cmd->convert_src;
-       cmd->convert_src &= TRIG_NOW;
-       if (!cmd->convert_src || tmp != cmd->convert_src)
-               err++;
-
-       /* issue a trigger when scan is finished and start a new scan */
-       tmp = cmd->scan_end_src;
-       cmd->scan_end_src &= TRIG_COUNT;
-       if (!cmd->scan_end_src || tmp != cmd->scan_end_src)
-               err++;
+       /* Step 1 : check if triggers are trivially valid */
 
-       /* trigger at the end of count events or not, stop condition or not */
-       tmp = cmd->stop_src;
-       cmd->stop_src &= TRIG_COUNT | TRIG_NONE;
-       if (!cmd->stop_src || tmp != cmd->stop_src)
-               err++;
+       err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW | TRIG_INT);
+       err |= cfc_check_trigger_src(&cmd->scan_begin_src, TRIG_TIMER);
+       err |= cfc_check_trigger_src(&cmd->convert_src, TRIG_NOW);
+       err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
+       err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE);
 
        if (err)
                return 1;
 
-       /*
-        * step 2: make sure trigger sources are unique and mutually compatible
-        * note that mutual compatibility is not an issue here
-        */
-       if (cmd->scan_begin_src != TRIG_FOLLOW &&
-           cmd->scan_begin_src != TRIG_EXT &&
-           cmd->scan_begin_src != TRIG_TIMER)
-               err++;
-       if (cmd->stop_src != TRIG_COUNT && cmd->stop_src != TRIG_NONE)
-               err++;
+       /* Step 2a : make sure trigger sources are unique */
+
+       err |= cfc_check_trigger_is_unique(cmd->start_src);
+       err |= cfc_check_trigger_is_unique(cmd->stop_src);
+
+       /* Step 2b : and mutually compatible */
 
        if (err)
                return 2;
@@ -1558,8 +1530,9 @@ static int usbdux_ao_cmdtest(struct comedi_device *dev,
                             struct comedi_subdevice *s,
                             struct comedi_cmd *cmd)
 {
-       int err = 0, tmp;
        struct usbduxsub *this_usbduxsub = dev->private;
+       int err = 0;
+       unsigned int flags;
 
        if (!this_usbduxsub)
                return -EFAULT;
@@ -1570,63 +1543,35 @@ static int usbdux_ao_cmdtest(struct comedi_device *dev,
        dev_dbg(&this_usbduxsub->interface->dev,
                "comedi%d: usbdux_ao_cmdtest\n", dev->minor);
 
-       /* make sure triggers are valid */
-       /* Only immediate triggers are allowed */
-       tmp = cmd->start_src;
-       cmd->start_src &= TRIG_NOW | TRIG_INT;
-       if (!cmd->start_src || tmp != cmd->start_src)
-               err++;
+       /* Step 1 : check if triggers are trivially valid */
+
+       err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW | TRIG_INT);
 
-       /* trigger should happen timed */
-       tmp = cmd->scan_begin_src;
-       /* just now we scan also in the high speed mode every frame */
-       /* this is due to ehci driver limitations */
        if (0) {                /* (this_usbduxsub->high_speed) */
-               /* start immediately a new scan */
-               /* the sampling rate is set by the coversion rate */
-               cmd->scan_begin_src &= TRIG_FOLLOW;
+               /*
+                * start immediately a new scan
+                * the sampling rate is set by the coversion rate
+                */
+               flags = TRIG_FOLLOW;
        } else {
                /* start a new scan (output at once) with a timer */
-               cmd->scan_begin_src &= TRIG_TIMER;
+               flags = TRIG_TIMER;
        }
-       if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src)
-               err++;
-
-       /* scanning is continuous */
-       tmp = cmd->convert_src;
+       err |= cfc_check_trigger_src(&cmd->scan_begin_src, flags);
 
-       /* all conversion events happen simultaneously */
-       cmd->convert_src &= TRIG_NOW;
-
-       if (!cmd->convert_src || tmp != cmd->convert_src)
-               err++;
-
-       /* issue a trigger when scan is finished and start a new scan */
-       tmp = cmd->scan_end_src;
-       cmd->scan_end_src &= TRIG_COUNT;
-       if (!cmd->scan_end_src || tmp != cmd->scan_end_src)
-               err++;
-
-       /* trigger at the end of count events or not, stop condition or not */
-       tmp = cmd->stop_src;
-       cmd->stop_src &= TRIG_COUNT | TRIG_NONE;
-       if (!cmd->stop_src || tmp != cmd->stop_src)
-               err++;
+       err |= cfc_check_trigger_src(&cmd->convert_src, TRIG_NOW);
+       err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
+       err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE);
 
        if (err)
                return 1;
 
-       /*
-        * step 2: make sure trigger sources
-        * are unique and mutually compatible
-        * note that mutual compatibility is not an issue here
-        */
-       if (cmd->scan_begin_src != TRIG_FOLLOW &&
-           cmd->scan_begin_src != TRIG_EXT &&
-           cmd->scan_begin_src != TRIG_TIMER)
-               err++;
-       if (cmd->stop_src != TRIG_COUNT && cmd->stop_src != TRIG_NONE)
-               err++;
+       /* Step 2a : make sure trigger sources are unique */
+
+       err |= cfc_check_trigger_is_unique(cmd->start_src);
+       err |= cfc_check_trigger_is_unique(cmd->stop_src);
+
+       /* Step 2b : and mutually compatible */
 
        if (err)
                return 2;