@@ -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 );
0 commit comments