Added insn ioctl support.
Added insn ioctl probing. Renamed previously misnamed insnlist probing. Rewrote comedi_data_read_n()
This commit is contained in:
parent
e9acd7e313
commit
7ea936090e
5 changed files with 88 additions and 94 deletions
20
lib/comedi.c
20
lib/comedi.c
|
@ -126,11 +126,7 @@ int comedi_cancel(comedi_t *it,unsigned int subdevice)
|
|||
|
||||
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)
|
||||
|
@ -166,12 +162,20 @@ int comedi_do_insnlist(comedi_t *it,comedi_insnlist *il)
|
|||
|
||||
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;
|
||||
|
||||
return ioctl(it->fd,COMEDI_INSNLIST,&il);
|
||||
ret = ioctl(it->fd,COMEDI_INSNLIST,&il);
|
||||
|
||||
if(ret<0)return ret;
|
||||
return insn->n;
|
||||
}
|
||||
}
|
||||
|
||||
int comedi_lock(comedi_t *it,unsigned int subdevice)
|
||||
|
|
81
lib/data.c
81
lib/data.c
|
@ -47,7 +47,7 @@ int comedi_data_write(comedi_t *it,unsigned int subdev,unsigned int chan,unsigne
|
|||
|
||||
s=it->subdevices+subdev;
|
||||
|
||||
if(s->has_insn){
|
||||
if(it->has_insnlist_ioctl){
|
||||
comedi_insn insn;
|
||||
|
||||
memset(&insn,0,sizeof(insn));
|
||||
|
@ -86,6 +86,36 @@ int comedi_data_write(comedi_t *it,unsigned int subdev,unsigned int chan,unsigne
|
|||
}
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
|
@ -96,7 +126,7 @@ int comedi_data_read(comedi_t *it,unsigned int subdev,unsigned int chan,unsigned
|
|||
|
||||
s=it->subdevices+subdev;
|
||||
|
||||
if(s->has_insn){
|
||||
if(it->has_insnlist_ioctl){
|
||||
comedi_insn insn;
|
||||
|
||||
memset(&insn,0,sizeof(insn));
|
||||
|
@ -143,50 +173,3 @@ int comedi_data_read(comedi_t *it,unsigned int subdev,unsigned int chan,unsigned
|
|||
}
|
||||
}
|
||||
|
||||
#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
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ int comedi_dio_config(comedi_t *it,unsigned int subdev,unsigned int chan,unsigne
|
|||
if(io!=COMEDI_INPUT && io!=COMEDI_OUTPUT)
|
||||
return -1;
|
||||
|
||||
if(s->has_insn){
|
||||
if(it->has_insnlist_ioctl){
|
||||
comedi_insn insn;
|
||||
lsampl_t data;
|
||||
|
||||
|
@ -94,7 +94,7 @@ int comedi_dio_read(comedi_t *it,unsigned int subdev,unsigned int chan,
|
|||
s->type!=COMEDI_SUBD_DI)
|
||||
return -1;
|
||||
|
||||
if(s->has_insn){
|
||||
if(it->has_insnlist_ioctl){
|
||||
comedi_insn insn;
|
||||
lsampl_t data;
|
||||
|
||||
|
@ -142,7 +142,7 @@ int comedi_dio_write(comedi_t *it,unsigned int subdev,unsigned int chan,
|
|||
s->type!=COMEDI_SUBD_DO)
|
||||
return -1;
|
||||
|
||||
if(s->has_insn){
|
||||
if(it->has_insnlist_ioctl){
|
||||
comedi_insn insn;
|
||||
lsampl_t data;
|
||||
|
||||
|
|
52
lib/filler.c
52
lib/filler.c
|
@ -39,7 +39,8 @@
|
|||
/* 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);
|
||||
|
||||
|
||||
|
@ -59,6 +60,8 @@ int get_subdevices(comedi_t *it)
|
|||
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;
|
||||
|
@ -96,8 +99,7 @@ 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){
|
||||
if(it->has_insnlist_ioctl){
|
||||
r[i].has_insn_bits = do_test_for_insn_bits(it,i);
|
||||
}else{
|
||||
r[i].has_insn_bits = 0;
|
||||
|
@ -163,7 +165,7 @@ static int do_test_for_cmd(comedi_t *dev,unsigned int subdevice)
|
|||
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;
|
||||
|
@ -178,19 +180,43 @@ static int do_test_for_insn(comedi_t *dev,unsigned int subdevice)
|
|||
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){
|
||||
return 0;
|
||||
}
|
||||
#if 0
|
||||
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;
|
||||
}
|
||||
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){
|
||||
if(errno!=EIO){
|
||||
fprintf(stderr,"BUG in do_test_for_insn()\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -219,12 +245,10 @@ static int do_test_for_insn_bits(comedi_t *dev,unsigned int subdevice)
|
|||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -66,6 +66,9 @@ struct comedi_t_struct{
|
|||
comedi_devinfo devinfo;
|
||||
|
||||
subdevice *subdevices;
|
||||
|
||||
unsigned int has_insnlist_ioctl;
|
||||
unsigned int has_insn_ioctl;
|
||||
};
|
||||
|
||||
struct subdevice_struct{
|
||||
|
@ -86,7 +89,6 @@ struct subdevice_struct{
|
|||
comedi_range **rangeinfo_list;
|
||||
|
||||
unsigned int has_cmd;
|
||||
unsigned int has_insn;
|
||||
unsigned int has_insn_bits;
|
||||
};
|
||||
|
||||
|
@ -123,24 +125,5 @@ enum{
|
|||
};
|
||||
|
||||
|
||||
/* 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
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue