sync with comedi
[comedilib.git] / include / comedi.h
1 /*
2     include/comedi.h (installed as /usr/include/comedi.h)
3     header file for comedi
4
5     COMEDI - Linux Control and Measurement Device Interface
6     Copyright (C) 1998-2001 David A. Schleef <ds@schleef.org>
7
8     This program is free software; you can redistribute it and/or modify
9     it under the terms of the GNU General Public License as published by
10     the Free Software Foundation; either version 2 of the License, or
11     (at your option) any later version.
12
13     This program is distributed in the hope that it will be useful,
14     but WITHOUT ANY WARRANTY; without even the implied warranty of
15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16     GNU General Public License for more details.
17
18     You should have received a copy of the GNU General Public License
19     along with this program; if not, write to the Free Software
20     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21
22 */
23
24
25 #ifndef _COMEDI_H
26 #define _COMEDI_H
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31
32 /* comedi's major device number */
33 #define COMEDI_MAJOR 98
34
35 /*
36    maximum number of minor devices.  This can be increased, although
37    kernel structures are currently statically allocated, thus you
38    don't want this to be much more than you actually use.
39  */
40 #define COMEDI_NDEVICES 16
41
42 /* number of config options in the config structure */
43 #define COMEDI_NDEVCONFOPTS 32
44 #define COMEDI_DEVCONF_AUX_DATA         30
45 #define COMEDI_DEVCONF_AUX_DATA_LENGTH  31
46
47 /* max length of device and driver names */
48 #define COMEDI_NAMELEN 20
49
50
51 typedef unsigned int lsampl_t;
52 typedef unsigned short sampl_t;
53
54 /* packs and unpacks a channel/range number */
55
56 #define CR_PACK(chan,rng,aref)          ( (((aref)&0x3)<<24) | (((rng)&0xff)<<16) | (chan) )
57 #define CR_PACK_FLAGS(chan, range, aref, flags) (CR_PACK(chan, range, aref) | ((flags) & CR_FLAGS_MASK))
58
59 #define CR_CHAN(a)      ((a)&0xffff)
60 #define CR_RANGE(a)     (((a)>>16)&0xff)
61 #define CR_AREF(a)      (((a)>>24)&0x03)
62
63 #define CR_FLAGS_MASK   0xfc000000
64 #define CR_ALT_FILTER   (1<<26)
65 #define CR_DITHER               CR_ALT_FILTER
66 #define CR_DEGLITCH             CR_ALT_FILTER
67 #define CR_ALT_SOURCE   (1<<27)
68 #define CR_EDGE (1<<30)
69 #define CR_INVERT       (1<<31)
70
71 #define AREF_GROUND     0x00            /* analog ref = analog ground */
72 #define AREF_COMMON     0x01            /* analog ref = analog common */
73 #define AREF_DIFF       0x02            /* analog ref = differential */
74 #define AREF_OTHER      0x03            /* analog ref = other (undefined) */
75
76 /* counters -- these are arbitrary values */
77 #define GPCT_RESET              0x0001
78 #define GPCT_SET_SOURCE         0x0002
79 #define GPCT_SET_GATE           0x0004
80 #define GPCT_SET_DIRECTION      0x0008
81 #define GPCT_SET_OPERATION      0x0010
82 #define GPCT_ARM                0x0020
83 #define GPCT_DISARM             0x0040
84 #define GPCT_GET_INT_CLK_FRQ    0x0080
85
86 #define GPCT_INT_CLOCK          0x0001
87 #define GPCT_EXT_PIN            0x0002
88 #define GPCT_NO_GATE            0x0004
89 #define GPCT_UP                 0x0008
90 #define GPCT_DOWN               0x0010
91 #define GPCT_HWUD               0x0020
92 #define GPCT_SIMPLE_EVENT       0x0040
93 #define GPCT_SINGLE_PERIOD      0x0080
94 #define GPCT_SINGLE_PW          0x0100
95 #define GPCT_CONT_PULSE_OUT     0x0200
96 #define GPCT_SINGLE_PULSE_OUT   0x0400
97
98 /* instructions */
99
100 #define INSN_MASK_WRITE         0x8000000
101 #define INSN_MASK_READ          0x4000000
102 #define INSN_MASK_SPECIAL       0x2000000
103
104 #define INSN_READ               ( 0 | INSN_MASK_READ)
105 #define INSN_WRITE              ( 1 | INSN_MASK_WRITE)
106 #define INSN_BITS               ( 2 | INSN_MASK_READ|INSN_MASK_WRITE)
107 #define INSN_CONFIG             ( 3 | INSN_MASK_READ|INSN_MASK_WRITE)
108 #define INSN_GTOD               ( 4 | INSN_MASK_READ|INSN_MASK_SPECIAL)
109 #define INSN_WAIT               ( 5 | INSN_MASK_WRITE|INSN_MASK_SPECIAL)
110 #define INSN_INTTRIG            ( 6 | INSN_MASK_WRITE|INSN_MASK_SPECIAL)
111
112 /* trigger flags */
113 /* These flags are used in comedi_trig structures */
114
115 #define TRIG_BOGUS      0x0001          /* do the motions */
116 #define TRIG_DITHER     0x0002          /* enable dithering */
117 #define TRIG_DEGLITCH   0x0004          /* enable deglitching */
118 //#define TRIG_RT       0x0008          /* perform op in real time */
119 #define TRIG_CONFIG     0x0010          /* perform configuration, not triggering */
120 #define TRIG_WAKE_EOS   0x0020          /* wake up on end-of-scan events */
121 //#define TRIG_WRITE    0x0040          /* write to bidirectional devices */
122
123 /* command flags */
124 /* These flags are used in comedi_cmd structures */
125
126 #define CMDF_PRIORITY           0x00000008 /* try to use a real-time interrupt while performing command */
127
128 #define TRIG_RT         CMDF_PRIORITY /* compatibility definition */
129
130 #define CMDF_WRITE              0x00000040
131 #define TRIG_WRITE      CMDF_WRITE /* compatibility definition */
132
133 #define CMDF_RAWDATA            0x00000080
134
135 #define COMEDI_EV_START         0x00040000
136 #define COMEDI_EV_SCAN_BEGIN    0x00080000
137 #define COMEDI_EV_CONVERT       0x00100000
138 #define COMEDI_EV_SCAN_END      0x00200000
139 #define COMEDI_EV_STOP          0x00400000
140
141 #define TRIG_ROUND_MASK         0x00030000
142 #define TRIG_ROUND_NEAREST      0x00000000
143 #define TRIG_ROUND_DOWN         0x00010000
144 #define TRIG_ROUND_UP           0x00020000
145 #define TRIG_ROUND_UP_NEXT      0x00030000
146
147 /* trigger sources */
148
149 #define TRIG_ANY        0xffffffff
150 #define TRIG_INVALID    0x00000000
151
152 #define TRIG_NONE       0x00000001      /* never trigger */
153 #define TRIG_NOW        0x00000002      /* trigger now + N ns */
154 #define TRIG_FOLLOW     0x00000004      /* trigger on next lower level trig */
155 #define TRIG_TIME       0x00000008      /* trigger at time N ns */
156 #define TRIG_TIMER      0x00000010      /* trigger at rate N ns */
157 #define TRIG_COUNT      0x00000020      /* trigger when count reaches N */
158 #define TRIG_EXT        0x00000040      /* trigger on external signal N */
159 #define TRIG_INT        0x00000080      /* trigger on comedi-internal signal N */
160 #define TRIG_OTHER      0x00000100      /* driver defined */
161
162 /* subdevice flags */
163
164 #define SDF_BUSY        0x0001          /* device is busy */
165 #define SDF_BUSY_OWNER  0x0002          /* device is busy with your job */
166 #define SDF_LOCKED      0x0004          /* subdevice is locked */
167 #define SDF_LOCK_OWNER  0x0008          /* you own lock */
168 #define SDF_MAXDATA     0x0010          /* maxdata depends on channel */
169 #define SDF_FLAGS       0x0020          /* flags depend on channel */
170 #define SDF_RANGETYPE   0x0040          /* range type depends on channel */
171 #define SDF_MODE0       0x0080          /* can do mode 0 */
172 #define SDF_MODE1       0x0100          /* can do mode 1 */
173 #define SDF_MODE2       0x0200          /* can do mode 2 */
174 #define SDF_MODE3       0x0400          /* can do mode 3 */
175 #define SDF_MODE4       0x0800          /* can do mode 4 */
176 #define SDF_CMD         0x1000          /* can do commands */
177
178 #define SDF_READABLE    0x00010000      /* subdevice can be read (e.g. analog input) */
179 #define SDF_WRITABLE    0x00020000      /* subdevice can be written (e.g. analog output) */
180 #define SDF_WRITEABLE   SDF_WRITABLE    /* spelling error in API */
181 #define SDF_INTERNAL    0x00040000      /* subdevice does not have externally visible lines */
182 #define SDF_RT          0x00080000      /* DEPRECATED: subdevice is RT capable */
183 #define SDF_GROUND      0x00100000      /* can do aref=ground */
184 #define SDF_COMMON      0x00200000      /* can do aref=common */
185 #define SDF_DIFF        0x00400000      /* can do aref=diff */
186 #define SDF_OTHER       0x00800000      /* can do aref=other */
187 #define SDF_DITHER      0x01000000      /* can do dithering */
188 #define SDF_DEGLITCH    0x02000000      /* can do deglitching */
189 #define SDF_MMAP        0x04000000      /* can do mmap() */
190 #define SDF_RUNNING     0x08000000      /* subdevice is acquiring data */
191 #define SDF_LSAMPL      0x10000000      /* subdevice uses 32-bit samples */
192 #define SDF_PACKED      0x20000000      /* subdevice can do packed DIO */
193
194 /* subdevice types */
195
196 #define COMEDI_SUBD_UNUSED              0       /* unused */
197 #define COMEDI_SUBD_AI                  1       /* analog input */
198 #define COMEDI_SUBD_AO                  2       /* analog output */
199 #define COMEDI_SUBD_DI                  3       /* digital input */
200 #define COMEDI_SUBD_DO                  4       /* digital output */
201 #define COMEDI_SUBD_DIO                 5       /* digital input/output */
202 #define COMEDI_SUBD_COUNTER             6       /* counter */
203 #define COMEDI_SUBD_TIMER               7       /* timer */
204 #define COMEDI_SUBD_MEMORY              8       /* memory, EEPROM, DPRAM */
205 #define COMEDI_SUBD_CALIB               9       /* calibration DACs */
206 #define COMEDI_SUBD_PROC                10      /* processor, DSP */
207 #define COMEDI_SUBD_SERIAL              11      /* serial IO */
208
209 /* configuration instructions */
210
211 enum configuration_ids
212 {
213         INSN_CONFIG_DIO_INPUT = 0,
214         INSN_CONFIG_DIO_OUTPUT = 1,
215         INSN_CONFIG_DIO_OPENDRAIN = 2,
216         COMEDI_INPUT = INSN_CONFIG_DIO_INPUT,
217         COMEDI_OUTPUT = INSN_CONFIG_DIO_OUTPUT,
218         COMEDI_OPENDRAIN = INSN_CONFIG_DIO_OPENDRAIN,
219         INSN_CONFIG_ANALOG_TRIG = 16,
220 //      INSN_CONFIG_WAVEFORM = 17,
221 //      INSN_CONFIG_TRIG = 18,
222 //      INSN_CONFIG_COUNTER = 19,
223         INSN_CONFIG_ALT_SOURCE = 20,
224         INSN_CONFIG_DIGITAL_TRIG = 21,
225         INSN_CONFIG_BLOCK_SIZE = 22,
226         INSN_CONFIG_TIMER_1 = 23,
227         INSN_CONFIG_FILTER = 24,
228         INSN_CONFIG_CHANGE_NOTIFY = 25,
229
230         /*ALPHA*/
231         INSN_CONFIG_SERIAL_CLOCK = 26,
232         INSN_CONFIG_BIDIRECTIONAL_DATA = 27,
233         INSN_CONFIG_GPCT_SINGLE_PULSE_GENERATOR = 1001, // Use CTR as single pulsegenerator
234         INSN_CONFIG_GPCT_PULSE_TRAIN_GENERATOR = 1002, // Use CTR as pulsetraingenerator
235         INSN_CONFIG_GPCT_QUADRATURE_ENCODER = 1003, // Use the counter as encoder
236         INSN_CONFIG_8254_SET_MODE = 4097,
237         INSN_CONFIG_8254_READ_STATUS = 4098
238 };
239
240 /* ioctls */
241
242 #define CIO 'd'
243 #define COMEDI_DEVCONFIG _IOW(CIO,0,comedi_devconfig)
244 #define COMEDI_DEVINFO _IOR(CIO,1,comedi_devinfo)
245 #define COMEDI_SUBDINFO _IOR(CIO,2,comedi_subdinfo)
246 #define COMEDI_CHANINFO _IOR(CIO,3,comedi_chaninfo)
247 #define COMEDI_TRIG _IOWR(CIO,4,comedi_trig)
248 #define COMEDI_LOCK _IO(CIO,5)
249 #define COMEDI_UNLOCK _IO(CIO,6)
250 #define COMEDI_CANCEL _IO(CIO,7)
251 #define COMEDI_RANGEINFO _IOR(CIO,8,comedi_rangeinfo)
252 #define COMEDI_CMD _IOR(CIO,9,comedi_cmd)
253 #define COMEDI_CMDTEST _IOR(CIO,10,comedi_cmd)
254 #define COMEDI_INSNLIST _IOR(CIO,11,comedi_insnlist)
255 #define COMEDI_INSN _IOR(CIO,12,comedi_insn)
256 #define COMEDI_BUFCONFIG _IOR(CIO,13,comedi_bufconfig)
257 #define COMEDI_BUFINFO _IOWR(CIO,14,comedi_bufinfo)
258 #define COMEDI_POLL _IO(CIO,15)
259
260
261 /* structures */
262
263 typedef struct comedi_trig_struct comedi_trig;
264 typedef struct comedi_cmd_struct comedi_cmd;
265 typedef struct comedi_insn_struct comedi_insn;
266 typedef struct comedi_insnlist_struct comedi_insnlist;
267 typedef struct comedi_chaninfo_struct comedi_chaninfo;
268 typedef struct comedi_subdinfo_struct comedi_subdinfo;
269 typedef struct comedi_devinfo_struct comedi_devinfo;
270 typedef struct comedi_devconfig_struct comedi_devconfig;
271 typedef struct comedi_rangeinfo_struct comedi_rangeinfo;
272 typedef struct comedi_krange_struct comedi_krange;
273 typedef struct comedi_bufconfig_struct comedi_bufconfig;
274 typedef struct comedi_bufinfo_struct comedi_bufinfo;
275
276 struct comedi_trig_struct{
277         unsigned int subdev;            /* subdevice */
278         unsigned int mode;              /* mode */
279         unsigned int flags;
280         unsigned int n_chan;            /* number of channels */
281         unsigned int *chanlist;         /* channel/range list */
282         sampl_t *data;                  /* data list, size depends on subd flags */
283         unsigned int n;                 /* number of scans */
284         unsigned int trigsrc;
285         unsigned int trigvar;
286         unsigned int trigvar1;
287         unsigned int data_len;
288         unsigned int unused[3];
289 };
290
291 struct comedi_insn_struct{
292         unsigned int insn;
293         unsigned int n;
294         lsampl_t *data;
295         unsigned int subdev;
296         unsigned int chanspec;
297         unsigned int unused[3];
298 };
299
300 struct comedi_insnlist_struct{
301         unsigned int n_insns;
302         comedi_insn *insns;
303 };
304
305 struct comedi_cmd_struct{
306         unsigned int subdev;
307         unsigned int flags;
308
309         unsigned int start_src;
310         unsigned int start_arg;
311
312         unsigned int scan_begin_src;
313         unsigned int scan_begin_arg;
314
315         unsigned int convert_src;
316         unsigned int convert_arg;
317
318         unsigned int scan_end_src;
319         unsigned int scan_end_arg;
320
321         unsigned int stop_src;
322         unsigned int stop_arg;
323
324         unsigned int *chanlist;         /* channel/range list */
325         unsigned int chanlist_len;
326
327         sampl_t *data;                  /* data list, size depends on subd flags */
328         unsigned int data_len;
329 };
330
331 struct comedi_chaninfo_struct{
332         unsigned int subdev;
333         lsampl_t *maxdata_list;
334         unsigned int *flaglist;
335         unsigned int *rangelist;
336         unsigned int unused[4];
337 };
338
339 struct comedi_rangeinfo_struct{
340         unsigned int range_type;
341         void *range_ptr;
342 };
343
344 struct comedi_krange_struct{
345         int min;        /* fixed point, multiply by 1e-6 */
346         int max;        /* fixed point, multiply by 1e-6 */
347         unsigned int flags;
348 };
349
350 struct comedi_subdinfo_struct{
351         unsigned int type;
352         unsigned int n_chan;
353         unsigned int subd_flags;
354         unsigned int timer_type;
355         unsigned int len_chanlist;
356         lsampl_t        maxdata;
357         unsigned int    flags;          /* channel flags */
358         unsigned int    range_type;     /* lookup in kernel */
359         unsigned int    settling_time_0;
360         unsigned int unused[9];
361 };
362
363 struct comedi_devinfo_struct{
364         unsigned int version_code;
365         unsigned int n_subdevs;
366         char driver_name[COMEDI_NAMELEN];
367         char board_name[COMEDI_NAMELEN];
368         int read_subdevice;
369         int write_subdevice;
370         int unused[30];
371 };
372
373 struct comedi_devconfig_struct{
374         char board_name[COMEDI_NAMELEN];
375         int options[COMEDI_NDEVCONFOPTS];
376 };
377
378 struct comedi_bufconfig_struct{
379         unsigned int subdevice;
380         unsigned int flags;
381
382         unsigned int maximum_size;
383         unsigned int size;
384
385         unsigned int unused[4];
386 };
387
388 struct comedi_bufinfo_struct{
389         unsigned int subdevice;
390         unsigned int bytes_read;
391
392         unsigned int buf_int_ptr;
393         unsigned int buf_user_ptr;
394         unsigned int buf_int_count;
395         unsigned int buf_user_count;
396
397         unsigned int bytes_written;
398
399         unsigned int unused[4];
400 };
401
402 /* range stuff */
403
404 #define __RANGE(a,b)    ((((a)&0xffff)<<16)|((b)&0xffff))
405
406 #define RANGE_OFFSET(a)         (((a)>>16)&0xffff)
407 #define RANGE_LENGTH(b)         ((b)&0xffff)
408
409 #define RF_UNIT(flags)          ((flags)&0xff)
410 #define RF_EXTERNAL             (1<<8)
411
412 #define UNIT_volt               0
413 #define UNIT_mA                 1
414 #define UNIT_none               2
415
416 #define COMEDI_MIN_SPEED        ((unsigned int)0xffffffff)
417
418 /* callback stuff */
419 /* only relevant to kernel modules. */
420
421 #define COMEDI_CB_EOS           1       /* end of scan */
422 #define COMEDI_CB_EOA           2       /* end of acquisition */
423 #define COMEDI_CB_BLOCK         4       /* DEPRECATED: convenient block size */
424 #define COMEDI_CB_EOBUF         8       /* DEPRECATED: end of buffer */
425 #define COMEDI_CB_ERROR         16      /* card error during acquisition */
426 #define COMEDI_CB_OVERFLOW      32      /* buffer overflow/underflow */
427
428 /**********************************************************/
429 /* everything after this line is ALPHA */
430 /**********************************************************/
431
432 /*
433         Added by Klaas Gadeyne after implementation of driver for comedi NI
434         660x counter card.
435         Please see
436         <http://people.mech.kuleuven.ac.be/~kgadeyne/linux/> for more
437         information about their use
438 */
439
440 #define GPCT_X1                 0x01 // X1 encoding
441 #define GPCT_X2                 0x02 // X2 encoding
442 #define GPCT_X4                 0x04 // X3 encoding
443 // When to take into account the indexpulse:
444 #define GPCT_IndexPhaseHighHigh 0
445 #define GPCT_IndexPhaseLowHigh 1
446 #define GPCT_IndexPhaseLowLow 2
447 #define GPCT_IndexPhaseHighLow 3
448 // Reset when index pulse arrives?
449 #define GPCT_RESET_COUNTER_ON_INDEX 1
450
451 /*
452   8254 specific configuration.
453
454   It supports two config commands:
455
456   0 ID: INSN_CONFIG_8254_SET_MODE
457   1 8254 Mode
458     I8254_MODE0, I8254_MODE1, ..., I8254_MODE5
459     OR'ed with:
460     I8254_BCD, I8254_BINARY
461
462   0 ID: INSN_CONFIG_8254_READ_STATUS
463   1 <-- Status byte returned here.
464     B7=Output
465     B6=NULL Count
466     B5-B0 Current mode.
467
468 */
469
470 enum i8254_mode
471 {
472         I8254_MODE0 = (0<<1),  /* Interrupt on terminal count */
473         I8254_MODE1 = (1<<1),  /* Hardware retriggerable one-shot */
474         I8254_MODE2 = (2<<1),  /* Rate generator */
475         I8254_MODE3 = (3<<1),  /* Square wave mode */
476         I8254_MODE4 = (4<<1),  /* Software triggered strobe */
477         I8254_MODE5 = (5<<1),  /* Hardware triggered strobe (retriggerable) */
478         I8254_BCD = 1, /* use binary-coded decimal instead of binary (pretty useless) */
479         I8254_BINARY = 0
480 };
481 #ifdef __cplusplus
482 }
483 #endif
484
485 #endif /* _COMEDI_H */
486