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

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

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

diff --git a/drivers/staging/comedi/drivers/amplc_pci230.c 
b/drivers/staging/comedi/drivers/amplc_pci230.c
index a46fffd..5f4b6750 100644
--- a/drivers/staging/comedi/drivers/amplc_pci230.c
+++ b/drivers/staging/comedi/drivers/amplc_pci230.c
@@ -491,7 +491,6 @@ struct pci230_private {
        spinlock_t ao_stop_spinlock;    /* Spin lock for stopping AO command */
        unsigned long daqio;            /* PCI230's DAQ I/O space */
        unsigned int ai_scan_count;     /* Number of AI scans remaining */
-       unsigned int ao_scan_count;     /* Number of AO scans remaining.  */
        int intr_cpuid;                 /* ID of CPU running ISR */
        unsigned short hwver;           /* Hardware version (for '+' models) */
        unsigned short adccon;          /* ADCCON register value */
@@ -1073,13 +1072,12 @@ static void pci230_ao_stop(struct comedi_device *dev,
 static void pci230_handle_ao_nofifo(struct comedi_device *dev,
                                    struct comedi_subdevice *s)
 {
-       struct pci230_private *devpriv = dev->private;
        struct comedi_async *async = s->async;
        struct comedi_cmd *cmd = &async->cmd;
        unsigned short data;
        int i;
 
-       if (cmd->stop_src == TRIG_COUNT && devpriv->ao_scan_count == 0)
+       if (cmd->stop_src == TRIG_COUNT && async->scans_done >= cmd->stop_arg)
                return;
 
        for (i = 0; i < cmd->chanlist_len; i++) {
@@ -1093,13 +1091,8 @@ static void pci230_handle_ao_nofifo(struct comedi_device 
*dev,
                s->readback[chan] = data;
        }
 
-       if (cmd->stop_src == TRIG_COUNT) {
-               devpriv->ao_scan_count--;
-               if (devpriv->ao_scan_count == 0) {
-                       /* End of acquisition. */
-                       async->events |= COMEDI_CB_EOA;
-               }
-       }
+       if (cmd->stop_src == TRIG_COUNT && async->scans_done >= cmd->stop_arg)
+               async->events |= COMEDI_CB_EOA;
 }
 
 /*
@@ -1112,7 +1105,7 @@ static bool pci230_handle_ao_fifo(struct comedi_device 
*dev,
        struct pci230_private *devpriv = dev->private;
        struct comedi_async *async = s->async;
        struct comedi_cmd *cmd = &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;
@@ -1120,17 +1113,10 @@ static bool pci230_handle_ao_fifo(struct comedi_device 
*dev,
 
        /* Get DAC FIFO status. */
        dacstat = inw(devpriv->daqio + PCI230_DACCON);
-       /* 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_scan_count)
-                       num_scans = devpriv->ao_scan_count;
-               if (devpriv->ao_scan_count == 0) {
-                       /* End of acquisition. */
-                       events |= COMEDI_CB_EOA;
-               }
-       }
+
+       if (cmd->stop_src == TRIG_COUNT && num_scans == 0)
+               events |= COMEDI_CB_EOA;
+
        if (events == 0) {
                /* Check for FIFO underrun. */
                if (dacstat & PCI230P2_DAC_FIFO_UNDERRUN_LATCHED) {
@@ -1175,21 +1161,16 @@ static bool pci230_handle_ao_fifo(struct comedi_device 
*dev,
                        }
                }
 
-               if (cmd->stop_src == TRIG_COUNT) {
-                       devpriv->ao_scan_count -= num_scans;
-                       if (devpriv->ao_scan_count == 0) {
-                               /*
-                                * All data for the command has been written
-                                * to FIFO.  Set FIFO interrupt trigger level
-                                * to 'empty'.
-                                */
-                               devpriv->daccon =
-                                   (devpriv->daccon &
-                                    ~PCI230P2_DAC_INT_FIFO_MASK) |
-                                   PCI230P2_DAC_INT_FIFO_EMPTY;
-                               outw(devpriv->daccon,
-                                    devpriv->daqio + PCI230_DACCON);
-                       }
+               if (cmd->stop_src == TRIG_COUNT &&
+                   async->scans_done >= cmd->stop_arg) {
+                       /*
+                        * All data for the command has been written
+                        * to FIFO.  Set FIFO interrupt trigger level
+                        * to 'empty'.
+                        */
+                       devpriv->daccon &= ~PCI230P2_DAC_INT_FIFO_MASK;
+                       devpriv->daccon |= PCI230P2_DAC_INT_FIFO_EMPTY;
+                       outw(devpriv->daccon, devpriv->daqio + PCI230_DACCON);
                }
                /* Check if FIFO underrun occurred while writing to FIFO. */
                dacstat = inw(devpriv->daqio + PCI230_DACCON);
@@ -1341,8 +1322,6 @@ static int pci230_ao_cmd(struct comedi_device *dev, 
struct comedi_subdevice *s)
                        return -EBUSY;
        }
 
-       devpriv->ao_scan_count = cmd->stop_arg;
-
        /*
         * Set range - see analogue output range table; 0 => unipolar 10V,
         * 1 => bipolar +/-10V range scale
-- 
2.0.3

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

Reply via email to