1 |
2 |
danv |
--------------------------------------------------------------------------------
|
2 |
|
|
--
|
3 |
3 |
danv |
-- Copyright 2020
|
4 |
2 |
danv |
-- ASTRON (Netherlands Institute for Radio Astronomy) <http://www.astron.nl/>
|
5 |
|
|
-- P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
|
6 |
3 |
danv |
--
|
7 |
|
|
-- Licensed under the Apache License, Version 2.0 (the "License");
|
8 |
|
|
-- you may not use this file except in compliance with the License.
|
9 |
|
|
-- You may obtain a copy of the License at
|
10 |
|
|
--
|
11 |
|
|
-- http://www.apache.org/licenses/LICENSE-2.0
|
12 |
|
|
--
|
13 |
|
|
-- Unless required by applicable law or agreed to in writing, software
|
14 |
|
|
-- distributed under the License is distributed on an "AS IS" BASIS,
|
15 |
|
|
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16 |
|
|
-- See the License for the specific language governing permissions and
|
17 |
|
|
-- limitations under the License.
|
18 |
2 |
danv |
--
|
19 |
|
|
--------------------------------------------------------------------------------
|
20 |
|
|
--
|
21 |
|
|
-- Purpose: Test bench for fft_r2_wide.vhd using file data
|
22 |
|
|
--
|
23 |
|
|
-- Usage:
|
24 |
|
|
-- This tb uses the same Matlab stimuli and expected results as
|
25 |
|
|
-- tb_fft_r2_pipe.vhd.
|
26 |
|
|
--
|
27 |
|
|
-- For the fft_r2_wide wb_factor > 1 and < nof_points, because it implements
|
28 |
|
|
-- a combination of fft_r2_pipe and fft_r2_par.
|
29 |
|
|
-- The fft_r2_wide does support use_reorder.
|
30 |
|
|
-- The fft_r2_wide does support use_separate.
|
31 |
|
|
-- The fft_r2_wide does support input flow control with invalid gaps in the
|
32 |
|
|
-- input.
|
33 |
|
|
-- The fft_r2_wide only supports nof_chan=0, because the concept of channels
|
34 |
|
|
-- is void when wb_factor > 0.
|
35 |
|
|
--
|
36 |
|
|
-- For more description see tb_fft_r2_pipe.vhd.
|
37 |
|
|
--
|
38 |
|
|
-- > run -all
|
39 |
|
|
-- > testbench is selftesting.
|
40 |
|
|
-- > observe the *_scope signals as radix decimal, format analogue format
|
41 |
|
|
-- signals in the Wave window
|
42 |
|
|
--
|
43 |
|
|
library ieee, common_pkg_lib, rTwoSDF_lib, common_ram_lib, mm_lib, other_lib;
|
44 |
|
|
use IEEE.std_logic_1164.all;
|
45 |
|
|
use IEEE.numeric_std.all;
|
46 |
|
|
use IEEE.std_logic_textio.all;
|
47 |
|
|
use std.textio.all;
|
48 |
|
|
use common_pkg_lib.common_pkg.all;
|
49 |
|
|
use common_ram_lib.common_ram_pkg.ALL;
|
50 |
|
|
use common_pkg_lib.common_lfsr_sequences_pkg.ALL;
|
51 |
|
|
use common_pkg_lib.tb_common_pkg.all;
|
52 |
|
|
use mm_lib.tb_common_mem_pkg.ALL;
|
53 |
|
|
use rTwoSDF_lib.rTwoSDFPkg.all;
|
54 |
|
|
use work.fft_pkg.all;
|
55 |
|
|
use work.tb_fft_pkg.all;
|
56 |
|
|
|
57 |
|
|
entity tb_fft_r2_wide is
|
58 |
|
|
generic(
|
59 |
|
|
-- DUT generics
|
60 |
|
|
--g_fft : t_fft := ( true, false, true, 0, 4, 0, 128, 8, 16, 0, c_dsp_mult_w, 2, true, 56, 2); -- two real inputs A and B
|
61 |
|
|
g_fft : t_fft := ( true, false, true, 0, 4, 0, 32, 8, 16, 0, c_dsp_mult_w, 2, true, 56, 2); -- two real inputs A and B
|
62 |
|
|
--g_fft : t_fft := ( true, false, false, 0, 4, 0, 32, 8, 16, 0, c_dsp_mult_w, 2, true, 56, 2); -- complex input reordered
|
63 |
|
|
--g_fft : t_fft := (false, false, false, 0, 4, 0, 32, 8, 16, 0, c_dsp_mult_w, 2, true, 56, 2); -- complex input flipped
|
64 |
|
|
-- type t_rtwo_fft is record
|
65 |
|
|
-- use_reorder : boolean; -- = false for bit-reversed output, true for normal output
|
66 |
|
|
-- use_fft_shift : boolean; -- = false for [0, pos, neg] bin frequencies order, true for [neg, 0, pos] bin frequencies order in case of complex input
|
67 |
|
|
-- use_separate : boolean; -- = false for complex input, true for two real inputs
|
68 |
|
|
-- nof_chan : natural; -- = default 0, defines the number of channels (=time-multiplexed input signals): nof channels = 2**nof_chan
|
69 |
|
|
-- wb_factor : natural; -- = default 1, wideband factor
|
70 |
|
|
-- twiddle_offset : natural; -- = default 0, twiddle offset for PFT sections in a wideband FFT
|
71 |
|
|
-- nof_points : natural; -- = 1024, N point FFT
|
72 |
|
|
-- in_dat_w : natural; -- = 8, number of input bits
|
73 |
|
|
-- out_dat_w : natural; -- = 13, number of output bits, bit growth: in_dat_w + natural((ceil_log2(nof_points))/2 + 2)
|
74 |
|
|
-- out_gain_w : natural; -- = 0, output gain factor applied after the last stage output, before requantization to out_dat_w
|
75 |
|
|
-- stage_dat_w : natural; -- = 18, data width used between the stages(= DSP multiplier-width)
|
76 |
|
|
-- guard_w : natural; -- = 2, Guard used to avoid overflow in FFT stage.
|
77 |
|
|
-- guard_enable : boolean; -- = true when input needs guarding, false when input requires no guarding but scaling must be skipped at the last stage(s) (used in wb fft)
|
78 |
|
|
-- stat_data_w : positive; -- = 56 (= 18b+18b)+log2(781250)
|
79 |
|
|
-- stat_data_sz : positive; -- = 2 (complex re and im)
|
80 |
|
|
-- end record;
|
81 |
|
|
--
|
82 |
|
|
-- TB generics
|
83 |
|
|
g_diff_margin : integer := 2; -- maximum difference between HDL output and expected output (> 0 to allow minor rounding differences)
|
84 |
|
|
|
85 |
|
|
-- Two real input data files A and B used when g_fft.use_separate = true
|
86 |
|
|
-- * 128 points = 64 subbands
|
87 |
|
|
--g_data_file_a : string := "data/run_pfft_m_sinusoid_chirp_8b_128points_16b.dat";
|
88 |
|
|
--g_data_file_a_nof_lines : natural := 25600;
|
89 |
|
|
--g_data_file_b : string := "UNUSED";
|
90 |
|
|
--g_data_file_b_nof_lines : natural := 0;
|
91 |
|
|
|
92 |
|
|
-- * 32 points = 16 subbands
|
93 |
|
|
g_data_file_a : string := "data/run_pfft_m_sinusoid_chirp_8b_32points_16b.dat";
|
94 |
|
|
g_data_file_a_nof_lines : natural := 6400;
|
95 |
|
|
--g_data_file_a : string := "data/run_pfft_m_sinusoid_8b_32points_16b.dat";
|
96 |
|
|
--g_data_file_a_nof_lines : natural := 160;
|
97 |
|
|
|
98 |
|
|
--g_data_file_b : string := "data/run_pfft_m_impulse_chirp_8b_32points_16b.dat";
|
99 |
|
|
--g_data_file_b_nof_lines : natural := 6400;
|
100 |
|
|
g_data_file_b : string := "UNUSED";
|
101 |
|
|
g_data_file_b_nof_lines : natural := 0;
|
102 |
|
|
|
103 |
|
|
-- One complex input data file C used when g_fft.use_separate = false
|
104 |
|
|
-- * 64 points = 64 channels
|
105 |
|
|
--g_data_file_c : string := "data/run_pfft_complex_m_phasor_chirp_8b_64points_16b.dat";
|
106 |
|
|
--g_data_file_c_nof_lines : natural := 12800;
|
107 |
|
|
--g_data_file_c : string := "data/run_pfft_complex_m_phasor_8b_64points_16b.dat";
|
108 |
|
|
--g_data_file_c_nof_lines : natural := 320;
|
109 |
|
|
--g_data_file_c : string := "data/run_pfft_complex_m_noise_8b_64points_16b.dat";
|
110 |
|
|
--g_data_file_c_nof_lines : natural := 640;
|
111 |
|
|
|
112 |
|
|
-- * 32 points = 32 channels
|
113 |
|
|
g_data_file_c : string := "data/run_pfft_complex_m_phasor_chirp_8b_32points_16b.dat";
|
114 |
|
|
g_data_file_c_nof_lines : natural := 6400;
|
115 |
|
|
--g_data_file_c : string := "data/run_pfft_complex_m_phasor_8b_32points_16b.dat";
|
116 |
|
|
--g_data_file_c_nof_lines : natural := 160;
|
117 |
|
|
--g_data_file_c : string := "data/run_pfft_complex_m_noise_8b_32points_16b.dat";
|
118 |
|
|
--g_data_file_c_nof_lines : natural := 320;
|
119 |
|
|
|
120 |
|
|
g_data_file_nof_lines : natural := 6400; -- actual number of lines with input data to simulate from the data files, must be <= g_data_file_*_nof_lines
|
121 |
|
|
g_enable_in_val_gaps : boolean := TRUE -- when false then in_val flow control active continuously, else with random inactive gaps
|
122 |
|
|
);
|
123 |
|
|
end entity tb_fft_r2_wide;
|
124 |
|
|
|
125 |
|
|
architecture tb of tb_fft_r2_wide is
|
126 |
|
|
|
127 |
|
|
constant c_clk_period : time := 10 ns;
|
128 |
|
|
constant c_sclk_period : time := c_clk_period / g_fft.wb_factor;
|
129 |
|
|
|
130 |
|
|
constant c_in_complex : boolean := not g_fft.use_separate;
|
131 |
|
|
constant c_fft_r2_check : boolean := fft_r2_parameter_asserts(g_fft);
|
132 |
|
|
|
133 |
|
|
constant c_nof_channels : natural := 1; -- fixed g_fft.nof_chan=0, because the concept of channels is void when wb_factor > 1
|
134 |
|
|
constant c_nof_data_per_block : natural := g_fft.nof_points * c_nof_channels;
|
135 |
|
|
constant c_nof_valid_per_block : natural := c_nof_data_per_block / g_fft.wb_factor;
|
136 |
|
|
|
137 |
|
|
constant c_rnd_factor : natural := sel_a_b(g_enable_in_val_gaps, 3, 1);
|
138 |
|
|
constant c_dut_block_latency : natural := 4;
|
139 |
|
|
constant c_dut_clk_latency : natural := c_nof_valid_per_block * c_dut_block_latency * c_rnd_factor + 50; -- worst case
|
140 |
|
|
|
141 |
|
|
-- input/output data width
|
142 |
|
|
constant c_in_dat_w : natural := g_fft.in_dat_w;
|
143 |
|
|
constant c_out_dat_w : natural := g_fft.out_dat_w;
|
144 |
|
|
|
145 |
|
|
-- Data file access (Header + WG data + PFFT data)
|
146 |
|
|
constant c_nof_lines_header : natural := 2;
|
147 |
|
|
constant c_nof_lines_a_wg_dat : natural := g_data_file_a_nof_lines; -- Real input A via in_re, one value per line
|
148 |
|
|
constant c_nof_lines_a_wg_header : natural := c_nof_lines_header;
|
149 |
|
|
constant c_nof_lines_a_pfft_dat : natural := g_data_file_a_nof_lines/c_nof_complex; -- Half spectrum, two values per line (re, im)
|
150 |
|
|
constant c_nof_lines_a_pfft_header : natural := c_nof_lines_header + c_nof_lines_a_wg_dat;
|
151 |
|
|
constant c_nof_lines_b_wg_dat : natural := g_data_file_b_nof_lines; -- Real input B via in_im, one value per line
|
152 |
|
|
constant c_nof_lines_b_wg_header : natural := c_nof_lines_header;
|
153 |
|
|
constant c_nof_lines_b_pfft_dat : natural := g_data_file_b_nof_lines/c_nof_complex; -- Half spectrum, two values per line (re, im)
|
154 |
|
|
constant c_nof_lines_b_pfft_header : natural := c_nof_lines_header + c_nof_lines_b_wg_dat;
|
155 |
|
|
constant c_nof_lines_c_wg_dat : natural := g_data_file_c_nof_lines; -- Complex input, two values per line (re, im)
|
156 |
|
|
constant c_nof_lines_c_wg_header : natural := c_nof_lines_header;
|
157 |
|
|
constant c_nof_lines_c_pfft_dat : natural := g_data_file_c_nof_lines; -- Full spectrum, two values per line (re, im)
|
158 |
|
|
constant c_nof_lines_c_pfft_header : natural := c_nof_lines_header + c_nof_lines_c_wg_dat;
|
159 |
|
|
|
160 |
|
|
-- signal definitions
|
161 |
|
|
signal tb_end : std_logic := '0';
|
162 |
|
|
signal tb_end_almost : std_logic := '0';
|
163 |
|
|
signal clk : std_logic := '0';
|
164 |
|
|
signal sclk : std_logic := '0';
|
165 |
|
|
signal rst : std_logic := '0';
|
166 |
|
|
signal random : std_logic_vector(15 DOWNTO 0) := (OTHERS=>'0'); -- use different lengths to have different random sequences
|
167 |
|
|
|
168 |
|
|
signal input_data_a_arr : t_integer_arr(0 to g_data_file_nof_lines-1) := (OTHERS=>0); -- one value per line (A via re input)
|
169 |
|
|
signal input_data_b_arr : t_integer_arr(0 to g_data_file_nof_lines-1) := (OTHERS=>0); -- one value per line (B via im input)
|
170 |
|
|
signal input_data_c_arr : t_integer_arr(0 to g_data_file_nof_lines*c_nof_complex-1) := (OTHERS=>0); -- two values per line (re, im)
|
171 |
|
|
|
172 |
|
|
signal output_data_a_re_arr : t_integer_arr(0 to g_data_file_nof_lines/c_nof_complex-1) := (OTHERS=>0); -- half spectrum, re
|
173 |
|
|
signal output_data_a_im_arr : t_integer_arr(0 to g_data_file_nof_lines/c_nof_complex-1) := (OTHERS=>0); -- half spectrum, im
|
174 |
|
|
signal output_data_b_re_arr : t_integer_arr(0 to g_data_file_nof_lines/c_nof_complex-1) := (OTHERS=>0); -- half spectrum, re
|
175 |
|
|
signal output_data_b_im_arr : t_integer_arr(0 to g_data_file_nof_lines/c_nof_complex-1) := (OTHERS=>0); -- half spectrum, im
|
176 |
|
|
signal output_data_c_re_arr : t_integer_arr(0 to g_data_file_nof_lines-1) := (OTHERS=>0); -- full spectrum, re
|
177 |
|
|
signal output_data_c_im_arr : t_integer_arr(0 to g_data_file_nof_lines-1) := (OTHERS=>0); -- full spectrum, im
|
178 |
|
|
|
179 |
|
|
signal expected_data_a_arr : t_integer_arr(0 to g_data_file_nof_lines-1) := (OTHERS=>0); -- half spectrum, two values per line (re, im)
|
180 |
|
|
signal expected_data_a_re_arr : t_integer_arr(0 to g_data_file_nof_lines/c_nof_complex-1) := (OTHERS=>0); -- half spectrum, re
|
181 |
|
|
signal expected_data_a_im_arr : t_integer_arr(0 to g_data_file_nof_lines/c_nof_complex-1) := (OTHERS=>0); -- half spectrum, im
|
182 |
|
|
signal expected_data_b_arr : t_integer_arr(0 to g_data_file_nof_lines-1) := (OTHERS=>0); -- half spectrum, two values per line (re, im)
|
183 |
|
|
signal expected_data_b_re_arr : t_integer_arr(0 to g_data_file_nof_lines/c_nof_complex-1) := (OTHERS=>0); -- half spectrum, re
|
184 |
|
|
signal expected_data_b_im_arr : t_integer_arr(0 to g_data_file_nof_lines/c_nof_complex-1) := (OTHERS=>0); -- half spectrum, im
|
185 |
|
|
signal expected_data_c_arr : t_integer_arr(0 to g_data_file_nof_lines*c_nof_complex-1) := (OTHERS=>0); -- full spectrum, two values per line (re, im)
|
186 |
|
|
signal expected_data_c_re_arr : t_integer_arr(0 to g_data_file_nof_lines-1) := (OTHERS=>0); -- full spectrum, re
|
187 |
|
|
signal expected_data_c_im_arr : t_integer_arr(0 to g_data_file_nof_lines-1) := (OTHERS=>0); -- full spectrum, im
|
188 |
|
|
|
189 |
|
|
signal t_blk : integer := 0; -- block time counter
|
190 |
|
|
|
191 |
|
|
-- Input
|
192 |
|
|
signal in_re_arr : t_fft_slv_arr(g_fft.wb_factor-1 downto 0);
|
193 |
|
|
signal in_im_arr : t_fft_slv_arr(g_fft.wb_factor-1 downto 0);
|
194 |
|
|
signal in_re_data : std_logic_vector(g_fft.wb_factor*c_in_dat_w-1 DOWNTO 0);
|
195 |
|
|
signal in_im_data : std_logic_vector(g_fft.wb_factor*c_in_dat_w-1 DOWNTO 0);
|
196 |
|
|
signal in_val : std_logic:= '0';
|
197 |
|
|
signal in_val_cnt : natural := 0;
|
198 |
|
|
signal in_gap : std_logic := '0';
|
199 |
|
|
|
200 |
|
|
-- Input in sclk domain
|
201 |
|
|
signal in_re_scope : integer;
|
202 |
|
|
signal in_im_scope : integer;
|
203 |
|
|
signal in_val_scope : std_logic:= '0';
|
204 |
|
|
|
205 |
|
|
-- Output
|
206 |
|
|
signal out_re_arr : t_fft_slv_arr(g_fft.wb_factor-1 downto 0);
|
207 |
|
|
signal out_im_arr : t_fft_slv_arr(g_fft.wb_factor-1 downto 0);
|
208 |
|
|
signal out_re_data : std_logic_vector(g_fft.wb_factor*c_out_dat_w-1 DOWNTO 0);
|
209 |
|
|
signal out_im_data : std_logic_vector(g_fft.wb_factor*c_out_dat_w-1 DOWNTO 0);
|
210 |
|
|
signal out_val : std_logic:= '0'; -- for parallel output
|
211 |
|
|
signal out_val_cnt : natural := 0;
|
212 |
|
|
|
213 |
|
|
-- Output in sclk domain
|
214 |
|
|
signal out_re_scope : integer := 0;
|
215 |
|
|
signal out_im_scope : integer := 0;
|
216 |
|
|
signal out_val_a : std_logic:= '0'; -- for real A
|
217 |
|
|
signal out_val_b : std_logic:= '0'; -- for real B
|
218 |
|
|
signal out_val_c : std_logic:= '0'; -- for complex(A,B)
|
219 |
|
|
signal out_channel : natural := 0;
|
220 |
|
|
signal out_cnt : natural := 0;
|
221 |
|
|
signal out_bin_cnt : natural := 0;
|
222 |
|
|
signal out_bin : natural;
|
223 |
|
|
|
224 |
|
|
-- Output data for complex input data
|
225 |
|
|
signal out_re_c_scope : integer := 0;
|
226 |
|
|
signal exp_re_c_scope : integer := 0;
|
227 |
|
|
signal out_im_c_scope : integer := 0;
|
228 |
|
|
signal exp_im_c_scope : integer := 0;
|
229 |
|
|
signal diff_re_c_scope : integer := 0;
|
230 |
|
|
signal diff_im_c_scope : integer := 0;
|
231 |
|
|
|
232 |
|
|
-- register control signals to account for sclk register in output scope signals
|
233 |
|
|
signal reg_out_val_a : std_logic;
|
234 |
|
|
signal reg_out_val_b : std_logic;
|
235 |
|
|
signal reg_out_val_c : std_logic;
|
236 |
|
|
signal reg_out_channel : natural := 0;
|
237 |
|
|
signal reg_out_cnt : natural := 0;
|
238 |
|
|
signal reg_out_bin_cnt : natural := 0;
|
239 |
|
|
signal reg_out_bin : natural;
|
240 |
|
|
|
241 |
|
|
-- Output data two real input data A and B
|
242 |
|
|
signal out_re_a_scope : integer := 0;
|
243 |
|
|
signal exp_re_a_scope : integer := 0;
|
244 |
|
|
signal out_im_a_scope : integer := 0;
|
245 |
|
|
signal exp_im_a_scope : integer := 0;
|
246 |
|
|
signal out_re_b_scope : integer := 0;
|
247 |
|
|
signal exp_re_b_scope : integer := 0;
|
248 |
|
|
signal out_im_b_scope : integer := 0;
|
249 |
|
|
signal exp_im_b_scope : integer := 0;
|
250 |
|
|
signal diff_re_a_scope : integer := 0;
|
251 |
|
|
signal diff_im_a_scope : integer := 0;
|
252 |
|
|
signal diff_re_b_scope : integer := 0;
|
253 |
|
|
signal diff_im_b_scope : integer := 0;
|
254 |
|
|
|
255 |
|
|
begin
|
256 |
|
|
|
257 |
|
|
sclk <= (not sclk) or tb_end after c_sclk_period/2;
|
258 |
|
|
clk <= (not clk) or tb_end after c_clk_period/2;
|
259 |
|
|
rst <= '1', '0' after c_clk_period*7;
|
260 |
|
|
random <= func_common_random(random) WHEN rising_edge(clk);
|
261 |
|
|
in_gap <= random(random'HIGH) WHEN g_enable_in_val_gaps=TRUE ELSE '0';
|
262 |
|
|
|
263 |
|
|
---------------------------------------------------------------
|
264 |
|
|
-- DATA INPUT
|
265 |
|
|
---------------------------------------------------------------
|
266 |
|
|
p_input_stimuli : process
|
267 |
|
|
begin
|
268 |
|
|
-- read input data from file
|
269 |
|
|
if c_in_complex then
|
270 |
|
|
proc_common_read_integer_file(g_data_file_c, c_nof_lines_c_wg_header, g_data_file_nof_lines, c_nof_complex, input_data_c_arr);
|
271 |
|
|
else
|
272 |
|
|
proc_common_read_integer_file(g_data_file_a, c_nof_lines_a_wg_header, g_data_file_nof_lines, 1, input_data_a_arr);
|
273 |
|
|
proc_common_read_integer_file(g_data_file_b, c_nof_lines_b_wg_header, g_data_file_nof_lines, 1, input_data_b_arr);
|
274 |
|
|
end if;
|
275 |
|
|
wait for 1 ns;
|
276 |
|
|
in_re_arr <= (others=>(others=>'0'));
|
277 |
|
|
in_im_arr <= (others=>(others=>'0'));
|
278 |
|
|
in_val <= '0';
|
279 |
|
|
proc_common_wait_until_low(clk, rst); -- Wait until reset has finished
|
280 |
|
|
proc_common_wait_some_cycles(clk, 10); -- Wait an additional amount of cycles
|
281 |
|
|
|
282 |
|
|
-- apply stimuli
|
283 |
|
|
for J in 0 to g_data_file_nof_lines/g_fft.wb_factor-1 loop -- serial
|
284 |
|
|
for I in 0 to g_fft.wb_factor-1 loop -- parallel
|
285 |
|
|
if c_in_complex then
|
286 |
|
|
in_re_arr(I) <= to_fft_svec(input_data_c_arr(2*(J*g_fft.wb_factor+I)));
|
287 |
|
|
in_im_arr(I) <= to_fft_svec(input_data_c_arr(2*(J*g_fft.wb_factor+I)+1));
|
288 |
|
|
else
|
289 |
|
|
in_re_arr(I) <= to_fft_svec(input_data_a_arr(J*g_fft.wb_factor+I));
|
290 |
|
|
in_im_arr(I) <= to_fft_svec(input_data_b_arr(J*g_fft.wb_factor+I));
|
291 |
|
|
end if;
|
292 |
|
|
end loop;
|
293 |
|
|
in_val <= '1';
|
294 |
|
|
proc_common_wait_some_cycles(clk, 1);
|
295 |
|
|
if in_gap='1' then
|
296 |
|
|
in_val <= '0';
|
297 |
|
|
proc_common_wait_some_cycles(clk, 1);
|
298 |
|
|
end if;
|
299 |
|
|
end loop;
|
300 |
|
|
|
301 |
|
|
-- Wait until done
|
302 |
|
|
in_val <= '0';
|
303 |
|
|
proc_common_wait_some_cycles(clk, c_dut_clk_latency); -- wait for DUT latency
|
304 |
|
|
tb_end_almost <= '1';
|
305 |
|
|
proc_common_wait_some_cycles(clk, 100);
|
306 |
|
|
tb_end <= '1';
|
307 |
|
|
wait;
|
308 |
|
|
end process;
|
309 |
|
|
|
310 |
|
|
---------------------------------------------------------------
|
311 |
|
|
-- DUT = Device Under Test
|
312 |
|
|
---------------------------------------------------------------
|
313 |
|
|
u_dut : entity work.fft_r2_wide
|
314 |
|
|
generic map(
|
315 |
|
|
g_fft => g_fft
|
316 |
|
|
)
|
317 |
|
|
port map(
|
318 |
|
|
clk => clk,
|
319 |
|
|
rst => rst,
|
320 |
|
|
in_re_arr => in_re_arr,
|
321 |
|
|
in_im_arr => in_im_arr,
|
322 |
|
|
in_val => in_val,
|
323 |
|
|
out_re_arr => out_re_arr,
|
324 |
|
|
out_im_arr => out_im_arr,
|
325 |
|
|
out_val => out_val
|
326 |
|
|
);
|
327 |
|
|
|
328 |
|
|
-- Data valid count
|
329 |
|
|
in_val_cnt <= in_val_cnt+1 when rising_edge(clk) and in_val='1' else in_val_cnt;
|
330 |
|
|
out_val_cnt <= out_val_cnt+1 when rising_edge(clk) and out_val='1' else out_val_cnt;
|
331 |
|
|
|
332 |
|
|
-- Block count t_blk time axis
|
333 |
|
|
t_blk <= in_val_cnt / (g_fft.nof_points /g_fft.wb_factor);
|
334 |
|
|
|
335 |
|
|
-- Verify nof valid counts
|
336 |
|
|
p_verify_out_val_cnt : process
|
337 |
|
|
begin
|
338 |
|
|
-- Wait until tb_end_almost
|
339 |
|
|
proc_common_wait_until_high(clk, tb_end_almost);
|
340 |
|
|
assert in_val_cnt > 0 report "Test did not run, no valid input data" severity error;
|
341 |
|
|
if g_fft.wb_factor=g_fft.nof_points then
|
342 |
|
|
-- Parallel FFT
|
343 |
|
|
assert out_val_cnt = in_val_cnt report "Unexpected number of valid output data" severity error;
|
344 |
|
|
else
|
345 |
|
|
-- Wideband FFT
|
346 |
|
|
-- The PFFT has a memory of 1 block, independent of use_reorder and use_separate, but without the
|
347 |
|
|
-- reorder buffer it outputs 1 sample more, because that is immediately available in a new block.
|
348 |
|
|
-- Ensure g_data_file_nof_lines is multiple of g_fft.nof_points.
|
349 |
|
|
if g_fft.use_reorder=true then
|
350 |
|
|
assert out_val_cnt = in_val_cnt-c_nof_valid_per_block report "Unexpected number of valid output data" severity error;
|
351 |
|
|
else
|
352 |
|
|
assert out_val_cnt = in_val_cnt-c_nof_valid_per_block+c_nof_channels report "Unexpected number of valid output data" severity error;
|
353 |
|
|
end if;
|
354 |
|
|
end if;
|
355 |
|
|
wait;
|
356 |
|
|
end process;
|
357 |
|
|
|
358 |
|
|
---------------------------------------------------------------
|
359 |
|
|
-- DATA OUTPUT CONTROL IN SCLK DOMAIN
|
360 |
|
|
---------------------------------------------------------------
|
361 |
|
|
out_cnt <= out_cnt + 1 when rising_edge(sclk) and out_val_c='1' else out_cnt;
|
362 |
|
|
|
363 |
|
|
proc_fft_out_control(g_fft.wb_factor, g_fft.nof_points, c_nof_channels, g_fft.use_reorder, g_fft.use_fft_shift, g_fft.use_separate,
|
364 |
|
|
out_cnt, out_val_c, out_val_a, out_val_b, out_channel, out_bin, out_bin_cnt);
|
365 |
|
|
|
366 |
|
|
-- clk diff to avoid combinatorial glitches when selecting the data with out_val_a,b,c
|
367 |
|
|
reg_out_val_a <= out_val_a when rising_edge(sclk);
|
368 |
|
|
reg_out_val_b <= out_val_b when rising_edge(sclk);
|
369 |
|
|
reg_out_val_c <= out_val_c when rising_edge(sclk);
|
370 |
|
|
reg_out_channel <= out_channel when rising_edge(sclk);
|
371 |
|
|
reg_out_cnt <= out_cnt when rising_edge(sclk);
|
372 |
|
|
reg_out_bin_cnt <= out_bin_cnt when rising_edge(sclk);
|
373 |
|
|
reg_out_bin <= out_bin when rising_edge(sclk);
|
374 |
|
|
|
375 |
|
|
out_re_a_scope <= out_re_scope when rising_edge(sclk) and out_val_a='1';
|
376 |
|
|
out_im_a_scope <= out_im_scope when rising_edge(sclk) and out_val_a='1';
|
377 |
|
|
out_re_b_scope <= out_re_scope when rising_edge(sclk) and out_val_b='1';
|
378 |
|
|
out_im_b_scope <= out_im_scope when rising_edge(sclk) and out_val_b='1';
|
379 |
|
|
out_re_c_scope <= out_re_scope when rising_edge(sclk) and out_val_c='1';
|
380 |
|
|
out_im_c_scope <= out_im_scope when rising_edge(sclk) and out_val_c='1';
|
381 |
|
|
|
382 |
|
|
exp_re_a_scope <= expected_data_a_re_arr(out_bin_cnt) when rising_edge(sclk) and out_val_a='1';
|
383 |
|
|
exp_im_a_scope <= expected_data_a_im_arr(out_bin_cnt) when rising_edge(sclk) and out_val_a='1';
|
384 |
|
|
exp_re_b_scope <= expected_data_b_re_arr(out_bin_cnt) when rising_edge(sclk) and out_val_b='1';
|
385 |
|
|
exp_im_b_scope <= expected_data_b_im_arr(out_bin_cnt) when rising_edge(sclk) and out_val_b='1';
|
386 |
|
|
exp_re_c_scope <= expected_data_c_re_arr(out_bin_cnt) when rising_edge(sclk) and out_val_c='1';
|
387 |
|
|
exp_im_c_scope <= expected_data_c_im_arr(out_bin_cnt) when rising_edge(sclk) and out_val_c='1';
|
388 |
|
|
|
389 |
|
|
diff_re_a_scope <= exp_re_a_scope - out_re_a_scope;
|
390 |
|
|
diff_im_a_scope <= exp_im_a_scope - out_im_a_scope;
|
391 |
|
|
diff_re_b_scope <= exp_re_b_scope - out_re_b_scope;
|
392 |
|
|
diff_im_b_scope <= exp_im_b_scope - out_im_b_scope;
|
393 |
|
|
diff_re_c_scope <= exp_re_c_scope - out_re_c_scope;
|
394 |
|
|
diff_im_c_scope <= exp_im_c_scope - out_im_c_scope;
|
395 |
|
|
|
396 |
|
|
---------------------------------------------------------------
|
397 |
|
|
-- VERIFY OUTPUT DATA
|
398 |
|
|
---------------------------------------------------------------
|
399 |
|
|
-- p_verify_output
|
400 |
|
|
gen_verify_two_real : if not c_in_complex generate
|
401 |
|
|
assert diff_re_a_scope >= -g_diff_margin and diff_re_a_scope <= g_diff_margin report "Output data A real error" severity error;
|
402 |
|
|
assert diff_im_a_scope >= -g_diff_margin and diff_im_a_scope <= g_diff_margin report "Output data A imag error" severity error;
|
403 |
|
|
assert diff_re_b_scope >= -g_diff_margin and diff_re_b_scope <= g_diff_margin report "Output data B real error" severity error;
|
404 |
|
|
assert diff_im_b_scope >= -g_diff_margin and diff_im_b_scope <= g_diff_margin report "Output data B imag error" severity error;
|
405 |
|
|
end generate;
|
406 |
|
|
gen_verify_complex : if c_in_complex generate
|
407 |
|
|
assert diff_re_c_scope >= -g_diff_margin and diff_re_c_scope <= g_diff_margin report "Output data C real error" severity error;
|
408 |
|
|
assert diff_im_c_scope >= -g_diff_margin and diff_im_c_scope <= g_diff_margin report "Output data C imag error" severity error;
|
409 |
|
|
end generate;
|
410 |
|
|
|
411 |
|
|
---------------------------------------------------------------
|
412 |
|
|
-- READ EXPECTED OUTPUT DATA FROM FILE
|
413 |
|
|
---------------------------------------------------------------
|
414 |
|
|
p_expected_output : process
|
415 |
|
|
begin
|
416 |
|
|
if c_in_complex then
|
417 |
|
|
proc_common_read_integer_file(g_data_file_c, c_nof_lines_c_pfft_header, g_data_file_nof_lines, c_nof_complex, expected_data_c_arr);
|
418 |
|
|
wait for 1 ns;
|
419 |
|
|
for I in 0 to g_data_file_nof_lines-1 loop
|
420 |
|
|
expected_data_c_re_arr(I) <= expected_data_c_arr(2*I);
|
421 |
|
|
expected_data_c_im_arr(I) <= expected_data_c_arr(2*I+1);
|
422 |
|
|
end loop;
|
423 |
|
|
else
|
424 |
|
|
proc_common_read_integer_file(g_data_file_a, c_nof_lines_a_pfft_header, g_data_file_nof_lines/c_nof_complex, c_nof_complex, expected_data_a_arr);
|
425 |
|
|
proc_common_read_integer_file(g_data_file_b, c_nof_lines_b_pfft_header, g_data_file_nof_lines/c_nof_complex, c_nof_complex, expected_data_b_arr);
|
426 |
|
|
wait for 1 ns;
|
427 |
|
|
for I in 0 to g_data_file_nof_lines/c_nof_complex-1 loop
|
428 |
|
|
expected_data_a_re_arr(I) <= expected_data_a_arr(2*I);
|
429 |
|
|
expected_data_a_im_arr(I) <= expected_data_a_arr(2*I+1);
|
430 |
|
|
expected_data_b_re_arr(I) <= expected_data_b_arr(2*I);
|
431 |
|
|
expected_data_b_im_arr(I) <= expected_data_b_arr(2*I+1);
|
432 |
|
|
end loop;
|
433 |
|
|
end if;
|
434 |
|
|
wait;
|
435 |
|
|
end process;
|
436 |
|
|
|
437 |
|
|
---------------------------------------------------------------
|
438 |
|
|
-- INPUT AND OUTPUT DATA SCOPES
|
439 |
|
|
---------------------------------------------------------------
|
440 |
|
|
p_data : process(in_re_arr, in_im_arr, out_re_arr, out_im_arr)
|
441 |
|
|
begin
|
442 |
|
|
for P in 0 to g_fft.wb_factor-1 loop
|
443 |
|
|
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);
|
444 |
|
|
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);
|
445 |
|
|
|
446 |
|
|
out_re_data((P+1)*c_out_dat_w-1 downto P*c_out_dat_w) <= out_re_arr(P)(c_out_dat_w-1 downto 0);
|
447 |
|
|
out_im_data((P+1)*c_out_dat_w-1 downto P*c_out_dat_w) <= out_im_arr(P)(c_out_dat_w-1 downto 0);
|
448 |
|
|
end loop;
|
449 |
|
|
end process;
|
450 |
|
|
|
451 |
|
|
u_in_re_scope : entity other_lib.common_wideband_data_scope
|
452 |
|
|
generic map (
|
453 |
|
|
g_sim => TRUE,
|
454 |
|
|
g_wideband_factor => g_fft.wb_factor, -- Wideband rate factor = 4 for dp_clk processing frequency is 200 MHz frequency and SCLK sample frequency Fs is 800 MHz
|
455 |
|
|
g_wideband_big_endian => FALSE, -- When true in_data[3:0] = sample[t0,t1,t2,t3], else when false : in_data[3:0] = sample[t3,t2,t1,t0]
|
456 |
|
|
g_dat_w => c_in_dat_w -- Actual width of the data samples
|
457 |
|
|
)
|
458 |
|
|
port map (
|
459 |
|
|
-- Sample clock
|
460 |
|
|
SCLK => sclk, -- sample clk, use only for simulation purposes
|
461 |
|
|
|
462 |
|
|
-- Streaming input data
|
463 |
|
|
in_data => in_re_data,
|
464 |
|
|
in_val => in_val,
|
465 |
|
|
|
466 |
|
|
-- Scope output samples
|
467 |
|
|
out_dat => OPEN,
|
468 |
|
|
out_int => in_re_scope,
|
469 |
|
|
out_val => in_val_scope
|
470 |
|
|
);
|
471 |
|
|
|
472 |
|
|
u_in_im_scope : entity other_lib.common_wideband_data_scope
|
473 |
|
|
generic map (
|
474 |
|
|
g_sim => TRUE,
|
475 |
|
|
g_wideband_factor => g_fft.wb_factor, -- Wideband rate factor = 4 for dp_clk processing frequency is 200 MHz frequency and SCLK sample frequency Fs is 800 MHz
|
476 |
|
|
g_wideband_big_endian => FALSE, -- When true in_data[3:0] = sample[t0,t1,t2,t3], else when false : in_data[3:0] = sample[t3,t2,t1,t0]
|
477 |
|
|
g_dat_w => c_in_dat_w -- Actual width of the data samples
|
478 |
|
|
)
|
479 |
|
|
port map (
|
480 |
|
|
-- Sample clock
|
481 |
|
|
SCLK => sclk, -- sample clk, use only for simulation purposes
|
482 |
|
|
|
483 |
|
|
-- Streaming input data
|
484 |
|
|
in_data => in_im_data,
|
485 |
|
|
in_val => in_val,
|
486 |
|
|
|
487 |
|
|
-- Scope output samples
|
488 |
|
|
out_dat => OPEN,
|
489 |
|
|
out_int => in_im_scope,
|
490 |
|
|
out_val => open
|
491 |
|
|
);
|
492 |
|
|
|
493 |
|
|
u_out_re_scope : entity other_lib.common_wideband_data_scope
|
494 |
|
|
generic map (
|
495 |
|
|
g_sim => TRUE,
|
496 |
|
|
g_wideband_factor => g_fft.wb_factor, -- Wideband rate factor = 4 for dp_clk processing frequency is 200 MHz frequency and SCLK sample frequency Fs is 800 MHz
|
497 |
|
|
g_wideband_big_endian => FALSE, -- When true in_data[3:0] = sample[t0,t1,t2,t3], else when false : in_data[3:0] = sample[t3,t2,t1,t0]
|
498 |
|
|
g_dat_w => c_out_dat_w -- Actual width of the data samples
|
499 |
|
|
)
|
500 |
|
|
port map (
|
501 |
|
|
-- Sample clock
|
502 |
|
|
SCLK => sclk, -- sample clk, use only for simulation purposes
|
503 |
|
|
|
504 |
|
|
-- Streaming input data
|
505 |
|
|
in_data => out_re_data,
|
506 |
|
|
in_val => out_val,
|
507 |
|
|
|
508 |
|
|
-- Scope output samples
|
509 |
|
|
out_dat => OPEN,
|
510 |
|
|
out_int => out_re_scope,
|
511 |
|
|
out_val => out_val_c
|
512 |
|
|
);
|
513 |
|
|
|
514 |
|
|
u_out_im_scope : entity other_lib.common_wideband_data_scope
|
515 |
|
|
generic map (
|
516 |
|
|
g_sim => TRUE,
|
517 |
|
|
g_wideband_factor => g_fft.wb_factor, -- Wideband rate factor = 4 for dp_clk processing frequency is 200 MHz frequency and SCLK sample frequency Fs is 800 MHz
|
518 |
|
|
g_wideband_big_endian => FALSE, -- When true in_data[3:0] = sample[t0,t1,t2,t3], else when false : in_data[3:0] = sample[t3,t2,t1,t0]
|
519 |
|
|
g_dat_w => c_out_dat_w -- Actual width of the data samples
|
520 |
|
|
)
|
521 |
|
|
port map (
|
522 |
|
|
-- Sample clock
|
523 |
|
|
SCLK => sclk, -- sample clk, use only for simulation purposes
|
524 |
|
|
|
525 |
|
|
-- Streaming input data
|
526 |
|
|
in_data => out_im_data,
|
527 |
|
|
in_val => out_val,
|
528 |
|
|
|
529 |
|
|
-- Scope output samples
|
530 |
|
|
out_dat => OPEN,
|
531 |
|
|
out_int => out_im_scope,
|
532 |
|
|
out_val => open
|
533 |
|
|
);
|
534 |
|
|
|
535 |
|
|
end tb;
|