• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2     kcomedilib/get.c
3     a comedlib interface for kernel modules
4 
5     COMEDI - Linux Control and Measurement Device Interface
6     Copyright (C) 1997-2000 David A. Schleef <ds@schleef.org>
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 #define __NO_VERSION__
25 #include "../comedi.h"
26 #include "../comedilib.h"
27 #include "../comedidev.h"
28 
comedi_get_n_subdevices(comedi_t * d)29 int comedi_get_n_subdevices(comedi_t * d)
30 {
31 	comedi_device *dev = (comedi_device *) d;
32 
33 	return dev->n_subdevices;
34 }
35 
comedi_get_version_code(comedi_t * d)36 int comedi_get_version_code(comedi_t * d)
37 {
38 	return COMEDI_VERSION_CODE;
39 }
40 
comedi_get_driver_name(comedi_t * d)41 const char *comedi_get_driver_name(comedi_t * d)
42 {
43 	comedi_device *dev = (comedi_device *) d;
44 
45 	return dev->driver->driver_name;
46 }
47 
comedi_get_board_name(comedi_t * d)48 const char *comedi_get_board_name(comedi_t * d)
49 {
50 	comedi_device *dev = (comedi_device *) d;
51 
52 	return dev->board_name;
53 }
54 
comedi_get_subdevice_type(comedi_t * d,unsigned int subdevice)55 int comedi_get_subdevice_type(comedi_t * d, unsigned int subdevice)
56 {
57 	comedi_device *dev = (comedi_device *) d;
58 	comedi_subdevice *s = dev->subdevices + subdevice;
59 
60 	return s->type;
61 }
62 
comedi_get_subdevice_flags(comedi_t * d,unsigned int subdevice)63 unsigned int comedi_get_subdevice_flags(comedi_t * d, unsigned int subdevice)
64 {
65 	comedi_device *dev = (comedi_device *) d;
66 	comedi_subdevice *s = dev->subdevices + subdevice;
67 
68 	return s->subdev_flags;
69 }
70 
comedi_find_subdevice_by_type(comedi_t * d,int type,unsigned int subd)71 int comedi_find_subdevice_by_type(comedi_t * d, int type, unsigned int subd)
72 {
73 	comedi_device *dev = (comedi_device *) d;
74 
75 	if (subd > dev->n_subdevices)
76 		return -ENODEV;
77 
78 	for (; subd < dev->n_subdevices; subd++) {
79 		if (dev->subdevices[subd].type == type)
80 			return subd;
81 	}
82 	return -1;
83 }
84 
comedi_get_n_channels(comedi_t * d,unsigned int subdevice)85 int comedi_get_n_channels(comedi_t * d, unsigned int subdevice)
86 {
87 	comedi_device *dev = (comedi_device *) d;
88 	comedi_subdevice *s = dev->subdevices + subdevice;
89 
90 	return s->n_chan;
91 }
92 
comedi_get_len_chanlist(comedi_t * d,unsigned int subdevice)93 int comedi_get_len_chanlist(comedi_t * d, unsigned int subdevice)
94 {
95 	comedi_device *dev = (comedi_device *) d;
96 	comedi_subdevice *s = dev->subdevices + subdevice;
97 
98 	return s->len_chanlist;
99 }
100 
comedi_get_maxdata(comedi_t * d,unsigned int subdevice,unsigned int chan)101 lsampl_t comedi_get_maxdata(comedi_t * d, unsigned int subdevice,
102 	unsigned int chan)
103 {
104 	comedi_device *dev = (comedi_device *) d;
105 	comedi_subdevice *s = dev->subdevices + subdevice;
106 
107 	if (s->maxdata_list)
108 		return s->maxdata_list[chan];
109 
110 	return s->maxdata;
111 }
112 
113 #ifdef KCOMEDILIB_DEPRECATED
comedi_get_rangetype(comedi_t * d,unsigned int subdevice,unsigned int chan)114 int comedi_get_rangetype(comedi_t * d, unsigned int subdevice,
115 	unsigned int chan)
116 {
117 	comedi_device *dev = (comedi_device *) d;
118 	comedi_subdevice *s = dev->subdevices + subdevice;
119 	int ret;
120 
121 	if (s->range_table_list) {
122 		ret = s->range_table_list[chan]->length;
123 	} else {
124 		ret = s->range_table->length;
125 	}
126 
127 	ret = ret | (dev->minor << 28) | (subdevice << 24) | (chan << 16);
128 
129 	return ret;
130 }
131 #endif
132 
comedi_get_n_ranges(comedi_t * d,unsigned int subdevice,unsigned int chan)133 int comedi_get_n_ranges(comedi_t * d, unsigned int subdevice, unsigned int chan)
134 {
135 	comedi_device *dev = (comedi_device *) d;
136 	comedi_subdevice *s = dev->subdevices + subdevice;
137 	int ret;
138 
139 	if (s->range_table_list) {
140 		ret = s->range_table_list[chan]->length;
141 	} else {
142 		ret = s->range_table->length;
143 	}
144 
145 	return ret;
146 }
147 
148 /*
149  * ALPHA (non-portable)
150 */
comedi_get_krange(comedi_t * d,unsigned int subdevice,unsigned int chan,unsigned int range,comedi_krange * krange)151 int comedi_get_krange(comedi_t * d, unsigned int subdevice, unsigned int chan,
152 	unsigned int range, comedi_krange * krange)
153 {
154 	comedi_device *dev = (comedi_device *) d;
155 	comedi_subdevice *s = dev->subdevices + subdevice;
156 	const comedi_lrange *lr;
157 
158 	if (s->range_table_list) {
159 		lr = s->range_table_list[chan];
160 	} else {
161 		lr = s->range_table;
162 	}
163 	if (range >= lr->length) {
164 		return -EINVAL;
165 	}
166 	memcpy(krange, lr->range + range, sizeof(comedi_krange));
167 
168 	return 0;
169 }
170 
171 /*
172  * ALPHA (may be renamed)
173 */
comedi_get_buf_head_pos(comedi_t * d,unsigned int subdevice)174 unsigned int comedi_get_buf_head_pos(comedi_t * d, unsigned int subdevice)
175 {
176 	comedi_device *dev = (comedi_device *) d;
177 	comedi_subdevice *s = dev->subdevices + subdevice;
178 	comedi_async *async;
179 
180 	async = s->async;
181 	if (async == NULL)
182 		return 0;
183 
184 	return async->buf_write_count;
185 }
186 
comedi_get_buffer_contents(comedi_t * d,unsigned int subdevice)187 int comedi_get_buffer_contents(comedi_t * d, unsigned int subdevice)
188 {
189 	comedi_device *dev = (comedi_device *) d;
190 	comedi_subdevice *s = dev->subdevices + subdevice;
191 	comedi_async *async;
192 	unsigned int num_bytes;
193 
194 	if (subdevice >= dev->n_subdevices)
195 		return -1;
196 	async = s->async;
197 	if (async == NULL)
198 		return 0;
199 	num_bytes = comedi_buf_read_n_available(s->async);
200 	return num_bytes;
201 }
202 
203 /*
204  * ALPHA
205 */
comedi_set_user_int_count(comedi_t * d,unsigned int subdevice,unsigned int buf_user_count)206 int comedi_set_user_int_count(comedi_t * d, unsigned int subdevice,
207 	unsigned int buf_user_count)
208 {
209 	comedi_device *dev = (comedi_device *) d;
210 	comedi_subdevice *s = dev->subdevices + subdevice;
211 	comedi_async *async;
212 	int num_bytes;
213 
214 	async = s->async;
215 	if (async == NULL)
216 		return -1;
217 
218 	num_bytes = buf_user_count - async->buf_read_count;
219 	if (num_bytes < 0)
220 		return -1;
221 	comedi_buf_read_alloc(async, num_bytes);
222 	comedi_buf_read_free(async, num_bytes);
223 
224 	return 0;
225 }
226 
comedi_mark_buffer_read(comedi_t * d,unsigned int subdevice,unsigned int num_bytes)227 int comedi_mark_buffer_read(comedi_t * d, unsigned int subdevice,
228 	unsigned int num_bytes)
229 {
230 	comedi_device *dev = (comedi_device *) d;
231 	comedi_subdevice *s = dev->subdevices + subdevice;
232 	comedi_async *async;
233 
234 	if (subdevice >= dev->n_subdevices)
235 		return -1;
236 	async = s->async;
237 	if (async == NULL)
238 		return -1;
239 
240 	comedi_buf_read_alloc(async, num_bytes);
241 	comedi_buf_read_free(async, num_bytes);
242 
243 	return 0;
244 }
245 
comedi_mark_buffer_written(comedi_t * d,unsigned int subdevice,unsigned int num_bytes)246 int comedi_mark_buffer_written(comedi_t * d, unsigned int subdevice,
247 	unsigned int num_bytes)
248 {
249 	comedi_device *dev = (comedi_device *) d;
250 	comedi_subdevice *s = dev->subdevices + subdevice;
251 	comedi_async *async;
252 	int bytes_written;
253 
254 	if (subdevice >= dev->n_subdevices)
255 		return -1;
256 	async = s->async;
257 	if (async == NULL)
258 		return -1;
259 	bytes_written = comedi_buf_write_alloc(async, num_bytes);
260 	comedi_buf_write_free(async, bytes_written);
261 	if (bytes_written != num_bytes)
262 		return -1;
263 	return 0;
264 }
265 
comedi_get_buffer_size(comedi_t * d,unsigned int subdev)266 int comedi_get_buffer_size(comedi_t * d, unsigned int subdev)
267 {
268 	comedi_device *dev = (comedi_device *) d;
269 	comedi_subdevice *s = dev->subdevices + subdev;
270 	comedi_async *async;
271 
272 	if (subdev >= dev->n_subdevices)
273 		return -1;
274 	async = s->async;
275 	if (async == NULL)
276 		return 0;
277 
278 	return async->prealloc_bufsz;
279 }
280 
comedi_get_buffer_offset(comedi_t * d,unsigned int subdevice)281 int comedi_get_buffer_offset(comedi_t * d, unsigned int subdevice)
282 {
283 	comedi_device *dev = (comedi_device *) d;
284 	comedi_subdevice *s = dev->subdevices + subdevice;
285 	comedi_async *async;
286 
287 	if (subdevice >= dev->n_subdevices)
288 		return -1;
289 	async = s->async;
290 	if (async == NULL)
291 		return 0;
292 
293 	return async->buf_read_ptr;
294 }
295