Added more INSN_CONFIG wrappers: comedi_get_clock_source(),

comedi_get_gate_source(), and comedi_get_routing().  Added "channel"
parameter to some of the INSN_CONFIG wrappers.
This commit is contained in:
Frank Mori Hess 2008-01-23 18:56:52 +00:00
parent 76791bfeed
commit a06bba542a
8 changed files with 202 additions and 29 deletions

View file

@ -78,13 +78,13 @@ int ni_gpct_configure_buffered_event_counting(comedi_t *device, unsigned subdevi
#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"
@ -106,7 +106,7 @@ int ni_gpct_configure_buffered_event_counting(comedi_t *device, unsigned subdevi
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.*/

View file

@ -43,11 +43,11 @@ int ni_gpct_start_encoder(comedi_t *device, unsigned subdevice,
/* 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);
@ -55,7 +55,7 @@ int ni_gpct_start_encoder(comedi_t *device, unsigned subdevice,
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);

View file

@ -45,9 +45,9 @@ int ni_gpct_start_pulse_generator(comedi_t *device, unsigned subdevice, unsigned
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"
@ -69,7 +69,7 @@ int ni_gpct_start_pulse_generator(comedi_t *device, unsigned subdevice, unsigned
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 */

View file

@ -39,9 +39,9 @@ int ni_gpct_start_simple_event_counting(comedi_t *device, unsigned subdevice)
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"
@ -61,7 +61,7 @@ int ni_gpct_start_simple_event_counting(comedi_t *device, unsigned subdevice)
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

View file

@ -14,6 +14,80 @@ Description:
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
@ -45,6 +119,9 @@ Description:
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.
@ -55,11 +132,18 @@ Function: comedi_set_counter_mode -- change mode of a counter subdevice
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:
@ -91,6 +175,8 @@ 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
@ -101,8 +187,12 @@ Description:
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.
@ -113,6 +203,7 @@ Function: comedi_set_other_source -- select source signal for something other th
Retval: int
Param: comedi_t * device
Param: unsigned int subdevice
Param: unsigned int channel
Param: unsigned int other
Param: unsigned int source
Status: alpha
@ -122,7 +213,10 @@ Description:
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
@ -137,7 +231,7 @@ Description:
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
@ -151,6 +245,8 @@ Description:
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.

View file

@ -275,11 +275,15 @@ int comedi_internal_trigger(comedi_t *dev, unsigned subd, unsigned trignum);
/* 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);

View file

@ -63,8 +63,77 @@ int _comedi_arm(comedi_t *device, unsigned subdevice, unsigned target)
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];
@ -72,7 +141,7 @@ int _comedi_set_counter_mode(comedi_t *device, unsigned subdevice, unsigned mode
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;
@ -122,7 +191,8 @@ int _comedi_set_filter(comedi_t *device, unsigned subdevice, unsigned channel, u
}
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];
@ -130,7 +200,7 @@ int _comedi_set_gate_source(comedi_t *device, unsigned subdevice, unsigned gate_
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;
@ -161,7 +231,7 @@ int comedi_internal_trigger(comedi_t *dev, unsigned subd, unsigned trignum)
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];
@ -170,7 +240,7 @@ int _comedi_set_other_source(comedi_t *device, unsigned subdevice,
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;

View file

@ -98,6 +98,9 @@ v0.9.0 {
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;