From: Frank Mori Hess Date: Sun, 23 Jan 2005 03:11:30 +0000 (+0000) Subject: mmap works for output waveforms now. X-Git-Tag: v0_8_0~136 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=5d4729b9eccc5661111d3dc9a3cccfd8535b0de3;p=comedilib.git mmap works for output waveforms now. --- diff --git a/demo/ao_mmap.c b/demo/ao_mmap.c index 1646c76..f4b65d9 100644 --- a/demo/ao_mmap.c +++ b/demo/ao_mmap.c @@ -76,6 +76,7 @@ int main(int argc, char *argv[]) comedi_range *rng; int ret; int size; + int num_samples; sampl_t *map; /* peak-to-peak amplitude, in DAC units (i.e., 0-4095) */ double amplitude; @@ -148,36 +149,45 @@ int main(int argc, char *argv[]) perror("mmap"); exit(1); } - write_waveform(map, size / sizeof(sampl_t), amplitude, offset, maxdata); + num_samples = size / sizeof(sampl_t); + write_waveform(map, num_samples, amplitude, offset, maxdata); if(msync(map, size, MS_SYNC) < 0) { perror("msync"); exit(1); } - if(comedi_mark_buffer_written(dev, subdevice, size) < 0) + printf("marking %i samples as written\n", num_samples); + ret = comedi_mark_buffer_written(dev, subdevice, size); + if(ret < 0) { comedi_perror("comedi_mark_buffer_written"); exit(1); } ret = comedi_internal_trigger(dev, subdevice, 0); if(ret<0){ - comedi_perror("comedi_internal_trigger\n"); + comedi_perror("comedi_internal_trigger"); exit(1); } - while(1){ + while(1) + { int bytes_marked = comedi_get_buffer_contents(dev,subdevice); - if(bytes_marked < 1) + if(bytes_marked < 0) { comedi_perror("comedi_get_buffer_contents"); exit(1); } int bytes_unmarked = size - bytes_marked; - // this keeps comedi from reporting a buffer underrun - if(comedi_mark_buffer_written(dev, subdevice, bytes_unmarked) < 0) + if(bytes_unmarked > 0) { - comedi_perror("comedi_mark_buffer_written"); - exit(1); - } + // this keeps comedi from reporting a buffer underrun + if(comedi_mark_buffer_written(dev, subdevice, bytes_unmarked) < 0) + { + comedi_perror("comedi_mark_buffer_written"); + exit(1); + } + printf("marked %i more samples as written\n", bytes_unmarked / sizeof(sampl_t)); + }else + usleep(10000); } return 0; } diff --git a/include/comedi.h b/include/comedi.h index f344656..a22c2b2 100644 --- a/include/comedi.h +++ b/include/comedi.h @@ -389,10 +389,10 @@ struct comedi_bufinfo_struct{ unsigned int subdevice; unsigned int bytes_read; - unsigned int buf_int_ptr; - unsigned int buf_user_ptr; - unsigned int buf_int_count; - unsigned int buf_user_count; + unsigned int buf_write_ptr; + unsigned int buf_read_ptr; + unsigned int buf_write_count; + unsigned int buf_read_count; unsigned int bytes_written; diff --git a/lib/buffer.c b/lib/buffer.c index b197c3e..a3d70b3 100644 --- a/lib/buffer.c +++ b/lib/buffer.c @@ -81,11 +81,12 @@ int _comedi_mark_buffer_read(comedi_t *it, unsigned int subdev, unsigned int byt comedi_bufinfo bi; memset(&bi, 0, sizeof(bi)); + bi.subdevice = subdev; bi.bytes_read = bytes; ret = comedi_ioctl(it->fd, COMEDI_BUFINFO, (unsigned long)&bi); __comedi_errno = errno; if(__comedi_errno == EPIPE)__comedi_errno = EBUF_OVR; - return bi.buf_int_count - bi.buf_user_count; + return bi.buf_write_count - bi.buf_read_count; } EXPORT_ALIAS_DEFAULT(_comedi_mark_buffer_written,comedi_mark_buffer_written,0.7.23); @@ -95,11 +96,12 @@ int _comedi_mark_buffer_written(comedi_t *it, unsigned int subdev, unsigned int comedi_bufinfo bi; memset(&bi, 0, sizeof(bi)); + bi.subdevice = subdev; bi.bytes_written = bytes; ret = comedi_ioctl(it->fd, COMEDI_BUFINFO, (unsigned long)&bi); __comedi_errno = errno; if(__comedi_errno == EPIPE)__comedi_errno = EBUF_UNDR; - return bi.buf_int_count - bi.buf_user_count; + return bi.buf_write_count - bi.buf_read_count; } EXPORT_ALIAS_DEFAULT(_comedi_get_buffer_offset,comedi_get_buffer_offset,0.7.18); @@ -109,9 +111,10 @@ int _comedi_get_buffer_offset(comedi_t *it, unsigned int subdev) comedi_bufinfo bi; memset(&bi, 0, sizeof(bi)); + bi.subdevice = subdev; ret = comedi_ioctl(it->fd, COMEDI_BUFINFO, (unsigned long)&bi); if(ret < 0) return ret; - return bi.buf_user_ptr; + return bi.buf_read_ptr; } EXPORT_ALIAS_DEFAULT(_comedi_get_front_count,comedi_get_front_count,0.7.18); @@ -121,8 +124,9 @@ int _comedi_get_front_count(comedi_t *it, unsigned int subdev) comedi_bufinfo bi; memset(&bi, 0, sizeof(bi)); + bi.subdevice = subdev; ret = comedi_ioctl(it->fd, COMEDI_BUFINFO, (unsigned long)&bi); if(ret < 0) return ret; - return bi.buf_int_count; + return bi.buf_write_count; } diff --git a/swig/comedi.i b/swig/comedi.i index f104692..c1bba44 100644 --- a/swig/comedi.i +++ b/swig/comedi.i @@ -362,10 +362,10 @@ struct comedi_bufinfo_struct{ unsigned int subdevice; unsigned int bytes_read; - unsigned int buf_int_ptr; - unsigned int buf_user_ptr; - unsigned int buf_int_count; - unsigned int buf_user_count; + unsigned int buf_write_ptr; + unsigned int buf_read_ptr; + unsigned int buf_write_count; + unsigned int buf_read_count; unsigned int bytes_written;