1 /***********************************************************
2 Interface file for wrapping Comedilib
4 Copyright (C) 2003 Bryan Cole <bryan.cole@teraview.co.uk>
5 Copyright (C) 1998-2002 David A. Schleef <ds@schleef.org>
6 Copyright (C) 2003,2004 Frank Mori Hess <fmhess@users.sourceforge.net>
7 Copyright (C) 2003 Steven Jenkins <steven.jenkins@ieee.org>
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 ***********************************************************
25 * This file was created with Python wrappers in mind but wil
26 * probably work for other swig-supported script languages
28 * to regenerate the wrappers run:
29 * swig -python comedi.i
31 ***********************************************************/
34 #include "comedilib.h"
40 static unsigned int cr_pack(unsigned int chan, unsigned int rng, unsigned int aref){
41 return CR_PACK(chan,rng,aref);
43 static unsigned int cr_pack_flags(unsigned int chan, unsigned int rng, unsigned int aref, unsigned int flags){
44 return CR_PACK_FLAGS(chan,rng,aref, flags);
46 static unsigned int cr_chan(unsigned int a){
49 static unsigned int cr_range(unsigned int a){
52 static unsigned int cr_aref(unsigned int a){
57 %array_class(unsigned int, chanlist);
59 %typemap(ruby, argout) comedi_cmd *INOUT(VALUE info) {
60 $result = output_helper($result, $arg);
63 /* below are (modified) copies of comedi.h and comedilib.h */
67 typedef unsigned int lsampl_t;
68 typedef unsigned short sampl_t;
70 #define CR_FLAGS_MASK 0xfc000000
71 #define CR_ALT_FILTER (1<<26)
72 #define CR_DITHER CR_ALT_FILTER
73 #define CR_DEGLITCH CR_ALT_FILTER
74 #define CR_ALT_SOURCE (1<<27)
75 #define CR_EDGE (1<<30)
76 #define CR_INVERT (1<<31)
78 #define AREF_GROUND 0x00 /* analog ref = analog ground */
79 #define AREF_COMMON 0x01 /* analog ref = analog common */
80 #define AREF_DIFF 0x02 /* analog ref = differential */
81 #define AREF_OTHER 0x03 /* analog ref = other (undefined) */
83 /* counters -- these are arbitrary values */
84 #define GPCT_RESET 0x0001
85 #define GPCT_SET_SOURCE 0x0002
86 #define GPCT_SET_GATE 0x0004
87 #define GPCT_SET_DIRECTION 0x0008
88 #define GPCT_SET_OPERATION 0x0010
89 #define GPCT_ARM 0x0020
90 #define GPCT_DISARM 0x0040
91 #define GPCT_GET_INT_CLK_FRQ 0x0080
93 #define GPCT_INT_CLOCK 0x0001
94 #define GPCT_EXT_PIN 0x0002
95 #define GPCT_NO_GATE 0x0004
96 #define GPCT_UP 0x0008
97 #define GPCT_DOWN 0x0010
98 #define GPCT_HWUD 0x0020
99 #define GPCT_SIMPLE_EVENT 0x0040
100 #define GPCT_SINGLE_PERIOD 0x0080
101 #define GPCT_SINGLE_PW 0x0100
102 #define GPCT_CONT_PULSE_OUT 0x0200
103 #define GPCT_SINGLE_PULSE_OUT 0x0400
108 #define INSN_MASK_WRITE 0x8000000
109 #define INSN_MASK_READ 0x4000000
110 #define INSN_MASK_SPECIAL 0x2000000
112 #define INSN_READ ( 0 | INSN_MASK_READ)
113 #define INSN_WRITE ( 1 | INSN_MASK_WRITE)
114 #define INSN_BITS ( 2 | INSN_MASK_READ|INSN_MASK_WRITE)
115 #define INSN_CONFIG ( 3 | INSN_MASK_READ|INSN_MASK_WRITE)
116 #define INSN_GTOD ( 4 | INSN_MASK_READ|INSN_MASK_SPECIAL)
117 #define INSN_WAIT ( 5 | INSN_MASK_WRITE|INSN_MASK_SPECIAL)
118 #define INSN_INTTRIG ( 6 | INSN_MASK_WRITE|INSN_MASK_SPECIAL)
121 /* These flags are used in comedi_trig structures */
123 #define TRIG_BOGUS 0x0001 /* do the motions */
124 #define TRIG_DITHER 0x0002 /* enable dithering */
125 #define TRIG_DEGLITCH 0x0004 /* enable deglitching */
126 //#define TRIG_RT 0x0008 /* perform op in real time */
127 #define TRIG_CONFIG 0x0010 /* perform configuration, not triggering */
128 //#define TRIG_WAKE_EOS 0x0020 /* wake up on end-of-scan events */
129 //#define TRIG_WRITE 0x0040 /* write to bidirectional devices */
132 /* These flags are used in comedi_cmd structures */
134 #define CMDF_PRIORITY 0x00000008 /* try to use a real-time interrupt while performing command */
136 #define TRIG_RT CMDF_PRIORITY /* compatibility definition */
137 #define TRIG_WAKE_EOS 0x00000020 /* legacy definition for COMEDI_EV_SCAN_END */
139 #define CMDF_WRITE 0x00000040
140 #define TRIG_WRITE CMDF_WRITE /* compatibility definition */
142 #define CMDF_RAWDATA 0x00000080
144 #define COMEDI_EV_START 0x00040000
145 #define COMEDI_EV_SCAN_BEGIN 0x00080000
146 #define COMEDI_EV_CONVERT 0x00100000
147 #define COMEDI_EV_SCAN_END 0x00200000
148 #define COMEDI_EV_STOP 0x00400000
150 #define TRIG_ROUND_MASK 0x00030000
151 #define TRIG_ROUND_NEAREST 0x00000000
152 #define TRIG_ROUND_DOWN 0x00010000
153 #define TRIG_ROUND_UP 0x00020000
154 #define TRIG_ROUND_UP_NEXT 0x00030000
156 /* trigger sources */
158 #define TRIG_ANY 0xffffffff
159 #define TRIG_INVALID 0x00000000
161 #define TRIG_NONE 0x00000001 /* never trigger */
162 #define TRIG_NOW 0x00000002 /* trigger now + N ns */
163 #define TRIG_FOLLOW 0x00000004 /* trigger on next lower level trig */
164 #define TRIG_TIME 0x00000008 /* trigger at time N ns */
165 #define TRIG_TIMER 0x00000010 /* trigger at rate N ns */
166 #define TRIG_COUNT 0x00000020 /* trigger when count reaches N */
167 #define TRIG_EXT 0x00000040 /* trigger on external signal N */
168 #define TRIG_INT 0x00000080 /* trigger on comedi-internal signal N */
169 #define TRIG_OTHER 0x00000100 /* driver defined */
171 /* subdevice flags */
173 #define SDF_BUSY 0x0001 /* device is busy */
174 #define SDF_BUSY_OWNER 0x0002 /* device is busy with your job */
175 #define SDF_LOCKED 0x0004 /* subdevice is locked */
176 #define SDF_LOCK_OWNER 0x0008 /* you own lock */
177 #define SDF_MAXDATA 0x0010 /* maxdata depends on channel */
178 #define SDF_FLAGS 0x0020 /* flags depend on channel */
179 #define SDF_RANGETYPE 0x0040 /* range type depends on channel */
180 #define SDF_MODE0 0x0080 /* can do mode 0 */
181 #define SDF_MODE1 0x0100 /* can do mode 1 */
182 #define SDF_MODE2 0x0200 /* can do mode 2 */
183 #define SDF_MODE3 0x0400 /* can do mode 3 */
184 #define SDF_MODE4 0x0800 /* can do mode 4 */
185 #define SDF_CMD 0x1000 /* can do commands */
187 #define SDF_READABLE 0x00010000 /* subdevice can be read (e.g. analog input) */
188 #define SDF_WRITABLE 0x00020000 /* subdevice can be written (e.g. analog output) */
189 #define SDF_WRITEABLE SDF_WRITABLE /* spelling error in API */
190 #define SDF_INTERNAL 0x00040000 /* subdevice does not have externally visible lines */
191 #define SDF_RT 0x00080000 /* DEPRECATED: subdevice is RT capable */
192 #define SDF_GROUND 0x00100000 /* can do aref=ground */
193 #define SDF_COMMON 0x00200000 /* can do aref=common */
194 #define SDF_DIFF 0x00400000 /* can do aref=diff */
195 #define SDF_OTHER 0x00800000 /* can do aref=other */
196 #define SDF_DITHER 0x01000000 /* can do dithering */
197 #define SDF_DEGLITCH 0x02000000 /* can do deglitching */
198 #define SDF_MMAP 0x04000000 /* can do mmap() */
199 #define SDF_RUNNING 0x08000000 /* subdevice is acquiring data */
200 #define SDF_LSAMPL 0x10000000 /* subdevice uses 32-bit samples */
201 #define SDF_PACKED 0x20000000 /* subdevice can do packed DIO */
203 /* subdevice types */
205 #define COMEDI_SUBD_UNUSED 0 /* unused */
206 #define COMEDI_SUBD_AI 1 /* analog input */
207 #define COMEDI_SUBD_AO 2 /* analog output */
208 #define COMEDI_SUBD_DI 3 /* digital input */
209 #define COMEDI_SUBD_DO 4 /* digital output */
210 #define COMEDI_SUBD_DIO 5 /* digital input/output */
211 #define COMEDI_SUBD_COUNTER 6 /* counter */
212 #define COMEDI_SUBD_TIMER 7 /* timer */
213 #define COMEDI_SUBD_MEMORY 8 /* memory, EEPROM, DPRAM */
214 #define COMEDI_SUBD_CALIB 9 /* calibration DACs */
215 #define COMEDI_SUBD_PROC 10 /* processor, DSP */
217 /* configuration instructions */
219 #define COMEDI_INPUT 0
220 #define COMEDI_OUTPUT 1
221 #define COMEDI_OPENDRAIN 2
223 #define INSN_CONFIG_ANALOG_TRIG 0x10
224 //#define INSN_CONFIG_WAVEFORM 0x11
225 //#define INSN_CONFIG_TRIG 0x12
226 //#define INSN_CONFIG_COUNTER 0x13
227 #define INSN_CONFIG_ALT_SOURCE 0x14
228 #define INSN_CONFIG_DIGITAL_TRIG 0x15
229 #define INSN_CONFIG_BLOCK_SIZE 0x16
230 #define INSN_CONFIG_TIMER_1 0x17
231 #define INSN_CONFIG_FILTER 0x18
232 #define INSN_CONFIG_CHANGE_NOTIFY 0x19
236 typedef struct comedi_trig_struct comedi_trig;
237 typedef struct comedi_cmd_struct comedi_cmd;
238 typedef struct comedi_insn_struct comedi_insn;
239 typedef struct comedi_insnlist_struct comedi_insnlist;
240 typedef struct comedi_chaninfo_struct comedi_chaninfo;
241 typedef struct comedi_subdinfo_struct comedi_subdinfo;
242 typedef struct comedi_devinfo_struct comedi_devinfo;
243 typedef struct comedi_devconfig_struct comedi_devconfig;
244 typedef struct comedi_rangeinfo_struct comedi_rangeinfo;
245 typedef struct comedi_krange_struct comedi_krange;
246 typedef struct comedi_bufconfig_struct comedi_bufconfig;
247 typedef struct comedi_bufinfo_struct comedi_bufinfo;
249 struct comedi_trig_struct{
250 unsigned int subdev; /* subdevice */
251 unsigned int mode; /* mode */
253 unsigned int n_chan; /* number of channels */
254 unsigned int *chanlist; /* channel/range list */
255 sampl_t *data; /* data list, size depends on subd flags */
256 unsigned int n; /* number of scans */
257 unsigned int trigsrc;
258 unsigned int trigvar;
259 unsigned int trigvar1;
260 unsigned int data_len;
261 unsigned int unused[3];
264 struct comedi_insn_struct{
269 unsigned int chanspec;
270 unsigned int unused[3];
273 struct comedi_insnlist_struct{
274 unsigned int n_insns;
278 struct comedi_cmd_struct{
282 unsigned int start_src;
283 unsigned int start_arg;
285 unsigned int scan_begin_src;
286 unsigned int scan_begin_arg;
288 unsigned int convert_src;
289 unsigned int convert_arg;
291 unsigned int scan_end_src;
292 unsigned int scan_end_arg;
294 unsigned int stop_src;
295 unsigned int stop_arg;
297 unsigned int *chanlist; /* channel/range list */
298 unsigned int chanlist_len;
300 sampl_t *data; /* data list, size depends on subd flags */
301 unsigned int data_len;
304 struct comedi_chaninfo_struct{
306 lsampl_t *maxdata_list;
307 unsigned int *flaglist;
308 unsigned int *rangelist;
309 unsigned int unused[4];
312 struct comedi_rangeinfo_struct{
313 unsigned int range_type;
317 struct comedi_krange_struct{
318 int min; /* fixed point, multiply by 1e-6 */
319 int max; /* fixed point, multiply by 1e-6 */
323 struct comedi_subdinfo_struct{
326 unsigned int subd_flags;
327 unsigned int timer_type;
328 unsigned int len_chanlist;
330 unsigned int flags; /* channel flags */
331 unsigned int range_type; /* lookup in kernel */
332 unsigned int settling_time_0;
333 unsigned int unused[9];
336 struct comedi_devinfo_struct{
337 unsigned int version_code;
338 unsigned int n_subdevs;
339 char driver_name[COMEDI_NAMELEN];
340 char board_name[COMEDI_NAMELEN];
346 struct comedi_devconfig_struct{
347 char board_name[COMEDI_NAMELEN];
348 int options[COMEDI_NDEVCONFOPTS];
351 struct comedi_bufconfig_struct{
352 unsigned int subdevice;
355 unsigned int maximum_size;
358 unsigned int unused[4];
361 struct comedi_bufinfo_struct{
362 unsigned int subdevice;
363 unsigned int bytes_read;
365 unsigned int buf_int_ptr;
366 unsigned int buf_user_ptr;
367 unsigned int buf_int_count;
368 unsigned int buf_user_count;
370 unsigned int bytes_written;
372 unsigned int unused[4];
377 #define __RANGE(a,b) ((((a)&0xffff)<<16)|((b)&0xffff))
379 #define RANGE_OFFSET(a) (((a)>>16)&0xffff)
380 #define RANGE_LENGTH(b) ((b)&0xffff)
382 #define RF_UNIT(flags) ((flags)&0xff)
383 #define RF_EXTERNAL (1<<8)
389 #define COMEDI_MIN_SPEED ((unsigned int)0xffffffff)
392 /* only relevant to kernel modules. */
394 #define COMEDI_CB_EOS 1 /* end of scan */
395 #define COMEDI_CB_EOA 2 /* end of acquisition */
396 #define COMEDI_CB_BLOCK 4 /* DEPRECATED: convenient block size */
397 #define COMEDI_CB_EOBUF 8 /* DEPRECATED: end of buffer */
398 #define COMEDI_CB_ERROR 16 /* card error during acquisition */
399 #define COMEDI_CB_OVERFLOW 32 /* buffer overflow/underflow */
402 typedef void comedi_t;
410 typedef struct comedi_sv_struct{
412 unsigned int subdevice;
419 /* number of measurements to average (for ai) */
425 enum comedi_oor_behavior {
426 COMEDI_OOR_NUMBER = 0,
430 comedi_t *comedi_open(const char *fn);
431 int comedi_close(comedi_t *it);
434 int comedi_loglevel(int loglevel);
435 void comedi_perror(const char *s);
436 char *comedi_strerror(int errnum);
437 int comedi_errno(void);
438 int comedi_fileno(comedi_t *it);
440 /* global behavior */
441 enum comedi_oor_behavior comedi_set_global_oor_behavior(enum comedi_oor_behavior behavior);
444 int comedi_get_n_subdevices(comedi_t *it);
445 #define COMEDI_VERSION_CODE(a,b,c) (((a)<<16) | ((b)<<8) | (c))
446 int comedi_get_version_code(comedi_t *it);
447 char *comedi_get_driver_name(comedi_t *it);
448 char *comedi_get_board_name(comedi_t *it);
449 int comedi_get_read_subdevice(comedi_t *dev);
450 int comedi_get_write_subdevice(comedi_t *dev);
452 /* subdevice queries */
453 int comedi_get_subdevice_type(comedi_t *it,unsigned int subdevice);
454 int comedi_find_subdevice_by_type(comedi_t *it,int type,unsigned int subd);
455 int comedi_get_subdevice_flags(comedi_t *it,unsigned int subdevice);
456 int comedi_get_n_channels(comedi_t *it,unsigned int subdevice);
457 int comedi_range_is_chan_specific(comedi_t *it,unsigned int subdevice);
458 int comedi_maxdata_is_chan_specific(comedi_t *it,unsigned int subdevice);
460 /* channel queries */
461 lsampl_t comedi_get_maxdata(comedi_t *it,unsigned int subdevice,
463 int comedi_get_n_ranges(comedi_t *it,unsigned int subdevice,
465 comedi_range * comedi_get_range(comedi_t *it,unsigned int subdevice,
466 unsigned int chan,unsigned int range);
467 int comedi_find_range(comedi_t *it,unsigned int subd,unsigned int chan,
468 unsigned int unit,double min,double max);
471 int comedi_get_buffer_size(comedi_t *it,unsigned int subdevice);
472 int comedi_get_max_buffer_size(comedi_t *it,unsigned int subdevice);
473 int comedi_set_buffer_size(comedi_t *it,unsigned int subdevice,
476 /* low-level stuff */
477 int comedi_do_insnlist(comedi_t *it,comedi_insnlist *il);
478 int comedi_do_insn(comedi_t *it,comedi_insn *insn);
479 int comedi_lock(comedi_t *it,unsigned int subdevice);
480 int comedi_unlock(comedi_t *it,unsigned int subdevice);
483 double comedi_to_phys(lsampl_t data,comedi_range *rng,lsampl_t maxdata);
484 lsampl_t comedi_from_phys(double data,comedi_range *rng,lsampl_t maxdata);
485 int comedi_sampl_to_phys(double *dest, int dst_stride, sampl_t *src,
486 int src_stride, comedi_range *rng, lsampl_t maxdata, int n);
487 int comedi_sampl_from_phys(sampl_t *dest,int dst_stride,double *src,
488 int src_stride, comedi_range *rng, lsampl_t maxdata, int n);
490 /* syncronous stuff */
491 int comedi_data_read(comedi_t *it,unsigned int subd,unsigned int chan,
492 unsigned int range,unsigned int aref,lsampl_t *OUTPUT);
493 int comedi_data_read_n(comedi_t *it,unsigned int subd,unsigned int chan,
494 unsigned int range,unsigned int aref,lsampl_t *OUTPUT, unsigned int n);
495 int comedi_data_read_hint(comedi_t *it,unsigned int subd,unsigned int chan,
496 unsigned int range,unsigned int aref);
497 int comedi_data_read_delayed(comedi_t *it,unsigned int subd,unsigned int chan,
498 unsigned int range,unsigned int aref,lsampl_t *OUTPUT, unsigned int nano_sec);
499 int comedi_data_write(comedi_t *it,unsigned int subd,unsigned int chan,
500 unsigned int range,unsigned int aref,lsampl_t data);
501 int comedi_dio_config(comedi_t *it,unsigned int subd,unsigned int chan,
503 int comedi_dio_read(comedi_t *it,unsigned int subd,unsigned int chan,
504 unsigned int *OUTPUT);
505 int comedi_dio_write(comedi_t *it,unsigned int subd,unsigned int chan,
507 int comedi_dio_bitfield(comedi_t *it,unsigned int subd,
508 unsigned int write_mask, unsigned int *INOUT);
510 /* slowly varying stuff */
511 int comedi_sv_init(comedi_sv_t *it,comedi_t *dev,unsigned int subd,unsigned int chan);
512 int comedi_sv_update(comedi_sv_t *it);
513 int comedi_sv_measure(comedi_sv_t *it,double *data);
515 /* streaming I/O (commands) */
517 int comedi_get_cmd_src_mask(comedi_t *dev,unsigned int subdevice,
519 int comedi_get_cmd_generic_timed(comedi_t *dev,unsigned int subdevice,
520 comedi_cmd *INOUT,unsigned int ns);
521 int comedi_cancel(comedi_t *it,unsigned int subdevice);
522 int comedi_command(comedi_t *it,comedi_cmd *cmd);
523 int comedi_command_test(comedi_t *it,comedi_cmd *INOUT);
524 int comedi_poll(comedi_t *dev,unsigned int subdevice);
528 int comedi_set_max_buffer_size(comedi_t *it, unsigned int subdev,
529 unsigned int max_size);
530 int comedi_get_buffer_contents(comedi_t *it, unsigned int subdev);
531 int comedi_mark_buffer_read(comedi_t *it, unsigned int subdev,
533 int comedi_get_buffer_offset(comedi_t *it, unsigned int subdev);
536 /* structs and functions used for parsing calibration files */
539 unsigned int subdevice;
540 unsigned int channel;
543 #define CS_MAX_AREFS_LENGTH 4
546 unsigned int subdevice;
547 unsigned int *channels;
548 unsigned int num_channels;
549 unsigned int *ranges;
550 unsigned int num_ranges;
551 unsigned int arefs[ CS_MAX_AREFS_LENGTH ];
552 unsigned int num_arefs;
553 comedi_caldac_t *caldacs;
554 unsigned int num_caldacs;
555 } comedi_calibration_setting_t;
561 comedi_calibration_setting_t *settings;
562 unsigned int num_settings;
563 } comedi_calibration_t;
565 comedi_calibration_t* comedi_parse_calibration_file( const char *cal_file_path );
566 int comedi_apply_parsed_calibration( comedi_t *dev, unsigned int subdev, unsigned int channel,
567 unsigned int range, unsigned int aref, const comedi_calibration_t *calibration );
568 char* comedi_get_default_calibration_path( comedi_t *dev );
569 void comedi_cleanup_calibration( comedi_calibration_t *calibration );
570 int comedi_apply_calibration( comedi_t *dev, unsigned int subdev, unsigned int channel,
571 unsigned int range, unsigned int aref, const char *cal_file_path);