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);
45 int get_subdevices(comedi_t *it)
52 s=malloc(sizeof(comedi_subdinfo)*it->n_subdevices);
53 ret=ioctl_subdinfo(it->fd,s);
56 r=it->subdevices=realloc(it->subdevices,
57 sizeof(subdevice)*it->n_subdevices);
59 memset(r,0,sizeof(subdevice)*it->n_subdevices);
61 for(i=0;i<it->n_subdevices;i++){
62 r[i].type = s[i].type;
63 if(r[i].type==COMEDI_SUBD_UNUSED)continue;
64 r[i].n_chan = s[i].n_chan;
65 r[i].subd_flags = s[i].subd_flags;
66 r[i].timer_type = s[i].timer_type;
67 r[i].len_chanlist = s[i].len_chanlist;
68 r[i].maxdata = s[i].maxdata;
69 r[i].flags = s[i].flags;
70 r[i].range_type = s[i].range_type;
72 if(r[i].subd_flags&SDF_FLAGS){
73 r[i].flags_list=malloc(sizeof(*r[i].flags_list)*r[i].n_chan);
74 debug_ptr(r[i].flags_list);
76 if(r[i].subd_flags&SDF_MAXDATA){
77 r[i].maxdata_list=malloc(sizeof(*r[i].maxdata_list)*r[i].n_chan);
78 debug_ptr(r[i].maxdata_list);
80 if(r[i].subd_flags&SDF_RANGETYPE){
81 r[i].range_type_list=malloc(sizeof(*r[i].range_type_list)*r[i].n_chan);
82 debug_ptr(r[i].range_type_list);
84 ret=ioctl_chaninfo(it->fd,i,r[i].maxdata_list,r[i].flags_list,r[i].range_type_list);
87 if(r[i].subd_flags&SDF_RANGETYPE){
88 r[i].rangeinfo_list=malloc(sizeof(*r[i].rangeinfo_list)*r[i].n_chan);
89 debug_ptr(r[i].rangeinfo_list);
90 for(j=0;j<r[i].n_chan;j++){
91 r[i].rangeinfo_list[j]=get_rangeinfo(it->fd,r[i].range_type_list[j]);
94 r[i].rangeinfo=get_rangeinfo(it->fd,r[i].range_type);
97 r[i].has_cmd = do_test_for_cmd(it,i);
98 r[i].has_insn = do_test_for_insn(it,i);
106 comedi_range *get_rangeinfo(int fd,unsigned int range_type)
113 kr=malloc(sizeof(comedi_krange)*RANGE_LENGTH(range_type));
114 r=malloc(sizeof(comedi_range)*RANGE_LENGTH(range_type));
116 ret=ioctl_rangeinfo(fd,range_type,kr);
118 fprintf(stderr,"ioctl_rangeinfo(%d,0x%08x,%p)\n",fd,range_type,kr);
121 for(i=0;i<RANGE_LENGTH(range_type);i++){
122 r[i].min=kr[i].min*1e-6;
123 r[i].max=kr[i].max*1e-6;
124 r[i].unit=RF_UNIT(kr[i].flags);
132 /* some command testing */
134 static int do_test_for_cmd(comedi_t *dev,unsigned int subdevice)
139 memset(&it,0,sizeof(it));
142 it.start_src = TRIG_ANY;
143 it.scan_begin_src = TRIG_ANY;
144 it.convert_src = TRIG_ANY;
145 it.scan_end_src = TRIG_ANY;
146 it.stop_src = TRIG_ANY;
148 ret = ioctl(dev->fd,COMEDI_CMDTEST,&it);
150 if(ret<0 && errno==EIO){
154 fprintf(stderr,"BUG in do_test_for_cmd()\n");
160 static int do_test_for_insn(comedi_t *dev,unsigned int subdevice)
167 memset(&insn,0,sizeof(insn));
172 insn.insn = INSN_GTOD;
174 insn.data = (void *)&data;
175 insn.subdev = subdevice;
177 ret = ioctl(dev->fd,COMEDI_INSN,&il);
179 if(ret<0 && errno==EIO){
183 fprintf(stderr,"BUG in do_test_for_insn()\n");