From da9a91703feab8dc309b2de1ba822f3ac05da42e Mon Sep 17 00:00:00 2001 From: David Schleef Date: Tue, 9 Jul 2002 03:35:16 +0000 Subject: [PATCH] More buffer fixes. AI and AO work now. --- comedi/comedi_fops.c | 1 + comedi/comedi_ksyms.c | 4 ++ comedi/drivers/ni_mio_common.c | 73 +++++++++++++++++++--------------- 3 files changed, 45 insertions(+), 33 deletions(-) diff --git a/comedi/comedi_fops.c b/comedi/comedi_fops.c index d11226c6..03e8645a 100644 --- a/comedi/comedi_fops.c +++ b/comedi/comedi_fops.c @@ -1375,6 +1375,7 @@ static ssize_t comedi_write_v22(struct file *file,const char *buf,size_t nbytes, n -= m; retval = -EFAULT; } + comedi_buf_write_free(async, n); count+=n; nbytes-=n; diff --git a/comedi/comedi_ksyms.c b/comedi/comedi_ksyms.c index 08e7438f..219d8946 100644 --- a/comedi/comedi_ksyms.c +++ b/comedi/comedi_ksyms.c @@ -67,6 +67,10 @@ EXPORT_SYMBOL(check_chanlist); EXPORT_SYMBOL(comedi_buf_put); EXPORT_SYMBOL(comedi_buf_get); EXPORT_SYMBOL(comedi_buf_read_n_available); +EXPORT_SYMBOL(comedi_buf_copy_from); +EXPORT_SYMBOL(comedi_buf_write_free); +EXPORT_SYMBOL(comedi_buf_write_alloc); +EXPORT_SYMBOL(comedi_buf_read_free); #endif diff --git a/comedi/drivers/ni_mio_common.c b/comedi/drivers/ni_mio_common.c index 7ba3b430..410daf5d 100644 --- a/comedi/drivers/ni_mio_common.c +++ b/comedi/drivers/ni_mio_common.c @@ -1604,12 +1604,12 @@ static int ni_ai_config_analog_trig(comedi_device *dev,comedi_subdevice *s, } -// munge data from unsigned to 2's complement for analog output bipolar modes +#if 0 +/* munge data from unsigned to 2's complement for analog output bipolar modes */ static void ni_ao_munge(comedi_device *dev, comedi_subdevice *s, sampl_t *array, unsigned int length) { comedi_async *async = s->async; - comedi_cmd *cmd = &async->cmd; unsigned int range; unsigned int i; unsigned int offset; @@ -1620,7 +1620,7 @@ static void ni_ao_munge(comedi_device *dev, comedi_subdevice *s, { channel_index = (async->cur_chan + i) % cmd->chanlist_len; range = CR_RANGE(cmd->chanlist[channel_index]); - // if it's a unipolar range, no munging is required + /* if it's a unipolar range, no munging is required */ if(boardtype.ao_unipolar && (range & 1)) continue; @@ -1628,35 +1628,42 @@ static void ni_ao_munge(comedi_device *dev, comedi_subdevice *s, array[i] -= offset; } } +#endif -static void ni_ao_fifo_load(comedi_device *dev,comedi_subdevice *s, - sampl_t *data,int n) +static void ni_ao_fifo_load(comedi_device *dev,comedi_subdevice *s, int n) { comedi_async *async = s->async; + comedi_cmd *cmd = &async->cmd; + int chan; int i; - - // do any munging necessary - ni_ao_munge(dev, s, data, n); + int port; + sampl_t d; + int range; + int offset; if(boardtype.reg_611x){ - for(i=0;icur_chan = (async->cur_chan + n) % async->cmd.chanlist_len; - // increment async buf_int_count and buf_int_ptr - async->buf_read_count += n * sizeof(sampl_t); - async->buf_read_ptr += n * sizeof(sampl_t); - // check if we have reached end of buffer - if(async->buf_read_ptr >= async->data_len) - { - async->buf_read_ptr -= async->data_len; - // this shouldn't ever happen - if(async->buf_read_ptr >= async->data_len) - comedi_error(dev, "ao bug!"); +printk("ao_fifo_load %d\n",n); + offset = 1 << (boardtype.aobits - 1); + chan = async->cur_chan; + for(i=0;ichanlist[chan]); + if(!boardtype.ao_unipolar || !(range & 1)){ + d -= offset; + } + + ni_writew(d,port); + + chan++; + if(chan>=cmd->chanlist_len)chan=0; } + async->cur_chan = chan; } @@ -1678,19 +1685,16 @@ static void ni_ao_fifo_load(comedi_device *dev,comedi_subdevice *s, */ static int ni_ao_fifo_half_empty(comedi_device *dev,comedi_subdevice *s) { - int n,m; + int n; - n=(s->async->buf_read_count - s->async->buf_write_count) / sizeof(sampl_t); + n = comedi_buf_read_n_available(s->async); if(n==0)return 0; + + n /= sizeof(sampl_t); if(n>boardtype.ao_fifo_depth/2) n=boardtype.ao_fifo_depth/2; - if(s->async->buf_read_ptr+n*sizeof(sampl_t)>s->async->data_len){ - m=(s->async->data_len-s->async->buf_read_ptr)/sizeof(sampl_t); - ni_ao_fifo_load(dev,s,s->async->data+s->async->buf_read_ptr,m); - n-=m; - } - ni_ao_fifo_load(dev,s,s->async->data+s->async->buf_read_ptr,n); + ni_ao_fifo_load(dev,s,n); s->async->events |= COMEDI_CB_BLOCK; @@ -1705,12 +1709,14 @@ static int ni_ao_prep_fifo(comedi_device *dev,comedi_subdevice *s) win_out(0,DAC_FIFO_Clear); /* load some data */ - n=(s->async->buf_write_count-s->async->buf_read_count)/sizeof(sampl_t); - if(n<0)return 0; + n = comedi_buf_read_n_available(s->async); + if(n==0)return 0; + + n /= sizeof(sampl_t); if(n>boardtype.ao_fifo_depth) n=boardtype.ao_fifo_depth; - ni_ao_fifo_load(dev,s,s->async->data+s->async->buf_read_ptr,n); + ni_ao_fifo_load(dev,s,n); return n; } @@ -1807,6 +1813,7 @@ static int ni_ao_inttrig(comedi_device *dev,comedi_subdevice *s, if(trignum!=0)return -EINVAL; ret = ni_ao_prep_fifo(dev,s); + if(ret==0)return -EPIPE; win_out(devpriv->ao_mode3|AO_Not_An_UPDATE,AO_Mode_3_Register); win_out(devpriv->ao_mode3,AO_Mode_3_Register); -- 2.26.2