3 a comedlib interface for kernel modules
5 COMEDI - Linux Control and Measurement Device Interface
6 Copyright (C) 1997-2000 David A. Schleef <ds@schleef.org>
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.
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.
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.
24 #define __NO_VERSION__
25 #include "../comedi.h"
26 #include "../comedilib.h"
27 #include "../comedidev.h"
29 int comedi_get_n_subdevices(void *d
)
31 struct comedi_device
*dev
= (struct comedi_device
*)d
;
33 return dev
->n_subdevices
;
36 int comedi_get_version_code(void *d
)
38 return COMEDI_VERSION_CODE
;
41 const char *comedi_get_driver_name(void *d
)
43 struct comedi_device
*dev
= (struct comedi_device
*)d
;
45 return dev
->driver
->driver_name
;
48 const char *comedi_get_board_name(void *d
)
50 struct comedi_device
*dev
= (struct comedi_device
*)d
;
52 return dev
->board_name
;
55 int comedi_get_subdevice_type(void *d
, unsigned int subdevice
)
57 struct comedi_device
*dev
= (struct comedi_device
*)d
;
58 struct comedi_subdevice
*s
= dev
->subdevices
+ subdevice
;
63 unsigned int comedi_get_subdevice_flags(void *d
, unsigned int subdevice
)
65 struct comedi_device
*dev
= (struct comedi_device
*)d
;
66 struct comedi_subdevice
*s
= dev
->subdevices
+ subdevice
;
68 return s
->subdev_flags
;
71 int comedi_find_subdevice_by_type(void *d
, int type
, unsigned int subd
)
73 struct comedi_device
*dev
= (struct comedi_device
*)d
;
75 if (subd
> dev
->n_subdevices
)
78 for (; subd
< dev
->n_subdevices
; subd
++) {
79 if (dev
->subdevices
[subd
].type
== type
)
85 int comedi_get_n_channels(void *d
, unsigned int subdevice
)
87 struct comedi_device
*dev
= (struct comedi_device
*)d
;
88 struct comedi_subdevice
*s
= dev
->subdevices
+ subdevice
;
93 int comedi_get_len_chanlist(void *d
, unsigned int subdevice
)
95 struct comedi_device
*dev
= (struct comedi_device
*)d
;
96 struct comedi_subdevice
*s
= dev
->subdevices
+ subdevice
;
98 return s
->len_chanlist
;
101 unsigned int comedi_get_maxdata(void *d
, unsigned int subdevice
,
104 struct comedi_device
*dev
= (struct comedi_device
*)d
;
105 struct comedi_subdevice
*s
= dev
->subdevices
+ subdevice
;
108 return s
->maxdata_list
[chan
];
113 #ifdef KCOMEDILIB_DEPRECATED
114 int comedi_get_rangetype(void *d
, unsigned int subdevice
, unsigned int chan
)
116 struct comedi_device
*dev
= (struct comedi_device
*)d
;
117 struct comedi_subdevice
*s
= dev
->subdevices
+ subdevice
;
120 if (s
->range_table_list
) {
121 ret
= s
->range_table_list
[chan
]->length
;
123 ret
= s
->range_table
->length
;
126 ret
= ret
| (dev
->minor
<< 28) | (subdevice
<< 24) | (chan
<< 16);
132 int comedi_get_n_ranges(void *d
, unsigned int subdevice
, unsigned int chan
)
134 struct comedi_device
*dev
= (struct comedi_device
*)d
;
135 struct comedi_subdevice
*s
= dev
->subdevices
+ subdevice
;
138 if (s
->range_table_list
) {
139 ret
= s
->range_table_list
[chan
]->length
;
141 ret
= s
->range_table
->length
;
148 * ALPHA (non-portable)
150 int comedi_get_krange(void *d
, unsigned int subdevice
, unsigned int chan
,
151 unsigned int range
, struct comedi_krange
*krange
)
153 struct comedi_device
*dev
= (struct comedi_device
*)d
;
154 struct comedi_subdevice
*s
= dev
->subdevices
+ subdevice
;
155 const struct comedi_lrange
*lr
;
157 if (s
->range_table_list
) {
158 lr
= s
->range_table_list
[chan
];
162 if (range
>= lr
->length
)
165 memcpy(krange
, lr
->range
+ range
, sizeof(struct comedi_krange
));
171 * ALPHA (may be renamed)
173 unsigned int comedi_get_buf_head_pos(void *d
, unsigned int subdevice
)
175 struct comedi_device
*dev
= (struct comedi_device
*)d
;
176 struct comedi_subdevice
*s
= dev
->subdevices
+ subdevice
;
177 struct comedi_async
*async
;
183 return async
->buf_write_count
;
186 int comedi_get_buffer_contents(void *d
, unsigned int subdevice
)
188 struct comedi_device
*dev
= (struct comedi_device
*)d
;
189 struct comedi_subdevice
*s
= dev
->subdevices
+ subdevice
;
190 struct comedi_async
*async
;
191 unsigned int num_bytes
;
193 if (subdevice
>= dev
->n_subdevices
)
198 num_bytes
= comedi_buf_read_n_available(s
->async
);
205 int comedi_set_user_int_count(void *d
, unsigned int subdevice
,
206 unsigned int buf_user_count
)
208 struct comedi_device
*dev
= (struct comedi_device
*)d
;
209 struct comedi_subdevice
*s
= dev
->subdevices
+ subdevice
;
210 struct comedi_async
*async
;
217 num_bytes
= buf_user_count
- async
->buf_read_count
;
220 comedi_buf_read_alloc(async
, num_bytes
);
221 comedi_buf_read_free(async
, num_bytes
);
226 int comedi_mark_buffer_read(void *d
, unsigned int subdevice
,
227 unsigned int num_bytes
)
229 struct comedi_device
*dev
= (struct comedi_device
*)d
;
230 struct comedi_subdevice
*s
= dev
->subdevices
+ subdevice
;
231 struct comedi_async
*async
;
233 if (subdevice
>= dev
->n_subdevices
)
239 comedi_buf_read_alloc(async
, num_bytes
);
240 comedi_buf_read_free(async
, num_bytes
);
245 int comedi_mark_buffer_written(void *d
, unsigned int subdevice
,
246 unsigned int num_bytes
)
248 struct comedi_device
*dev
= (struct comedi_device
*)d
;
249 struct comedi_subdevice
*s
= dev
->subdevices
+ subdevice
;
250 struct comedi_async
*async
;
253 if (subdevice
>= dev
->n_subdevices
)
258 bytes_written
= comedi_buf_write_alloc(async
, num_bytes
);
259 comedi_buf_write_free(async
, bytes_written
);
260 if (bytes_written
!= num_bytes
)
265 int comedi_get_buffer_size(void *d
, unsigned int subdev
)
267 struct comedi_device
*dev
= (struct comedi_device
*)d
;
268 struct comedi_subdevice
*s
= dev
->subdevices
+ subdev
;
269 struct comedi_async
*async
;
271 if (subdev
>= dev
->n_subdevices
)
277 return async
->prealloc_bufsz
;
280 int comedi_get_buffer_offset(void *d
, unsigned int subdevice
)
282 struct comedi_device
*dev
= (struct comedi_device
*)d
;
283 struct comedi_subdevice
*s
= dev
->subdevices
+ subdevice
;
284 struct comedi_async
*async
;
286 if (subdevice
>= dev
->n_subdevices
)
292 return async
->buf_read_ptr
;