lots of changes with commands and instructions
authorDavid Schleef <ds@schleef.org>
Sun, 3 Sep 2000 02:22:28 +0000 (02:22 +0000)
committerDavid Schleef <ds@schleef.org>
Sun, 3 Sep 2000 02:22:28 +0000 (02:22 +0000)
lib/comedi.c
lib/data.c
lib/dio.c
lib/filler.c
lib/get.c
lib/ioctl.c
lib/libinternal.h
lib/range.c

index 009b8606bdaff2d5fdb2b1337295c0eb00262a3c..d1553c7a0a5a78446e3d6fe39f118b40fa90bc59 100644 (file)
@@ -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);
+}
 
index aa4922ee39b150b88097c540646a9384caec4360..272a201fc6936690d969293af1391a856afa8564 100644 (file)
 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
index ac2581c73d4d052e039af03b73e78d15b2144bdf..bccd3d5c0ebc274797bf5f7da0e87ee0453e5b2b 100644 (file)
--- 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;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;
+       }
 }
 
index 5c344160bfc0211d46caff2efae9e7b47236eef6..08ee608a11e6e3f0b785d6aaa537ee532deb8b15 100644 (file)
@@ -40,6 +40,7 @@
 
 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)
@@ -96,6 +97,11 @@ 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);
@@ -171,10 +177,10 @@ static int do_test_for_insn(comedi_t *dev,unsigned int subdevice)
 
        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;
@@ -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;
+}
+
+
 
index 0b9fbe397a0c3bdc61e79664c860bc151eaa1afb..da061a18987dfc3b710fb16ab30cb6883e4b27d4 100644 (file)
--- 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))
index a9fa51376b7fde093c997e110f069c3e7e6bcb3a..3bc58ee6d418a056aed74eb2d5f8a71ad91cb12b 100644 (file)
@@ -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;
index 53381a53de311b300d7b94d2bf9c079acbfe82b3..7aac704f53428a7d7b662fd4d20f64f0a62defab 100644 (file)
@@ -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 */
index 3452761c3f4951034625d2ae7dcb2cbe276c94d2..c0baf51e9177b05a66d896b6a972b78fae043988 100644 (file)
@@ -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;
+}
+