Added comedi_map, comedi_unmap, comedi_poll
[comedi.git] / include / linux / 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-2000 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 4
41
42 /* number of config options in the config structure */
43 #define COMEDI_NDEVCONFOPTS 32
44
45 /* max length of device and driver names */
46 #define COMEDI_NAMELEN 20
47
48
49 typedef unsigned int lsampl_t;
50 typedef unsigned short sampl_t;
51
52 /* packs and unpacks a channel/range number */
53
54 #define CR_PACK(chan,rng,aref)          ( (((aref)&0x3)<<24) | (((rng)&0xff)<<16) | ((chan)&0xffff) )
55
56 #define CR_CHAN(a)      ((a)&0xffff)
57 #define CR_RANGE(a)     (((a)>>16)&0xff)
58 #define CR_AREF(a)      (((a)>>24)&0x03)
59
60 #define AREF_GROUND     0x00            /* analog ref = analog ground */
61 #define AREF_COMMON     0x01            /* analog ref = analog common */
62 #define AREF_DIFF       0x02            /* analog ref = differential */
63 #define AREF_OTHER      0x03            /* analog ref = other (undefined) */
64
65 /* counters -- these are arbitrary values */
66 #define GPCT_RESET              0x0001
67 #define GPCT_SET_SOURCE         0x0002
68 #define GPCT_SET_GATE           0x0004
69 #define GPCT_SET_DIRECTION      0x0008
70 #define GPCT_SET_OPERATION      0x0010
71 #define GPCT_ARM                0x0020
72 #define GPCT_DISARM             0x0040
73 #define GPCT_GET_INT_CLK_FRQ    0x0080
74
75 #define GPCT_INT_CLOCK          0x0001
76 #define GPCT_EXT_PIN            0x0002
77 #define GPCT_NO_GATE            0x0004
78 #define GPCT_UP                 0x0008
79 #define GPCT_DOWN               0x0010
80 #define GPCT_HWUD               0x0020
81 #define GPCT_SIMPLE_EVENT       0x0040
82 #define GPCT_SINGLE_PERIOD      0x0080
83 #define GPCT_SINGLE_PW          0x0100
84 #define GPCT_CONT_PULSE_OUT     0x0200
85 #define GPCT_SINGLE_PULSE_OUT   0x0400
86
87
88 /* instructions */
89
90 #define INSN_MASK_WRITE         0x8000000
91 #define INSN_MASK_READ          0x4000000
92 #define INSN_MASK_SPECIAL       0x2000000
93
94 #define INSN_READ               ( 0 | INSN_MASK_READ)
95 #define INSN_WRITE              ( 1 | INSN_MASK_WRITE)
96 #define INSN_BITS               ( 2 | INSN_MASK_READ|INSN_MASK_WRITE)
97 #define INSN_CONFIG             ( 3 | INSN_MASK_READ|INSN_MASK_WRITE)
98 #define INSN_GTOD               ( 4 | INSN_MASK_READ|INSN_MASK_SPECIAL)
99 #define INSN_WAIT               ( 5 | INSN_MASK_WRITE|INSN_MASK_SPECIAL)
100
101 /* trigger flags */
102
103 #define TRIG_BOGUS      0x0001          /* do the motions */
104 #define TRIG_DITHER     0x0002          /* enable dithering */
105 #define TRIG_DEGLITCH   0x0004          /* enable deglitching */
106 #define TRIG_RT         0x0008          /* perform op in real time */
107 #define TRIG_CONFIG     0x0010          /* perform configuration, not triggering */
108 #define TRIG_WAKE_EOS   0x0020          /* wake up on end-of-scan events */
109 #define TRIG_WRITE      0x0040          /* write to bidirectional devices */
110
111 #define TRIG_ROUND_MASK         0x00030000
112 #define TRIG_ROUND_NEAREST      0x00000000
113 #define TRIG_ROUND_DOWN         0x00010000
114 #define TRIG_ROUND_UP           0x00020000
115 #define TRIG_ROUND_UP_NEXT      0x00030000
116
117 /* trigger sources */
118
119 #define TRIG_ANY        0xffffffff
120 #define TRIG_NONE       0x00000001      /* never trigger */
121 #define TRIG_NOW        0x00000002      /* trigger now + N ns */
122 #define TRIG_FOLLOW     0x00000004      /* trigger on next lower level trig */
123 #define TRIG_TIME       0x00000008      /* trigger at time N ns */
124 #define TRIG_TIMER      0x00000010      /* trigger at rate N ns */
125 #define TRIG_COUNT      0x00000020      /* trigger when count reaches N */
126 #define TRIG_EXT        0x00000040      /* trigger on external signal N */
127 #define TRIG_INT        0x00000080      /* trigger on comedi-internal signal N */
128
129 #define TRIG_INVAL      0x00000100      /* choice was invalid */
130
131 /* subdevice flags */
132
133 #define SDF_BUSY        0x0001          /* device is busy */
134 #define SDF_BUSY_OWNER  0x0002          /* device is busy with your job */
135 #define SDF_LOCKED      0x0004          /* subdevice is locked */
136 #define SDF_LOCK_OWNER  0x0008          /* you own lock */
137 #define SDF_MAXDATA     0x0010          /* maxdata depends on channel */
138 #define SDF_FLAGS       0x0020          /* flags depend on channel */
139 #define SDF_RANGETYPE   0x0040          /* range type depends on channel */
140 #define SDF_MODE0       0x0080          /* can do mode 0 */
141 #define SDF_MODE1       0x0100          /* can do mode 1 */
142 #define SDF_MODE2       0x0200          /* can do mode 2 */
143 #define SDF_MODE3       0x0400          /* can do mode 3 */
144 #define SDF_MODE4       0x0800          /* can do mode 4 */
145 #define SDF_CMD         0x1000          /* can do commands */
146
147 #define SDF_READABLE    0x00010000      /* subdevice can be read (e.g. analog input) */
148 #define SDF_WRITEABLE   0x00020000      /* subdevice can be written (e.g. analog output) */
149 #define SDF_INTERNAL    0x00040000      /* subdevice does not have externally visible lines */
150 #define SDF_RT          0x00080000      /* subdevice is RT capable */
151 #define SDF_GROUND      0x00100000      /* can do aref=ground */
152 #define SDF_COMMON      0x00200000      /* can do aref=common */
153 #define SDF_DIFF        0x00400000      /* can do aref=diff */
154 #define SDF_OTHER       0x00800000      /* can do aref=other */
155 #define SDF_DITHER      0x01000000      /* can do dithering */
156 #define SDF_DEGLITCH    0x02000000      /* can do deglitching */
157 #define SDF_MMAP        0x04000000      /* can do mmap() */
158 #define SDF_RUNNING     0x08000000      /* subdevice is acquiring data */
159 #define SDF_LSAMPL      0x10000000      /* subdevice uses 32-bit samples */
160 #define SDF_PACKED      0x20000000      /* subdevice can do packed DIO */
161
162 /* subdevice types */
163
164 #define COMEDI_SUBD_UNUSED              0       /* unused */
165 #define COMEDI_SUBD_AI                  1       /* analog input */
166 #define COMEDI_SUBD_AO                  2       /* analog output */
167 #define COMEDI_SUBD_DI                  3       /* digital input */
168 #define COMEDI_SUBD_DO                  4       /* digital output */
169 #define COMEDI_SUBD_DIO                 5       /* digital input/output */
170 #define COMEDI_SUBD_COUNTER             6       /* counter */
171 #define COMEDI_SUBD_TIMER               7       /* timer */
172 #define COMEDI_SUBD_MEMORY              8       /* memory, EEPROM, DPRAM */
173 #define COMEDI_SUBD_CALIB               9       /* calibration DACs */
174 #define COMEDI_SUBD_PROC                10      /* processor, DSP */
175
176
177 #define COMEDI_INPUT                    0
178 #define COMEDI_OUTPUT                   1
179
180 /* ioctls */
181
182 #define CIO 'd'
183 #define COMEDI_DEVCONFIG _IOW(CIO,0,comedi_devconfig)
184 #define COMEDI_DEVINFO _IOR(CIO,1,comedi_devinfo)
185 #define COMEDI_SUBDINFO _IOR(CIO,2,comedi_subdinfo)
186 #define COMEDI_CHANINFO _IOR(CIO,3,comedi_chaninfo)
187 #define COMEDI_TRIG _IOWR(CIO,4,comedi_trig)
188 #define COMEDI_LOCK _IO(CIO,5)
189 #define COMEDI_UNLOCK _IO(CIO,6)
190 #define COMEDI_CANCEL _IO(CIO,7)
191 #define COMEDI_RANGEINFO _IOR(CIO,8,comedi_rangeinfo)
192 #define COMEDI_CMD _IOR(CIO,9,comedi_cmd)
193 #define COMEDI_CMDTEST _IOR(CIO,10,comedi_cmd)
194 #define COMEDI_INSNLIST _IOR(CIO,11,comedi_insnlist)
195 #define COMEDI_INSN _IOR(CIO,12,comedi_insn)
196 #define COMEDI_BUFCONFIG _IOR(CIO,13,comedi_bufconfig)
197 #define COMEDI_BUFINFO _IOWR(CIO,14,comedi_bufinfo)
198 #define COMEDI_POLL _IO(CIO,15)
199
200
201 /* structures */
202
203 typedef struct comedi_trig_struct comedi_trig;
204 typedef struct comedi_cmd_struct comedi_cmd;
205 typedef struct comedi_insn_struct comedi_insn;
206 typedef struct comedi_insnlist_struct comedi_insnlist;
207 typedef struct comedi_chaninfo_struct comedi_chaninfo;
208 typedef struct comedi_subdinfo_struct comedi_subdinfo;
209 typedef struct comedi_devinfo_struct comedi_devinfo;
210 typedef struct comedi_devconfig_struct comedi_devconfig;
211 typedef struct comedi_rangeinfo_struct comedi_rangeinfo;
212 typedef struct comedi_krange_struct comedi_krange;
213 typedef struct comedi_bufconfig_struct comedi_bufconfig;
214 typedef struct comedi_bufinfo_struct comedi_bufinfo;
215
216 struct comedi_trig_struct{
217         unsigned int subdev;            /* subdevice */
218         unsigned int mode;              /* mode */
219         unsigned int flags;
220         unsigned int n_chan;            /* number of channels */
221         unsigned int *chanlist;         /* channel/range list */
222         sampl_t *data;                  /* data list, size depends on subd flags */
223         unsigned int n;                 /* number of scans */
224         unsigned int trigsrc;
225         unsigned int trigvar;
226         unsigned int trigvar1;
227         unsigned int data_len;
228         unsigned int unused[3];
229 };
230
231 struct comedi_insn_struct{
232         unsigned int insn;
233         unsigned int n;
234         lsampl_t *data;
235         unsigned int subdev;
236         unsigned int chanspec;
237         unsigned int unused[3];
238 };
239
240 struct comedi_insnlist_struct{
241         unsigned int n_insns;
242         comedi_insn *insns;
243 };
244
245 struct comedi_cmd_struct{
246         unsigned int subdev;
247         unsigned int flags;
248
249         unsigned int start_src;
250         unsigned int start_arg;
251
252         unsigned int scan_begin_src;
253         unsigned int scan_begin_arg;
254
255         unsigned int convert_src;
256         unsigned int convert_arg;
257
258         unsigned int scan_end_src;
259         unsigned int scan_end_arg;
260
261         unsigned int stop_src;
262         unsigned int stop_arg;
263
264         unsigned int *chanlist;         /* channel/range list */
265         unsigned int chanlist_len;
266
267         sampl_t *data;                  /* data list, size depends on subd flags */
268         unsigned int data_len;
269 };
270
271 struct comedi_chaninfo_struct{
272         unsigned int subdev;
273         lsampl_t *maxdata_list;
274         unsigned int *flaglist;
275         unsigned int *rangelist;
276         unsigned int unused[4];
277 };
278
279 struct comedi_rangeinfo_struct{
280         unsigned int range_type;
281         void *range_ptr;
282 };
283
284 struct comedi_krange_struct{
285         int min;        /* fixed point, multiply by 1e-6 */
286         int max;        /* fixed point, multiply by 1e-6 */
287         unsigned int flags;
288 };
289
290 struct comedi_subdinfo_struct{
291         unsigned int type;
292         unsigned int n_chan;
293         unsigned int subd_flags;
294         unsigned int timer_type;
295         unsigned int len_chanlist;
296         lsampl_t        maxdata;
297         unsigned int    flags;          /* channel flags */
298         unsigned int    range_type;     /* lookup in kernel */
299         unsigned int unused[10];
300 };
301
302 struct comedi_devinfo_struct{
303         unsigned int version_code;
304         unsigned int n_subdevs;
305         char driver_name[COMEDI_NAMELEN];
306         char board_name[COMEDI_NAMELEN];
307         int read_subdevice;
308         int write_subdevice;
309         int unused[30];
310 };
311
312 struct comedi_devconfig_struct{
313         char board_name[COMEDI_NAMELEN];
314         int options[COMEDI_NDEVCONFOPTS];
315 };
316
317 struct comedi_bufconfig_struct{
318         unsigned int subdevice;
319         unsigned int flags;
320
321         unsigned int maximum_size;
322         unsigned int size;
323
324         unsigned int unused[4];
325 };
326
327 struct comedi_bufinfo_struct{
328         unsigned int subdevice;
329         unsigned int bytes_read;
330
331         unsigned int buf_int_ptr;
332         unsigned int buf_user_ptr;
333         unsigned int buf_int_count;
334         unsigned int buf_user_count;
335
336         unsigned int unused[5];
337 };
338
339 /* range stuff */
340
341 #define __RANGE(a,b)    ((((a)&0xffff)<<16)|((b)&0xffff))
342
343 #define RANGE_OFFSET(a)         (((a)>>16)&0xffff)
344 #define RANGE_LENGTH(b)         ((b)&0xffff)
345
346 #define RF_UNIT(flags)          ((flags)&0xff)
347 #define RF_EXTERNAL             (1<<8)
348
349 #define UNIT_volt               0
350 #define UNIT_mA                 1
351 #define UNIT_none               2
352
353
354 /* callback stuff */
355 /* only relevant to kernel modules. */
356
357 #define COMEDI_CB_EOS           1       /* end of scan */
358 #define COMEDI_CB_EOA           2       /* end of acquisition */
359 #define COMEDI_CB_BLOCK         4       /* convenient block size */
360 #define COMEDI_CB_EOBUF         8       /* end of buffer */
361 #define COMEDI_CB_ERROR         16      /* card error during acquisition */
362
363
364 #ifdef __cplusplus
365 }
366 #endif
367
368 #endif /* _COMEDI_H */
369