From b1743314712f2ec342385195a563997dbd286194 Mon Sep 17 00:00:00 2001
From: Eric Kooistra <kooistra@astron.nl>
Date: Fri, 24 Feb 2023 07:44:18 +0100
Subject: [PATCH] Use proc_common_wait_until_clk_and_high() for correct
 rx_beamlet_* read out.

---
 .../tb_disturb2_unb2b_sdp_station_full_wg.vhd       | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/applications/lofar2/designs/lofar2_unb2b_sdp_station/revisions/disturb2_unb2b_sdp_station_full_wg/tb_disturb2_unb2b_sdp_station_full_wg.vhd b/applications/lofar2/designs/lofar2_unb2b_sdp_station/revisions/disturb2_unb2b_sdp_station_full_wg/tb_disturb2_unb2b_sdp_station_full_wg.vhd
index 60428a055e..ef0db39baf 100644
--- a/applications/lofar2/designs/lofar2_unb2b_sdp_station/revisions/disturb2_unb2b_sdp_station_full_wg/tb_disturb2_unb2b_sdp_station_full_wg.vhd
+++ b/applications/lofar2/designs/lofar2_unb2b_sdp_station/revisions/disturb2_unb2b_sdp_station_full_wg/tb_disturb2_unb2b_sdp_station_full_wg.vhd
@@ -419,9 +419,9 @@ BEGIN
 
     -- Read 3 packets to make sure we get 1 from each beamset. It can happen that two packets
     -- (but not three) from the same beamset are received back to back.
-    FOR packet IN 0 TO 10 LOOP
+    FOR packet IN 0 TO 2 LOOP
       -- Get beamlet_index from packet header
-      proc_common_wait_until_high(ext_clk, tr_10GbE_src_out.sop);
+      proc_common_wait_until_clk_and_high(ext_clk, tr_10GbE_src_out.sop);
       FOR I IN 0 TO 8 LOOP -- Packet header is 9.25 words wide, which can be discarded
         IF I = 7 THEN
           rx_beamlet_scale <= tr_10GbE_src_out.data(55 DOWNTO 40);
@@ -434,8 +434,7 @@ BEGIN
           rx_block_period <= tr_10GbE_src_out.data(63 DOWNTO 48);
           rx_bsn(63 DOWNTO 16) <= tr_10GbE_src_out.data(47 DOWNTO 0);
         END IF;
-        proc_common_wait_until_high(ext_clk, tr_10GbE_src_out.valid);
-        proc_common_wait_some_cycles(ext_clk, 1);
+        proc_common_wait_until_clk_and_high(ext_clk, tr_10GbE_src_out.valid);
       END LOOP;
       rx_bsn(15 DOWNTO 0) <= tr_10GbE_src_out.data(63 DOWNTO 48);
 
@@ -456,8 +455,7 @@ BEGIN
         beamlet_arr2_re(v_beamlet_index_offset + 1) <= tr_10GbE_src_out.data(23 DOWNTO 16);
         beamlet_arr2_im(v_beamlet_index_offset + 2) <= tr_10GbE_src_out.data(15 DOWNTO 8);
         beamlet_arr2_re(v_beamlet_index_offset + 2) <= tr_10GbE_src_out.data(7 DOWNTO 0);
-        proc_common_wait_until_high(ext_clk, tr_10GbE_src_out.valid);
-        proc_common_wait_some_cycles(ext_clk, 1);
+        proc_common_wait_until_clk_and_high(ext_clk, tr_10GbE_src_out.valid);
         rx_beamlet_cnt <= rx_beamlet_cnt + 1;
         rx_beamlet_sop <= '0';
         -- . get beamlets during block, there are 4 complex beamlets per 64b word
@@ -470,8 +468,7 @@ BEGIN
           beamlet_arr2_re(v_beamlet_index_offset + I*4 +1) <= tr_10GbE_src_out.data(23 DOWNTO 16);
           beamlet_arr2_im(v_beamlet_index_offset + I*4 +2) <= tr_10GbE_src_out.data(15 DOWNTO 8);
           beamlet_arr2_re(v_beamlet_index_offset + I*4 +2) <= tr_10GbE_src_out.data(7 DOWNTO 0);
-          proc_common_wait_until_high(ext_clk, tr_10GbE_src_out.valid);
-          proc_common_wait_some_cycles(ext_clk, 1);
+          proc_common_wait_until_clk_and_high(ext_clk, tr_10GbE_src_out.valid);
           rx_beamlet_cnt <= rx_beamlet_cnt + 1;
         END LOOP;
         -- . get last beamlet of block
-- 
GitLab