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

powered by: WebSVN 2.1.0

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