Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: LGPL-2.0+ WITH Linux-syscall-note */
0002 /*
0003  * comedi.h
0004  * header file for COMEDI user API
0005  *
0006  * COMEDI - Linux Control and Measurement Device Interface
0007  * Copyright (C) 1998-2001 David A. Schleef <ds@schleef.org>
0008  */
0009 
0010 #ifndef _COMEDI_H
0011 #define _COMEDI_H
0012 
0013 #define COMEDI_MAJORVERSION 0
0014 #define COMEDI_MINORVERSION 7
0015 #define COMEDI_MICROVERSION 76
0016 #define VERSION "0.7.76"
0017 
0018 /* comedi's major device number */
0019 #define COMEDI_MAJOR 98
0020 
0021 /*
0022  * maximum number of minor devices.  This can be increased, although
0023  * kernel structures are currently statically allocated, thus you
0024  * don't want this to be much more than you actually use.
0025  */
0026 #define COMEDI_NDEVICES 16
0027 
0028 /* number of config options in the config structure */
0029 #define COMEDI_NDEVCONFOPTS 32
0030 
0031 /*
0032  * NOTE: 'comedi_config --init-data' is deprecated
0033  *
0034  * The following indexes in the config options were used by
0035  * comedi_config to pass firmware blobs from user space to the
0036  * comedi drivers. The request_firmware() hotplug interface is
0037  * now used by all comedi drivers instead.
0038  */
0039 
0040 /* length of nth chunk of firmware data -*/
0041 #define COMEDI_DEVCONF_AUX_DATA3_LENGTH     25
0042 #define COMEDI_DEVCONF_AUX_DATA2_LENGTH     26
0043 #define COMEDI_DEVCONF_AUX_DATA1_LENGTH     27
0044 #define COMEDI_DEVCONF_AUX_DATA0_LENGTH     28
0045 /* most significant 32 bits of pointer address (if needed) */
0046 #define COMEDI_DEVCONF_AUX_DATA_HI      29
0047 /* least significant 32 bits of pointer address */
0048 #define COMEDI_DEVCONF_AUX_DATA_LO      30
0049 #define COMEDI_DEVCONF_AUX_DATA_LENGTH      31  /* total data length */
0050 
0051 /* max length of device and driver names */
0052 #define COMEDI_NAMELEN 20
0053 
0054 /* packs and unpacks a channel/range number */
0055 
0056 #define CR_PACK(chan, rng, aref)                    \
0057     ((((aref) & 0x3) << 24) | (((rng) & 0xff) << 16) | (chan))
0058 #define CR_PACK_FLAGS(chan, range, aref, flags)             \
0059     (CR_PACK(chan, range, aref) | ((flags) & CR_FLAGS_MASK))
0060 
0061 #define CR_CHAN(a)  ((a) & 0xffff)
0062 #define CR_RANGE(a) (((a) >> 16) & 0xff)
0063 #define CR_AREF(a)  (((a) >> 24) & 0x03)
0064 
0065 #define CR_FLAGS_MASK   0xfc000000
0066 #define CR_ALT_FILTER   0x04000000
0067 #define CR_DITHER   CR_ALT_FILTER
0068 #define CR_DEGLITCH CR_ALT_FILTER
0069 #define CR_ALT_SOURCE   0x08000000
0070 #define CR_EDGE     0x40000000
0071 #define CR_INVERT   0x80000000
0072 
0073 #define AREF_GROUND 0x00    /* analog ref = analog ground */
0074 #define AREF_COMMON 0x01    /* analog ref = analog common */
0075 #define AREF_DIFF   0x02    /* analog ref = differential */
0076 #define AREF_OTHER  0x03    /* analog ref = other (undefined) */
0077 
0078 /* counters -- these are arbitrary values */
0079 #define GPCT_RESET      0x0001
0080 #define GPCT_SET_SOURCE     0x0002
0081 #define GPCT_SET_GATE       0x0004
0082 #define GPCT_SET_DIRECTION  0x0008
0083 #define GPCT_SET_OPERATION  0x0010
0084 #define GPCT_ARM        0x0020
0085 #define GPCT_DISARM     0x0040
0086 #define GPCT_GET_INT_CLK_FRQ    0x0080
0087 
0088 #define GPCT_INT_CLOCK      0x0001
0089 #define GPCT_EXT_PIN        0x0002
0090 #define GPCT_NO_GATE        0x0004
0091 #define GPCT_UP         0x0008
0092 #define GPCT_DOWN       0x0010
0093 #define GPCT_HWUD       0x0020
0094 #define GPCT_SIMPLE_EVENT   0x0040
0095 #define GPCT_SINGLE_PERIOD  0x0080
0096 #define GPCT_SINGLE_PW      0x0100
0097 #define GPCT_CONT_PULSE_OUT 0x0200
0098 #define GPCT_SINGLE_PULSE_OUT   0x0400
0099 
0100 /* instructions */
0101 
0102 #define INSN_MASK_WRITE     0x8000000
0103 #define INSN_MASK_READ      0x4000000
0104 #define INSN_MASK_SPECIAL   0x2000000
0105 
0106 #define INSN_READ       (0 | INSN_MASK_READ)
0107 #define INSN_WRITE      (1 | INSN_MASK_WRITE)
0108 #define INSN_BITS       (2 | INSN_MASK_READ | INSN_MASK_WRITE)
0109 #define INSN_CONFIG     (3 | INSN_MASK_READ | INSN_MASK_WRITE)
0110 #define INSN_DEVICE_CONFIG  (INSN_CONFIG | INSN_MASK_SPECIAL)
0111 #define INSN_GTOD       (4 | INSN_MASK_READ | INSN_MASK_SPECIAL)
0112 #define INSN_WAIT       (5 | INSN_MASK_WRITE | INSN_MASK_SPECIAL)
0113 #define INSN_INTTRIG        (6 | INSN_MASK_WRITE | INSN_MASK_SPECIAL)
0114 
0115 /* command flags */
0116 /* These flags are used in comedi_cmd structures */
0117 
0118 #define CMDF_BOGUS      0x00000001  /* do the motions */
0119 
0120 /* try to use a real-time interrupt while performing command */
0121 #define CMDF_PRIORITY       0x00000008
0122 
0123 /* wake up on end-of-scan events */
0124 #define CMDF_WAKE_EOS       0x00000020
0125 
0126 #define CMDF_WRITE      0x00000040
0127 
0128 #define CMDF_RAWDATA        0x00000080
0129 
0130 /* timer rounding definitions */
0131 #define CMDF_ROUND_MASK     0x00030000
0132 #define CMDF_ROUND_NEAREST  0x00000000
0133 #define CMDF_ROUND_DOWN     0x00010000
0134 #define CMDF_ROUND_UP       0x00020000
0135 #define CMDF_ROUND_UP_NEXT  0x00030000
0136 
0137 #define COMEDI_EV_START     0x00040000
0138 #define COMEDI_EV_SCAN_BEGIN    0x00080000
0139 #define COMEDI_EV_CONVERT   0x00100000
0140 #define COMEDI_EV_SCAN_END  0x00200000
0141 #define COMEDI_EV_STOP      0x00400000
0142 
0143 /* compatibility definitions */
0144 #define TRIG_BOGUS      CMDF_BOGUS
0145 #define TRIG_RT         CMDF_PRIORITY
0146 #define TRIG_WAKE_EOS       CMDF_WAKE_EOS
0147 #define TRIG_WRITE      CMDF_WRITE
0148 #define TRIG_ROUND_MASK     CMDF_ROUND_MASK
0149 #define TRIG_ROUND_NEAREST  CMDF_ROUND_NEAREST
0150 #define TRIG_ROUND_DOWN     CMDF_ROUND_DOWN
0151 #define TRIG_ROUND_UP       CMDF_ROUND_UP
0152 #define TRIG_ROUND_UP_NEXT  CMDF_ROUND_UP_NEXT
0153 
0154 /* trigger sources */
0155 
0156 #define TRIG_ANY    0xffffffff
0157 #define TRIG_INVALID    0x00000000
0158 
0159 #define TRIG_NONE   0x00000001 /* never trigger */
0160 #define TRIG_NOW    0x00000002 /* trigger now + N ns */
0161 #define TRIG_FOLLOW 0x00000004 /* trigger on next lower level trig */
0162 #define TRIG_TIME   0x00000008 /* trigger at time N ns */
0163 #define TRIG_TIMER  0x00000010 /* trigger at rate N ns */
0164 #define TRIG_COUNT  0x00000020 /* trigger when count reaches N */
0165 #define TRIG_EXT    0x00000040 /* trigger on external signal N */
0166 #define TRIG_INT    0x00000080 /* trigger on comedi-internal signal N */
0167 #define TRIG_OTHER  0x00000100 /* driver defined */
0168 
0169 /* subdevice flags */
0170 
0171 #define SDF_BUSY    0x0001  /* device is busy */
0172 #define SDF_BUSY_OWNER  0x0002  /* device is busy with your job */
0173 #define SDF_LOCKED  0x0004  /* subdevice is locked */
0174 #define SDF_LOCK_OWNER  0x0008  /* you own lock */
0175 #define SDF_MAXDATA 0x0010  /* maxdata depends on channel */
0176 #define SDF_FLAGS   0x0020  /* flags depend on channel */
0177 #define SDF_RANGETYPE   0x0040  /* range type depends on channel */
0178 #define SDF_PWM_COUNTER 0x0080  /* PWM can automatically switch off */
0179 #define SDF_PWM_HBRIDGE 0x0100  /* PWM is signed (H-bridge) */
0180 #define SDF_CMD     0x1000  /* can do commands (deprecated) */
0181 #define SDF_SOFT_CALIBRATED 0x2000 /* subdevice uses software calibration */
0182 #define SDF_CMD_WRITE       0x4000 /* can do output commands */
0183 #define SDF_CMD_READ        0x8000 /* can do input commands */
0184 
0185 /* subdevice can be read (e.g. analog input) */
0186 #define SDF_READABLE    0x00010000
0187 /* subdevice can be written (e.g. analog output) */
0188 #define SDF_WRITABLE    0x00020000
0189 #define SDF_WRITEABLE   SDF_WRITABLE    /* spelling error in API */
0190 /* subdevice does not have externally visible lines */
0191 #define SDF_INTERNAL    0x00040000
0192 #define SDF_GROUND  0x00100000  /* can do aref=ground */
0193 #define SDF_COMMON  0x00200000  /* can do aref=common */
0194 #define SDF_DIFF    0x00400000  /* can do aref=diff */
0195 #define SDF_OTHER   0x00800000  /* can do aref=other */
0196 #define SDF_DITHER  0x01000000  /* can do dithering */
0197 #define SDF_DEGLITCH    0x02000000  /* can do deglitching */
0198 #define SDF_MMAP    0x04000000  /* can do mmap() */
0199 #define SDF_RUNNING 0x08000000  /* subdevice is acquiring data */
0200 #define SDF_LSAMPL  0x10000000  /* subdevice uses 32-bit samples */
0201 #define SDF_PACKED  0x20000000  /* subdevice can do packed DIO */
0202 
0203 /* subdevice types */
0204 
0205 /**
0206  * enum comedi_subdevice_type - COMEDI subdevice types
0207  * @COMEDI_SUBD_UNUSED:     Unused subdevice.
0208  * @COMEDI_SUBD_AI:     Analog input.
0209  * @COMEDI_SUBD_AO:     Analog output.
0210  * @COMEDI_SUBD_DI:     Digital input.
0211  * @COMEDI_SUBD_DO:     Digital output.
0212  * @COMEDI_SUBD_DIO:        Digital input/output.
0213  * @COMEDI_SUBD_COUNTER:    Counter.
0214  * @COMEDI_SUBD_TIMER:      Timer.
0215  * @COMEDI_SUBD_MEMORY:     Memory, EEPROM, DPRAM.
0216  * @COMEDI_SUBD_CALIB:      Calibration DACs.
0217  * @COMEDI_SUBD_PROC:       Processor, DSP.
0218  * @COMEDI_SUBD_SERIAL:     Serial I/O.
0219  * @COMEDI_SUBD_PWM:        Pulse-Width Modulation output.
0220  */
0221 enum comedi_subdevice_type {
0222     COMEDI_SUBD_UNUSED,
0223     COMEDI_SUBD_AI,
0224     COMEDI_SUBD_AO,
0225     COMEDI_SUBD_DI,
0226     COMEDI_SUBD_DO,
0227     COMEDI_SUBD_DIO,
0228     COMEDI_SUBD_COUNTER,
0229     COMEDI_SUBD_TIMER,
0230     COMEDI_SUBD_MEMORY,
0231     COMEDI_SUBD_CALIB,
0232     COMEDI_SUBD_PROC,
0233     COMEDI_SUBD_SERIAL,
0234     COMEDI_SUBD_PWM
0235 };
0236 
0237 /* configuration instructions */
0238 
0239 /**
0240  * enum comedi_io_direction - COMEDI I/O directions
0241  * @COMEDI_INPUT:   Input.
0242  * @COMEDI_OUTPUT:  Output.
0243  * @COMEDI_OPENDRAIN:   Open-drain (or open-collector) output.
0244  *
0245  * These are used by the %INSN_CONFIG_DIO_QUERY configuration instruction to
0246  * report a direction.  They may also be used in other places where a direction
0247  * needs to be specified.
0248  */
0249 enum comedi_io_direction {
0250     COMEDI_INPUT = 0,
0251     COMEDI_OUTPUT = 1,
0252     COMEDI_OPENDRAIN = 2
0253 };
0254 
0255 /**
0256  * enum configuration_ids - COMEDI configuration instruction codes
0257  * @INSN_CONFIG_DIO_INPUT:  Configure digital I/O as input.
0258  * @INSN_CONFIG_DIO_OUTPUT: Configure digital I/O as output.
0259  * @INSN_CONFIG_DIO_OPENDRAIN:  Configure digital I/O as open-drain (or open
0260  *              collector) output.
0261  * @INSN_CONFIG_ANALOG_TRIG:    Configure analog trigger.
0262  * @INSN_CONFIG_ALT_SOURCE: Configure alternate input source.
0263  * @INSN_CONFIG_DIGITAL_TRIG:   Configure digital trigger.
0264  * @INSN_CONFIG_BLOCK_SIZE: Configure block size for DMA transfers.
0265  * @INSN_CONFIG_TIMER_1:    Configure divisor for external clock.
0266  * @INSN_CONFIG_FILTER:     Configure a filter.
0267  * @INSN_CONFIG_CHANGE_NOTIFY:  Configure change notification for digital
0268  *              inputs.  (New drivers should use
0269  *              %INSN_CONFIG_DIGITAL_TRIG instead.)
0270  * @INSN_CONFIG_SERIAL_CLOCK:   Configure clock for serial I/O.
0271  * @INSN_CONFIG_BIDIRECTIONAL_DATA: Send and receive byte over serial I/O.
0272  * @INSN_CONFIG_DIO_QUERY:  Query direction of digital I/O channel.
0273  * @INSN_CONFIG_PWM_OUTPUT: Configure pulse-width modulator output.
0274  * @INSN_CONFIG_GET_PWM_OUTPUT: Get pulse-width modulator output configuration.
0275  * @INSN_CONFIG_ARM:        Arm a subdevice or channel.
0276  * @INSN_CONFIG_DISARM:     Disarm a subdevice or channel.
0277  * @INSN_CONFIG_GET_COUNTER_STATUS: Get counter status.
0278  * @INSN_CONFIG_RESET:      Reset a subdevice or channel.
0279  * @INSN_CONFIG_GPCT_SINGLE_PULSE_GENERATOR: Configure counter/timer as
0280  *              single pulse generator.
0281  * @INSN_CONFIG_GPCT_PULSE_TRAIN_GENERATOR: Configure counter/timer as
0282  *              pulse train generator.
0283  * @INSN_CONFIG_GPCT_QUADRATURE_ENCODER: Configure counter as a quadrature
0284  *              encoder.
0285  * @INSN_CONFIG_SET_GATE_SRC:   Set counter/timer gate source.
0286  * @INSN_CONFIG_GET_GATE_SRC:   Get counter/timer gate source.
0287  * @INSN_CONFIG_SET_CLOCK_SRC:  Set counter/timer master clock source.
0288  * @INSN_CONFIG_GET_CLOCK_SRC:  Get counter/timer master clock source.
0289  * @INSN_CONFIG_SET_OTHER_SRC:  Set counter/timer "other" source.
0290  * @INSN_CONFIG_GET_HARDWARE_BUFFER_SIZE: Get size (in bytes) of subdevice's
0291  *              on-board FIFOs used during streaming
0292  *              input/output.
0293  * @INSN_CONFIG_SET_COUNTER_MODE: Set counter/timer mode.
0294  * @INSN_CONFIG_8254_SET_MODE:  (Deprecated) Same as
0295  *              %INSN_CONFIG_SET_COUNTER_MODE.
0296  * @INSN_CONFIG_8254_READ_STATUS: Read status of 8254 counter channel.
0297  * @INSN_CONFIG_SET_ROUTING:    Set routing for a channel.
0298  * @INSN_CONFIG_GET_ROUTING:    Get routing for a channel.
0299  * @INSN_CONFIG_PWM_SET_PERIOD: Set PWM period in nanoseconds.
0300  * @INSN_CONFIG_PWM_GET_PERIOD: Get PWM period in nanoseconds.
0301  * @INSN_CONFIG_GET_PWM_STATUS: Get PWM status.
0302  * @INSN_CONFIG_PWM_SET_H_BRIDGE: Set PWM H bridge duty cycle and polarity for
0303  *              a relay simultaneously.
0304  * @INSN_CONFIG_PWM_GET_H_BRIDGE: Get PWM H bridge duty cycle and polarity.
0305  * @INSN_CONFIG_GET_CMD_TIMING_CONSTRAINTS: Get the hardware timing restraints,
0306  *              regardless of trigger sources.
0307  */
0308 enum configuration_ids {
0309     INSN_CONFIG_DIO_INPUT = COMEDI_INPUT,
0310     INSN_CONFIG_DIO_OUTPUT = COMEDI_OUTPUT,
0311     INSN_CONFIG_DIO_OPENDRAIN = COMEDI_OPENDRAIN,
0312     INSN_CONFIG_ANALOG_TRIG = 16,
0313 /*  INSN_CONFIG_WAVEFORM = 17, */
0314 /*  INSN_CONFIG_TRIG = 18, */
0315 /*  INSN_CONFIG_COUNTER = 19, */
0316     INSN_CONFIG_ALT_SOURCE = 20,
0317     INSN_CONFIG_DIGITAL_TRIG = 21,
0318     INSN_CONFIG_BLOCK_SIZE = 22,
0319     INSN_CONFIG_TIMER_1 = 23,
0320     INSN_CONFIG_FILTER = 24,
0321     INSN_CONFIG_CHANGE_NOTIFY = 25,
0322 
0323     INSN_CONFIG_SERIAL_CLOCK = 26,  /*ALPHA*/
0324     INSN_CONFIG_BIDIRECTIONAL_DATA = 27,
0325     INSN_CONFIG_DIO_QUERY = 28,
0326     INSN_CONFIG_PWM_OUTPUT = 29,
0327     INSN_CONFIG_GET_PWM_OUTPUT = 30,
0328     INSN_CONFIG_ARM = 31,
0329     INSN_CONFIG_DISARM = 32,
0330     INSN_CONFIG_GET_COUNTER_STATUS = 33,
0331     INSN_CONFIG_RESET = 34,
0332     INSN_CONFIG_GPCT_SINGLE_PULSE_GENERATOR = 1001,
0333     INSN_CONFIG_GPCT_PULSE_TRAIN_GENERATOR = 1002,
0334     INSN_CONFIG_GPCT_QUADRATURE_ENCODER = 1003,
0335     INSN_CONFIG_SET_GATE_SRC = 2001,
0336     INSN_CONFIG_GET_GATE_SRC = 2002,
0337     INSN_CONFIG_SET_CLOCK_SRC = 2003,
0338     INSN_CONFIG_GET_CLOCK_SRC = 2004,
0339     INSN_CONFIG_SET_OTHER_SRC = 2005,
0340     INSN_CONFIG_GET_HARDWARE_BUFFER_SIZE = 2006,
0341     INSN_CONFIG_SET_COUNTER_MODE = 4097,
0342     INSN_CONFIG_8254_SET_MODE = INSN_CONFIG_SET_COUNTER_MODE,
0343     INSN_CONFIG_8254_READ_STATUS = 4098,
0344     INSN_CONFIG_SET_ROUTING = 4099,
0345     INSN_CONFIG_GET_ROUTING = 4109,
0346     INSN_CONFIG_PWM_SET_PERIOD = 5000,
0347     INSN_CONFIG_PWM_GET_PERIOD = 5001,
0348     INSN_CONFIG_GET_PWM_STATUS = 5002,
0349     INSN_CONFIG_PWM_SET_H_BRIDGE = 5003,
0350     INSN_CONFIG_PWM_GET_H_BRIDGE = 5004,
0351     INSN_CONFIG_GET_CMD_TIMING_CONSTRAINTS = 5005,
0352 };
0353 
0354 /**
0355  * enum device_configuration_ids - COMEDI configuration instruction codes global
0356  * to an entire device.
0357  * @INSN_DEVICE_CONFIG_TEST_ROUTE:  Validate the possibility of a
0358  *                  globally-named route
0359  * @INSN_DEVICE_CONFIG_CONNECT_ROUTE:   Connect a globally-named route
0360  * @INSN_DEVICE_CONFIG_DISCONNECT_ROUTE:Disconnect a globally-named route
0361  * @INSN_DEVICE_CONFIG_GET_ROUTES:  Get a list of all globally-named routes
0362  *                  that are valid for a particular device.
0363  */
0364 enum device_config_route_ids {
0365     INSN_DEVICE_CONFIG_TEST_ROUTE = 0,
0366     INSN_DEVICE_CONFIG_CONNECT_ROUTE = 1,
0367     INSN_DEVICE_CONFIG_DISCONNECT_ROUTE = 2,
0368     INSN_DEVICE_CONFIG_GET_ROUTES = 3,
0369 };
0370 
0371 /**
0372  * enum comedi_digital_trig_op - operations for configuring a digital trigger
0373  * @COMEDI_DIGITAL_TRIG_DISABLE:    Return digital trigger to its default,
0374  *                  inactive, unconfigured state.
0375  * @COMEDI_DIGITAL_TRIG_ENABLE_EDGES:   Set rising and/or falling edge inputs
0376  *                  that each can fire the trigger.
0377  * @COMEDI_DIGITAL_TRIG_ENABLE_LEVELS:  Set a combination of high and/or low
0378  *                  level inputs that can fire the trigger.
0379  *
0380  * These are used with the %INSN_CONFIG_DIGITAL_TRIG configuration instruction.
0381  * The data for the configuration instruction is as follows...
0382  *
0383  *   data[%0] = %INSN_CONFIG_DIGITAL_TRIG
0384  *
0385  *   data[%1] = trigger ID
0386  *
0387  *   data[%2] = configuration operation
0388  *
0389  *   data[%3] = configuration parameter 1
0390  *
0391  *   data[%4] = configuration parameter 2
0392  *
0393  *   data[%5] = configuration parameter 3
0394  *
0395  * The trigger ID (data[%1]) is used to differentiate multiple digital triggers
0396  * belonging to the same subdevice.  The configuration operation (data[%2]) is
0397  * one of the enum comedi_digital_trig_op values.  The configuration
0398  * parameters (data[%3], data[%4], and data[%5]) depend on the operation; they
0399  * are not used with %COMEDI_DIGITAL_TRIG_DISABLE.
0400  *
0401  * For %COMEDI_DIGITAL_TRIG_ENABLE_EDGES and %COMEDI_DIGITAL_TRIG_ENABLE_LEVELS,
0402  * configuration parameter 1 (data[%3]) contains a "left-shift" value that
0403  * specifies the input corresponding to bit 0 of configuration parameters 2
0404  * and 3.  This is useful if the trigger has more than 32 inputs.
0405  *
0406  * For %COMEDI_DIGITAL_TRIG_ENABLE_EDGES, configuration parameter 2 (data[%4])
0407  * specifies which of up to 32 inputs have rising-edge sensitivity, and
0408  * configuration parameter 3 (data[%5]) specifies which of up to 32 inputs
0409  * have falling-edge sensitivity that can fire the trigger.
0410  *
0411  * For %COMEDI_DIGITAL_TRIG_ENABLE_LEVELS, configuration parameter 2 (data[%4])
0412  * specifies which of up to 32 inputs must be at a high level, and
0413  * configuration parameter 3 (data[%5]) specifies which of up to 32 inputs
0414  * must be at a low level for the trigger to fire.
0415  *
0416  * Some sequences of %INSN_CONFIG_DIGITAL_TRIG instructions may have a (partly)
0417  * accumulative effect, depending on the low-level driver.  This is useful
0418  * when setting up a trigger that has more than 32 inputs, or has a combination
0419  * of edge- and level-triggered inputs.
0420  */
0421 enum comedi_digital_trig_op {
0422     COMEDI_DIGITAL_TRIG_DISABLE = 0,
0423     COMEDI_DIGITAL_TRIG_ENABLE_EDGES = 1,
0424     COMEDI_DIGITAL_TRIG_ENABLE_LEVELS = 2
0425 };
0426 
0427 /**
0428  * enum comedi_support_level - support level for a COMEDI feature
0429  * @COMEDI_UNKNOWN_SUPPORT: Unspecified support for feature.
0430  * @COMEDI_SUPPORTED:       Feature is supported.
0431  * @COMEDI_UNSUPPORTED:     Feature is unsupported.
0432  */
0433 enum comedi_support_level {
0434     COMEDI_UNKNOWN_SUPPORT = 0,
0435     COMEDI_SUPPORTED,
0436     COMEDI_UNSUPPORTED
0437 };
0438 
0439 /**
0440  * enum comedi_counter_status_flags - counter status bits
0441  * @COMEDI_COUNTER_ARMED:       Counter is armed.
0442  * @COMEDI_COUNTER_COUNTING:        Counter is counting.
0443  * @COMEDI_COUNTER_TERMINAL_COUNT:  Counter reached terminal count.
0444  *
0445  * These bitwise values are used by the %INSN_CONFIG_GET_COUNTER_STATUS
0446  * configuration instruction to report the status of a counter.
0447  */
0448 enum comedi_counter_status_flags {
0449     COMEDI_COUNTER_ARMED = 0x1,
0450     COMEDI_COUNTER_COUNTING = 0x2,
0451     COMEDI_COUNTER_TERMINAL_COUNT = 0x4,
0452 };
0453 
0454 /* ioctls */
0455 
0456 #define CIO 'd'
0457 #define COMEDI_DEVCONFIG _IOW(CIO, 0, struct comedi_devconfig)
0458 #define COMEDI_DEVINFO _IOR(CIO, 1, struct comedi_devinfo)
0459 #define COMEDI_SUBDINFO _IOR(CIO, 2, struct comedi_subdinfo)
0460 #define COMEDI_CHANINFO _IOR(CIO, 3, struct comedi_chaninfo)
0461 /* _IOWR(CIO, 4, ...) is reserved */
0462 #define COMEDI_LOCK _IO(CIO, 5)
0463 #define COMEDI_UNLOCK _IO(CIO, 6)
0464 #define COMEDI_CANCEL _IO(CIO, 7)
0465 #define COMEDI_RANGEINFO _IOR(CIO, 8, struct comedi_rangeinfo)
0466 #define COMEDI_CMD _IOR(CIO, 9, struct comedi_cmd)
0467 #define COMEDI_CMDTEST _IOR(CIO, 10, struct comedi_cmd)
0468 #define COMEDI_INSNLIST _IOR(CIO, 11, struct comedi_insnlist)
0469 #define COMEDI_INSN _IOR(CIO, 12, struct comedi_insn)
0470 #define COMEDI_BUFCONFIG _IOR(CIO, 13, struct comedi_bufconfig)
0471 #define COMEDI_BUFINFO _IOWR(CIO, 14, struct comedi_bufinfo)
0472 #define COMEDI_POLL _IO(CIO, 15)
0473 #define COMEDI_SETRSUBD _IO(CIO, 16)
0474 #define COMEDI_SETWSUBD _IO(CIO, 17)
0475 
0476 /* structures */
0477 
0478 /**
0479  * struct comedi_insn - COMEDI instruction
0480  * @insn:   COMEDI instruction type (%INSN_xxx).
0481  * @n:      Length of @data[].
0482  * @data:   Pointer to data array operated on by the instruction.
0483  * @subdev: Subdevice index.
0484  * @chanspec:   A packed "chanspec" value consisting of channel number,
0485  *      analog range index, analog reference type, and flags.
0486  * @unused: Reserved for future use.
0487  *
0488  * This is used with the %COMEDI_INSN ioctl, and indirectly with the
0489  * %COMEDI_INSNLIST ioctl.
0490  */
0491 struct comedi_insn {
0492     unsigned int insn;
0493     unsigned int n;
0494     unsigned int __user *data;
0495     unsigned int subdev;
0496     unsigned int chanspec;
0497     unsigned int unused[3];
0498 };
0499 
0500 /**
0501  * struct comedi_insnlist - list of COMEDI instructions
0502  * @n_insns:    Number of COMEDI instructions.
0503  * @insns:  Pointer to array COMEDI instructions.
0504  *
0505  * This is used with the %COMEDI_INSNLIST ioctl.
0506  */
0507 struct comedi_insnlist {
0508     unsigned int n_insns;
0509     struct comedi_insn __user *insns;
0510 };
0511 
0512 /**
0513  * struct comedi_cmd - COMEDI asynchronous acquisition command details
0514  * @subdev:     Subdevice index.
0515  * @flags:      Command flags (%CMDF_xxx).
0516  * @start_src:      "Start acquisition" trigger source (%TRIG_xxx).
0517  * @start_arg:      "Start acquisition" trigger argument.
0518  * @scan_begin_src: "Scan begin" trigger source.
0519  * @scan_begin_arg: "Scan begin" trigger argument.
0520  * @convert_src:    "Convert" trigger source.
0521  * @convert_arg:    "Convert" trigger argument.
0522  * @scan_end_src:   "Scan end" trigger source.
0523  * @scan_end_arg:   "Scan end" trigger argument.
0524  * @stop_src:       "Stop acquisition" trigger source.
0525  * @stop_arg:       "Stop acquisition" trigger argument.
0526  * @chanlist:       Pointer to array of "chanspec" values, containing a
0527  *          sequence of channel numbers packed with analog range
0528  *          index, etc.
0529  * @chanlist_len:   Number of channels in sequence.
0530  * @data:       Pointer to miscellaneous set-up data (not used).
0531  * @data_len:       Length of miscellaneous set-up data.
0532  *
0533  * This is used with the %COMEDI_CMD or %COMEDI_CMDTEST ioctl to set-up
0534  * or validate an asynchronous acquisition command.  The ioctl may modify
0535  * the &struct comedi_cmd and copy it back to the caller.
0536  *
0537  * Optional command @flags values that can be ORed together...
0538  *
0539  * %CMDF_BOGUS - makes %COMEDI_CMD ioctl return error %EAGAIN instead of
0540  * starting the command.
0541  *
0542  * %CMDF_PRIORITY - requests "hard real-time" processing (which is not
0543  * supported in this version of COMEDI).
0544  *
0545  * %CMDF_WAKE_EOS - requests the command makes data available for reading
0546  * after every "scan" period.
0547  *
0548  * %CMDF_WRITE - marks the command as being in the "write" (to device)
0549  * direction.  This does not need to be specified by the caller unless the
0550  * subdevice supports commands in either direction.
0551  *
0552  * %CMDF_RAWDATA - prevents the command from "munging" the data between the
0553  * COMEDI sample format and the raw hardware sample format.
0554  *
0555  * %CMDF_ROUND_NEAREST - requests timing periods to be rounded to nearest
0556  * supported values.
0557  *
0558  * %CMDF_ROUND_DOWN - requests timing periods to be rounded down to supported
0559  * values (frequencies rounded up).
0560  *
0561  * %CMDF_ROUND_UP - requests timing periods to be rounded up to supported
0562  * values (frequencies rounded down).
0563  *
0564  * Trigger source values for @start_src, @scan_begin_src, @convert_src,
0565  * @scan_end_src, and @stop_src...
0566  *
0567  * %TRIG_ANY - "all ones" value used to test which trigger sources are
0568  * supported.
0569  *
0570  * %TRIG_INVALID - "all zeroes" value used to indicate that all requested
0571  * trigger sources are invalid.
0572  *
0573  * %TRIG_NONE - never trigger (often used as a @stop_src value).
0574  *
0575  * %TRIG_NOW - trigger after '_arg' nanoseconds.
0576  *
0577  * %TRIG_FOLLOW - trigger follows another event.
0578  *
0579  * %TRIG_TIMER - trigger every '_arg' nanoseconds.
0580  *
0581  * %TRIG_COUNT - trigger when count '_arg' is reached.
0582  *
0583  * %TRIG_EXT - trigger on external signal specified by '_arg'.
0584  *
0585  * %TRIG_INT - trigger on internal, software trigger specified by '_arg'.
0586  *
0587  * %TRIG_OTHER - trigger on other, driver-defined signal specified by '_arg'.
0588  */
0589 struct comedi_cmd {
0590     unsigned int subdev;
0591     unsigned int flags;
0592 
0593     unsigned int start_src;
0594     unsigned int start_arg;
0595 
0596     unsigned int scan_begin_src;
0597     unsigned int scan_begin_arg;
0598 
0599     unsigned int convert_src;
0600     unsigned int convert_arg;
0601 
0602     unsigned int scan_end_src;
0603     unsigned int scan_end_arg;
0604 
0605     unsigned int stop_src;
0606     unsigned int stop_arg;
0607 
0608     unsigned int *chanlist;
0609     unsigned int chanlist_len;
0610 
0611     short __user *data;
0612     unsigned int data_len;
0613 };
0614 
0615 /**
0616  * struct comedi_chaninfo - used to retrieve per-channel information
0617  * @subdev:     Subdevice index.
0618  * @maxdata_list:   Optional pointer to per-channel maximum data values.
0619  * @flaglist:       Optional pointer to per-channel flags.
0620  * @rangelist:      Optional pointer to per-channel range types.
0621  * @unused:     Reserved for future use.
0622  *
0623  * This is used with the %COMEDI_CHANINFO ioctl to get per-channel information
0624  * for the subdevice.  Use of this requires knowledge of the number of channels
0625  * and subdevice flags obtained using the %COMEDI_SUBDINFO ioctl.
0626  *
0627  * The @maxdata_list member must be %NULL unless the %SDF_MAXDATA subdevice
0628  * flag is set.  The @flaglist member must be %NULL unless the %SDF_FLAGS
0629  * subdevice flag is set.  The @rangelist member must be %NULL unless the
0630  * %SDF_RANGETYPE subdevice flag is set.  Otherwise, the arrays they point to
0631  * must be at least as long as the number of channels.
0632  */
0633 struct comedi_chaninfo {
0634     unsigned int subdev;
0635     unsigned int __user *maxdata_list;
0636     unsigned int __user *flaglist;
0637     unsigned int __user *rangelist;
0638     unsigned int unused[4];
0639 };
0640 
0641 /**
0642  * struct comedi_rangeinfo - used to retrieve the range table for a channel
0643  * @range_type:     Encodes subdevice index (bits 27:24), channel index
0644  *          (bits 23:16) and range table length (bits 15:0).
0645  * @range_ptr:      Pointer to array of @struct comedi_krange to be filled
0646  *          in with the range table for the channel or subdevice.
0647  *
0648  * This is used with the %COMEDI_RANGEINFO ioctl to retrieve the range table
0649  * for a specific channel (if the subdevice has the %SDF_RANGETYPE flag set to
0650  * indicate that the range table depends on the channel), or for the subdevice
0651  * as a whole (if the %SDF_RANGETYPE flag is clear, indicating the range table
0652  * is shared by all channels).
0653  *
0654  * The @range_type value is an input to the ioctl and comes from a previous
0655  * use of the %COMEDI_SUBDINFO ioctl (if the %SDF_RANGETYPE flag is clear),
0656  * or the %COMEDI_CHANINFO ioctl (if the %SDF_RANGETYPE flag is set).
0657  */
0658 struct comedi_rangeinfo {
0659     unsigned int range_type;
0660     void __user *range_ptr;
0661 };
0662 
0663 /**
0664  * struct comedi_krange - describes a range in a range table
0665  * @min:    Minimum value in millionths (1e-6) of a unit.
0666  * @max:    Maximum value in millionths (1e-6) of a unit.
0667  * @flags:  Indicates the units (in bits 7:0) OR'ed with optional flags.
0668  *
0669  * A range table is associated with a single channel, or with all channels in a
0670  * subdevice, and a list of one or more ranges.  A %struct comedi_krange
0671  * describes the physical range of units for one of those ranges.  Sample
0672  * values in COMEDI are unsigned from %0 up to some 'maxdata' value.  The
0673  * mapping from sample values to physical units is assumed to be nomimally
0674  * linear (for the purpose of describing the range), with sample value %0
0675  * mapping to @min, and the 'maxdata' sample value mapping to @max.
0676  *
0677  * The currently defined units are %UNIT_volt (%0), %UNIT_mA (%1), and
0678  * %UNIT_none (%2).  The @min and @max values are the physical range multiplied
0679  * by 1e6, so a @max value of %1000000 (with %UNIT_volt) represents a maximal
0680  * value of 1 volt.
0681  *
0682  * The only defined flag value is %RF_EXTERNAL (%0x100), indicating that the
0683  * range needs to be multiplied by an external reference.
0684  */
0685 struct comedi_krange {
0686     int min;
0687     int max;
0688     unsigned int flags;
0689 };
0690 
0691 /**
0692  * struct comedi_subdinfo - used to retrieve information about a subdevice
0693  * @type:       Type of subdevice from &enum comedi_subdevice_type.
0694  * @n_chan:     Number of channels the subdevice supports.
0695  * @subd_flags:     A mixture of static and dynamic flags describing
0696  *          aspects of the subdevice and its current state.
0697  * @timer_type:     Timer type.  Always set to %5 ("nanosecond timer").
0698  * @len_chanlist:   Maximum length of a channel list if the subdevice
0699  *          supports asynchronous acquisition commands.
0700  * @maxdata:        Maximum sample value for all channels if the
0701  *          %SDF_MAXDATA subdevice flag is clear.
0702  * @flags:      Channel flags for all channels if the %SDF_FLAGS
0703  *          subdevice flag is clear.
0704  * @range_type:     The range type for all channels if the %SDF_RANGETYPE
0705  *          subdevice flag is clear.  Encodes the subdevice index
0706  *          (bits 27:24), a dummy channel index %0 (bits 23:16),
0707  *          and the range table length (bits 15:0).
0708  * @settling_time_0:    Not used.
0709  * @insn_bits_support:  Set to %COMEDI_SUPPORTED if the subdevice supports the
0710  *          %INSN_BITS instruction, or to %COMEDI_UNSUPPORTED if it
0711  *          does not.
0712  * @unused:     Reserved for future use.
0713  *
0714  * This is used with the %COMEDI_SUBDINFO ioctl which copies an array of
0715  * &struct comedi_subdinfo back to user space, with one element per subdevice.
0716  * Use of this requires knowledge of the number of subdevices obtained from
0717  * the %COMEDI_DEVINFO ioctl.
0718  *
0719  * These are the @subd_flags values that may be ORed together...
0720  *
0721  * %SDF_BUSY - the subdevice is busy processing an asynchronous command or a
0722  * synchronous instruction.
0723  *
0724  * %SDF_BUSY_OWNER - the subdevice is busy processing an asynchronous
0725  * acquisition command started on the current file object (the file object
0726  * issuing the %COMEDI_SUBDINFO ioctl).
0727  *
0728  * %SDF_LOCKED - the subdevice is locked by a %COMEDI_LOCK ioctl.
0729  *
0730  * %SDF_LOCK_OWNER - the subdevice is locked by a %COMEDI_LOCK ioctl from the
0731  * current file object.
0732  *
0733  * %SDF_MAXDATA - maximum sample values are channel-specific.
0734  *
0735  * %SDF_FLAGS - channel flags are channel-specific.
0736  *
0737  * %SDF_RANGETYPE - range types are channel-specific.
0738  *
0739  * %SDF_PWM_COUNTER - PWM can switch off automatically.
0740  *
0741  * %SDF_PWM_HBRIDGE - or PWM is signed (H-bridge).
0742  *
0743  * %SDF_CMD - the subdevice supports asynchronous commands.
0744  *
0745  * %SDF_SOFT_CALIBRATED - the subdevice uses software calibration.
0746  *
0747  * %SDF_CMD_WRITE - the subdevice supports asynchronous commands in the output
0748  * ("write") direction.
0749  *
0750  * %SDF_CMD_READ - the subdevice supports asynchronous commands in the input
0751  * ("read") direction.
0752  *
0753  * %SDF_READABLE - the subdevice is readable (e.g. analog input).
0754  *
0755  * %SDF_WRITABLE (aliased as %SDF_WRITEABLE) - the subdevice is writable (e.g.
0756  * analog output).
0757  *
0758  * %SDF_INTERNAL - the subdevice has no externally visible lines.
0759  *
0760  * %SDF_GROUND - the subdevice can use ground as an analog reference.
0761  *
0762  * %SDF_COMMON - the subdevice can use a common analog reference.
0763  *
0764  * %SDF_DIFF - the subdevice can use differential inputs (or outputs).
0765  *
0766  * %SDF_OTHER - the subdevice can use some other analog reference.
0767  *
0768  * %SDF_DITHER - the subdevice can do dithering.
0769  *
0770  * %SDF_DEGLITCH - the subdevice can do deglitching.
0771  *
0772  * %SDF_MMAP - this is never set.
0773  *
0774  * %SDF_RUNNING - an asynchronous command is still running.
0775  *
0776  * %SDF_LSAMPL - the subdevice uses "long" (32-bit) samples (for asynchronous
0777  * command data).
0778  *
0779  * %SDF_PACKED - the subdevice packs several DIO samples into a single sample
0780  * (for asynchronous command data).
0781  *
0782  * No "channel flags" (@flags) values are currently defined.
0783  */
0784 struct comedi_subdinfo {
0785     unsigned int type;
0786     unsigned int n_chan;
0787     unsigned int subd_flags;
0788     unsigned int timer_type;
0789     unsigned int len_chanlist;
0790     unsigned int maxdata;
0791     unsigned int flags;
0792     unsigned int range_type;
0793     unsigned int settling_time_0;
0794     unsigned int insn_bits_support;
0795     unsigned int unused[8];
0796 };
0797 
0798 /**
0799  * struct comedi_devinfo - used to retrieve information about a COMEDI device
0800  * @version_code:   COMEDI version code.
0801  * @n_subdevs:      Number of subdevices the device has.
0802  * @driver_name:    Null-terminated COMEDI driver name.
0803  * @board_name:     Null-terminated COMEDI board name.
0804  * @read_subdevice: Index of the current "read" subdevice (%-1 if none).
0805  * @write_subdevice:    Index of the current "write" subdevice (%-1 if none).
0806  * @unused:     Reserved for future use.
0807  *
0808  * This is used with the %COMEDI_DEVINFO ioctl to get basic information about
0809  * the device.
0810  */
0811 struct comedi_devinfo {
0812     unsigned int version_code;
0813     unsigned int n_subdevs;
0814     char driver_name[COMEDI_NAMELEN];
0815     char board_name[COMEDI_NAMELEN];
0816     int read_subdevice;
0817     int write_subdevice;
0818     int unused[30];
0819 };
0820 
0821 /**
0822  * struct comedi_devconfig - used to configure a legacy COMEDI device
0823  * @board_name:     Null-terminated string specifying the type of board
0824  *          to configure.
0825  * @options:        An array of integer configuration options.
0826  *
0827  * This is used with the %COMEDI_DEVCONFIG ioctl to configure a "legacy" COMEDI
0828  * device, such as an ISA card.  Not all COMEDI drivers support this.  Those
0829  * that do either expect the specified board name to match one of a list of
0830  * names registered with the COMEDI core, or expect the specified board name
0831  * to match the COMEDI driver name itself.  The configuration options are
0832  * handled in a driver-specific manner.
0833  */
0834 struct comedi_devconfig {
0835     char board_name[COMEDI_NAMELEN];
0836     int options[COMEDI_NDEVCONFOPTS];
0837 };
0838 
0839 /**
0840  * struct comedi_bufconfig - used to set or get buffer size for a subdevice
0841  * @subdevice:      Subdevice index.
0842  * @flags:      Not used.
0843  * @maximum_size:   Maximum allowed buffer size.
0844  * @size:       Buffer size.
0845  * @unused:     Reserved for future use.
0846  *
0847  * This is used with the %COMEDI_BUFCONFIG ioctl to get or configure the
0848  * maximum buffer size and current buffer size for a COMEDI subdevice that
0849  * supports asynchronous commands.  If the subdevice does not support
0850  * asynchronous commands, @maximum_size and @size are ignored and set to 0.
0851  *
0852  * On ioctl input, non-zero values of @maximum_size and @size specify a
0853  * new maximum size and new current size (in bytes), respectively.  These
0854  * will by rounded up to a multiple of %PAGE_SIZE.  Specifying a new maximum
0855  * size requires admin capabilities.
0856  *
0857  * On ioctl output, @maximum_size and @size and set to the current maximum
0858  * buffer size and current buffer size, respectively.
0859  */
0860 struct comedi_bufconfig {
0861     unsigned int subdevice;
0862     unsigned int flags;
0863 
0864     unsigned int maximum_size;
0865     unsigned int size;
0866 
0867     unsigned int unused[4];
0868 };
0869 
0870 /**
0871  * struct comedi_bufinfo - used to manipulate buffer position for a subdevice
0872  * @subdevice:      Subdevice index.
0873  * @bytes_read:     Specify amount to advance read position for an
0874  *          asynchronous command in the input ("read") direction.
0875  * @buf_write_ptr:  Current write position (index) within the buffer.
0876  * @buf_read_ptr:   Current read position (index) within the buffer.
0877  * @buf_write_count:    Total amount written, modulo 2^32.
0878  * @buf_read_count: Total amount read, modulo 2^32.
0879  * @bytes_written:  Specify amount to advance write position for an
0880  *          asynchronous command in the output ("write") direction.
0881  * @unused:     Reserved for future use.
0882  *
0883  * This is used with the %COMEDI_BUFINFO ioctl to optionally advance the
0884  * current read or write position in an asynchronous acquisition data buffer,
0885  * and to get the current read and write positions in the buffer.
0886  */
0887 struct comedi_bufinfo {
0888     unsigned int subdevice;
0889     unsigned int bytes_read;
0890 
0891     unsigned int buf_write_ptr;
0892     unsigned int buf_read_ptr;
0893     unsigned int buf_write_count;
0894     unsigned int buf_read_count;
0895 
0896     unsigned int bytes_written;
0897 
0898     unsigned int unused[4];
0899 };
0900 
0901 /* range stuff */
0902 
0903 #define __RANGE(a, b)   ((((a) & 0xffff) << 16) | ((b) & 0xffff))
0904 
0905 #define RANGE_OFFSET(a)     (((a) >> 16) & 0xffff)
0906 #define RANGE_LENGTH(b)     ((b) & 0xffff)
0907 
0908 #define RF_UNIT(flags)      ((flags) & 0xff)
0909 #define RF_EXTERNAL     0x100
0910 
0911 #define UNIT_volt       0
0912 #define UNIT_mA         1
0913 #define UNIT_none       2
0914 
0915 #define COMEDI_MIN_SPEED    0xffffffffu
0916 
0917 /**********************************************************/
0918 /* everything after this line is ALPHA */
0919 /**********************************************************/
0920 
0921 /*
0922  * 8254 specific configuration.
0923  *
0924  * It supports two config commands:
0925  *
0926  * 0 ID: INSN_CONFIG_SET_COUNTER_MODE
0927  * 1 8254 Mode
0928  * I8254_MODE0, I8254_MODE1, ..., I8254_MODE5
0929  * OR'ed with:
0930  * I8254_BCD, I8254_BINARY
0931  *
0932  * 0 ID: INSN_CONFIG_8254_READ_STATUS
0933  * 1 <-- Status byte returned here.
0934  * B7 = Output
0935  * B6 = NULL Count
0936  * B5 - B0 Current mode.
0937  */
0938 
0939 enum i8254_mode {
0940     I8254_MODE0 = (0 << 1), /* Interrupt on terminal count */
0941     I8254_MODE1 = (1 << 1), /* Hardware retriggerable one-shot */
0942     I8254_MODE2 = (2 << 1), /* Rate generator */
0943     I8254_MODE3 = (3 << 1), /* Square wave mode */
0944     I8254_MODE4 = (4 << 1), /* Software triggered strobe */
0945     /* Hardware triggered strobe (retriggerable) */
0946     I8254_MODE5 = (5 << 1),
0947     /* Use binary-coded decimal instead of binary (pretty useless) */
0948     I8254_BCD = 1,
0949     I8254_BINARY = 0
0950 };
0951 
0952 /* *** BEGIN GLOBALLY-NAMED NI TERMINALS/SIGNALS *** */
0953 
0954 /*
0955  * Common National Instruments Terminal/Signal names.
0956  * Some of these have no NI_ prefix as they are useful for non-NI hardware, such
0957  * as those that utilize the PXI/RTSI trigger lines.
0958  *
0959  * NOTE ABOUT THE CHOICE OF NAMES HERE AND THE CAMELSCRIPT:
0960  *   The choice to use CamelScript and the exact names below is for
0961  *   maintainability, clarity, similarity to manufacturer's documentation,
0962  *   _and_ a mitigation for confusion that has plagued the use of these drivers
0963  *   for years!
0964  *
0965  *   More detail:
0966  *   There have been significant confusions over the past many years for users
0967  *   when trying to understand how to connect to/from signals and terminals on
0968  *   NI hardware using comedi.  The major reason for this is that the actual
0969  *   register values were exposed and required to be used by users.  Several
0970  *   major reasons exist why this caused major confusion for users:
0971  *   1) The register values are _NOT_ in user documentation, but rather in
0972  *     arcane locations, such as a few register programming manuals that are
0973  *     increasingly hard to find and the NI MHDDK (comments in example code).
0974  *     There is no one place to find the various valid values of the registers.
0975  *   2) The register values are _NOT_ completely consistent.  There is no way to
0976  *     gain any sense of intuition of which values, or even enums one should use
0977  *     for various registers.  There was some attempt in prior use of comedi to
0978  *     name enums such that a user might know which enums should be used for
0979  *     varying purposes, but the end-user had to gain a knowledge of register
0980  *     values to correctly wield this approach.
0981  *   3) The names for signals and registers found in the various register level
0982  *     programming manuals and vendor-provided documentation are _not_ even
0983  *     close to the same names that are in the end-user documentation.
0984  *
0985  *   Similar, albeit less, confusion plagued NI's previous version of their own
0986  *   drivers.  Earlier than 2003, NI greatly simplified the situation for users
0987  *   by releasing a new API that abstracted the names of signals/terminals to a
0988  *   common and intuitive set of names.
0989  *
0990  *   The names below mirror the names chosen and well documented by NI.  These
0991  *   names are exposed to the user via the comedilib user library.  By keeping
0992  *   the names below, in spite of the use of CamelScript, maintenance will be
0993  *   greatly eased and confusion for users _and_ comedi developers will be
0994  *   greatly reduced.
0995  */
0996 
0997 /*
0998  * Base of abstracted NI names.
0999  * The first 16 bits of *_arg are reserved for channel selection.
1000  * Since we only actually need the first 4 or 5 bits for all register values on
1001  * NI select registers anyways, we'll identify all values >= (1<<15) as being an
1002  * abstracted NI signal/terminal name.
1003  * These values are also used/returned by INSN_DEVICE_CONFIG_TEST_ROUTE,
1004  * INSN_DEVICE_CONFIG_CONNECT_ROUTE, INSN_DEVICE_CONFIG_DISCONNECT_ROUTE,
1005  * and INSN_DEVICE_CONFIG_GET_ROUTES.
1006  */
1007 #define NI_NAMES_BASE   0x8000u
1008 
1009 #define _TERM_N(base, n, x) ((base) + ((x) & ((n) - 1)))
1010 
1011 /*
1012  * not necessarily all allowed 64 PFIs are valid--certainly not for all devices
1013  */
1014 #define NI_PFI(x)       _TERM_N(NI_NAMES_BASE, 64, x)
1015 /* 8 trigger lines by standard, Some devices cannot talk to all eight. */
1016 #define TRIGGER_LINE(x)     _TERM_N(NI_PFI(-1) + 1, 8, x)
1017 /* 4 RTSI shared MUXes to route signals to/from TRIGGER_LINES on NI hardware */
1018 #define NI_RTSI_BRD(x)      _TERM_N(TRIGGER_LINE(-1) + 1, 4, x)
1019 
1020 /* *** Counter/timer names : 8 counters max *** */
1021 #define NI_MAX_COUNTERS     8
1022 #define NI_COUNTER_NAMES_BASE   (NI_RTSI_BRD(-1)  + 1)
1023 #define NI_CtrSource(x)       _TERM_N(NI_COUNTER_NAMES_BASE, NI_MAX_COUNTERS, x)
1024 /* Gate, Aux, A,B,Z are all treated, at times as gates */
1025 #define NI_GATES_NAMES_BASE (NI_CtrSource(-1) + 1)
1026 #define NI_CtrGate(x)       _TERM_N(NI_GATES_NAMES_BASE, NI_MAX_COUNTERS, x)
1027 #define NI_CtrAux(x)        _TERM_N(NI_CtrGate(-1)  + 1, NI_MAX_COUNTERS, x)
1028 #define NI_CtrA(x)      _TERM_N(NI_CtrAux(-1)   + 1, NI_MAX_COUNTERS, x)
1029 #define NI_CtrB(x)      _TERM_N(NI_CtrA(-1)     + 1, NI_MAX_COUNTERS, x)
1030 #define NI_CtrZ(x)      _TERM_N(NI_CtrB(-1)     + 1, NI_MAX_COUNTERS, x)
1031 #define NI_GATES_NAMES_MAX  NI_CtrZ(-1)
1032 #define NI_CtrArmStartTrigger(x) _TERM_N(NI_CtrZ(-1)    + 1, NI_MAX_COUNTERS, x)
1033 #define NI_CtrInternalOutput(x) \
1034               _TERM_N(NI_CtrArmStartTrigger(-1) + 1, NI_MAX_COUNTERS, x)
1035 /** external pin(s) labeled conveniently as Ctr<i>Out. */
1036 #define NI_CtrOut(x)   _TERM_N(NI_CtrInternalOutput(-1) + 1, NI_MAX_COUNTERS, x)
1037 /** For Buffered sampling of ctr -- x series capability. */
1038 #define NI_CtrSampleClock(x)    _TERM_N(NI_CtrOut(-1)   + 1, NI_MAX_COUNTERS, x)
1039 #define NI_COUNTER_NAMES_MAX    NI_CtrSampleClock(-1)
1040 
1041 enum ni_common_signal_names {
1042     /* PXI_Star: this is a non-NI-specific signal */
1043     PXI_Star = NI_COUNTER_NAMES_MAX + 1,
1044     PXI_Clk10,
1045     PXIe_Clk100,
1046     NI_AI_SampleClock,
1047     NI_AI_SampleClockTimebase,
1048     NI_AI_StartTrigger,
1049     NI_AI_ReferenceTrigger,
1050     NI_AI_ConvertClock,
1051     NI_AI_ConvertClockTimebase,
1052     NI_AI_PauseTrigger,
1053     NI_AI_HoldCompleteEvent,
1054     NI_AI_HoldComplete,
1055     NI_AI_ExternalMUXClock,
1056     NI_AI_STOP, /* pulse signal that occurs when a update is finished(?) */
1057     NI_AO_SampleClock,
1058     NI_AO_SampleClockTimebase,
1059     NI_AO_StartTrigger,
1060     NI_AO_PauseTrigger,
1061     NI_DI_SampleClock,
1062     NI_DI_SampleClockTimebase,
1063     NI_DI_StartTrigger,
1064     NI_DI_ReferenceTrigger,
1065     NI_DI_PauseTrigger,
1066     NI_DI_InputBufferFull,
1067     NI_DI_ReadyForStartEvent,
1068     NI_DI_ReadyForTransferEventBurst,
1069     NI_DI_ReadyForTransferEventPipelined,
1070     NI_DO_SampleClock,
1071     NI_DO_SampleClockTimebase,
1072     NI_DO_StartTrigger,
1073     NI_DO_PauseTrigger,
1074     NI_DO_OutputBufferFull,
1075     NI_DO_DataActiveEvent,
1076     NI_DO_ReadyForStartEvent,
1077     NI_DO_ReadyForTransferEvent,
1078     NI_MasterTimebase,
1079     NI_20MHzTimebase,
1080     NI_80MHzTimebase,
1081     NI_100MHzTimebase,
1082     NI_200MHzTimebase,
1083     NI_100kHzTimebase,
1084     NI_10MHzRefClock,
1085     NI_FrequencyOutput,
1086     NI_ChangeDetectionEvent,
1087     NI_AnalogComparisonEvent,
1088     NI_WatchdogExpiredEvent,
1089     NI_WatchdogExpirationTrigger,
1090     NI_SCXI_Trig1,
1091     NI_LogicLow,
1092     NI_LogicHigh,
1093     NI_ExternalStrobe,
1094     NI_PFI_DO,
1095     NI_CaseGround,
1096     /* special internal signal used as variable source for RTSI bus: */
1097     NI_RGOUT0,
1098 
1099     /* just a name to make the next more convenient, regardless of above */
1100     _NI_NAMES_MAX_PLUS_1,
1101     NI_NUM_NAMES = _NI_NAMES_MAX_PLUS_1 - NI_NAMES_BASE,
1102 };
1103 
1104 /* *** END GLOBALLY-NAMED NI TERMINALS/SIGNALS *** */
1105 
1106 #define NI_USUAL_PFI_SELECT(x)  (((x) < 10) ? (0x1 + (x)) : (0xb + (x)))
1107 #define NI_USUAL_RTSI_SELECT(x) (((x) < 7) ? (0xb + (x)) : 0x1b)
1108 
1109 /*
1110  * mode bits for NI general-purpose counters, set with
1111  * INSN_CONFIG_SET_COUNTER_MODE
1112  */
1113 #define NI_GPCT_COUNTING_MODE_SHIFT 16
1114 #define NI_GPCT_INDEX_PHASE_BITSHIFT 20
1115 #define NI_GPCT_COUNTING_DIRECTION_SHIFT 24
1116 enum ni_gpct_mode_bits {
1117     NI_GPCT_GATE_ON_BOTH_EDGES_BIT = 0x4,
1118     NI_GPCT_EDGE_GATE_MODE_MASK = 0x18,
1119     NI_GPCT_EDGE_GATE_STARTS_STOPS_BITS = 0x0,
1120     NI_GPCT_EDGE_GATE_STOPS_STARTS_BITS = 0x8,
1121     NI_GPCT_EDGE_GATE_STARTS_BITS = 0x10,
1122     NI_GPCT_EDGE_GATE_NO_STARTS_NO_STOPS_BITS = 0x18,
1123     NI_GPCT_STOP_MODE_MASK = 0x60,
1124     NI_GPCT_STOP_ON_GATE_BITS = 0x00,
1125     NI_GPCT_STOP_ON_GATE_OR_TC_BITS = 0x20,
1126     NI_GPCT_STOP_ON_GATE_OR_SECOND_TC_BITS = 0x40,
1127     NI_GPCT_LOAD_B_SELECT_BIT = 0x80,
1128     NI_GPCT_OUTPUT_MODE_MASK = 0x300,
1129     NI_GPCT_OUTPUT_TC_PULSE_BITS = 0x100,
1130     NI_GPCT_OUTPUT_TC_TOGGLE_BITS = 0x200,
1131     NI_GPCT_OUTPUT_TC_OR_GATE_TOGGLE_BITS = 0x300,
1132     NI_GPCT_HARDWARE_DISARM_MASK = 0xc00,
1133     NI_GPCT_NO_HARDWARE_DISARM_BITS = 0x000,
1134     NI_GPCT_DISARM_AT_TC_BITS = 0x400,
1135     NI_GPCT_DISARM_AT_GATE_BITS = 0x800,
1136     NI_GPCT_DISARM_AT_TC_OR_GATE_BITS = 0xc00,
1137     NI_GPCT_LOADING_ON_TC_BIT = 0x1000,
1138     NI_GPCT_LOADING_ON_GATE_BIT = 0x4000,
1139     NI_GPCT_COUNTING_MODE_MASK = 0x7 << NI_GPCT_COUNTING_MODE_SHIFT,
1140     NI_GPCT_COUNTING_MODE_NORMAL_BITS =
1141         0x0 << NI_GPCT_COUNTING_MODE_SHIFT,
1142     NI_GPCT_COUNTING_MODE_QUADRATURE_X1_BITS =
1143         0x1 << NI_GPCT_COUNTING_MODE_SHIFT,
1144     NI_GPCT_COUNTING_MODE_QUADRATURE_X2_BITS =
1145         0x2 << NI_GPCT_COUNTING_MODE_SHIFT,
1146     NI_GPCT_COUNTING_MODE_QUADRATURE_X4_BITS =
1147         0x3 << NI_GPCT_COUNTING_MODE_SHIFT,
1148     NI_GPCT_COUNTING_MODE_TWO_PULSE_BITS =
1149         0x4 << NI_GPCT_COUNTING_MODE_SHIFT,
1150     NI_GPCT_COUNTING_MODE_SYNC_SOURCE_BITS =
1151         0x6 << NI_GPCT_COUNTING_MODE_SHIFT,
1152     NI_GPCT_INDEX_PHASE_MASK = 0x3 << NI_GPCT_INDEX_PHASE_BITSHIFT,
1153     NI_GPCT_INDEX_PHASE_LOW_A_LOW_B_BITS =
1154         0x0 << NI_GPCT_INDEX_PHASE_BITSHIFT,
1155     NI_GPCT_INDEX_PHASE_LOW_A_HIGH_B_BITS =
1156         0x1 << NI_GPCT_INDEX_PHASE_BITSHIFT,
1157     NI_GPCT_INDEX_PHASE_HIGH_A_LOW_B_BITS =
1158         0x2 << NI_GPCT_INDEX_PHASE_BITSHIFT,
1159     NI_GPCT_INDEX_PHASE_HIGH_A_HIGH_B_BITS =
1160         0x3 << NI_GPCT_INDEX_PHASE_BITSHIFT,
1161     NI_GPCT_INDEX_ENABLE_BIT = 0x400000,
1162     NI_GPCT_COUNTING_DIRECTION_MASK =
1163         0x3 << NI_GPCT_COUNTING_DIRECTION_SHIFT,
1164     NI_GPCT_COUNTING_DIRECTION_DOWN_BITS =
1165         0x00 << NI_GPCT_COUNTING_DIRECTION_SHIFT,
1166     NI_GPCT_COUNTING_DIRECTION_UP_BITS =
1167         0x1 << NI_GPCT_COUNTING_DIRECTION_SHIFT,
1168     NI_GPCT_COUNTING_DIRECTION_HW_UP_DOWN_BITS =
1169         0x2 << NI_GPCT_COUNTING_DIRECTION_SHIFT,
1170     NI_GPCT_COUNTING_DIRECTION_HW_GATE_BITS =
1171         0x3 << NI_GPCT_COUNTING_DIRECTION_SHIFT,
1172     NI_GPCT_RELOAD_SOURCE_MASK = 0xc000000,
1173     NI_GPCT_RELOAD_SOURCE_FIXED_BITS = 0x0,
1174     NI_GPCT_RELOAD_SOURCE_SWITCHING_BITS = 0x4000000,
1175     NI_GPCT_RELOAD_SOURCE_GATE_SELECT_BITS = 0x8000000,
1176     NI_GPCT_OR_GATE_BIT = 0x10000000,
1177     NI_GPCT_INVERT_OUTPUT_BIT = 0x20000000
1178 };
1179 
1180 /*
1181  * Bits for setting a clock source with
1182  * INSN_CONFIG_SET_CLOCK_SRC when using NI general-purpose counters.
1183  */
1184 enum ni_gpct_clock_source_bits {
1185     NI_GPCT_CLOCK_SRC_SELECT_MASK = 0x3f,
1186     NI_GPCT_TIMEBASE_1_CLOCK_SRC_BITS = 0x0,
1187     NI_GPCT_TIMEBASE_2_CLOCK_SRC_BITS = 0x1,
1188     NI_GPCT_TIMEBASE_3_CLOCK_SRC_BITS = 0x2,
1189     NI_GPCT_LOGIC_LOW_CLOCK_SRC_BITS = 0x3,
1190     NI_GPCT_NEXT_GATE_CLOCK_SRC_BITS = 0x4,
1191     NI_GPCT_NEXT_TC_CLOCK_SRC_BITS = 0x5,
1192     /* NI 660x-specific */
1193     NI_GPCT_SOURCE_PIN_i_CLOCK_SRC_BITS = 0x6,
1194     NI_GPCT_PXI10_CLOCK_SRC_BITS = 0x7,
1195     NI_GPCT_PXI_STAR_TRIGGER_CLOCK_SRC_BITS = 0x8,
1196     NI_GPCT_ANALOG_TRIGGER_OUT_CLOCK_SRC_BITS = 0x9,
1197     NI_GPCT_PRESCALE_MODE_CLOCK_SRC_MASK = 0x30000000,
1198     NI_GPCT_NO_PRESCALE_CLOCK_SRC_BITS = 0x0,
1199     /* divide source by 2 */
1200     NI_GPCT_PRESCALE_X2_CLOCK_SRC_BITS = 0x10000000,
1201     /* divide source by 8 */
1202     NI_GPCT_PRESCALE_X8_CLOCK_SRC_BITS = 0x20000000,
1203     NI_GPCT_INVERT_CLOCK_SRC_BIT = 0x80000000
1204 };
1205 
1206 /* NI 660x-specific */
1207 #define NI_GPCT_SOURCE_PIN_CLOCK_SRC_BITS(x)    (0x10 + (x))
1208 
1209 #define NI_GPCT_RTSI_CLOCK_SRC_BITS(x)      (0x18 + (x))
1210 
1211 /* no pfi on NI 660x */
1212 #define NI_GPCT_PFI_CLOCK_SRC_BITS(x)       (0x20 + (x))
1213 
1214 /*
1215  * Possibilities for setting a gate source with
1216  * INSN_CONFIG_SET_GATE_SRC when using NI general-purpose counters.
1217  * May be bitwise-or'd with CR_EDGE or CR_INVERT.
1218  */
1219 enum ni_gpct_gate_select {
1220     /* m-series gates */
1221     NI_GPCT_TIMESTAMP_MUX_GATE_SELECT = 0x0,
1222     NI_GPCT_AI_START2_GATE_SELECT = 0x12,
1223     NI_GPCT_PXI_STAR_TRIGGER_GATE_SELECT = 0x13,
1224     NI_GPCT_NEXT_OUT_GATE_SELECT = 0x14,
1225     NI_GPCT_AI_START1_GATE_SELECT = 0x1c,
1226     NI_GPCT_NEXT_SOURCE_GATE_SELECT = 0x1d,
1227     NI_GPCT_ANALOG_TRIGGER_OUT_GATE_SELECT = 0x1e,
1228     NI_GPCT_LOGIC_LOW_GATE_SELECT = 0x1f,
1229     /* more gates for 660x */
1230     NI_GPCT_SOURCE_PIN_i_GATE_SELECT = 0x100,
1231     NI_GPCT_GATE_PIN_i_GATE_SELECT = 0x101,
1232     /* more gates for 660x "second gate" */
1233     NI_GPCT_UP_DOWN_PIN_i_GATE_SELECT = 0x201,
1234     NI_GPCT_SELECTED_GATE_GATE_SELECT = 0x21e,
1235     /*
1236      * m-series "second gate" sources are unknown,
1237      * we should add them here with an offset of 0x300 when
1238      * known.
1239      */
1240     NI_GPCT_DISABLED_GATE_SELECT = 0x8000,
1241 };
1242 
1243 #define NI_GPCT_GATE_PIN_GATE_SELECT(x)     (0x102 + (x))
1244 #define NI_GPCT_RTSI_GATE_SELECT(x)     NI_USUAL_RTSI_SELECT(x)
1245 #define NI_GPCT_PFI_GATE_SELECT(x)      NI_USUAL_PFI_SELECT(x)
1246 #define NI_GPCT_UP_DOWN_PIN_GATE_SELECT(x)  (0x202 + (x))
1247 
1248 /*
1249  * Possibilities for setting a source with
1250  * INSN_CONFIG_SET_OTHER_SRC when using NI general-purpose counters.
1251  */
1252 enum ni_gpct_other_index {
1253     NI_GPCT_SOURCE_ENCODER_A,
1254     NI_GPCT_SOURCE_ENCODER_B,
1255     NI_GPCT_SOURCE_ENCODER_Z
1256 };
1257 
1258 enum ni_gpct_other_select {
1259     /* m-series gates */
1260     /* Still unknown, probably only need NI_GPCT_PFI_OTHER_SELECT */
1261     NI_GPCT_DISABLED_OTHER_SELECT = 0x8000,
1262 };
1263 
1264 #define NI_GPCT_PFI_OTHER_SELECT(x) NI_USUAL_PFI_SELECT(x)
1265 
1266 /*
1267  * start sources for ni general-purpose counters for use with
1268  * INSN_CONFIG_ARM
1269  */
1270 enum ni_gpct_arm_source {
1271     NI_GPCT_ARM_IMMEDIATE = 0x0,
1272     /*
1273      * Start both the counter and the adjacent paired counter simultaneously
1274      */
1275     NI_GPCT_ARM_PAIRED_IMMEDIATE = 0x1,
1276     /*
1277      * If the NI_GPCT_HW_ARM bit is set, we will pass the least significant
1278      * bits (3 bits for 660x or 5 bits for m-series) through to the
1279      * hardware. To select a hardware trigger, pass the appropriate select
1280      * bit, e.g.,
1281      * NI_GPCT_HW_ARM | NI_GPCT_AI_START1_GATE_SELECT or
1282      * NI_GPCT_HW_ARM | NI_GPCT_PFI_GATE_SELECT(pfi_number)
1283      */
1284     NI_GPCT_HW_ARM = 0x1000,
1285     NI_GPCT_ARM_UNKNOWN = NI_GPCT_HW_ARM,   /* for backward compatibility */
1286 };
1287 
1288 /* digital filtering options for ni 660x for use with INSN_CONFIG_FILTER. */
1289 enum ni_gpct_filter_select {
1290     NI_GPCT_FILTER_OFF = 0x0,
1291     NI_GPCT_FILTER_TIMEBASE_3_SYNC = 0x1,
1292     NI_GPCT_FILTER_100x_TIMEBASE_1 = 0x2,
1293     NI_GPCT_FILTER_20x_TIMEBASE_1 = 0x3,
1294     NI_GPCT_FILTER_10x_TIMEBASE_1 = 0x4,
1295     NI_GPCT_FILTER_2x_TIMEBASE_1 = 0x5,
1296     NI_GPCT_FILTER_2x_TIMEBASE_3 = 0x6
1297 };
1298 
1299 /*
1300  * PFI digital filtering options for ni m-series for use with
1301  * INSN_CONFIG_FILTER.
1302  */
1303 enum ni_pfi_filter_select {
1304     NI_PFI_FILTER_OFF = 0x0,
1305     NI_PFI_FILTER_125ns = 0x1,
1306     NI_PFI_FILTER_6425ns = 0x2,
1307     NI_PFI_FILTER_2550us = 0x3
1308 };
1309 
1310 /* master clock sources for ni mio boards and INSN_CONFIG_SET_CLOCK_SRC */
1311 enum ni_mio_clock_source {
1312     NI_MIO_INTERNAL_CLOCK = 0,
1313     /*
1314      * Doesn't work for m-series, use NI_MIO_PLL_RTSI_CLOCK()
1315      * the NI_MIO_PLL_* sources are m-series only
1316      */
1317     NI_MIO_RTSI_CLOCK = 1,
1318     NI_MIO_PLL_PXI_STAR_TRIGGER_CLOCK = 2,
1319     NI_MIO_PLL_PXI10_CLOCK = 3,
1320     NI_MIO_PLL_RTSI0_CLOCK = 4
1321 };
1322 
1323 #define NI_MIO_PLL_RTSI_CLOCK(x)    (NI_MIO_PLL_RTSI0_CLOCK + (x))
1324 
1325 /*
1326  * Signals which can be routed to an NI RTSI pin with INSN_CONFIG_SET_ROUTING.
1327  * The numbers assigned are not arbitrary, they correspond to the bits required
1328  * to program the board.
1329  */
1330 enum ni_rtsi_routing {
1331     NI_RTSI_OUTPUT_ADR_START1 = 0,
1332     NI_RTSI_OUTPUT_ADR_START2 = 1,
1333     NI_RTSI_OUTPUT_SCLKG = 2,
1334     NI_RTSI_OUTPUT_DACUPDN = 3,
1335     NI_RTSI_OUTPUT_DA_START1 = 4,
1336     NI_RTSI_OUTPUT_G_SRC0 = 5,
1337     NI_RTSI_OUTPUT_G_GATE0 = 6,
1338     NI_RTSI_OUTPUT_RGOUT0 = 7,
1339     NI_RTSI_OUTPUT_RTSI_BRD_0 = 8,
1340     /* Pre-m-series always have RTSI clock on line 7 */
1341     NI_RTSI_OUTPUT_RTSI_OSC = 12
1342 };
1343 
1344 #define NI_RTSI_OUTPUT_RTSI_BRD(x)  (NI_RTSI_OUTPUT_RTSI_BRD_0 + (x))
1345 
1346 /*
1347  * Signals which can be routed to an NI PFI pin on an m-series board with
1348  * INSN_CONFIG_SET_ROUTING.  These numbers are also returned by
1349  * INSN_CONFIG_GET_ROUTING on pre-m-series boards, even though their routing
1350  * cannot be changed.  The numbers assigned are not arbitrary, they correspond
1351  * to the bits required to program the board.
1352  */
1353 enum ni_pfi_routing {
1354     NI_PFI_OUTPUT_PFI_DEFAULT = 0,
1355     NI_PFI_OUTPUT_AI_START1 = 1,
1356     NI_PFI_OUTPUT_AI_START2 = 2,
1357     NI_PFI_OUTPUT_AI_CONVERT = 3,
1358     NI_PFI_OUTPUT_G_SRC1 = 4,
1359     NI_PFI_OUTPUT_G_GATE1 = 5,
1360     NI_PFI_OUTPUT_AO_UPDATE_N = 6,
1361     NI_PFI_OUTPUT_AO_START1 = 7,
1362     NI_PFI_OUTPUT_AI_START_PULSE = 8,
1363     NI_PFI_OUTPUT_G_SRC0 = 9,
1364     NI_PFI_OUTPUT_G_GATE0 = 10,
1365     NI_PFI_OUTPUT_EXT_STROBE = 11,
1366     NI_PFI_OUTPUT_AI_EXT_MUX_CLK = 12,
1367     NI_PFI_OUTPUT_GOUT0 = 13,
1368     NI_PFI_OUTPUT_GOUT1 = 14,
1369     NI_PFI_OUTPUT_FREQ_OUT = 15,
1370     NI_PFI_OUTPUT_PFI_DO = 16,
1371     NI_PFI_OUTPUT_I_ATRIG = 17,
1372     NI_PFI_OUTPUT_RTSI0 = 18,
1373     NI_PFI_OUTPUT_PXI_STAR_TRIGGER_IN = 26,
1374     NI_PFI_OUTPUT_SCXI_TRIG1 = 27,
1375     NI_PFI_OUTPUT_DIO_CHANGE_DETECT_RTSI = 28,
1376     NI_PFI_OUTPUT_CDI_SAMPLE = 29,
1377     NI_PFI_OUTPUT_CDO_UPDATE = 30
1378 };
1379 
1380 #define NI_PFI_OUTPUT_RTSI(x)       (NI_PFI_OUTPUT_RTSI0 + (x))
1381 
1382 /*
1383  * Signals which can be routed to output on a NI PFI pin on a 660x board
1384  * with INSN_CONFIG_SET_ROUTING.  The numbers assigned are
1385  * not arbitrary, they correspond to the bits required
1386  * to program the board.  Lines 0 to 7 can only be set to
1387  * NI_660X_PFI_OUTPUT_DIO.  Lines 32 to 39 can only be set to
1388  * NI_660X_PFI_OUTPUT_COUNTER.
1389  */
1390 enum ni_660x_pfi_routing {
1391     NI_660X_PFI_OUTPUT_COUNTER = 1, /* counter */
1392     NI_660X_PFI_OUTPUT_DIO = 2, /* static digital output */
1393 };
1394 
1395 /*
1396  * NI External Trigger lines.  These values are not arbitrary, but are related
1397  * to the bits required to program the board (offset by 1 for historical
1398  * reasons).
1399  */
1400 #define NI_EXT_PFI(x)           (NI_USUAL_PFI_SELECT(x) - 1)
1401 #define NI_EXT_RTSI(x)          (NI_USUAL_RTSI_SELECT(x) - 1)
1402 
1403 /*
1404  * Clock sources for CDIO subdevice on NI m-series boards.  Used as the
1405  * scan_begin_arg for a comedi_command. These sources may also be bitwise-or'd
1406  * with CR_INVERT to change polarity.
1407  */
1408 enum ni_m_series_cdio_scan_begin_src {
1409     NI_CDIO_SCAN_BEGIN_SRC_GROUND = 0,
1410     NI_CDIO_SCAN_BEGIN_SRC_AI_START = 18,
1411     NI_CDIO_SCAN_BEGIN_SRC_AI_CONVERT = 19,
1412     NI_CDIO_SCAN_BEGIN_SRC_PXI_STAR_TRIGGER = 20,
1413     NI_CDIO_SCAN_BEGIN_SRC_G0_OUT = 28,
1414     NI_CDIO_SCAN_BEGIN_SRC_G1_OUT = 29,
1415     NI_CDIO_SCAN_BEGIN_SRC_ANALOG_TRIGGER = 30,
1416     NI_CDIO_SCAN_BEGIN_SRC_AO_UPDATE = 31,
1417     NI_CDIO_SCAN_BEGIN_SRC_FREQ_OUT = 32,
1418     NI_CDIO_SCAN_BEGIN_SRC_DIO_CHANGE_DETECT_IRQ = 33
1419 };
1420 
1421 #define NI_CDIO_SCAN_BEGIN_SRC_PFI(x)   NI_USUAL_PFI_SELECT(x)
1422 #define NI_CDIO_SCAN_BEGIN_SRC_RTSI(x)  NI_USUAL_RTSI_SELECT(x)
1423 
1424 /*
1425  * scan_begin_src for scan_begin_arg==TRIG_EXT with analog output command on NI
1426  * boards.  These scan begin sources can also be bitwise-or'd with CR_INVERT to
1427  * change polarity.
1428  */
1429 #define NI_AO_SCAN_BEGIN_SRC_PFI(x) NI_USUAL_PFI_SELECT(x)
1430 #define NI_AO_SCAN_BEGIN_SRC_RTSI(x)    NI_USUAL_RTSI_SELECT(x)
1431 
1432 /*
1433  * Bits for setting a clock source with
1434  * INSN_CONFIG_SET_CLOCK_SRC when using NI frequency output subdevice.
1435  */
1436 enum ni_freq_out_clock_source_bits {
1437     NI_FREQ_OUT_TIMEBASE_1_DIV_2_CLOCK_SRC, /* 10 MHz */
1438     NI_FREQ_OUT_TIMEBASE_2_CLOCK_SRC    /* 100 KHz */
1439 };
1440 
1441 /*
1442  * Values for setting a clock source with INSN_CONFIG_SET_CLOCK_SRC for
1443  * 8254 counter subdevices on Amplicon DIO boards (amplc_dio200 driver).
1444  */
1445 enum amplc_dio_clock_source {
1446     /*
1447      * Per channel external clock
1448      * input/output pin (pin is only an
1449      * input when clock source set to this value,
1450      * otherwise it is an output)
1451      */
1452     AMPLC_DIO_CLK_CLKN,
1453     AMPLC_DIO_CLK_10MHZ,    /* 10 MHz internal clock */
1454     AMPLC_DIO_CLK_1MHZ, /* 1 MHz internal clock */
1455     AMPLC_DIO_CLK_100KHZ,   /* 100 kHz internal clock */
1456     AMPLC_DIO_CLK_10KHZ,    /* 10 kHz internal clock */
1457     AMPLC_DIO_CLK_1KHZ, /* 1 kHz internal clock */
1458     /*
1459      * Output of preceding counter channel
1460      * (for channel 0, preceding counter
1461      * channel is channel 2 on preceding
1462      * counter subdevice, for first counter
1463      * subdevice, preceding counter
1464      * subdevice is the last counter
1465      * subdevice)
1466      */
1467     AMPLC_DIO_CLK_OUTNM1,
1468     AMPLC_DIO_CLK_EXT,  /* per chip external input pin */
1469     /* the following are "enhanced" clock sources for PCIe models */
1470     AMPLC_DIO_CLK_VCC,  /* clock input HIGH */
1471     AMPLC_DIO_CLK_GND,  /* clock input LOW */
1472     AMPLC_DIO_CLK_PAT_PRESENT, /* "pattern present" signal */
1473     AMPLC_DIO_CLK_20MHZ /* 20 MHz internal clock */
1474 };
1475 
1476 /*
1477  * Values for setting a clock source with INSN_CONFIG_SET_CLOCK_SRC for
1478  * timer subdevice on some Amplicon DIO PCIe boards (amplc_dio200 driver).
1479  */
1480 enum amplc_dio_ts_clock_src {
1481     AMPLC_DIO_TS_CLK_1GHZ,  /* 1 ns period with 20 ns granularity */
1482     AMPLC_DIO_TS_CLK_1MHZ,  /* 1 us period */
1483     AMPLC_DIO_TS_CLK_1KHZ   /* 1 ms period */
1484 };
1485 
1486 /*
1487  * Values for setting a gate source with INSN_CONFIG_SET_GATE_SRC for
1488  * 8254 counter subdevices on Amplicon DIO boards (amplc_dio200 driver).
1489  */
1490 enum amplc_dio_gate_source {
1491     AMPLC_DIO_GAT_VCC,  /* internal high logic level */
1492     AMPLC_DIO_GAT_GND,  /* internal low logic level */
1493     AMPLC_DIO_GAT_GATN, /* per channel external gate input */
1494     /*
1495      * negated output of counter channel minus 2
1496      * (for channels 0 or 1, channel minus 2 is channel 1 or 2 on
1497      * the preceding counter subdevice, for the first counter subdevice
1498      * the preceding counter subdevice is the last counter subdevice)
1499      */
1500     AMPLC_DIO_GAT_NOUTNM2,
1501     AMPLC_DIO_GAT_RESERVED4,
1502     AMPLC_DIO_GAT_RESERVED5,
1503     AMPLC_DIO_GAT_RESERVED6,
1504     AMPLC_DIO_GAT_RESERVED7,
1505     /* the following are "enhanced" gate sources for PCIe models */
1506     AMPLC_DIO_GAT_NGATN = 6, /* negated per channel gate input */
1507     /* non-negated output of counter channel minus 2 */
1508     AMPLC_DIO_GAT_OUTNM2,
1509     AMPLC_DIO_GAT_PAT_PRESENT, /* "pattern present" signal */
1510     AMPLC_DIO_GAT_PAT_OCCURRED, /* "pattern occurred" latched */
1511     AMPLC_DIO_GAT_PAT_GONE, /* "pattern gone away" latched */
1512     AMPLC_DIO_GAT_NPAT_PRESENT, /* negated "pattern present" */
1513     AMPLC_DIO_GAT_NPAT_OCCURRED, /* negated "pattern occurred" */
1514     AMPLC_DIO_GAT_NPAT_GONE /* negated "pattern gone away" */
1515 };
1516 
1517 /*
1518  * Values for setting a clock source with INSN_CONFIG_SET_CLOCK_SRC for
1519  * the counter subdevice on the Kolter Electronic PCI-Counter board
1520  * (ke_counter driver).
1521  */
1522 enum ke_counter_clock_source {
1523     KE_CLK_20MHZ,   /* internal 20MHz (default) */
1524     KE_CLK_4MHZ,    /* internal 4MHz (option) */
1525     KE_CLK_EXT  /* external clock on pin 21 of D-Sub */
1526 };
1527 
1528 #endif /* _COMEDI_H */