From: Gerhard Sittig Date: Sat, 22 Jan 2022 09:04:14 +0000 (+0100) Subject: kingst-la2016: rephrase FPGA bitstream content zero padding X-Git-Url: https://sigrok.org/gitweb/?p=libsigrok.git;a=commitdiff_plain;h=b0d0131eff8bacbf69aa0da818efaa4439f19a64 kingst-la2016: rephrase FPGA bitstream content zero padding The upload_fpga_bitstream() routine open codes a magic length for the padded file content, which is hard to relate to a firmware file size, and impossible to spot during maintenance. Declare an assumed chunk size instead and let the resource file handling code path determine the needed length of zero padding. Drop an unneeded device context member variable. --- diff --git a/src/hardware/kingst-la2016/protocol.c b/src/hardware/kingst-la2016/protocol.c index da254d31..a0de3be7 100644 --- a/src/hardware/kingst-la2016/protocol.c +++ b/src/hardware/kingst-la2016/protocol.c @@ -198,19 +198,18 @@ static int check_fpga_bitstream(const struct sr_dev_inst *sdi) static int upload_fpga_bitstream(const struct sr_dev_inst *sdi, const char *bitstream_fname) { - struct dev_context *devc; struct drv_context *drvc; struct sr_usb_dev_inst *usb; struct sr_resource bitstream; + uint32_t bitstream_size; uint8_t buffer[sizeof(uint32_t)]; uint8_t *wrptr; uint8_t block[4096]; int len, act_len; unsigned int pos; int ret; - unsigned int zero_pad_to = 0x2c000; + unsigned int zero_pad_to; - devc = sdi->priv; drvc = sdi->driver->context; usb = sdi->conn; @@ -222,14 +221,18 @@ static int upload_fpga_bitstream(const struct sr_dev_inst *sdi, return ret; } - devc->bitstream_size = (uint32_t)bitstream.size; + bitstream_size = (uint32_t)bitstream.size; wrptr = buffer; - write_u32le_inc(&wrptr, devc->bitstream_size); + write_u32le_inc(&wrptr, bitstream_size); if ((ret = ctrl_out(sdi, CMD_FPGA_INIT, 0x00, 0, buffer, wrptr - buffer)) != SR_OK) { sr_err("Cannot initiate FPGA bitstream upload."); sr_resource_close(drvc->sr_ctx, &bitstream); return ret; } + zero_pad_to = bitstream_size; + zero_pad_to += LA2016_EP2_PADDING - 1; + zero_pad_to /= LA2016_EP2_PADDING; + zero_pad_to *= LA2016_EP2_PADDING; pos = 0; while (1) { diff --git a/src/hardware/kingst-la2016/protocol.h b/src/hardware/kingst-la2016/protocol.h index 8ea01809..6d3cf264 100644 --- a/src/hardware/kingst-la2016/protocol.h +++ b/src/hardware/kingst-la2016/protocol.h @@ -57,6 +57,12 @@ #define RENUM_GONE_DELAY_MS 1800 #define RENUM_POLL_INTERVAL_MS 200 +/* + * The device expects some zero padding to follow the content of the + * file which contains the FPGA bitstream. Specify the chunk size here. + */ +#define LA2016_EP2_PADDING 2048 + #define LA2016_THR_VOLTAGE_MIN 0.40 #define LA2016_THR_VOLTAGE_MAX 4.00 @@ -105,8 +111,6 @@ struct dev_context { uint16_t cur_channels; int num_channels; - uint32_t bitstream_size; - /* Values derived from user specs. */ uint64_t pre_trigger_size;