Split check_and_setup_channel_list() into separate functions
authorDavid Schleef <ds@schleef.org>
Tue, 10 Jul 2001 21:20:02 +0000 (21:20 +0000)
committerDavid Schleef <ds@schleef.org>
Tue, 10 Jul 2001 21:20:02 +0000 (21:20 +0000)
comedi/drivers/adl_pci9118.c
comedi/drivers/adv_pci1710.c

index 691f68d501b2d7134cce6dc2761d59739264aff7..ce23855b75ccc8a5ad58ca0a11f37cd8294a77e2 100644 (file)
@@ -237,7 +237,10 @@ typedef struct{
 ==============================================================================
 */
 
-int check_and_setup_channel_list(comedi_device * dev, comedi_subdevice * s, int n_chan, unsigned int *chanlist,char rot, char check);
+int check_channel_list(comedi_device * dev, comedi_subdevice * s, int n_chan,
+       unsigned int *chanlist);
+int setup_channel_list(comedi_device * dev, comedi_subdevice * s, int n_chan,
+       unsigned int *chanlist,int rot);
 void start_pacer(comedi_device * dev, int mode, unsigned int divisor1, unsigned int divisor2);
 static int pci9118_reset(comedi_device *dev);
 int pci9118_exttrg_add(comedi_device * dev, unsigned char source);
@@ -497,7 +500,10 @@ static int pci9118_ai_docmd_and_mode(int mode, comedi_device * dev, comedi_subde
 
        devpriv->AdControlReg=0;        // bipolar, S.E., use 8254, stop 8354, internal trigger, soft trigger, disable DMA
 
-       if (!check_and_setup_channel_list(dev, s, devpriv->ai1234_n_chan, devpriv->ai1234_chanlist, 8, 0)) return -EINVAL;
+       if (!check_channel_list(dev, s, devpriv->ai1234_n_chan,
+               devpriv->ai1234_chanlist)) return -EINVAL;
+       if (!setup_channel_list(dev, s, devpriv->ai1234_n_chan,
+               devpriv->ai1234_chanlist, 8)) return -EINVAL;
 
        outl(devpriv->AdControlReg,dev->iobase+PCI9118_ADCNTRL);
        devpriv->AdFunctionReg=AdFunction_PDTrg|AdFunction_PETrg;       // positive triggers, no S&H, no burst, burst stop, no post trigger, no about trigger, trigger stop
@@ -649,7 +655,7 @@ int pci9118_insn_read_ai(comedi_device *dev,comedi_subdevice *s, comedi_insn *in
        devpriv->AdFunctionReg=AdFunction_PDTrg|AdFunction_PETrg;
        outl(devpriv->AdFunctionReg,dev->iobase+PCI9118_ADFUNC);// positive triggers, no S&H, no burst, burst stop, no post trigger, no about trigger, trigger stop
 
-       if (!check_and_setup_channel_list(dev,s,1,&insn->chanspec, 0, 0))  return -EINVAL;
+       if (!setup_channel_list(dev,s,1,&insn->chanspec, 0))  return -EINVAL;
 
        outl(0,dev->iobase+PCI9118_DELFIFO); // flush FIFO
 
@@ -897,11 +903,12 @@ static int pci9118_ai_cmdtest(comedi_device *dev,comedi_subdevice *s,comedi_cmd
                }
        }
 
-       if (cmd->chanlist)
-               if (!check_and_setup_channel_list(dev, s, cmd->chanlist_len, cmd->chanlist, 0, 1)) return 5; // incorrect channels list
-
        if(err) return 4;
 
+       if (cmd->chanlist)
+               if (!check_channel_list(dev, s, cmd->chanlist_len,
+                       cmd->chanlist)) return 5; // incorrect channels list
+
        return 0;
 }
 
@@ -954,14 +961,14 @@ static int pci9118_ai_cmd(comedi_device *dev,comedi_subdevice *s)
 /*
 ==============================================================================
 */
-int check_and_setup_channel_list(comedi_device * dev, comedi_subdevice * s, int n_chan, unsigned int *chanlist,char rot,char check) 
+int check_channel_list(comedi_device * dev, comedi_subdevice * s,
+       int n_chan, unsigned int *chanlist)
 {
         unsigned int i, differencial=0, bipolar=0;
-       unsigned int scanquad, gain;
            
-    /* correct channel and range number check itself comedi/range.c */
+       /* correct channel and range number check itself comedi/range.c */
        if (n_chan<1) {
-               if (!check) comedi_error(dev,"range/channel list is empty!");
+               comedi_error(dev,"range/channel list is empty!");
                return 0;             
         }
 
@@ -972,21 +979,33 @@ int check_and_setup_channel_list(comedi_device * dev, comedi_subdevice * s, int
         if (n_chan > 1)
                for (i=1 ; i<n_chan; i++) { // check S.E/diff
                        if ((CR_AREF(chanlist[i])==AREF_DIFF)!=(differencial)) {
-                               if (!check) comedi_error(dev,"Differencial and single ended inputs cann't be mixtured!");
+                               comedi_error(dev,"Differencial and single ended inputs cann't be mixtured!");
                                return 0;             
                        }
                        if ((CR_RANGE(chanlist[i])<PCI9118_BIPOLAR_RANGES)!=(bipolar)) {
-                               if (!check) comedi_error(dev,"Bipolar and unipolar ranges cann't be mixtured!");
+                               comedi_error(dev,"Bipolar and unipolar ranges cann't be mixtured!");
                                return 0;             
                        }
                        if ((!devpriv->usemux)&(differencial)&(CR_CHAN(chanlist[i])>=this_board->n_aichand)) {
-                               if (!check) comedi_error(dev,"If AREF_DIFF is used then is available only 8 channels!");
+                               comedi_error(dev,"If AREF_DIFF is used then is available only 8 channels!");
                                return 0;             
                        }
                }
                
-       if (check) return 1;
-       
+       return 1;
+}
+
+int setup_channel_list(comedi_device * dev, comedi_subdevice * s, int n_chan,
+       unsigned int *chanlist,int rot)
+{
+        unsigned int i, differencial=0, bipolar=0;
+       unsigned int scanquad, gain;
+
+       if (CR_AREF(chanlist[0])==AREF_DIFF)
+               differencial=1;  // all input must be diff
+       if (CR_RANGE(chanlist[0])<PCI9118_BIPOLAR_RANGES)
+               bipolar=1;  // all input must be bipolar
+
        // All is ok, so we can setup channel/range list
 
        if (!bipolar) {
index 7f21ab8cc3ed49bba6174cdedbe69102acafdb29..8fa4d22d0aa36f716c5af0a74cd0e166a53393c5 100644 (file)
@@ -255,7 +255,9 @@ typedef struct{
 ==============================================================================
 */
 
-int check_and_setup_channel_list(comedi_device * dev, comedi_subdevice * s, unsigned int *chanlist, unsigned int n_chan, char check);
+int check_channel_list(comedi_device * dev, comedi_subdevice * s, unsigned int *chanlist, unsigned int n_chan);
+void setup_channel_list(comedi_device * dev, comedi_subdevice * s, unsigned int *chanlist,
+       unsigned int n_chan, unsigned int seglen);
 void start_pacer(comedi_device * dev, int mode, unsigned int divisor1, unsigned int divisor2);
 static int pci1710_reset(comedi_device *dev);
 int pci171x_ai_cancel(comedi_device * dev, comedi_subdevice * s);
@@ -285,7 +287,7 @@ int pci171x_insn_read_ai(comedi_device * dev, comedi_subdevice * s, comedi_insn
        outb(0,dev->iobase + PCI171x_CLRFIFO);
        outb(0,dev->iobase + PCI171x_CLRINT);
        
-       if (!check_and_setup_channel_list(dev,s,&insn->chanspec, 1, 0))  return -EINVAL;
+       setup_channel_list(dev,s,&insn->chanspec, 1, 1);
 
 #ifdef PCI171X_EXTDEBUG
        rt_printk("adv_pci1710 A ST=%4x IO=%x\n",inw(dev->iobase+PCI171x_STATUS), dev->iobase+PCI171x_STATUS);
@@ -678,13 +680,18 @@ static void interrupt_service_pci1710(int irq, void *d, struct pt_regs *regs)
 static int pci171x_ai_docmd_and_mode(int mode, comedi_device * dev, comedi_subdevice * s) 
 {
         unsigned int divisor1, divisor2;
+       unsigned int seglen;
 
 #ifdef PCI171X_EXTDEBUG
        rt_printk("adv_pci1710 EDBG: BGN: pci171x_ai_docmd_and_mode(%d,...)\n",mode);
 #endif
        start_pacer(dev, -1, 0, 0); // stop pacer
 
-        if (!check_and_setup_channel_list(dev, s, devpriv->ai_chanlist, devpriv->ai_n_chan, 0)) return -EINVAL;
+        seglen = check_channel_list(dev, s, devpriv->ai_chanlist,
+               devpriv->ai_n_chan);
+       if(seglen<1)return -EINVAL;
+        setup_channel_list(dev, s, devpriv->ai_chanlist,
+               devpriv->ai_n_chan,seglen);
        udelay(1);
 
        outb(0, dev->iobase + PCI171x_CLRFIFO);
@@ -883,9 +890,6 @@ static int pci171x_ai_cmdtest(comedi_device *dev,comedi_subdevice *s,comedi_cmd
                if(tmp!=cmd->convert_arg)err++;
        }
 
-       if (cmd->chanlist)
-               if (!check_and_setup_channel_list(dev, s, cmd->chanlist, cmd->chanlist_len, 1)) return 5; // incorrect channels list
-
        if(err) {
 #ifdef PCI171X_EXTDEBUG
                rt_printk("adv_pci1710 EDBG: BGN: pci171x_ai_cmdtest(...) err=%d ret=4\n",err);
@@ -893,6 +897,13 @@ static int pci171x_ai_cmdtest(comedi_device *dev,comedi_subdevice *s,comedi_cmd
                return 4;
        }
 
+       /* step 5: complain about special chanlist considerations */
+
+       if (cmd->chanlist){
+               if (!check_channel_list(dev, s, cmd->chanlist,
+                       cmd->chanlist_len)) return 5; // incorrect channels list
+       }
+
 #ifdef PCI171X_EXTDEBUG
        rt_printk("adv_pci1710 EDBG: BGN: pci171x_ai_cmdtest(...) ret=0\n");
 #endif
@@ -939,18 +950,18 @@ static int pci171x_ai_cmd(comedi_device *dev,comedi_subdevice *s)
  If it's ok, then program scan/gain logic.
  This works for all cards.
 */
-int check_and_setup_channel_list(comedi_device * dev, comedi_subdevice * s, unsigned int *chanlist, unsigned int n_chan, char check) 
+int check_channel_list(comedi_device * dev, comedi_subdevice * s, unsigned int *chanlist, unsigned int n_chan)
 {
         unsigned int chansegment[32];  
-        unsigned int i, nowmustbechan, seglen, segpos,range,chanprog;
+        unsigned int i, nowmustbechan, seglen, segpos;
     
 #ifdef PCI171X_EXTDEBUG
-       rt_printk("adv_pci1710 EDBG:  check_and_setup_channel_list(...,%d)\n",n_chan);
+       rt_printk("adv_pci1710 EDBG:  check_channel_list(...,%d)\n",n_chan);
 #endif
     /* correct channel and range number check itself comedi/range.c */
        if (n_chan<1) {
-               if (!check) comedi_error(dev,"range/channel list is empty!");
-               return 0;             
+               comedi_error(dev,"range/channel list is empty!");
+               return 0;
         }
 
         if (n_chan > 1) {
@@ -960,16 +971,16 @@ int check_and_setup_channel_list(comedi_device * dev, comedi_subdevice * s, unsi
                        if (chanlist[0]==chanlist[i]) break; // we detect loop, this must by finish
                        if (CR_CHAN(chanlist[i]) & 1) // odd channel cann't by differencial
                                if (CR_AREF(chanlist[i])==AREF_DIFF) {
-                                       if (!check) rt_printk("comedi%d: adv_pci171x: Odd channel cann't be differencial input!\n", dev->minor);
-                                       return 0;             
+                                       comedi_error(dev,"Odd channel can't be differential input!\n");
+                                       return 0;
                                }
                        nowmustbechan=(CR_CHAN(chansegment[i-1])+1) % s->n_chan;
                        if (CR_AREF(chansegment[i-1])==AREF_DIFF) 
                                nowmustbechan=(nowmustbechan+1) % s->n_chan;
                        if (nowmustbechan!=CR_CHAN(chanlist[i])) { // channel list isn't continous :-(
-                               if (!check) rt_printk("comedi%d: adv_pci171x: channel list must be continous! chanlist[%i]=%d but must be %d or %d!\n",
-                                           dev->minor,i,CR_CHAN(chanlist[i]),nowmustbechan,CR_CHAN(chanlist[0]) );
-                               return 0;             
+                               rt_printk("channel list must be continous! chanlist[%i]=%d but must be %d or %d!\n",
+                                           i,CR_CHAN(chanlist[i]),nowmustbechan,CR_CHAN(chanlist[0]) );
+                               return 0;
                        }
                        chansegment[i]=chanlist[i]; // well, this is next correct channel in list
                }
@@ -977,17 +988,25 @@ int check_and_setup_channel_list(comedi_device * dev, comedi_subdevice * s, unsi
                for (i=0, segpos=0; i<n_chan; i++) {  // check whole chanlist
                        //rt_printk("%d %d=%d %d\n",CR_CHAN(chansegment[i%seglen]),CR_RANGE(chansegment[i%seglen]),CR_CHAN(chanlist[i]),CR_RANGE(chanlist[i]));
                        if (chanlist[i]!=chansegment[i%seglen]) {
-                               if (!check) rt_printk("comedi%d: adv_pci171x: bad channel, reference or range number! chanlist[%i]=%d,%d,%d and not %d,%d,%d!\n",
-                                           dev->minor,i,CR_CHAN(chansegment[i]),CR_RANGE(chansegment[i]),CR_AREF(chansegment[i]),CR_CHAN(chanlist[i%seglen]),CR_RANGE(chanlist[i%seglen]),CR_AREF(chansegment[i%seglen]));
+                               rt_printk("bad channel, reference or range number! chanlist[%i]=%d,%d,%d and not %d,%d,%d!\n",
+                                           i,CR_CHAN(chansegment[i]),CR_RANGE(chansegment[i]),CR_AREF(chansegment[i]),CR_CHAN(chanlist[i%seglen]),CR_RANGE(chanlist[i%seglen]),CR_AREF(chansegment[i%seglen]));
                                return 0; // chan/gain list is strange
                        }
                }
        } else {
                seglen=1;
        }
+       return seglen;
+}
        
-       if (check) return 1;
+void setup_channel_list(comedi_device * dev, comedi_subdevice * s, unsigned int *chanlist,
+       unsigned int n_chan, unsigned int seglen)
+{
+       unsigned int i, range, chanprog;
        
+#ifdef PCI171X_EXTDEBUG
+       rt_printk("adv_pci1710 EDBG:  setup_channel_list(...,%d,%d)\n",n_chan,seglen);
+#endif
        devpriv->act_chanlist_len=seglen;
        devpriv->act_chanlist_pos=0;
 
@@ -1014,7 +1033,6 @@ int check_and_setup_channel_list(comedi_device * dev, comedi_subdevice * s, unsi
 #ifdef PCI171X_EXTDEBUG
        rt_printk("MUX: %4x L%4x.H%4x\n", CR_CHAN(chanlist[0]) | (CR_CHAN(chanlist[seglen-1]) << 8), CR_CHAN(chanlist[0]), CR_CHAN(chanlist[seglen-1]));
 #endif
-       return 1; // we can serve this with MUX logic
 }
 
 /*