Will add some reference documentation for the new functions soon.
-AC_INIT([comedilib], [0.8.1])
+AC_INIT([comedilib], [0.9.0])
AC_CANONICAL_TARGET([])
AC_CONFIG_AUX_DIR([.])
# age to 0.
#
# AS_LIBTOOL arguments are (prefix, current, revision, age)
-AS_LIBTOOL(COMEDILIB, 8, 1, 8)
+AS_LIBTOOL(COMEDILIB, 9, 0, 9)
#libscxi c:r:a
-SCXI_SO_VERSION=8:0:8
+SCXI_SO_VERSION=9:0:9
AC_SUBST(SCXI_SO_VERSION)
AM_CONFIG_HEADER(config.h)
cmd_src(cmd->stop_src,buf),
cmd->stop_arg);
}
-
-int arm(comedi_t *device, unsigned subdevice, lsampl_t source)
-{
- comedi_insn insn;
- lsampl_t data[2];
- int retval;
-
- memset(&insn, 0, sizeof(comedi_insn));
- insn.insn = INSN_CONFIG;
- insn.subdev = subdevice;
- insn.chanspec = 0;
- insn.data = data;
- insn.n = sizeof(data) / sizeof(data[0]);
- data[0] = INSN_CONFIG_ARM;
- data[1] = source;
-
- retval = comedi_do_insn(device, &insn);
- if(retval < 0)
- {
- fprintf(stderr, "%s: error:\n", __FUNCTION__);
- comedi_perror("comedi_do_insn");
- return retval;
- }
- return 0;
-}
-
-/* This resets the count to zero and disarms the counter. The counter output
- is set low. */
-int reset_counter(comedi_t *device, unsigned subdevice)
-{
- comedi_insn insn;
- lsampl_t data[1];
- int retval;
-
- memset(&insn, 0, sizeof(comedi_insn));
- insn.insn = INSN_CONFIG;
- insn.subdev = subdevice;
- insn.chanspec = 0;
- insn.data = data;
- insn.n = sizeof(data) / sizeof(data[0]);
- data[0] = INSN_CONFIG_RESET;
-
- retval = comedi_do_insn(device, &insn);
- if(retval < 0)
- {
- fprintf(stderr, "%s: error:\n", __FUNCTION__);
- comedi_perror("comedi_do_insn");
- return retval;
- }
- return 0;
-}
-
-int set_counter_mode(comedi_t *device, unsigned subdevice, lsampl_t mode_bits)
-{
- comedi_insn insn;
- lsampl_t data[2];
- int retval;
-
- memset(&insn, 0, sizeof(comedi_insn));
- insn.insn = INSN_CONFIG;
- insn.subdev = subdevice;
- insn.chanspec = 0;
- insn.data = data;
- insn.n = sizeof(data) / sizeof(data[0]);
- data[0] = INSN_CONFIG_SET_COUNTER_MODE;
- data[1] = mode_bits;
-
- retval = comedi_do_insn(device, &insn);
- if(retval < 0)
- {
- fprintf(stderr, "%s: error:\n", __FUNCTION__);
- comedi_perror("comedi_do_insn");
- return retval;
- }
- return 0;
-}
-
-int set_clock_source(comedi_t *device, unsigned subdevice, lsampl_t clock, lsampl_t period_ns)
-{
- comedi_insn insn;
- lsampl_t data[3];
- int retval;
-
- memset(&insn, 0, sizeof(comedi_insn));
- insn.insn = INSN_CONFIG;
- insn.subdev = subdevice;
- insn.chanspec = 0;
- insn.data = data;
- insn.n = sizeof(data) / sizeof(data[0]);
- data[0] = INSN_CONFIG_SET_CLOCK_SRC;
- data[1] = clock;
- data[2] = period_ns;
-
- retval = comedi_do_insn(device, &insn);
- if(retval < 0)
- {
- fprintf(stderr, "%s: error:\n", __FUNCTION__);
- comedi_perror("comedi_do_insn");
- return retval;
- }
- return 0;
-}
-
-int set_gate_source(comedi_t *device, unsigned subdevice, lsampl_t gate_index, lsampl_t gate_source)
-{
- comedi_insn insn;
- lsampl_t data[3];
- int retval;
-
- memset(&insn, 0, sizeof(comedi_insn));
- insn.insn = INSN_CONFIG;
- insn.subdev = subdevice;
- insn.chanspec = 0;
- insn.data = data;
- insn.n = sizeof(data) / sizeof(data[0]);
- data[0] = INSN_CONFIG_SET_GATE_SRC;
- data[1] = gate_index;
- data[2] = gate_source;
-
- retval = comedi_do_insn(device, &insn);
- if(retval < 0)
- {
- fprintf(stderr, "%s: error:\n", __FUNCTION__);
- comedi_perror("comedi_do_insn");
- return retval;
- }
- return 0;
-}
-
-int comedi_internal_trigger(comedi_t *dev, unsigned int subd, unsigned int trignum)
-{
- comedi_insn insn;
- lsampl_t data[1];
-
- memset(&insn, 0, sizeof(comedi_insn));
- insn.insn = INSN_INTTRIG;
- insn.subdev = subd;
- insn.data = data;
- insn.n = 1;
-
- data[0] = trignum;
-
- return comedi_do_insn(dev, &insn);
-}
extern int parse_options(struct parsed_options *options, int argc, char *argv[]);
extern char *cmd_src(int src,char *buf);
extern void dump_cmd(FILE *file,comedi_cmd *cmd);
-/* some helper functions used primarily for counter demos */
-extern int arm(comedi_t *device, unsigned subdevice, lsampl_t source);
-extern int reset_counter(comedi_t *device, unsigned subdevice);
-extern int set_counter_mode(comedi_t *device, unsigned subdevice, lsampl_t mode_bits);
-extern int set_clock_source(comedi_t *device, unsigned subdevice, lsampl_t clock, lsampl_t period_ns);
-extern int set_gate_source(comedi_t *device, unsigned subdevice, lsampl_t gate_index, lsampl_t gate_source);
-extern int comedi_internal_trigger(comedi_t *dev, unsigned int subd, unsigned int trignum);
#define sec_to_nsec(x) ((x)*1000000000)
#define sec_to_usec(x) ((x)*1000000)
static const unsigned gate_pfi_channel = 1;
static const unsigned initial_count = 0;
- retval = reset_counter(device, subdevice);
+ retval = comedi_reset(device, subdevice);
if(retval < 0) return retval;
- retval = set_gate_source(device, subdevice, 0, NI_GPCT_PFI_GATE_SELECT(gate_pfi_channel) /*| CR_EDGE*/);
+#if 1
+ // PFI gate select works for e and m series
+ retval = comedi_set_gate_source(device, subdevice, 0, NI_GPCT_PFI_GATE_SELECT(gate_pfi_channel) /*| CR_EDGE*/);
+#else
+ // gate pin gate select works for 660x
+ retval = comedi_set_gate_source(device, subdevice, 0, NI_GPCT_GATE_PIN_i_GATE_SELECT /*| CR_EDGE*/);
+#endif
if(retval < 0) return retval;
- retval = set_gate_source(device, subdevice, 1, NI_GPCT_DISABLED_GATE_SELECT | CR_EDGE);
+ retval = comedi_set_gate_source(device, subdevice, 1, NI_GPCT_DISABLED_GATE_SELECT | CR_EDGE);
if(retval < 0)
{
fprintf(stderr, "Failed to set second gate source. This is expected for older boards (e-series, etc.)\n"
counter_mode |= NI_GPCT_STOP_ON_GATE_BITS;
// don't disarm on terminal count or gate signal
counter_mode |= NI_GPCT_NO_HARDWARE_DISARM_BITS;
- retval = set_counter_mode(device, subdevice, counter_mode);
+ retval = comedi_set_counter_mode(device, subdevice, counter_mode);
if(retval < 0) return retval;
/* Set initial counter value by writing to channel 0.*/
int ni_gpct_read_and_dump_counts(comedi_t *device, unsigned subdevice)
{
- char subdevice_filename[100];
int retval;
int fd;
static const unsigned buffer_size = 1000;
}
if(retval < 0)
{
- fprintf(stderr, "error reading from subdevice file \"%s\".\n", subdevice_filename);
+ fprintf(stderr, "error reading from subdevice file.\n");
perror("read");
return -errno;
}
#include <ctype.h>
#include "examples.h"
-int set_other_source(comedi_t *device, unsigned subdevice,
- lsampl_t index, lsampl_t source)
-{
- comedi_insn insn;
- lsampl_t data[3];
- int retval;
-
- memset(&insn, 0, sizeof(comedi_insn));
- insn.insn = INSN_CONFIG;
- insn.subdev = subdevice;
- insn.chanspec = 0;
- insn.data = data;
- insn.n = sizeof(data) / sizeof(data[0]);
- data[0] = INSN_CONFIG_SET_OTHER_SRC;
- data[1] = index;
- data[2] = source;
-
- retval = comedi_do_insn(device, &insn);
- if(retval < 0)
- {
- fprintf(stderr, "%s: error:\n", __FUNCTION__);
- comedi_perror("comedi_do_insn");
- return retval;
- }
- return 0;
-}
-
int ni_gpct_start_encoder(comedi_t *device, unsigned subdevice,
unsigned int initial_value,
int a, int b, int z)
lsampl_t counter_mode;
- retval = reset_counter(device, subdevice);
+ retval = comedi_reset(device, subdevice);
/* set initial counter value by writing to channel 0 */
retval = comedi_data_write(device, subdevice, 0, 0, 0, initial_value);
/* set "load a" register to initial_value by writing to channel 1 */
/* set "load b" register to initial_value by writing to channel 2 */
retval = comedi_data_write(device, subdevice, 2, 0, 0, initial_value);
- set_gate_source(device, subdevice, 0, NI_GPCT_DISABLED_GATE_SELECT);
- set_gate_source(device, subdevice, 1, NI_GPCT_DISABLED_GATE_SELECT);
- set_other_source(device, subdevice, NI_GPCT_SOURCE_ENCODER_A, a);
- set_other_source(device, subdevice, NI_GPCT_SOURCE_ENCODER_B, b);
- set_other_source(device, subdevice, NI_GPCT_SOURCE_ENCODER_Z, z);
+ comedi_set_gate_source(device, subdevice, 0, NI_GPCT_DISABLED_GATE_SELECT);
+ comedi_set_gate_source(device, subdevice, 1, NI_GPCT_DISABLED_GATE_SELECT);
+ comedi_set_other_source(device, subdevice, NI_GPCT_SOURCE_ENCODER_A, a);
+ comedi_set_other_source(device, subdevice, NI_GPCT_SOURCE_ENCODER_B, b);
+ comedi_set_other_source(device, subdevice, NI_GPCT_SOURCE_ENCODER_Z, z);
counter_mode = (NI_GPCT_COUNTING_MODE_QUADRATURE_X4_BITS |
NI_GPCT_COUNTING_DIRECTION_HW_UP_DOWN_BITS);
counter_mode |= (NI_GPCT_INDEX_ENABLE_BIT |
NI_GPCT_INDEX_PHASE_HIGH_A_HIGH_B_BITS);
}
- retval = set_counter_mode(device, subdevice, counter_mode);
+ retval = comedi_set_counter_mode(device, subdevice, counter_mode);
if(retval < 0) return retval;
- retval = arm(device, subdevice, NI_GPCT_ARM_IMMEDIATE);
+ retval = comedi_arm(device, subdevice, NI_GPCT_ARM_IMMEDIATE);
if(retval < 0) return retval;
return 0;
const unsigned clock_period_ns = 50; /* 20MHz clock */
unsigned up_ticks, down_ticks;
- retval = reset_counter(device, subdevice);
+ retval = comedi_reset(device, subdevice);
if(retval < 0) return retval;
- retval = set_gate_source(device, subdevice, 0, NI_GPCT_DISABLED_GATE_SELECT | CR_EDGE);
+ retval = comedi_set_gate_source(device, subdevice, 0, NI_GPCT_DISABLED_GATE_SELECT | CR_EDGE);
if(retval < 0) return retval;
- retval = set_gate_source(device, subdevice, 1, NI_GPCT_DISABLED_GATE_SELECT | CR_EDGE);
+ retval = comedi_set_gate_source(device, subdevice, 1, NI_GPCT_DISABLED_GATE_SELECT | CR_EDGE);
if(retval < 0)
{
fprintf(stderr, "Failed to set second gate source. This is expected for older boards (e-series, etc.)\n"
counter_mode |= NI_GPCT_STOP_ON_GATE_BITS;
// don't disarm on terminal count or gate signal
counter_mode |= NI_GPCT_NO_HARDWARE_DISARM_BITS;
- retval = set_counter_mode(device, subdevice, counter_mode);
+ retval = comedi_set_counter_mode(device, subdevice, counter_mode);
if(retval < 0) return retval;
/* 20MHz clock */
- retval = set_clock_source(device, subdevice, NI_GPCT_TIMEBASE_1_CLOCK_SRC_BITS, clock_period_ns);
+ retval = comedi_set_clock_source(device, subdevice, NI_GPCT_TIMEBASE_1_CLOCK_SRC_BITS, clock_period_ns);
if(retval < 0) return retval;
up_ticks = (up_time_ns + clock_period_ns / 2) / clock_period_ns;
comedi_data_write(device, subdevice, 2, 0, 0, up_ticks);
if(retval < 0) return retval;
- retval = arm(device, subdevice, NI_GPCT_ARM_IMMEDIATE);
+ retval = comedi_arm(device, subdevice, NI_GPCT_ARM_IMMEDIATE);
if(retval < 0) return retval;
return 0;
lsampl_t counter_mode;
static const unsigned initial_count = 0;
- retval = reset_counter(device, subdevice);
+ retval = comedi_reset(device, subdevice);
if(retval < 0) return retval;
- retval = set_gate_source(device, subdevice, 0, NI_GPCT_DISABLED_GATE_SELECT | CR_EDGE);
+ retval = comedi_set_gate_source(device, subdevice, 0, NI_GPCT_GATE_PIN_GATE_SELECT(0) /* NI_GPCT_GATE_PIN_i_GATE_SELECT *//*| CR_EDGE*/);
if(retval < 0) return retval;
- retval = set_gate_source(device, subdevice, 1, NI_GPCT_DISABLED_GATE_SELECT | CR_EDGE);
+ retval = comedi_set_gate_source(device, subdevice, 1, NI_GPCT_DISABLED_GATE_SELECT | CR_EDGE);
if(retval < 0)
{
fprintf(stderr, "Failed to set second gate source. This is expected for older boards (e-series, etc.)\n"
counter_mode |= NI_GPCT_STOP_ON_GATE_BITS;
// don't disarm on terminal count or gate signal
counter_mode |= NI_GPCT_NO_HARDWARE_DISARM_BITS;
- retval = set_counter_mode(device, subdevice, counter_mode);
+ retval = comedi_set_counter_mode(device, subdevice, counter_mode);
if(retval < 0) return retval;
/* set initial counter value by writing to channel 0. The "load a" and "load b" registers can be
set by writing to channels 1 and 2 respectively. */
retval = comedi_data_write(device, subdevice, 0, 0, 0, initial_count);
- retval = arm(device, subdevice, NI_GPCT_ARM_IMMEDIATE);
+ retval = comedi_arm(device, subdevice, NI_GPCT_ARM_IMMEDIATE);
if(retval < 0) return retval;
return 0;
lsampl_t comedi_from_physical(double data,
const comedi_polynomial_t *conversion_polynomial);
+/* INSN_CONFIG wrappers */
+int comedi_reset(comedi_t *device, unsigned subdevice);
+int comedi_arm(comedi_t *device, unsigned subdevice, unsigned target);
+int comedi_set_counter_mode(comedi_t *device, unsigned subdevice, unsigned mode_bits);
+int comedi_set_clock_source(comedi_t *device, unsigned subdevice, unsigned clock, unsigned period_ns);
+int comedi_set_gate_source(comedi_t *device, unsigned subdevice, unsigned gate_index, unsigned gate_source);
+int comedi_internal_trigger(comedi_t *dev, unsigned subd, unsigned trignum);
+int comedi_set_other_source(comedi_t *device, unsigned subdevice,
+ unsigned other, unsigned source);
+
#endif
#ifdef __cplusplus
libcomedi_la_SOURCES = \
buffer.c calib.c cmd.c comedi.c data.c dio.c error.c \
filler.c get.c ioctl.c range.c sv.c timed.c timer.c \
- calib_lex.c calib_yacc.c
+ calib_lex.c calib_yacc.c insn_config_wrappers.c
libcomedi_la_CFLAGS = $(COMEDILIB_CFLAGS) -D_REENTRANT -DLOCALSTATEDIR=\"\$(localstatedir)\"
-
libcomedi_la_LDFLAGS = -soname libcomedi \
$(COMEDILIB_LT_LDFLAGS) \
-Wl,--version-script=$(srcdir)/version_script
$(srcdir)/calib_lex.c $(srcdir)/calib_lex.h: $(srcdir)/calib_lex.l
$(LEX) --header-file=$(srcdir)/calib_lex.h -Pcalib_yy -o$(srcdir)/calib_lex.c $<
-
--- /dev/null
+/*
+ lib/insn_config_wrappers.c
+ wrappers for various INSN_CONFIG instructions
+
+ COMEDILIB - Linux Control and Measurement Device Interface Library
+ Copyright (C) 1997-2001 David A. Schleef <ds@schleef.org>
+ Copyright (C) 2008 Frank Mori Hess <fmhess@users.sourceforge.net>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+*/
+
+#include <string.h>
+
+#include "libinternal.h"
+
+EXPORT_ALIAS_DEFAULT(_comedi_reset,comedi_reset,0.9.0);
+int _comedi_reset(comedi_t *device, unsigned subdevice)
+{
+ comedi_insn insn;
+ lsampl_t data[1];
+
+ memset(&insn, 0, sizeof(comedi_insn));
+ insn.insn = INSN_CONFIG;
+ insn.subdev = subdevice;
+ insn.chanspec = 0;
+ insn.data = data;
+ insn.n = sizeof(data) / sizeof(data[0]);
+ data[0] = INSN_CONFIG_RESET;
+
+ return comedi_do_insn(device, &insn);
+}
+
+EXPORT_ALIAS_DEFAULT(_comedi_arm,comedi_arm,0.9.0);
+int _comedi_arm(comedi_t *device, unsigned subdevice, unsigned target)
+{
+ comedi_insn insn;
+ lsampl_t data[2];
+
+ memset(&insn, 0, sizeof(comedi_insn));
+ insn.insn = INSN_CONFIG;
+ insn.subdev = subdevice;
+ insn.chanspec = 0;
+ insn.data = data;
+ insn.n = sizeof(data) / sizeof(data[0]);
+ data[0] = INSN_CONFIG_ARM;
+ data[1] = target;
+
+ return comedi_do_insn(device, &insn);
+}
+
+EXPORT_ALIAS_DEFAULT(_comedi_set_counter_mode,comedi_set_counter_mode,0.9.0);
+int _comedi_set_counter_mode(comedi_t *device, unsigned subdevice, unsigned mode_bits)
+{
+ comedi_insn insn;
+ lsampl_t data[2];
+
+ memset(&insn, 0, sizeof(comedi_insn));
+ insn.insn = INSN_CONFIG;
+ insn.subdev = subdevice;
+ insn.chanspec = 0;
+ insn.data = data;
+ insn.n = sizeof(data) / sizeof(data[0]);
+ data[0] = INSN_CONFIG_SET_COUNTER_MODE;
+ data[1] = mode_bits;
+
+ return comedi_do_insn(device, &insn);
+}
+
+EXPORT_ALIAS_DEFAULT(_comedi_set_clock_source,comedi_set_clock_source,0.9.0);
+int _comedi_set_clock_source(comedi_t *device, unsigned subdevice, unsigned clock, unsigned period_ns)
+{
+ comedi_insn insn;
+ lsampl_t data[3];
+
+ memset(&insn, 0, sizeof(comedi_insn));
+ insn.insn = INSN_CONFIG;
+ insn.subdev = subdevice;
+ insn.chanspec = 0;
+ insn.data = data;
+ insn.n = sizeof(data) / sizeof(data[0]);
+ data[0] = INSN_CONFIG_SET_CLOCK_SRC;
+ data[1] = clock;
+ data[2] = period_ns;
+
+ return comedi_do_insn(device, &insn);
+}
+
+EXPORT_ALIAS_DEFAULT(_comedi_set_gate_source,comedi_set_gate_source,0.9.0);
+int _comedi_set_gate_source(comedi_t *device, unsigned subdevice, unsigned gate_index, unsigned gate_source)
+{
+ comedi_insn insn;
+ lsampl_t data[3];
+
+ memset(&insn, 0, sizeof(comedi_insn));
+ insn.insn = INSN_CONFIG;
+ insn.subdev = subdevice;
+ insn.chanspec = 0;
+ insn.data = data;
+ insn.n = sizeof(data) / sizeof(data[0]);
+ data[0] = INSN_CONFIG_SET_GATE_SRC;
+ data[1] = gate_index;
+ data[2] = gate_source;
+
+ return comedi_do_insn(device, &insn);
+}
+
+EXPORT_ALIAS_DEFAULT(_comedi_internal_trigger,comedi_internal_trigger,0.9.0);
+int comedi_internal_trigger(comedi_t *dev, unsigned subd, unsigned trignum)
+{
+ comedi_insn insn;
+ lsampl_t data[1];
+
+ memset(&insn, 0, sizeof(comedi_insn));
+ insn.insn = INSN_INTTRIG;
+ insn.subdev = subd;
+ insn.data = data;
+ insn.n = 1;
+
+ data[0] = trignum;
+
+ return comedi_do_insn(dev, &insn);
+}
+
+EXPORT_ALIAS_DEFAULT(_comedi_set_other_source,comedi_set_other_source,0.9.0);
+int _comedi_set_other_source(comedi_t *device, unsigned subdevice,
+ unsigned other, unsigned source)
+{
+ comedi_insn insn;
+ lsampl_t data[3];
+ int retval;
+
+ memset(&insn, 0, sizeof(comedi_insn));
+ insn.insn = INSN_CONFIG;
+ insn.subdev = subdevice;
+ insn.chanspec = 0;
+ insn.data = data;
+ insn.n = sizeof(data) / sizeof(data[0]);
+ data[0] = INSN_CONFIG_SET_OTHER_SRC;
+ data[1] = other;
+ data[2] = source;
+
+ retval = comedi_do_insn(device, &insn);
+ if(retval < 0)
+ {
+ fprintf(stderr, "%s: error:\n", __FUNCTION__);
+ comedi_perror("comedi_do_insn");
+ return retval;
+ }
+ return 0;
+}
v0.9.0 {
global:
comedi_get_cmd_generic_timed;
+ comedi_reset;
+ comedi_arm;
+ comedi_set_counter_mode;
+ comedi_set_clock_source;
+ comedi_set_gate_source;
+ comedi_internal_trigger;
+ comedi_set_other_source;
} v0.8.0;