From c9f298466fc774cdf5daf23e0e68872e09c9852e Mon Sep 17 00:00:00 2001 From: David Schleef Date: Sun, 3 Sep 2000 02:22:28 +0000 Subject: [PATCH] lots of changes with commands and instructions --- lib/comedi.c | 35 ++++++++++--- lib/data.c | 126 +++++++++++++++++++++++++++++----------------- lib/dio.c | 63 ++++++++++++++++------- lib/filler.c | 43 +++++++++++++++- lib/get.c | 7 +++ lib/ioctl.c | 29 ----------- lib/libinternal.h | 5 +- lib/range.c | 5 ++ 8 files changed, 207 insertions(+), 106 deletions(-) diff --git a/lib/comedi.c b/lib/comedi.c index 009b860..d1553c7 100644 --- a/lib/comedi.c +++ b/lib/comedi.c @@ -128,15 +128,36 @@ int comedi_trigger(comedi_t *it,comedi_trig *t) 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); +} diff --git a/lib/data.c b/lib/data.c index aa4922e..272a201 100644 --- a/lib/data.c +++ b/lib/data.c @@ -40,71 +40,107 @@ 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 diff --git a/lib/dio.c b/lib/dio.c index ac2581c..bccd3d5 100644 --- a/lib/dio.c +++ b/lib/dio.c @@ -119,34 +119,59 @@ int comedi_dio_write(comedi_t *it,unsigned int subdev,unsigned int chan, 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;itype!=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;ifd,COMEDI_INSN,&il); + ret = comedi_do_insnlist(dev,&il); if(ret<0 && errno==EIO){ return 0; @@ -186,4 +192,37 @@ static int do_test_for_insn(comedi_t *dev,unsigned int subdevice) 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; +} + + diff --git a/lib/get.c b/lib/get.c index 0b9fbe3..da061a1 100644 --- a/lib/get.c +++ b/lib/get.c @@ -111,6 +111,13 @@ lsampl_t comedi_get_maxdata(comedi_t *it,unsigned int subdevice,unsigned int cha 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)) diff --git a/lib/ioctl.c b/lib/ioctl.c index a9fa513..3bc58ee 100644 --- a/lib/ioctl.c +++ b/lib/ioctl.c @@ -65,35 +65,6 @@ int ioctl_trigger(int fd,comedi_trig *it) 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; diff --git a/lib/libinternal.h b/lib/libinternal.h index 53381a5..7aac704 100644 --- a/lib/libinternal.h +++ b/lib/libinternal.h @@ -87,6 +87,7 @@ struct subdevice_struct{ unsigned int has_cmd; unsigned int has_insn; + unsigned int has_insn_bits; }; @@ -98,10 +99,6 @@ int ioctl_subdinfo(int fd,comedi_subdinfo *it); 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 */ diff --git a/lib/range.c b/lib/range.c index 3452761..c0baf51 100644 --- a/lib/range.c +++ b/lib/range.c @@ -129,3 +129,8 @@ int comedi_get_n_ranges(comedi_t *it,unsigned int subd,unsigned int chan) 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; +} + -- 2.26.2