@@ -159,6 +159,7 @@ SR_PRIV struct dev_context *ols_dev_new(void)
159159
160160 devc = g_malloc0 (sizeof (struct dev_context ));
161161 devc -> trigger_at_smpl = OLS_NO_TRIGGER ;
162+ devc -> trigger_rle_at_smpl_from_end = OLS_NO_TRIGGER ;
162163
163164 return devc ;
164165}
@@ -462,6 +463,15 @@ SR_PRIV int ols_receive_data(int fd, int revents, void *cb_data)
462463 devc -> rle_count );
463464 devc -> raw_sample_size = 0 ;
464465
466+ if (devc -> trigger_at_smpl !=
467+ OLS_NO_TRIGGER &&
468+ devc -> trigger_rle_at_smpl_from_end ==
469+ OLS_NO_TRIGGER &&
470+ (unsigned int )devc -> trigger_at_smpl ==
471+ devc -> cnt_rx_raw_samples )
472+ devc -> trigger_rle_at_smpl_from_end =
473+ devc -> cnt_samples ;
474+
465475 /*
466476 * Even on the rare occasion that the sampling ends with an RLE message,
467477 * the acquisition should end immediately, without any timeout.
@@ -523,6 +533,15 @@ SR_PRIV int ols_receive_data(int fd, int revents, void *cb_data)
523533 new_sample_buf_size - old_size );
524534 }
525535
536+ if (devc -> capture_flags & CAPTURE_FLAG_RLE &&
537+ devc -> trigger_at_smpl != OLS_NO_TRIGGER &&
538+ devc -> trigger_rle_at_smpl_from_end ==
539+ OLS_NO_TRIGGER &&
540+ (unsigned int )devc -> trigger_at_smpl ==
541+ devc -> cnt_rx_raw_samples )
542+ devc -> trigger_rle_at_smpl_from_end =
543+ devc -> cnt_samples ;
544+
526545 for (i = 0 ; i < samples_to_write ; i ++ )
527546 memcpy (devc -> sample_buf +
528547 (devc -> cnt_samples + i ) * 4 ,
@@ -555,6 +574,19 @@ SR_PRIV int ols_receive_data(int fd, int revents, void *cb_data)
555574 devc -> cnt_rx_bytes , devc -> cnt_rx_raw_samples ,
556575 devc -> cnt_samples );
557576
577+ if (devc -> capture_flags & CAPTURE_FLAG_RLE ) {
578+ if (devc -> trigger_rle_at_smpl_from_end !=
579+ OLS_NO_TRIGGER )
580+ devc -> trigger_at_smpl =
581+ devc -> cnt_samples -
582+ devc -> trigger_rle_at_smpl_from_end ;
583+ else {
584+ if (devc -> trigger_at_smpl != OLS_NO_TRIGGER )
585+ sr_warn ("No trigger point found. Short read?" );
586+ devc -> trigger_at_smpl = OLS_NO_TRIGGER ;
587+ }
588+ }
589+
558590 /*
559591 * The OLS sends its sample buffer backwards.
560592 * Flip it back before sending it on the session bus.
@@ -649,7 +681,7 @@ ols_set_basic_trigger_stage(const struct ols_basic_trigger_desc *trigger_desc,
649681
650682SR_PRIV int ols_prepare_acquisition (const struct sr_dev_inst * sdi )
651683{
652- int ret ;
684+ int ret , trigger_point ;
653685 uint32_t readcount , delaycount ;
654686
655687 struct dev_context * devc = sdi -> priv ;
@@ -673,6 +705,7 @@ SR_PRIV int ols_prepare_acquisition(const struct sr_dev_inst *sdi)
673705 (MIN (devc -> max_samples / num_changroups , devc -> limit_samples ) + 3 )
674706 / 4 * 4 ;
675707 readcount = devc -> limit_samples / 4 ;
708+ trigger_point = OLS_NO_TRIGGER ;
676709
677710 /* Basic triggers. */
678711 struct ols_basic_trigger_desc basic_trigger_desc ;
@@ -690,7 +723,7 @@ SR_PRIV int ols_prepare_acquisition(const struct sr_dev_inst *sdi)
690723 return SR_ERR ;
691724
692725 delaycount = readcount * (1 - devc -> capture_ratio / 100.0 );
693- devc -> trigger_at_smpl = (readcount - delaycount ) * 4 - 1 ;
726+ trigger_point = (readcount - delaycount ) * 4 - 1 ;
694727 for (int i = 0 ; i < basic_trigger_desc .num_stages ; i ++ ) {
695728 sr_dbg ("Setting OLS stage %d trigger." , i );
696729 if ((ret = ols_set_basic_trigger_stage (
@@ -707,6 +740,18 @@ SR_PRIV int ols_prepare_acquisition(const struct sr_dev_inst *sdi)
707740 delaycount = readcount ;
708741 }
709742
743+ /*
744+ * To determine the proper trigger sample position in RLE mode, a reverse
745+ * lookup is needed while reading the samples. Set up the right trigger
746+ * point in that case or the normal trigger point for non-RLE acquisitions.
747+ */
748+ devc -> trigger_at_smpl =
749+ trigger_point == OLS_NO_TRIGGER ?
750+ OLS_NO_TRIGGER :
751+ devc -> capture_flags & CAPTURE_FLAG_RLE ?
752+ (int )devc -> limit_samples - trigger_point :
753+ trigger_point ;
754+
710755 /* Samplerate. */
711756 sr_dbg ("Setting samplerate to %" PRIu64 "Hz (divider %u)" ,
712757 devc -> cur_samplerate , devc -> cur_samplerate_divider );
0 commit comments