From 29335661141864b032b13b5413feaf18e97d4519 Mon Sep 17 00:00:00 2001
From: Eric Kooistra <kooistra@astron.nl>
Date: Tue, 5 Oct 2021 17:01:57 +0200
Subject: [PATCH] Verify zero gap, diff_delay_max and pipeline and read
 latency.

---
 .../base/dp/tb/vhdl/tb_dp_bsn_align_v2.vhd    | 38 +++++++++++--------
 .../base/dp/tb/vhdl/tb_tb_dp_bsn_align_v2.vhd | 21 +++++-----
 2 files changed, 34 insertions(+), 25 deletions(-)

diff --git a/libraries/base/dp/tb/vhdl/tb_dp_bsn_align_v2.vhd b/libraries/base/dp/tb/vhdl/tb_dp_bsn_align_v2.vhd
index 3551678121..5d735d6e82 100644
--- a/libraries/base/dp/tb/vhdl/tb_dp_bsn_align_v2.vhd
+++ b/libraries/base/dp/tb/vhdl/tb_dp_bsn_align_v2.vhd
@@ -23,7 +23,7 @@
 --   . DUT alignment of g_nof_streams
 --   . DUT restart via g_tb_nof_restart > 1
 --   . gaps or no gaps between blocks via g_block_period >= g_block_size
---   . g_bsn_latency_max in combination with g_tb_diff_delay_max
+--   . g_bsn_latency_max in combination with g_tb_diff_delay
 --   . g_use_mm_output using DUT MM to DP or external MM to DP in tb
 --   . g_replacement_value for a remote g_disable_stream (one is enough
 --     to verify), the local stream cannot be disabled.
@@ -46,20 +46,21 @@ ENTITY tb_dp_bsn_align_v2 IS
   GENERIC (
     -- DUT
     g_nof_streams          : NATURAL := 2;      -- number of input and output streams
-    g_bsn_latency_max      : NATURAL := 2;      -- Maximum travel latency of a remote block in number of block periods T_blk
+    g_bsn_latency_max      : NATURAL := 1;      -- Maximum travel latency of a remote block in number of block periods T_blk
     g_nof_aligners_max     : POSITIVE := 1;     -- 1 when only align at last node, > 1 when align at every intermediate node
     g_block_size           : NATURAL := 11;     -- > 1, g_block_size=1 is not supported
     g_block_period         : NATURAL := 20;     -- >= g_block_size, = g_block_size + c_gap_size
     g_bsn_w                : NATURAL := c_dp_stream_bsn_w;  -- number of bits in sosi BSN
     g_data_w               : NATURAL := 16;     -- number of bits in sosi data
     g_replacement_value    : INTEGER := 17;      -- output sosi data replacement value for missing input blocks
-    g_disable_stream       : NATURAL := 1;      -- default 0 to enable all streams, > 0 selects stream that will be disabled
+    g_disable_stream       : NATURAL := 0;      -- default 0 to enable all streams, > 0 selects stream that will be disabled
     g_use_mm_output        : BOOLEAN := FALSE;   -- output via MM or via streaming DP
-    g_pipeline_input       : NATURAL := 1;      -- >= 0, choose 0 for wires, choose 1 to ease timing closure
-    g_rd_latency           : NATURAL := 2;      -- 1 or 2, choose 2 to ease timing closure
+    g_pipeline_input       : NATURAL := 0;      -- >= 0, choose 0 for wires, choose 1 to ease timing closure
+    g_rd_latency           : NATURAL := 1;      -- 1 or 2, choose 2 to ease timing closure
 
     -- TB
-    g_tb_diff_delay_max    : NATURAL := 10;      -- maximum nof clk delay between any inputs, <= c_align_latency_nof_clk
+    g_tb_diff_delay        : INTEGER := 0;       -- 0 = aligned inputs, -1 = max input delay for no loss,
+                                                 -- >~ g_bsn_latency_max * g_block_period will give loss
     g_tb_nof_restart       : NATURAL := 2;       -- number of times to restart the input stimuli
     g_tb_nof_blocks        : NATURAL := 20       -- number of input blocks per restart
   );
@@ -79,8 +80,20 @@ ARCHITECTURE tb OF tb_dp_bsn_align_v2 IS
   CONSTANT c_sync_period              : NATURAL := 7;
   CONSTANT c_sync_offset              : NATURAL := 2;
   
+  -- maximum nof clk delay between any inputs, <= c_align_latency_nof_clk
+  -- . the -1 is due to some acceptable pipeline detail related to dp_block_from_mm
+  CONSTANT c_diff_delay_max           : NATURAL := g_bsn_latency_max * g_block_period - sel_a_b(g_rd_latency > 1, 0, 1);
+  CONSTANT c_diff_delay               : NATURAL := sel_a_b(g_tb_diff_delay < 0, c_diff_delay_max, g_tb_diff_delay);
+
+  -- Return input delay as function of inputs stream index I
+  FUNCTION func_input_delay(I : NATURAL) RETURN NATURAL IS
+  BEGIN
+    RETURN c_diff_delay * I / (g_nof_streams - 1);
+  END;
+
   CONSTANT c_gap_size                 : NATURAL := g_block_period - g_block_size;
-  CONSTANT c_dut_latency              : NATURAL := g_pipeline_input + g_rd_latency + 2;
+  CONSTANT c_mm_to_dp_latency         : NATURAL := 1;
+  CONSTANT c_dut_latency              : NATURAL := g_pipeline_input + g_rd_latency + c_mm_to_dp_latency;
   CONSTANT c_align_latency_nof_blocks : NATURAL := g_bsn_latency_max;  -- DUT buffer latency in number blocks
   CONSTANT c_align_latency_nof_valid  : NATURAL := g_bsn_latency_max * g_block_size;  -- DUT buffer latency in number of data samples
   CONSTANT c_align_latency_nof_clk    : NATURAL := g_bsn_latency_max * g_block_period;  -- DUT buffer latency in number clk cycles
@@ -164,14 +177,7 @@ ARCHITECTURE tb OF tb_dp_bsn_align_v2 IS
   SIGNAL expected_out_bsn_arr  : t_bsn_arr;
   SIGNAL expected_out_data_arr : t_data_arr;
 
-  -- Return input delay as function of inputs stream index I
-  FUNCTION func_input_delay(I : NATURAL) RETURN NATURAL IS
-  BEGIN
-    RETURN g_tb_diff_delay_max * I / (g_nof_streams - 1);
-  END;
-
-  SIGNAL dbg_tb_diff_delay_max : NATURAL := g_tb_diff_delay_max;
-  SIGNAL dbg_func_delay_max : NATURAL := func_input_delay(g_nof_streams - 1);
+  SIGNAL dbg_func_delay_max    : NATURAL := func_input_delay(g_nof_streams - 1);
 
 BEGIN
 
@@ -306,7 +312,7 @@ BEGIN
   --   because the DUT has no flow control and has a fixed latency.
   p_verify_sosi_en_arr : PROCESS(out_sosi_exp)
   BEGIN
-    IF g_tb_diff_delay_max <= c_align_latency_nof_clk THEN
+    IF c_diff_delay <= c_align_latency_nof_clk THEN
       verify_sosi_en_arr <= (OTHERS => '1');
       IF TO_UINT(out_sosi_exp.bsn) - c_bsn_init >= c_verify_nof_blocks THEN
         verify_sosi_en_arr <= (OTHERS => '0');
diff --git a/libraries/base/dp/tb/vhdl/tb_tb_dp_bsn_align_v2.vhd b/libraries/base/dp/tb/vhdl/tb_tb_dp_bsn_align_v2.vhd
index 3805e23c5e..c0662c3aee 100644
--- a/libraries/base/dp/tb/vhdl/tb_tb_dp_bsn_align_v2.vhd
+++ b/libraries/base/dp/tb/vhdl/tb_tb_dp_bsn_align_v2.vhd
@@ -34,11 +34,10 @@ END tb_tb_dp_bsn_align_v2;
 
 ARCHITECTURE tb OF tb_tb_dp_bsn_align_v2 IS
 
-  CONSTANT c_bsn_latency_max      : POSITIVE := 1;
   CONSTANT c_block                : NATURAL := 11;
   CONSTANT c_period               : NATURAL := 20;
-  CONSTANT c_delay_max            : NATURAL := c_bsn_latency_max * c_period;
- 
+  CONSTANT c_nof_blk              : NATURAL := 30;
+
   SIGNAL tb_end : STD_LOGIC := '0';  -- declare tb_end to avoid 'No objects found' error on 'when -label tb_end'
 
 BEGIN
@@ -58,15 +57,19 @@ BEGIN
   -- g_rd_latency                 : NATURAL := 2;      -- 1 or 2, choose 2 to ease timing closure
   --
   -- -- TB
-  -- g_tb_diff_delay_max    : NATURAL := 45;      -- maximum nof clk delay between any inputs, <= c_align_latency
+  -- g_tb_diff_delay        : INTEGER := 0;       -- 0 = aligned inputs, -1 = max input delay for no loss,
+  --                                              -- >~ g_bsn_latency_max * g_block_period will give loss
   -- g_tb_nof_restart       : NATURAL := 1;       -- number of times to restart the input stimuli
   -- g_tb_nof_blocks        : NATURAL := 10       -- number of input blocks per restart
 
-  u_mm_output          : ENTITY work.tb_dp_bsn_align_v2 GENERIC MAP (2, c_bsn_latency_max, 1, c_block, c_period, 32, 16, 17, 0,  TRUE, 0, 1,                0, 1, 50);
-  u_dp_output          : ENTITY work.tb_dp_bsn_align_v2 GENERIC MAP (2, c_bsn_latency_max, 1, c_block, c_period, 32, 16, 17, 0, FALSE, 0, 1,                0, 1, 50);
-  u_dp_disable         : ENTITY work.tb_dp_bsn_align_v2 GENERIC MAP (4, c_bsn_latency_max, 1, c_block, c_period, 32, 16, 17, 2, FALSE, 0, 1,                0, 1, 50);
+  u_mm_output           : ENTITY work.tb_dp_bsn_align_v2 GENERIC MAP (2, 1, 1, c_block, c_period, 32, 16, 17, 0,  TRUE, 0, 1,  0, 2, c_nof_blk);
+  u_dp_output           : ENTITY work.tb_dp_bsn_align_v2 GENERIC MAP (2, 1, 1, c_block, c_period, 32, 16, 17, 0, FALSE, 0, 1,  0, 2, c_nof_blk);
+  u_dp_output_bsn_lat_2 : ENTITY work.tb_dp_bsn_align_v2 GENERIC MAP (2, 2, 1, c_block, c_period, 32, 16, 17, 0, FALSE, 0, 1,  0, 2, c_nof_blk);
+  u_dp_output_bsn_lat_3 : ENTITY work.tb_dp_bsn_align_v2 GENERIC MAP (2, 3, 1, c_block, c_period, 32, 16, 17, 0, FALSE, 0, 1,  0, 2, c_nof_blk);
+  u_dp_output_p1_rd2    : ENTITY work.tb_dp_bsn_align_v2 GENERIC MAP (2, 1, 1, c_block, c_period, 32, 16, 17, 0, FALSE, 1, 2,  0, 2, c_nof_blk);
+  u_dp_zero_gap         : ENTITY work.tb_dp_bsn_align_v2 GENERIC MAP (2, 1, 1, c_block,  c_block, 32, 16, 17, 0, FALSE, 0, 1,  0, 2, c_nof_blk);
+  u_dp_disable_one      : ENTITY work.tb_dp_bsn_align_v2 GENERIC MAP (4, 1, 1, c_block, c_period, 32, 16, 17, 2, FALSE, 0, 1,  0, 2, c_nof_blk);
 
-  u_diff_delay_no_loss : ENTITY work.tb_dp_bsn_align_v2 GENERIC MAP (2, c_bsn_latency_max, 1, c_block, c_period, 32, 16, 17, 0, FALSE, 0, 1,      c_delay_max, 1, 50);
-  --u_loss_replacement   : ENTITY work.tb_dp_bsn_align_v2 GENERIC MAP (2, c_bsn_latency_max, 1, c_block, c_period, 32, 16, 17, 0, FALSE, 0, 1, 40 + c_delay_max, 1, 50);
+  u_diff_delay_no_loss  : ENTITY work.tb_dp_bsn_align_v2 GENERIC MAP (2, 1, 1, c_block, c_period, 32, 16, 17, 0, FALSE, 0, 1, -1, 2, c_nof_blk);
 
 END tb;
-- 
GitLab