Added insn ioctl probing.
Renamed previously misnamed insnlist probing.
Rewrote comedi_data_read_n()
int comedi_poll(comedi_t *it,unsigned int subdevice)
{
-#ifdef HAVE_COMEDI_POLL
return ioctl(it->fd,COMEDI_POLL,subdevice);
-#else
- return -1;
-#endif
}
int comedi_fileno(comedi_t *it)
int comedi_do_insn(comedi_t *it,comedi_insn *insn)
{
- comedi_insnlist il;
+ if(it->has_insn_ioctl){
+ return ioctl(it->fd,COMEDI_INSN,insn);
+ }else{
+ comedi_insnlist il;
+ int ret;
+
+ il.n_insns = 1;
+ il.insns = insn;
- il.n_insns = 1;
- il.insns = insn;
+ ret = ioctl(it->fd,COMEDI_INSNLIST,&il);
- return ioctl(it->fd,COMEDI_INSNLIST,&il);
+ if(ret<0)return ret;
+ return insn->n;
+ }
}
int comedi_lock(comedi_t *it,unsigned int subdevice)
s=it->subdevices+subdev;
- if(s->has_insn){
+ if(it->has_insnlist_ioctl){
comedi_insn insn;
memset(&insn,0,sizeof(insn));
}
+int comedi_data_read_n(comedi_t *it,unsigned int subdev,unsigned int chan,
+ unsigned int range, unsigned int aref,lsampl_t *data,
+ unsigned int n)
+{
+ subdevice *s;
+ comedi_insn insn;
+
+ if(!valid_chan(it,subdev,chan))
+ return -1;
+
+ s=it->subdevices+subdev;
+
+ if(it->has_insnlist_ioctl){
+
+ 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{
+ /* There's no need to be fast for a case that is
+ * obsolete. */
+ return comedi_data_read(it,subdev,chan,range,aref,data);
+ }
+}
+
int comedi_data_read(comedi_t *it,unsigned int subdev,unsigned int chan,unsigned int range,
unsigned int aref,lsampl_t *data)
{
s=it->subdevices+subdev;
- if(s->has_insn){
+ if(it->has_insnlist_ioctl){
comedi_insn insn;
memset(&insn,0,sizeof(insn));
}
}
-#if 1
-/*
- I don't like this function, which is why it is marked out.
- The problem is the sampl_t/lsampl_t fiasco, which is beginning
- to be a PITA.
- */
-int comedi_data_read_n(comedi_t *it,unsigned int subdev,unsigned int chan,unsigned int range,
- unsigned int aref,unsigned int n,lsampl_t *data)
-{
- comedi_trig cmd;
- unsigned int i;
- int ret;
-
- if(!valid_chan(it,subdev,chan))
- return -1;
-
- if(n==0)
- return 0;
-
- chan=CR_PACK(chan,range,aref);
-
- memset(&cmd,0,sizeof(cmd));
- cmd.mode=0;
- cmd.n_chan=1;
- cmd.subdev=subdev;
- cmd.chanlist=&chan;
-
- i=0;
- while(i<n){
- cmd.data=(void *)(data+i);
- cmd.n=n-i;
-
- ret=ioctl_trigger(it->fd,&cmd);
- if(ret<0)
- goto out;
-
- i+=ret;
- }
-out:
- if(i==0)return -1;
-
- return (int)i;
-}
-#endif
-
-
-
if(io!=COMEDI_INPUT && io!=COMEDI_OUTPUT)
return -1;
- if(s->has_insn){
+ if(it->has_insnlist_ioctl){
comedi_insn insn;
lsampl_t data;
s->type!=COMEDI_SUBD_DI)
return -1;
- if(s->has_insn){
+ if(it->has_insnlist_ioctl){
comedi_insn insn;
lsampl_t data;
s->type!=COMEDI_SUBD_DO)
return -1;
- if(s->has_insn){
+ if(it->has_insnlist_ioctl){
comedi_insn insn;
lsampl_t data;
/* these functions download information from the comedi module. */
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(comedi_t *dev);
+static int do_test_for_insnlist(comedi_t *dev);
static int do_test_for_insn_bits(comedi_t *dev,unsigned int subdevice);
debug_ptr(r);
memset(r,0,sizeof(subdevice)*it->n_subdevices);
+ it->has_insnlist_ioctl = do_test_for_insnlist(it);
+ it->has_insn_ioctl = do_test_for_insn(it);
for(i=0;i<it->n_subdevices;i++){
r[i].type = s[i].type;
if(r[i].type==COMEDI_SUBD_UNUSED)continue;
}
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){
+ if(it->has_insnlist_ioctl){
r[i].has_insn_bits = do_test_for_insn_bits(it,i);
}else{
r[i].has_insn_bits = 0;
return 1;
}
-static int do_test_for_insn(comedi_t *dev,unsigned int subdevice)
+static int do_test_for_insnlist(comedi_t *dev)
{
comedi_insn insn;
comedi_insnlist il;
insn.insn = INSN_GTOD;
insn.n = 2;
insn.data = data;
- insn.subdev = subdevice;
- ret = comedi_do_insnlist(dev,&il);
+ ret = ioctl(dev->fd,COMEDI_INSNLIST,&il);
- if(ret<0 && errno==EIO){
+ if(ret<0){
+ if(errno!=EIO){
+ fprintf(stderr,"BUG in do_test_for_insn()\n");
+ }
return 0;
}
-#if 0
+ return 1;
+}
+
+/* the COMEID_INSN ioctl was introduced in comedi-0.7.60 */
+static int do_test_for_insn(comedi_t *dev)
+{
+ 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_GTOD;
+ insn.n = 2;
+ insn.data = data;
+
+ ret = ioctl(dev->fd,COMEDI_INSN,&insn);
+
if(ret<0){
- fprintf(stderr,"BUG in do_test_for_insn()\n");
+ if(errno!=EIO){
+ fprintf(stderr,"BUG in do_test_for_insn()\n");
+ }
return 0;
}
-#endif
return 1;
}
if(ret<0 && (errno==EINVAL || errno==EIO)){
return 0;
}
-#if 0
if(ret<0){
fprintf(stderr,"BUG in do_test_for_insn_bits()\n");
return 0;
}
-#endif
return 1;
}
comedi_devinfo devinfo;
subdevice *subdevices;
+
+ unsigned int has_insnlist_ioctl;
+ unsigned int has_insn_ioctl;
};
struct subdevice_struct{
comedi_range **rangeinfo_list;
unsigned int has_cmd;
- unsigned int has_insn;
unsigned int has_insn_bits;
};
};
-/* comedi version compatibility */
-
-#ifndef TRIG_WRITE
-#define TRIG_WRITE 0x0040
-#endif
-
-#ifdef COMEDI_CMD
-#define HAVE_COMEDI_CMD
-#endif
-
-#ifdef COMEDI_INSNLIST
-#define HAVE_COMEDI_INSN
-#endif
-
-#ifdef COMEDI_POLL
-#define HAVE_COMEDI_POLL
-#endif
-
-
#endif