From: Gerhard Sittig Date: Sun, 30 Jan 2022 08:55:56 +0000 (+0100) Subject: kingst-la2016: complete hardware setup in probe, set features in open X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=6d53e9497892df15e13899465ce4c2962a70a782;p=libsigrok.git kingst-la2016: complete hardware setup in probe, set features in open Complete all of the MCU firmware load, device type identification, FPGA bitstream load, and FPGA initialization by the end of scan(). This gives an easily usable device of known capabilities for the remaining driver lifetime, which just needs to get opened by connection ID (which was retrieved during scan). I still don't like how the driver's open() configures PWM without user provided specs. And enforcing the logic threshold is redundant before acquisition start. This needs more attention later. --- diff --git a/src/hardware/kingst-la2016/api.c b/src/hardware/kingst-la2016/api.c index 0b672eea..8f8afef8 100644 --- a/src/hardware/kingst-la2016/api.c +++ b/src/hardware/kingst-la2016/api.c @@ -249,7 +249,17 @@ static int la2016_identify_read(struct sr_dev_inst *sdi, sr_err("Cannot communicate to MCU firmware."); return ret; } + + /* + * Also complete the hardware configuration (FPGA bitstream) + * when MCU firmware communication became operational. Either + * failure is considered fatal when probing for the device. + */ ret = la2016_identify_device(sdi, show_message); + if (ret == SR_OK) { + ret = la2016_init_hardware(sdi); + } + la2016_close_usb(usb); return ret; @@ -582,6 +592,16 @@ static int dev_open(struct sr_dev_inst *sdi) return ret; } + /* + * Setup a default configuration of device features. This + * affects the logic threshold, PWM channels, and similar. + */ + ret = la2016_init_params(sdi); + if (ret != SR_OK) { + sr_err("Cannot initialize device's hardware."); + return ret; + } + return SR_OK; } @@ -594,7 +614,7 @@ static int dev_close(struct sr_dev_inst *sdi) if (!usb->devhdl) return SR_ERR_BUG; - la2016_deinit_device(sdi); + la2016_deinit_hardware(sdi); sr_info("Closing device on %d.%d (logical) / %s (physical) interface %d.", usb->bus, usb->address, sdi->connection_id, USB_INTERFACE); diff --git a/src/hardware/kingst-la2016/protocol.c b/src/hardware/kingst-la2016/protocol.c index 00cda352..9ecaa718 100644 --- a/src/hardware/kingst-la2016/protocol.c +++ b/src/hardware/kingst-la2016/protocol.c @@ -1371,7 +1371,7 @@ SR_PRIV int la2016_identify_device(const struct sr_dev_inst *sdi, return SR_OK; } -SR_PRIV int la2016_init_device(const struct sr_dev_inst *sdi) +SR_PRIV int la2016_init_hardware(const struct sr_dev_inst *sdi) { struct dev_context *devc; const char *bitstream_fn; @@ -1400,13 +1400,21 @@ SR_PRIV int la2016_init_device(const struct sr_dev_inst *sdi) sr_warn("Unexpected run state, want 0x85e9, got 0x%04x.", state); } - if ((ret = ctrl_out(sdi, CMD_BULK_RESET, 0x00, 0, NULL, 0)) != SR_OK) { + ret = ctrl_out(sdi, CMD_BULK_RESET, 0x00, 0, NULL, 0); + if (ret != SR_OK) { sr_err("Cannot reset USB bulk transfer."); return ret; } sr_dbg("Device should be initialized."); + return SR_OK; +} + +SR_PRIV int la2016_init_params(const struct sr_dev_inst *sdi) +{ + int ret; + ret = set_defaults(sdi); if (ret != SR_OK) return ret; @@ -1414,11 +1422,12 @@ SR_PRIV int la2016_init_device(const struct sr_dev_inst *sdi) return SR_OK; } -SR_PRIV int la2016_deinit_device(const struct sr_dev_inst *sdi) +SR_PRIV int la2016_deinit_hardware(const struct sr_dev_inst *sdi) { int ret; - if ((ret = ctrl_out(sdi, CMD_FPGA_ENABLE, 0x00, 0, NULL, 0)) != SR_OK) { + ret = ctrl_out(sdi, CMD_FPGA_ENABLE, 0x00, 0, NULL, 0); + if (ret != SR_OK) { sr_err("Cannot deinitialize device's FPGA."); return ret; } diff --git a/src/hardware/kingst-la2016/protocol.h b/src/hardware/kingst-la2016/protocol.h index 8b1121ec..c308005e 100644 --- a/src/hardware/kingst-la2016/protocol.h +++ b/src/hardware/kingst-la2016/protocol.h @@ -155,7 +155,8 @@ SR_PRIV int la2016_abort_acquisition(const struct sr_dev_inst *sdi); SR_PRIV int la2016_receive_data(int fd, int revents, void *cb_data); SR_PRIV int la2016_identify_device(const struct sr_dev_inst *sdi, gboolean show_message); -SR_PRIV int la2016_init_device(const struct sr_dev_inst *sdi); -SR_PRIV int la2016_deinit_device(const struct sr_dev_inst *sdi); +SR_PRIV int la2016_init_hardware(const struct sr_dev_inst *sdi); +SR_PRIV int la2016_init_params(const struct sr_dev_inst *sdi); +SR_PRIV int la2016_deinit_hardware(const struct sr_dev_inst *sdi); #endif