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 2

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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