Skip to content

Commit 6791751

Browse files
committed
ols: Determine the right trigger point when using RLE
Due to the nature of RLE, the number of samples from the start to the trigger point is unknown. What is known is that the hardware triggers still records a given number of raw samples to its sample memory. When reading and expanding these raw samples from the back (remember, OLS sends the recording back-to-front), remember the expanded sample position from the back and then map it back to the right position from the front once the total number of expanded samples is known.
1 parent e73bf19 commit 6791751

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

src/hardware/openbench-logic-sniffer/api.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
403403

404404
/* Reset all operational states. */
405405
devc->rle_count = 0;
406+
devc->trigger_rle_at_smpl_from_end = OLS_NO_TRIGGER;
406407
devc->cnt_samples = devc->raw_sample_size = 0;
407408
devc->cnt_rx_bytes = devc->cnt_rx_raw_samples = 0;
408409
memset(devc->raw_sample, 0, 4);

src/hardware/openbench-logic-sniffer/protocol.c

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ SR_PRIV struct dev_context *ols_dev_new(void)
152152

153153
devc = g_malloc0(sizeof(struct dev_context));
154154
devc->trigger_at_smpl = OLS_NO_TRIGGER;
155+
devc->trigger_rle_at_smpl_from_end = OLS_NO_TRIGGER;
155156

156157
return devc;
157158
}
@@ -434,6 +435,11 @@ SR_PRIV int ols_receive_data(int fd, int revents, void *cb_data)
434435
sr_dbg("RLE count: %u.", devc->rle_count);
435436
devc->raw_sample_size = 0;
436437

438+
if (devc->trigger_at_smpl != OLS_NO_TRIGGER
439+
&& devc->trigger_rle_at_smpl_from_end == OLS_NO_TRIGGER
440+
&& (unsigned int)devc->trigger_at_smpl == devc->cnt_rx_raw_samples)
441+
devc->trigger_rle_at_smpl_from_end = devc->cnt_samples;
442+
437443
/*
438444
* Even on the rare occasion that the sampling ends with an RLE message,
439445
* the acquisition should end immediately, without any timeout.
@@ -488,6 +494,12 @@ SR_PRIV int ols_receive_data(int fd, int revents, void *cb_data)
488494
new_sample_buf_size - old_size);
489495
}
490496

497+
if (devc->capture_flags & CAPTURE_FLAG_RLE
498+
&& devc->trigger_at_smpl != OLS_NO_TRIGGER
499+
&& devc->trigger_rle_at_smpl_from_end == OLS_NO_TRIGGER
500+
&& (unsigned int)devc->trigger_at_smpl == devc->cnt_rx_raw_samples)
501+
devc->trigger_rle_at_smpl_from_end = devc->cnt_samples;
502+
491503
for (i = 0; i < samples_to_write; i++)
492504
memcpy(devc->sample_buf + (devc->cnt_samples + i) * 4, devc->raw_sample,
493505
4);
@@ -516,6 +528,17 @@ SR_PRIV int ols_receive_data(int fd, int revents, void *cb_data)
516528
devc->cnt_rx_bytes, devc->cnt_rx_raw_samples,
517529
devc->cnt_samples);
518530

531+
if (devc->capture_flags & CAPTURE_FLAG_RLE) {
532+
if (devc->trigger_rle_at_smpl_from_end != OLS_NO_TRIGGER)
533+
devc->trigger_at_smpl =
534+
devc->cnt_samples - devc->trigger_rle_at_smpl_from_end;
535+
else {
536+
if (devc->trigger_at_smpl != OLS_NO_TRIGGER)
537+
sr_warn("No trigger point found. Short read?");
538+
devc->trigger_at_smpl = OLS_NO_TRIGGER;
539+
}
540+
}
541+
519542
/*
520543
* The OLS sends its sample buffer backwards.
521544
* Flip it back before sending it on the session bus.
@@ -620,6 +643,7 @@ SR_PRIV int ols_prepare_acquisition(const struct sr_dev_inst *sdi) {
620643
(MIN(devc->max_samples / num_changroups, devc->limit_samples) + 3) / 4 * 4;
621644
uint32_t readcount = devc->limit_samples / 4;
622645
uint32_t delaycount;
646+
int trigger_point = OLS_NO_TRIGGER;
623647

624648
/* Basic triggers. */
625649
struct ols_basic_trigger_desc basic_trigger_desc;
@@ -636,7 +660,7 @@ SR_PRIV int ols_prepare_acquisition(const struct sr_dev_inst *sdi) {
636660
RETURN_ON_ERROR(ols_send_reset(serial));
637661

638662
delaycount = readcount * (1 - devc->capture_ratio / 100.0);
639-
devc->trigger_at_smpl = (readcount - delaycount) * 4 - 1;
663+
trigger_point = (readcount - delaycount) * 4 - 1;
640664
for (int i = 0; i < basic_trigger_desc.num_stages; i++) {
641665
sr_dbg("Setting OLS stage %d trigger.", i);
642666
RETURN_ON_ERROR(ols_set_basic_trigger_stage(&basic_trigger_desc, serial, i));
@@ -649,6 +673,15 @@ SR_PRIV int ols_prepare_acquisition(const struct sr_dev_inst *sdi) {
649673
delaycount = readcount;
650674
}
651675

676+
/*
677+
* To determine the proper trigger sample position in RLE mode, a reverse
678+
* lookup is needed while reading the samples. Set up the right trigger
679+
* point in that case or the normal trigger point for non-RLE acquisitions.
680+
*/
681+
devc->trigger_at_smpl = trigger_point == OLS_NO_TRIGGER ? OLS_NO_TRIGGER
682+
: devc->capture_flags & CAPTURE_FLAG_RLE ?
683+
(int)devc->limit_samples - trigger_point : trigger_point;
684+
652685
/* Samplerate. */
653686
sr_dbg("Setting samplerate to %" PRIu64 "Hz (divider %u)",
654687
devc->cur_samplerate, devc->cur_samplerate_divider);

src/hardware/openbench-logic-sniffer/protocol.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ struct dev_context {
112112
uint64_t limit_samples;
113113
uint64_t capture_ratio;
114114
int trigger_at_smpl;
115+
int trigger_rle_at_smpl_from_end;
115116
uint16_t capture_flags;
116117

117118
unsigned int cnt_rx_bytes; /* number of bytes received */

0 commit comments

Comments
 (0)