From a5c2e41f490b6240c86883a99a1d4eea1d365dcd Mon Sep 17 00:00:00 2001 From: Frank Mori Hess Date: Mon, 8 Apr 2002 01:30:22 +0000 Subject: [PATCH] added comedi_buf_put_array() writes array to buffer --- include/linux/comedidev.h | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/include/linux/comedidev.h b/include/linux/comedidev.h index 15266e1c..cf73eccd 100644 --- a/include/linux/comedidev.h +++ b/include/linux/comedidev.h @@ -307,7 +307,6 @@ static inline int alloc_private(comedi_device *dev,int size) // writes a data point to comedi's buffer, used for input static inline void comedi_buf_put(comedi_async *async, sampl_t x) { - *(sampl_t *)(async->data + async->buf_int_ptr) = x; async->buf_int_ptr += sizeof(sampl_t); if(async->buf_int_ptr >= async->data_len){ @@ -321,6 +320,37 @@ static inline void comedi_buf_put(comedi_async *async, sampl_t x) async->buf_int_count += sizeof(sampl_t); } +/* Writes an array of data points to comedi's buffer, used for input. + * Can be more efficient than comedi_buf_put() */ +static inline void comedi_buf_put_array(comedi_async *async, sampl_t* array, unsigned int length) +{ + unsigned int num_bytes; + unsigned int xfer_count = 0; + + while((num_bytes = length * sizeof(sampl_t) - xfer_count)) + { + if( async->buf_int_ptr + num_bytes > async->data_len) + num_bytes = async->data_len - async->buf_int_ptr; + + memcpy(async->data + async->buf_int_ptr + xfer_count, array, num_bytes); + + async->buf_int_ptr += num_bytes; + if(async->buf_int_ptr >= async->data_len) + { + async->buf_int_ptr %= async->data_len; + async->events |= COMEDI_CB_EOBUF; + } + async->cur_chan += num_bytes / sizeof(sampl_t); + if(async->cur_chan >= async->cmd.chanlist_len) + { + async->cur_chan %= async->cmd.chanlist_len; + async->events |= COMEDI_CB_EOS; + } + async->buf_int_count += num_bytes; + xfer_count += num_bytes; + } +} + /* Reads a data point from comedi's buffer, used for output. * returns negative value on error. */ static inline int comedi_buf_get(comedi_async *async, sampl_t *x) -- 2.26.2