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

powered by: WebSVN 2.1.0

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