Commit fb1ef622 authored by H Hartley Sweeten's avatar H Hartley Sweeten Committed by Greg Kroah-Hartman

staging: comedi: usbduxsigma: tidy up analog output command support

Rename the (*do_cmdtest) and (*do_cmd) functions so they have namespace
associated with the driver. Rename the local variable used for the
private data pointer.

Move all the command argument initialization and testing into the
(*do_cmdtest) function. That function is always called by the comedi
core before the (*do_cmd) function. The only thing the (*do_cmd) function
should have to do is setup the channel list, initialize the counter for
the conversion, then either start the conversion (submit the urbs) or
set the trigger to start the conversion.
Signed-off-by: default avatarH Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 8cd6f5eb
...@@ -930,18 +930,23 @@ static int usbduxsigma_ao_inttrig(struct comedi_device *dev, ...@@ -930,18 +930,23 @@ static int usbduxsigma_ao_inttrig(struct comedi_device *dev,
return 1; return 1;
} }
static int usbdux_ao_cmdtest(struct comedi_device *dev, static int usbduxsigma_ao_cmdtest(struct comedi_device *dev,
struct comedi_subdevice *s, struct comedi_subdevice *s,
struct comedi_cmd *cmd) struct comedi_cmd *cmd)
{ {
struct usbduxsigma_private *devpriv = dev->private;
int err = 0; int err = 0;
int high_speed;
unsigned int flags; unsigned int flags;
/* high speed conversions are not used yet */
high_speed = 0; /* (devpriv->high_speed) */
/* Step 1 : check if triggers are trivially valid */ /* Step 1 : check if triggers are trivially valid */
err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW | TRIG_INT); err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW | TRIG_INT);
if (0) { /* (this_usbduxsub->high_speed) */ if (high_speed) {
/* /*
* start immediately a new scan * start immediately a new scan
* the sampling rate is set by the coversion rate * the sampling rate is set by the coversion rate
...@@ -957,8 +962,10 @@ static int usbdux_ao_cmdtest(struct comedi_device *dev, ...@@ -957,8 +962,10 @@ static int usbdux_ao_cmdtest(struct comedi_device *dev,
err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT); err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE); err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE);
if (err) if (err) {
up(&devpriv->sem);
return 1; return 1;
}
/* Step 2a : make sure trigger sources are unique */ /* Step 2a : make sure trigger sources are unique */
...@@ -997,81 +1004,83 @@ static int usbdux_ao_cmdtest(struct comedi_device *dev, ...@@ -997,81 +1004,83 @@ static int usbdux_ao_cmdtest(struct comedi_device *dev,
if (err) if (err)
return 3; return 3;
return 0; /* Step 4: fix up any arguments */
}
static int usbdux_ao_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
{
struct usbduxsigma_private *this_usbduxsub = dev->private;
struct comedi_cmd *cmd = &s->async->cmd;
unsigned int chan, gain;
int i, ret;
down(&this_usbduxsub->sem); /* we count in timer steps */
/* set current channel of the running acquisition to zero */ if (high_speed) {
s->async->cur_chan = 0;
for (i = 0; i < cmd->chanlist_len; ++i) {
chan = CR_CHAN(cmd->chanlist[i]);
gain = CR_RANGE(cmd->chanlist[i]);
this_usbduxsub->dac_commands[i] = chan;
}
/* we count in steps of 1ms (125us) */
/* 125us mode not used yet */
if (0) { /* (this_usbduxsub->high_speed) */
/* 125us */
/* timing of the conversion itself: every 125 us */ /* timing of the conversion itself: every 125 us */
this_usbduxsub->ao_timer = cmd->convert_arg / 125000; devpriv->ao_timer = cmd->convert_arg / 125000;
} else { } else {
/* 1ms */ /*
/* timing of the scan: we get all channels at once */ * timing of the scan: every 1ms
this_usbduxsub->ao_timer = cmd->scan_begin_arg / 1000000; * we get all channels at once
if (this_usbduxsub->ao_timer < 1) { */
up(&this_usbduxsub->sem); devpriv->ao_timer = cmd->scan_begin_arg / 1000000;
return -EINVAL; if (devpriv->ao_timer < 1)
} err |= -EINVAL;
} }
this_usbduxsub->ao_counter = this_usbduxsub->ao_timer;
if (cmd->stop_src == TRIG_COUNT) { if (cmd->stop_src == TRIG_COUNT) {
/* not continuous */ /* not continuous, use counter */
/* counter */ if (high_speed) {
/* high speed also scans everything at once */ /* high speed also scans everything at once */
if (0) { /* (this_usbduxsub->high_speed) */ devpriv->ao_sample_count = cmd->stop_arg *
this_usbduxsub->ao_sample_count = cmd->scan_end_arg;
(cmd->stop_arg) * (cmd->scan_end_arg);
} else { } else {
/* there's no scan as the scan has been */ /*
/* perf inside the FX2 */ * There's no scan as the scan has been
/* data arrives as one packet */ * handled inside the FX2. Data arrives as
this_usbduxsub->ao_sample_count = cmd->stop_arg; * one packet.
*/
devpriv->ao_sample_count = cmd->stop_arg;
} }
this_usbduxsub->ao_continuous = 0; devpriv->ao_continuous = 0;
} else { } else {
/* continuous acquisition */ /* continuous acquisition */
this_usbduxsub->ao_continuous = 1; devpriv->ao_continuous = 1;
this_usbduxsub->ao_sample_count = 0; devpriv->ao_sample_count = 0;
} }
if (err)
return 4;
return 0;
}
static int usbduxsigma_ao_cmd(struct comedi_device *dev,
struct comedi_subdevice *s)
{
struct usbduxsigma_private *devpriv = dev->private;
struct comedi_cmd *cmd = &s->async->cmd;
int ret;
int i;
down(&devpriv->sem);
/* set current channel of the running acquisition to zero */
s->async->cur_chan = 0;
for (i = 0; i < cmd->chanlist_len; ++i)
devpriv->dac_commands[i] = CR_CHAN(cmd->chanlist[i]);
devpriv->ao_counter = devpriv->ao_timer;
if (cmd->start_src == TRIG_NOW) { if (cmd->start_src == TRIG_NOW) {
/* enable this acquisition operation */ /* enable this acquisition operation */
ret = usbduxsigma_submit_urbs(dev, this_usbduxsub->urbOut, ret = usbduxsigma_submit_urbs(dev, devpriv->urbOut,
this_usbduxsub->numOfOutBuffers, devpriv->numOfOutBuffers, 0);
0);
if (ret < 0) { if (ret < 0) {
up(&this_usbduxsub->sem); up(&devpriv->sem);
return ret; return ret;
} }
this_usbduxsub->ao_cmd_running = 1;
s->async->inttrig = NULL; s->async->inttrig = NULL;
} else { devpriv->ao_cmd_running = 1;
/* TRIG_INT */ } else { /* TRIG_INT */
/* submit the urbs later */ /* wait for an internal signal and submit the urbs later */
/* wait for an internal signal */
s->async->inttrig = usbduxsigma_ao_inttrig; s->async->inttrig = usbduxsigma_ao_inttrig;
} }
up(&this_usbduxsub->sem); up(&devpriv->sem);
return 0; return 0;
} }
...@@ -1461,8 +1470,8 @@ static int usbduxsigma_attach_common(struct comedi_device *dev) ...@@ -1461,8 +1470,8 @@ static int usbduxsigma_attach_common(struct comedi_device *dev)
s->range_table = &range_unipolar2_5; s->range_table = &range_unipolar2_5;
s->insn_write = usbdux_ao_insn_write; s->insn_write = usbdux_ao_insn_write;
s->insn_read = usbdux_ao_insn_read; s->insn_read = usbdux_ao_insn_read;
s->do_cmdtest = usbdux_ao_cmdtest; s->do_cmdtest = usbduxsigma_ao_cmdtest;
s->do_cmd = usbdux_ao_cmd; s->do_cmd = usbduxsigma_ao_cmd;
s->cancel = usbdux_ao_cancel; s->cancel = usbdux_ao_cancel;
/* Digital I/O subdevice */ /* Digital I/O subdevice */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment