From ecebcb1894d2c751e962a80b277e6609310d2c5d Mon Sep 17 00:00:00 2001
From: Erik Kooistra <kooistra@astron.nl>
Date: Wed, 19 Oct 2016 13:47:50 +0000
Subject: [PATCH] Added verification of nof_wb_streams > 1

---
 .../dsp/wpfb/tb/vhdl/tb_wpfb_unit_wide.vhd    | 79 +++++++++++--------
 1 file changed, 45 insertions(+), 34 deletions(-)

diff --git a/libraries/dsp/wpfb/tb/vhdl/tb_wpfb_unit_wide.vhd b/libraries/dsp/wpfb/tb/vhdl/tb_wpfb_unit_wide.vhd
index 66ee79b323..5b220ded5d 100644
--- a/libraries/dsp/wpfb/tb/vhdl/tb_wpfb_unit_wide.vhd
+++ b/libraries/dsp/wpfb/tb/vhdl/tb_wpfb_unit_wide.vhd
@@ -37,8 +37,8 @@
 --   . tb supports use_separate for complex and two real input 
 --   . tb supports use_reorder for complex input with flipped or reordered output
 --   . tb supports use_reorder for two real input with reordered output
+--   . tb does support nof_wb_streams > 1
 --   . tb does not yet support nof_chan > 0 
---   . tb does not yet support nof_streams > 1
 -- 
 -- Usage:
 --   > run -all
@@ -66,15 +66,15 @@ use work.wpfb_pkg.all;
 entity tb_wpfb_unit_wide is
   generic(
     -- DUT generics
-    g_wpfb : t_wpfb := (4, 32, 0, 1,
+    g_wpfb : t_wpfb := (4, 32, 0, 4,
                         16, 1, 8, 16, 16,
-                        true, false, true, 16, 16, 1, c_dsp_mult_w, 2, true, 56, 2,  
+                        true, false, false, 16, 16, 0, c_dsp_mult_w, 2, true, 56, 2,  
                         c_fft_pipeline, c_fft_pipeline, c_fil_ppf_pipeline);
     --  type t_wpfb is record  
     --    -- General parameters for the wideband poly phase filter
     --    wb_factor         : natural;        -- = default 4, wideband factor
     --    nof_points        : natural;        -- = 1024, N point FFT (Also the number of subbands for the filter part)
-    --    nof_chan          : natural;        -- = default 0, defines the number of channels (=time-multiplexed input signals): nof channels = 2**nof_chan     
+    --    nof_chan          : natural;        -- = default 0, defines the number of channels (=time-multiplexed input signals): nof channels = 2**nof_chan
     --    nof_wb_streams    : natural;        -- = 1, the number of parallel wideband streams. The filter coefficients are shared on every wb-stream. 
     --    
     --    -- Parameters for the poly phase filter
@@ -162,7 +162,7 @@ architecture tb of tb_wpfb_unit_wide is
   
   constant c_in_complex            : boolean := not g_wpfb.use_separate;
   
-  constant c_nof_channels          : natural := 1;
+  constant c_nof_channels          : natural := 2**g_wpfb.nof_chan;
   constant c_nof_coefs             : natural := g_wpfb.nof_taps * g_wpfb.nof_points;       -- nof PFIR coef
 
   constant c_nof_data_per_block    : natural := g_wpfb.nof_points * c_nof_channels;
@@ -250,10 +250,10 @@ architecture tb of tb_wpfb_unit_wide is
   signal t_blk                  : integer := 0;  -- block time counter
 
   -- Input
-  signal in_re_arr              : t_fft_slv_arr(g_wpfb.wb_factor-1 downto 0);
-  signal in_im_arr              : t_fft_slv_arr(g_wpfb.wb_factor-1 downto 0);
-  signal in_re_data             : std_logic_vector(g_wpfb.wb_factor*c_in_dat_w-1 DOWNTO 0);
-  signal in_im_data             : std_logic_vector(g_wpfb.wb_factor*c_in_dat_w-1 DOWNTO 0);
+  signal in_re_arr              : t_fft_slv_arr(g_wpfb.nof_wb_streams*g_wpfb.wb_factor-1 downto 0);
+  signal in_im_arr              : t_fft_slv_arr(g_wpfb.nof_wb_streams*g_wpfb.wb_factor-1 downto 0);
+  signal in_re_data             : std_logic_vector(g_wpfb.wb_factor*c_in_dat_w-1 DOWNTO 0);  -- scope data only for stream 0
+  signal in_im_data             : std_logic_vector(g_wpfb.wb_factor*c_in_dat_w-1 DOWNTO 0);  -- scope data only for stream 0
   signal in_val                 : std_logic:= '0';
   signal in_val_cnt             : natural := 0;
   signal in_gap                 : std_logic := '0';
@@ -266,10 +266,10 @@ architecture tb of tb_wpfb_unit_wide is
 
   -- Filter output
   signal fil_sosi_arr           : t_dp_sosi_arr(g_wpfb.nof_wb_streams*g_wpfb.wb_factor-1 downto 0);
-  signal fil_re_arr             : t_fft_slv_arr(g_wpfb.wb_factor-1 downto 0);
-  signal fil_im_arr             : t_fft_slv_arr(g_wpfb.wb_factor-1 downto 0);
-  signal fil_re_data            : std_logic_vector(g_wpfb.wb_factor*c_fil_dat_w-1 DOWNTO 0);
-  signal fil_im_data            : std_logic_vector(g_wpfb.wb_factor*c_fil_dat_w-1 DOWNTO 0);
+  signal fil_re_arr             : t_fft_slv_arr(g_wpfb.nof_wb_streams*g_wpfb.wb_factor-1 downto 0);
+  signal fil_im_arr             : t_fft_slv_arr(g_wpfb.nof_wb_streams*g_wpfb.wb_factor-1 downto 0);
+  signal fil_re_data            : std_logic_vector(g_wpfb.wb_factor*c_fil_dat_w-1 DOWNTO 0);  -- scope data only for stream 0
+  signal fil_im_data            : std_logic_vector(g_wpfb.wb_factor*c_fil_dat_w-1 DOWNTO 0);  -- scope data only for stream 0
   signal fil_val                : std_logic:= '0';  -- for parallel output
 
   -- Filter in sclk domain
@@ -281,10 +281,10 @@ architecture tb of tb_wpfb_unit_wide is
   
   -- Output
   signal out_sosi_arr           : t_dp_sosi_arr(g_wpfb.nof_wb_streams*g_wpfb.wb_factor-1 downto 0) := (others=>c_dp_sosi_rst);
-  signal out_re_arr             : t_fft_slv_arr(g_wpfb.wb_factor-1 downto 0);
-  signal out_im_arr             : t_fft_slv_arr(g_wpfb.wb_factor-1 downto 0);
-  signal out_re_data            : std_logic_vector(g_wpfb.wb_factor*c_out_dat_w-1 DOWNTO 0);
-  signal out_im_data            : std_logic_vector(g_wpfb.wb_factor*c_out_dat_w-1 DOWNTO 0);
+  signal out_re_arr             : t_fft_slv_arr(g_wpfb.nof_wb_streams*g_wpfb.wb_factor-1 downto 0);
+  signal out_im_arr             : t_fft_slv_arr(g_wpfb.nof_wb_streams*g_wpfb.wb_factor-1 downto 0);
+  signal out_re_data            : std_logic_vector(g_wpfb.wb_factor*c_out_dat_w-1 DOWNTO 0);  -- scope data only for stream 0
+  signal out_im_data            : std_logic_vector(g_wpfb.wb_factor*c_out_dat_w-1 DOWNTO 0);  -- scope data only for stream 0
   signal out_val                : std_logic:= '0';  -- for parallel output
   signal out_val_cnt            : natural := 0;
   
@@ -360,20 +360,31 @@ begin
 
     -- apply stimuli
     for I in 0 to g_data_file_nof_lines/g_wpfb.wb_factor-1 loop  -- serial
-      for P in 0 to g_wpfb.wb_factor-1 loop  -- parallel
-        vP := g_wpfb.wb_factor-1-P;          -- time to big endian
-        if c_in_complex then
-          in_re_arr(vP) <= TO_SVEC_32(input_data_c_arr((I*g_wpfb.wb_factor+P)*c_nof_complex));
-          in_im_arr(vP) <= TO_SVEC_32(input_data_c_arr((I*g_wpfb.wb_factor+P)*c_nof_complex+1));
-        else
-          in_re_arr(vP) <= TO_SVEC_32(input_data_a_arr(I*g_wpfb.wb_factor+P));
-          in_im_arr(vP) <= TO_SVEC_32(input_data_b_arr(I*g_wpfb.wb_factor+P));
-        end if;
+      for K in 0 to c_nof_channels-1 loop  -- serial
+        for S in 0 to g_wpfb.nof_wb_streams-1 loop  -- parallel
+          for P in 0 to g_wpfb.wb_factor-1 loop  -- parallel
+            vP := g_wpfb.wb_factor-1-P;          -- time to big endian
+            if S=1 then
+              -- if present then stream 1 carries zero data to be able to recognize the stream order in the wave window
+              in_re_arr(S*g_wpfb.wb_factor + vP) <= (OTHERS=>'0');
+              in_im_arr(S*g_wpfb.wb_factor + vP) <= (OTHERS=>'0');
+            else
+              -- stream 0 and if present the other streams >= 2 carry the same input reference data to verify the filter function
+              if c_in_complex then
+                in_re_arr(S*g_wpfb.wb_factor + vP) <= TO_SVEC_32(input_data_c_arr((I*g_wpfb.wb_factor+P)*c_nof_complex));
+                in_im_arr(S*g_wpfb.wb_factor + vP) <= TO_SVEC_32(input_data_c_arr((I*g_wpfb.wb_factor+P)*c_nof_complex+1));
+              else
+                in_re_arr(S*g_wpfb.wb_factor + vP) <= TO_SVEC_32(input_data_a_arr(I*g_wpfb.wb_factor+P));
+                in_im_arr(S*g_wpfb.wb_factor + vP) <= TO_SVEC_32(input_data_b_arr(I*g_wpfb.wb_factor+P));
+              end if;
+            end if;
+          end loop;
+        end loop;
       end loop;
-      in_val <= '1';
+      in_val <= '1';  -- serial
       proc_common_wait_some_cycles(clk, 1);
       if in_gap='1' then
-        in_val <= '0';
+        in_val <= '0';  -- serial
         proc_common_wait_some_cycles(clk, 1);
       end if;
     end loop;
@@ -392,7 +403,7 @@ begin
   ---------------------------------------------------------------
   p_in_sosi_arr : process(in_re_arr, in_im_arr, in_val)
   begin
-    for I in 0 to g_wpfb.wb_factor-1 loop
+    for I in 0 to g_wpfb.nof_wb_streams*g_wpfb.wb_factor-1 loop
       -- DUT input
       in_sosi_arr(I).re    <= RESIZE_DP_DSP_DATA(in_re_arr(I));
       in_sosi_arr(I).im    <= RESIZE_DP_DSP_DATA(in_im_arr(I));
@@ -429,7 +440,7 @@ begin
   
   p_fil_sosi_arr : process(fil_sosi_arr)
   begin
-    for I in 0 to g_wpfb.wb_factor-1 loop
+    for I in 0 to g_wpfb.nof_wb_streams*g_wpfb.wb_factor-1 loop
       fil_re_arr(I) <= RESIZE_SVEC_32(fil_sosi_arr(I).re);
       fil_im_arr(I) <= RESIZE_SVEC_32(fil_sosi_arr(I).im);
     end loop;
@@ -438,7 +449,7 @@ begin
   
   p_out_sosi_arr : process(out_sosi_arr)
   begin
-    for I in 0 to g_wpfb.wb_factor-1 loop
+    for I in 0 to g_wpfb.nof_wb_streams*g_wpfb.wb_factor-1 loop
       out_re_arr(I) <= RESIZE_SVEC_32(out_sosi_arr(I).re);
       out_im_arr(I) <= resize_fft_svec(out_sosi_arr(I).im);
     end loop;
@@ -570,11 +581,11 @@ begin
   end process;
   
   ---------------------------------------------------------------
-  -- INPUT AND OUTPUT DATA SCOPES
+  -- INPUT AND OUTPUT DATA SCOPES : ONLY FOR WB STREAM S = 0
   ---------------------------------------------------------------
   rewire_scope_data : for P in 0 to g_wpfb.wb_factor-1 generate
-    in_re_data( (P+1)*c_in_dat_w-1 downto P*c_in_dat_w) <= in_re_arr( P)(c_in_dat_w-1 downto 0);
-    in_im_data( (P+1)*c_in_dat_w-1 downto P*c_in_dat_w) <= in_im_arr( P)(c_in_dat_w-1 downto 0);
+    in_re_data((P+1)*c_in_dat_w-1 downto P*c_in_dat_w) <= in_re_arr(P)(c_in_dat_w-1 downto 0);
+    in_im_data((P+1)*c_in_dat_w-1 downto P*c_in_dat_w) <= in_im_arr(P)(c_in_dat_w-1 downto 0);
       
     fil_re_data((P+1)*c_fil_dat_w-1 downto P*c_fil_dat_w) <= fil_re_arr(P)(c_fil_dat_w-1 downto 0);
     fil_im_data((P+1)*c_fil_dat_w-1 downto P*c_fil_dat_w) <= fil_im_arr(P)(c_fil_dat_w-1 downto 0);
-- 
GitLab