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_reorder_sepa_pipe
|
22 |
|
|
-- Features:
|
23 |
|
|
--
|
24 |
|
|
-- Usage:
|
25 |
|
|
-- > as 10
|
26 |
|
|
-- > run -all
|
27 |
|
|
-- Testbench is selftesting.
|
28 |
|
|
-- Run testbench for different values of c_seperate and c_reorder. (Recompile is required)
|
29 |
|
|
|
30 |
5 |
danv |
library IEEE, common_pkg_lib, dp_pkg_lib, astron_diagnostics_lib, astron_mm_lib, astron_ram_lib;
|
31 |
2 |
danv |
use IEEE.std_logic_1164.ALL;
|
32 |
|
|
use IEEE.numeric_std.ALL;
|
33 |
|
|
use common_pkg_lib.common_pkg.ALL;
|
34 |
5 |
danv |
use astron_ram_lib.common_ram_pkg.ALL;
|
35 |
2 |
danv |
use common_pkg_lib.common_lfsr_sequences_pkg.ALL;
|
36 |
|
|
use common_pkg_lib.tb_common_pkg.ALL;
|
37 |
5 |
danv |
use astron_mm_lib.tb_common_mem_pkg.ALL;
|
38 |
2 |
danv |
use dp_pkg_lib.dp_stream_pkg.ALL;
|
39 |
5 |
danv |
use astron_diagnostics_lib.diag_pkg.ALL;
|
40 |
2 |
danv |
|
41 |
|
|
entity tb_fft_reorder_sepa_pipe is
|
42 |
|
|
end tb_fft_reorder_sepa_pipe;
|
43 |
|
|
|
44 |
|
|
architecture tb of tb_fft_reorder_sepa_pipe is
|
45 |
|
|
|
46 |
|
|
constant c_clk_period : time := 10 ns;
|
47 |
|
|
constant c_nof_points : natural := 16; -- Number of points should be a power of 2
|
48 |
|
|
constant c_in_dat_w : natural := 16;
|
49 |
|
|
constant c_separate : boolean := true; -- When true the seperate function is enabled
|
50 |
|
|
constant c_reorder : boolean := true; -- When enabled the reordering is performed
|
51 |
|
|
constant c_nof_chan : natural := 1;
|
52 |
|
|
constant c_nof_channels : natural := 2**c_nof_chan;
|
53 |
|
|
|
54 |
|
|
type t_input_buf_arr is array (integer range <>) of std_logic_vector(c_in_dat_w-1 downto 0);
|
55 |
|
|
|
56 |
|
|
-- BG derived constants
|
57 |
|
|
constant c_bg_mem_size : natural := 1024;
|
58 |
|
|
constant c_bg_addr_w : natural := ceil_log2(c_bg_mem_size);
|
59 |
|
|
constant c_nof_samples_in_packet : natural := c_nof_channels*c_nof_points;
|
60 |
|
|
constant c_gap : natural := 0; -- Gapsize is set to 0 in order to generate a continuous stream of packets.
|
61 |
|
|
constant c_bst_skip_nof_sync : natural := 3;
|
62 |
|
|
constant c_nof_accum_per_sync : natural := 10;
|
63 |
|
|
constant c_bsn_init : natural := 32;
|
64 |
|
|
constant c_bg_prefix : string := "data/to_separate";
|
65 |
|
|
|
66 |
|
|
signal tb_end : std_logic := '0';
|
67 |
|
|
signal rst : std_logic;
|
68 |
|
|
signal clk : std_logic := '1';
|
69 |
|
|
|
70 |
|
|
signal ram_bg_data_mosi : t_mem_mosi;
|
71 |
|
|
signal reg_bg_ctrl_mosi : t_mem_mosi;
|
72 |
|
|
signal in_sosi_arr : t_dp_sosi_arr(0 downto 0);
|
73 |
|
|
signal in_siso_arr : t_dp_siso_arr(0 downto 0);
|
74 |
|
|
signal out_sosi : t_dp_sosi;
|
75 |
|
|
signal in_dat : std_logic_vector(2*c_in_dat_w-1 downto 0);
|
76 |
|
|
signal out_dat : std_logic_vector(2*c_in_dat_w-1 downto 0);
|
77 |
|
|
signal out_dat_re : std_logic_vector(c_in_dat_w-1 downto 0);
|
78 |
|
|
signal out_dat_im : std_logic_vector(c_in_dat_w-1 downto 0);
|
79 |
|
|
signal out_val : std_logic;
|
80 |
|
|
|
81 |
|
|
signal buf_input_re : t_input_buf_arr(c_nof_channels*c_nof_points-1 downto 0);
|
82 |
|
|
signal buf_input_im : t_input_buf_arr(c_nof_channels*c_nof_points-1 downto 0);
|
83 |
|
|
signal buf_output_a_re : t_input_buf_arr(c_nof_channels*c_nof_points/2-1 downto 0);
|
84 |
|
|
signal buf_output_a_im : t_input_buf_arr(c_nof_channels*c_nof_points/2-1 downto 0);
|
85 |
|
|
signal buf_output_b_re : t_input_buf_arr(c_nof_channels*c_nof_points/2-1 downto 0);
|
86 |
|
|
signal buf_output_b_im : t_input_buf_arr(c_nof_channels*c_nof_points/2-1 downto 0);
|
87 |
|
|
signal buf_output_re : t_input_buf_arr(c_nof_channels*c_nof_points-1 downto 0);
|
88 |
|
|
signal buf_output_im : t_input_buf_arr(c_nof_channels*c_nof_points-1 downto 0);
|
89 |
|
|
|
90 |
|
|
BEGIN
|
91 |
|
|
|
92 |
|
|
clk <= (not clk) or tb_end after c_clk_period/2;
|
93 |
|
|
rst <= '1', '0' after c_clk_period*3;
|
94 |
|
|
|
95 |
|
|
p_control_input_stream : process
|
96 |
|
|
begin
|
97 |
|
|
tb_end <= '0';
|
98 |
|
|
reg_bg_ctrl_mosi <= c_mem_mosi_rst;
|
99 |
|
|
|
100 |
|
|
-- Wait until reset is done
|
101 |
|
|
proc_common_wait_until_high(clk, rst);
|
102 |
|
|
proc_common_wait_some_cycles(clk, 10);
|
103 |
|
|
|
104 |
|
|
-- Set and enable the waveform generators. All generators are controlled by the same registers
|
105 |
|
|
proc_mem_mm_bus_wr(1, c_nof_samples_in_packet, clk, reg_bg_ctrl_mosi); -- Set the number of samples per block
|
106 |
|
|
proc_mem_mm_bus_wr(2, c_nof_accum_per_sync, clk, reg_bg_ctrl_mosi); -- Set the number of blocks per sync
|
107 |
|
|
proc_mem_mm_bus_wr(3, c_gap, clk, reg_bg_ctrl_mosi); -- Set the gapsize
|
108 |
|
|
proc_mem_mm_bus_wr(4, 0, clk, reg_bg_ctrl_mosi); -- Set the start address of the memory
|
109 |
|
|
proc_mem_mm_bus_wr(5, c_nof_samples_in_packet-1, clk, reg_bg_ctrl_mosi); -- Set the end address of the memory
|
110 |
|
|
proc_mem_mm_bus_wr(6, c_bsn_init, clk, reg_bg_ctrl_mosi); -- Set the BSNInit low value
|
111 |
|
|
proc_mem_mm_bus_wr(7, 0, clk, reg_bg_ctrl_mosi); -- Set the BSNInit high value
|
112 |
|
|
proc_mem_mm_bus_wr(0, 1, clk, reg_bg_ctrl_mosi); -- Enable the BG
|
113 |
|
|
|
114 |
|
|
-- Run time
|
115 |
|
|
proc_common_wait_some_cycles(clk, 10*c_nof_points);
|
116 |
|
|
proc_mem_mm_bus_wr(0, 0, clk, reg_bg_ctrl_mosi); -- Disable the BG
|
117 |
|
|
|
118 |
|
|
-- The end
|
119 |
|
|
proc_common_wait_some_cycles(clk, c_nof_points + 20);
|
120 |
|
|
tb_end <= '1';
|
121 |
|
|
wait;
|
122 |
|
|
end process;
|
123 |
|
|
|
124 |
5 |
danv |
u_block_generator : entity astron_diagnostics_lib.mms_diag_block_gen
|
125 |
2 |
danv |
generic map(
|
126 |
|
|
g_nof_streams => 1,
|
127 |
|
|
g_buf_dat_w => c_nof_complex*c_in_dat_w,
|
128 |
|
|
g_buf_addr_w => c_bg_addr_w, -- Waveform buffer size 2**g_buf_addr_w nof samples
|
129 |
|
|
g_file_name_prefix => c_bg_prefix
|
130 |
|
|
)
|
131 |
|
|
port map(
|
132 |
|
|
-- Clocks and reset
|
133 |
|
|
mm_rst => rst,
|
134 |
|
|
mm_clk => clk,
|
135 |
|
|
dp_rst => rst,
|
136 |
|
|
dp_clk => clk,
|
137 |
|
|
en_sync => '1',
|
138 |
|
|
ram_bg_data_mosi => ram_bg_data_mosi,
|
139 |
|
|
ram_bg_data_miso => open,
|
140 |
|
|
reg_bg_ctrl_mosi => reg_bg_ctrl_mosi,
|
141 |
|
|
reg_bg_ctrl_miso => open,
|
142 |
|
|
out_siso_arr => in_siso_arr,
|
143 |
|
|
out_sosi_arr => in_sosi_arr
|
144 |
|
|
);
|
145 |
|
|
in_siso_arr(0) <= c_dp_siso_rdy;
|
146 |
|
|
|
147 |
|
|
-- device under test
|
148 |
|
|
u_dut : entity work.fft_reorder_sepa_pipe
|
149 |
|
|
generic map (
|
150 |
|
|
g_separate => c_separate,
|
151 |
|
|
g_nof_points => c_nof_points,
|
152 |
|
|
g_bit_flip => c_reorder,
|
153 |
|
|
g_nof_chan => c_nof_chan
|
154 |
|
|
)
|
155 |
|
|
port map (
|
156 |
|
|
clk => clk,
|
157 |
|
|
rst => rst,
|
158 |
|
|
in_dat => in_dat,
|
159 |
|
|
in_val => in_sosi_arr(0).valid,
|
160 |
|
|
out_dat => out_dat,
|
161 |
|
|
out_val => out_val
|
162 |
|
|
);
|
163 |
|
|
|
164 |
|
|
in_dat <= in_sosi_arr(0).im(c_in_dat_w-1 downto 0) & in_sosi_arr(0).re(c_in_dat_w-1 downto 0);
|
165 |
|
|
out_dat_re <= out_dat(c_in_dat_w-1 downto 0);
|
166 |
|
|
out_dat_im <= out_dat(2*c_in_dat_w-1 downto c_in_dat_w);
|
167 |
|
|
|
168 |
|
|
-- verification
|
169 |
|
|
p_verify : process
|
170 |
|
|
variable I : integer;
|
171 |
|
|
variable v_buf_input_re_temp : t_input_buf_arr(c_nof_channels*c_nof_points-1 downto 0);
|
172 |
|
|
variable v_buf_input_im_temp : t_input_buf_arr(c_nof_channels*c_nof_points-1 downto 0);
|
173 |
|
|
variable v_buf_output_a_re : t_input_buf_arr(c_nof_channels*c_nof_points/2-1 downto 0);
|
174 |
|
|
variable v_buf_output_a_im : t_input_buf_arr(c_nof_channels*c_nof_points/2-1 downto 0);
|
175 |
|
|
variable v_buf_output_b_re : t_input_buf_arr(c_nof_channels*c_nof_points/2-1 downto 0);
|
176 |
|
|
variable v_buf_output_b_im : t_input_buf_arr(c_nof_channels*c_nof_points/2-1 downto 0);
|
177 |
|
|
begin
|
178 |
|
|
I := 0;
|
179 |
|
|
wait until in_sosi_arr(0).sync = '1';
|
180 |
|
|
while I < c_nof_channels*c_nof_points loop
|
181 |
|
|
wait until (rising_edge(clk) and in_sosi_arr(0).valid = '1');
|
182 |
|
|
buf_input_re(I) <= in_sosi_arr(0).re(c_in_dat_w-1 downto 0); -- The first dataframe is latched in and used as reference
|
183 |
|
|
buf_input_im(I) <= in_sosi_arr(0).im(c_in_dat_w-1 downto 0);
|
184 |
|
|
I := I + 1;
|
185 |
|
|
end loop;
|
186 |
|
|
proc_common_wait_some_cycles(clk, 1);
|
187 |
|
|
-- Perform re-order function to the reference data if re-ordering is enabled
|
188 |
|
|
if(c_reorder=true) then
|
189 |
|
|
for H in 0 to c_nof_channels-1 loop
|
190 |
|
|
for J in 0 to c_nof_points-1 loop
|
191 |
|
|
v_buf_input_re_temp(c_nof_channels*J + H) := buf_input_re(TO_UINT(TO_UVEC(H, c_nof_chan) & FLIP(TO_UVEC(J, ceil_log2(c_nof_points)))));
|
192 |
|
|
v_buf_input_im_temp(c_nof_channels*J + H) := buf_input_im(TO_UINT(TO_UVEC(H, c_nof_chan) & FLIP(TO_UVEC(J, ceil_log2(c_nof_points)))));
|
193 |
|
|
end loop;
|
194 |
|
|
end loop;
|
195 |
|
|
else
|
196 |
|
|
for H in 0 to c_nof_channels-1 loop
|
197 |
|
|
for J in 0 to c_nof_points-1 loop
|
198 |
|
|
v_buf_input_re_temp(H*c_nof_points + J) := buf_input_re(c_nof_channels*J + H);
|
199 |
|
|
v_buf_input_im_temp(H*c_nof_points + J) := buf_input_im(c_nof_channels*J + H);
|
200 |
|
|
end loop;
|
201 |
|
|
end loop;
|
202 |
|
|
end if;
|
203 |
|
|
-- Do the separate function on the reference data if separata is enabled.
|
204 |
|
|
if(c_separate=true) then
|
205 |
|
|
for H in 0 to c_nof_channels-1 loop
|
206 |
|
|
for J in 0 to c_nof_points/2-1 loop
|
207 |
|
|
if(J = 0) then
|
208 |
|
|
v_buf_output_a_re(H*c_nof_points/2 + J) := v_buf_input_re_temp(H*c_nof_points);
|
209 |
|
|
v_buf_output_a_im(H*c_nof_points/2 + J) := (others => '0');
|
210 |
|
|
v_buf_output_b_re(H*c_nof_points/2 + J) := v_buf_input_im_temp(H*c_nof_points);
|
211 |
|
|
v_buf_output_b_im(H*c_nof_points/2 + J) := (others => '0');
|
212 |
|
|
buf_output_re(H*c_nof_points) <= v_buf_output_a_re(H*c_nof_points/2 + J);
|
213 |
|
|
buf_output_im(H*c_nof_points) <= v_buf_output_a_im(H*c_nof_points/2 + J);
|
214 |
|
|
buf_output_re(H*c_nof_points + 1) <= v_buf_output_b_re(H*c_nof_points/2 + J);
|
215 |
|
|
buf_output_im(H*c_nof_points + 1) <= v_buf_output_b_im(H*c_nof_points/2 + J);
|
216 |
|
|
else
|
217 |
|
|
v_buf_output_a_re(H*c_nof_points/2 + J) := ADD_SVEC(v_buf_input_re_temp(H*c_nof_points + c_nof_points-J), v_buf_input_re_temp(H*c_nof_points + J), c_in_dat_w+1)(c_in_dat_w downto 1);
|
218 |
|
|
v_buf_output_a_im(H*c_nof_points/2 + J) := SUB_SVEC(v_buf_input_im_temp(H*c_nof_points + J), v_buf_input_im_temp(H*c_nof_points + c_nof_points-J), c_in_dat_w+1)(c_in_dat_w downto 1);
|
219 |
|
|
v_buf_output_b_re(H*c_nof_points/2 + J) := ADD_SVEC(v_buf_input_im_temp(H*c_nof_points + c_nof_points-J), v_buf_input_im_temp(H*c_nof_points + J), c_in_dat_w+1)(c_in_dat_w downto 1);
|
220 |
|
|
v_buf_output_b_im(H*c_nof_points/2 + J) := SUB_SVEC(v_buf_input_re_temp(H*c_nof_points + c_nof_points-J), v_buf_input_re_temp(H*c_nof_points + J), c_in_dat_w+1)(c_in_dat_w downto 1);
|
221 |
|
|
buf_output_re(H*c_nof_points + 2*J) <= v_buf_output_a_re(H*c_nof_points/2 + J);
|
222 |
|
|
buf_output_im(H*c_nof_points + 2*J) <= v_buf_output_a_im(H*c_nof_points/2 + J);
|
223 |
|
|
buf_output_re(H*c_nof_points + 2*J+1) <= v_buf_output_b_re(H*c_nof_points/2 + J);
|
224 |
|
|
buf_output_im(H*c_nof_points + 2*J+1) <= v_buf_output_b_im(H*c_nof_points/2 + J);
|
225 |
|
|
end if;
|
226 |
|
|
end loop;
|
227 |
|
|
end loop;
|
228 |
|
|
else
|
229 |
|
|
buf_output_re <= v_buf_input_re_temp;
|
230 |
|
|
buf_output_im <= v_buf_input_im_temp;
|
231 |
|
|
end if;
|
232 |
|
|
wait;
|
233 |
|
|
end process;
|
234 |
|
|
|
235 |
|
|
------------------------------------------------------------------------
|
236 |
|
|
-- Simple process that does the final test.
|
237 |
|
|
------------------------------------------------------------------------
|
238 |
|
|
p_tester : process(rst, clk)
|
239 |
|
|
variable I : integer;
|
240 |
|
|
begin
|
241 |
|
|
if rst='0' then
|
242 |
|
|
if rising_edge(clk) and out_val = '1' then
|
243 |
|
|
assert buf_output_re(I) = out_dat_re report "Error: wrong RTL result in real path" severity error;
|
244 |
|
|
assert buf_output_im(I) = out_dat_im report "Error: wrong RTL result in imag path" severity error;
|
245 |
|
|
if(I = c_nof_channels*c_nof_points - 1 ) then
|
246 |
|
|
I := 0;
|
247 |
|
|
else
|
248 |
|
|
I := I + 1;
|
249 |
|
|
end if;
|
250 |
|
|
end if;
|
251 |
|
|
else
|
252 |
|
|
I := 0;
|
253 |
|
|
end if;
|
254 |
|
|
end process p_tester;
|
255 |
|
|
|
256 |
|
|
end tb;
|