]> sigrok.org Git - libsigrok.git/commitdiff
input/protocoldata: improve use of feed queue API
authorGerhard Sittig <redacted>
Sun, 15 Oct 2023 08:31:15 +0000 (10:31 +0200)
committerGerhard Sittig <redacted>
Mon, 16 Oct 2023 20:21:22 +0000 (22:21 +0200)
Improve feed queue related calls in the submission of capture start/end
idle phases, inter-frame idle phases, and bit time quanta of generated
protocol traffic. The submit-one API call accepts a repeat count which
eliminates caller's loops.

This also happens to eliminate a misguided yet harmless wrong use of the
feed queue API. An earlier implementation assumed "data pointer, and
data size" as arguments, and looped around that at the caller's. While
it's "data pointer, and repeat count". Used to work because sizeof(u8)
"was mistaken" as repeat count 1, so this flaw went unnoticed.

Propagate errors as they are seen, an earlier implementation silently
ignored them for frame payloads.

src/input/protocoldata.c

index c1d516f4aad08eefb6bbde29a011fb52cc088da8..148048ea38ca9d8ec83ce5f8a0b4b2992aa819f7 100644 (file)
@@ -713,12 +713,9 @@ static int send_idle_capture(struct context *inc)
        if (ret != SR_OK)
                return ret;
        count *= inc->curr_opts.samples_per_bit;
-       while (count--) {
-               ret = feed_queue_logic_submit_one(inc->feed_logic,
-                       &data, sizeof(data));
-               if (ret != SR_OK)
-                       return ret;
-       }
+       ret = feed_queue_logic_submit_one(inc->feed_logic, &data, count);
+       if (ret != SR_OK)
+               return ret;
 
        return SR_OK;
 }
@@ -738,12 +735,9 @@ static int send_idle_interframe(struct context *inc)
        ret = handler->get_idle_interframe(inc, &count, &data);
        if (ret != SR_OK)
                return ret;
-       while (count--) {
-               ret = feed_queue_logic_submit_one(inc->feed_logic,
-                       &data, sizeof(data));
-               if (ret != SR_OK)
-                       return ret;
-       }
+       ret = feed_queue_logic_submit_one(inc->feed_logic, &data, count);
+       if (ret != SR_OK)
+               return ret;
 
        return SR_OK;
 }
@@ -754,16 +748,17 @@ static int send_frame(struct sr_input *in)
        struct context *inc;
        size_t count, index;
        uint8_t data;
+       int ret;
 
        inc = in->priv;
 
        for (index = 0; index < inc->top_frame_bits; index++) {
                data = inc->sample_levels[index];
                count = inc->sample_widths[index];
-               while (count--) {
-                       feed_queue_logic_submit_one(inc->feed_logic,
-                               &data, sizeof(data));
-               }
+               ret = feed_queue_logic_submit_one(inc->feed_logic,
+                       &data, count);
+               if (ret != SR_OK)
+                       return ret;
        }
 
        return SR_OK;