staging: comedi: drivers: introduce comedi_nsamples_left()
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Wed, 5 Nov 2014 17:31:33 +0000 (10:31 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 7 Nov 2014 17:29:41 +0000 (09:29 -0800)
Introduce a helper function to calculate the number of samples remaining
when the cmd->stop_src is TRIG_COUNT.

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/comedidev.h
drivers/staging/comedi/drivers.c

index 616e9b08c026f0668c1eca161a94cc3e9534be0b..77be191988ca532dc5791a2af4e5717b7f75a827 100644 (file)
@@ -518,6 +518,8 @@ unsigned int comedi_dio_update_state(struct comedi_subdevice *,
 unsigned int comedi_bytes_per_scan(struct comedi_subdevice *s);
 unsigned int comedi_nscans_left(struct comedi_subdevice *s,
                                unsigned int nscans);
+unsigned int comedi_nsamples_left(struct comedi_subdevice *s,
+                                 unsigned int nsamples);
 void comedi_inc_scan_progress(struct comedi_subdevice *s,
                              unsigned int num_bytes);
 
index 00194a5092cf17f7a28c5e8f6628e4de1bd3dc77..82ac84504589e01f25b115cf1aba5e33ec15bef9 100644 (file)
@@ -366,6 +366,38 @@ unsigned int comedi_nscans_left(struct comedi_subdevice *s,
 }
 EXPORT_SYMBOL_GPL(comedi_nscans_left);
 
+/**
+ * comedi_nsamples_left - return the number of samples left in the command
+ * @s: comedi_subdevice struct
+ * @nsamples: the expected number of samples
+ *
+ * Returns the expected number of samples of the number of samples remaining
+ * in the command.
+ */
+unsigned int comedi_nsamples_left(struct comedi_subdevice *s,
+                                 unsigned int nsamples)
+{
+       struct comedi_async *async = s->async;
+       struct comedi_cmd *cmd = &async->cmd;
+
+       if (cmd->stop_src == TRIG_COUNT) {
+               /* +1 to force comedi_nscans_left() to return the scans left */
+               unsigned int nscans = (nsamples / cmd->scan_end_arg) + 1;
+               unsigned int scans_left = comedi_nscans_left(s, nscans);
+               unsigned long long samples_left = 0;
+
+               if (scans_left) {
+                       samples_left = ((unsigned long long)scans_left *
+                                      cmd->scan_end_arg) - async->cur_chan;
+               }
+
+               if (samples_left < nsamples)
+                       nsamples = samples_left;
+       }
+       return nsamples;
+}
+EXPORT_SYMBOL_GPL(comedi_nsamples_left);
+
 /**
  * comedi_inc_scan_progress - update scan progress in asynchronous command
  * @s: comedi_subdevice struct