The previous implementation started on a single model with lots of
experiments, and could benefit from a cleanup after more knowledge was
gathered. Rename variables and routines to better reflect what actually
is happening, use more suitable data types. Drop unused devc members.
Fixup typos in diagnostics, protect against MSB issues in bitmasks.
The USB scan just yields one of the supported devices, its model is
unknown at this time. The list of enabled channels is determined upon
acquisition start when the trigger configuration gets created. The
device executes captures in hardware to internal RAM, while the driver
waits for the acquisition to complete, before downloading sample data
to the PC. Feeding sample data to the session ends when the data is
exhausted (a good condition is yet to get found). An optional trigger
marker is put into the stream of samples but only if a trigger was
configured.
continue;
/* USB identification matches, a device was found. */
continue;
/* USB identification matches, a device was found. */
- sr_dbg("Found a LA2016 device.");
+ sr_dbg("Found a device (USB identification).");
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_INITIALIZING;
sdi->connection_id = g_strdup(connection_id);
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_INITIALIZING;
sdi->connection_id = g_strdup(connection_id);
devc = sdi->priv;
devc->cur_channels = 0;
devc = sdi->priv;
devc->cur_channels = 0;
- devc->num_channels = 0;
-
for (GSList *l = sdi->channels; l; l = l->next) {
struct sr_channel *ch = (struct sr_channel*)l->data;
if (ch->enabled == FALSE)
continue;
devc->cur_channels |= 1 << ch->index;
for (GSList *l = sdi->channels; l; l = l->next) {
struct sr_channel *ch = (struct sr_channel*)l->data;
if (ch->enabled == FALSE)
continue;
devc->cur_channels |= 1 << ch->index;
- devc->have_trigger = 0;
+ devc->completion_seen = FALSE;
usb_source_add(sdi->session, drvc->sr_ctx, 50,
la2016_receive_data, (void *)sdi);
usb_source_add(sdi->session, drvc->sr_ctx, 50,
la2016_receive_data, (void *)sdi);
devc = sdi->priv;
devc->capture_ratio = LA2016_DFLT_CAPT_RATIO;
devc = sdi->priv;
devc->capture_ratio = LA2016_DFLT_CAPT_RATIO;
- devc->cur_channels = 0xffff;
devc->limit_samples = LA2016_DFLT_SAMPLEDEPTH;
devc->cur_samplerate = LA2016_DFLT_SAMPLERATE;
devc->limit_samples = LA2016_DFLT_SAMPLEDEPTH;
devc->cur_samplerate = LA2016_DFLT_SAMPLERATE;
channel = stage1->matches;
while (channel) {
match = channel->data;
channel = stage1->matches;
while (channel) {
match = channel->data;
- ch_mask = 1 << match->channel->index;
+ ch_mask = 1UL << match->channel->index;
switch (match->match) {
case SR_TRIGGER_ZERO:
switch (match->match) {
case SR_TRIGGER_ZERO:
"level-triggered 0x%04x, high/falling 0x%04x.",
cfg.channels, cfg.enabled, cfg.level, cfg.high_or_falling);
"level-triggered 0x%04x, high/falling 0x%04x.",
cfg.channels, cfg.enabled, cfg.level, cfg.high_or_falling);
- devc->had_triggers_configured = cfg.enabled != 0;
+ devc->trigger_involved = cfg.enabled != 0;
wrptr = buf;
write_u32le_inc(&wrptr, cfg.channels);
wrptr = buf;
write_u32le_inc(&wrptr, cfg.channels);
-static int la2016_has_triggered(const struct sr_dev_inst *sdi)
+static int la2016_is_idle(const struct sr_dev_inst *sdi)
devc->info.n_rep_packets_before_trigger = read_u32le_inc(&rdptr);
devc->info.write_pos = read_u32le_inc(&rdptr);
devc->info.n_rep_packets_before_trigger = read_u32le_inc(&rdptr);
devc->info.write_pos = read_u32le_inc(&rdptr);
- sr_dbg("Capture info: n_rep_packets: 0x%08x/%d, before_trigger: 0x%08x/%d, write_pos: 0x%08x%d.",
+ sr_dbg("Capture info: n_rep_packets: 0x%08x/%d, before_trigger: 0x%08x/%d, write_pos: 0x%08x/%d.",
devc->info.n_rep_packets, devc->info.n_rep_packets,
devc->info.n_rep_packets_before_trigger,
devc->info.n_rep_packets_before_trigger,
devc->info.n_rep_packets, devc->info.n_rep_packets,
devc->info.n_rep_packets_before_trigger,
devc->info.n_rep_packets_before_trigger,
-static int la2016_start_retrieval(const struct sr_dev_inst *sdi,
+static int la2016_start_download(const struct sr_dev_inst *sdi,
libusb_transfer_cb_fn cb)
{
struct dev_context *devc;
libusb_transfer_cb_fn cb)
{
struct dev_context *devc;
struct sr_datafeed_packet sr_packet;
unsigned int max_samples, n_samples, total_samples, free_n_samples;
unsigned int i, j, k;
struct sr_datafeed_packet sr_packet;
unsigned int max_samples, n_samples, total_samples, free_n_samples;
unsigned int i, j, k;
+ gboolean do_signal_trigger;
uint8_t *wp;
const uint8_t *rp;
uint16_t state;
uint8_t *wp;
const uint8_t *rp;
uint16_t state;
n_samples = 0;
wp = devc->convbuffer;
total_samples = 0;
n_samples = 0;
wp = devc->convbuffer;
total_samples = 0;
+ do_signal_trigger = FALSE;
- if (devc->had_triggers_configured && devc->reading_behind_trigger == 0 && devc->info.n_rep_packets_before_trigger == 0) {
+ if (devc->trigger_involved && !devc->trigger_marked && devc->info.n_rep_packets_before_trigger == 0) {
std_session_send_df_trigger(sdi);
std_session_send_df_trigger(sdi);
- devc->reading_behind_trigger = 1;
+ devc->trigger_marked = TRUE;
wp = devc->convbuffer;
if (do_signal_trigger) {
std_session_send_df_trigger(sdi);
wp = devc->convbuffer;
if (do_signal_trigger) {
std_session_send_df_trigger(sdi);
+ do_signal_trigger = FALSE;
n_samples += repetitions;
total_samples += repetitions;
devc->total_samples += repetitions;
n_samples += repetitions;
total_samples += repetitions;
devc->total_samples += repetitions;
- if (!devc->reading_behind_trigger) {
- devc->n_reps_until_trigger--;
- if (devc->n_reps_until_trigger == 0) {
- devc->reading_behind_trigger = 1;
- do_signal_trigger = 1;
+ if (devc->trigger_involved && !devc->trigger_marked) {
+ if (!--devc->n_reps_until_trigger) {
+ devc->trigger_marked = TRUE;
+ do_signal_trigger = TRUE;
sr_dbg("Trigger position after %" PRIu64 " samples, %.6fms.",
devc->total_samples,
(double)devc->total_samples / devc->cur_samplerate * 1e3);
sr_dbg("Trigger position after %" PRIu64 " samples, %.6fms.",
devc->total_samples,
(double)devc->total_samples / devc->cur_samplerate * 1e3);
if (transfer->status == LIBUSB_TRANSFER_TIMED_OUT) {
sr_err("USB bulk transfer timeout.");
if (transfer->status == LIBUSB_TRANSFER_TIMED_OUT) {
sr_err("USB bulk transfer timeout.");
- devc->transfer_finished = 1;
+ devc->download_finished = TRUE;
}
send_chunk(sdi, transfer->buffer, transfer->actual_length / TRANSFER_PACKET_LENGTH);
}
send_chunk(sdi, transfer->buffer, transfer->actual_length / TRANSFER_PACKET_LENGTH);
g_free(transfer->buffer);
libusb_free_transfer(transfer);
g_free(transfer->buffer);
libusb_free_transfer(transfer);
- devc->transfer_finished = 1;
+ devc->download_finished = TRUE;
}
SR_PRIV int la2016_receive_data(int fd, int revents, void *cb_data)
}
SR_PRIV int la2016_receive_data(int fd, int revents, void *cb_data)
devc = sdi->priv;
drvc = sdi->driver->context;
devc = sdi->priv;
drvc = sdi->driver->context;
- if (devc->have_trigger == 0) {
- if (la2016_has_triggered(sdi) == 0) {
+ if (!devc->completion_seen) {
+ if (!la2016_is_idle(sdi)) {
/* Not yet ready for sample data download. */
return TRUE;
}
/* Not yet ready for sample data download. */
return TRUE;
}
- devc->have_trigger = 1;
- devc->transfer_finished = 0;
- devc->reading_behind_trigger = 0;
+ devc->completion_seen = TRUE;
+ devc->download_finished = FALSE;
+ devc->trigger_marked = FALSE;
devc->total_samples = 0;
/* We can start downloading sample data. */
devc->total_samples = 0;
/* We can start downloading sample data. */
- if (la2016_start_retrieval(sdi, receive_transfer) != SR_OK) {
+ if (la2016_start_download(sdi, receive_transfer) != SR_OK) {
sr_err("Cannot start acquisition data download.");
return FALSE;
}
sr_err("Cannot start acquisition data download.");
return FALSE;
}
tv.tv_sec = tv.tv_usec = 0;
libusb_handle_events_timeout(drvc->sr_ctx->libusb_ctx, &tv);
tv.tv_sec = tv.tv_usec = 0;
libusb_handle_events_timeout(drvc->sr_ctx->libusb_ctx, &tv);
- if (devc->transfer_finished) {
+ if (devc->download_finished) {
sr_dbg("Download finished, post processing.");
std_session_send_df_frame_end(sdi);
sr_dbg("Download finished, post processing.");
std_session_send_df_frame_end(sdi);
uint64_t limit_samples;
uint64_t capture_ratio;
uint16_t cur_channels;
uint64_t limit_samples;
uint64_t capture_ratio;
uint16_t cur_channels;
/* Internal acquisition and download state. */
/* Internal acquisition and download state. */
- int had_triggers_configured;
- int have_trigger;
- int transfer_finished;
+ gboolean trigger_involved;
+ gboolean completion_seen;
+ gboolean download_finished;
capture_info_t info;
unsigned int n_transfer_packets_to_read; /* each with 5 acq packets */
unsigned int n_bytes_to_read;
unsigned int n_reps_until_trigger;
capture_info_t info;
unsigned int n_transfer_packets_to_read; /* each with 5 acq packets */
unsigned int n_bytes_to_read;
unsigned int n_reps_until_trigger;
- unsigned int reading_behind_trigger;
+ gboolean trigger_marked;
uint64_t total_samples;
uint32_t read_pos;
uint64_t total_samples;
uint32_t read_pos;