3 comedi library routines
5 COMEDI - Linux Control and Measurement Device Interface
6 Copyright (C) 1997-8 David A. Schleef <ds@stm.lbl.gov>
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.
27 #include <sys/types.h>
31 #include <sys/ioctl.h>
36 #include <libinternal.h>
39 /* these functions download information from the comedi module. */
41 static int do_test_for_cmd(comedi_t *dev,unsigned int subdevice);
42 static int do_test_for_insn(comedi_t *dev,unsigned int subdevice);
43 static int do_test_for_insn_bits(comedi_t *dev,unsigned int subdevice);
46 int get_subdevices(comedi_t *it)
53 s=malloc(sizeof(comedi_subdinfo)*it->n_subdevices);
54 ret=ioctl_subdinfo(it->fd,s);
57 r=it->subdevices=realloc(it->subdevices,
58 sizeof(subdevice)*it->n_subdevices);
60 memset(r,0,sizeof(subdevice)*it->n_subdevices);
62 for(i=0;i<it->n_subdevices;i++){
63 r[i].type = s[i].type;
64 if(r[i].type==COMEDI_SUBD_UNUSED)continue;
65 r[i].n_chan = s[i].n_chan;
66 r[i].subd_flags = s[i].subd_flags;
67 r[i].timer_type = s[i].timer_type;
68 r[i].len_chanlist = s[i].len_chanlist;
69 r[i].maxdata = s[i].maxdata;
70 r[i].flags = s[i].flags;
71 r[i].range_type = s[i].range_type;
73 if(r[i].subd_flags&SDF_FLAGS){
74 r[i].flags_list=malloc(sizeof(*r[i].flags_list)*r[i].n_chan);
75 debug_ptr(r[i].flags_list);
77 if(r[i].subd_flags&SDF_MAXDATA){
78 r[i].maxdata_list=malloc(sizeof(*r[i].maxdata_list)*r[i].n_chan);
79 debug_ptr(r[i].maxdata_list);
81 if(r[i].subd_flags&SDF_RANGETYPE){
82 r[i].range_type_list=malloc(sizeof(*r[i].range_type_list)*r[i].n_chan);
83 debug_ptr(r[i].range_type_list);
85 ret=ioctl_chaninfo(it->fd,i,r[i].maxdata_list,r[i].flags_list,r[i].range_type_list);
88 if(r[i].subd_flags&SDF_RANGETYPE){
89 r[i].rangeinfo_list=malloc(sizeof(*r[i].rangeinfo_list)*r[i].n_chan);
90 debug_ptr(r[i].rangeinfo_list);
91 for(j=0;j<r[i].n_chan;j++){
92 r[i].rangeinfo_list[j]=get_rangeinfo(it->fd,r[i].range_type_list[j]);
95 r[i].rangeinfo=get_rangeinfo(it->fd,r[i].range_type);
98 r[i].has_cmd = do_test_for_cmd(it,i);
99 r[i].has_insn = do_test_for_insn(it,i);
101 r[i].has_insn_bits = do_test_for_insn_bits(it,i);
103 r[i].has_insn_bits = 0;
112 comedi_range *get_rangeinfo(int fd,unsigned int range_type)
119 kr=malloc(sizeof(comedi_krange)*RANGE_LENGTH(range_type));
120 r=malloc(sizeof(comedi_range)*RANGE_LENGTH(range_type));
122 ret=ioctl_rangeinfo(fd,range_type,kr);
124 fprintf(stderr,"ioctl_rangeinfo(%d,0x%08x,%p)\n",fd,range_type,kr);
127 for(i=0;i<RANGE_LENGTH(range_type);i++){
128 r[i].min=kr[i].min*1e-6;
129 r[i].max=kr[i].max*1e-6;
130 r[i].unit=RF_UNIT(kr[i].flags);
138 /* some command testing */
140 static int do_test_for_cmd(comedi_t *dev,unsigned int subdevice)
145 memset(&it,0,sizeof(it));
148 it.start_src = TRIG_ANY;
149 it.scan_begin_src = TRIG_ANY;
150 it.convert_src = TRIG_ANY;
151 it.scan_end_src = TRIG_ANY;
152 it.stop_src = TRIG_ANY;
154 ret = ioctl(dev->fd,COMEDI_CMDTEST,&it);
156 if(ret<0 && errno==EIO){
160 fprintf(stderr,"BUG in do_test_for_cmd()\n");
166 static int do_test_for_insn(comedi_t *dev,unsigned int subdevice)
173 memset(&insn,0,sizeof(insn));
178 insn.insn = INSN_GTOD;
181 insn.subdev = subdevice;
183 ret = comedi_do_insnlist(dev,&il);
185 if(ret<0 && errno==EIO){
189 fprintf(stderr,"BUG in do_test_for_insn()\n");
195 static int do_test_for_insn_bits(comedi_t *dev,unsigned int subdevice)
202 memset(&insn,0,sizeof(insn));
207 insn.insn = INSN_BITS;
210 insn.subdev = subdevice;
215 ret = comedi_do_insnlist(dev,&il);
217 if(ret<0 && (errno==EINVAL || errno==EIO)){
221 fprintf(stderr,"BUG in do_test_for_insn_bits()\n");