summaryrefslogtreecommitdiff
path: root/drivers/staging/comedi
diff options
context:
space:
mode:
authorIan Abbott <abbotti@mev.co.uk>2015-10-27 16:59:15 +0000
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2015-10-29 08:58:36 +0900
commit8fa8a260d22b5a6da088afb12e3321a35f397104 (patch)
tree9624b0cd48a840f56bfc8409d218e7ce72316549 /drivers/staging/comedi
parent783ddaebd3978cb9a1c6899899b2208a96d2b9f0 (diff)
staging: comedi: comedi_test: move modulo operations for waveform
The fake waveform generator functions, `fake_sawtooth()` and `fake_squarewave()`, called from `fake_waveform()`, have a `current_time` parameter which is the time since the start of a waveform period. The parameter value may be greater than the waveform period so they do a modulo operation to bring it into range. Do the modulo operations outside the functions in `waveform_ai_interrupt()` so that the waveform generator functions always get a `current_time` parameter less than the waveform period and do not have to do the modulo operation themselves. Also, only do the modulo operations when the time since the start of a waveform exceeds the waveform period. Usually, several samples are produced in each waveform period and modulo operations are typically more expensive than a simple comparison. Signed-off-by: Ian Abbott <abbotti@mev.co.uk> Reviewed-by: H Hartley Sweeten <hsweeten@visionengravers.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/staging/comedi')
-rw-r--r--drivers/staging/comedi/drivers/comedi_test.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/drivers/staging/comedi/drivers/comedi_test.c b/drivers/staging/comedi/drivers/comedi_test.c
index cc35bd645d1b..021522882905 100644
--- a/drivers/staging/comedi/drivers/comedi_test.c
+++ b/drivers/staging/comedi/drivers/comedi_test.c
@@ -97,7 +97,6 @@ static unsigned short fake_sawtooth(struct comedi_device *dev,
binary_amplitude *= devpriv->uvolt_amplitude;
do_div(binary_amplitude, krange->max - krange->min);
- current_time %= devpriv->usec_period;
value = current_time;
value *= binary_amplitude * 2;
do_div(value, devpriv->usec_period);
@@ -125,7 +124,6 @@ static unsigned short fake_squarewave(struct comedi_device *dev,
const struct comedi_krange *krange =
&s->range_table->range[range_index];
- current_time %= devpriv->usec_period;
value = s->maxdata;
value *= devpriv->uvolt_amplitude;
do_div(value, krange->max - krange->min);
@@ -206,20 +204,24 @@ static void waveform_ai_interrupt(unsigned long arg)
num_scans = comedi_nscans_left(s, num_scans);
for (i = 0; i < num_scans; i++) {
+ unsigned long scan_remain_period = devpriv->scan_period;
+
for (j = 0; j < cmd->chanlist_len; j++) {
unsigned short sample;
+ if (devpriv->usec_current >= devpriv->usec_period)
+ devpriv->usec_current %= devpriv->usec_period;
sample = fake_waveform(dev, CR_CHAN(cmd->chanlist[j]),
CR_RANGE(cmd->chanlist[j]),
- devpriv->usec_current +
- i * devpriv->scan_period +
- j * devpriv->convert_period);
+ devpriv->usec_current);
comedi_buf_write_samples(s, &sample, 1);
+ devpriv->usec_current += devpriv->convert_period;
+ scan_remain_period -= devpriv->convert_period;
}
+ devpriv->usec_current += scan_remain_period;
}
-
- devpriv->usec_current += elapsed_time;
- devpriv->usec_current %= devpriv->usec_period;
+ if (devpriv->usec_current >= devpriv->usec_period)
+ devpriv->usec_current %= devpriv->usec_period;
if (cmd->stop_src == TRIG_COUNT && async->scans_done >= cmd->stop_arg)
async->events |= COMEDI_CB_EOA;