From 0e799ff86ac3c55fd1c43af8bff3812b7f4aaed2 Mon Sep 17 00:00:00 2001 From: David Schleef Date: Sat, 11 Mar 2000 16:17:32 +0000 Subject: [PATCH] Added prototypes for kcomedilib functions in comedi.h, added comedi_open and comedi_close, removed conflict with comedi. --- comedi/comedi_fops.c | 6 +- comedi/kcomedilib/kcomedilib_main.c | 90 +++++++++++++++++++++++++++-- include/comedi.h | 30 +++++++++- 3 files changed, 115 insertions(+), 11 deletions(-) diff --git a/comedi/comedi_fops.c b/comedi/comedi_fops.c index e8ab46bb..b6f1e0ac 100644 --- a/comedi/comedi_fops.c +++ b/comedi/comedi_fops.c @@ -1261,7 +1261,7 @@ static loff_t comedi_lseek_v22(struct file *file,loff_t offset,int origin) return file->f_pos=new_offset; } -static int comedi_open(struct inode *inode,struct file *file) +static int comedi_fop_open(struct inode *inode,struct file *file) { kdev_t minor=MINOR(inode->i_rdev); comedi_device *dev; @@ -1352,7 +1352,7 @@ static void comedi_close_v20(struct inode *inode,struct file *file) } #define comedi_ioctl_v20 comedi_ioctl -#define comedi_open_v20 comedi_open +#define comedi_open_v20 comedi_fop_open static struct file_operations comedi_fops={ lseek : comedi_lseek_v20, @@ -1368,7 +1368,7 @@ static struct file_operations comedi_fops={ #ifdef LINUX_V22 #define comedi_ioctl_v22 comedi_ioctl -#define comedi_open_v22 comedi_open +#define comedi_open_v22 comedi_fop_open static struct file_operations comedi_fops={ llseek : comedi_lseek_v22, diff --git a/comedi/kcomedilib/kcomedilib_main.c b/comedi/kcomedilib/kcomedilib_main.c index f20715e2..334acc19 100644 --- a/comedi/kcomedilib/kcomedilib_main.c +++ b/comedi/kcomedilib/kcomedilib_main.c @@ -67,6 +67,25 @@ static inline int minor_to_dev(unsigned int minor,comedi_device **dev) } +int comedi_open(unsigned int minor) +{ + comedi_device *dev; + + if(minor>=COMEDI_NDEVICES) + return -ENODEV; + + dev=comedi_get_device_by_minor(minor); + + if(!dev->attached) + return -ENODEV; + + return minor; +} + +void comedi_close(unsigned int minor) +{ +} + /* These functions are #if 0'd because they aren't appropriate inside RTLinux, at least, not in this form. Interface needs @@ -236,11 +255,13 @@ static int do_chaninfo_ioctl(comedi_device *dev,comedi_chaninfo *arg) 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_trig_ioctl(unsigned int minor,unsigned int subdev,comedi_trig *it) { comedi_device *dev; comedi_subdevice *s; - int ret=0; + int ret; if((ret=minor_to_dev(minor,&dev))<0) return ret; @@ -252,6 +273,68 @@ int comedi_trig_ioctl(unsigned int minor,unsigned int subdev,comedi_trig *it) if(s->type==COMEDI_SUBD_UNUSED) return -EIO; + if(it->mode==0) + return comedi_trig_ioctl_mode0(dev,s,it); + + 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; + 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; + /* is subdevice RT capable? (important!) */ if(!(s->subdev_flags&SDF_RT)){ ret=-EINVAL; @@ -307,11 +390,6 @@ int comedi_trig_ioctl(unsigned int minor,unsigned int subdev,comedi_trig *it) ret=s->trig[it->mode](dev,s,it); if(ret==0)return 0; - if(ret<0)goto cleanup; - - if(ret>it->n*it->n_chan){ - rt_printk("comedi: (bug) trig returned too many samples\n"); - } cleanup: s->busy=NULL; diff --git a/include/comedi.h b/include/comedi.h index 28e276cc..a3bdc6aa 100644 --- a/include/comedi.h +++ b/include/comedi.h @@ -282,14 +282,40 @@ struct comedi_devconfig_struct{ /* exported functions */ -int comedi_trig_ioctl(unsigned int minor,unsigned int subdev,comedi_trig *it); -int __comedi_trig_ioctl(unsigned int minor,unsigned int subdev,comedi_trig *it); +/* these functions may not be called at real-time priority */ + +int comedi_open(unsigned int minor); +void comedi_close(unsigned int minor); + +/* these functions may be called at any priority, but may fail at + real-time priority */ + int comedi_lock_ioctl(unsigned int minor,unsigned int subdev); int comedi_unlock_ioctl(unsigned int minor,unsigned int subdev); + +/* these functions may be called at any priority, but you must hold + the lock for the subdevice */ + int comedi_cancel_ioctl(unsigned int minor,unsigned int subdev); int comedi_register_callback(unsigned int minor,unsigned int subdev, unsigned int mask,int (*cb)(unsigned int,void *),void *arg); +int comedi_trig_ioctl(unsigned int minor,unsigned int subdev,comedi_trig *it); +int __comedi_trig_ioctl(unsigned int minor,unsigned int subdev,comedi_trig *it); +int comedi_data_write(unsigned int dev,unsigned int subdev,unsigned int chan, + unsigned int range,unsigned int aref,lsampl_t data); +int comedi_data_read(unsigned int dev,unsigned int subdev,unsigned int chan, + unsigned int range,unsigned int aref,lsampl_t *data); +int comedi_dio_config(unsigned int dev,unsigned int subdev,unsigned int chan, + unsigned int io); +int comedi_dio_read(unsigned int dev,unsigned int subdev,unsigned int chan, + unsigned int *val); +int comedi_dio_write(unsigned int dev,unsigned int subdev,unsigned int chan, + unsigned int val); +int comedi_dio_bitfield(unsigned int dev,unsigned int subdev,unsigned int mask, + unsigned int *bits); + + #endif -- 2.26.2