1 <!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook V3.1//EN">
8 <section id="ref-macro-CR-PACK">
14 CR_PACK is used to initialize the elements of the chanlist array in the
15 comedi_cmd structure, and the chanspec member
16 of the comedi_insn structure.
20 The channel argument is the channel you wish to use, with the channel
21 numbering starting at zero.
25 The range is an index, starting at zero, whose meaning
26 is device dependent. The
27 comedi_get_n_ranges() and
28 comedi_get_range functions
29 are useful in discovering information about the available ranges.
33 The aref argument indicates what reference you want the device to use. It
34 can be any of the following:
39 <term>AREF_GROUND</term>
42 is for inputs/outputs referenced to ground
47 <term>AREF_COMMON</term>
50 is for a `common' reference (the low inputs of all the channels are tied
51 together, but are isolated from ground)
56 <term>AREF_DIFF</term>
59 is for differential inputs/outputs
64 <term>AREF_OTHER</term>
67 is for any reference that does not fit into the above categories
74 Particular drivers may or may not use the AREF flags. If they are
75 not supported, they are silently ignored.
79 <section id="ref-macro-RANGE-LENGTH">
81 RANGE_LENGTH (deprecated)
85 Rangetype values are library-internal tokens that represent an
86 array of range information structures. These numbers are primarily
87 used for communication between the kernel and library.
91 The RANGE_LENGTH() macro returns the length of the array that is
92 specified by the rangetype token.
96 The RANGE_LENGTH() macro is deprecated, and should not be used in
97 new applications. It is scheduled to be removed from the header
98 file at version 1.0. Binary compatibility may be broken for version
107 Data Types and Structures
110 <section id="ref-type-comedi-t">
116 typedef struct comedi_t_struct comedi_t;
120 The data type comedi_t is used to represent an open Comedi
121 device. A valid comedi_t pointer is returned by a successful
122 call to comedi_open(), and should be used for subsequent
123 access to the device.
124 It is a transparent type, and pointers to type comedi_t
125 should not be dereferenced by the application.
131 <section id="ref-type-sampl-t">
137 typedef unsigned short sampl_t;
141 The data type sampl_t is one of the generic types used to represent
142 data values in Comedilib. It is used in a few places where a data type
143 shorter than lsampl_t is useful. On most architectures, sampl_t
144 is defined to be uint16.
148 Most drivers represent data trasferred by read() and write()
149 using sampl_t. Applications should check the subdevice flag
150 SDF_LSAMPL to determine if the subdevice uses sampl_t or
156 <section id="ref-type-lsampl-t">
162 typedef unsigned int lsampl_t;
166 The data type lsampl_t is the data type typically used to represent
167 data values in libcomedi. On most architectures, lsampl_t is
168 defined to be uint32.
173 <section id="ref-type-comedi-trig">
175 comedi_trig (deprecated)
179 typedef struct comedi_trig_struct comedi_trig;
181 struct comedi_trig_struct{
182 unsigned int subdev; /* subdevice */
183 unsigned int mode; /* mode */
185 unsigned int n_chan; /* number of channels */
186 unsigned int *chanlist; /* channel/range list */
187 sampl_t *data; /* data list, size depends on subd flags */
188 unsigned int n; /* number of scans */
189 unsigned int trigsrc;
190 unsigned int trigvar;
191 unsigned int trigvar1;
192 unsigned int data_len;
193 unsigned int unused[3];
198 The comedi_trig structure is a control structure used by the
199 COMEDI_TRIG ioctl, an older method of communicating
200 instructions to the driver and hardware. Use of comedi_trig is
201 deprecated, and should not be used in new applications.
205 <section id="ref-type-comedi-sv-t">
211 typedef struct comedi_sv_struct comedi_sv_t;
213 struct comedi_sv_struct{
215 unsigned int subdevice;
222 /* number of measurements to average (for ai) */
230 The comedi_sv_t structure is used by the comedi_sv_*()
231 functions to provide a simple method of accurately measuring
232 slowly varying inputs. See the relevant section for more
237 <section id="ref-type-comedi-cmd">
243 typedef struct comedi_cmd_struct comedi_cmd;
245 struct comedi_cmd_struct{
249 unsigned int start_src;
250 unsigned int start_arg;
252 unsigned int scan_begin_src;
253 unsigned int scan_begin_arg;
255 unsigned int convert_src;
256 unsigned int convert_arg;
258 unsigned int scan_end_src;
259 unsigned int scan_end_arg;
261 unsigned int stop_src;
262 unsigned int stop_arg;
264 unsigned int *chanlist;
265 unsigned int chanlist_len;
268 unsigned int data_len;
273 More information on using commands can be found in the
278 <section id="ref-type-comedi-insn">
284 typedef struct comedi_insn_struct comedi_insn;
286 struct comedi_insn_struct{
291 unsigned int chanspec;
292 unsigned int unused[3];
297 Comedi instructions are described by the comedi_insn structure.
298 Applications send instructions to the driver in order to preform
299 control and measurement operations that are done immediately or
300 synchronously, i.e., the operations complete before program control
301 returns to the application. In particular, instructions cannot
302 describe acquisition that involves timers or external events.
306 The field insn determines the type of instruction that is sent
307 to the driver. Valid instruction types are
317 read values from an input channel
327 write values to an output channel
337 read/write values on multiple digital I/O channels
347 configure a subdevice
357 read a timestamp, identical to gettimeofday()
367 wait a specified number of nanoseconds
374 The number of samples to read or write, or the size of the configuration
375 structure is specified by the field n, and the buffer for those
376 samples by data. The field subdev is the subdevice index
377 that the instruction is sent to. The field chanspec specifies
378 the channel, range, and analog reference (if applicable).
382 Instructions can be sent to drivers using comedi_do_insn().
383 Multiple instructions can be sent to drivers in the same system
384 call using comedi_do_insnlist().
388 <section id="ref-type-comedi-range">
394 typedef struct comedi_range_struct comedi_range;
396 struct comedi_range_struct{
404 The comedi_range structure conveys part of the information
405 necessary to translate sample values to physical units, in particular,
406 the endpoints of the range and the physical unit type. The
407 physical unit type is specified by the field unit, which may
408 take the values UNIT_volt for volts, UNIT_mA for milliamps,
409 or UNIT_none for unitless. The endpoints are specified by
410 the fields min and max.
414 <section id="ref-type-comedi-krange">
420 typedef struct comedi_krange_struct comedi_krange;
422 struct comedi_krange_struct{
430 The comedi_krange structure is used to transfer range information
431 between the driver and Comedilib, and should not normally be used
432 by applications. The structure conveys the same information as the
433 comedi_range structure, except the fields min and max
434 are integers, multiplied by a factor of 1000000 compared to the
435 counterparts in comedi_range.
439 In addition, kcomedilib uses the comedi_krange structure in place
440 of the comedi_range structure.
445 <section id="ref-type-comedi-insnlist">
451 typedef struct comedi_insnlist_struct comedi_insnlist;
453 struct comedi_insnlist_struct{
454 unsigned int n_insns;
460 An instruction list (insnlist) structure is used to communicate
461 a list of instructions.
474 This chapter is meant to be a reference for some of the advanced
480 Digital input combining machines
484 When one or several digital inputs are used to modify an output
485 value, either an accumulator or a single digital line or bit,
486 a bitfield structure is typically used in the Comedi interface.
487 The digital inputs have two properties, "sensitive" inputs and
488 "modifier" inputs. Edge transitions on sensitive inputs cause
489 changes in the output signal, whereas modifier inputs change the
490 effect of edge transitions on sensitive inputs. Note that inputs
491 can be both modifier inputs and sensitive inputs.
495 For simplification purposes, it is assumed that multiple digital
496 inputs do not change simultaneously.
500 The combined state of the modifier inputs determine a modifier
501 state. For each combination of modifier state and sensitive
502 input, there is a set of bits that determine the effect on the
503 output value due to positive or negative transitions of the
504 sensitive input. For each transition direction, there are two
505 bits defined as follows:
515 transition is ignored
525 accumulator is incremented, or output is set
535 accumulator is decremented, or output is cleared
552 For example, a simple digital follower is specified by the bit
553 pattern 01 10, because it sets the output on positive transitions
554 of the input, and clears the output on negative transitions. A
555 digital inverter is similarily 10 01. These systems have only
560 As another example, a simple up counter, which increments on
561 positive transitions of one input, is specified by 01 00. This
562 system has only one sensitive input.
566 When multiple digital inputs are used, the inputs are divided
567 into two types, inputs which cause changes in the accumulator, and
568 those that only modify the meaning of transitions on other inputs.
569 Modifier inputs do not require bitfields, but there needs to be
570 a bitfield of length 4*(2^(N-1)) for each edge sensitive input,
571 where N is the total number of inputs. Since N is usually 2 or
572 3, with only one edge sensitive input, the scaling issues are
584 Configuration instructions are used to access device and driver features
585 that do not fit well into other parts of the Comedi interface. This
586 includes changing the direction of configurable digital I/O lines,
587 configuring complex triggering engines, and counter/timer configuration.
591 If a specified ID is not supported, the driver must return -EINVAL.
597 Digital I/O configuration
606 ID: COMEDI_INPUT, COMEDI_OUTPUT, COMEDI_OPENDRAIN
612 Chanspec: used to specify channel
617 These IDs are used to configure direction of digital I/O lines.
618 Direction is chosen by the ID. On typical devices, multiple
619 channels are grouped together in blocks for determining direction.
620 Configuring one channel in a block configures the entire block.
624 There should also be a method to read the configuration.
628 Errors: Should return -EINVAL if the ID is not supported.
635 Analog conversion configuration
649 Chanspec: used to specify channel
654 Some devices have the capability to add white noise (dithering) to
655 analog input measurement. This additional noise can then be averaged
656 out, to get a more accurate measurement of the input signal. It
657 should not be assumed that channels can be separately configured.
658 A simple design can use 1 bit to turn this feature on/off.
662 Some devices have the capability of changing the glitch characteristics
663 of analog output subsytems. The default (off) case should be where
664 the average settling time is lowest. A simple design can use 1 bit
665 to turn this feature on/off.
669 Some devices have a configurable analog filters as part of the analog
670 input stage. A simple designe can use 1 bit to enable/disable the
671 filter. Default is disabled, i.e., the filter being bypassed, or if
672 the choice is between two filters, the filter with the largest
679 Analog Output Waveform Generation
698 Some devices have the ability to cyclicly loop through samples kept in
699 an on-board analog output FIFO. This config should allow the user to
700 enable/disable this mode.
704 This config should allow the user to configure the number of samples
705 to loop through. It may be necessary to configure the channels used.
728 This section covers common information for all extended
729 triggering configuration, and doesn't describe a particular
730 type of extended trigger.
734 Extended triggering is used to configure triggering engines that
735 do not fit into commands. In a typical programming sequence, the
736 application will use configuration instructions to configure an
737 extended trigger, and the issue a command, specifying TRIG_OTHER
738 as one of the trigger sources.
742 Extended trigger configuration should be designed in such a way
743 that the user can probe for valid parameters, similar to how
744 command testing works. An extended trigger config instruction
745 should not configure the hardware directly, rather, the configuration
746 should be saved until the subsequent command is issued. This
747 allows more flexibility for future interface changes.
751 It has not been decided whether the config stage should return a
752 token that is then used as the trigger argument in the command.
753 Using tokens is one method to satisfy the problem that extended
754 trigger configurations may have subtle compatiblity issues with
755 other trigger sources/arguments that can only be determined at
756 command test time. Passing all stages of a command test should
757 only be allowed with a properly configured extended trigger.
761 Extended triggers must use data[1] as flags. The upper 16 bits
762 are reserved and used only for flags that are common to
763 all extended triggers. The lower 16 bits may be defined by the
764 particular type of extended trigger.
768 Various types of extended triggers must use data[1] to know which
769 event the extended trigger will be assigned to in the command
770 structure. The possible values are an OR'd mask of the following:
816 Implementation: ni_mio_common
825 data 1 - trigger and combining machine configuration
828 data 2 - analog triggering signal chanspec
831 data 3 - primary analog level
834 data 4 - secondary analog level
839 Analog triggering is described by a digital combining machine that
840 has two sensitive digital inputs. The sensitive digital inputs are
841 generated by configurable analog comparators. The analog comparators
842 generate a digital 1 when the analog triggering signal is greater
843 than the comparator level. The digital inputs are not modifier
844 inputs. Note, however, there is an effective modifier due to the
845 restriction that the primary analog comparator level must be less
846 than the secondary analog comparator level.
850 If only one analog comparator signal is used, the combining machine
851 for the secondary input should be set to ignored, and the secondary
852 analog level should be set to 0.
856 The interpretation of the chanspec and voltage levels is device
857 dependent, but should correspond to similar values of the analog
858 input subdevice, if possible.
862 Notes: Reading range information is not addressed. This makes it
863 difficult to convert comparator voltages to data values.
867 Possible extensions: A parameter that specifies the necessary time
868 that the set condition has to be true before the trigger is generated.
869 A parameter that specifies the necessary time that the reset condition
870 has to be true before the state machine is reset.
877 Bitfield Pattern Matching Extended Trigger
894 data 1 - trigger flags
905 The pattern matching trigger issues a trigger when all of a specifed
906 set of input lines match a specified pattern. If the device allows,
907 the input lines should correspond to the input lines of a digital input
908 subdevice, however, this will necessarily be device dependent. Each
909 possible digital line that can be matched is assigned a bit in the
910 mask and pattern. A bit set in the mask indicates that the
911 input line must match the corresponding bit in the pattern.
912 A bit cleared in the mask indicates that the input line is ignored.
916 Notes: This only allows 32 bits in the pattern/mask, which may be
917 too few. Devices may support selecting different sets of lines from
918 which to match a pattern.
922 Discovery: The number of bits can be discovered by setting the mask
923 to all 1's. The driver must modify this value and return -EAGAIN.
930 Counter configuration
941 Chanspec: used to specify counter
947 data 1 - trigger configuration
950 data 2 - primary input chanspec
953 data 3 - primary combining machine configuration
956 data 4 - secondary input chanspec
959 data 5 - secondary combining machine configuration
962 data 6 - latch configuration
967 Counters can be operated either in synchronous mode (using insn_read)
968 or asynchronous mode (using commands), similar to analog input subdevices.
969 The input signal for both modes is the accumulator.
970 Commands on counter subdevices are almost always specified using
971 scan_begin_src=TRIG_OTHER, with the counter configuration also serving
972 as the extended configuration for the scan begin source.
976 Counters are made up of an accumulator and a combining machine that
977 determines when the accumulator should be incremented or decremented
978 based on the values of the input signals. The combining machine
979 optionally determines when the accumulator should be latched and
980 put into a buffer. This feature is used in asynchronous mode.
984 Notes: How to access multiple pieces of data acquired at each event?
991 One source plus auxiliary counter configuration
1007 data[1] is flags, including the flags for the command triggering
1008 configuration. If a command is not subsequently issued on the
1009 subdevice, the command triggering portion of the flags are ignored.
1013 data[2] determines the mode of operation. The mode of operation
1014 is actually a bitfield that encodes what to do for various
1015 transitions of the source signals.
1019 data[3] and data[4] determine the primary source for the counter,
1020 similar to _src and _arg used in commands.
1025 Notes: How to specify which events cause a latch and push, and what