mirror of https://gitee.com/openkylin/linux.git
staging: comedi: comedi_buf: introduce comedi_buf_read_samples()
Introduce a generic method to read samples from the async buffer. The number of requested samples is clampled to the number of samples that would fill the async buffer. The size of each sample is determined using the bytes_per_sample() helper. The number of bytes need are then read from the async buffer using comedi_read_array_from_buffer(). This will allow converting all the comedi drivers to use a common method to read data from the async buffer. Since comedi_read_array_from_buffer() sets the COMEDI_CB_BLOCK event after reading the data, those events can be removed from the drivers. In addition, comedi_inc_scan_progress() will automatically detect the end of scan and set the COMEDI_CB_EOS event. Those events can also be removed from the drivers. 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
22be3f8142
commit
4455d7c351
|
@ -575,3 +575,30 @@ unsigned int comedi_read_array_from_buffer(struct comedi_subdevice *s,
|
||||||
return num_bytes;
|
return num_bytes;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(comedi_read_array_from_buffer);
|
EXPORT_SYMBOL_GPL(comedi_read_array_from_buffer);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* comedi_buf_read_samples - read sample data from comedi buffer
|
||||||
|
* @s: comedi_subdevice struct
|
||||||
|
* @data: destination
|
||||||
|
* @nsamples: maximum number of samples to read
|
||||||
|
*
|
||||||
|
* Reads up to nsamples from the comedi buffer associated with the subdevice,
|
||||||
|
* marks it as read and updates the acquisition scan progress.
|
||||||
|
*
|
||||||
|
* Returns the amount of data read in bytes.
|
||||||
|
*/
|
||||||
|
unsigned int comedi_buf_read_samples(struct comedi_subdevice *s,
|
||||||
|
void *data, unsigned int nsamples)
|
||||||
|
{
|
||||||
|
unsigned int max_samples;
|
||||||
|
unsigned int nbytes;
|
||||||
|
|
||||||
|
max_samples = s->async->prealloc_bufsz / bytes_per_sample(s);
|
||||||
|
if (nsamples > max_samples)
|
||||||
|
nsamples = max_samples;
|
||||||
|
|
||||||
|
nbytes = nsamples * bytes_per_sample(s);
|
||||||
|
|
||||||
|
return comedi_read_array_from_buffer(s, data, nbytes);
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL_GPL(comedi_buf_read_samples);
|
||||||
|
|
|
@ -453,6 +453,8 @@ unsigned int comedi_write_array_to_buffer(struct comedi_subdevice *s,
|
||||||
unsigned int num_bytes);
|
unsigned int num_bytes);
|
||||||
unsigned int comedi_read_array_from_buffer(struct comedi_subdevice *s,
|
unsigned int comedi_read_array_from_buffer(struct comedi_subdevice *s,
|
||||||
void *data, unsigned int num_bytes);
|
void *data, unsigned int num_bytes);
|
||||||
|
unsigned int comedi_buf_read_samples(struct comedi_subdevice *s,
|
||||||
|
void *data, unsigned int nsamples);
|
||||||
|
|
||||||
/* drivers.c - general comedi driver functions */
|
/* drivers.c - general comedi driver functions */
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue