staging: comedi: ni_mio_common: tidy up ni_ao_munge()
Use the bytes_per_sample() helper instead of 'sizeof(short)' to clarify the length calculation. Use comedi_offset_munge() to handle the unsigned to two's complement munge of the data for bipolar ranges. Tidy up the local variables. 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>
This commit is contained in:
parent
a52b53e4a7
commit
a10817d67f
@ -2886,28 +2886,30 @@ static int ni_ai_insn_config(struct comedi_device *dev,
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* munge data from unsigned to 2's complement for analog output bipolar modes */
|
|
||||||
static void ni_ao_munge(struct comedi_device *dev, struct comedi_subdevice *s,
|
static void ni_ao_munge(struct comedi_device *dev, struct comedi_subdevice *s,
|
||||||
void *data, unsigned int num_bytes,
|
void *data, unsigned int num_bytes,
|
||||||
unsigned int chan_index)
|
unsigned int chan_index)
|
||||||
{
|
{
|
||||||
const struct ni_board_struct *board = comedi_board(dev);
|
struct comedi_cmd *cmd = &s->async->cmd;
|
||||||
struct comedi_async *async = s->async;
|
unsigned int length = num_bytes / bytes_per_sample(s);
|
||||||
struct comedi_cmd *cmd = &async->cmd;
|
|
||||||
unsigned int length = num_bytes / sizeof(short);
|
|
||||||
unsigned int offset = 1 << (board->aobits - 1);
|
|
||||||
unsigned short *array = data;
|
unsigned short *array = data;
|
||||||
unsigned int range;
|
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
for (i = 0; i < length; i++) {
|
for (i = 0; i < length; i++) {
|
||||||
range = CR_RANGE(cmd->chanlist[chan_index]);
|
unsigned int range = CR_RANGE(cmd->chanlist[chan_index]);
|
||||||
|
unsigned short val = array[i];
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Munge data from unsigned to two's complement for
|
||||||
|
* bipolar ranges.
|
||||||
|
*/
|
||||||
if (comedi_range_is_bipolar(s, range))
|
if (comedi_range_is_bipolar(s, range))
|
||||||
array[i] -= offset;
|
val = comedi_offset_munge(s, val);
|
||||||
#ifdef PCIDMA
|
#ifdef PCIDMA
|
||||||
array[i] = cpu_to_le16(array[i]);
|
val = cpu_to_le16(val);
|
||||||
#endif
|
#endif
|
||||||
|
array[i] = val;
|
||||||
|
|
||||||
chan_index++;
|
chan_index++;
|
||||||
chan_index %= cmd->chanlist_len;
|
chan_index %= cmd->chanlist_len;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user