int comedi_command(comedi_t *it,comedi_cmd *t)
{
-#ifdef HAVE_COMEDI_CMD
- if(!it || !t)
- return -1;
+ return ioctl(it->fd,COMEDI_CMD,t);
+}
- return ioctl_cmd(it->fd,t);
-#else
- return -1;
-#endif
+int comedi_command_test(comedi_t *it,comedi_cmd *t)
+{
+ return ioctl(it->fd,COMEDI_CMDTEST,t);
}
+int comedi_do_insnlist(comedi_t *it,comedi_insnlist *il)
+{
+ return ioctl(it->fd,COMEDI_INSNLIST,il);
+}
+int comedi_do_insn(comedi_t *it,comedi_insn *insn)
+{
+ comedi_insnlist il;
+
+ il.insns = insn;
+ il.n_insns = 1;
+
+ return comedi_do_insnlist(it,&il);
+}
+
+int comedi_lock(comedi_t *it,unsigned int subdevice)
+{
+ return ioctl(it->fd,COMEDI_LOCK,subdevice);
+}
+
+int comedi_unlock(comedi_t *it,unsigned int subdevice)
+{
+ return ioctl(it->fd,COMEDI_UNLOCK,subdevice);
+}
int comedi_data_write(comedi_t *it,unsigned int subdev,unsigned int chan,unsigned int range,
unsigned int aref,lsampl_t data)
{
- comedi_trig cmd={
- mode: 0,
- flags: TRIG_WRITE,
- n_chan: 1,
- n: 1,
- trigsrc: 0,
- trigvar: 0,
- trigvar1: 0,
- };
- sampl_t sdata=data;
+ subdevice *s;
if(!valid_chan(it,subdev,chan))
return -1;
+
+ s=it->subdevices+subdev;
- chan=CR_PACK(chan,range,aref);
+ if(s->has_insn){
+ comedi_insn insn;
- cmd.subdev=subdev;
- if(it->subdevices[subdev].subd_flags & SDF_LSAMPL){
- cmd.data=(sampl_t *)(&data);
+ memset(&insn,0,sizeof(insn));
+
+ insn.insn = INSN_WRITE;
+ insn.n = 1;
+ insn.data = &data;
+ insn.subdev = subdev;
+ insn.chanspec = CR_PACK(chan,range,aref);
+
+ return comedi_do_insn(it,&insn);
}else{
- cmd.data=&sdata;
+ comedi_trig cmd={
+ mode: 0,
+ flags: TRIG_WRITE,
+ n_chan: 1,
+ n: 1,
+ trigsrc: 0,
+ trigvar: 0,
+ trigvar1: 0,
+ };
+ sampl_t sdata=data;
+
+ chan=CR_PACK(chan,range,aref);
+
+ cmd.subdev=subdev;
+ if(it->subdevices[subdev].subd_flags & SDF_LSAMPL){
+ cmd.data=(sampl_t *)(&data);
+ }else{
+ cmd.data=&sdata;
+ }
+ cmd.chanlist=&chan;
+
+ return ioctl_trigger(it->fd,&cmd);
}
- cmd.chanlist=&chan;
-
- return ioctl_trigger(it->fd,&cmd);
}
int comedi_data_read(comedi_t *it,unsigned int subdev,unsigned int chan,unsigned int range,
unsigned int aref,lsampl_t *data)
{
- comedi_trig cmd={
- mode: 0,
- flags: 0,
- n_chan: 1,
- n: 1,
- trigsrc: 0,
- trigvar: 0,
- trigvar1: 0,
- };
- int ret;
- sampl_t sdata;
+ subdevice *s;
if(!valid_chan(it,subdev,chan))
return -1;
-
- chan=CR_PACK(chan,range,aref);
-
- cmd.subdev=subdev;
- cmd.chanlist=&chan;
- if(it->subdevices[subdev].subd_flags & SDF_LSAMPL){
- cmd.data=(sampl_t *)data;
+
+ s=it->subdevices+subdev;
+
+ if(s->has_insn){
+ comedi_insn insn;
+
+ memset(&insn,0,sizeof(insn));
+
+ insn.insn = INSN_READ;
+ insn.n = 1;
+ insn.data = data;
+ insn.subdev = subdev;
+ insn.chanspec = CR_PACK(chan,range,aref);
+
+ return comedi_do_insn(it,&insn);
}else{
- cmd.data=&sdata;
- }
+ comedi_trig cmd={
+ mode: 0,
+ flags: 0,
+ n_chan: 1,
+ n: 1,
+ trigsrc: 0,
+ trigvar: 0,
+ trigvar1: 0,
+ };
+ int ret;
+ sampl_t sdata;
+
+ chan=CR_PACK(chan,range,aref);
+
+ cmd.subdev=subdev;
+ cmd.chanlist=&chan;
+ if(s->subd_flags & SDF_LSAMPL){
+ cmd.data=(sampl_t *)data;
+ }else{
+ cmd.data=&sdata;
+ }
+
+ ret=ioctl_trigger(it->fd,&cmd);
+ if(ret<0)
+ return ret;
- ret=ioctl_trigger(it->fd,&cmd);
- if(ret<0)
- return ret;
+ if(!(s->subd_flags & SDF_LSAMPL)){
+ *data=sdata;
+ }
- if(!(it->subdevices[subdev].subd_flags & SDF_LSAMPL)){
- *data=sdata;
+ return 0;
}
-
- return 0;
}
#if 1
int comedi_dio_bitfield(comedi_t *it,unsigned int subdev,unsigned int mask,unsigned int *bits)
{
int ret;
- unsigned int i,n_chan;
unsigned int m,bit;
subdevice *s;
if(!valid_subd(it,subdev))
return -1;
- if(it->subdevices[subdev].type!=COMEDI_SUBD_DIO &&
- it->subdevices[subdev].type!=COMEDI_SUBD_DO &&
- it->subdevices[subdev].type!=COMEDI_SUBD_DI)
- return -1;
-
s=it->subdevices+subdev;
- n_chan=comedi_get_n_channels(it,subdev);
- if(n_chan>32)n_chan=32;
- for(i=0,m=1;i<n_chan;i++,m<<=1){
- if(mask&m){
- bit=(*bits&m)?1:0;
- ret=comedi_dio_write(it,subdev,i,bit);
- }else{
- ret=comedi_dio_read(it,subdev,i,&bit);
- if(bit) *bits|=m;
- else (*bits)&=~m;
- }
+ if(s->type!=COMEDI_SUBD_DIO && s->type!=COMEDI_SUBD_DO &&
+ s->type!=COMEDI_SUBD_DI)
+ return -1;
+
+ if(s->has_insn_bits){
+ comedi_insn insn;
+ comedi_insnlist il;
+ lsampl_t data[2];
+
+ memset(&insn,0,sizeof(insn));
+ il.n_insns = 1;
+ il.insns = &insn;
+
+ insn.insn = INSN_BITS;
+ insn.n = 2;
+ insn.data = data;
+ insn.subdev = subdev;
+
+ data[0]=mask;
+ data[1]=*bits;
+
+ ret = ioctl(it->fd,COMEDI_INSN,&il);
+
if(ret<0)return ret;
- }
- return (int)n_chan;
+ *bits = data[1];
+
+ return 0;
+ }else{
+ unsigned int i,n_chan;
+
+ n_chan=comedi_get_n_channels(it,subdev);
+ if(n_chan>32)n_chan=32;
+ for(i=0,m=1;i<n_chan;i++,m<<=1){
+ if(mask&m){
+ bit=(*bits&m)?1:0;
+ ret=comedi_dio_write(it,subdev,i,bit);
+ }else{
+ ret=comedi_dio_read(it,subdev,i,&bit);
+ if(bit) *bits|=m;
+ else (*bits)&=~m;
+ }
+ if(ret<0)return ret;
+ }
+ return (int)n_chan;
+ }
}
static int do_test_for_cmd(comedi_t *dev,unsigned int subdevice);
static int do_test_for_insn(comedi_t *dev,unsigned int subdevice);
+static int do_test_for_insn_bits(comedi_t *dev,unsigned int subdevice);
int get_subdevices(comedi_t *it)
r[i].has_cmd = do_test_for_cmd(it,i);
r[i].has_insn = do_test_for_insn(it,i);
+ if(r[i].has_insn){
+ r[i].has_insn_bits = do_test_for_insn_bits(it,i);
+ }else{
+ r[i].has_insn_bits = 0;
+ }
}
free(s);
insn.insn = INSN_GTOD;
insn.n = 2;
- insn.data = (void *)&data;
+ insn.data = data;
insn.subdev = subdevice;
- ret = ioctl(dev->fd,COMEDI_INSN,&il);
+ ret = comedi_do_insnlist(dev,&il);
if(ret<0 && errno==EIO){
return 0;
return 1;
}
+static int do_test_for_insn_bits(comedi_t *dev,unsigned int subdevice)
+{
+ comedi_insn insn;
+ comedi_insnlist il;
+ lsampl_t data[2];
+ int ret;
+
+ memset(&insn,0,sizeof(insn));
+
+ il.n_insns = 1;
+ il.insns = &insn;
+
+ insn.insn = INSN_BITS;
+ insn.n = 2;
+ insn.data = data;
+ insn.subdev = subdevice;
+
+ data[0]=0;
+ data[1]=0;
+
+ ret = comedi_do_insnlist(dev,&il);
+
+ if(ret<0 && errno==EINVAL){
+ return 0;
+ }
+ if(ret<0){
+ fprintf(stderr,"BUG in do_test_for_insn_bits()\n");
+ return 0;
+ }
+ return 1;
+}
+
+
return it->subdevices[subdevice].maxdata;
}
+int comedi_maxdata_is_chan_specific(comedi_t *it,unsigned int subdevice)
+{
+ if(it->subdevices[subdevice].maxdata_list)
+ return 1;
+ return 0;
+}
+
int comedi_get_rangetype(comedi_t *it,unsigned int subdevice,unsigned int chan)
{
if(!valid_chan(it,subdevice,chan))
return ioctl(fd,COMEDI_TRIG,it);
}
-#ifdef HAVE_COMEDI_CMD
-int ioctl_cmd(int fd,comedi_cmd *it)
-{
- return ioctl(fd,COMEDI_CMD,it);
-}
-#endif
-
-#ifdef HAVE_COMEDI_INSN
-int ioctl_insnlist(int fd,comedi_insn *it)
-{
- return ioctl(fd,COMEDI_INSNLIST,it);
-}
-#endif
-
-int ioctl_lock(int fd,int subdevice)
-{
- return ioctl(fd,COMEDI_LOCK,subdevice);
-}
-
-int ioctl_unlock(int fd,int subdevice)
-{
- return ioctl(fd,COMEDI_UNLOCK,subdevice);
-}
-
-int ioctl_cancel(int fd,int subdevice)
-{
- return ioctl(fd,COMEDI_CANCEL,subdevice);
-}
-
int ioctl_rangeinfo(int fd,int range_type,comedi_krange *range_ptr)
{
comedi_rangeinfo it;
unsigned int has_cmd;
unsigned int has_insn;
+ unsigned int has_insn_bits;
};
int ioctl_chaninfo(int fd,unsigned int subdev,lsampl_t *maxdata_list,
unsigned int *flaglist,unsigned int *rangelist);
int ioctl_trigger(int fd,comedi_trig *it);
-int ioctl_cmd(int fd,comedi_cmd *it);
-int ioctl_lock(int fd,int subdevice);
-int ioctl_unlock(int fd,int subdevice);
-int ioctl_cancel(int fd,int subdevice);
int ioctl_rangeinfo(int fd,int range_type,comedi_krange *range_ptr);
/* filler routines */
return RANGE_LENGTH(range_type);
}
+int comedi_range_is_chan_specific(comedi_t *it,unsigned int subd)
+{
+ return (it->subdevices[subd].subd_flags&SDF_RANGETYPE)?1:0;
+}
+