Use symbolic identifiers to select firmware images, which eliminates
magic 0/1/2 position numbers in the list of files, improves readability
and also improves robustness. Move 'devc' to 'ctx' and before other
arguments in routine signatures while we are here.
devc->id.type = dev_type;
devc->samplerate = samplerates[0];
sr_sw_limits_init(&devc->cfg_limits);
devc->id.type = dev_type;
devc->samplerate = samplerates[0];
sr_sw_limits_init(&devc->cfg_limits);
- devc->cur_firmware = -1;
+ devc->firmware_idx = SIGMA_FW_NONE;
devc->capture_ratio = 50;
devc->use_triggers = 0;
}
devc->capture_ratio = 50;
devc->use_triggers = 0;
}
SR_PRIV const size_t samplerates_count = ARRAY_SIZE(samplerates);
static const char *firmware_files[] = {
SR_PRIV const size_t samplerates_count = ARRAY_SIZE(samplerates);
static const char *firmware_files[] = {
- "asix-sigma-50.fw", /* Up to 50MHz sample rate, 8bit divider. */
- "asix-sigma-100.fw", /* 100MHz sample rate, fixed. */
- "asix-sigma-200.fw", /* 200MHz sample rate, fixed. */
- "asix-sigma-50sync.fw", /* Synchronous clock from external pin. */
- "asix-sigma-phasor.fw", /* Frequency counter. */
+ [SIGMA_FW_50MHZ] = "asix-sigma-50.fw", /* 50MHz, 8bit divider. */
+ [SIGMA_FW_100MHZ] = "asix-sigma-100.fw", /* 100MHz, fixed. */
+ [SIGMA_FW_200MHZ] = "asix-sigma-200.fw", /* 200MHz, fixed. */
+ [SIGMA_FW_SYNC] = "asix-sigma-50sync.fw", /* Sync from external pin. */
+ [SIGMA_FW_FREQ] = "asix-sigma-phasor.fw", /* Frequency counter. */
};
#define SIGMA_FIRMWARE_SIZE_LIMIT (256 * 1024)
};
#define SIGMA_FIRMWARE_SIZE_LIMIT (256 * 1024)
}
static int upload_firmware(struct sr_context *ctx,
}
static int upload_firmware(struct sr_context *ctx,
- int firmware_idx, struct dev_context *devc)
+ struct dev_context *devc, enum sigma_firmware_idx firmware_idx)
{
int ret;
unsigned char *buf;
{
int ret;
unsigned char *buf;
size_t buf_size;
const char *firmware;
size_t buf_size;
const char *firmware;
- /* Avoid downloading the same firmware multiple times. */
+ /* Check for valid firmware file selection. */
+ if (firmware_idx >= ARRAY_SIZE(firmware_files))
+ return SR_ERR_ARG;
firmware = firmware_files[firmware_idx];
firmware = firmware_files[firmware_idx];
- if (devc->cur_firmware == firmware_idx) {
+ if (!firmware || !*firmware)
+ return SR_ERR_ARG;
+
+ /* Avoid downloading the same firmware multiple times. */
+ if (devc->firmware_idx == firmware_idx) {
sr_info("Not uploading firmware file '%s' again.", firmware);
return SR_OK;
}
sr_info("Not uploading firmware file '%s' again.", firmware);
return SR_OK;
}
/* Keep track of successful firmware download completion. */
devc->state.state = SIGMA_IDLE;
/* Keep track of successful firmware download completion. */
devc->state.state = SIGMA_IDLE;
- devc->cur_firmware = firmware_idx;
+ devc->firmware_idx = firmware_idx;
sr_info("Firmware uploaded.");
return SR_OK;
sr_info("Firmware uploaded.");
return SR_OK;
*/
num_channels = devc->num_channels;
if (samplerate <= SR_MHZ(50)) {
*/
num_channels = devc->num_channels;
if (samplerate <= SR_MHZ(50)) {
- ret = upload_firmware(drvc->sr_ctx, 0, devc);
+ ret = upload_firmware(drvc->sr_ctx, devc, SIGMA_FW_50MHZ);
num_channels = 16;
} else if (samplerate == SR_MHZ(100)) {
num_channels = 16;
} else if (samplerate == SR_MHZ(100)) {
- ret = upload_firmware(drvc->sr_ctx, 1, devc);
+ ret = upload_firmware(drvc->sr_ctx, devc, SIGMA_FW_100MHZ);
num_channels = 8;
} else if (samplerate == SR_MHZ(200)) {
num_channels = 8;
} else if (samplerate == SR_MHZ(200)) {
- ret = upload_firmware(drvc->sr_ctx, 2, devc);
+ ret = upload_firmware(drvc->sr_ctx, devc, SIGMA_FW_200MHZ);
+enum sigma_firmware_idx {
+ SIGMA_FW_NONE,
+ SIGMA_FW_50MHZ,
+ SIGMA_FW_100MHZ,
+ SIGMA_FW_200MHZ,
+ SIGMA_FW_SYNC,
+ SIGMA_FW_FREQ,
+};
+
struct submit_buffer;
struct dev_context {
struct submit_buffer;
struct dev_context {
struct sr_sw_limits cfg_limits; /* Configured limits (user specified). */
struct sr_sw_limits acq_limits; /* Acquisition limits (internal use). */
struct sr_sw_limits feed_limits; /* Datafeed limits (internal use). */
struct sr_sw_limits cfg_limits; /* Configured limits (user specified). */
struct sr_sw_limits acq_limits; /* Acquisition limits (internal use). */
struct sr_sw_limits feed_limits; /* Datafeed limits (internal use). */
+ enum sigma_firmware_idx firmware_idx;
int num_channels;
int samples_per_event;
uint64_t capture_ratio;
int num_channels;
int samples_per_event;
uint64_t capture_ratio;