From e73c24b951409d812386765d50f5d2d73ee88066 Mon Sep 17 00:00:00 2001 From: Frank Mori Hess Date: Mon, 29 Apr 2002 21:13:13 +0000 Subject: [PATCH] added comedi_data_read_n() --- include/comedilib.h | 2 ++ lib/data.c | 28 +++++++++++++++++++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/include/comedilib.h b/include/comedilib.h index df0104b..3e0fe7b 100644 --- a/include/comedilib.h +++ b/include/comedilib.h @@ -118,6 +118,8 @@ lsampl_t comedi_from_phys(double data,comedi_range *rng,lsampl_t maxdata); /* syncronous stuff */ int comedi_data_read(comedi_t *it,unsigned int subd,unsigned int chan, unsigned int range,unsigned int aref,lsampl_t *data); +int comedi_data_read_n(comedi_t *it,unsigned int subd,unsigned int chan, + unsigned int range,unsigned int aref,lsampl_t *data, unsigned int n); int comedi_data_read_hint(comedi_t *it,unsigned int subd,unsigned int chan, unsigned int range,unsigned int aref); int comedi_data_read_delayed(comedi_t *it,unsigned int subd,unsigned int chan, diff --git a/lib/data.c b/lib/data.c index fdec01b..0028fc4 100644 --- a/lib/data.c +++ b/lib/data.c @@ -85,7 +85,7 @@ int comedi_data_write(comedi_t *it,unsigned int subdev,unsigned int chan,unsigne } } -int comedi_data_read_n(comedi_t *it, unsigned int subdev, unsigned int chan, unsigned int range, +static inline int comedi_internal_data_read_n(comedi_t *it, unsigned int subdev, unsigned int chan, unsigned int range, unsigned int aref, lsampl_t *data, unsigned int n) { subdevice *s; @@ -144,17 +144,39 @@ int comedi_data_read_n(comedi_t *it, unsigned int subdev, unsigned int chan, uns } } +int comedi_data_read_n(comedi_t *it, unsigned int subdev, unsigned int chan, unsigned int range, + unsigned int aref, lsampl_t *data, unsigned int n) +{ + static const int max_chunk_size = 100; + unsigned int chunk_size; + unsigned int sample_count = 0; + int retval; + + while( n ) + { + if( n > max_chunk_size) + chunk_size = max_chunk_size; + else + chunk_size = n; + retval = comedi_internal_data_read_n( it, subdev, chan, range, aref, &data[sample_count], chunk_size); + if( retval < 0 ) return retval; + n -= chunk_size; + sample_count += chunk_size; + } + return 0; +} + int comedi_data_read(comedi_t *it, unsigned int subdev, unsigned int chan, unsigned int range, unsigned int aref, lsampl_t *data) { - return comedi_data_read_n(it, subdev, chan, range, aref, data, 1); + return comedi_internal_data_read_n(it, subdev, chan, range, aref, data, 1); } int comedi_data_read_hint(comedi_t *it,unsigned int subdev,unsigned int chan,unsigned int range, unsigned int aref) { lsampl_t dummy_data; - return comedi_data_read_n(it, subdev, chan, range, aref, &dummy_data, 0); + return comedi_internal_data_read_n(it, subdev, chan, range, aref, &dummy_data, 0); } int comedi_data_read_delayed( comedi_t *it, unsigned int subdev, unsigned int chan, unsigned int range, -- 2.26.2