#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*/);
+ retval = comedi_set_gate_source(device, subdevice, 0, 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*/);
+ retval = comedi_set_gate_source(device, subdevice, 0, 0, NI_GPCT_GATE_PIN_i_GATE_SELECT /*| CR_EDGE*/);
#endif
if(retval < 0) return retval;
- retval = comedi_set_gate_source(device, subdevice, 1, NI_GPCT_DISABLED_GATE_SELECT | CR_EDGE);
+ retval = comedi_set_gate_source(device, subdevice, 0, 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 = comedi_set_counter_mode(device, subdevice, counter_mode);
+ retval = comedi_set_counter_mode(device, subdevice, 0, counter_mode);
if(retval < 0) return retval;
/* Set initial counter value by writing to channel 0.*/
/* set "load b" register to initial_value by writing to channel 2 */
retval = comedi_data_write(device, subdevice, 2, 0, 0, initial_value);
- 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);
+ comedi_set_gate_source(device, subdevice, 0, 0, NI_GPCT_DISABLED_GATE_SELECT);
+ comedi_set_gate_source(device, subdevice, 0, 1, NI_GPCT_DISABLED_GATE_SELECT);
+ comedi_set_other_source(device, subdevice, 0, NI_GPCT_SOURCE_ENCODER_A, a);
+ comedi_set_other_source(device, subdevice, 0, NI_GPCT_SOURCE_ENCODER_B, b);
+ comedi_set_other_source(device, subdevice, 0, 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 = comedi_set_counter_mode(device, subdevice, counter_mode);
+ retval = comedi_set_counter_mode(device, subdevice, 0, counter_mode);
if(retval < 0) return retval;
retval = comedi_arm(device, subdevice, NI_GPCT_ARM_IMMEDIATE);
retval = comedi_reset(device, subdevice);
if(retval < 0) return retval;
- retval = comedi_set_gate_source(device, subdevice, 0, NI_GPCT_DISABLED_GATE_SELECT | CR_EDGE);
+ retval = comedi_set_gate_source(device, subdevice, 0, 0, NI_GPCT_DISABLED_GATE_SELECT | CR_EDGE);
if(retval < 0) return retval;
- retval = comedi_set_gate_source(device, subdevice, 1, NI_GPCT_DISABLED_GATE_SELECT | CR_EDGE);
+ retval = comedi_set_gate_source(device, subdevice, 0, 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 = comedi_set_counter_mode(device, subdevice, counter_mode);
+ retval = comedi_set_counter_mode(device, subdevice, 0, counter_mode);
if(retval < 0) return retval;
/* 20MHz clock */
retval = comedi_reset(device, subdevice);
if(retval < 0) return retval;
- retval = comedi_set_gate_source(device, subdevice, 0, NI_GPCT_GATE_PIN_GATE_SELECT(0) /* NI_GPCT_GATE_PIN_i_GATE_SELECT *//*| CR_EDGE*/);
+ retval = comedi_set_gate_source(device, subdevice, 0, 0, NI_GPCT_GATE_PIN_GATE_SELECT(0) /* NI_GPCT_GATE_PIN_i_GATE_SELECT *//*| CR_EDGE*/);
if(retval < 0) return retval;
- retval = comedi_set_gate_source(device, subdevice, 1, NI_GPCT_DISABLED_GATE_SELECT | CR_EDGE);
+ retval = comedi_set_gate_source(device, subdevice, 0, 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 = comedi_set_counter_mode(device, subdevice, counter_mode);
+ retval = comedi_set_counter_mode(device, subdevice, 0, 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
Returns:
0 on success, -1 on error.
+Function: comedi_get_clock_source -- get master clock for a subdevice
+Retval: int
+Param: comedi_t * device
+Param: unsigned int subdevice
+Param: unsigned int *clock
+Param: unsigned int *period_ns
+Status: alpha
+Description:
+ This function queries the master clock for a subdevice, as
+ set by
+ <link linkend="func-ref-comedi-set-clock-source">comedi_set_clock_source()</link>.
+ The currently configured master clock
+ will be written to *<parameter>clock</parameter>.
+ The possible values and their corresponding clocks are
+ driver-dependant.
+ The frequency of the clock in nanoseconds (or zero if it is unknown)
+ will be written to
+ *<parameter>period_ns</parameter>.
+
+ It is safe to pass NULL pointers as the <parameter>clock</parameter> or
+ <parameter>period_ns</parameter>
+ parameters. This function is only useable
+ on subdevices that provide support for the INSN_CONFIG_GET_CLOCK_SOURCE
+ configuration instruction.
+Returns:
+ 0 on success, -1 on error.
+
+Function: comedi_get_gate_source -- get gate for a subdevice
+Retval: int
+Param: comedi_t * device
+Param: unsigned int subdevice
+Param: unsigned int channel
+Param: unsigned int gate_index
+Param: unsigned int *gate_source
+Status: alpha
+Description:
+ This function queries the gate for a subdevice, as
+ set by
+ <link linkend="func-ref-comedi-set-gate-source">comedi_set_gate_source()</link>.
+ The currently configured gate source
+ will be written to *<parameter>gate_source</parameter>.
+ The possible values and their corresponding gates are
+ driver-dependant. If the subdevice does not
+ support configuring its gates on a per-channel basis, then the
+ <parameter>channel</parameter> parameter will be ignored.
+
+ This function is only useable
+ on subdevices that provide support for the INSN_CONFIG_GET_GATE_SOURCE
+ configuration instruction.
+Returns:
+ 0 on success, -1 on error.
+
+Function: comedi_get_routing -- get routing for an output
+Retval: int
+Param: comedi_t * device
+Param: unsigned int subdevice
+Param: unsigned int channel
+Param: unsigned int *routing
+Status: alpha
+Description:
+ This function queries the routing for an output, as
+ set by
+ <link linkend="func-ref-comedi-set-routing">comedi_set_routing()</link>.
+ The currently configured routing
+ will be written to *<parameter>routing</parameter>.
+ The possible values and their corresponding routings are
+ driver-dependant.
+
+ This function is only useable
+ on subdevices that provide support for the INSN_CONFIG_GET_ROUTING
+ configuration instruction.
+Returns:
+ 0 on success, -1 on error.
+
Function: comedi_reset -- reset a subdevice
Retval: int
Param: comedi_t * device
the driver to support TRIG_TIMER sources in commands while
using the external clock.
+ The clock may be queried with the <link linkend="func-ref-comedi-get-clock-source">comedi_get_clock_source()</link>
+ function.
+
This function is only useable
on subdevices that provide support for the INSN_CONFIG_SET_CLOCK_SOURCE
configuration instruction.
Retval: int
Param: comedi_t * device
Param: unsigned int subdevice
+Param: unsigned int channel
Param: unsigned int mode
Status: alpha
Description:
This function configures a counter subdevice. The meaning of the
- <parameter>mode</parameter> parameter is driver-dependent. It is only useable
+ <parameter>mode</parameter> parameter is driver-dependent.
+ If the subdevice does not
+ support configuring its mode on a per-channel basis, then the
+ <parameter>channel</parameter>
+ parameter will be ignored.
+
+ It is only useable
on subdevices that provide support for the INSN_CONFIG_SET_COUNTER_MODE
configuration instruction.
Returns:
Function: comedi_set_gate_source -- select gate source for a subdevice
Retval: int
Param: comedi_t * device
+Param: unsigned int subdevice
+Param: unsigned int channel
Param: unsigned int gate_index
Param: unsigned int gate_source
Status: alpha
from 0 to N-1 for a subdevice with N different gates.
The <parameter>gate_source</parameter> parameter selects which signal you wish to
use as
- the gate, and is also driver-dependent.
+ the gate, and is also driver-dependent. If the subdevice does not
+ support configuring its gates on a per-channel basis, then the
+ <parameter>channel</parameter> parameter will be ignored.
+ You may query the gate source with the <link linkend="func-ref-comedi-get-gate-source">comedi_get_gate_source()</link>
+ function.
This function is only useable
on subdevices that provide support for the INSN_CONFIG_SET_GATE_SOURCE
configuration instruction.
Retval: int
Param: comedi_t * device
Param: unsigned int subdevice
+Param: unsigned int channel
Param: unsigned int other
Param: unsigned int source
Status: alpha
comedi_set_clock_source()). The <parameter>other</parameter> parameter selects
which "other" we are configuring, and is driver-dependent. The
<parameter>source</parameter> selects the source we which to use for the
- "other".
+ "other". If the subdevice does not
+ support configuring its "other" sources on a per-channel basis, then the
+ <parameter>channel</parameter>
+ parameter will be ignored.
As an example, this function is used to select which PFI digital input channels
should be used as the A/B/Z signals when running a counter on an NI M-Series board as
Returns:
0 on success, -1 on error.
-Function: comedi_set_routing -- select a signal for an output
+Function: comedi_set_routing -- select a routing for an output
Retval: int
Param: comedi_t * device
Param: unsigned int subdevice
parameter selects which signal should be routed to appear on the
selected output channel, and is driver-dependant.
+ The routing may be queried with the
+ <link linkend="func-ref-comedi-get-routing">comedi_get_routing()</link> function.
This function is only useable
on subdevices that provide support for the INSN_CONFIG_SET_ROUTING
configuration instruction.
/* INSN_CONFIG wrappers */
int comedi_arm(comedi_t *device, unsigned subdevice, unsigned source);
int comedi_reset(comedi_t *device, unsigned subdevice);
-int comedi_set_counter_mode(comedi_t *device, unsigned subdevice, unsigned mode_bits);
+int comedi_get_clock_source(comedi_t *device, unsigned subdevice, unsigned *clock, unsigned *period_ns);
+int comedi_get_gate_source(comedi_t *device, unsigned subdevice, unsigned channel,
+ unsigned gate, unsigned *source);
+int comedi_get_routing(comedi_t *device, unsigned subdevice, unsigned channel, unsigned *routing);
+int comedi_set_counter_mode(comedi_t *device, unsigned subdevice, unsigned channel, unsigned mode_bits);
int comedi_set_clock_source(comedi_t *device, unsigned subdevice, unsigned clock, unsigned period_ns);
int comedi_set_filter(comedi_t *device, unsigned subdevice, unsigned channel, unsigned filter);
-int comedi_set_gate_source(comedi_t *device, unsigned subdevice, unsigned gate_index, unsigned gate_source);
-int comedi_set_other_source(comedi_t *device, unsigned subdevice,
+int comedi_set_gate_source(comedi_t *device, unsigned subdevice, unsigned channel, unsigned gate_index, unsigned gate_source);
+int comedi_set_other_source(comedi_t *device, unsigned subdevice, unsigned channel,
unsigned other, unsigned source);
int comedi_set_routing(comedi_t *device, unsigned subdevice, unsigned channel, unsigned routing);
else return -1;
}
+EXPORT_ALIAS_DEFAULT(_comedi_get_clock_source,comedi_get_clock_source,0.9.0);
+int _comedi_get_clock_source(comedi_t *device, unsigned subdevice, unsigned *clock, unsigned *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]);
+ memset(data, 0, insn.n * sizeof(data[0]));
+ data[0] = INSN_CONFIG_GET_CLOCK_SRC;
+
+ retval = comedi_do_insn(device, &insn);
+ if(retval < 0) return -1;
+ if(clock) *clock = insn.data[1];
+ if(period_ns) *period_ns = insn.data[2];
+ return 0;
+}
+
+EXPORT_ALIAS_DEFAULT(_comedi_get_gate_source,comedi_get_gate_source,0.9.0);
+int _comedi_get_gate_source(comedi_t *device, unsigned subdevice, unsigned channel,
+ unsigned gate, 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 = channel;
+ insn.data = data;
+ insn.n = sizeof(data) / sizeof(data[0]);
+ memset(insn.data, 0, insn.n * sizeof(insn.data[0]));
+ data[0] = INSN_CONFIG_GET_GATE_SRC;
+ data[1] = gate;
+
+ retval = comedi_do_insn(device, &insn);
+ if(retval < 0) return -1;
+ if(source) *source = insn.data[2];
+ return 0;
+}
+
+EXPORT_ALIAS_DEFAULT(_comedi_get_routing,comedi_get_routing,0.9.0);
+int _comedi_get_routing(comedi_t *device, unsigned subdevice, unsigned channel, unsigned *routing)
+{
+ comedi_insn insn;
+ lsampl_t data[2];
+ int retval;
+
+ memset(&insn, 0, sizeof(comedi_insn));
+ insn.insn = INSN_CONFIG;
+ insn.subdev = subdevice;
+ insn.chanspec = channel;
+ insn.data = data;
+ insn.n = sizeof(data) / sizeof(data[0]);
+ memset(insn.data, 0, insn.n * sizeof(insn.data[0]));
+ data[0] = INSN_CONFIG_GET_ROUTING;
+
+ retval = comedi_do_insn(device, &insn);
+ if(retval < 0) return -1;
+ if(routing) *routing = insn.data[1];
+ return 0;
+}
+
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)
+int _comedi_set_counter_mode(comedi_t *device, unsigned subdevice, unsigned channel, 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.chanspec = channel;
insn.data = data;
insn.n = sizeof(data) / sizeof(data[0]);
data[0] = INSN_CONFIG_SET_COUNTER_MODE;
}
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)
+int _comedi_set_gate_source(comedi_t *device, unsigned subdevice, unsigned channel,
+ 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.chanspec = channel;
insn.data = data;
insn.n = sizeof(data) / sizeof(data[0]);
data[0] = INSN_CONFIG_SET_GATE_SRC;
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)
+ unsigned channel, unsigned other, unsigned 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.chanspec = channel;
insn.data = data;
insn.n = sizeof(data) / sizeof(data[0]);
data[0] = INSN_CONFIG_SET_OTHER_SRC;
comedi_get_cmd_generic_timed;
comedi_reset;
comedi_arm;
+ comedi_get_clock_source;
+ comedi_get_gate_source;
+ comedi_get_routing;
comedi_set_counter_mode;
comedi_set_clock_source;
comedi_set_filter;