From a06bba542a9b2305b0d455294017160da65697c7 Mon Sep 17 00:00:00 2001 From: Frank Mori Hess Date: Wed, 23 Jan 2008 18:56:52 +0000 Subject: [PATCH] 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. --- demo/gpct_buffered_counting.c | 8 +-- demo/gpct_encoder.c | 12 ++-- demo/gpct_pulse_generator.c | 6 +- demo/gpct_simple_counting.c | 6 +- doc/extensions_funcref.txt | 104 ++++++++++++++++++++++++++++++++-- include/comedilib.h | 10 +++- lib/insn_config_wrappers.c | 82 +++++++++++++++++++++++++-- lib/version_script | 3 + 8 files changed, 202 insertions(+), 29 deletions(-) diff --git a/demo/gpct_buffered_counting.c b/demo/gpct_buffered_counting.c index 77f20d4..39d099a 100644 --- a/demo/gpct_buffered_counting.c +++ b/demo/gpct_buffered_counting.c @@ -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.*/ diff --git a/demo/gpct_encoder.c b/demo/gpct_encoder.c index 91e2a43..f535424 100644 --- a/demo/gpct_encoder.c +++ b/demo/gpct_encoder.c @@ -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); diff --git a/demo/gpct_pulse_generator.c b/demo/gpct_pulse_generator.c index 6026507..c236621 100644 --- a/demo/gpct_pulse_generator.c +++ b/demo/gpct_pulse_generator.c @@ -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 */ diff --git a/demo/gpct_simple_counting.c b/demo/gpct_simple_counting.c index a114f00..649dd52 100644 --- a/demo/gpct_simple_counting.c +++ b/demo/gpct_simple_counting.c @@ -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 diff --git a/doc/extensions_funcref.txt b/doc/extensions_funcref.txt index afcb545..0c1a8e3 100644 --- a/doc/extensions_funcref.txt +++ b/doc/extensions_funcref.txt @@ -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 + comedi_set_clock_source(). + The currently configured master clock + will be written to *clock. + 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 + *period_ns. + + It is safe to pass NULL pointers as the clock or + period_ns + 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 + comedi_set_gate_source(). + The currently configured gate source + will be written to *gate_source. + 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 + channel 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 + comedi_set_routing(). + The currently configured routing + will be written to *routing. + 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 comedi_get_clock_source() + 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 - mode parameter is driver-dependent. It is only useable + mode parameter is driver-dependent. + If the subdevice does not + support configuring its mode on a per-channel basis, then the + channel + 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 gate_source 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 + channel parameter will be ignored. + You may query the gate source with the comedi_get_gate_source() + 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 other parameter selects which "other" we are configuring, and is driver-dependent. The source 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 + channel + 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 + comedi_get_routing() function. This function is only useable on subdevices that provide support for the INSN_CONFIG_SET_ROUTING configuration instruction. diff --git a/include/comedilib.h b/include/comedilib.h index 009ad85..db2eb95 100644 --- a/include/comedilib.h +++ b/include/comedilib.h @@ -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); diff --git a/lib/insn_config_wrappers.c b/lib/insn_config_wrappers.c index 88d4a29..3d86afd 100644 --- a/lib/insn_config_wrappers.c +++ b/lib/insn_config_wrappers.c @@ -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; diff --git a/lib/version_script b/lib/version_script index d6e116c..2b608ab 100644 --- a/lib/version_script +++ b/lib/version_script @@ -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; -- 2.26.2