From efad7cccec8ab00043939b36de950ba2ced15f85 Mon Sep 17 00:00:00 2001 From: Uwe Hermann Date: Fri, 28 Jul 2017 21:29:12 +0200 Subject: [PATCH] drivers: SR_CONF_CAPTURE_RATIO fixes. Move the check for the capture ratio being 0..100 into the wrappers, drop unneeded helper functions, fix incorrect variable types, minor other consistency fixes. --- src/hardware/asix-sigma/api.c | 12 ++++-------- src/hardware/asix-sigma/protocol.h | 2 +- src/hardware/beaglelogic/api.c | 6 ++---- src/hardware/dreamsourcelab-dslogic/api.c | 2 +- src/hardware/fx2lafw/api.c | 2 +- src/hardware/fx2lafw/protocol.c | 2 +- src/hardware/ikalogic-scanalogic2/api.c | 9 ++++++--- src/hardware/ikalogic-scanalogic2/protocol.c | 19 ------------------- src/hardware/ikalogic-scanalogic2/protocol.h | 4 +--- src/hardware/lecroy-logicstudio/api.c | 2 -- src/hardware/lecroy-logicstudio/protocol.c | 2 +- src/hardware/openbench-logic-sniffer/api.c | 4 ---- .../openbench-logic-sniffer/protocol.h | 2 +- src/hardware/pipistrello-ols/api.c | 4 ---- src/hardware/pipistrello-ols/protocol.h | 2 +- src/hardware/saleae-logic16/api.c | 4 ++-- src/hardware/zeroplus-logic-cube/api.c | 3 ++- src/hardware/zeroplus-logic-cube/protocol.c | 16 +--------------- src/hardware/zeroplus-logic-cube/protocol.h | 3 +-- src/hwdriver.c | 9 +++++++++ 20 files changed, 35 insertions(+), 74 deletions(-) diff --git a/src/hardware/asix-sigma/api.c b/src/hardware/asix-sigma/api.c index 96cdb2a7..042793a8 100644 --- a/src/hardware/asix-sigma/api.c +++ b/src/hardware/asix-sigma/api.c @@ -193,7 +193,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { struct dev_context *devc; - uint64_t tmp; (void)cg; @@ -206,16 +205,13 @@ static int config_set(uint32_t key, GVariant *data, devc->limit_msec = g_variant_get_uint64(data); break; case SR_CONF_LIMIT_SAMPLES: - tmp = g_variant_get_uint64(data); - devc->limit_samples = tmp; - devc->limit_msec = sigma_limit_samples_to_msec(devc, tmp); + devc->limit_samples = g_variant_get_uint64(data); + devc->limit_msec = sigma_limit_samples_to_msec(devc, + devc->limit_samples); break; #if ASIX_SIGMA_WITH_TRIGGER case SR_CONF_CAPTURE_RATIO: - tmp = g_variant_get_uint64(data); - if (tmp > 100) - return SR_ERR; - devc->capture_ratio = tmp; + devc->capture_ratio = g_variant_get_uint64(data); break; #endif default: diff --git a/src/hardware/asix-sigma/protocol.h b/src/hardware/asix-sigma/protocol.h index 40206342..d59c95d2 100644 --- a/src/hardware/asix-sigma/protocol.h +++ b/src/hardware/asix-sigma/protocol.h @@ -264,7 +264,7 @@ struct dev_context { int num_channels; int cur_channels; int samples_per_event; - int capture_ratio; + uint64_t capture_ratio; struct sigma_trigger trigger; int use_triggers; struct sigma_state state; diff --git a/src/hardware/beaglelogic/api.c b/src/hardware/beaglelogic/api.c index ebe1522f..2f632e7c 100644 --- a/src/hardware/beaglelogic/api.c +++ b/src/hardware/beaglelogic/api.c @@ -227,9 +227,7 @@ static int config_set(uint32_t key, GVariant *data, return beaglelogic_set_triggerflags(devc); case SR_CONF_CAPTURE_RATIO: devc->capture_ratio = g_variant_get_uint64(data); - if (devc->capture_ratio > 100) - return SR_ERR; - return SR_OK; + break; default: return SR_ERR_NA; } @@ -279,7 +277,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) if ((trigger = sr_session_trigger_get(sdi->session))) { int pre_trigger_samples = 0; if (devc->limit_samples > 0) - pre_trigger_samples = devc->capture_ratio * devc->limit_samples/100; + pre_trigger_samples = (devc->capture_ratio * devc->limit_samples) / 100; devc->stl = soft_trigger_logic_new(sdi, trigger, pre_trigger_samples); if (!devc->stl) return SR_ERR_MALLOC; diff --git a/src/hardware/dreamsourcelab-dslogic/api.c b/src/hardware/dreamsourcelab-dslogic/api.c index 4e0a1d10..7ea5f6eb 100644 --- a/src/hardware/dreamsourcelab-dslogic/api.c +++ b/src/hardware/dreamsourcelab-dslogic/api.c @@ -464,7 +464,7 @@ static int config_set(uint32_t key, GVariant *data, break; case SR_CONF_CAPTURE_RATIO: devc->capture_ratio = g_variant_get_uint64(data); - return (devc->capture_ratio > 100) ? SR_ERR : SR_OK; + break; case SR_CONF_VOLTAGE_THRESHOLD: if (!strcmp(devc->profile->model, "DSLogic")) { if ((idx = std_double_tuple_idx(data, ARRAY_AND_SIZE(voltage_thresholds))) < 0) diff --git a/src/hardware/fx2lafw/api.c b/src/hardware/fx2lafw/api.c index c72daa7f..34c5bc41 100644 --- a/src/hardware/fx2lafw/api.c +++ b/src/hardware/fx2lafw/api.c @@ -508,7 +508,7 @@ static int config_set(uint32_t key, GVariant *data, break; case SR_CONF_CAPTURE_RATIO: devc->capture_ratio = g_variant_get_uint64(data); - return (devc->capture_ratio > 100) ? SR_ERR : SR_OK; + break; default: return SR_ERR_NA; } diff --git a/src/hardware/fx2lafw/protocol.c b/src/hardware/fx2lafw/protocol.c index e88bbd2f..fc6fd331 100644 --- a/src/hardware/fx2lafw/protocol.c +++ b/src/hardware/fx2lafw/protocol.c @@ -614,7 +614,7 @@ static int start_transfers(const struct sr_dev_inst *sdi) if ((trigger = sr_session_trigger_get(sdi->session))) { int pre_trigger_samples = 0; if (devc->limit_samples > 0) - pre_trigger_samples = devc->capture_ratio * devc->limit_samples/100; + pre_trigger_samples = (devc->capture_ratio * devc->limit_samples) / 100; devc->stl = soft_trigger_logic_new(sdi, trigger, pre_trigger_samples); if (!devc->stl) return SR_ERR_MALLOC; diff --git a/src/hardware/ikalogic-scanalogic2/api.c b/src/hardware/ikalogic-scanalogic2/api.c index ef3ca0d8..9a84a767 100644 --- a/src/hardware/ikalogic-scanalogic2/api.c +++ b/src/hardware/ikalogic-scanalogic2/api.c @@ -270,10 +270,13 @@ static int config_get(uint32_t key, GVariant **data, static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { - uint64_t samplerate, limit_samples, capture_ratio; + struct dev_context *devc; + uint64_t samplerate, limit_samples; (void)cg; + devc = sdi->priv; + switch (key) { case SR_CONF_LIMIT_SAMPLES: limit_samples = g_variant_get_uint64(data); @@ -282,8 +285,8 @@ static int config_set(uint32_t key, GVariant *data, samplerate = g_variant_get_uint64(data); return sl2_set_samplerate(sdi, samplerate); case SR_CONF_CAPTURE_RATIO: - capture_ratio = g_variant_get_uint64(data); - return sl2_set_capture_ratio(sdi, capture_ratio); + devc->capture_ratio = g_variant_get_uint64(data); + break; default: return SR_ERR_NA; } diff --git a/src/hardware/ikalogic-scanalogic2/protocol.c b/src/hardware/ikalogic-scanalogic2/protocol.c index 6dd66999..b1a85b03 100644 --- a/src/hardware/ikalogic-scanalogic2/protocol.c +++ b/src/hardware/ikalogic-scanalogic2/protocol.c @@ -531,25 +531,6 @@ SR_PRIV int sl2_convert_trigger(const struct sr_dev_inst *sdi) return SR_OK; } -SR_PRIV int sl2_set_capture_ratio(const struct sr_dev_inst *sdi, - uint64_t capture_ratio) -{ - struct dev_context *devc; - - devc = sdi->priv; - - if (capture_ratio > 100) { - sr_err("Invalid capture ratio: %" PRIu64 " %%.", capture_ratio); - return SR_ERR_ARG; - } - - sr_info("Capture ratio set to %" PRIu64 " %%.", capture_ratio); - - devc->capture_ratio = capture_ratio; - - return SR_OK; -} - SR_PRIV int sl2_set_after_trigger_delay(const struct sr_dev_inst *sdi, uint64_t after_trigger_delay) { diff --git a/src/hardware/ikalogic-scanalogic2/protocol.h b/src/hardware/ikalogic-scanalogic2/protocol.h index a9471bb5..3a14b20b 100644 --- a/src/hardware/ikalogic-scanalogic2/protocol.h +++ b/src/hardware/ikalogic-scanalogic2/protocol.h @@ -138,7 +138,7 @@ struct dev_context { uint8_t trigger_channel; uint8_t trigger_type; - unsigned int capture_ratio; + uint64_t capture_ratio; /* Time that the trigger will be delayed in milliseconds. */ uint16_t after_trigger_delay; @@ -218,8 +218,6 @@ SR_PRIV int sl2_set_samplerate(const struct sr_dev_inst *sdi, SR_PRIV int sl2_set_limit_samples(const struct sr_dev_inst *sdi, uint64_t limit_samples); SR_PRIV int sl2_convert_trigger(const struct sr_dev_inst *sdi); -SR_PRIV int sl2_set_capture_ratio(const struct sr_dev_inst *sdi, - uint64_t capture_ratio); SR_PRIV int sl2_set_after_trigger_delay(const struct sr_dev_inst *sdi, uint64_t after_trigger_delay); SR_PRIV void sl2_calculate_trigger_samples(const struct sr_dev_inst *sdi); diff --git a/src/hardware/lecroy-logicstudio/api.c b/src/hardware/lecroy-logicstudio/api.c index f61d69ae..3d16f3a2 100644 --- a/src/hardware/lecroy-logicstudio/api.c +++ b/src/hardware/lecroy-logicstudio/api.c @@ -393,8 +393,6 @@ static int config_set(uint32_t key, GVariant *data, return lls_set_samplerate(sdi, g_variant_get_uint64(data)); case SR_CONF_CAPTURE_RATIO: devc->capture_ratio = g_variant_get_uint64(data); - if (devc->capture_ratio > 100) - return SR_ERR; break; default: return SR_ERR_NA; diff --git a/src/hardware/lecroy-logicstudio/protocol.c b/src/hardware/lecroy-logicstudio/protocol.c index d48ed4a6..7b3a41a6 100644 --- a/src/hardware/lecroy-logicstudio/protocol.c +++ b/src/hardware/lecroy-logicstudio/protocol.c @@ -1127,7 +1127,7 @@ SR_PRIV int lls_start_acquisition(const struct sr_dev_inst *sdi) total_samples = devc->num_thousand_samples * 1000; - pre_trigger_samples = total_samples * devc->capture_ratio / 100; + pre_trigger_samples = (total_samples * devc->capture_ratio) / 100; post_trigger_samples = total_samples - pre_trigger_samples; pre_trigger_tr = transform_sample_count(devc, pre_trigger_samples); diff --git a/src/hardware/openbench-logic-sniffer/api.c b/src/hardware/openbench-logic-sniffer/api.c index cdd50747..d15cb12c 100644 --- a/src/hardware/openbench-logic-sniffer/api.c +++ b/src/hardware/openbench-logic-sniffer/api.c @@ -253,10 +253,6 @@ static int config_set(uint32_t key, GVariant *data, break; case SR_CONF_CAPTURE_RATIO: devc->capture_ratio = g_variant_get_uint64(data); - if (devc->capture_ratio < 0 || devc->capture_ratio > 100) - return SR_ERR; - else - return SR_OK; break; case SR_CONF_EXTERNAL_CLOCK: if (g_variant_get_boolean(data)) { diff --git a/src/hardware/openbench-logic-sniffer/protocol.h b/src/hardware/openbench-logic-sniffer/protocol.h index bed0594f..cfe98cb4 100644 --- a/src/hardware/openbench-logic-sniffer/protocol.h +++ b/src/hardware/openbench-logic-sniffer/protocol.h @@ -75,7 +75,7 @@ struct dev_context { uint64_t cur_samplerate; uint32_t cur_samplerate_divider; uint64_t limit_samples; - int capture_ratio; + uint64_t capture_ratio; int trigger_at; uint32_t channel_mask; uint32_t trigger_mask[NUM_TRIGGER_STAGES]; diff --git a/src/hardware/pipistrello-ols/api.c b/src/hardware/pipistrello-ols/api.c index 9fc0ccff..1d1388ba 100644 --- a/src/hardware/pipistrello-ols/api.c +++ b/src/hardware/pipistrello-ols/api.c @@ -264,10 +264,6 @@ static int config_set(uint32_t key, GVariant *data, break; case SR_CONF_CAPTURE_RATIO: devc->capture_ratio = g_variant_get_uint64(data); - if (devc->capture_ratio < 0 || devc->capture_ratio > 100) - return SR_ERR; - else - return SR_OK; break; case SR_CONF_EXTERNAL_CLOCK: if (g_variant_get_boolean(data)) { diff --git a/src/hardware/pipistrello-ols/protocol.h b/src/hardware/pipistrello-ols/protocol.h index 7bbf69dc..1ac0d06d 100644 --- a/src/hardware/pipistrello-ols/protocol.h +++ b/src/hardware/pipistrello-ols/protocol.h @@ -87,7 +87,7 @@ struct dev_context { uint32_t cur_samplerate_divider; uint32_t max_samples; uint64_t limit_samples; - int capture_ratio; + uint64_t capture_ratio; int trigger_at; uint32_t channel_mask; uint32_t trigger_mask[NUM_TRIGGER_STAGES]; diff --git a/src/hardware/saleae-logic16/api.c b/src/hardware/saleae-logic16/api.c index 3ee4ea65..02fab9ba 100644 --- a/src/hardware/saleae-logic16/api.c +++ b/src/hardware/saleae-logic16/api.c @@ -468,7 +468,7 @@ static int config_set(uint32_t key, GVariant *data, break; case SR_CONF_CAPTURE_RATIO: devc->capture_ratio = g_variant_get_uint64(data); - return (devc->capture_ratio > 100) ? SR_ERR : SR_OK; + break; case SR_CONF_VOLTAGE_THRESHOLD: if ((idx = std_double_tuple_idx(data, ARRAY_AND_SIZE(volt_thresholds))) < 0) return SR_ERR_ARG; @@ -649,7 +649,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) if ((trigger = sr_session_trigger_get(sdi->session))) { int pre_trigger_samples = 0; if (devc->limit_samples > 0) - pre_trigger_samples = devc->capture_ratio * devc->limit_samples/100; + pre_trigger_samples = (devc->capture_ratio * devc->limit_samples) / 100; devc->stl = soft_trigger_logic_new(sdi, trigger, pre_trigger_samples); if (!devc->stl) return SR_ERR_MALLOC; diff --git a/src/hardware/zeroplus-logic-cube/api.c b/src/hardware/zeroplus-logic-cube/api.c index 73af06ea..d8067416 100644 --- a/src/hardware/zeroplus-logic-cube/api.c +++ b/src/hardware/zeroplus-logic-cube/api.c @@ -372,7 +372,8 @@ static int config_set(uint32_t key, GVariant *data, case SR_CONF_LIMIT_SAMPLES: return set_limit_samples(devc, g_variant_get_uint64(data)); case SR_CONF_CAPTURE_RATIO: - return set_capture_ratio(devc, g_variant_get_uint64(data)); + devc->capture_ratio = g_variant_get_uint64(data); + break; case SR_CONF_VOLTAGE_THRESHOLD: g_variant_get(data, "(dd)", &low, &high); return set_voltage_threshold(devc, (low + high) / 2.0); diff --git a/src/hardware/zeroplus-logic-cube/protocol.c b/src/hardware/zeroplus-logic-cube/protocol.c index 6e0e9614..bc517c35 100644 --- a/src/hardware/zeroplus-logic-cube/protocol.c +++ b/src/hardware/zeroplus-logic-cube/protocol.c @@ -79,20 +79,6 @@ SR_PRIV int set_limit_samples(struct dev_context *devc, uint64_t samples) return SR_OK; } -SR_PRIV int set_capture_ratio(struct dev_context *devc, uint64_t ratio) -{ - if (ratio > 100) { - sr_err("Invalid capture ratio: %" PRIu64 ".", ratio); - return SR_ERR_ARG; - } - - devc->capture_ratio = ratio; - - sr_info("Setting capture ratio to %d%%.", devc->capture_ratio); - - return SR_OK; -} - SR_PRIV int set_voltage_threshold(struct dev_context *devc, double thresh) { if (thresh > 6.0) @@ -118,7 +104,7 @@ SR_PRIV void set_triggerbar(struct dev_context *devc) trigger_depth = devc->limit_samples; if (devc->trigger) - triggerbar = trigger_depth * devc->capture_ratio / 100; + triggerbar = (trigger_depth * devc->capture_ratio) / 100; else triggerbar = 0; diff --git a/src/hardware/zeroplus-logic-cube/protocol.h b/src/hardware/zeroplus-logic-cube/protocol.h index bf0657ff..e179f1f8 100644 --- a/src/hardware/zeroplus-logic-cube/protocol.h +++ b/src/hardware/zeroplus-logic-cube/protocol.h @@ -42,7 +42,7 @@ struct dev_context { //uint8_t trigger_value[NUM_TRIGGER_STAGES]; // uint8_t trigger_buffer[NUM_TRIGGER_STAGES]; int trigger; - unsigned int capture_ratio; + uint64_t capture_ratio; double cur_threshold; const struct zp_model *prof; }; @@ -50,7 +50,6 @@ struct dev_context { SR_PRIV unsigned int get_memory_size(int type); SR_PRIV int zp_set_samplerate(struct dev_context *devc, uint64_t samplerate); SR_PRIV int set_limit_samples(struct dev_context *devc, uint64_t samples); -SR_PRIV int set_capture_ratio(struct dev_context *devc, uint64_t ratio); SR_PRIV int set_voltage_threshold(struct dev_context *devc, double thresh); SR_PRIV void set_triggerbar(struct dev_context *devc); diff --git a/src/hwdriver.c b/src/hwdriver.c index 8da425c8..c81a87a1 100644 --- a/src/hwdriver.c +++ b/src/hwdriver.c @@ -690,6 +690,15 @@ static int check_key(const struct sr_dev_driver *driver, return SR_ERR_ARG; } break; + case SR_CONF_CAPTURE_RATIO: + /* Capture ratio must always be between 0 and 100. */ + if (op != SR_CONF_SET || !data) + break; + if (g_variant_get_uint64(data) > 100) { + sr_err("Capture ratio must be 0..100."); + return SR_ERR_ARG; + } + break; } if (sr_config_list(driver, sdi, cg, SR_CONF_DEVICE_OPTIONS, &gvar_opts) != SR_OK) {