]> sigrok.org Git - libsigrok.git/commitdiff
drivers: SR_CONF_CAPTURE_RATIO fixes.
authorUwe Hermann <redacted>
Fri, 28 Jul 2017 19:29:12 +0000 (21:29 +0200)
committerUwe Hermann <redacted>
Mon, 31 Jul 2017 14:23:32 +0000 (16:23 +0200)
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.

20 files changed:
src/hardware/asix-sigma/api.c
src/hardware/asix-sigma/protocol.h
src/hardware/beaglelogic/api.c
src/hardware/dreamsourcelab-dslogic/api.c
src/hardware/fx2lafw/api.c
src/hardware/fx2lafw/protocol.c
src/hardware/ikalogic-scanalogic2/api.c
src/hardware/ikalogic-scanalogic2/protocol.c
src/hardware/ikalogic-scanalogic2/protocol.h
src/hardware/lecroy-logicstudio/api.c
src/hardware/lecroy-logicstudio/protocol.c
src/hardware/openbench-logic-sniffer/api.c
src/hardware/openbench-logic-sniffer/protocol.h
src/hardware/pipistrello-ols/api.c
src/hardware/pipistrello-ols/protocol.h
src/hardware/saleae-logic16/api.c
src/hardware/zeroplus-logic-cube/api.c
src/hardware/zeroplus-logic-cube/protocol.c
src/hardware/zeroplus-logic-cube/protocol.h
src/hwdriver.c

index 96cdb2a787ad4653cbc7f7394684f4c5aa4da797..042793a8961c8e52c5ee7d1acb094a01ab1c91f9 100644 (file)
@@ -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:
index 40206342110c020fa91840b413269896e8645e10..d59c95d2a1b0704d1a7812e9f0c4d80c82466f90 100644 (file)
@@ -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;
index ebe1522fa5af1870afa61c4ddaa944baf32618a7..2f632e7c6493782d9ffd32bc7d410b41a560182f 100644 (file)
@@ -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;
index 4e0a1d10016eddff95be28ad75e3f12817dbe5cd..7ea5f6eb32e7cc1b4ef73a7fa8a9bf0550130a2b 100644 (file)
@@ -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)
index c72daa7f0e9965e7deeee54f04806a806be0ba05..34c5bc412ebfec2b9dc582da3cefab98588d92f6 100644 (file)
@@ -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;
        }
index e88bbd2fd6fa47e7dcda8e7d700993c3cd719ce5..fc6fd3315a2c2ab6f76a3612e7e30db1362888f0 100644 (file)
@@ -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;
index ef3ca0d8a77edb18ee06f18233f0a750d394f62c..9a84a767ed283fc50a7eb4ad2a4a56e8809a8dfe 100644 (file)
@@ -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;
        }
index 6dd66999bd2b3e7fcb921904f80b00a47207021a..b1a85b03a621110d64a16c4397d2f01f1524be7f 100644 (file)
@@ -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)
 {
index a9471bb5d93930935065cc26adca8afbcb873316..3a14b20b415b740600b7656ff873a96e71794d17 100644 (file)
@@ -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);
index f61d69ae5c5a954f528b4a4c88de90be2e32827c..3d16f3a2dd4dbf6f8328bddd3fcdaa37e62a403d 100644 (file)
@@ -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;
index d48ed4a6ccf8674dd09bb5ee93fa4e6d321d47dd..7b3a41a69d30c026a3272b87dafd3f895a5390d9 100644 (file)
@@ -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);
index cdd5074723e2940c6971bcb04b3297a092e6d24e..d15cb12cfa425e1a5664abdb6081726ef6e34652 100644 (file)
@@ -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)) {
index bed0594f7675c5150f1ea09458dbfc9abc381c48..cfe98cb4667497ec6c8f1970d887f5bd3429c976 100644 (file)
@@ -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];
index 9fc0ccffd44ea2d9bcc8994f232302c2df6520c3..1d1388bae3bdc174488dc58677132ea5743498e2 100644 (file)
@@ -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)) {
index 7bbf69dc94eaf93d2fa8411e0aff49d532ef3f40..1ac0d06d6f1c23f3127a76abfb8d095cb611fdef 100644 (file)
@@ -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];
index 3ee4ea65802df47465b2f25db57c96c84a39e909..02fab9ba2e6a8043469e5345a06d9390dbf2b407 100644 (file)
@@ -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;
index 73af06ea0dc7a58d062cc775a4b7a26e448c93d4..d8067416286b47d7654cf3bb271a55c532972a09 100644 (file)
@@ -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);
index 6e0e96149711ce0f4d4d8e96c9212c518efd54b0..bc517c35acbf526d9c513d11fb50dd9e15417e8a 100644 (file)
@@ -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;
 
index bf0657ff23295afdc0fd18177249b5424b23671d..e179f1f8a2280b86b89e5f5e1c811ab6f52eaa1e 100644 (file)
@@ -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);
 
index 8da425c848a86089ac8bb754f136f682832e8ef3..c81a87a169d0f9e8ef52a1abba87b51c4cb5d63a 100644 (file)
@@ -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) {