lots of changes with commands and instructions
This commit is contained in:
parent
f4420f799e
commit
c9f298466f
8 changed files with 211 additions and 110 deletions
37
lib/comedi.c
37
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_cmd(it->fd,t);
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
return ioctl(it->fd,COMEDI_CMD,t);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
130
lib/data.c
130
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;
|
||||
}
|
||||
cmd.chanlist=&chan;
|
||||
comedi_trig cmd={
|
||||
mode: 0,
|
||||
flags: TRIG_WRITE,
|
||||
n_chan: 1,
|
||||
n: 1,
|
||||
trigsrc: 0,
|
||||
trigvar: 0,
|
||||
trigvar1: 0,
|
||||
};
|
||||
sampl_t sdata=data;
|
||||
|
||||
return ioctl_trigger(it->fd,&cmd);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
|
||||
if(!(s->subd_flags & SDF_LSAMPL)){
|
||||
*data=sdata;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
ret=ioctl_trigger(it->fd,&cmd);
|
||||
if(ret<0)
|
||||
return ret;
|
||||
|
||||
if(!(it->subdevices[subdev].subd_flags & SDF_LSAMPL)){
|
||||
*data=sdata;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if 1
|
||||
|
|
65
lib/dio.c
65
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(ret<0)return ret;
|
||||
}
|
||||
if(s->type!=COMEDI_SUBD_DIO && s->type!=COMEDI_SUBD_DO &&
|
||||
s->type!=COMEDI_SUBD_DI)
|
||||
return -1;
|
||||
|
||||
return (int)n_chan;
|
||||
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;
|
||||
|
||||
*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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
43
lib/filler.c
43
lib/filler.c
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -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))
|
||||
|
|
29
lib/ioctl.c
29
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;
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue