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(comedi_t * d)
31 comedi_device *dev = (comedi_device *) d;
33 return dev->n_subdevices;
36 int comedi_get_version_code(comedi_t * d)
38 return COMEDI_VERSION_CODE;
41 const char *comedi_get_driver_name(comedi_t * d)
43 comedi_device *dev = (comedi_device *) d;
45 return dev->driver->driver_name;
48 const char *comedi_get_board_name(comedi_t * d)
50 comedi_device *dev = (comedi_device *) d;
52 return dev->board_name;
55 int comedi_get_subdevice_type(comedi_t * d, unsigned int subdevice)
57 comedi_device *dev = (comedi_device *) d;
58 comedi_subdevice *s = dev->subdevices + subdevice;
63 unsigned int comedi_get_subdevice_flags(comedi_t * d, unsigned int subdevice)
65 comedi_device *dev = (comedi_device *) d;
66 comedi_subdevice *s = dev->subdevices + subdevice;
68 return s->subdev_flags;
71 int comedi_find_subdevice_by_type(comedi_t * d, int type, unsigned int subd)
73 comedi_device *dev = (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(comedi_t * d, unsigned int subdevice)
87 comedi_device *dev = (comedi_device *) d;
88 comedi_subdevice *s = dev->subdevices + subdevice;
93 int comedi_get_len_chanlist(comedi_t * d, unsigned int subdevice)
95 comedi_device *dev = (comedi_device *) d;
96 comedi_subdevice *s = dev->subdevices + subdevice;
98 return s->len_chanlist;
101 lsampl_t comedi_get_maxdata(comedi_t * d, unsigned int subdevice,
104 comedi_device *dev = (comedi_device *) d;
105 comedi_subdevice *s = dev->subdevices + subdevice;
108 return s->maxdata_list[chan];
113 #ifdef KCOMEDILIB_DEPRECATED
114 int comedi_get_rangetype(comedi_t * d, unsigned int subdevice,
117 comedi_device *dev = (comedi_device *) d;
118 comedi_subdevice *s = dev->subdevices + subdevice;
121 if (s->range_table_list) {
122 ret = s->range_table_list[chan]->length;
124 ret = s->range_table->length;
127 ret = ret | (dev->minor << 28) | (subdevice << 24) | (chan << 16);
133 int comedi_get_n_ranges(comedi_t * d, unsigned int subdevice, unsigned int chan)
135 comedi_device *dev = (comedi_device *) d;
136 comedi_subdevice *s = dev->subdevices + subdevice;
139 if (s->range_table_list) {
140 ret = s->range_table_list[chan]->length;
142 ret = s->range_table->length;
149 * ALPHA (non-portable)
151 int comedi_get_krange(comedi_t * d, unsigned int subdevice, unsigned int chan,
152 unsigned int range, comedi_krange * krange)
154 comedi_device *dev = (comedi_device *) d;
155 comedi_subdevice *s = dev->subdevices + subdevice;
156 const comedi_lrange *lr;
158 if (s->range_table_list) {
159 lr = s->range_table_list[chan];
163 if (range >= lr->length) {
166 memcpy(krange, lr->range + range, sizeof(comedi_krange));
172 * ALPHA (may be renamed)
174 unsigned int comedi_get_buf_head_pos(comedi_t * d, unsigned int subdevice)
176 comedi_device *dev = (comedi_device *) d;
177 comedi_subdevice *s = dev->subdevices + subdevice;
184 return async->buf_write_count;
187 int comedi_get_buffer_contents(comedi_t * d, unsigned int subdevice)
189 comedi_device *dev = (comedi_device *) d;
190 comedi_subdevice *s = dev->subdevices + subdevice;
192 unsigned int num_bytes;
194 if (subdevice >= dev->n_subdevices)
199 num_bytes = comedi_buf_read_n_available(s->async);
206 int comedi_set_user_int_count(comedi_t * d, unsigned int subdevice,
207 unsigned int buf_user_count)
209 comedi_device *dev = (comedi_device *) d;
210 comedi_subdevice *s = dev->subdevices + subdevice;
218 num_bytes = buf_user_count - async->buf_read_count;
221 comedi_buf_read_alloc(async, num_bytes);
222 comedi_buf_read_free(async, num_bytes);
227 int comedi_mark_buffer_read(comedi_t * d, unsigned int subdevice,
228 unsigned int num_bytes)
230 comedi_device *dev = (comedi_device *) d;
231 comedi_subdevice *s = dev->subdevices + subdevice;
234 if (subdevice >= dev->n_subdevices)
240 comedi_buf_read_alloc(async, num_bytes);
241 comedi_buf_read_free(async, num_bytes);
246 int comedi_mark_buffer_written(comedi_t * d, unsigned int subdevice,
247 unsigned int num_bytes)
249 comedi_device *dev = (comedi_device *) d;
250 comedi_subdevice *s = dev->subdevices + subdevice;
254 if (subdevice >= dev->n_subdevices)
259 bytes_written = comedi_buf_write_alloc(async, num_bytes);
260 comedi_buf_write_free(async, bytes_written);
261 if (bytes_written != num_bytes)
266 int comedi_get_buffer_size(comedi_t * d, unsigned int subdev)
268 comedi_device *dev = (comedi_device *) d;
269 comedi_subdevice *s = dev->subdevices + subdev;
272 if (subdev >= dev->n_subdevices)
278 return async->prealloc_bufsz;
281 int comedi_get_buffer_offset(comedi_t * d, unsigned int subdevice)
283 comedi_device *dev = (comedi_device *) d;
284 comedi_subdevice *s = dev->subdevices + subdevice;
287 if (subdevice >= dev->n_subdevices)
293 return async->buf_read_ptr;