Moved trig compatibility functions from drivers.c to trig.c.
authorDavid Schleef <ds@schleef.org>
Sun, 27 May 2001 23:03:35 +0000 (23:03 +0000)
committerDavid Schleef <ds@schleef.org>
Sun, 27 May 2001 23:03:35 +0000 (23:03 +0000)
Wrapped all trig related code in CONFIG_COMEDI_TRIG.
Added config option for CONFIG_COMEDI_TRIG.

comedi/Config.in
comedi/Makefile
comedi/comedi_fops.c
comedi/drivers.c
comedi/kcomedilib/kcomedilib_main.c
comedi/trig.c [new file with mode: 0644]
include/linux/comedidev.h

index 0260a31c2aac5f273460d8f1d9b61b31e7511fd6..f7c19ad1d1418ebcba0c95ee1417ff74f719cca9 100644 (file)
@@ -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
 
index 76f41f29db8eeefd212d25e1cf1e91ebf826e501..dce14283656c98f98aac2686438eaff34540f5c2 100644 (file)
@@ -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
index d691f0866a8e12769f873b084f8aa09372a989c1..2196bc39c73f919df8444199ef69ea043caced8d 100644 (file)
@@ -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;
index cdf095624364e75f5455626f343bfde62c66f3b0..6967bd350559c9ff97e46a1597bf841e4fb6741e 100644 (file)
 #include <linux/malloc.h>
 #include <asm/io.h>
 
+#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)
index 0e67b43a02ca3a9d98c7d13e0faab73287792d14..53a72cfb9916d811f216c52f039b92a59959f5b4 100644 (file)
@@ -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 (file)
index 0000000..65c94df
--- /dev/null
@@ -0,0 +1,188 @@
+/*
+    module/trig.c
+    back-compatibility functions
+
+    COMEDI - Linux Control and Measurement Device Interface
+    Copyright (C) 1997-2001 David A. Schleef <ds@schleef.org>
+
+    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 <linux/comedidev.h>
+#include <kvmem.h>
+
+#define __NO_VERSION__
+#include <linux/module.h>
+
+#include <linux/errno.h>
+#include <linux/kernel.h>
+#include <linux/sched.h>
+#include <linux/fcntl.h>
+#include <linux/delay.h>
+#include <linux/ioport.h>
+#include <linux/mm.h>
+#include <linux/malloc.h>
+#include <asm/io.h>
+
+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;
+}
+
index f015a7c4dfc2be34f9b431739d79e061dc0f224e..dd58094bd2bd1ea5fbe6131f41e84737e1884ba5 100644 (file)
@@ -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