OpenCores
URL https://opencores.org/ocsvn/astron_wb_fft/astron_wb_fft/trunk

Subversion Repositories astron_wb_fft

[/] [astron_wb_fft/] [trunk/] [tb_mmf_fft_r2_par.vhd] - Blame information for rev 7

Details | Compare with Previous | View Log

Line No. Rev Author Line
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 the parallel radix-2 FFT.
22
--
23
--          The testbech uses blockgenerators to generate data for 
24
--          every input of the parallel FFT. 
25
--          The output of the FFT is stored in databuffers. 
26
--          Both the block generators and databuffers are controlled
27
--          via a mm interface. 
28
--          Use this testbench in conjunction with ../python/tc_mmf_fft_r2_par.py
29
--
30
-- Usage:
31
--   > run -all
32
--   > Run python script in separate terminal: "python tc_mmf_fft_r2_par.py --unb 0 --bn 0 --sim"
33
--   > Check the results of the python script. 
34
--   > Stop the simulation manually in Modelsim by pressing the stop-button. 
35
 
36
 
37 7 danv
LIBRARY IEEE, common_pkg_lib, astron_mm_lib, astron_diagnostics_lib, dp_pkg_lib, astron_r2sdf_fft_lib;
38 2 danv
USE IEEE.std_logic_1164.ALL;
39
USE IEEE.numeric_std.ALL;
40
USE common_pkg_lib.common_pkg.ALL;
41
USE common_lib.common_mem_pkg.ALL;
42
USE common_pkg_lib.common_str_pkg.ALL;
43
USE common_pkg_lib.tb_common_pkg.ALL;
44
USE common_lib.tb_common_mem_pkg.ALL;
45 5 danv
USE astron_mm_lib.mm_file_unb_pkg.ALL;
46
USE astron_mm_lib.mm_file_pkg.ALL;
47 2 danv
USE dp_pkg_lib.dp_stream_pkg.ALL;
48 5 danv
USE astron_r2sdf_fft_lib.rTwoSDFPkg.all;
49 2 danv
USE work.fft_pkg.all;
50
 
51
ENTITY tb_mmf_fft_r2_par IS
52
  GENERIC(
53
    g_fft : t_fft := (true, false, false, 0, 1, 0, 64, 8, 14, 0, c_dsp_mult_w, 2, true, 56, 2)
54
    --  type t_rtwo_fft is record
55
    --    use_reorder    : boolean;  -- = false for bit-reversed output, true for normal output
56
    --    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
57
    --    use_separate   : boolean;  -- = false for complex input, true for two real inputs
58
    --    nof_chan       : natural;  -- = default 0, defines the number of channels (=time-multiplexed input signals): nof channels = 2**nof_chan     
59
    --    wb_factor      : natural;  -- = default 1, wideband factor
60
    --    twiddle_offset : natural;  -- = default 0, twiddle offset for PFT sections in a wideband FFT
61
    --    nof_points     : natural;  -- = 1024, N point FFT
62
    --    in_dat_w       : natural;  -- = 8, number of input bits
63
    --    out_dat_w      : natural;  -- = 13, number of output bits: in_dat_w + natural((ceil_log2(nof_points))/2 + 2)  
64
    --    out_gain_w     : natural;  -- = 0, output gain factor applied after the last stage output, before requantization to out_dat_w
65
    --    stage_dat_w    : natural;  -- = 18, data width used between the stages(= DSP multiplier-width)
66
    --    guard_w        : natural;  -- = 2,  Guard used to avoid overflow in FFT stage. 
67
    --    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)    
68
    --    stat_data_w    : positive; -- = 56
69
    --    stat_data_sz   : positive; -- = 2
70
    --  end record;
71
  );
72
END tb_mmf_fft_r2_par;
73
 
74
ARCHITECTURE tb OF tb_mmf_fft_r2_par IS
75
 
76
  CONSTANT c_sim                : BOOLEAN := TRUE;
77
 
78
  ----------------------------------------------------------------------------
79
  -- Clocks and resets
80
  ----------------------------------------------------------------------------   
81
  CONSTANT c_mm_clk_period      : TIME := 1 ns;
82
  CONSTANT c_dp_clk_period      : TIME := 5 ns;
83
  CONSTANT c_dp_pps_period      : NATURAL := 64;
84
 
85
  SIGNAL dp_pps                 : STD_LOGIC;
86
 
87
  SIGNAL mm_rst                 : STD_LOGIC;
88
  SIGNAL mm_clk                 : STD_LOGIC := '0';
89
 
90
  SIGNAL dp_rst                 : STD_LOGIC;
91
  SIGNAL dp_clk                 : STD_LOGIC := '0';
92
 
93
  ----------------------------------------------------------------------------
94
  -- MM buses
95
  ----------------------------------------------------------------------------                                         
96
  SIGNAL reg_diag_bg_mosi          : t_mem_mosi;
97
  SIGNAL reg_diag_bg_miso          : t_mem_miso;
98
 
99
  SIGNAL ram_diag_bg_mosi          : t_mem_mosi;
100
  SIGNAL ram_diag_bg_miso          : t_mem_miso;
101
 
102
  SIGNAL ram_ss_ss_wide_mosi       : t_mem_mosi;
103
  SIGNAL ram_ss_ss_wide_miso       : t_mem_miso;
104
 
105
  SIGNAL ram_diag_data_buf_re_mosi : t_mem_mosi;
106
  SIGNAL ram_diag_data_buf_re_miso : t_mem_miso;
107
 
108
  SIGNAL reg_diag_data_buf_re_mosi : t_mem_mosi;
109
  SIGNAL reg_diag_data_buf_re_miso : t_mem_miso;
110
 
111
  SIGNAL ram_diag_data_buf_im_mosi : t_mem_mosi;
112
  SIGNAL ram_diag_data_buf_im_miso : t_mem_miso;
113
 
114
  SIGNAL reg_diag_data_buf_im_mosi : t_mem_mosi;
115
  SIGNAL reg_diag_data_buf_im_miso : t_mem_miso;
116
 
117
  CONSTANT c_nof_streams            : POSITIVE := g_fft.nof_points;
118
  CONSTANT c_bg_block_len           : NATURAL  := 4;
119
 
120
  CONSTANT c_bg_buf_adr_w           : NATURAL := ceil_log2(c_bg_block_len);
121
  CONSTANT c_bg_data_file_index_arr : t_nat_natural_arr := array_init(0, g_fft.nof_points, 1);
122
  CONSTANT c_bg_data_file_prefix    : STRING := "UNUSED";
123
 
124
  SIGNAL bg_siso_arr                : t_dp_siso_arr(g_fft.nof_points-1 DOWNTO 0) := (OTHERS=>c_dp_siso_rdy);
125
  SIGNAL bg_sosi_arr                : t_dp_sosi_arr(g_fft.nof_points-1 DOWNTO 0);
126
 
127
  SIGNAL ss_out_sosi_re_arr         : t_dp_sosi_arr(g_fft.nof_points-1 DOWNTO 0) := (OTHERS => c_dp_sosi_rst);
128
  SIGNAL ss_out_sosi_im_arr         : t_dp_sosi_arr(g_fft.nof_points-1 DOWNTO 0) := (OTHERS => c_dp_sosi_rst);
129
 
130
  SIGNAL in_re_arr                  : t_fft_slv_arr(g_fft.nof_points-1 downto 0);
131
  SIGNAL in_im_arr                  : t_fft_slv_arr(g_fft.nof_points-1 downto 0);
132
  SIGNAL in_val                     : STD_LOGIC := '0';
133
 
134
  SIGNAL out_re_arr                 : t_fft_slv_arr(g_fft.nof_points-1 downto 0);
135
  SIGNAL out_im_arr                 : t_fft_slv_arr(g_fft.nof_points-1 downto 0);
136
  SIGNAL out_val                    : STD_LOGIC := '0';
137
 
138
BEGIN
139
 
140
  ----------------------------------------------------------------------------
141
  -- Clock and reset generation
142
  ----------------------------------------------------------------------------
143
  mm_clk <= NOT mm_clk AFTER c_mm_clk_period/2;
144
  mm_rst <= '1', '0' AFTER c_mm_clk_period*5;
145
 
146
  dp_clk <= NOT dp_clk AFTER c_dp_clk_period/2;
147
  dp_rst <= '1', '0' AFTER c_dp_clk_period*5;
148
 
149
  ------------------------------------------------------------------------------
150
  -- External PPS
151
  ------------------------------------------------------------------------------  
152
  proc_common_gen_pulse(1, c_dp_pps_period, '1', dp_clk, dp_pps);
153
 
154
   ----------------------------------------------------------------------------
155
  -- Procedure that polls a sim control file that can be used to e.g. get
156
  -- the simulation time in ns
157
  ----------------------------------------------------------------------------
158
  mmf_poll_sim_ctrl_file(c_mmf_unb_file_path & "sim.ctrl", c_mmf_unb_file_path & "sim.stat");
159
 
160
  ----------------------------------------------------------------------------
161
  -- MM buses  
162
  ----------------------------------------------------------------------------
163
  u_mm_file_reg_diag_bg          : mm_file GENERIC MAP(mmf_unb_file_prefix(0, 0, "BN") & "REG_DIAG_BG")
164
                                           PORT MAP(mm_rst, mm_clk, reg_diag_bg_mosi, reg_diag_bg_miso);
165
 
166
  u_mm_file_ram_diag_bg          : mm_file GENERIC MAP(mmf_unb_file_prefix(0, 0, "BN") & "RAM_DIAG_BG")
167
                                           PORT MAP(mm_rst, mm_clk, ram_diag_bg_mosi, ram_diag_bg_miso);
168
 
169
  u_mm_file_ram_diag_data_buf_re : mm_file GENERIC MAP(mmf_unb_file_prefix(0, 0, "BN") & "RAM_DIAG_DATA_BUFFER_REAL")
170
                                           PORT MAP(mm_rst, mm_clk, ram_diag_data_buf_re_mosi, ram_diag_data_buf_re_miso);
171
 
172
  u_mm_file_reg_diag_data_buf_re : mm_file GENERIC MAP(mmf_unb_file_prefix(0, 0, "BN") & "REG_DIAG_DATA_BUFFER_REAL")
173
                                           PORT MAP(mm_rst, mm_clk, reg_diag_data_buf_re_mosi, reg_diag_data_buf_re_miso);
174
 
175
  u_mm_file_ram_diag_data_buf_im : mm_file GENERIC MAP(mmf_unb_file_prefix(0, 0, "BN") & "RAM_DIAG_DATA_BUFFER_IMAG")
176
                                           PORT MAP(mm_rst, mm_clk, ram_diag_data_buf_im_mosi, ram_diag_data_buf_im_miso);
177
 
178
  u_mm_file_reg_diag_data_buf_im : mm_file GENERIC MAP(mmf_unb_file_prefix(0, 0, "BN") & "REG_DIAG_DATA_BUFFER_IMAG")
179
                                           PORT MAP(mm_rst, mm_clk, reg_diag_data_buf_im_mosi, reg_diag_data_buf_im_miso);
180
 
181
  ----------------------------------------------------------------------------
182
  -- Source: block generator
183
  ---------------------------------------------------------------------------- 
184 5 danv
  u_bg : ENTITY astron_diagnostics_lib.mms_diag_block_gen
185 2 danv
  GENERIC MAP(
186
    g_nof_output_streams => c_nof_streams,
187
    g_buf_dat_w          => c_nof_complex*g_fft.in_dat_w,
188
    g_buf_addr_w         => c_bg_buf_adr_w,               -- Waveform buffer size 2**g_buf_addr_w nof samples
189
    g_file_index_arr     => c_bg_data_file_index_arr,
190
    g_file_name_prefix   => c_bg_data_file_prefix
191
  )
192
  PORT MAP(
193
    -- System
194
    mm_rst           => mm_rst,
195
    mm_clk           => mm_clk,
196
    dp_rst           => dp_rst,
197
    dp_clk           => dp_clk,
198
    en_sync          => dp_pps,
199
    -- MM interface
200
    reg_bg_ctrl_mosi => reg_diag_bg_mosi,
201
    reg_bg_ctrl_miso => reg_diag_bg_miso,
202
    ram_bg_data_mosi => ram_diag_bg_mosi,
203
    ram_bg_data_miso => ram_diag_bg_miso,
204
    -- ST interface
205
    out_siso_arr     => bg_siso_arr,
206
    out_sosi_arr     => bg_sosi_arr
207
  );
208
 
209
  connect_input_data : FOR I IN 0 TO g_fft.nof_points -1 GENERATE
210
    in_re_arr(I) <= RESIZE_SVEC(bg_sosi_arr(I).re(g_fft.in_dat_w-1 DOWNTO 0), in_re_arr(I)'LENGTH);
211
    in_im_arr(I) <= RESIZE_SVEC(bg_sosi_arr(I).im(g_fft.in_dat_w-1 DOWNTO 0), in_im_arr(I)'LENGTH);
212
  END GENERATE;
213
 
214
  in_val <= bg_sosi_arr(0).valid;
215
 
216
  -- DUT = Device Under Test
217
  u_dut : ENTITY work.fft_r2_par
218
  GENERIC MAP(
219
    g_fft      => g_fft     -- generics for the FFT
220
  )
221
  PORT MAP(
222
    clk        => dp_clk,
223
    rst        => dp_rst,
224
    in_re_arr  => in_re_arr,
225
    in_im_arr  => in_im_arr,
226
    in_val     => in_val,
227
    out_re_arr => out_re_arr,
228
    out_im_arr => out_im_arr,
229
    out_val    => out_val
230
  );
231
 
232
  connect_output_data : FOR I IN 0 TO g_fft.nof_points -1 GENERATE
233
    ss_out_sosi_re_arr(I).data  <= RESIZE_SVEC(out_re_arr(I), ss_out_sosi_re_arr(I).data'LENGTH);
234
    ss_out_sosi_re_arr(I).valid <= out_val;
235
    ss_out_sosi_re_arr(I).sync  <= out_val;
236
 
237
    ss_out_sosi_im_arr(I).data  <= RESIZE_SVEC(out_im_arr(I), ss_out_sosi_im_arr(I).data'LENGTH);
238
    ss_out_sosi_im_arr(I).valid <= out_val;
239
    ss_out_sosi_im_arr(I).sync  <= out_val;
240
  END GENERATE;
241
 
242
  ----------------------------------------------------------------------------
243
  -- Sink: data buffer real 
244
  ---------------------------------------------------------------------------- 
245 5 danv
  u_data_buf_re : ENTITY astron_diagnostics_lib.mms_diag_data_buffer
246 2 danv
  GENERIC MAP (
247
    g_nof_streams  => c_nof_streams,
248
    g_data_w       => g_fft.out_dat_w,
249
    g_buf_nof_data => 1024,
250
    g_buf_use_sync => FALSE
251
  )
252
  PORT MAP (
253
    -- System
254
    mm_rst            => mm_rst,
255
    mm_clk            => mm_clk,
256
    dp_rst            => dp_rst,
257
    dp_clk            => dp_clk,
258
 
259
    -- MM interface
260
    ram_data_buf_mosi => ram_diag_data_buf_re_mosi,
261
    ram_data_buf_miso => ram_diag_data_buf_re_miso,
262
 
263
    reg_data_buf_mosi => reg_diag_data_buf_re_mosi,
264
    reg_data_buf_miso => reg_diag_data_buf_re_miso,
265
 
266
    -- ST interface
267
    in_sync           => ss_out_sosi_re_arr(0).sync,
268
    in_sosi_arr       => ss_out_sosi_re_arr
269
  );
270
 
271
  ----------------------------------------------------------------------------
272
  -- Sink: data buffer imag 
273
  ---------------------------------------------------------------------------- 
274 5 danv
  u_data_buf_im : ENTITY astron_diagnostics_lib.mms_diag_data_buffer
275 2 danv
  GENERIC MAP (
276
    g_nof_streams  => c_nof_streams,
277
    g_data_w       => g_fft.out_dat_w,
278
    g_buf_nof_data => 1024,
279
    g_buf_use_sync => FALSE
280
  )
281
  PORT MAP (
282
    -- System
283
    mm_rst            => mm_rst,
284
    mm_clk            => mm_clk,
285
    dp_rst            => dp_rst,
286
    dp_clk            => dp_clk,
287
 
288
    -- MM interface
289
    ram_data_buf_mosi => ram_diag_data_buf_im_mosi,
290
    ram_data_buf_miso => ram_diag_data_buf_im_miso,
291
 
292
    reg_data_buf_mosi => reg_diag_data_buf_im_mosi,
293
    reg_data_buf_miso => reg_diag_data_buf_im_miso,
294
 
295
    -- ST interface
296
    in_sync           => ss_out_sosi_im_arr(0).sync,
297
    in_sosi_arr       => ss_out_sosi_im_arr
298
  );
299
 
300
END tb;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.