From: Frank Mori Hess Date: Mon, 10 Jan 2005 00:46:28 +0000 (+0000) Subject: added comedi_mark_buffer_written() (untested) X-Git-Tag: v0_8_0~139 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=9f6b16e004a2545af7014dc9d4b07b94bd64c921;p=comedilib.git added comedi_mark_buffer_written() (untested) --- diff --git a/doc/comedilib.sgml b/doc/comedilib.sgml index e491ce1..14e9a77 100644 --- a/doc/comedilib.sgml +++ b/doc/comedilib.sgml @@ -55,7 +55,7 @@ handbook David Schleef - 2001-2003 + 2001-2003, 2005 Frank Mori Hess diff --git a/doc/funcref b/doc/funcref index e60fd69..04e25e1 100644 --- a/doc/funcref +++ b/doc/funcref @@ -795,18 +795,38 @@ Description: are available in the streaming buffer is returned. If there is an error, -1 is returned. -Function: comedi_mark_buffer_read -- streaming buffer status +Function: comedi_mark_buffer_read -- streaming buffer control Retval: int Param: comedi_t * device Param: unsigned int subdevice Param: unsigned int num_bytes Description: The function comedi_mark_buffer_read() is used on a subdevice - that has a Comedi command in progress. This function can be + that has a Comedi input command in progress. It should only be used + if you are using a mmap() (as opposed + to calling read() on the device file) to read data from Comedi's buffer, + since Comedi will automatically keep track of how many bytes have been + transferred via read() calls. This function is used to indicate that the next num_bytes bytes in the buffer are no longer needed and may be discarded. If there is an error, -1 is returned. +Function: comedi_mark_buffer_written -- streaming buffer control +Retval: int +Param: comedi_t * device +Param: unsigned int subdevice +Param: unsigned int num_bytes +Description: + The function comedi_mark_buffer_written() is used on a subdevice + that has a Comedi output command in progress. It should only be used + if you are using a mmap() (as opposed to calling write() on the device + file) to write data to Comedi's buffer, since Comedi + will automatically keep track of how many bytes have been + transferred via write() calls. This function is + used to indicate that the next num_bytes bytes in the buffer + are valid and may be sent to the device. + If there is an error, -1 is returned. + Function: comedi_get_buffer_offset -- streaming buffer status Retval: int Param: comedi_t * device diff --git a/include/comedilib.h b/include/comedilib.h index 3ede497..81ef65e 100644 --- a/include/comedilib.h +++ b/include/comedilib.h @@ -171,6 +171,8 @@ int comedi_set_max_buffer_size(comedi_t *it, unsigned int subdev, int comedi_get_buffer_contents(comedi_t *it, unsigned int subdev); int comedi_mark_buffer_read(comedi_t *it, unsigned int subdev, unsigned int bytes); +int comedi_mark_buffer_written(comedi_t *it, unsigned int subdev, + unsigned int bytes); int comedi_get_buffer_offset(comedi_t *it, unsigned int subdev); #ifdef _COMEDILIB_DEPRECATED diff --git a/lib/buffer.c b/lib/buffer.c index 4b89542..b197c3e 100644 --- a/lib/buffer.c +++ b/lib/buffer.c @@ -84,7 +84,21 @@ int _comedi_mark_buffer_read(comedi_t *it, unsigned int subdev, unsigned int byt bi.bytes_read = bytes; ret = comedi_ioctl(it->fd, COMEDI_BUFINFO, (unsigned long)&bi); __comedi_errno = errno; - if(__comedi_errno == EINVAL)__comedi_errno = EBUF_OVR; + if(__comedi_errno == EPIPE)__comedi_errno = EBUF_OVR; + return bi.buf_int_count - bi.buf_user_count; +} + +EXPORT_ALIAS_DEFAULT(_comedi_mark_buffer_written,comedi_mark_buffer_written,0.7.23); +int _comedi_mark_buffer_written(comedi_t *it, unsigned int subdev, unsigned int bytes) +{ + int ret; + comedi_bufinfo bi; + + memset(&bi, 0, sizeof(bi)); + 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; } diff --git a/lib/version_script b/lib/version_script index 41578d5..0a67f04 100644 --- a/lib/version_script +++ b/lib/version_script @@ -80,3 +80,8 @@ v0.7.20 { comedi_parse_calibration_file; } v0.7.19; + +v0.7.23 { + global: + comedi_mark_buffer_written; +} v0.7.20;