From 58d6f8debd8b6995229839b95ebf0fd584468e6a Mon Sep 17 00:00:00 2001 From: Frank Mori Hess Date: Wed, 3 Sep 2003 19:15:44 +0000 Subject: [PATCH] fix problems with buffer wrap-around by using generic comedi_fc code --- comedi/drivers/dt282x.c | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/comedi/drivers/dt282x.c b/comedi/drivers/dt282x.c index b0438523..93e697d5 100644 --- a/comedi/drivers/dt282x.c +++ b/comedi/drivers/dt282x.c @@ -58,6 +58,7 @@ Notes: #include #include #include +#include "comedi_fc.h" #define DEBUG @@ -382,14 +383,13 @@ static int dt282x_ns_to_timer(int *nanosec,int round_mode); static int dt282x_grab_dma(comedi_device *dev,int dma1,int dma2); -static void dt282x_copy_to_buffer(comedi_device *dev,sampl_t *buf, +static void dt282x_munge(comedi_device *dev,sampl_t *buf, unsigned int nbytes) { comedi_async *async = dev->subdevices[0].async; unsigned int i; unsigned short mask=(1<ad_2scomp){ @@ -398,19 +398,11 @@ static void dt282x_copy_to_buffer(comedi_device *dev,sampl_t *buf, sign = 0; } - abuf = async->prealloc_buf + async->buf_write_ptr; - if(async->buf_write_ptr + nbytes >= async->prealloc_bufsz){ - n = (async->prealloc_bufsz - async->buf_write_ptr - nbytes)/2; - for(i=0;iprealloc_buf; - buf = buf + i; - } + if( nbytes % 2 ) + comedi_error( dev, "bug! odd number of bytes from dma xfer" ); n = nbytes/2; for(i=0;icurrent_dma_chan = 1-i; - ret = comedi_buf_write_alloc(s->async, size); - if(!ret){ - rt_printk("dt282x: AI buffer overflow\n"); - s->async->events |= COMEDI_CB_OVERFLOW; - comedi_event(dev,s,s->async->events); - return; - } - dt282x_copy_to_buffer(dev, ptr, size); - comedi_buf_write_free(s->async, size); + dt282x_munge(dev, ptr, size ); + ret = cfc_write_array_to_buffer( s, ptr, size ); + if( ret == 0 ) return; devpriv->nread-=size/2; -- 2.26.2