pcl816: bug fix: AI scan counter was being updated after every channel in
authorIan Abbott <abbotti@mev.co.uk>
Mon, 18 Jan 2010 16:25:33 +0000 (16:25 +0000)
committerIan Abbott <abbotti@mev.co.uk>
Mon, 18 Jan 2010 16:25:33 +0000 (16:25 +0000)
non-DMA mode, or after every repeated segment of the channel list in DMA
mode.  Keep track of the current channel for each sample and update the
scan counter at the end of the scan.

comedi/drivers/pcl816.c

index b5ca45bbf71f336cfeacc6a14d72c955740a8d19..835abaa7eb821673224162126ebcd3db6f9355a8 100644 (file)
@@ -198,6 +198,7 @@ typedef struct {
        unsigned int ai_act_chanlist[16];       // MUX setting for actual AI operations
        unsigned int ai_act_chanlist_len;       // how long is actual MUX list
        unsigned int ai_act_chanlist_pos;       // actual position in MUX list
+       unsigned int ai_n_chan;         // how many channels is measured
        unsigned int ai_poll_ptr;       // how many sampes transfer poll
        comedi_subdevice *sub_ai;       // ptr to AI subdevice
 #ifdef unused
@@ -312,7 +313,9 @@ static irqreturn_t interrupt_pcl816_ai_mode13_int(int irq, void *d)
        if (++devpriv->ai_act_chanlist_pos >= devpriv->ai_act_chanlist_len)
                devpriv->ai_act_chanlist_pos = 0;
 
-       if (s->async->cur_chan == 0) {
+       s->async->cur_chan++;
+       if (s->async->cur_chan >= devpriv->ai_n_chan) {
+               s->async->cur_chan = 0;
                devpriv->ai_act_scan++;
        }
 
@@ -344,6 +347,11 @@ static void transfer_from_dma_buf(comedi_device * dev, comedi_subdevice * s,
                if (++devpriv->ai_act_chanlist_pos >=
                        devpriv->ai_act_chanlist_len) {
                        devpriv->ai_act_chanlist_pos = 0;
+               }
+
+               s->async->cur_chan++;
+               if (s->async->cur_chan >= devpriv->ai_n_chan) {
+                       s->async->cur_chan = 0;
                        devpriv->ai_act_scan++;
                }
 
@@ -636,6 +644,7 @@ static int pcl816_ai_cmd(comedi_device * dev, comedi_subdevice * s)
                return -EINVAL;
        comedi_udelay(1);
 
+       devpriv->ai_n_chan = cmd->chanlist_len;
        devpriv->ai_act_scan = 0;
        s->async->cur_chan = 0;
        devpriv->irq_blocked = 1;