From: Gerhard Sittig Date: Sat, 22 Jan 2022 11:01:45 +0000 (+0100) Subject: kingst-la2016: endianess and redundancy in run state gatherer X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=21d68fd9afe72afa9d288e6f8c3e317037c5698a;p=libsigrok.git kingst-la2016: endianess and redundancy in run state gatherer 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. --- diff --git a/src/hardware/kingst-la2016/protocol.c b/src/hardware/kingst-la2016/protocol.c index 5ae79caa..b5e70b3d 100644 --- a/src/hardware/kingst-la2016/protocol.c +++ b/src/hardware/kingst-la2016/protocol.c @@ -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); }