]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/openbench-logic-sniffer/api.c
ols: simplify calculation of readcount
[libsigrok.git] / src / hardware / openbench-logic-sniffer / api.c
index cdd5074723e2940c6971bcb04b3297a092e6d24e..8ff1456daad47e8896fb6aaec6a1b8b387b59d94 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)) {
@@ -269,7 +265,6 @@ static int config_set(uint32_t key, GVariant *data,
                break;
        case SR_CONF_PATTERN_MODE:
                stropt = g_variant_get_string(data, NULL);
-               flag = 0xffff;
                if (!strcmp(stropt, STR_PATTERN_NONE)) {
                        sr_info("Disabling test modes.");
                        flag = 0x0000;
@@ -282,10 +277,9 @@ static int config_set(uint32_t key, GVariant *data,
                } else {
                        return SR_ERR;
                }
-               if (flag != 0xffff) {
-                       devc->flag_reg &= ~(FLAG_INTERNAL_TEST_MODE | FLAG_EXTERNAL_TEST_MODE);
-                       devc->flag_reg |= flag;
-               }
+               devc->flag_reg &= ~FLAG_INTERNAL_TEST_MODE;
+               devc->flag_reg &= ~FLAG_EXTERNAL_TEST_MODE;
+               devc->flag_reg |= flag;
                break;
        case SR_CONF_SWAP:
                if (g_variant_get_boolean(data)) {
@@ -402,7 +396,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
 {
        struct dev_context *devc;
        struct sr_serial_dev_inst *serial;
-       uint16_t samplecount, readcount, delaycount;
+       uint32_t samplecount, readcount, delaycount;
        uint8_t ols_changrp_mask, arg[4];
        int num_ols_changrp;
        int ret, i;
@@ -423,14 +417,10 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
 
        /*
         * Limit readcount to prevent reading past the end of the hardware
-        * buffer.
+        * buffer. Rather read too many samples than too few.
         */
        samplecount = MIN(devc->max_samples / num_ols_changrp, devc->limit_samples);
-       readcount = samplecount / 4;
-
-       /* Rather read too many samples than too few. */
-       if (samplecount % 4 != 0)
-               readcount++;
+       readcount = (samplecount + 3) / 4;
 
        /* Basic triggers. */
        if (ols_convert_trigger(sdi) != SR_OK) {