Remove the private data member 'ao_stop_count' and use the comedi_async
'scans_done' member to detect the end-of-acquisition.

Use the helper function comedi_nscans_left() to determine the number of scans
available in the async buffer or left in the command.

Signed-off-by: H Hartley Sweeten <hswee...@visionengravers.com>
Cc: Ian Abbott <abbo...@mev.co.uk>
Cc: Greg Kroah-Hartman <gre...@linuxfoundation.org>
---
 drivers/staging/comedi/drivers/amplc_pci224.c | 43 ++++++++-------------------
 1 file changed, 12 insertions(+), 31 deletions(-)

diff --git a/drivers/staging/comedi/drivers/amplc_pci224.c 
b/drivers/staging/comedi/drivers/amplc_pci224.c
index 342779f..a896f01 100644
--- a/drivers/staging/comedi/drivers/amplc_pci224.c
+++ b/drivers/staging/comedi/drivers/amplc_pci224.c
@@ -381,7 +381,6 @@ struct pci224_private {
        unsigned short daccon;
        unsigned int cached_div1;
        unsigned int cached_div2;
-       unsigned int ao_stop_count;
        unsigned short ao_enab; /* max 16 channels so 'short' will do */
        unsigned char intsce;
 };
@@ -514,26 +513,18 @@ static void pci224_ao_handle_fifo(struct comedi_device 
*dev,
 {
        struct pci224_private *devpriv = dev->private;
        struct comedi_cmd *cmd = &s->async->cmd;
-       unsigned int num_scans;
+       unsigned int num_scans = comedi_nscans_left(s, 0);
        unsigned int room;
        unsigned short dacstat;
        unsigned int i, n;
 
-       /* Determine number of scans available in buffer. */
-       num_scans = comedi_buf_read_n_available(s) / comedi_bytes_per_scan(s);
-       if (cmd->stop_src == TRIG_COUNT) {
-               /* Fixed number of scans. */
-               if (num_scans > devpriv->ao_stop_count)
-                       num_scans = devpriv->ao_stop_count;
-       }
-
        /* Determine how much room is in the FIFO (in samples). */
        dacstat = inw(dev->iobase + PCI224_DACCON);
        switch (dacstat & PCI224_DACCON_FIFOFL_MASK) {
        case PCI224_DACCON_FIFOFL_EMPTY:
                room = PCI224_FIFO_ROOM_EMPTY;
                if (cmd->stop_src == TRIG_COUNT &&
-                   devpriv->ao_stop_count == 0) {
+                   s->async->scans_done >= cmd->stop_arg) {
                        /* FIFO empty at end of counted acquisition. */
                        s->async->events |= COMEDI_CB_EOA;
                        comedi_handle_events(dev, s);
@@ -574,18 +565,16 @@ static void pci224_ao_handle_fifo(struct comedi_device 
*dev,
                             dev->iobase + PCI224_DACDATA);
                }
        }
-       if (cmd->stop_src == TRIG_COUNT) {
-               devpriv->ao_stop_count -= num_scans;
-               if (devpriv->ao_stop_count == 0) {
-                       /*
-                        * Change FIFO interrupt trigger level to wait
-                        * until FIFO is empty.
-                        */
-                       devpriv->daccon = COMBINE(devpriv->daccon,
-                                                 PCI224_DACCON_FIFOINTR_EMPTY,
-                                                 PCI224_DACCON_FIFOINTR_MASK);
-                       outw(devpriv->daccon, dev->iobase + PCI224_DACCON);
-               }
+       if (cmd->stop_src == TRIG_COUNT &&
+           s->async->scans_done >= cmd->stop_arg) {
+               /*
+                * Change FIFO interrupt trigger level to wait
+                * until FIFO is empty.
+                */
+               devpriv->daccon = COMBINE(devpriv->daccon,
+                                         PCI224_DACCON_FIFOINTR_EMPTY,
+                                         PCI224_DACCON_FIFOINTR_MASK);
+               outw(devpriv->daccon, dev->iobase + PCI224_DACCON);
        }
        if ((devpriv->daccon & PCI224_DACCON_TRIG_MASK) ==
            PCI224_DACCON_TRIG_NONE) {
@@ -907,14 +896,6 @@ static int pci224_ao_cmd(struct comedi_device *dev, struct 
comedi_subdevice *s)
        if (cmd->scan_begin_src == TRIG_TIMER)
                pci224_ao_start_pacer(dev, s);
 
-       /*
-        * Sort out end of acquisition.
-        */
-       if (cmd->stop_src == TRIG_COUNT)
-               devpriv->ao_stop_count = cmd->stop_arg;
-       else    /* TRIG_EXT | TRIG_NONE */
-               devpriv->ao_stop_count = 0;
-
        spin_lock_irqsave(&devpriv->ao_spinlock, flags);
        if (cmd->start_src == TRIG_INT) {
                s->async->inttrig = pci224_ao_inttrig_start;
-- 
2.0.3

_______________________________________________
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

Reply via email to