From 6bb01fce3cc123d05d16ad61ce7fdc5047f83ec3 Mon Sep 17 00:00:00 2001
From: Eric Kooistra <kooistra@astron.nl>
Date: Thu, 24 Aug 2023 11:43:56 +0200
Subject: [PATCH] Add subtypes. Rename c_sdp_cep_nof_beamlets_per_longword into
 c_sdp_nof_beamlets_per_longword.

---
 .../lofar2/libraries/sdp/src/vhdl/sdp_pkg.vhd     | 15 +++++++++++++--
 .../lofar2/libraries/sdp/tb/vhdl/tb_sdp_pkg.vhd   | 10 ++++++----
 2 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/applications/lofar2/libraries/sdp/src/vhdl/sdp_pkg.vhd b/applications/lofar2/libraries/sdp/src/vhdl/sdp_pkg.vhd
index 3b7b9ec057..4283c9e67b 100644
--- a/applications/lofar2/libraries/sdp/src/vhdl/sdp_pkg.vhd
+++ b/applications/lofar2/libraries/sdp/src/vhdl/sdp_pkg.vhd
@@ -137,11 +137,23 @@ package sdp_pkg is
   constant c_sdp_N_beamlets_sdp          : natural := c_sdp_N_beamsets * c_sdp_S_sub_bf;  -- = 976
   constant c_sdp_W_dual_pol_beamlet      : natural := c_sdp_N_pol_bf * c_nof_complex * c_sdp_W_beamlet;  -- 2 * 2 * 8 = 32b
 
+  constant c_sdp_nof_beamlets_per_longword : natural := 2;  -- 2 dual pol, complex, 8bit beamlets fit in 1 64bit longword
+
   -- . unit weights
   constant c_sdp_unit_sub_weight      : natural := 2**c_sdp_W_sub_weight_fraction;  -- 2**13, so range +-4.0 for 16 bit signed weight
   constant c_sdp_unit_bf_weight       : natural := 2**c_sdp_W_bf_weight_fraction;  -- 2**14, so range +-2.0 for 16 bit signed weight
   constant c_sdp_unit_beamlet_scale   : natural := 2**c_sdp_W_beamlet_scale_fraction;  -- 2**15, so range +-1.0 for 16 bit signed weight
 
+  -- One dual polarization beamlet fits in a 32b word:
+  -- [0:3] = [Xre, Xim, Yre, Yim] parts of c_sdp_W_beamlet = 8 bit, so
+  -- c_sdp_N_pol_bf * c_nof_complex * c_sdp_W_beamlet = 2 * 2 = 4 octets
+  subtype t_sdp_dual_pol_beamlet_in_word is t_slv_8_arr(0 to 3);
+
+  -- Two dual polarization beamlets fit in a 64b longword:
+  -- [0:7] = [0:3,4:7] = [Xre, Xim, Yre, Yim,  Xre, Xim, Yre, Yim], so
+  -- c_sdp_nof_beamlets_per_longword * c_sdp_N_pol_bf * c_nof_complex = 2 * 2 * 2 = 8 octets
+  subtype t_sdp_dual_pol_beamlet_in_longword is t_slv_8_arr(0 to 7);
+
   -----------------------------------------------------------------------------
   -- PFB
   -----------------------------------------------------------------------------
@@ -409,8 +421,7 @@ package sdp_pkg is
   constant c_sdp_cep_nof_blocks_per_packet     : natural := 4;  -- number of time blocks of beamlets per output packet
   constant c_sdp_cep_nof_beamlets_per_block    : natural := c_sdp_S_sub_bf;  -- number of dual pol beamlets (c_sdp_N_pol_bf = 2)
   constant c_sdp_cep_nof_beamlets_per_packet   : natural := c_sdp_cep_nof_blocks_per_packet * c_sdp_cep_nof_beamlets_per_block;
-  constant c_sdp_cep_nof_beamlets_per_longword : natural := 2;  -- 2 dual pol, complex, 8bit beamlets fit in 1 64bit longword
-  constant c_sdp_cep_payload_nof_longwords     : natural := c_sdp_cep_nof_beamlets_per_packet / c_sdp_cep_nof_beamlets_per_longword;  -- = 976
+  constant c_sdp_cep_payload_nof_longwords     : natural := c_sdp_cep_nof_beamlets_per_packet / c_sdp_nof_beamlets_per_longword;  -- = 976
   constant c_sdp_cep_packet_nof_longwords      : natural := ceil_div(c_sdp_cep_header_len, c_longword_sz) + c_sdp_cep_payload_nof_longwords;  -- without tail CRC, the CRC is applied by 10GbE MAC
 
   constant c_sdp_cep_nof_hdr_fields : natural := 3 + 12 + 4 + 4 + 9 + 6 + 1;  -- = 39 fields
diff --git a/applications/lofar2/libraries/sdp/tb/vhdl/tb_sdp_pkg.vhd b/applications/lofar2/libraries/sdp/tb/vhdl/tb_sdp_pkg.vhd
index ce46462c4d..858594c6fb 100644
--- a/applications/lofar2/libraries/sdp/tb/vhdl/tb_sdp_pkg.vhd
+++ b/applications/lofar2/libraries/sdp/tb/vhdl/tb_sdp_pkg.vhd
@@ -109,9 +109,10 @@ package tb_sdp_pkg is
   -- Beamlet output packet
   -----------------------------------------------------------------------------
   -- beamlet part index [0 : 3] of X, Y, X, Y in network longword:
-  -- . re[0 : 3] at 0, 2, 4, 6 in longword
-  -- . im[0 : 3] at 1, 3, 5, 7 in longword
-  subtype t_sdp_beamlet_part_arr is t_slv_8_arr(0 to c_sdp_cep_nof_beamlets_per_longword * c_sdp_N_pol_bf - 1);
+  -- - use separate array for re and for im:
+  --   . re[0 : 3] at 0, 2, 4, 6 in longword
+  --   . im[0 : 3] at 1, 3, 5, 7 in longword
+  subtype t_sdp_beamlet_part_arr is t_slv_8_arr(0 to c_sdp_nof_beamlets_per_longword * c_sdp_N_pol_bf - 1);
 
   -- beamlet part index in packet with 4 blocks [0 : 4 * 488 * 2 - 1] = [0 : 3903]
   -- . use separate list for re and for im
@@ -500,7 +501,8 @@ package body tb_sdp_pkg is
   --   v_out = func_sdp_bdo_transpose_packet(4, 488, v_in) yields the expected v_out.
   -- . See data repacking section in:
   --   https://support.astron.nl/confluence/pages/viewpage.action?spaceKey=L2M&title=L4+SDPFW+Decision%3A+Multiple+beamlet+output+destinations
-  -- . Use separate packet_list for re and im
+  -- . Use separate packet_list for re and im. The list contain 4 * 488 * 2 = 3904
+  --   beamlet part octet values.
   -- input packet_list:
   -- . blk               0,            1,            2,            3,  for nof_blocks_per_packet = 4
   -- . blet   0,   ... 487, 0,   ... 487, 0,   ... 487, 0,   ... 487,  for nof_beamlets_per_block = 488
-- 
GitLab