X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fkingst-la2016%2Fprotocol.c;h=f21a2ba0613b75bd7130b7ad2c054a92bb8031b4;hb=ea436ba7c5dc89e87c24200850fe458d6e6576d1;hp=067ab4ada9df4fc795dd4ff6795cbae5ee1024a3;hpb=084d6b927163fb0881941ad13014e07a6a5e7a77;p=libsigrok.git diff --git a/src/hardware/kingst-la2016/protocol.c b/src/hardware/kingst-la2016/protocol.c index 067ab4ad..f21a2ba0 100644 --- a/src/hardware/kingst-la2016/protocol.c +++ b/src/hardware/kingst-la2016/protocol.c @@ -34,13 +34,6 @@ #define FPGA_FW_LA1016 "kingst-la1016-fpga.bitstream" #define FPGA_FW_LA1016A "kingst-la1016a1-fpga.bitstream" -/* Maximum device capabilities. May differ between models. */ -#define MAX_SAMPLE_RATE_LA2016 SR_MHZ(200) -#define MAX_SAMPLE_RATE_LA1016 SR_MHZ(100) -#define MAX_SAMPLE_DEPTH 10e9 -#define MAX_PWM_FREQ SR_MHZ(20) -#define PWM_CLOCK SR_MHZ(200) /* 200MHz for both LA2016 and LA1016 */ - /* * Default device configuration. Must be applicable to any of the * supported devices (no model specific default values yet). Specific @@ -51,14 +44,6 @@ #define LA2016_DFLT_SAMPLEDEPTH (5 * 1000 * 1000) #define LA2016_DFLT_CAPT_RATIO 5 /* Capture ratio, in percent. */ -/* TODO - * What is the origin and motivation of that 128Mi literal? What is its - * unit? How does it relate to a device's hardware capabilities? How to - * map the 1GiB of RAM of an LA2016 (at 16 channels) to the 128Mi value? - * It cannot be sample count. Is it memory size in bytes perhaps? - */ -#define LA2016_PRE_MEM_LIMIT_BASE (128 * 1024 * 1024) - /* USB vendor class control requests, executed by the Cypress FX2 MCU. */ #define CMD_FPGA_ENABLE 0x10 #define CMD_FPGA_SPI 0x20 /* R/W access to FPGA registers via SPI. */ @@ -304,7 +289,7 @@ static int upload_fpga_bitstream(const struct sr_dev_inst *sdi, pos += len; } sr_resource_close(drvc->sr_ctx, &bitstream); - if (ret != 0) + if (ret != SR_OK) return ret; sr_info("FPGA bitstream upload (%" PRIu64 " bytes) done.", bitstream.size); @@ -514,6 +499,25 @@ static int set_defaults(const struct sr_dev_inst *sdi) return SR_OK; } +static uint16_t get_channels_mask(const struct sr_dev_inst *sdi) +{ + uint16_t channels; + GSList *l; + struct sr_channel *ch; + + channels = 0; + for (l = sdi->channels; l; l = l->next) { + ch = l->data; + if (ch->type != SR_CHANNEL_LOGIC) + continue; + if (!ch->enabled) + continue; + channels |= 1UL << ch->index; + } + + return channels; +} + static int set_trigger_config(const struct sr_dev_inst *sdi) { struct dev_context *devc; @@ -533,7 +537,7 @@ static int set_trigger_config(const struct sr_dev_inst *sdi) memset(&cfg, 0, sizeof(cfg)); - cfg.channels = devc->cur_channels; + cfg.channels = get_channels_mask(sdi); if (trigger && trigger->stages) { stages = trigger->stages; @@ -623,7 +627,12 @@ static int set_sample_config(const struct sr_dev_inst *sdi) if (devc->cur_samplerate > devc->max_samplerate) { sr_err("Too high a sample rate: %" PRIu64 ".", devc->cur_samplerate); - return SR_ERR; + return SR_ERR_ARG; + } + if (devc->cur_samplerate < MIN_SAMPLE_RATE_LA2016) { + sr_err("Too low a sample rate: %" PRIu64 ".", + devc->cur_samplerate); + return SR_ERR_ARG; } clock_divisor = devc->max_samplerate / (double)devc->cur_samplerate; @@ -632,11 +641,16 @@ static int set_sample_config(const struct sr_dev_inst *sdi) divider_u16 = (uint16_t)(clock_divisor + 0.5); devc->cur_samplerate = devc->max_samplerate / divider_u16; - if (devc->limit_samples > MAX_SAMPLE_DEPTH) { + if (devc->limit_samples > LA2016_NUM_SAMPLES_MAX) { sr_err("Too high a sample depth: %" PRIu64 ".", devc->limit_samples); return SR_ERR; } + if (devc->limit_samples < LA2016_NUM_SAMPLES_MIN) { + sr_err("Too low a sample depth: %" PRIu64 ".", + devc->limit_samples); + return SR_ERR; + } /* * The acquisition configuration communicates "pre-trigger" @@ -831,7 +845,7 @@ SR_PRIV int la2016_upload_firmware(struct sr_context *sr_ctx, libusb_device *dev, uint16_t product_id) { char fw_file[1024]; - snprintf(fw_file, sizeof(fw_file) - 1, UC_FIRMWARE, product_id); + snprintf(fw_file, sizeof(fw_file), UC_FIRMWARE, product_id); return ezusb_upload_firmware(sr_ctx, dev, USB_CONFIGURATION, fw_file); }