#include <linux/malloc.h>
#include <asm/io.h>
-#define USE_INSN
-
extern volatile int rtcomedi_lock_semaphore;
int comedi_data_write(unsigned int dev,unsigned int subdev,unsigned int chan,
unsigned int range,unsigned int aref,lsampl_t data)
{
-#ifdef USE_INSN
comedi_insn insn;
-
+
memset(&insn,0,sizeof(insn));
insn.insn = INSN_WRITE;
insn.n = 1;
insn.chanspec = CR_PACK(chan,range,aref);
return comedi_do_insn(dev,&insn);
-#else
- comedi_trig cmd;
- sampl_t sdata = data;
-
- memset(&cmd,0,sizeof(cmd));
-
- cmd.flags = TRIG_WRITE;
- cmd.n_chan = 1;
- cmd.n = 1;
-
- chan = CR_PACK(chan,range,aref);
- cmd.subdev = subdev;
- cmd.data = &sdata;
- cmd.data_len = sizeof(sampl_t);
-
- cmd.chanlist = &chan;
-
- return comedi_trigger(dev,subdev,&cmd);
-#endif
}
int comedi_data_read(unsigned int dev,unsigned int subdev,unsigned int chan,
unsigned int range,unsigned int aref,lsampl_t *data)
{
-#ifdef USE_INSN
comedi_insn insn;
-
+
memset(&insn,0,sizeof(insn));
insn.insn = INSN_READ;
insn.n = 1;
insn.chanspec = CR_PACK(chan,range,aref);
return comedi_do_insn(dev,&insn);
-#else
- comedi_trig cmd;
- int ret;
- sampl_t sdata;
-
- memset(&cmd,0,sizeof(cmd));
-
- cmd.n_chan = 1;
- cmd.n = 1;
-
- chan = CR_PACK(chan,range,aref);
- cmd.subdev = subdev;
- cmd.data = &sdata;
- cmd.data_len = sizeof(sampl_t);
-
- cmd.chanlist = &chan;
-
- ret = comedi_trigger(dev,subdev,&cmd);
-
- *data = sdata;
-
- return ret;
-#endif
}
#include <linux/malloc.h>
#include <asm/io.h>
-#define USE_INSN
-
extern volatile int rtcomedi_lock_semaphore;
int comedi_dio_config(unsigned int dev,unsigned int subdev,unsigned int chan,
unsigned int io)
{
-#ifdef USE_INSN
comedi_insn insn;
memset(&insn,0,sizeof(insn));
insn.chanspec = CR_PACK(chan,0,0);
return comedi_do_insn(dev,&insn);
-#else
- comedi_trig cmd;
- sampl_t sdata = io;
-
- memset(&cmd,0,sizeof(cmd));
-
- cmd.flags = TRIG_CONFIG|TRIG_WRITE;
- cmd.n_chan = 1;
- cmd.n = 1;
-
- cmd.subdev = subdev;
- cmd.data = &sdata;
- cmd.data_len = sizeof(sampl_t);
-
- cmd.chanlist = &chan;
-
- return comedi_trigger(dev,subdev,&cmd);
-#endif
}
int comedi_dio_read(unsigned int dev,unsigned int subdev,unsigned int chan,
unsigned int *val)
{
-#ifdef USE_INSN
comedi_insn insn;
memset(&insn,0,sizeof(insn));
insn.chanspec = CR_PACK(chan,0,0);
return comedi_do_insn(dev,&insn);
-#else
- comedi_trig cmd;
- sampl_t sdata;
- int ret;
-
- memset(&cmd,0,sizeof(cmd));
-
- cmd.n_chan = 1;
- cmd.n = 1;
- cmd.subdev = subdev;
- cmd.data = &sdata;
- cmd.data_len = sizeof(sampl_t);
- cmd.chanlist = &chan;
-
- ret = comedi_trigger(dev,subdev,&cmd);
-
- *val = sdata;
-
- return ret;
-#endif
}
int comedi_dio_write(unsigned int dev,unsigned int subdev,unsigned int chan,
unsigned int val)
{
-#ifdef USE_INSN
comedi_insn insn;
memset(&insn,0,sizeof(insn));
insn.chanspec = CR_PACK(chan,0,0);
return comedi_do_insn(dev,&insn);
-#else
- comedi_trig cmd;
- sampl_t sdata=val;
- int ret;
-
- memset(&cmd,0,sizeof(cmd));
-
- cmd.flags = TRIG_WRITE;
- cmd.n_chan = 1;
- cmd.n = 1;
- cmd.subdev = subdev;
- cmd.data = &sdata;
- cmd.data_len = sizeof(sampl_t);
- cmd.chanlist = &chan;
-
- ret = comedi_trigger(dev,subdev,&cmd);
-
- return ret;
-#endif
}
int comedi_dio_bitfield(unsigned int minor,unsigned int subdev,unsigned int mask,
unsigned int *bits)
{
-#ifdef USE_INSN
comedi_insn insn;
lsampl_t data[2];
int ret;
*bits = data[1];
return ret;
-#else
- int ret;
- unsigned int i,n_chan;
- unsigned int m,bit;
- comedi_subdevice *s;
-
- s=comedi_get_device_by_minor(minor)->subdevices+subdev;
-
- n_chan=s->n_chan;
- 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(minor,subdev,i,bit);
- }else{
- ret=comedi_dio_read(minor,subdev,i,&bit);
- if(bit) *bits|=m;
- else (*bits)&=~m;
- }
- if(ret<0)return ret;
- }
-
- return (int)n_chan;
-#endif
}
async->buf_int_ptr=0;
async->buf_int_count=0;
-// cur_trig deprecated, looks like all drivers have abandoned it by now - FMH
-// s->cur_trig.data_len = async->cmd.data_len;
-// s->cur_trig.data = async->cmd.data;
-
async->data = cmd->data;
async->data_len = cmd->data_len;
async->cur_chan = 0;
return s->do_cmdtest(dev,s,cmd);
}
-#ifdef unused
-/*
- COMEDI_TRIG
- trigger ioctl
-
- arg:
- pointer to trig structure
-
- reads:
- trig structure at arg
- channel/range list
-
- writes:
- modified trig structure at arg
- data list
-
- this function is too complicated
-*/
-static int comedi_trig_ioctl_mode0(comedi_device *dev,comedi_subdevice *s,comedi_trig *it);
-static int comedi_trig_ioctl_modeN(comedi_device *dev,comedi_subdevice *s,comedi_trig *it);
-int comedi_trigger(unsigned int minor,unsigned int subdev,comedi_trig *it)
-{
- comedi_device *dev;
- comedi_subdevice *s;
- int ret;
-
- if((ret=minor_to_dev(minor,&dev))<0)
- return ret;
-
- if(it->subdev>=dev->n_subdevices)
- return -ENODEV;
-
- s=dev->subdevices+it->subdev;
- if(s->type==COMEDI_SUBD_UNUSED)
- return -EIO;
-
- if(it->mode==0)
- return comedi_trig_ioctl_mode0(dev,s,it);
-
- if(s->async == NULL)
- return -ENODEV;
-
- return comedi_trig_ioctl_modeN(dev,s,it);
-}
-
-static int comedi_trig_ioctl_mode0(comedi_device *dev,comedi_subdevice *s,comedi_trig *it)
-{
- int ret=0;
-
- /* are we locked? (ioctl lock) */
- if(s->lock && s->lock!=&rtcomedi_lock_semaphore)
- return -EACCES;
-
- /* are we busy? */
- if(s->busy)
- return -EBUSY;
- s->busy=(void *)&rtcomedi_lock_semaphore;
-
- /* make sure channel/gain list isn't too long */
- if(it->n_chan > s->len_chanlist){
- ret = -EINVAL;
- goto cleanup;
- }
-
- /* make sure each element in channel/gain list is valid */
- if((ret=check_chanlist(s,it->n_chan,it->chanlist))<0)
- goto cleanup;
-
- if(it->data==NULL){
- ret=-EINVAL;
- goto cleanup;
- }
-
- if(!it->data_len){
-#if 0
- ret=-EINVAL;
- goto cleanup;
-#else
- it->data_len=it->n_chan*it->n*sizeof(sampl_t);
- rt_printk("comedi: warning: trig->data_len not set\n");
-#endif
- }
-
- //s->cur_trig=*it;
-
- ret=s->trig[0](dev,s,it);
-
- if(ret>it->n*it->n_chan){
- rt_printk("comedi: (bug) trig returned too many samples\n");
- }
-
-cleanup:
- s->busy=NULL;
-
- return ret;
-}
-
-static int comedi_trig_ioctl_modeN(comedi_device *dev,comedi_subdevice *s,comedi_trig *it)
-{
- int ret=0;
- comedi_async *async = s->async;
-
- /* are we locked? (ioctl lock) */
- if(s->lock && s->lock!=&rtcomedi_lock_semaphore)
- return -EACCES;
-
- /* are we busy? */
- if(s->busy)
- return -EBUSY;
- s->busy=(void *)&rtcomedi_lock_semaphore;
-
- /* make sure channel/gain list isn't too long */
- if(it->n_chan > s->len_chanlist){
- ret = -EINVAL;
- goto cleanup;
- }
-
- if(async == NULL)
- return -ENODEV;
-
- /* make sure each element in channel/gain list is valid */
- if((ret=check_chanlist(s,it->n_chan,it->chanlist))<0)
- goto cleanup;
-
- async->buf_user_ptr=0;
- async->buf_user_count=0;
- async->buf_int_ptr=0;
- async->buf_int_count=0;
-
- if(it->data==NULL){
- ret=-EINVAL;
- goto cleanup;
- }
-
- if(!it->data_len){
-#if 0
- ret=-EINVAL;
- goto cleanup;
-#else
- it->data_len=it->n_chan*it->n*sizeof(sampl_t);
- rt_printk("comedi: warning: trig->data_len not set\n");
-#endif
- }
-
- if(it->mode>=5 || s->trig[it->mode]==NULL){
- ret=-EINVAL;
- goto cleanup;
- }
-
-// s->cur_trig=*it;
- async->data = it->data;
- async->data_len = it->data_len;
-
- ret=s->trig[it->mode](dev,s,it);
-
- if(ret==0)return 0;
-
-cleanup:
- s->busy=NULL;
-
- return ret;
-}
-
-/*
- This function does the same as above, but without any sanity
- checks. Any insanity in code calling this function must be
- assumed by the writer.
- */
-int __comedi_trigger(unsigned int minor,unsigned int subdev,comedi_trig *it)
-{
- comedi_device *dev;
- comedi_subdevice *s;
- int ret=0;
-
- dev=comedi_get_device_by_minor(minor);
- s=dev->subdevices+subdev;
-
-// s->cur_trig=*it;
-
- ret=s->trig[it->mode](dev,s,it);
-
- return ret;
-}
-#endif
-
/*
* COMEDI_INSN
* perform an instruction
/* functions specific to kcomedilib */
-#ifdef unused
-EXPORT_SYMBOL(__comedi_trigger);
-#endif
EXPORT_SYMBOL(comedi_register_callback);
EXPORT_SYMBOL(comedi_get_subdevice_flags);
EXPORT_SYMBOL(comedi_get_len_chanlist);
//EXPORT_SYMBOL(comedi_range_is_chan_specific);
//EXPORT_SYMBOL(comedi_maxdata_is_chan_specific);
EXPORT_SYMBOL(comedi_cancel);
-#ifdef unused
-EXPORT_SYMBOL(comedi_trigger);
-#endif
EXPORT_SYMBOL(comedi_command);
EXPORT_SYMBOL(comedi_command_test);
//EXPORT_SYMBOL(comedi_do_insnlist);