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 5

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

powered by: WebSVN 2.1.0

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