5 COMEDILIB - Linux Control and Measurement Device Interface Library
6 Copyright (C) 1997-2001 David A. Schleef <ds@schleef.org>
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation, version 2.1
13 This library 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 GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public
19 License along with this library; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
27 #include <sys/types.h>
34 #include "libinternal.h"
37 EXPORT_ALIAS_DEFAULT(_comedi_dio_config,comedi_dio_config,0.7.18);
38 int _comedi_dio_config(comedi_t *it,unsigned int subdev,unsigned int chan,unsigned int io)
42 if(!valid_chan(it,subdev,chan))
45 s=it->subdevices+subdev;
46 if(s->type!=COMEDI_SUBD_DIO)
49 if(io!=COMEDI_INPUT && io!=COMEDI_OUTPUT)
52 if(it->has_insnlist_ioctl){
56 memset(&insn,0,sizeof(insn));
57 insn.insn = INSN_CONFIG;
61 insn.chanspec = CR_PACK(chan,0,0);
64 return comedi_do_insn(it,&insn);
70 memset(&trig,0,sizeof(trig));
71 trig.flags=TRIG_CONFIG|TRIG_WRITE;
78 return comedi_trigger(it,&trig);
82 EXPORT_ALIAS_DEFAULT(_comedi_dio_read,comedi_dio_read,0.7.18);
83 int _comedi_dio_read(comedi_t *it,unsigned int subdev,unsigned int chan,
89 if(!valid_chan(it,subdev,chan))
92 s = it->subdevices+subdev;
93 if(s->type!=COMEDI_SUBD_DIO &&
94 s->type!=COMEDI_SUBD_DO &&
95 s->type!=COMEDI_SUBD_DI)
98 if(it->has_insnlist_ioctl){
102 memset(&insn,0,sizeof(insn));
103 insn.insn = INSN_READ;
106 insn.subdev = subdev;
107 insn.chanspec = CR_PACK(chan,0,0);
109 ret = comedi_do_insn(it,&insn);
118 memset(&trig,0,sizeof(trig));
125 ret=comedi_trigger(it,&trig);
127 if(ret>=0 && val)*val=data;
133 EXPORT_ALIAS_DEFAULT(_comedi_dio_write,comedi_dio_write,0.7.18);
134 int _comedi_dio_write(comedi_t *it,unsigned int subdev,unsigned int chan,
139 if(!valid_chan(it,subdev,chan))
142 s = it->subdevices+subdev;
143 if(s->type!=COMEDI_SUBD_DIO &&
144 s->type!=COMEDI_SUBD_DO)
147 if(it->has_insnlist_ioctl){
151 memset(&insn,0,sizeof(insn));
152 insn.insn = INSN_WRITE;
155 insn.subdev = subdev;
156 insn.chanspec = CR_PACK(chan,0,0);
160 return comedi_do_insn(it,&insn);
167 memset(&trig,0,sizeof(trig));
170 trig.flags=TRIG_WRITE;
175 return comedi_trigger(it,&trig);
179 EXPORT_ALIAS_DEFAULT(_comedi_dio_bitfield,comedi_dio_bitfield,0.7.18);
180 int _comedi_dio_bitfield(comedi_t *it,unsigned int subdev,unsigned int mask,unsigned int *bits)
186 if(!valid_subd(it,subdev))
189 s=it->subdevices+subdev;
191 if(s->type!=COMEDI_SUBD_DIO && s->type!=COMEDI_SUBD_DO &&
192 s->type!=COMEDI_SUBD_DI)
195 if(s->has_insn_bits){
199 memset(&insn,0,sizeof(insn));
201 insn.insn = INSN_BITS;
204 insn.subdev = subdev;
209 ret = comedi_do_insn(it,&insn);
217 unsigned int i,n_chan;
219 n_chan=comedi_get_n_channels(it,subdev);
220 if(n_chan>32)n_chan=32;
221 for(i=0,m=1;i<n_chan;i++,m<<=1){
224 ret=comedi_dio_write(it,subdev,i,bit);
226 ret=comedi_dio_read(it,subdev,i,&bit);