fixed errno sign problem
[comedilib.git] / lib / libinternal.h
1 /*
2     lib/libinternal.h
3     header file for comedilib internals
4
5     COMEDI - Linux Control and Measurement Device Interface
6     Copyright (C) 1998 David A. Schleef <ds@stm.lbl.gov>
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 _LIBINTERNAL_H
26 #define _LIBINTERNAL_H
27
28 #include <comedilib.h>
29 #include <sys/ioctl.h>
30 #include <fcntl.h>
31 #include <stdio.h>
32
33
34 #define debug_ptr(a)    if(!(a))fprintf(stderr," ** NULL pointer: " __FILE__ ", line %d\n",__LINE__);
35 #define debug_int(a)    if((a)<0)fprintf(stderr," ** error: " __FILE__ ", line %d\n",__LINE__);
36
37 #define COMEDILIB_MAGIC 0xc001dafe
38
39
40 extern int __comedi_init;
41 extern int __comedi_loglevel;
42 extern int __comedi_errno;
43
44 #if 0
45
46 #define libc_error()            (__comedi_errno=errno)
47 #define internal_error(a)       (__comedi_errno=(a))
48
49 #else
50
51 void libc_error(void);
52 void internal_error(int error_number);
53
54 #endif
55
56
57 typedef struct subdevice_struct subdevice;
58 typedef struct device_struct device;
59
60 struct comedi_t_struct{
61         int magic;
62
63         int fd;
64         int n_subdevices;
65
66         comedi_devinfo devinfo;
67
68         subdevice *subdevices;
69 };
70
71 struct subdevice_struct{
72         unsigned int type;
73         unsigned int n_chan;
74         unsigned int subd_flags;
75         unsigned int timer_type;
76         unsigned int len_chanlist;
77         lsampl_t maxdata;
78         unsigned int flags;
79         unsigned int range_type;
80
81         lsampl_t *maxdata_list;
82         unsigned int *range_type_list;
83         unsigned int *flags_list;
84
85         comedi_range *rangeinfo;
86         comedi_range **rangeinfo_list;
87
88         unsigned int has_cmd;
89         unsigned int has_insn;
90         unsigned int has_insn_bits;
91 };
92
93
94
95 /* ioctl wrappers */
96
97 int ioctl_devinfo(int fd,comedi_devinfo *it);
98 int ioctl_subdinfo(int fd,comedi_subdinfo *it);
99 int ioctl_chaninfo(int fd,unsigned int subdev,lsampl_t *maxdata_list,
100                                 unsigned int *flaglist,unsigned int *rangelist);
101 int ioctl_trigger(int fd,comedi_trig *it);
102 int ioctl_rangeinfo(int fd,int range_type,comedi_krange *range_ptr);
103
104 /* filler routines */
105
106 int get_subdevices(comedi_t *it);
107 comedi_range *get_rangeinfo(int fd,unsigned int range_type);
108
109 /* validators */
110
111 int valid_dev(comedi_t *it);
112 int valid_subd(comedi_t *it,unsigned int subdevice);
113 int valid_chan(comedi_t *it,unsigned int subdevice,unsigned int chan);
114
115 enum{
116         COMEDILIB_NOERROR = 0x1000,
117         COMEDILIB_UNKNOWN,
118         COMEDILIB_BADDEV,
119         COMEDILIB_BADSUBD,
120         COMEDILIB_BADCHAN,
121 };
122
123
124 /* comedi version compatibility */
125
126 #ifndef TRIG_WRITE
127 #define TRIG_WRITE      0x0040
128 #endif
129
130 #ifdef COMEDI_CMD
131 #define HAVE_COMEDI_CMD
132 #endif
133
134 #ifdef COMEDI_INSNLIST
135 #define HAVE_COMEDI_INSN
136 #endif
137
138
139
140 #endif
141