]> sigrok.org Git - libsigrok.git/commitdiff
kingst-la2016: endianess and redundancy in run state gatherer
authorGerhard Sittig <redacted>
Sat, 22 Jan 2022 11:01:45 +0000 (12:01 +0100)
committerGerhard Sittig <redacted>
Sun, 6 Feb 2022 17:53:53 +0000 (18:53 +0100)
The run_state() routine assumed a little endian host. Get the device's
16bits run state by means of an endianess aware reader instead. Reduce
redundancy in the run state change diagnostics. Individually determine
the run state name, but use common code to print that information. Use
short hex literals to better reflect that only the lowest nibble gets
inspected, all other bits' meaning are unknown to us.

It remains uncertain why the state progress logic keeps checking the
"sample to DRAM" bit field. In theory these states should also work for
streaming. May just not have come up yet in the absence of support.

src/hardware/kingst-la2016/protocol.c

index 5ae79caaf13c13a5cd81823ec5a9beb5e725bcb8..b5e70b3d7dcb646afa0d6498fe11c6b9095af09a 100644 (file)
@@ -662,14 +662,20 @@ static int set_sample_config(const struct sr_dev_inst *sdi)
  */
 static uint16_t run_state(const struct sr_dev_inst *sdi)
 {
-       uint16_t state;
-       static uint16_t previous_state = 0;
+       static uint16_t previous_state;
+
        int ret;
+       uint16_t state;
+       uint8_t buff[sizeof(state)];
+       const uint8_t *rdptr;
+       const char *label;
 
-       if ((ret = ctrl_in(sdi, CMD_FPGA_SPI, REG_RUN, 0, &state, sizeof(state))) != SR_OK) {
+       if ((ret = ctrl_in(sdi, CMD_FPGA_SPI, REG_RUN, 0, buff, sizeof(state))) != SR_OK) {
                sr_err("Cannot read run state.");
                return ret;
        }
+       rdptr = buff;
+       state = read_u16le_inc(&rdptr);
 
        /*
         * Avoid flooding the log, only dump values as they change.
@@ -677,17 +683,19 @@ static uint16_t run_state(const struct sr_dev_inst *sdi)
         */
        if (state != previous_state) {
                previous_state = state;
-               if ((state & 0x0003) == 0x01) {
-                       sr_dbg("Run state: 0x%04x (%s).", state, "idle");
-               } else if ((state & 0x000f) == 0x02) {
-                       sr_dbg("Run state: 0x%04x (%s).", state,
-                               "pre-trigger sampling");
-               } else if ((state & 0x000f) == 0x0a) {
-                       sr_dbg("Run state: 0x%04x (%s).", state,
-                               "sampling, waiting for trigger");
-               } else if ((state & 0x000f) == 0x0e) {
-                       sr_dbg("Run state: 0x%04x (%s).", state,
-                               "post-trigger sampling");
+               if ((state & 0x3) == 0x1) {
+                       label = "idle";
+               } else if ((state & 0xf) == 0x2) {
+                       label = "pre-trigger sampling";
+               } else if ((state & 0xf) == 0xa) {
+                       label = "sampling, waiting for trigger";
+               } else if ((state & 0xf) == 0xe) {
+                       label = "post-trigger sampling";
+               } else {
+                       label = NULL;
+               }
+               if (label && *label) {
+                       sr_dbg("Run state: 0x%04x (%s).", state, label);
                } else {
                        sr_dbg("Run state: 0x%04x.", state);
                }