Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/hardware/openbench-logic-sniffer/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)

/* Reset all operational states. */
devc->rle_count = 0;
devc->trigger_rle_at_smpl_from_end = OLS_NO_TRIGGER;
devc->cnt_samples = devc->raw_sample_size = 0;
devc->cnt_rx_bytes = devc->cnt_rx_raw_samples = 0;
memset(devc->raw_sample, 0, 4);
Expand Down
49 changes: 47 additions & 2 deletions src/hardware/openbench-logic-sniffer/protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ SR_PRIV struct dev_context *ols_dev_new(void)

devc = g_malloc0(sizeof(struct dev_context));
devc->trigger_at_smpl = OLS_NO_TRIGGER;
devc->trigger_rle_at_smpl_from_end = OLS_NO_TRIGGER;

return devc;
}
Expand Down Expand Up @@ -462,6 +463,15 @@ SR_PRIV int ols_receive_data(int fd, int revents, void *cb_data)
devc->rle_count);
devc->raw_sample_size = 0;

if (devc->trigger_at_smpl !=
OLS_NO_TRIGGER &&
devc->trigger_rle_at_smpl_from_end ==
OLS_NO_TRIGGER &&
(unsigned int)devc->trigger_at_smpl ==
devc->cnt_rx_raw_samples)
devc->trigger_rle_at_smpl_from_end =
devc->cnt_samples;

/*

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This if-condition is really hard to read. And unless I missed something, it is needed a second time later. I'd suggest an inline function here like "is_<some_good_description>_trigger(devc)"

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! I extracted the ugliness to set_rle_trigger_point_if_unset

* Even on the rare occasion that the sampling ends with an RLE message,
* the acquisition should end immediately, without any timeout.
Expand Down Expand Up @@ -523,6 +533,15 @@ SR_PRIV int ols_receive_data(int fd, int revents, void *cb_data)
new_sample_buf_size - old_size);
}

if (devc->capture_flags & CAPTURE_FLAG_RLE &&
devc->trigger_at_smpl != OLS_NO_TRIGGER &&
devc->trigger_rle_at_smpl_from_end ==
OLS_NO_TRIGGER &&
(unsigned int)devc->trigger_at_smpl ==
devc->cnt_rx_raw_samples)
devc->trigger_rle_at_smpl_from_end =
devc->cnt_samples;

for (i = 0; i < samples_to_write; i++)
memcpy(devc->sample_buf +
(devc->cnt_samples + i) * 4,
Expand Down Expand Up @@ -555,6 +574,19 @@ SR_PRIV int ols_receive_data(int fd, int revents, void *cb_data)
devc->cnt_rx_bytes, devc->cnt_rx_raw_samples,
devc->cnt_samples);

if (devc->capture_flags & CAPTURE_FLAG_RLE) {
if (devc->trigger_rle_at_smpl_from_end !=
OLS_NO_TRIGGER)
devc->trigger_at_smpl =
devc->cnt_samples -
devc->trigger_rle_at_smpl_from_end;
else {
if (devc->trigger_at_smpl != OLS_NO_TRIGGER)
sr_warn("No trigger point found. Short read?");
devc->trigger_at_smpl = OLS_NO_TRIGGER;
}
}

/*
* The OLS sends its sample buffer backwards.
* Flip it back before sending it on the session bus.
Expand Down Expand Up @@ -649,7 +681,7 @@ ols_set_basic_trigger_stage(const struct ols_basic_trigger_desc *trigger_desc,

SR_PRIV int ols_prepare_acquisition(const struct sr_dev_inst *sdi)
{
int ret;
int ret, trigger_point;
uint32_t readcount, delaycount;

struct dev_context *devc = sdi->priv;
Expand All @@ -673,6 +705,7 @@ SR_PRIV int ols_prepare_acquisition(const struct sr_dev_inst *sdi)
(MIN(devc->max_samples / num_changroups, devc->limit_samples) + 3)
/ 4 * 4;
readcount = devc->limit_samples / 4;
trigger_point = OLS_NO_TRIGGER;

/* Basic triggers. */
struct ols_basic_trigger_desc basic_trigger_desc;
Expand All @@ -690,7 +723,7 @@ SR_PRIV int ols_prepare_acquisition(const struct sr_dev_inst *sdi)
return SR_ERR;

delaycount = readcount * (1 - devc->capture_ratio / 100.0);
devc->trigger_at_smpl = (readcount - delaycount) * 4 - 1;
trigger_point = (readcount - delaycount) * 4 - 1;
for (int i = 0; i < basic_trigger_desc.num_stages; i++) {
sr_dbg("Setting OLS stage %d trigger.", i);
if ((ret = ols_set_basic_trigger_stage(
Expand All @@ -707,6 +740,18 @@ SR_PRIV int ols_prepare_acquisition(const struct sr_dev_inst *sdi)
delaycount = readcount;
}

/*
* To determine the proper trigger sample position in RLE mode, a reverse
* lookup is needed while reading the samples. Set up the right trigger
* point in that case or the normal trigger point for non-RLE acquisitions.
*/
devc->trigger_at_smpl =
trigger_point == OLS_NO_TRIGGER ?
OLS_NO_TRIGGER :
devc->capture_flags & CAPTURE_FLAG_RLE ?
(int)devc->limit_samples - trigger_point :
trigger_point;

/* Samplerate. */
sr_dbg("Setting samplerate to %" PRIu64 "Hz (divider %u)",
devc->cur_samplerate, devc->cur_samplerate_divider);
Expand Down
1 change: 1 addition & 0 deletions src/hardware/openbench-logic-sniffer/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ struct dev_context {
uint64_t limit_samples;
uint64_t capture_ratio;
int trigger_at_smpl;
int trigger_rle_at_smpl_from_end;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But in genral, this patch is cool :)

uint16_t capture_flags;

unsigned int cnt_rx_bytes; /* number of bytes received */
Expand Down