from ds
[comedilib.git] / lib / libinternal.h
1 /*
2     lib/libinternal.h
3     internal definitions for comedilib
4
5     COMEDILIB - Linux Control and Measurement Device Interface Library
6     Copyright (C) 1997-2001 David A. Schleef <ds@schleef.org>
7
8     This library is free software; you can redistribute it and/or
9     modify it under the terms of the GNU Lesser General Public
10     License as published by the Free Software Foundation, version 2.1
11     of the License.
12
13     This library 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 GNU
16     Lesser General Public License for more details.
17
18     You should have received a copy of the GNU Lesser General Public
19     License along with this library; if not, write to the Free Software
20     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
21     USA.
22 */
23
24 #ifndef _LIBINTERNAL_H
25 #define _LIBINTERNAL_H
26
27 #define _COMEDILIB_DEPRECATED
28
29 #include <comedilib.h>
30 #include <sys/ioctl.h>
31 #include <fcntl.h>
32 #include <stdio.h>
33 #ifdef I18N
34 #include <libintl.h>
35 #endif
36
37 #include <comedi_errno.h>
38
39 /* This indicates a symbol that should not be exported as part of
40  * the library.  But I don't know how to make it useful yet. */
41 #define INTERNAL
42
43 /* gettext()ization */
44
45 #ifdef I18N
46 #define _(a) gettext((a))
47 #else
48 #define _(a) (a)
49 #endif
50 #define _s(a) (a)
51
52
53 #define debug_ptr(a)    if(!(a))fprintf(stderr," ** NULL pointer: " __FILE__ ", line %d\n",__LINE__);
54 #define debug_int(a)    if((a)<0)fprintf(stderr," ** error: " __FILE__ ", line %d\n",__LINE__);
55
56 #define DEBUG(level,format,args...) do{if(__comedi_loglevel>=(level))fprintf(stderr,__FUNCTION__ ": " format, ## args);}while(0)
57
58 #define COMEDILIB_MAGIC 0xc001dafe
59
60 extern int __comedi_init;
61 extern int __comedi_loglevel;
62 extern int __comedi_errno;
63
64 #if 0
65
66 #define libc_error()            (__comedi_errno=errno)
67 #define internal_error(a)       (__comedi_errno=(a))
68
69 #else
70
71 void libc_error(void);
72 void internal_error(int error_number);
73
74 #endif
75
76
77 typedef struct subdevice_struct subdevice;
78 typedef struct device_struct device;
79
80 struct comedi_t_struct{
81         int magic;
82
83         int fd;
84         int n_subdevices;
85
86         comedi_devinfo devinfo;
87
88         subdevice *subdevices;
89
90         unsigned int has_insnlist_ioctl;
91         unsigned int has_insn_ioctl;
92 };
93
94 struct subdevice_struct{
95         unsigned int type;
96         unsigned int n_chan;
97         unsigned int subd_flags;
98         unsigned int timer_type;
99         unsigned int len_chanlist;
100         lsampl_t maxdata;
101         unsigned int flags;
102         unsigned int range_type;
103
104         lsampl_t *maxdata_list;
105         unsigned int *range_type_list;
106         unsigned int *flags_list;
107
108         comedi_range *rangeinfo;
109         comedi_range **rangeinfo_list;
110
111         unsigned int has_cmd;
112         unsigned int has_insn_bits;
113
114         int cmd_mask_errno;
115         comedi_cmd *cmd_mask;
116         int cmd_timed_errno;
117         comedi_cmd *cmd_timed;
118 };
119
120
121
122 /* ioctl wrappers */
123
124 int ioctl_devinfo(int fd,comedi_devinfo *it);
125 int ioctl_subdinfo(int fd,comedi_subdinfo *it);
126 int ioctl_chaninfo(int fd,unsigned int subdev,lsampl_t *maxdata_list,
127                                 unsigned int *flaglist,unsigned int *rangelist);
128 int ioctl_trigger(int fd,comedi_trig *it);
129 int ioctl_rangeinfo(int fd,int range_type,comedi_krange *range_ptr);
130 int ioctl_bufconfig(int fd, comedi_bufconfig *bc);
131 int ioctl_bufinfo(int fd, comedi_bufinfo *bi);
132
133 /* filler routines */
134
135 int get_subdevices(comedi_t *it);
136 comedi_range *get_rangeinfo(int fd,unsigned int range_type);
137
138 /* validators */
139
140 int valid_dev(comedi_t *it);
141 int valid_subd(comedi_t *it,unsigned int subdevice);
142 int valid_chan(comedi_t *it,unsigned int subdevice,unsigned int chan);
143
144 enum{
145         COMEDILIB_NOERROR = 0x1000,
146         COMEDILIB_UNKNOWN,
147         COMEDILIB_BADDEV,
148         COMEDILIB_BADSUBD,
149         COMEDILIB_BADCHAN,
150 };
151
152 // used by range.c, was in comedilib.h but apparently deprecated so I put it here - fmhess
153 int comedi_get_rangetype(comedi_t *it,unsigned int subdevice,unsigned int chan);
154
155 #endif
156