staging: comedi: usbduxfast: use comedi_async 'scans_done' to detect AI EOA
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Wed, 5 Nov 2014 17:31:35 +0000 (10:31 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 7 Nov 2014 17:29:41 +0000 (09:29 -0800)
Remove the private data member 'ai_sample_count' and use the comedi_async
'scans_done' member to detect the analog input end-of-acquisition.

Use the comedi_nsamples_left() helper to get the number of samples to actually
add to the async buffer.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/comedi/drivers/usbduxfast.c

index 5de76aba8fd9ae36ef5da050a4a6943015c2f720..ddc4cb9d5ed468a35274f89d806f3ffb45f1befb 100644 (file)
@@ -161,7 +161,6 @@ struct usbduxfast_private {
        uint8_t *duxbuf;
        int8_t *inbuf;
        short int ai_cmd_running;       /* asynchronous command is running */
-       long int ai_sample_count;       /* number of samples to acquire */
        int ignore;             /* counter which ignores the first
                                   buffers */
        struct semaphore sem;
@@ -251,15 +250,12 @@ static void usbduxfast_ai_handle_urb(struct comedi_device *dev,
                unsigned int nsamples;
 
                nsamples = comedi_bytes_to_samples(s, urb->actual_length);
-               if (cmd->stop_src == TRIG_COUNT) {
-                       if (devpriv->ai_sample_count < nsamples) {
-                               nsamples = devpriv->ai_sample_count;
-                               async->events |= COMEDI_CB_EOA;
-                       }
-                       devpriv->ai_sample_count -= nsamples;
-               }
-
+               nsamples = comedi_nsamples_left(s, nsamples);
                comedi_buf_write_samples(s, urb->transfer_buffer, nsamples);
+
+               if (cmd->stop_src == TRIG_COUNT &&
+                   async->scans_done >= cmd->stop_arg)
+                       async->events |= COMEDI_CB_EOA;
        }
 
        /* if command is still running, resubmit urb for BULK transfer */
@@ -788,11 +784,6 @@ static int usbduxfast_ai_cmd(struct comedi_device *dev,
                return result;
        }
 
-       if (cmd->stop_src == TRIG_COUNT)
-               devpriv->ai_sample_count = cmd->stop_arg * cmd->scan_end_arg;
-       else    /* TRIG_NONE */
-               devpriv->ai_sample_count = 0;
-
        if ((cmd->start_src == TRIG_NOW) || (cmd->start_src == TRIG_EXT)) {
                /* enable this acquisition operation */
                devpriv->ai_cmd_running = 1;