Commit graph

186 commits

Author SHA1 Message Date
Ian Abbott
3f8514739a lib/calib.c: Include <sys/sysmacros.h> for fstat()
Relying on <sys/types.h> to define major(), minor() and makedev() is
deprecated, so include <sys/sysmacros.h> to define them.

Als include <sys/types.h> and <unistd.h> as the Linux man page for
fstat() has them in the synopsys.
2017-04-10 19:02:55 +01:00
Ian Abbott
70d6a02dd9 lib: dio: set internal error for incompatible subdevice type
comedi_dio_get_config(), comedi_dio_read(), comedi_dio_write(),
comedi_dio_bitfield2() (and comedi_dio_bitfield()) return -1 if the
subdevice type is unsuitable, but do not set an internal comedi error
code in that case.  Change them to do so.

Also, don't bother checking if instruction list ioctl is supported in
comedi_get_dio_config(), as it doesn't use it.
2016-06-09 15:04:28 +01:00
Ian Abbott
8c31fb88c1 lib: don't change read or write subdevice unnecessarily
Change comedi_set_read_subdevice() and comedi_set_write_subdevice() to
do nothing if the requested subdevice is already set as the current read
or write subdevice, respectively.

The functions now return success even if the Comedi drivers do not
support changes to the read or write subdevice as long as the specified
subdevice is the default one.
2016-05-13 16:18:02 +01:00
Ian Abbott
aff4937e03 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.
2016-05-13 15:14:47 +01:00
Ian Abbott
66070c6af6 Add comedi_set_read_subdevice() and comedi_set_write_subdevice()
These functions allow the current read or write subdevice to be changed
to another subdevice that supports streaming input (for read), or
streaming output (for write) asynchronous commands.

They return 0 on success, in which case the comedi_get_read_subdevice()
or comedi_get_write_subdevice() functions will get the updated read or
write subdevice.

Changes are local to the "open file description" that was created by
comedi_open() (actually, by open()), and have no effect on other open
file descriptions created by other calls to comedi_open() (or open())
for the same underlying Comedi device node.

Changes to the read or write subdevice is not currently supported by the
comedi.org version of the Comedi drivers, but is supported by the Linux
"in-tree" Comedi drivers since kernel version 3.19.
2016-05-12 18:10:59 +01:00
Ian Abbott
6458b08e56 lib: remove some unnecessary setting of __comedi_errno
Since comedi_ioctl() calls libc_error() to set __comedi_errno to errno
(and possibly print an error message), there is no need for callers of
comedi_ioctl() to set __comedi_errno immediately afterwards.  But
comedi_command(), comedi_command_test(), and comedi_do_insnlist()
currently do that.  Remove the unneeded setting of __comedi_errno in
those functions.

Also, comedi_command() and comedi_command_test() check __comedi_errno
regardless of whether comedi_ioctl() returnis an error, and possibly
modify the error code to an internal comedi error.  Change them to only
do that if comedi_ioctl() returns an error, because __comedi_errno might
contain a stale value.
2016-05-12 16:12:43 +01:00
Ian Abbott
27509ba9c9 Add digital trigger configuration functions
Add wrapper functions for the INSN_CONFIG_DIGITAL_TRIG configuration
instruction.  These are comedi_digital_trigger_disable(),
comedi_digital_trigger_enable_edges(), and
comedi_digital_trigger_enable_levels().
2016-03-21 11:28:29 +00:00
Ian Abbott
ac2ce44520 Add channel-specific arm, disarm, and reset wrappers.
The comedi_arm(), comedi_disarm(), and comedi_reset() functions always
set the channel number in the corresponding configuration instructions
to 0, as they assume the channel number will be ignored by the driver.
Some drivers do in fact use the channel number in these configuration
instructions.  Add additional wrapper functions comedi_arm_channel(),
comedi_disarm_channel(), and comedi_reset_channel() to allow the channel
number to be specified.
2016-03-21 11:28:29 +00:00
Ian Abbott
2062d615ff Add comedi_disarm() and bump to 0.11.0
Add the comedi_disarm() function to send the INSN_CONFIG_DISARM
configuration instruction to a subdevice.

In configure.ac, bump the comedilib libtool version code to 11:0:11, so
the comedilib version becomes 0.11.0.  Also bump the comedilib manual
version to 0.11.0 in doc/comedilib.ent.
2016-03-21 11:28:29 +00:00
Ian Abbott
49f298cf86 lib/range.c: deal with samples > maxdata when converting to phys
By default, comedi_to_phys() and comedi_sample_to_phys() return NAN (not
a number) if the raw sample value is 0 or maxdata.  Change it to convert
any raw sample values above maxdata to NAN.  Such raw samples shouldn't
occur, but this seems like a sensible thing to do.  (Note that the
conversion of out-of-range values to NAN behavior can be changed via the
comedi_set_global_oor_behavior() function.)
2015-08-24 17:33:11 +01:00
Ian Abbott
3e337824f4 lib/calib_yacc.y: fix segfault in comedi_parse_calibration_file()
Don't call fill_inverse_linear_polynomials(priv.parsed_file) if
priv.parsed_file is NULL as that would dereference the NULL pointer
leading to a segmentation fault.
2015-08-20 13:02:53 +01:00
Ian Abbott
f55d30396a lib/Makefile.am: Add 'comedi_la_LIBADD = -lm'
Builds on some systems need the line:

comedi_la_LIBADD = -lm

in lib/Makefile.am

Reported by Jan Banda, using a Linux Mint Petra system with gcc version
4.8.1.
2014-02-13 11:39:35 +00:00
Ian Abbott
2277e82787 lib/calib_yacc.y: eliminate priv() casting function
Parse parameters are now passed as the correct type instead of `void *`,
so the static inline priv() function is no longer needed to cast the
pointer to the correct type.
2014-01-07 14:28:43 +00:00
Ian Abbott
c689eff475 lib: replace YYPARSE_PARAM and YYLEX_PARAM
In the Bison source calib_yacc.y, replace the use of YYPARSE_PARAM and
YYLEX_PARAM C macros with the %parse-param and %lex-param declarations.
I still need a C macro in combination with %lex-param for it to work, so
I'm not sure I'm doing it right!

Also correct the %pure_parser declaration which should be %pure-parser
(i.e. the underscore should be a dash).  This has a knock-on effect for
the yyerror() function, which now needs an extra parameter.
2014-01-07 14:24:36 +00:00
Ian Abbott
fdf9d2d98b lib/data.c: remove unused variables
Remove unused variable 's' from comedi_data_write() and
comedi_data_read_delayed().
2013-05-07 13:01:08 +01:00
Ian Abbott
0868eccbf7 lib: remove cached cmd_timed and cmd_timed_errno from subdevice
Remove the cmd_timed and cmd_timed_errno members from the internal
struct subdevice_struct.

cmd_timed_errno is checked but never set, so it will always be 0 and the
code that uses it is buggy as it returns the value of s->cmd_mask_errno
if s->cmd_timed_errno is non-zero and sets s->cmd_mask_errno on failure.
It shouldn't be setting s->cmd_mask_errno at all.

Since the generic timed command could depend on the length of the
channel list, don't bother caching the result, and don't set
s->cmd_mask_errno on failure.
2013-05-07 12:58:30 +01:00
Ian Abbott
2811aea038 lib: check some malloc/calloc/realloc failures
Some calls to malloc(), realloc() or calloc() do not check the result.
Do so.  Also call internal function libc_error() if they fail to set the
result for comedi_errno().
2013-05-07 12:32:26 +01:00
Ian Abbott
f4e228e231 lib/calib_lex.l: Add #define YY_NO_INPUT to C pre-amble
This suppresses a compiler warning about 'input' defined but not used.
2013-03-21 15:49:18 +00:00
Ian Abbott
cc0c9e7405 lib/calib_yacc.y: Move comedi_parse_calibration_file()
Move the comedi_parse_calibration_file() function definition to the
bottom of the file.  It calls calib_yyparse() and the declaration might
not be in scope since we removed the declaration from
"lib/libinternal.h", but we know it will be declared somewhere above the
bottom of the generated "lib/calib_yacc.c" above the new location of
comedi_parse_calibration_file().
2013-03-21 15:36:14 +00:00
Ian Abbott
90ce9a94bd lib: fix calib_yyparse() conflict
For newer versions of Bison, the declaration of our calib_yyparse()
function in "lib/libinternal.h" clashes with that in the generated
"lib/calib_yacc.h".

Remove the declarations of calib_yyerror() and calib_yyparse() from
"lib/libinternal.h" and declare them in "lib/calib_yacc.c".
2013-03-21 15:12:35 +00:00
Anders Blomdell
2b8c2f8087 comedi_open has file descriptor leak
If something fails after a succesful open, cleanup fails to close the file.

The code

   cleanup:
         if(it)
                 free(it);

needs to be replaced with something like:

   cleanup:
         if (it) {
           if (it->fd >= 0) {
             close(it->fd);
           }
         free(it);

Regards

Anders Blomdell
2012-08-22 09:54:19 +01:00
Ian Abbott
2665ee5627 libcomedi: don't ignore channel in comedi_set_clock_source()
Fix bug reported by Finn Hoffman on comedi email list.
2011-12-01 15:37:43 +00:00
Ian Abbott
c530564317 #include <sys/stat.h> needed for fstat(). 2011-01-05 15:02:44 +00:00
Ian Abbott
b8a4f1a265 Added channel parameter to comedi_set_clock_source() and
comedi_get_clock_source().  Bumped library version to 0.10.0.
2010-03-19 13:44:56 +00:00
Ian Abbott
b06cecc151 comedi_find_range() should skip ranges that don't match specified units. 2010-02-17 18:28:15 +00:00
Ian Abbott
12eedd26b3 comedi_get_default_calibration_path(): Check result of asprintf() for error. 2009-02-18 15:35:09 +00:00
Ian Abbott
f2fdf25018 Move "comedi_errno.h" into "include/" and install it. 2009-02-18 14:47:06 +00:00
Ian Abbott
76a2e658b7 Put __comedi_errno variable into thread-local storage if the compiler
supports it.  Configuration test uses Alan Woodland's 'ax_tls.m4' from
<http://autoconf-archive.cryp.to/ax_tls.html>.
2009-02-18 14:10:54 +00:00
Ian Abbott
564e9680b0 Fixed do_test_for_insn_bits(), broken by validity checks added to
comedi_do_insnlist().  Call comedi_ioctl() instead of comedi_do_insnlist().
2008-12-18 17:23:14 +00:00
Ian Abbott
9a06deb6f9 Removed unneeded comedi_insnlist from do_test_for_insn(). 2008-12-18 16:44:20 +00:00
Ian Abbott
d8c3b29ca4 Corrected the 'BUG' message in do_test_for_insnlist() (it reported the
wrong function).
2008-12-18 16:38:51 +00:00
Ian Abbott
4df5ffd451 Added some device and subdevice validity checks. 2008-11-05 12:52:25 +00:00
Frank Mori Hess
8103c5334a Updated it to only run the (unreliable) do_test_for_insn_bits() if the
information was not available in the subdevice info.
2008-09-16 14:49:35 +00:00
Frank Mori Hess
b94b2ba024 Fixed memory leak in comedi_cleanup_calibration(). 2008-08-29 19:17:40 +00:00
Ian Abbott
64f8e05331 Fix some 64-bit warnings. 2008-04-23 18:53:09 +00:00
Frank Mori Hess
d0956ca8b5 Added comedi_get_hardware_buffer_size() wrapper function, and made
comedi_strerror return a const char*.
2008-03-28 15:56:35 +00:00
Frank Mori Hess
e0b0b89338 Allow comedi_cleanup_calibration to accept a NULL argument. 2008-03-14 17:52:20 +00:00
Frank Mori Hess
0695475797 Updated comedi_dio_config implementation to reflect logical split
between COMEDI_INPUT/COMEDI_OUTPUT and corresponding config insn ids
(even though they still have the same value).  Made comedi_dio_config
return 0 on success for better consistency in API.
2008-02-12 18:27:00 +00:00
Frank Mori Hess
0c69850ffc Made comedi_ioctl take its third argument as a void* instead of
and integer type, and got rid of a bunch of casts (and added a few).
2008-02-12 01:12:46 +00:00
Frank Mori Hess
a61ed59402 Fixed return values from comedi_mark_buffer_read/written(). Removed
some redundant assignments of __comedi_errno
2008-02-11 20:50:14 +00:00
Frank Mori Hess
a06bba542a Added more INSN_CONFIG wrappers: comedi_get_clock_source(),
comedi_get_gate_source(), and comedi_get_routing().  Added "channel"
parameter to some of the INSN_CONFIG wrappers.
2008-01-23 18:56:52 +00:00
Frank Mori Hess
76791bfeed Added comedi_set_filter() and comedi_set_routing() configuration
instruction wrappers.
2008-01-18 16:37:32 +00:00
Ian Abbott
1979b2f2cc More memory initialization, error detection and cleanup in get_subdevices()
and get_rangeinfo().
2008-01-17 13:52:02 +00:00
Ian Abbott
625d44af04 Free elements of rangeinfo_list on close. 2008-01-17 13:50:32 +00:00
Frank Mori Hess
37dc388297 Return 0 from the INSN_CONFIG wrappers on success. 2008-01-16 20:09:38 +00:00
Frank Mori Hess
ebe72a2b2a Added more memory initialization for the sake of valgrind (especially
memory that gets set by ioctls that valgrind can't see).  Added a little
error handling for a few memory allocations.
2008-01-16 19:45:05 +00:00
Frank Mori Hess
4d07ce9969 Moved some wrappers for INSN_CONFIG instructions into comedilib.
Will add some reference documentation for the new functions soon.
2008-01-15 21:01:40 +00:00
Ian Abbott
0b21f80783 Avoid mixing declarations and code. 2007-12-10 13:20:19 +00:00
Frank Mori Hess
f87490e0f6 Fixed setting of comedi_errno in comedi_dio_config() for invalid
arguments.
2007-12-01 15:54:08 +00:00
Frank Mori Hess
792e4b741f Got rid of obsolete error codes. 2007-12-01 15:53:18 +00:00