This patch removes COMEDI_CB_* macros that are of no use to userspace at
any rate. COMEDI_CB_* are no longer in comedi.h in the staging tree, but
rather in comedidev.h.
This patch also removes an old commented-out INSN_CONFIG_GET_OTHER_SRC, the
value of which was already taken long ago by
INSN_CONFIG_GET_HARDWARE_BUFFER_SIZE.
This partial sync of staging tree to the comedilib version of comedi.h
brings documentation and some mild formatting. The documentation should be
beneficial to userspace and the sync helps to visually maintain future
syncing between kernel and userspace code.
This revisits the change made in da0fe745fc:
1) Changes c-macro constants back to their original definition (without
explicit typing them as unsigned) so-as to more exactly compare
the comedilib version of comedi.h with that of the kernel module.
2) Removes the duplicate definition of NI_GPCT_INVERT_CLOCK_SRC_BIT in
comedi.i.
3) Instead of redefining the macros to fix the mishandling of signedness
by SWIG for python, teach SWIG to treat these as unsigned ints.
This is a partial sync of the staging tree to comedilib with these
benefits:
1. This is first in a series of patches to sync comedilib to the kernel
modules in the staging development tree. The point of this series of
patches is to make the syncing of the userspace and kernel comedi.h
files be visually more easily done.
2. This patch also teaches SWIG out to properly wrap these macros and
provide them to the user.
3. The redef of static inline NI_* functions as macro functions eases
alternative use of comedi.h as an import source for a new ctypes-based
python interface for comedilib.
This patch documents the new interpretation of stop_arg when stop_src ==
TRIG_NONE. In the new interpretation, if stop_src==TRIG_NONE, a user may
specify that a buffer of finite length (and less than or equal to the
maximum buffer size) be repeated indefinitely.
For now, only the NI MIO driver implements this new interpretation. All
other drivers should continue to force stop_arg==0 when
stop_src==TRIG_NONE. In this case, the old behavior is maintained.
Currently, the 'front' and 'back' variables are of type 'int' (signed
32-bit integers). The loop will break when 'front < back', which will
happen when more than 'INT_MAX' bytes of data have been produced.
Redefine them as 'unsigned int' and also allow 'front < back' which will
happen when more than 'UINT_MAX' bytes of data have been produced.
Because the buffer size is not necessarily a power of 2, we can no
longer just use '(back + i) % size' to get the buffer position
corresponding to 'back + i', so introduce a new variable 'bufpos' to
keep track of the buffer position.
Also allow for subdevices that set the 'SDF_LSAMPL' flag to indicate
they use the large (32-bit, 'lsampl_t') sample type instead of the small
(16-bit, 'sampl_t') sample type.
Also, rename the buffer size variable 'size' to 'bufsize'.
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.)
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.
In C, mixing up between int and unsigned int doesn't matter too much for constants
because in memory they end up the same.
However, in Python, they appear differently.
Swig assumes (wrongly?) by default that the constants are signed, intead of being unsigned.
For every value equal or greater that 2**31, it matters.
For instance CR_INVERT should be 2147483648, but it is -2147483648 in python.
By marking the values explicitly unsigned, swig generates the right values.
That's excepted for enum, which swig just consider int. So for the only constant in that
case, we manually override it in swig.
If the comedi data buffer is larger than the total size of the data
being written to the buffer in first test_cmd_write_fast_1chan(), the
first loop iterates endlessly writing 0 bytes to the buffer. Break out
of the first loop once the required amount of data has been written.
In the rule to make the 'calibrations' directory during installation,
use Make variable '$(localstatedir)' instead of shell variable
'${localstatedir}'. Also remove an unnecessary '/' after '$(DESTDIR)'
in the rule.
Add an install-data-local rule that creates the
${localstatedir}/lib/comedi/calibrations during installation. This
matches the directory name used by the
comedi_get_default_calibration_path() function.
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.
python always use the namespace of the library so it was redundant.
so what used to be written comedi.comedi_open() can be written comedi.open().
The main trick is to add a special python code that allows for the old names to still be compatible.
That avoids to break every single python program previously written.
The demo is supposed to take one reading for each channel for each
range, but was using the range from the command line options instead.
Thanks to Daniele Mazzi for spotting the bug!
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.
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.
The msync() call doesn't seem to work on Comedi devices, and seems a bit
pointless anyway, as it is meant for use on files with a backing store.
Remove it.
Some systems (e.g. Arch Linux) put the Python C headers in a strange
place, so try and run `$PYTHON-config --includes` first to find the -I
options to pass to the C compiler. Fall back to the old method if it
fails.
Thanks to Darrell Enns for reporting the problem and suggesting a
solution. I changed it a bit.
Remove the global variable 'capabilities' which is set to 0 by the
get_capabilities() function but not used anywhere else. Remove the
'type' and 'flags' local variables from get_capabilities() which are set
to the return values of comedi_get_subdevice_type() and
comedi_get_subdevice_flags() but never used. Remove the 'tmp' local
variable from test_segfault(); it was involved in a volatile memory
access to test for segmentation faults. Still do the volatile memory
access but don't use the variable.
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.
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().
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().
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".