Added some more buffer position functions for use with mmap

Added comedi_get_buffer_read_offset(), comedi_get_buffer_write_offset(),
comedi_get_buffer_read_count(), and comedi_get_buffer_write_count().

comedi_get_buffer_read_offset() is the same as
comedi_get_buffer_offset(), which has now been documented as deprecated,
but is currently still declared in "comedilib.h" by default.  It gets
the read position within the buffer as an offset from the start of the
buffer (modulo the buffer size).

comedi_get_buffer_write_offset() gets the write position within the
buffer as an offset from the start of the buffer (modulo the buffer
size).

comedi_get_buffer_read_count() gets the number of bytes read from the
buffer, modulo UINT_MAX+1.

comedi_get_buffer_write_count() gets the number of bytes written to the
buffer, modulo UINT_MAX+1.
This commit is contained in:
Ian Abbott 2016-05-13 15:14:47 +01:00
parent fad46b9b16
commit aff4937e03
6 changed files with 143 additions and 12 deletions

View file

@ -119,21 +119,71 @@ Returns:
number of unread bytes in the buffer.
On failure, <literal>-1</literal> is returned.
Function: comedi_get_buffer_offset -- streaming buffer status
Function: comedi_get_buffer_read_offset -- streaming buffer read offset
Retval: int
Param: comedi_t * device
Param: unsigned int subdevice
Description:
The function <function>comedi_get_buffer_offset</function> is used on a subdevice
that has a Comedi command in progress to get the current read position in the
streaming buffer as an offset in bytes from the start of the buffer.
The position will wrap around to 0 when it reaches the buffer size.
This offset is only useful for memory mapped buffers.
The function <function>comedi_get_buffer_read_offset</function> is used on
a subdevice that has a Comedi command in progress to get the current read
position in the streaming buffer as an offset in bytes from the start of
the buffer. The position will wrap around to 0 when it reaches the buffer
size. This offset is only useful for memory mapped buffers.
This function replaces <function><link
linkend="func-ref-comedi-get-buffer-offset">comedi_get_buffer_offset</link></function> and has the same functionality.
Returns:
On success, <function>comedi_get_buffer_offset</function> returns the current
On success, <function>comedi_get_buffer_read_offset</function> returns the current
read position as an offset in bytes from the start of the buffer.
On failure, <literal>-1</literal> is returned.
Function: comedi_get_buffer_write_offset -- streaming buffer write offset
Retval: int
Param: comedi_t * device
Param: unsigned int subdevice
Description:
The function <function>comedi_get_buffer_write_offset</function> is used on
a subdevice that has a Comedi command in progress to get the current write
position in the streaming buffer as an offset in bytes from the start of
the buffer. The position will wrap around to 0 when it reaches the buffer
size. This offset is only useful for memory mapped buffers.
Returns:
On success, <function>comedi_get_buffer_write_offset</function> returns the
current write position as an offset in bytes from the start of the buffer.
On failure, <literal>-1</literal> is returned.
Function: comedi_get_buffer_read_count -- streaming buffer read count
Retval: int
Param: comedi_t * device
Param: unsigned int subdevice
Param: unsigned int * read_count
Description:
The function <function>comedi_get_buffer_read_count</function> is used on
a subdevice that has a Comedi command in progress to get the number of bytes
that have been read from the buffer, modulo
<constant class="limit">UINT_MAX</constant> + <literal>1</literal>. The
value is stored in
<code>*<parameter class="function">read_count</parameter></code>.
Returns:
On success, <literal>0</literal> is returned.
On failure, <literal>-1</literal> is returned.
Function: comedi_get_buffer_write_count -- streaming buffer write count
Retval: int
Param: comedi_t * device
Param: unsigned int subdevice
Param: unsigned int * write_count
Description:
The function <function>comedi_get_buffer_write_count</function> is used on
a subdevice that has a Comedi command in progress to get the number of bytes
that have been written to the buffer, modulo
<constant class="limit">UINT_MAX</constant> + <literal>1</literal>. The
value is stored in
<code>*<parameter class="function">write_count</parameter></code>.
Returns:
On success, <literal>0</literal> is returned.
On failure, <literal>-1</literal> is returned.
Function: comedi_get_buffer_size -- streaming buffer size of subdevice
Retval: int
Param: comedi_t * device

View file

@ -13,6 +13,14 @@ Description:
with <parameter class="function">base_channel</parameter> set to
<literal>0</literal>.
Function: comedi_get_buffer_offset -- streaming buffer status (deprecated)
Status: deprecated
Description:
This function is deprecated. Use <function><link
linkend="func-ref-comedi-get-buffer-read-offset">comedi_get_buffer_read_offset</link></function>
instead. It has the same functionality as
<function>comedi_get_buffer_read_offset</function>.
Function: comedi_get_timer -- timer information (deprecated)
Retval: int
Param: comedi_t * device

View file

@ -201,6 +201,14 @@ 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_read_offset(comedi_t *it, unsigned int subdev);
int comedi_get_buffer_write_offset(comedi_t *it, unsigned int subdev);
int comedi_get_buffer_read_count(comedi_t *it, unsigned int subdev,
unsigned int *SWIG_OUTPUT(read_count));
int comedi_get_buffer_write_count(comedi_t *it, unsigned int subdev,
unsigned int *SWIG_OUTPUT(write_count));
/* Should be moved to _COMEDILIB_DEPRECATED - use comedi_get_buffer_read_offset instead. */
int comedi_get_buffer_offset(comedi_t *it, unsigned int subdev);
#ifdef _COMEDILIB_DEPRECATED

View file

@ -124,8 +124,8 @@ int _comedi_mark_buffer_written(comedi_t *it, unsigned int subdev, unsigned int
return bi.bytes_written;
}
EXPORT_ALIAS_DEFAULT(_comedi_get_buffer_offset,comedi_get_buffer_offset,0.7.18);
int _comedi_get_buffer_offset(comedi_t *it, unsigned int subdev)
EXPORT_ALIAS_DEFAULT(_comedi_get_buffer_read_offset,comedi_get_buffer_read_offset,0.11.0);
int _comedi_get_buffer_read_offset(comedi_t *it, unsigned int subdev)
{
int ret;
comedi_bufinfo bi;
@ -138,8 +138,19 @@ int _comedi_get_buffer_offset(comedi_t *it, unsigned int subdev)
return bi.buf_read_ptr;
}
EXPORT_ALIAS_DEFAULT(_comedi_get_front_count,comedi_get_front_count,0.7.18);
int _comedi_get_front_count(comedi_t *it, unsigned int subdev)
/*
* Keep this for backwards compatibility as a synonym of
* comedi_get_buffer_read_offset().
* TODO: mark this as deprecated.
*/
EXPORT_ALIAS_DEFAULT(_comedi_get_buffer_offset,comedi_get_buffer_offset,0.7.18);
int _comedi_get_buffer_offset(comedi_t *it, unsigned int subdev)
{
return comedi_get_buffer_read_offset(it, subdev);
}
EXPORT_ALIAS_DEFAULT(_comedi_get_buffer_write_offset,comedi_get_buffer_write_offset,0.11.0);
int _comedi_get_buffer_write_offset(comedi_t *it, unsigned int subdev)
{
int ret;
comedi_bufinfo bi;
@ -149,6 +160,52 @@ int _comedi_get_front_count(comedi_t *it, unsigned int subdev)
bi.subdevice = subdev;
ret = comedi_ioctl(it->fd, COMEDI_BUFINFO, &bi);
if(ret < 0) return ret;
return bi.buf_write_count;
return bi.buf_write_ptr;
}
EXPORT_ALIAS_DEFAULT(_comedi_get_buffer_read_count,comedi_get_buffer_read_count,0.11.0);
int _comedi_get_buffer_read_count(comedi_t *it, unsigned int subdev, unsigned int *read_count)
{
int ret;
comedi_bufinfo bi;
*read_count = 0;
if(!valid_subd(it,subdev)) return -1;
memset(&bi, 0, sizeof(bi));
bi.subdevice = subdev;
ret = comedi_ioctl(it->fd, COMEDI_BUFINFO, &bi);
if(ret < 0) return ret;
*read_count = bi.buf_read_count;
return 0;
}
EXPORT_ALIAS_DEFAULT(_comedi_get_buffer_write_count,comedi_get_buffer_write_count,0.11.0);
int _comedi_get_buffer_write_count(comedi_t *it, unsigned int subdev, unsigned int *write_count)
{
int ret;
comedi_bufinfo bi;
*write_count = 0;
if(!valid_subd(it,subdev)) return -1;
memset(&bi, 0, sizeof(bi));
bi.subdevice = subdev;
ret = comedi_ioctl(it->fd, COMEDI_BUFINFO, &bi);
if(ret < 0) return ret;
*write_count = bi.buf_write_count;
return 0;
}
/*
* Keep _comedi_get_front_count for backwards compatibility.
* It is not in "comedilib.h" and is not documented.
*/
EXPORT_ALIAS_DEFAULT(_comedi_get_front_count,comedi_get_front_count,0.7.18);
int _comedi_get_front_count(comedi_t *it, unsigned int subdev)
{
unsigned int write_count;
int ret;
ret = _comedi_get_buffer_write_count(it, subdev, &write_count);
if (ret < 0) return ret;
return write_count;
}

View file

@ -128,4 +128,8 @@ v0.11.0 {
comedi_digital_trigger_enable_levels;
comedi_set_read_subdevice;
comedi_set_write_subdevice;
comedi_get_buffer_read_offset;
comedi_get_buffer_write_offset;
comedi_get_buffer_read_count;
comedi_get_buffer_write_count;
} v0.10.0;

View file

@ -211,6 +211,8 @@ private
mark_buffer_read
mark_buffer_written
get_buffer_offset
get_buffer_read_offset
get_buffer_write_offset
get_softcal_converter
get_hardcal_converter
internal_trigger
@ -247,6 +249,8 @@ private
get_cmd_generic_timed
get_gate_source
get_routing
get_buffer_read_count
get_buffer_write_count
}),
# TODO: add get_clock_source, but it returns status and two values.