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.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: Testbench for the radix-2 FFT.
24
--
25
--          The testbench serves the pipelined, wideband and parallel FFTs.
26
--          The generic g_fft_type is used to select the desired FFT. 
27
--
28
--          The testbech uses blockgenerators to generate data for 
29
--          every input of the FFT. 
30
--          The output of the FFT is stored in databuffers. 
31
--          Both the block generators and databuffers are controlled
32
--          via a mm interface. 
33
--          Use this testbench in conjunction with ../python/tc_mmf_fft_r2.py
34
--
35
-- The testbench can be used in two modes: auto-mode and non-auto-mode. The mode
36
-- is determined by the constant c_modelsim_start in the tc_mmf_fft_r2.py script. 
37
-- 
38
-- Usage in auto-mode (c_modelsim_start = 1 in python):
39
--   > Run python script in separate terminal: "python tc_mmf_fft_r2.py --unb 0 --bn 0 --sim"
40
--
41
-- Usage in non-auto-mode (c_modelsim_start = 0 in python):
42
--   > run -all
43
--   > Run python script in separate terminal: "python tc_mmf_fft_r2.py --unb 0 --bn 0 --sim"
44
--   > Check the results of the python script. 
45
--   > Stop the simulation manually in Modelsim by pressing the stop-button. 
46
 
47
 
48
LIBRARY IEEE, common_pkg_lib, mm_lib, diag_lib, dp_pkg_lib, rTwoSDF_lib, common_ram_lib, mm_lib, other_lib;
49
USE IEEE.std_logic_1164.ALL;
50
USE IEEE.numeric_std.ALL;
51
USE common_pkg_lib.common_pkg.ALL;
52
USE common_ram_lib.common_ram_pkg.ALL;
53
USE common_pkg_lib.common_str_pkg.ALL;
54
USE common_pkg_lib.tb_common_pkg.ALL;
55
USE mm_lib.tb_common_mem_pkg.ALL;
56
USE mm_lib.mm_file_unb_pkg.ALL;
57
USE mm_lib.mm_file_pkg.ALL;
58
USE dp_pkg_lib.dp_stream_pkg.ALL;
59
USE diag_lib.diag_pkg.ALL;
60
USE rTwoSDF_lib.rTwoSDFPkg.all;
61
USE work.fft_pkg.all;
62
 
63
ENTITY tb_mmf_fft_r2 IS
64
  GENERIC(
65
    g_fft_type         : string  := "wide"; -- = default "wide", 3 fft types possible: pipe, wide or par 
66
    g_nof_chan         : natural := 0;      -- = default 0, defines the number of channels (=time-multiplexed input signals): nof channels = 2**nof_chan         
67
    g_wb_factor        : natural := 4;      -- = default 1, wideband factor
68
    g_nof_points       : natural := 1024;     -- = 1024, N point FFT
69
    g_nof_blocks       : natural := 4;      -- = 4, the number of blocks of g_nof_points each in the BG waveform (must be power of 2 due to that BG c_bg_block_len must be power of 2)
70
    g_in_dat_w         : natural := 8;      -- = 8, number of input bits                                                       
71
    g_out_dat_w        : natural := 16;     -- = 14, number of output bits: in_dat_w + natural((ceil_log2(nof_points))/2) 
72
    g_use_separate     : boolean := false   -- = false for complex input, true for two real inputs
73
 
74
  );
75
END tb_mmf_fft_r2;
76
 
77
ARCHITECTURE tb OF tb_mmf_fft_r2 IS
78
 
79
  CONSTANT c_fft : t_fft := (true, false, g_use_separate, g_nof_chan, g_wb_factor, 0, g_nof_points, g_in_dat_w, g_out_dat_w, 0, c_dsp_mult_w, 2, true, 56, 2);
80
    --  type t_rtwo_fft is record
81
    --    use_reorder    : boolean;  -- = false for bit-reversed output, true for normal output
82
    --    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
83
    --    use_separate   : boolean;  -- = false for complex input, true for two real inputs
84
    --    nof_chan       : natural;  -- = default 0, defines the number of channels (=time-multiplexed input signals): nof channels = 2**nof_chan         
85
    --    wb_factor      : natural;  -- = default 1, wideband factor
86
    --    twiddle_offset : natural;  -- = default 0, twiddle offset for PFT sections in a wideband FFT
87
    --    nof_points     : natural;  -- = 1024, N point FFT
88
    --    in_dat_w       : natural;  -- = 8, number of input bits
89
    --    out_dat_w      : natural;  -- = 13, number of output bits: in_dat_w + natural((ceil_log2(nof_points))/2 + 2)  
90
    --    out_gain_w     : natural;  -- = 0, output gain factor applied after the last stage output, before requantization to out_dat_w
91
    --    stage_dat_w    : natural;  -- = 18, data width used between the stages(= DSP multiplier-width)
92
    --    guard_w        : natural;  -- = 2,  Guard used to avoid overflow in FFT stage. 
93
    --    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)    
94
    --    stat_data_w    : positive; -- = 56
95
    --    stat_data_sz   : positive; -- = 2
96
    --  end record;  
97
 
98
  CONSTANT c_sim                : BOOLEAN := TRUE;
99
 
100
  ----------------------------------------------------------------------------
101
  -- Clocks and resets
102
  ----------------------------------------------------------------------------   
103
  CONSTANT c_mm_clk_period      : TIME := 100 ps;
104
  CONSTANT c_dp_clk_period      : TIME := 5 ns;
105
  CONSTANT c_sclk_period        : TIME := 1250 ps;
106
  CONSTANT c_dp_pps_period      : NATURAL := 64;
107
 
108
  SIGNAL dp_pps                 : STD_LOGIC;
109
 
110
  SIGNAL mm_rst                 : STD_LOGIC;
111
  SIGNAL mm_clk                 : STD_LOGIC := '0';
112
 
113
  SIGNAL dp_rst                 : STD_LOGIC;
114
  SIGNAL dp_clk                 : STD_LOGIC := '0';
115
 
116
  SIGNAL SCLK                   : STD_LOGIC := '0';
117
 
118
  ----------------------------------------------------------------------------
119
  -- MM buses
120
  ----------------------------------------------------------------------------                                         
121
  SIGNAL reg_diag_bg_mosi          : t_mem_mosi;
122
  SIGNAL reg_diag_bg_miso          : t_mem_miso;
123
 
124
  SIGNAL ram_diag_bg_mosi          : t_mem_mosi;
125
  SIGNAL ram_diag_bg_miso          : t_mem_miso;
126
 
127
  SIGNAL ram_diag_data_buf_re_mosi : t_mem_mosi;
128
  SIGNAL ram_diag_data_buf_re_miso : t_mem_miso;
129
 
130
  SIGNAL reg_diag_data_buf_re_mosi : t_mem_mosi;
131
  SIGNAL reg_diag_data_buf_re_miso : t_mem_miso;
132
 
133
  SIGNAL ram_diag_data_buf_im_mosi : t_mem_mosi;
134
  SIGNAL ram_diag_data_buf_im_miso : t_mem_miso;
135
 
136
  SIGNAL reg_diag_data_buf_im_mosi : t_mem_mosi;
137
  SIGNAL reg_diag_data_buf_im_miso : t_mem_miso;
138
 
139
  CONSTANT c_nof_channels           : NATURAL  := 2**c_fft.nof_chan;
140
  CONSTANT c_nof_streams            : POSITIVE := c_fft.wb_factor;
141
  CONSTANT c_bg_block_len           : NATURAL  := c_fft.nof_points*g_nof_blocks*c_nof_channels/c_fft.wb_factor;
142
 
143
  CONSTANT c_bg_buf_adr_w           : NATURAL := ceil_log2(c_bg_block_len);
144
  CONSTANT c_bg_data_file_index_arr : t_nat_natural_arr := array_init(0, c_fft.wb_factor, 1);
145
  CONSTANT c_bg_data_file_prefix    : STRING := "UNUSED";
146
 
147
  SIGNAL bg_siso_arr                : t_dp_siso_arr(c_fft.wb_factor-1 DOWNTO 0) := (OTHERS=>c_dp_siso_rdy);
148
  SIGNAL bg_sosi_arr                : t_dp_sosi_arr(c_fft.wb_factor-1 DOWNTO 0);
149
 
150
  SIGNAL out_sosi_arr               : t_dp_sosi_arr(c_fft.wb_factor-1 DOWNTO 0) := (OTHERS => c_dp_sosi_rst);
151
 
152
  SIGNAL in_re_arr                  : t_fft_slv_arr(c_fft.wb_factor-1 DOWNTO 0);
153
  SIGNAL in_im_arr                  : t_fft_slv_arr(c_fft.wb_factor-1 DOWNTO 0);
154
  SIGNAL in_val                     : STD_LOGIC := '0';
155
 
156
  SIGNAL out_re_arr                 : t_fft_slv_arr(c_fft.wb_factor-1 DOWNTO 0);
157
  SIGNAL out_im_arr                 : t_fft_slv_arr(c_fft.wb_factor-1 DOWNTO 0);
158
  SIGNAL out_val                    : STD_LOGIC := '0';
159
 
160
  SIGNAL scope_in_sosi              : t_dp_sosi_integer;
161
  SIGNAL scope_out_sosi             : t_dp_sosi_integer;
162
 
163
BEGIN
164
 
165
  ----------------------------------------------------------------------------
166
  -- Clock and reset generation
167
  ----------------------------------------------------------------------------
168
  mm_clk <= NOT mm_clk AFTER c_mm_clk_period/2;
169
  mm_rst <= '1', '0' AFTER c_mm_clk_period*5;
170
 
171
  SCLK   <= NOT SCLK AFTER c_sclk_period/2;
172
  dp_clk <= NOT dp_clk AFTER c_dp_clk_period/2;
173
  dp_rst <= '1', '0' AFTER c_dp_clk_period*5;
174
 
175
  ------------------------------------------------------------------------------
176
  -- External PPS
177
  ------------------------------------------------------------------------------  
178
  proc_common_gen_pulse(1, c_dp_pps_period, '1', dp_clk, dp_pps);
179
 
180
   ----------------------------------------------------------------------------
181
  -- Procedure that polls a sim control file that can be used to e.g. get
182
  -- the simulation time in ns
183
  ----------------------------------------------------------------------------
184
  mmf_poll_sim_ctrl_file(c_mmf_unb_file_path & "sim.ctrl", c_mmf_unb_file_path & "sim.stat");
185
 
186
  ----------------------------------------------------------------------------
187
  -- MM buses  
188
  ----------------------------------------------------------------------------
189
  u_mm_file_reg_diag_bg          : mm_file GENERIC MAP(mmf_unb_file_prefix(0, 0, "BN") & "REG_DIAG_BG")
190
                                           PORT MAP(mm_rst, mm_clk, reg_diag_bg_mosi, reg_diag_bg_miso);
191
 
192
  u_mm_file_ram_diag_bg          : mm_file GENERIC MAP(mmf_unb_file_prefix(0, 0, "BN") & "RAM_DIAG_BG")
193
                                           PORT MAP(mm_rst, mm_clk, ram_diag_bg_mosi, ram_diag_bg_miso);
194
 
195
  u_mm_file_ram_diag_data_buf_re : mm_file GENERIC MAP(mmf_unb_file_prefix(0, 0, "BN") & "RAM_DIAG_DATA_BUFFER_REAL")
196
                                           PORT MAP(mm_rst, mm_clk, ram_diag_data_buf_re_mosi, ram_diag_data_buf_re_miso);
197
 
198
  u_mm_file_reg_diag_data_buf_re : mm_file GENERIC MAP(mmf_unb_file_prefix(0, 0, "BN") & "REG_DIAG_DATA_BUFFER_REAL")
199
                                           PORT MAP(mm_rst, mm_clk, reg_diag_data_buf_re_mosi, reg_diag_data_buf_re_miso);
200
 
201
  u_mm_file_ram_diag_data_buf_im : mm_file GENERIC MAP(mmf_unb_file_prefix(0, 0, "BN") & "RAM_DIAG_DATA_BUFFER_IMAG")
202
                                           PORT MAP(mm_rst, mm_clk, ram_diag_data_buf_im_mosi, ram_diag_data_buf_im_miso);
203
 
204
  u_mm_file_reg_diag_data_buf_im : mm_file GENERIC MAP(mmf_unb_file_prefix(0, 0, "BN") & "REG_DIAG_DATA_BUFFER_IMAG")
205
                                           PORT MAP(mm_rst, mm_clk, reg_diag_data_buf_im_mosi, reg_diag_data_buf_im_miso);
206
 
207
  ----------------------------------------------------------------------------
208
  -- Source: block generator
209
  ---------------------------------------------------------------------------- 
210
  u_bg : ENTITY diag_lib.mms_diag_block_gen
211
  GENERIC MAP(
212
    g_nof_streams        => c_nof_streams,
213
    g_buf_dat_w          => c_nof_complex*c_fft.in_dat_w,
214
    g_buf_addr_w         => c_bg_buf_adr_w,               -- Waveform buffer size 2**g_buf_addr_w nof samples
215
    g_file_index_arr     => c_bg_data_file_index_arr,
216
    g_file_name_prefix   => c_bg_data_file_prefix
217
  )
218
  PORT MAP(
219
    -- System
220
    mm_rst           => mm_rst,
221
    mm_clk           => mm_clk,
222
    dp_rst           => dp_rst,
223
    dp_clk           => dp_clk,
224
    en_sync          => dp_pps,
225
    -- MM interface
226
    reg_bg_ctrl_mosi => reg_diag_bg_mosi,
227
    reg_bg_ctrl_miso => reg_diag_bg_miso,
228
    ram_bg_data_mosi => ram_diag_bg_mosi,
229
    ram_bg_data_miso => ram_diag_bg_miso,
230
    -- ST interface
231
    out_siso_arr     => bg_siso_arr,
232
    out_sosi_arr     => bg_sosi_arr
233
  );
234
 
235
  u_in_scope : ENTITY other_lib.dp_wideband_wb_arr_scope
236
  GENERIC MAP (
237
    g_sim                 => TRUE,
238
    g_wideband_factor     => c_fft.wb_factor,
239
    g_wideband_big_endian => FALSE,
240
    g_dat_w               => c_fft.in_dat_w
241
  )
242
  PORT MAP (
243
    SCLK         => SCLK,
244
    wb_sosi_arr  => bg_sosi_arr,
245
    scope_sosi   => scope_in_sosi
246
  );
247
 
248
  connect_input_data : FOR I IN 0 TO c_fft.wb_factor -1 GENERATE
249
    in_re_arr(I) <= RESIZE_SVEC(bg_sosi_arr(I).re(c_fft.in_dat_w-1 DOWNTO 0), in_re_arr(I)'LENGTH);
250
    in_im_arr(I) <= RESIZE_SVEC(bg_sosi_arr(I).im(c_fft.in_dat_w-1 DOWNTO 0), in_im_arr(I)'LENGTH);
251
  END GENERATE;
252
 
253
  in_val <= bg_sosi_arr(0).valid;
254
 
255
  -- DUT = Device Under Test  
256
  -- Based on the g_fft_type generic the appropriate 
257
  -- DUT is instantiated.  
258
  gen_wideband_fft : IF g_fft_type = "wide" GENERATE
259
    u_dut : ENTITY work.fft_r2_wide
260
    GENERIC MAP(
261
      g_fft          => c_fft     -- generics for the FFT
262
    )
263
    PORT MAP(
264
      clk        => dp_clk,
265
      rst        => dp_rst,
266
      in_re_arr  => in_re_arr,
267
      in_im_arr  => in_im_arr,
268
      in_val     => in_val,
269
      out_re_arr => out_re_arr,
270
      out_im_arr => out_im_arr,
271
      out_val    => out_val
272
    );
273
  END GENERATE;
274
 
275
  gen_pipelined_fft : IF g_fft_type = "pipe" GENERATE
276
    u_dut : ENTITY work.fft_r2_pipe
277
    GENERIC MAP(
278
      g_fft      => c_fft
279
    )
280
    port map(
281
      clk       => dp_clk,
282
      rst       => dp_rst,
283
      in_re     => in_re_arr(0)(c_fft.in_dat_w-1 DOWNTO 0),
284
      in_im     => in_im_arr(0)(c_fft.in_dat_w-1 DOWNTO 0),
285
      in_val    => in_val,
286
      out_re    => out_re_arr(0)(c_fft.out_dat_w-1 DOWNTO 0),
287
      out_im    => out_im_arr(0)(c_fft.out_dat_w-1 DOWNTO 0),
288
      out_val   => out_val
289
    );
290
  END GENERATE;
291
 
292
  gen_parallel_fft : IF g_fft_type = "par" GENERATE
293
    u_dut : ENTITY work.fft_r2_par
294
    GENERIC MAP(
295
      g_fft      => c_fft
296
    )
297
    PORT MAP(
298
      clk        => dp_clk,
299
      rst        => dp_rst,
300
      in_re_arr  => in_re_arr,
301
      in_im_arr  => in_im_arr,
302
      in_val     => in_val,
303
      out_re_arr => out_re_arr,
304
      out_im_arr => out_im_arr,
305
      out_val    => out_val
306
    );
307
  END GENERATE;
308
 
309
  connect_output_data : FOR I IN 0 TO c_fft.wb_factor -1 GENERATE
310
    out_sosi_arr(I).re    <= RESIZE_DP_DSP_DATA(out_re_arr(I));
311
    out_sosi_arr(I).im    <= RESIZE_DP_DSP_DATA(out_im_arr(I));
312
    out_sosi_arr(I).valid <= out_val;
313
  END GENERATE;
314
 
315
  u_out_scope : ENTITY other_lib.dp_wideband_wb_arr_scope
316
  GENERIC MAP (
317
    g_sim                 => TRUE,
318
    g_wideband_factor     => c_fft.wb_factor,
319
    g_wideband_big_endian => FALSE,
320
    g_dat_w               => c_fft.out_dat_w
321
  )
322
  PORT MAP (
323
    SCLK         => SCLK,
324
    wb_sosi_arr  => out_sosi_arr,
325
    scope_sosi   => scope_out_sosi
326
  );
327
 
328
  ----------------------------------------------------------------------------
329
  -- Sink: data buffer real 
330
  ---------------------------------------------------------------------------- 
331
  u_data_buf_re : ENTITY diag_lib.mms_diag_data_buffer
332
  GENERIC MAP (
333
    g_nof_streams  => c_nof_streams,
334
    g_data_type    => e_real,
335
    g_data_w       => c_fft.out_dat_w,
336
    g_buf_nof_data => c_bg_block_len,
337
    g_buf_use_sync => FALSE
338
  )
339
  PORT MAP (
340
    -- System
341
    mm_rst            => mm_rst,
342
    mm_clk            => mm_clk,
343
    dp_rst            => dp_rst,
344
    dp_clk            => dp_clk,
345
 
346
    -- MM interface
347
    ram_data_buf_mosi => ram_diag_data_buf_re_mosi,
348
    ram_data_buf_miso => ram_diag_data_buf_re_miso,
349
 
350
    reg_data_buf_mosi => reg_diag_data_buf_re_mosi,
351
    reg_data_buf_miso => reg_diag_data_buf_re_miso,
352
 
353
    -- ST interface
354
    in_sync           => OPEN,
355
    in_sosi_arr       => out_sosi_arr
356
  );
357
 
358
  ----------------------------------------------------------------------------
359
  -- Sink: data buffer imag 
360
  ---------------------------------------------------------------------------- 
361
  u_data_buf_im : ENTITY diag_lib.mms_diag_data_buffer
362
  GENERIC MAP (
363
    g_nof_streams  => c_nof_streams,
364
    g_data_type    => e_imag,
365
    g_data_w       => c_fft.out_dat_w,
366
    g_buf_nof_data => c_bg_block_len,
367
    g_buf_use_sync => FALSE
368
  )
369
  PORT MAP (
370
    -- System
371
    mm_rst            => mm_rst,
372
    mm_clk            => mm_clk,
373
    dp_rst            => dp_rst,
374
    dp_clk            => dp_clk,
375
 
376
    -- MM interface
377
    ram_data_buf_mosi => ram_diag_data_buf_im_mosi,
378
    ram_data_buf_miso => ram_diag_data_buf_im_miso,
379
 
380
    reg_data_buf_mosi => reg_diag_data_buf_im_mosi,
381
    reg_data_buf_miso => reg_diag_data_buf_im_miso,
382
 
383
    -- ST interface
384
    in_sync           => OPEN,
385
    in_sosi_arr       => out_sosi_arr
386
  );
387
 
388
END tb;

powered by: WebSVN 2.1.0

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