1 |
2 |
danv |
-- Author: Eric Kooistra : kooistra at astron.nl: july 2016
|
2 |
|
|
--------------------------------------------------------------------------------
|
3 |
|
|
--
|
4 |
|
|
-- Copyright (C) 2016
|
5 |
|
|
-- ASTRON (Netherlands Institute for Radio Astronomy) <http://www.astron.nl/>
|
6 |
|
|
-- P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
|
7 |
|
|
--
|
8 |
|
|
-- This program is free software: you can redistribute it and/or modify
|
9 |
|
|
-- it under the terms of the GNU General Public License as published by
|
10 |
|
|
-- the Free Software Foundation, either version 3 of the License, or
|
11 |
|
|
-- (at your option) any later version.
|
12 |
|
|
--
|
13 |
|
|
-- This program is distributed in the hope that it will be useful,
|
14 |
|
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 |
|
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16 |
|
|
-- GNU General Public License for more details.
|
17 |
|
|
--
|
18 |
|
|
-- You should have received a copy of the GNU General Public License
|
19 |
|
|
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
20 |
|
|
--
|
21 |
|
|
--------------------------------------------------------------------------------
|
22 |
|
|
--
|
23 |
|
|
-- Purpose: Test bench for fil_ppf_wide.vhd using file data
|
24 |
|
|
--
|
25 |
|
|
-- The DUT fil_ppf_wide.vhd has wb_factor >= 1 and uses array types and
|
26 |
|
|
-- wb_factor instances of fil_ppf_single.vhd.
|
27 |
|
|
--
|
28 |
|
|
-- Usage:
|
29 |
|
|
-- The g_coefs_file_prefix dat-file and g_data_file dat-file are created by
|
30 |
|
|
-- the Matlab script:
|
31 |
|
|
--
|
32 |
|
|
-- $RADIOHDL_WORK/applications/apertif/matlab/run_pfir.m
|
33 |
|
|
--
|
34 |
|
|
-- yields:
|
35 |
|
|
--
|
36 |
|
|
-- . g_coefs_file_prefix : run_pfir_m_pfir_coeff_fircls1_16taps_128points_16b.dat
|
37 |
|
|
-- . g_data_file : run_pfir_m_sinusoid_chirp_8b_16taps_128points_16b_16b.dat
|
38 |
|
|
--
|
39 |
|
|
-- The g_fil_ppf parameters nof_taps, nof_bands (= nof polyphase), c_in_dat_w,
|
40 |
|
|
-- out_dat_w and coef_dat_w must match the settings in run_pfir.m.
|
41 |
|
|
--
|
42 |
|
|
-- The g_fil_ppf.in_dat_w = 8 bit to fit run_pfir_m_sinusoid_chirp_wg_8b.dat. The
|
43 |
|
|
-- g_fil_ppf.backoff_w = 1 is necessary to accommodate the factor 2 overshoot that
|
44 |
|
|
-- the PFIR output can have.
|
45 |
|
|
--
|
46 |
|
|
-- The g_data_file contains a header followed by the PFIR coefficients, WG
|
47 |
|
|
-- data, PFIR data and PFFT data. The tb verifies that the PFIR coefficients
|
48 |
|
|
-- are the same as in the dat-fil indicated by g_coefs_file_prefix. The PFFT
|
49 |
|
|
-- data is not used in this tb.
|
50 |
|
|
--
|
51 |
|
|
-- The MIF files are generated from the g_coefs_file_prefix dat-file by
|
52 |
|
|
-- the Python script:
|
53 |
|
|
--
|
54 |
|
|
-- $RADIOHDL_WORK/libraries/dsp/filter/src/python/
|
55 |
|
|
-- python fil_ppf_create_mifs.py -f ../hex/run_pfir_m_pfir_coeff_fircls1_16taps_128points_16b.dat -t 16 -p 128 -w 1 -c 16
|
56 |
|
|
-- python fil_ppf_create_mifs.py -f ../hex/run_pfir_m_pfir_coeff_fircls1_16taps_128points_16b.dat -t 16 -p 128 -w 4 -c 16
|
57 |
|
|
--
|
58 |
|
|
-- yields:
|
59 |
|
|
--
|
60 |
|
|
-- . run_pfir_m_pfir_coeff_fircls1_16taps_128points_16b_1wb_#.mif, where # = 0:15
|
61 |
|
|
-- . run_pfir_m_pfir_coeff_fircls1_16taps_128points_16b_4wb_#.mif, where # = 0:64
|
62 |
|
|
--
|
63 |
|
|
-- The PFIR coefficient dat and mif files are kept in local ../hex
|
64 |
|
|
-- The input and expected output dat files are kept in local ../data.
|
65 |
|
|
--
|
66 |
|
|
-- The dat files that are created by Matlab first need to be copied manually
|
67 |
|
|
-- to these local directories and then the mif files need to be generated.
|
68 |
|
|
-- The modelsim_copy_files key in the hdllib.cfg will copy these files to the
|
69 |
|
|
-- build directory from where they are loaded by Modelsim.
|
70 |
|
|
--
|
71 |
|
|
-- > run -all
|
72 |
|
|
-- > testbench is selftesting.
|
73 |
|
|
-- > observe the *_scope as radix decimal, format analogue format signals
|
74 |
|
|
-- in the Wave window
|
75 |
|
|
--
|
76 |
|
|
library ieee, common_pkg_lib, dp_pkg_lib, astron_diagnostics_lib, astron_ram_lib, astron_mm_lib, astron_sim_tools_lib;
|
77 |
|
|
use IEEE.std_logic_1164.all;
|
78 |
|
|
use IEEE.numeric_std.all;
|
79 |
|
|
use IEEE.std_logic_textio.all;
|
80 |
|
|
use std.textio.all;
|
81 |
|
|
use common_pkg_lib.common_pkg.all;
|
82 |
|
|
use astron_ram_lib.common_ram_pkg.ALL;
|
83 |
|
|
use common_pkg_lib.common_lfsr_sequences_pkg.ALL;
|
84 |
|
|
use common_pkg_lib.tb_common_pkg.all;
|
85 |
|
|
use astron_mm_lib.tb_common_mem_pkg.ALL;
|
86 |
|
|
use dp_pkg_lib.dp_stream_pkg.ALL;
|
87 |
|
|
use work.fil_pkg.all;
|
88 |
|
|
|
89 |
|
|
entity tb_fil_ppf_wide_file_data is
|
90 |
|
|
generic(
|
91 |
|
|
-- generics for tb
|
92 |
|
|
g_big_endian_wb_in : boolean := true;
|
93 |
|
|
g_big_endian_wb_out : boolean := true;
|
94 |
|
|
g_fil_ppf_pipeline : t_fil_ppf_pipeline := (1, 1, 1, 1, 1, 1, 0);
|
95 |
|
|
-- type t_fil_pipeline is record
|
96 |
|
|
-- -- generic for the taps and coefficients memory
|
97 |
|
|
-- mem_delay : natural; -- = 2
|
98 |
|
|
-- -- generics for the multiplier in in the filter unit
|
99 |
|
|
-- mult_input : natural; -- = 1
|
100 |
|
|
-- mult_product : natural; -- = 1
|
101 |
|
|
-- mult_output : natural; -- = 1
|
102 |
|
|
-- -- generics for the adder tree in in the filter unit
|
103 |
|
|
-- adder_stage : natural; -- = 1
|
104 |
|
|
-- -- generics for the requantizer in the filter unit
|
105 |
|
|
-- requant_remove_lsb : natural; -- = 1
|
106 |
|
|
-- requant_remove_msb : natural; -- = 0
|
107 |
|
|
-- end record;
|
108 |
|
|
g_fil_ppf : t_fil_ppf := (4, 0, 128, 16, 2, 1, 8, 16, 16);
|
109 |
|
|
-- type t_fil_ppf is record
|
110 |
|
|
-- wb_factor : natural; -- = 4, the wideband factor
|
111 |
|
|
-- nof_chan : natural; -- = default 0, defines the number of channels (=time-multiplexed input signals): nof channels = 2**nof_chan
|
112 |
|
|
-- nof_bands : natural; -- = 1024, the number of polyphase channels (= number of points of the FFT)
|
113 |
|
|
-- nof_taps : natural; -- = 16, the number of FIR taps per subband
|
114 |
|
|
-- nof_streams : natural; -- = 1, the number of streams that are served by the same coefficients.
|
115 |
|
|
-- backoff_w : natural; -- = 0, number of bits for input backoff to avoid output overflow
|
116 |
|
|
-- in_dat_w : natural; -- = 8, number of input bits per stream
|
117 |
|
|
-- out_dat_w : natural; -- = 16, number of output bits (per stream)
|
118 |
|
|
-- coef_dat_w : natural; -- = 16, data width of the FIR coefficients
|
119 |
|
|
-- end record;
|
120 |
|
|
g_coefs_file_prefix : string := "hex/run_pfir_m_pfir_coeff_fircls1";
|
121 |
|
|
g_data_file : string := "data/run_pfir_m_sinusoid_chirp_8b_16taps_128points_16b_16b.dat"; -- coefs, input and output data for 1 stream
|
122 |
|
|
g_data_file_nof_lines : natural := 25600; -- number of lines with input data that is available in the g_data_file
|
123 |
|
|
|
124 |
|
|
g_data_file_nof_read : natural := 5000; -- number of lines with input data to read and simulate, must be <= g_data_file_nof_lines
|
125 |
|
|
g_enable_in_val_gaps : boolean := FALSE
|
126 |
|
|
);
|
127 |
|
|
end entity tb_fil_ppf_wide_file_data;
|
128 |
|
|
|
129 |
|
|
architecture tb of tb_fil_ppf_wide_file_data is
|
130 |
|
|
|
131 |
|
|
constant c_clk_period : time := 10 ns;
|
132 |
|
|
constant c_sclk_period : time := c_clk_period / g_fil_ppf.wb_factor;
|
133 |
|
|
|
134 |
|
|
constant c_diff_margin : integer := 0; -- maximum difference between PFIR HDL output and expected output (> 0 to allow minor rounding differences)
|
135 |
|
|
|
136 |
|
|
constant c_nof_channels : natural := 2**g_fil_ppf.nof_chan;
|
137 |
|
|
constant c_nof_coefs : natural := g_fil_ppf.nof_taps * g_fil_ppf.nof_bands; -- nof PFIR coef
|
138 |
|
|
constant c_nof_data_per_block : natural := g_fil_ppf.nof_bands * c_nof_channels; -- 1 block corresponds to 1 tap
|
139 |
|
|
constant c_nof_valid_per_block : natural := c_nof_data_per_block / g_fil_ppf.wb_factor;
|
140 |
|
|
|
141 |
|
|
constant c_rnd_factor : natural := sel_a_b(g_enable_in_val_gaps, 3, 1);
|
142 |
|
|
constant c_dut_block_latency : natural := 2;
|
143 |
|
|
constant c_dut_clk_latency : natural := c_nof_valid_per_block * c_dut_block_latency * c_rnd_factor; -- worst case
|
144 |
|
|
|
145 |
|
|
-- input/output data width
|
146 |
|
|
constant c_in_dat_w : natural := g_fil_ppf.in_dat_w;
|
147 |
|
|
constant c_out_dat_w : natural := g_fil_ppf.out_dat_w;
|
148 |
|
|
|
149 |
|
|
-- PFIR coefficients file access
|
150 |
|
|
constant c_coefs_dat_file_prefix : string := g_coefs_file_prefix & "_" & integer'image(g_fil_ppf.nof_taps) & "taps" &
|
151 |
|
|
"_" & integer'image(g_fil_ppf.nof_bands) & "points" &
|
152 |
|
|
"_" & integer'image(g_fil_ppf.coef_dat_w) & "b";
|
153 |
|
|
constant c_coefs_mif_file_prefix : string := c_coefs_dat_file_prefix & "_" & integer'image(g_fil_ppf.wb_factor) & "wb";
|
154 |
|
|
|
155 |
|
|
-- Data file access
|
156 |
|
|
constant c_nof_lines_pfir_coefs : natural := c_nof_coefs;
|
157 |
|
|
constant c_nof_lines_wg_dat : natural := g_data_file_nof_lines;
|
158 |
|
|
constant c_nof_lines_pfir_dat : natural := c_nof_lines_wg_dat;
|
159 |
|
|
constant c_nof_lines_header : natural := 4;
|
160 |
|
|
constant c_nof_lines_header_wg : natural := c_nof_lines_header + c_nof_lines_pfir_coefs;
|
161 |
|
|
constant c_nof_lines_header_pfir : natural := c_nof_lines_header + c_nof_lines_pfir_coefs + c_nof_lines_wg_dat;
|
162 |
|
|
|
163 |
|
|
-- signal definitions
|
164 |
|
|
signal tb_end : std_logic := '0';
|
165 |
|
|
signal tb_end_almost : std_logic := '0';
|
166 |
|
|
signal clk : std_logic := '0';
|
167 |
|
|
signal sclk : std_logic := '1';
|
168 |
|
|
signal rst : std_logic := '0';
|
169 |
|
|
signal random : std_logic_vector(15 DOWNTO 0) := (OTHERS=>'0'); -- use different lengths to have different random sequences
|
170 |
|
|
|
171 |
|
|
signal coefs_dat_arr : t_integer_arr(c_nof_coefs-1 downto 0) := (OTHERS=>0); -- = PFIR coef for all taps as read from via c_coefs_dat_file_prefix
|
172 |
|
|
signal coefs_ref_arr : t_integer_arr(c_nof_coefs-1 downto 0) := (OTHERS=>0); -- = PFIR coef for all taps as read from via g_data_file
|
173 |
|
|
|
174 |
|
|
signal expected_data_arr : t_integer_arr(0 to g_data_file_nof_read-1) := (OTHERS=>0);
|
175 |
|
|
signal input_data_arr : t_integer_arr(0 to g_data_file_nof_read-1) := (OTHERS=>0);
|
176 |
|
|
signal input_data : std_logic_vector(g_fil_ppf.wb_factor*c_in_dat_w-1 DOWNTO 0);
|
177 |
|
|
signal input_data_scope : integer;
|
178 |
|
|
|
179 |
|
|
signal in_dat_arr : t_fil_slv_arr(g_fil_ppf.wb_factor*g_fil_ppf.nof_streams-1 downto 0); -- = t_slv_32_arr fits g_fil_ppf.in_dat_w <= 32
|
180 |
|
|
signal in_val : std_logic;
|
181 |
|
|
signal in_val_cnt : natural := 0;
|
182 |
|
|
signal in_sub_val : std_logic;
|
183 |
|
|
signal in_sub_val_cnt : natural := 0;
|
184 |
|
|
signal in_gap : std_logic := '0';
|
185 |
|
|
|
186 |
|
|
signal tsub : integer := 0; -- subband time counter
|
187 |
|
|
signal exp_data : std_logic_vector(g_fil_ppf.wb_factor*c_out_dat_w-1 DOWNTO 0);
|
188 |
|
|
signal exp_data_scope : integer;
|
189 |
|
|
signal diff_data_scope : integer;
|
190 |
|
|
signal output_data_scope : integer;
|
191 |
|
|
signal output_data : std_logic_vector(g_fil_ppf.wb_factor*c_out_dat_w-1 DOWNTO 0);
|
192 |
|
|
signal out_dat_arr : t_fil_slv_arr(g_fil_ppf.wb_factor*g_fil_ppf.nof_streams-1 downto 0); -- = t_slv_32_arr fits g_fil_ppf.out_dat_w <= 32
|
193 |
|
|
signal out_val : std_logic;
|
194 |
|
|
signal out_val_cnt : natural := 0;
|
195 |
|
|
signal out_sub_val : std_logic;
|
196 |
|
|
signal out_sub_val_cnt : natural := 0;
|
197 |
|
|
|
198 |
|
|
begin
|
199 |
|
|
|
200 |
|
|
sclk <= (not sclk) or tb_end after c_sclk_period/2;
|
201 |
|
|
clk <= (not clk) or tb_end after c_clk_period/2;
|
202 |
|
|
rst <= '1', '0' after c_clk_period*7;
|
203 |
|
|
random <= func_common_random(random) WHEN rising_edge(clk);
|
204 |
|
|
in_gap <= random(random'HIGH) WHEN g_enable_in_val_gaps=TRUE ELSE '0';
|
205 |
|
|
|
206 |
|
|
---------------------------------------------------------------
|
207 |
|
|
-- DATA INPUT
|
208 |
|
|
---------------------------------------------------------------
|
209 |
|
|
--
|
210 |
|
|
-- In this testbench use:
|
211 |
|
|
--
|
212 |
|
|
-- parallel serial type
|
213 |
|
|
-- in_dat_arr [wb_factor][nof_streams] [t][nof_channels] int
|
214 |
|
|
--
|
215 |
|
|
-- The time to wb_factor mapping for the fil_ppf_wide is big endian,
|
216 |
|
|
-- so [3:0] = [t0,t1,t2,t3], when g_big_endian_wb_in = TRUE.
|
217 |
|
|
-- When wb_factor = 4 and nof_streams = 2 then the mapping is as
|
218 |
|
|
-- follows (S = stream index, P = wideband factor index):
|
219 |
|
|
--
|
220 |
|
|
-- t P S
|
221 |
|
|
-- 0 3 0
|
222 |
|
|
-- 0 3 1
|
223 |
|
|
-- 1 2 0
|
224 |
|
|
-- 1 2 1
|
225 |
|
|
-- 2 1 0
|
226 |
|
|
-- 2 1 1
|
227 |
|
|
-- 3 0 0
|
228 |
|
|
-- 3 0 1
|
229 |
|
|
p_input_stimuli : process
|
230 |
|
|
variable vP : natural;
|
231 |
|
|
begin
|
232 |
|
|
-- read input data from file
|
233 |
|
|
proc_common_read_integer_file(g_data_file, c_nof_lines_header_wg, g_data_file_nof_read, 1, input_data_arr);
|
234 |
|
|
wait for 1 ns;
|
235 |
|
|
tb_end <= '0';
|
236 |
|
|
in_dat_arr <= (others=>(others=>'0'));
|
237 |
|
|
in_val <= '0';
|
238 |
|
|
proc_common_wait_until_low(clk, rst); -- Wait until reset has finished
|
239 |
|
|
proc_common_wait_some_cycles(clk, 10); -- Wait an additional amount of cycles
|
240 |
|
|
|
241 |
|
|
-- apply stimuli
|
242 |
|
|
for I in 0 to g_data_file_nof_read/g_fil_ppf.wb_factor-1 loop -- serial
|
243 |
|
|
for K in 0 to c_nof_channels-1 loop -- serial
|
244 |
|
|
for P in 0 to g_fil_ppf.wb_factor-1 loop -- parallel
|
245 |
|
|
if g_big_endian_wb_in=TRUE then
|
246 |
|
|
vP := g_fil_ppf.wb_factor-1-P; -- time to wideband big endian
|
247 |
|
|
else
|
248 |
|
|
vP := P; -- time to wideband little endian
|
249 |
|
|
end if;
|
250 |
|
|
for S in 0 to g_fil_ppf.nof_streams-1 loop -- parallel
|
251 |
|
|
if S=1 then
|
252 |
|
|
-- if present then stream 1 carries zero data to be able to recognize the stream order in the wave window
|
253 |
|
|
in_dat_arr(vP*g_fil_ppf.nof_streams + S) <= (OTHERS=>'0');
|
254 |
|
|
else
|
255 |
|
|
-- stream 0 and if present the other streams >= 2 carry the same input reference data to verify the filter function
|
256 |
|
|
in_dat_arr(vP*g_fil_ppf.nof_streams + S) <= TO_SVEC(input_data_arr(I*g_fil_ppf.wb_factor + P), c_fil_slv_w);
|
257 |
|
|
end if;
|
258 |
|
|
in_val <= '1';
|
259 |
|
|
end loop;
|
260 |
|
|
end loop;
|
261 |
|
|
in_val <= '1';
|
262 |
|
|
proc_common_wait_some_cycles(clk, 1);
|
263 |
|
|
if in_gap='1' then
|
264 |
|
|
in_val <= '0';
|
265 |
|
|
proc_common_wait_some_cycles(clk, 1);
|
266 |
|
|
end if;
|
267 |
|
|
end loop;
|
268 |
|
|
end loop;
|
269 |
|
|
|
270 |
|
|
-- Wait until done
|
271 |
|
|
in_val <= '0';
|
272 |
|
|
proc_common_wait_some_cycles(clk, c_dut_clk_latency); -- wait for at least PPF latency of 1 tap
|
273 |
|
|
tb_end_almost <= '1';
|
274 |
|
|
proc_common_wait_some_cycles(clk, 100);
|
275 |
|
|
tb_end <= '1';
|
276 |
|
|
wait;
|
277 |
|
|
end process;
|
278 |
|
|
|
279 |
|
|
---------------------------------------------------------------
|
280 |
|
|
-- DUT = Device Under Test
|
281 |
|
|
---------------------------------------------------------------
|
282 |
|
|
u_dut : entity work.fil_ppf_wide
|
283 |
|
|
generic map (
|
284 |
|
|
g_big_endian_wb_in => g_big_endian_wb_in,
|
285 |
|
|
g_big_endian_wb_out => g_big_endian_wb_out,
|
286 |
|
|
g_fil_ppf => g_fil_ppf,
|
287 |
|
|
g_fil_ppf_pipeline => g_fil_ppf_pipeline,
|
288 |
|
|
g_coefs_file_prefix => c_coefs_mif_file_prefix
|
289 |
|
|
)
|
290 |
|
|
port map (
|
291 |
|
|
dp_clk => clk,
|
292 |
|
|
dp_rst => rst,
|
293 |
|
|
mm_clk => clk,
|
294 |
|
|
mm_rst => rst,
|
295 |
|
|
ram_coefs_mosi => c_mem_mosi_rst,
|
296 |
|
|
ram_coefs_miso => OPEN,
|
297 |
|
|
in_dat_arr => in_dat_arr,
|
298 |
|
|
in_val => in_val,
|
299 |
|
|
out_dat_arr => out_dat_arr,
|
300 |
|
|
out_val => out_val
|
301 |
|
|
);
|
302 |
|
|
|
303 |
|
|
---------------------------------------------------------------
|
304 |
|
|
-- Verify PFIR coefficients
|
305 |
|
|
---------------------------------------------------------------
|
306 |
|
|
p_verify_pfir_coefs_files : PROCESS
|
307 |
|
|
begin
|
308 |
|
|
-- Verify that the PFIR coefficients in g_data_file are the same as those in c_coefs_dat_file_prefix.dat
|
309 |
|
|
-- Just assume that the c_coefs_dat_file_prefix.dat is the same as the PFIR coefficients that are loaded via the MIFs,
|
310 |
|
|
-- so do not read back the PFIR coefficients via MM.
|
311 |
|
|
proc_common_read_integer_file(c_coefs_dat_file_prefix & ".dat", 0, c_nof_coefs, 1, coefs_dat_arr);
|
312 |
|
|
proc_common_read_integer_file(g_data_file, c_nof_lines_header, c_nof_coefs, 1, coefs_ref_arr);
|
313 |
|
|
wait for 1 ns;
|
314 |
|
|
-- Wait until tb_end_almost to avoid that the Error message gets lost in earlier messages
|
315 |
|
|
proc_common_wait_until_high(clk, tb_end_almost);
|
316 |
|
|
assert coefs_dat_arr = coefs_ref_arr report "Unexpected PFIR coefficients." severity error;
|
317 |
|
|
wait;
|
318 |
|
|
end process;
|
319 |
|
|
|
320 |
|
|
---------------------------------------------------------------
|
321 |
|
|
-- VERIFY OUTPUT
|
322 |
|
|
---------------------------------------------------------------
|
323 |
|
|
p_verify_out_val_cnt : process
|
324 |
|
|
begin
|
325 |
|
|
-- Wait until tb_end_almost
|
326 |
|
|
proc_common_wait_until_high(clk, tb_end_almost);
|
327 |
|
|
-- The filter has a latency of 1 tap, so there remains in_dat for tap in the filter
|
328 |
|
|
assert in_val_cnt > 0 report "Test did not run, no valid input data" severity error;
|
329 |
|
|
assert out_val_cnt = in_val_cnt-c_nof_valid_per_block report "Unexpected number of valid output data" severity error;
|
330 |
|
|
wait;
|
331 |
|
|
end process;
|
332 |
|
|
|
333 |
|
|
tsub <= tsub+1 when rising_edge(clk) and in_sub_val='1' and in_sub_val_cnt > 0 and (in_sub_val_cnt MOD c_nof_valid_per_block = 0);
|
334 |
|
|
|
335 |
|
|
in_sub_val <= '1' when in_val='1' and (in_val_cnt mod c_nof_channels)=0 else '0';
|
336 |
|
|
out_sub_val <= '1' when out_val='1' and (out_val_cnt mod c_nof_channels)=0 else '0';
|
337 |
|
|
in_sub_val_cnt <= in_val_cnt/c_nof_channels;
|
338 |
|
|
out_sub_val_cnt <= out_val_cnt/c_nof_channels;
|
339 |
|
|
|
340 |
|
|
in_val_cnt <= in_val_cnt+1 when rising_edge(clk) and in_val='1' else in_val_cnt;
|
341 |
|
|
out_val_cnt <= out_val_cnt+1 when rising_edge(clk) and out_val='1' else out_val_cnt;
|
342 |
|
|
|
343 |
|
|
p_expected_output : process
|
344 |
|
|
begin
|
345 |
|
|
-- read expected output data from file
|
346 |
|
|
proc_common_read_integer_file(g_data_file, c_nof_lines_header_pfir, g_data_file_nof_read, 1, expected_data_arr);
|
347 |
|
|
wait;
|
348 |
|
|
end process;
|
349 |
|
|
|
350 |
|
|
p_verify_output : process(clk)
|
351 |
|
|
variable vI : natural := 0;
|
352 |
|
|
variable vK : natural := 0;
|
353 |
|
|
variable vP : natural;
|
354 |
|
|
variable v_out_dat : integer;
|
355 |
|
|
variable v_exp_dat : integer;
|
356 |
|
|
begin
|
357 |
|
|
if rising_edge(clk) then
|
358 |
|
|
if out_val='1' then
|
359 |
|
|
for P in 0 to g_fil_ppf.wb_factor-1 loop -- parallel
|
360 |
|
|
if g_big_endian_wb_out=true then
|
361 |
|
|
vP := g_fil_ppf.wb_factor-1-P; -- time to wideband big endian
|
362 |
|
|
else
|
363 |
|
|
vP := P; -- time to wideband little endian
|
364 |
|
|
end if;
|
365 |
|
|
for S in 0 to g_fil_ppf.nof_streams-1 loop -- parallel
|
366 |
|
|
v_out_dat := TO_SINT(out_dat_arr(vP*g_fil_ppf.nof_streams + S));
|
367 |
|
|
if S=1 then
|
368 |
|
|
-- stream 1 carries zero data
|
369 |
|
|
v_exp_dat := 0;
|
370 |
|
|
assert v_out_dat = v_exp_dat report "Output data error (stream 1 not zero)" severity error;
|
371 |
|
|
else
|
372 |
|
|
-- stream 0 and all other streams >= 2 carry the same data
|
373 |
|
|
v_exp_dat := expected_data_arr(vI*g_fil_ppf.wb_factor + P);
|
374 |
|
|
assert v_out_dat <= v_exp_dat + c_diff_margin and
|
375 |
|
|
v_out_dat >= v_exp_dat - c_diff_margin report "Output data error" severity error;
|
376 |
|
|
end if;
|
377 |
|
|
end loop;
|
378 |
|
|
end loop;
|
379 |
|
|
if vK < c_nof_channels-1 then -- serial
|
380 |
|
|
vK := vK + 1;
|
381 |
|
|
else
|
382 |
|
|
vK := 0;
|
383 |
|
|
vI := vI + 1;
|
384 |
|
|
end if;
|
385 |
|
|
end if;
|
386 |
|
|
end if;
|
387 |
|
|
end process;
|
388 |
|
|
|
389 |
|
|
---------------------------------------------------------------
|
390 |
|
|
-- DATA SCOPES
|
391 |
|
|
---------------------------------------------------------------
|
392 |
|
|
p_input_data : process(in_dat_arr)
|
393 |
|
|
constant cS : natural := 0; -- tap the input_data from stream 0
|
394 |
|
|
begin
|
395 |
|
|
for P in 0 to g_fil_ppf.wb_factor-1 loop
|
396 |
|
|
input_data((P+1)*c_in_dat_w-1 downto P*c_in_dat_w) <= in_dat_arr(P*g_fil_ppf.nof_streams + cS)(c_in_dat_w-1 downto 0);
|
397 |
|
|
end loop;
|
398 |
|
|
end process;
|
399 |
|
|
|
400 |
|
|
p_output_data : process(out_dat_arr)
|
401 |
|
|
variable cS : natural; -- tap the output_data from stream 0
|
402 |
|
|
begin
|
403 |
|
|
for P in 0 to g_fil_ppf.wb_factor-1 loop
|
404 |
|
|
output_data((P+1)*c_out_dat_w-1 DOWNTO P*c_out_dat_w) <= out_dat_arr(P*g_fil_ppf.nof_streams + cS)(c_out_dat_w-1 downto 0);
|
405 |
|
|
end loop;
|
406 |
|
|
end process;
|
407 |
|
|
|
408 |
|
|
p_exp_data : process(expected_data_arr, out_sub_val_cnt)
|
409 |
|
|
variable vP : natural;
|
410 |
|
|
begin
|
411 |
|
|
for P in 0 to g_fil_ppf.wb_factor-1 loop
|
412 |
|
|
if g_big_endian_wb_out=true then
|
413 |
|
|
vP := g_fil_ppf.wb_factor-1-P;
|
414 |
|
|
else
|
415 |
|
|
vP := P;
|
416 |
|
|
end if;
|
417 |
|
|
exp_data((vP+1)*c_out_dat_w-1 DOWNTO vP*c_out_dat_w) <= TO_SVEC(expected_data_arr(out_sub_val_cnt*g_fil_ppf.wb_factor + P), c_out_dat_w);
|
418 |
|
|
end loop;
|
419 |
|
|
end process;
|
420 |
|
|
|
421 |
|
|
u_input_data_scope : entity astron_sim_tools_lib.common_wideband_data_scope
|
422 |
|
|
generic map (
|
423 |
|
|
g_sim => TRUE,
|
424 |
|
|
g_wideband_factor => g_fil_ppf.wb_factor, -- Wideband rate factor = 4 for dp_clk processing frequency is 200 MHz frequency and SCLK sample frequency Fs is 800 MHz
|
425 |
|
|
g_wideband_big_endian => g_big_endian_wb_in, -- When true in_data[3:0] = sample[t0,t1,t2,t3], else when false : in_data[3:0] = sample[t3,t2,t1,t0]
|
426 |
|
|
g_dat_w => c_in_dat_w -- Actual width of the data samples
|
427 |
|
|
)
|
428 |
|
|
port map (
|
429 |
|
|
-- Sample clock
|
430 |
|
|
SCLK => sclk, -- sample clk, use only for simulation purposes
|
431 |
|
|
|
432 |
|
|
-- Streaming input data
|
433 |
|
|
in_data => input_data,
|
434 |
|
|
in_val => in_val,
|
435 |
|
|
|
436 |
|
|
-- Scope output samples
|
437 |
|
|
out_dat => OPEN,
|
438 |
|
|
out_int => input_data_scope
|
439 |
|
|
);
|
440 |
|
|
|
441 |
|
|
u_exp_data_scope : entity astron_sim_tools_lib.common_wideband_data_scope
|
442 |
|
|
generic map (
|
443 |
|
|
g_sim => TRUE,
|
444 |
|
|
g_wideband_factor => g_fil_ppf.wb_factor, -- Wideband rate factor = 4 for dp_clk processing frequency is 200 MHz frequency and SCLK sample frequency Fs is 800 MHz
|
445 |
|
|
g_wideband_big_endian => g_big_endian_wb_out, -- When true in_data[3:0] = sample[t0,t1,t2,t3], else when false : in_data[3:0] = sample[t3,t2,t1,t0]
|
446 |
|
|
g_dat_w => c_out_dat_w -- Actual width of the data samples
|
447 |
|
|
)
|
448 |
|
|
port map (
|
449 |
|
|
-- Sample clock
|
450 |
|
|
SCLK => sclk, -- sample clk, use only for simulation purposes
|
451 |
|
|
|
452 |
|
|
-- Streaming input data
|
453 |
|
|
in_data => exp_data,
|
454 |
|
|
in_val => out_val,
|
455 |
|
|
|
456 |
|
|
-- Scope output samples
|
457 |
|
|
out_dat => OPEN,
|
458 |
|
|
out_int => exp_data_scope
|
459 |
|
|
);
|
460 |
|
|
|
461 |
|
|
u_output_data_scope : entity astron_sim_tools_lib.common_wideband_data_scope
|
462 |
|
|
generic map (
|
463 |
|
|
g_sim => TRUE,
|
464 |
|
|
g_wideband_factor => g_fil_ppf.wb_factor, -- Wideband rate factor = 4 for dp_clk processing frequency is 200 MHz frequency and SCLK sample frequency Fs is 800 MHz
|
465 |
|
|
g_wideband_big_endian => g_big_endian_wb_out, -- When true in_data[3:0] = sample[t0,t1,t2,t3], else when false : in_data[3:0] = sample[t3,t2,t1,t0]
|
466 |
|
|
g_dat_w => c_out_dat_w -- Actual width of the data samples
|
467 |
|
|
)
|
468 |
|
|
port map (
|
469 |
|
|
-- Sample clock
|
470 |
|
|
SCLK => sclk, -- sample clk, use only for simulation purposes
|
471 |
|
|
|
472 |
|
|
-- Streaming input data
|
473 |
|
|
in_data => output_data,
|
474 |
|
|
in_val => out_val,
|
475 |
|
|
|
476 |
|
|
-- Scope output samples
|
477 |
|
|
out_dat => OPEN,
|
478 |
|
|
out_int => output_data_scope
|
479 |
|
|
);
|
480 |
|
|
|
481 |
|
|
diff_data_scope <= exp_data_scope - output_data_scope;
|
482 |
|
|
|
483 |
|
|
-- Equivalent to p_verify_output, but using the sclk scope data
|
484 |
|
|
p_verify_data_scope : process(sclk)
|
485 |
|
|
begin
|
486 |
|
|
if rising_edge(clk) then
|
487 |
|
|
assert diff_data_scope <= c_diff_margin and
|
488 |
|
|
diff_data_scope >= -c_diff_margin report "Output data scope error" severity error;
|
489 |
|
|
end if;
|
490 |
|
|
end process;
|
491 |
|
|
|
492 |
|
|
end tb;
|