From a7ec785b4937677c3fa0dcfecfb4195832e685b4 Mon Sep 17 00:00:00 2001 From: David Schleef Date: Sun, 20 Feb 2000 22:54:10 +0000 Subject: [PATCH] added comedi_data_*() and comedi_dio_*() functions --- comedi/kcomedilib/Makefile | 5 ++ comedi/kcomedilib/data.c | 89 ++++++++++++++++++++++++ comedi/kcomedilib/dio.c | 136 +++++++++++++++++++++++++++++++++++++ 3 files changed, 230 insertions(+) create mode 100644 comedi/kcomedilib/data.c create mode 100644 comedi/kcomedilib/dio.c diff --git a/comedi/kcomedilib/Makefile b/comedi/kcomedilib/Makefile index fc530185..0968866c 100644 --- a/comedi/kcomedilib/Makefile +++ b/comedi/kcomedilib/Makefile @@ -6,8 +6,13 @@ MOD_LIST_NAME := MISC_MODULES EXTRA_CFLAGS := -I ../ +MI_OBJS := data.o dio.o +MIX_OBJS := kcomedilib_main.o M_OBJS := kcomedilib.o include $(TOPDIR)/Rules.make +kcomedilib.o: $(MI_OBJS) $(MIX_OBJS) + $(LD) -r -o $@ $(MI_OBJS) $(MIX_OBS) + diff --git a/comedi/kcomedilib/data.c b/comedi/kcomedilib/data.c new file mode 100644 index 00000000..e9e8addc --- /dev/null +++ b/comedi/kcomedilib/data.c @@ -0,0 +1,89 @@ +/* + kcomedilib/data.c + implements comedi_data_*() functions + + COMEDI - Linux Control and Measurement Device Interface + Copyright (C) 2000 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 +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef LINUX_V22 +#include +#endif + + +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) +{ + 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.chanlist = &chan; + + return comedi_trig_ioctl(dev,subdev,&cmd); +} + +int comedi_data_read(unsigned int dev,unsigned int subdev,unsigned int chan, + unsigned int range,unsigned int aref,lsampl_t *data) +{ + 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.chanlist = &chan; + + ret = comedi_trig_ioctl(dev,subdev,&cmd); + + *data = sdata; + + return ret; +} + diff --git a/comedi/kcomedilib/dio.c b/comedi/kcomedilib/dio.c new file mode 100644 index 00000000..fae086b6 --- /dev/null +++ b/comedi/kcomedilib/dio.c @@ -0,0 +1,136 @@ +/* + kcomedilib/dio.c + implements comedi_dio_*() functions + + COMEDI - Linux Control and Measurement Device Interface + Copyright (C) 2000 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 +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef LINUX_V22 +#include +#endif + + +extern volatile int rtcomedi_lock_semaphore; + +int comedi_dio_config(unsigned int dev,unsigned int subdev,unsigned int chan, + unsigned int io) +{ + 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.chanlist = &chan; + + return comedi_trig_ioctl(dev,subdev,&cmd); +} + +int comedi_dio_read(unsigned int dev,unsigned int subdev,unsigned int chan, + unsigned int *val) +{ + 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.chanlist = &chan; + + ret = comedi_trig_ioctl(dev,subdev,&cmd); + + *val = sdata; + + return ret; +} + +int comedi_dio_write(unsigned int dev,unsigned int subdev,unsigned int chan, + unsigned int val) +{ + 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.chanlist = &chan; + + ret = comedi_trig_ioctl(dev,subdev,&cmd); + + return ret; +} + +int comedi_dio_bitfield(unsigned int dev,unsigned int subdev,unsigned int mask, + unsigned int *bits) +{ + int ret; + unsigned int i,n_chan; + unsigned int m,bit; + comedi_subdevice *s; + + s=comedi_devices[dev].subdevices+subdev; + + n_chan=s->n_chan; + if(n_chan>32)n_chan=32; + + for(i=0,m=1;i