From 80e9b18511d2a8e4a17d476aef1d7bb73c6d1bca Mon Sep 17 00:00:00 2001 From: David Schleef Date: Sun, 27 May 2001 23:03:35 +0000 Subject: [PATCH] Moved trig compatibility functions from drivers.c to trig.c. Wrapped all trig related code in CONFIG_COMEDI_TRIG. Added config option for CONFIG_COMEDI_TRIG. --- comedi/Config.in | 7 +- comedi/Makefile | 7 +- comedi/comedi_fops.c | 12 +- comedi/drivers.c | 177 +++----------------------- comedi/kcomedilib/kcomedilib_main.c | 2 + comedi/trig.c | 188 ++++++++++++++++++++++++++++ include/linux/comedidev.h | 4 +- 7 files changed, 221 insertions(+), 176 deletions(-) create mode 100644 comedi/trig.c diff --git a/comedi/Config.in b/comedi/Config.in index 0260a31c..f7c19ad1 100644 --- a/comedi/Config.in +++ b/comedi/Config.in @@ -3,11 +3,7 @@ define_bool CONFIG_COMEDI m comment 'Comedi Features' -define_bool CONFIG_COMEDI_MODES y -define_bool CONFIG_COMEDI_MODE0 y -define_bool CONFIG_COMEDI_MODE_CORE y - -#bool 'Backwards compatibility' CONFIG_COMEDI_BACKWARDS +bool 'Trig compatibility (say yes)' CONFIG_COMEDI_TRIG if [ "$CONFIG_RTL" = "y" ];then bool 'Real-time support' CONFIG_COMEDI_RT @@ -29,7 +25,6 @@ if [ "$CONFIG_RTHAL" = "y" ];then fi bool 'Verbose Debugging' CONFIG_COMEDI_DEBUG -#bool 'Version 0.8 support' CONFIG_COMEDI_VER08 dep_tristate 'Kernel Comedilib' CONFIG_COMEDI_KLIB $CONFIG_COMEDI diff --git a/comedi/Makefile b/comedi/Makefile index 76f41f29..dce14283 100644 --- a/comedi/Makefile +++ b/comedi/Makefile @@ -24,15 +24,20 @@ ifeq ($(CONFIG_COMEDI),y) O_TARGET := comedi.o O_OBJS := comedi_fops.o proc.o range.o drivers.o kvmem.o OX_OBJS := comedi_ksyms.o + ifeq ($(CONFIG_COMEDI_TRIG),y) + MI_OBJS += trig.o + endif else ifeq ($(CONFIG_COMEDI),m) M_OBJS := comedi.o MI_OBJS := comedi_fops.o proc.o range.o drivers.o kvmem.o MIX_OBJS := comedi_ksyms.o + ifeq ($(CONFIG_COMEDI_TRIG),y) + MI_OBJS += trig.o + endif endif endif - ifeq ($(CONFIG_COMEDI_RT),y) MI_OBJS += rt.o endif diff --git a/comedi/comedi_fops.c b/comedi/comedi_fops.c index d691f086..2196bc39 100644 --- a/comedi/comedi_fops.c +++ b/comedi/comedi_fops.c @@ -53,7 +53,7 @@ static int do_devinfo_ioctl(comedi_device *dev,comedi_devinfo *arg); static int do_subdinfo_ioctl(comedi_device *dev,comedi_subdinfo *arg,void *file); static int do_chaninfo_ioctl(comedi_device *dev,comedi_chaninfo *arg); static int do_bufinfo_ioctl(comedi_device *dev,void *arg); -#ifdef CONFIG_COMEDI_MODE_CORE +#ifdef CONFIG_COMEDI_TRIG static int do_trig_ioctl(comedi_device *dev,void *arg,void *file); #endif static int do_cmd_ioctl(comedi_device *dev,void *arg,void *file); @@ -101,7 +101,7 @@ static int comedi_ioctl(struct inode * inode,struct file * file, return do_rangeinfo_ioctl(dev,(void *)arg); case COMEDI_BUFINFO: return do_bufinfo_ioctl(dev,(void*)arg); -#ifdef CONFIG_COMEDI_MODE_CORE +#ifdef CONFIG_COMEDI_TRIG case COMEDI_TRIG: return do_trig_ioctl(dev,(void *)arg,file); #endif @@ -371,7 +371,7 @@ static int do_subdinfo_ioctl(comedi_device *dev,comedi_subdinfo *arg,void *file) us->subd_flags |= SDF_FLAGS; if(s->range_table_list) us->subd_flags |= SDF_RANGETYPE; -#ifdef CONFIG_COMEDI_MODE_CORE +#ifdef CONFIG_COMEDI_TRIG if(s->trig[0]) us->subd_flags |= SDF_MODE0; if(s->trig[1]) @@ -530,7 +530,7 @@ copyback: return 0; } -#ifdef CONFIG_COMEDI_MODE_CORE +#ifdef CONFIG_COMEDI_TRIG /* COMEDI_TRIG trigger ioctl @@ -1678,7 +1678,7 @@ printk("m is %d\n",m); n-=m; // check for buffer overrun - if(async->buf_int_count - async->buf_user_count > async->data_len){ /* XXX MODE */ + if(async->buf_int_count - async->buf_user_count > async->data_len){ async->buf_user_count = async->buf_int_count; async->buf_user_ptr = async->buf_int_ptr; retval=-EINVAL; @@ -1727,10 +1727,12 @@ static void do_become_nonbusy(comedi_device *dev,comedi_subdevice *s) } #endif +#ifdef CONFIG_COMEDI_TRIG if(s->cur_trig.chanlist){ /* XXX wrong? */ kfree(s->cur_trig.chanlist); s->cur_trig.chanlist=NULL; } +#endif if(async){ async->buf_user_ptr=0; diff --git a/comedi/drivers.c b/comedi/drivers.c index cdf09562..6967bd35 100644 --- a/comedi/drivers.c +++ b/comedi/drivers.c @@ -37,16 +37,18 @@ #include #include +#ifdef CONFIG_COMEDI_TRIG +/* in comedi/trig.c */ +int command_trig(comedi_device *dev,comedi_subdevice *s,comedi_trig *it); +int mode_to_command(comedi_cmd *cmd,comedi_trig *it); +int mode0_emulate(comedi_device *dev,comedi_subdevice *s,comedi_trig *trig); +int mode0_emulate_config(comedi_device *dev,comedi_subdevice *s,comedi_trig *trig); +#endif + static int postconfig(comedi_device *dev); -static int command_trig(comedi_device *dev,comedi_subdevice *s,comedi_trig *it); -static int mode_to_command(comedi_cmd *cmd,comedi_trig *it); static int insn_rw_emulate_bits(comedi_device *dev,comedi_subdevice *s, comedi_insn *insn,lsampl_t *data); static int insn_inval(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -#if 0 -static int mode0_emulate(comedi_device *dev,comedi_subdevice *s,comedi_trig *trig); -static int mode0_emulate_config(comedi_device *dev,comedi_subdevice *s,comedi_trig *trig); -#endif static void *comedi_recognize(comedi_driver *driv, const char *name); static void comedi_report_boards(comedi_driver *driv); static int poll_invalid(comedi_device *dev,comedi_subdevice *s); @@ -235,14 +237,20 @@ static int postconfig(comedi_device *dev) if(s->len_chanlist==0) s->len_chanlist=1; +#ifdef CONFIG_COMEDI_TRIG if(s->do_cmd){ s->trig[1]=command_trig; s->trig[2]=command_trig; s->trig[3]=command_trig; s->trig[4]=command_trig; } +#endif - if(s->do_cmd || s->trig[1] || s->trig[2] || s->trig[3] ||s->trig[4]){ + if(s->do_cmd +#ifdef CONFIG_COMEDI_TRIG + || s->trig[1] || s->trig[2] || s->trig[3] ||s->trig[4] +#endif + ){ async = kmalloc(sizeof(comedi_async), GFP_KERNEL); if(async == NULL) { @@ -362,161 +370,6 @@ static int insn_rw_emulate_bits(comedi_device *dev,comedi_subdevice *s, return 1; } -#define SUPPORT_TRIG -#define SUPPORT_TRIG0 -#ifdef SUPPORT_TRIG -#if 0 -static int mode0_emulate(comedi_device *dev,comedi_subdevice *s,comedi_trig *trig) -{ - comedi_insn insn; - lsampl_t ldata; - int ret; - - insn.subdev=trig->subdev; - insn.data=&ldata; - insn.n=1; - insn.chanspec=trig->chanlist[0]; - - if(trig->flags&TRIG_CONFIG) - return mode0_emulate_config(dev,s,trig); - - if(s->subdev_flags & SDF_WRITEABLE){ - if(s->subdev_flags & SDF_READABLE){ - if(trig->flags&TRIG_WRITE){ - insn.insn=INSN_WRITE; - }else{ - insn.insn=INSN_READ; - } - }else{ - insn.insn=INSN_WRITE; - } - }else{ - insn.insn=INSN_READ; - } - - switch(insn.insn){ - case INSN_READ: - ret=s->insn_read(dev,s,&insn,&ldata); - if(s->subdev_flags&SDF_LSAMPL){ - *(lsampl_t *)trig->data=ldata; - }else{ - trig->data[0]=ldata; - } - return ret; - case INSN_WRITE: - if(s->subdev_flags&SDF_LSAMPL){ - ldata=*(lsampl_t *)trig->data; - }else{ - ldata=trig->data[0]; - } - return s->insn_write(dev,s,&insn,&ldata); - default: - } - - return -EINVAL; -} -#endif -#endif - -#ifdef SUPPORT_TRIG0 -#if 0 -static int mode0_emulate_config(comedi_device *dev,comedi_subdevice *s,comedi_trig *trig) -{ - comedi_insn insn; - lsampl_t ldata; - - insn.subdev=trig->subdev; - insn.data=&ldata; - insn.n=1; - insn.chanspec=trig->chanlist[0]; - - ldata = trig->data[0]; - - return s->insn_config(dev,s,&insn,&ldata); -} -#endif -#endif - -#ifdef SUPPORT_TRIG -static int command_trig(comedi_device *dev,comedi_subdevice *s,comedi_trig *it) -{ - int ret; - comedi_async *async = s->async; - - ret=mode_to_command(&async->cmd,it); - if(ret)return ret; - - ret=s->do_cmdtest(dev,s,&async->cmd); - if(ret)return -EINVAL; - - ret=s->do_cmd(dev,s); - if(ret>0)return -EINVAL; - return ret; -} -#endif - -static int mode_to_command(comedi_cmd *cmd,comedi_trig *it) -{ - memset(cmd,0,sizeof(comedi_cmd)); - cmd->subdev=it->subdev; - cmd->chanlist_len=it->n_chan; - cmd->chanlist=it->chanlist; - cmd->data=it->data; - cmd->data_len=it->data_len; - - cmd->start_src=TRIG_NOW; - - switch(it->mode){ - case 1: - cmd->scan_begin_src=TRIG_FOLLOW; - cmd->convert_src=TRIG_TIMER; - cmd->convert_arg=it->trigvar; - cmd->scan_end_src=TRIG_COUNT; - cmd->scan_end_arg=it->n_chan; - cmd->stop_src=TRIG_COUNT; - cmd->stop_arg=it->n; - - break; - case 2: - cmd->scan_begin_src=TRIG_TIMER; - cmd->scan_begin_arg=it->trigvar; - cmd->convert_src=TRIG_TIMER; - cmd->convert_arg=it->trigvar1; - cmd->scan_end_src=TRIG_COUNT; - cmd->scan_end_arg=it->n_chan; - cmd->stop_src=TRIG_COUNT; - cmd->stop_arg=it->n; - - break; - case 3: - cmd->scan_begin_src=TRIG_FOLLOW; - cmd->convert_src=TRIG_EXT; - cmd->convert_arg=it->trigvar; - cmd->scan_end_src=TRIG_COUNT; - cmd->scan_end_arg=it->n_chan; - cmd->stop_src=TRIG_COUNT; - cmd->stop_arg=it->n; - - break; - case 4: - cmd->scan_begin_src=TRIG_EXT; - cmd->scan_begin_arg=it->trigvar; - cmd->convert_src=TRIG_TIMER; - cmd->convert_arg=it->trigvar1; - cmd->scan_end_src=TRIG_COUNT; - cmd->scan_end_arg=it->n_chan; - cmd->stop_src=TRIG_COUNT; - cmd->stop_arg=it->n; - - break; - default: - return -EINVAL; - } - - return 0; -} - - #define REG(x) {extern comedi_driver (x);comedi_driver_register(&(x));} void init_drivers(void) diff --git a/comedi/kcomedilib/kcomedilib_main.c b/comedi/kcomedilib/kcomedilib_main.c index 0e67b43a..53a72cfb 100644 --- a/comedi/kcomedilib/kcomedilib_main.c +++ b/comedi/kcomedilib/kcomedilib_main.c @@ -427,6 +427,7 @@ int comedi_command_test(unsigned int minor,comedi_cmd *cmd) return s->do_cmdtest(dev,s,cmd); } +#ifdef CONFIG_COMEDI_TRIG /* COMEDI_TRIG trigger ioctl @@ -609,6 +610,7 @@ int __comedi_trigger(unsigned int minor,unsigned int subdev,comedi_trig *it) return ret; } +#endif /* * COMEDI_INSN diff --git a/comedi/trig.c b/comedi/trig.c new file mode 100644 index 00000000..65c94df7 --- /dev/null +++ b/comedi/trig.c @@ -0,0 +1,188 @@ +/* + module/trig.c + back-compatibility functions + + COMEDI - Linux Control and Measurement Device Interface + Copyright (C) 1997-2001 David A. Schleef + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include +#include + +#define __NO_VERSION__ +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int command_trig(comedi_device *dev,comedi_subdevice *s,comedi_trig *it); +int mode_to_command(comedi_cmd *cmd,comedi_trig *it); +int mode0_emulate(comedi_device *dev,comedi_subdevice *s,comedi_trig *trig); +int mode0_emulate_config(comedi_device *dev,comedi_subdevice *s,comedi_trig *trig); + + + +int mode0_emulate(comedi_device *dev,comedi_subdevice *s,comedi_trig *trig) +{ + comedi_insn insn; + lsampl_t ldata; + int ret; + + insn.subdev=trig->subdev; + insn.data=&ldata; + insn.n=1; + insn.chanspec=trig->chanlist[0]; + + if(trig->flags&TRIG_CONFIG) + return mode0_emulate_config(dev,s,trig); + + if(s->subdev_flags & SDF_WRITEABLE){ + if(s->subdev_flags & SDF_READABLE){ + if(trig->flags&TRIG_WRITE){ + insn.insn=INSN_WRITE; + }else{ + insn.insn=INSN_READ; + } + }else{ + insn.insn=INSN_WRITE; + } + }else{ + insn.insn=INSN_READ; + } + + switch(insn.insn){ + case INSN_READ: + ret=s->insn_read(dev,s,&insn,&ldata); + if(s->subdev_flags&SDF_LSAMPL){ + *(lsampl_t *)trig->data=ldata; + }else{ + trig->data[0]=ldata; + } + return ret; + case INSN_WRITE: + if(s->subdev_flags&SDF_LSAMPL){ + ldata=*(lsampl_t *)trig->data; + }else{ + ldata=trig->data[0]; + } + return s->insn_write(dev,s,&insn,&ldata); + default: + } + + return -EINVAL; +} + +int mode0_emulate_config(comedi_device *dev,comedi_subdevice *s,comedi_trig *trig) +{ + comedi_insn insn; + lsampl_t ldata; + + insn.subdev=trig->subdev; + insn.data=&ldata; + insn.n=1; + insn.chanspec=trig->chanlist[0]; + + ldata = trig->data[0]; + + return s->insn_config(dev,s,&insn,&ldata); +} + +int command_trig(comedi_device *dev,comedi_subdevice *s,comedi_trig *it) +{ + int ret; + comedi_async *async = s->async; + + ret=mode_to_command(&async->cmd,it); + if(ret)return ret; + + ret=s->do_cmdtest(dev,s,&async->cmd); + if(ret)return -EINVAL; + + ret=s->do_cmd(dev,s); + if(ret>0)return -EINVAL; + return ret; +} + +int mode_to_command(comedi_cmd *cmd,comedi_trig *it) +{ + memset(cmd,0,sizeof(comedi_cmd)); + cmd->subdev=it->subdev; + cmd->chanlist_len=it->n_chan; + cmd->chanlist=it->chanlist; + cmd->data=it->data; + cmd->data_len=it->data_len; + + cmd->start_src=TRIG_NOW; + + switch(it->mode){ + case 1: + cmd->scan_begin_src=TRIG_FOLLOW; + cmd->convert_src=TRIG_TIMER; + cmd->convert_arg=it->trigvar; + cmd->scan_end_src=TRIG_COUNT; + cmd->scan_end_arg=it->n_chan; + cmd->stop_src=TRIG_COUNT; + cmd->stop_arg=it->n; + + break; + case 2: + cmd->scan_begin_src=TRIG_TIMER; + cmd->scan_begin_arg=it->trigvar; + cmd->convert_src=TRIG_TIMER; + cmd->convert_arg=it->trigvar1; + cmd->scan_end_src=TRIG_COUNT; + cmd->scan_end_arg=it->n_chan; + cmd->stop_src=TRIG_COUNT; + cmd->stop_arg=it->n; + + break; + case 3: + cmd->scan_begin_src=TRIG_FOLLOW; + cmd->convert_src=TRIG_EXT; + cmd->convert_arg=it->trigvar; + cmd->scan_end_src=TRIG_COUNT; + cmd->scan_end_arg=it->n_chan; + cmd->stop_src=TRIG_COUNT; + cmd->stop_arg=it->n; + + break; + case 4: + cmd->scan_begin_src=TRIG_EXT; + cmd->scan_begin_arg=it->trigvar; + cmd->convert_src=TRIG_TIMER; + cmd->convert_arg=it->trigvar1; + cmd->scan_end_src=TRIG_COUNT; + cmd->scan_end_arg=it->n_chan; + cmd->stop_src=TRIG_COUNT; + cmd->stop_arg=it->n; + + break; + default: + return -EINVAL; + } + + return 0; +} + diff --git a/include/linux/comedidev.h b/include/linux/comedidev.h index f015a7c4..dd58094b 100644 --- a/include/linux/comedidev.h +++ b/include/linux/comedidev.h @@ -86,7 +86,7 @@ struct comedi_subdevice_struct{ unsigned int *chanlist; /* driver-owned chanlist (not used) */ -#ifdef CONFIG_COMEDI_MODE_CORE +#ifdef CONFIG_COMEDI_TRIG comedi_trig cur_trig; /* current trig structure */ int (*trig[5])(comedi_device *,comedi_subdevice *,comedi_trig *); #endif @@ -215,7 +215,7 @@ void stop_polling(comedi_device *); void comedi_proc_init(void); void comedi_proc_cleanup(void); -#ifdef CONFIG_COMEDI_MODE_CORE +#ifdef CONFIG_COMEDI_TRIG int di_unpack(unsigned int bits,comedi_trig *it); int do_pack(unsigned int *bits,comedi_trig *it); #endif -- 2.26.2