From 77ec4308bcb1ce3a20206ac27d6765fda092f4fd Mon Sep 17 00:00:00 2001
From: Eric Kooistra <kooistra@astron.nl>
Date: Thu, 23 Feb 2023 17:38:44 +0100
Subject: [PATCH] Get all blocks from packets. Add beamlet output index
 counters.

---
 .../tb_disturb2_unb2b_sdp_station_full_wg.vhd | 77 +++++++++++--------
 1 file changed, 45 insertions(+), 32 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 c2451724e2..b3ad16ece0 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
@@ -166,8 +166,12 @@ ARCHITECTURE tb OF tb_disturb2_unb2b_sdp_station_full_wg IS
   SIGNAL rd_beamlet_scale    : STD_LOGIC_VECTOR(15 DOWNTO 0);
 
   -- 10GbE
-  SIGNAL dbg_beamlet_index_offset : NATURAL := 0;
+  SIGNAL rx_beamlet_index_offset : NATURAL := 0;
 
+  SIGNAL rx_beamlet_blk      : NATURAL := 0;
+  SIGNAL rx_beamlet_cnt      : NATURAL := 0;
+  SIGNAL rx_beamlet_valid    : STD_LOGIC := '0';
+  SIGNAL rx_beamlet_sop      : STD_LOGIC := '0';
   SIGNAL beamlet_arr2_re : t_slv_8_arr(c_sdp_R_os * c_sdp_N_pol_bf * c_sdp_cep_nof_beamlets_per_block-1 DOWNTO 0);
   SIGNAL beamlet_arr2_im : t_slv_8_arr(c_sdp_R_os * c_sdp_N_pol_bf * c_sdp_cep_nof_beamlets_per_block-1 DOWNTO 0);
 
@@ -396,50 +400,59 @@ 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 blk IN 0 TO 6 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);
       FOR I IN 0 TO 8 LOOP -- Packet header is 9.25 words wide, which can be discarded
         IF I = 7 THEN
           v_beamlet_index_offset :=  c_sdp_N_pol_bf * TO_UINT(tr_10GbE_src_out.data(39 DOWNTO 24)); -- Read beamlet index
-          dbg_beamlet_index_offset <= v_beamlet_index_offset;
+          rx_beamlet_index_offset <= v_beamlet_index_offset;
         END IF;
         proc_common_wait_until_high(ext_clk, tr_10GbE_src_out.valid);
-        proc_common_wait_some_cycles(ext_clk, 1);
       END LOOP;
   
-      -- Get first beamlets block from the packet
-      -- . First word contains 1 header part of two bytes and 3 beamlets
-      --   [0:2]. The data is send big endian so index [0] first, therefore
-      --   beamlet.re[0] is at [47:40].
-      beamlet_arr2_re(v_beamlet_index_offset + 0) <= tr_10GbE_src_out.data(47 DOWNTO 40);
-      beamlet_arr2_im(v_beamlet_index_offset + 0) <= tr_10GbE_src_out.data(39 DOWNTO 32);
-      beamlet_arr2_re(v_beamlet_index_offset + 1) <= tr_10GbE_src_out.data(31 DOWNTO 24);
-      beamlet_arr2_im(v_beamlet_index_offset + 1) <= tr_10GbE_src_out.data(23 DOWNTO 16);
-      beamlet_arr2_re(v_beamlet_index_offset + 2) <= tr_10GbE_src_out.data(15 DOWNTO 8);
-      beamlet_arr2_im(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);
-      -- . There are 4 complex beamlets per 64b word
-      FOR I IN 1 TO (c_sdp_N_pol_bf * c_sdp_cep_nof_beamlets_per_block/4)-1 LOOP
-        beamlet_arr2_re(v_beamlet_index_offset + I*4 -1) <= tr_10GbE_src_out.data(63 DOWNTO 56);
-        beamlet_arr2_im(v_beamlet_index_offset + I*4 -1) <= tr_10GbE_src_out.data(55 DOWNTO 48);
-        beamlet_arr2_re(v_beamlet_index_offset + I*4 +0) <= tr_10GbE_src_out.data(47 DOWNTO 40);
-        beamlet_arr2_im(v_beamlet_index_offset + I*4 +0) <= tr_10GbE_src_out.data(39 DOWNTO 32);
-        beamlet_arr2_re(v_beamlet_index_offset + I*4 +1) <= tr_10GbE_src_out.data(31 DOWNTO 24);
-        beamlet_arr2_im(v_beamlet_index_offset + I*4 +1) <= tr_10GbE_src_out.data(23 DOWNTO 16);
-        beamlet_arr2_re(v_beamlet_index_offset + I*4 +2) <= tr_10GbE_src_out.data(15 DOWNTO 8);
-        beamlet_arr2_im(v_beamlet_index_offset + I*4 +2) <= tr_10GbE_src_out.data(7 DOWNTO 0);
+      -- Get all c_sdp_cep_nof_blocks_per_packet = 4 blocks from the packet
+      FOR blk IN 0 TO c_sdp_cep_nof_blocks_per_packet-1 LOOP
+        -- . First word contains 1 header part of two bytes and 3 beamlets [0:2].
+        -- . expect c_sdp_cep_nof_beamlets_per_block = c_sdp_S_sub_bf = 488 dual pol
+        --   and complex beamlets per packet, so 2 dual pol beamlets/64b data word.
+        -- . Beamlets array is stored big endian in the data, so X index 0 first in
+        --   MSByte of tr_10GbE_src_out.data.
+        rx_beamlet_blk <= blk;
+        rx_beamlet_cnt <= 0;
+        rx_beamlet_valid <= '1';
+        rx_beamlet_sop <= '1';
+        beamlet_arr2_im(v_beamlet_index_offset + 0) <= tr_10GbE_src_out.data(47 DOWNTO 40);
+        beamlet_arr2_re(v_beamlet_index_offset + 0) <= tr_10GbE_src_out.data(39 DOWNTO 32);
+        beamlet_arr2_im(v_beamlet_index_offset + 1) <= tr_10GbE_src_out.data(31 DOWNTO 24);
+        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);
+        rx_beamlet_cnt <= rx_beamlet_cnt + 1;
+        rx_beamlet_sop <= '0';
+        -- . get beamlets during block, there are 4 complex beamlets per 64b word
+        FOR I IN 1 TO (c_sdp_N_pol_bf * c_sdp_cep_nof_beamlets_per_block/4)-1 LOOP
+          beamlet_arr2_im(v_beamlet_index_offset + I*4 -1) <= tr_10GbE_src_out.data(63 DOWNTO 56);
+          beamlet_arr2_re(v_beamlet_index_offset + I*4 -1) <= tr_10GbE_src_out.data(55 DOWNTO 48);
+          beamlet_arr2_im(v_beamlet_index_offset + I*4 +0) <= tr_10GbE_src_out.data(47 DOWNTO 40);
+          beamlet_arr2_re(v_beamlet_index_offset + I*4 +0) <= tr_10GbE_src_out.data(39 DOWNTO 32);
+          beamlet_arr2_im(v_beamlet_index_offset + I*4 +1) <= tr_10GbE_src_out.data(31 DOWNTO 24);
+          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);
+          rx_beamlet_cnt <= rx_beamlet_cnt + 1;
+        END LOOP;
+        -- . get last beamlet of block
+        beamlet_arr2_im(v_beamlet_index_offset + c_sdp_N_pol_bf * c_sdp_cep_nof_beamlets_per_block-1) <= tr_10GbE_src_out.data(63 DOWNTO 56);
+        beamlet_arr2_re(v_beamlet_index_offset + c_sdp_N_pol_bf * c_sdp_cep_nof_beamlets_per_block-1) <= tr_10GbE_src_out.data(55 DOWNTO 48);
         proc_common_wait_some_cycles(ext_clk, 1);
+        rx_beamlet_valid <= '0';
+        -- Loop for next block.
       END LOOP;
 
-      beamlet_arr2_re(v_beamlet_index_offset + c_sdp_N_pol_bf * c_sdp_cep_nof_beamlets_per_block-1) <= tr_10GbE_src_out.data(55 DOWNTO 48);
-      beamlet_arr2_im(v_beamlet_index_offset + c_sdp_N_pol_bf * c_sdp_cep_nof_beamlets_per_block-1) <= tr_10GbE_src_out.data(63 DOWNTO 56);
-
-      -- There are c_sdp_cep_nof_blocks_per_packet = 4 blocks per packet. Only
-      -- read the first beamlets block in the packet, the other three beamlets
-      -- blocks in the packet contain the same. Loop and wait for next packet.
+      -- Loop and wait for next packet.
     END LOOP;
 
     ---------------------------------------------------------------------------
-- 
GitLab