From bb1ff949c9e5a9c76a0ecc5cec8d02f5c2289329 Mon Sep 17 00:00:00 2001 From: Frank Mori Hess Date: Sun, 29 Feb 2004 16:52:17 +0000 Subject: [PATCH] beginnings of scxi convenience library from Caleb Tennis --- Makefile.am | 2 +- configure.ac | 9 ++++-- include/Makefile.am | 4 +-- include/comedilib_scxi.h | 63 ++++++++++++++++++++++++++++++++++++++++ scxi/Makefile.am | 11 +++++++ scxi/scxi.c | 43 +++++++++++++++++++++++++++ 6 files changed, 127 insertions(+), 5 deletions(-) create mode 100644 include/comedilib_scxi.h create mode 100644 scxi/Makefile.am create mode 100644 scxi/scxi.c diff --git a/Makefile.am b/Makefile.am index 3e2c4c8..67c0578 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,6 +1,6 @@ SUBDIRS = lib comedi_calibrate comedi_config man testing demo doc swig \ - include etc + include etc scxi #pkgconfigdir = $(libdir)/pkgconfig #pkgconfig_DATA = comedilib.pc diff --git a/configure.ac b/configure.ac index 4f51e87..3f0cb76 100644 --- a/configure.ac +++ b/configure.ac @@ -44,8 +44,8 @@ AS_COMPILER_FLAG([-fno-strict-aliasing],[PYTHON_QUIET="$PYTHON_QUIET -fno-strict AS_COMPILER_FLAG([-Wno-unused-function],[PYTHON_QUIET="$PYTHON_QUIET -Wno-unused-function"], true ) AC_SUBST(PYTHON_QUIET) -AC_ARG_ENABLE([ruby-binding],[ --disable-ruby-binding Disable building of Ruby binding], - [ENABLE_RUBY=$enableval],[ENABLE_RUBY="yes"]) +AC_ARG_ENABLE([ruby-binding], [ --disable-ruby-binding Disable building of Ruby binding], + [ENABLE_RUBY=$enableval], [ENABLE_RUBY="yes"]) AC_PATH_PROG(RUBY, ruby, no) if test "$RUBY" != "no" ; then RUBY_INC_DIR=`$RUBY -e "require 'rbconfig'; c = ::Config::CONFIG; print c[['archdir']];"` @@ -65,6 +65,10 @@ if test "$RUBY_SO_DIR" != "" ; then fi AC_SUBST(RUBY_CONFIG_OPTIONS) +AC_ARG_ENABLE([scxi], [ --enable-scxi Enable SCXI convenience library], + [ENABLE_SCXI=$enableval], [ENABLE_SCXI="no"]) +AM_CONDITIONAL(BUILD_SCXI, [test "$ENABLE_SCXI" == "yes"]) + AC_PATH_PROG(DOCBOOK2MAN, docbook2man, no) if test "$DOCBOOK2MAN" = "no" ; then AC_MSG_WARN([docbook2man not found, will not be able to rebuild man pages]) @@ -110,6 +114,7 @@ demo/Makefile include/Makefile lib/Makefile man/Makefile +scxi/Makefile swig/Makefile swig/python/Makefile swig/ruby/Makefile diff --git a/include/Makefile.am b/include/Makefile.am index 1c6be98..efd2b43 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -1,5 +1,5 @@ -EXTRA_DIST = comedi.h comedilib.h +EXTRA_DIST = comedi.h comedilib.h comedilib_scxi.h -include_HEADERS = comedi.h comedilib.h +include_HEADERS = comedi.h comedilib.h comedilib_scxi.h diff --git a/include/comedilib_scxi.h b/include/comedilib_scxi.h new file mode 100644 index 0000000..4af4484 --- /dev/null +++ b/include/comedilib_scxi.h @@ -0,0 +1,63 @@ +#include + +#define SLOT0_INTERVAL 1200 +#define FAST_INTERVAL 1200 +#define MEDIUM_INTERVAL 10000 +#define SLOW_INTERVAL 30000 + +#define SCXI_LINE_MOSI 0 +#define SCXI_LINE_DA 1 +#define SCXI_LINE_SS 2 +#define SCXI_LINE_MISO 4 + +#define SCXI_DIO_NONE 0 +#define SCXI_DIO_DO 1 +#define SCXI_DIO_DI 2 + +#define SCXI_AIO_NONE 0 +#define SCXI_AIO_AO 1 +#define SCXI_AIO_AI 2 + +struct scxi_board_struct { + unsigned int device_id; + char name[12]; + int modclass; + unsigned int clock_interval; + int dio_type, aio_type, channels, status_reg, data_reg; + int config_reg, eeprom_reg, gain_reg; +}; + +typedef struct scxi_board_struct scxi_board_t; + +const scxi_board_t scxi_boards[] = { + { 0, "unknown\0", 2, SLOW_INTERVAL, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0xffffffff, "empty\0", 2, SLOW_INTERVAL, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0x06, "SCXI-1100\0", 1, FAST_INTERVAL, SCXI_DIO_NONE, SCXI_AIO_AI, 32, + 0x00, 0x00, 0x00, 0x00, 0x00 }, + { 0x1e, "SCXI-1102\0", 2, FAST_INTERVAL, SCXI_DIO_NONE, SCXI_AIO_AI, 32, + 0x02, 0x05, 0x01, 0x03, 0x04 }, + //{ 0x14, "SCXI-1124\0", 2, SLOW_INTERVAL, SCXI_DIO_NONE, SCXI_AIO_AO, 6, + // 0x02, 0x08, 0x00, 0x03, 0x00 }, +}; + +#define n_scxi_boards ((sizeof(scxi_boards)/sizeof(scxi_boards[0]))) + +struct scxi_module_struct { + comedi_t *dev; + unsigned int board; + unsigned int dio_subdev, ser_subdev; + unsigned int chassis, slot; +}; + +typedef struct scxi_module_struct scxi_mod_t; + +#ifdef __cplusplus +extern "C" { +#endif + +int comedi_scxi_serial_readwrite(comedi_t *it, unsigned char out_bits, unsigned char *in_bits); +int comedi_scxi_serial_config(comedi_t *it, unsigned int clock_interval); + +#ifdef __cplusplus +} +#endif diff --git a/scxi/Makefile.am b/scxi/Makefile.am new file mode 100644 index 0000000..ba1823a --- /dev/null +++ b/scxi/Makefile.am @@ -0,0 +1,11 @@ + +if BUILD_SCXI +lib_LTLIBRARIES = libscxi.la +else +lib_LTLIBRARIES = +endif + +libscxi_la_SOURCES = scxi.c +libscxi_la_CFLAGS = $(COMEDILIB_CFLAGS) -D_REENTRANT +libscxi_la_LDFLAGS = -release $(VERSION) -Wl +libscxi_la_LIBADD = -lcomedi diff --git a/scxi/scxi.c b/scxi/scxi.c new file mode 100644 index 0000000..7c47034 --- /dev/null +++ b/scxi/scxi.c @@ -0,0 +1,43 @@ +#include "comedilib_scxi.h" + +int comedi_scxi_serial_config(comedi_t *it, unsigned int clock_interval) +{ + comedi_insn insn; + lsampl_t data[2]; + + memset(&insn,0,sizeof(insn)); + insn.insn = INSN_CONFIG; + insn.n = 2; + insn.data = &data[0]; + insn.subdev = comedi_find_subdevice_by_type(it, COMEDI_SUBD_SERIAL, 0); + data[0]=INSN_CONFIG_SERIAL_CLOCK; + data[1]=clock_interval; + + return comedi_do_insn(it,&insn); +} + +int comedi_scxi_serial_readwrite(comedi_t *it, unsigned char out_bits, unsigned char *in_bits) +{ + int ret; + comedi_insn insn; + lsampl_t data[2]; + + memset(&insn,0,sizeof(insn)); + + insn.insn = INSN_CONFIG; + insn.n = 2; + insn.data = data; + insn.subdev = comedi_find_subdevice_by_type(it, COMEDI_SUBD_SERIAL, 0); + + data[0]=INSN_CONFIG_BIDIRECTIONAL_DATA; + data[1]=out_bits; + + ret = comedi_do_insn(it,&insn); + + if(ret<0) return ret; + + if(in_bits) + *in_bits = data[1]; + + return 0; +} -- 2.26.2