OpenCores
URL https://opencores.org/ocsvn/astron_wb_fft/astron_wb_fft/trunk

Subversion Repositories astron_wb_fft

[/] [astron_wb_fft/] [trunk/] [tb_fft_wide_unit.vhd] - Blame information for rev 3

Go to most recent revision | 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
--
22
-- Purpose: Test bench for the Wideband Complex radix 2 FFT
23
--
24
--
25
-- Usage:
26
--   > run -all
27
--   > testbench is selftesting. The first four spectrums are verified. 
28
--
29
 
30
library ieee, common_pkg_lib, dp_pkg_lib, diag_lib, rTwoSDF_lib, common_ram_lib, mm_lib;
31
use IEEE.std_logic_1164.all;
32
use IEEE.numeric_std.all;
33
use IEEE.std_logic_textio.all;
34
use STD.textio.all;
35
use common_pkg_lib.common_pkg.all;
36
use common_ram_lib.common_ram_pkg.ALL;
37
use common_pkg_lib.common_lfsr_sequences_pkg.all;
38
use common_pkg_lib.tb_common_pkg.all;
39
use mm_lib.tb_common_mem_pkg.ALL;
40
use dp_pkg_lib.dp_stream_pkg.ALL;
41
use rTwoSDF_lib.twiddlesPkg.all;
42
use rTwoSDF_lib.rTwoSDFPkg.all;
43
use work.tb_fft_pkg.all;
44
use work.fft_pkg.all;
45
 
46
entity tb_fft_wide_unit is
47
  generic(
48
    -- generics for tb
49
    g_use_uniNoise_file  : boolean  := true;
50
    g_use_sinus_file     : boolean  := false;
51
    g_use_sinNoise_file  : boolean  := false;
52
    g_use_impulse_file   : boolean  := false;
53
    g_use_2xreal_inputs  : boolean  := false;  -- Set to true for running the two-real input variants  
54
    g_fft : t_fft := (true, false, false, 0, 4, 0, 1024, 16, 18, 0, 18, 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 entity tb_fft_wide_unit;
74
 
75
architecture tb of tb_fft_wide_unit is
76
 
77
  constant c_clk_period : time    := 100 ns;
78
 
79
  -- input/output data width
80
  constant c_in_dat_w   : natural := g_fft.in_dat_w;
81
  constant c_twiddle_w  : natural := 16;
82
  constant c_out_dat_w  : natural := g_fft.out_dat_w; --   g_rtwo_fft.in_dat_w + natural((ceil_log2(g_rtwo_fft.nof_points))/2 + 2);  -- bit growth
83
 
84
  -- input/output files
85
  constant c_nof_spectra_in_file : natural := 4;
86
  constant c_file_len            : natural := c_nof_spectra_in_file*g_fft.nof_points;
87
 
88
  -- block generator  
89
  constant c_bg_mem_size           : natural := c_nof_spectra_in_file*g_fft.nof_points/g_fft.wb_factor;
90
  constant c_bg_addr_w             : natural := ceil_log2(c_bg_mem_size);
91
  constant c_nof_samples_in_packet : natural := c_bg_mem_size/c_nof_spectra_in_file;
92
  constant c_gap                   : natural := 3;    -- Gapsize is set to 0 in order to generate a continuous stream of packets. 
93
  constant c_nof_accum_per_sync    : natural := 8;
94
  constant c_bsn_init              : natural := 32;
95
  constant c_bg_prefix             : string  := "UNUSED";
96
  constant c_nof_sync_periods      : natural := 6;
97
  constant c_bst_skip_nof_sync     : natural := 3;
98
 
99
  constant c_normal                : BOOLEAN  := TRUE;
100
 
101
      -- input from uniform noise file created automatically by MATLAB testFFT_input.m
102
  constant c_noiseInputFile    : string := "data/test/in/uniNoise_p"  & natural'image(g_fft.nof_points)& "_b"& natural'image(c_twiddle_w) &"_in.txt";
103
  constant c_noiseGoldenFile   : string := "data/test/out/uniNoise_p" & natural'image(g_fft.nof_points)& "_b"& natural'image(c_twiddle_w) &"_tb"&natural'image(wTyp'length) &"_out.txt";
104
  constant c_noiseOutputFile   : string := "data/test/out/uniNoise_out.txt";
105
 
106
  -- input from sinus file. Data is from diag_wg_wideband. 
107
  constant c_sinusInputFile    : string := "data/test/in/sinus_p"     & natural'image(g_fft.nof_points)& "_b"& natural'image(g_fft.in_dat_w) &"_in.txt";
108
  constant c_sinusGoldenFile   : string := "data/test/out/sinus_p"    & natural'image(g_fft.nof_points)& "_b"& natural'image(g_fft.in_dat_w) &"_tb"&natural'image(wTyp'length) &"_out.txt";
109
  constant c_sinusOutputFile   : string := "data/test/out/sinus_out.txt";
110
 
111
  -- input from combined sinus with noise file. Real part is sinus, imaginary part is noise
112
  constant c_sinNoiseInputFile    : string := "data/test/in/sinNoise_p"     & natural'image(g_fft.nof_points)& "_b"& natural'image(g_fft.in_dat_w) &"_in.txt";
113
  constant c_sinNoiseGoldenFile   : string := "data/test/out/sinNoise_p"    & natural'image(g_fft.nof_points)& "_b"& natural'image(g_fft.in_dat_w) &"_tb"&natural'image(wTyp'length) &"_out.txt";
114
  constant c_sinNoiseOutputFile   : string := "data/test/out/sinNoise_out.txt";
115
 
116
  -- input from impulse files
117
  constant c_impulseInputFile  : string := "data/impulse_p"           & natural'image(g_fft.nof_points)& "_b"& natural'image(c_twiddle_w)& "_in.txt";
118
  constant c_impulseGoldenFile : string := "data/impulse_p"           & natural'image(g_fft.nof_points)& "_b"& natural'image(c_twiddle_w)& "_out.txt";
119
  constant c_impulseOutputFile : string := "data/impulse_out.txt";
120
 
121
  -- input from 2xreal impulse files
122
  constant c_2xrealImpulseInputFile   : string := "data/2xreal_impulse_p"    & natural'image(g_fft.nof_points)& "_b"& natural'image(c_twiddle_w)& "_in.txt";
123
  constant c_2xrealImpulseGoldenFile  : string := "data/2xreal_impulse_p"    & natural'image(g_fft.nof_points)& "_b"& natural'image(c_twiddle_w)& "_out.txt";
124
  constant c_2xrealImpulseOutputFile  : string := "data/2xreal_impulse_out.txt";
125
 
126
  constant c_2xrealNoiseGoldenFile    : string := "data/test/out/uniNoise_2xreal_p" & natural'image(g_fft.nof_points)& "_b"& natural'image(c_twiddle_w) &"_tb"&natural'image(wTyp'length) &"_out.txt";
127
  constant c_2xrealSinusGoldenFile    : string := "data/test/out/sinus_2xreal_p"    & natural'image(g_fft.nof_points)& "_b"& natural'image(g_fft.in_dat_w) &"_tb"&natural'image(wTyp'length) &"_out.txt";
128
  constant c_2xrealSinNoiseGoldenFile : string := "data/test/out/sinNoise_2xreal_p" & natural'image(g_fft.nof_points)& "_b"& natural'image(g_fft.in_dat_w) &"_tb"&natural'image(wTyp'length) &"_out.txt";
129
 
130
  -- determine active stimuli and result files
131
  constant c_preSelImpulseInputFile   : string := sel_a_b(g_use_2xreal_inputs, c_2xrealImpulseInputFile,   c_impulseInputFile);
132
  constant c_preSelImpulseGoldenFile  : string := sel_a_b(g_use_2xreal_inputs, c_2xrealImpulseGoldenFile,  c_impulseGoldenFile);
133
  constant c_preSelImpulseOutputFile  : string := sel_a_b(g_use_2xreal_inputs, c_2xrealImpulseOutputFile,  c_impulseOutputFile);
134
  constant c_preSelNoiseGoldenFile    : string := sel_a_b(g_use_2xreal_inputs, c_2xrealNoiseGoldenFile,    c_noiseGoldenFile);
135
  constant c_preSelSinusGoldenFile    : string := sel_a_b(g_use_2xreal_inputs, c_2xrealSinusGoldenFile,    c_sinusGoldenFile);
136
  constant c_preSelSinNoiseGoldenFile : string := sel_a_b(g_use_2xreal_inputs, c_2xrealSinNoiseGoldenFile, c_sinNoiseGoldenFile);
137
 
138
  constant c_inputFile  : string := sel_a_b(g_use_uniNoise_file, c_noiseInputFile,
139
                                    sel_a_b(g_use_sinus_file,    c_sinusInputFile,
140
                                    sel_a_b(g_use_sinNoise_file, c_sinNoiseInputFile,        c_preSelImpulseInputFile)));
141
 
142
  constant c_goldenFile : string := sel_a_b(g_use_uniNoise_file, c_preSelNoiseGoldenFile,
143
                                    sel_a_b(g_use_sinus_file,    c_preSelSinusGoldenFile,
144
                                    sel_a_b(g_use_sinNoise_file, c_preSelSinNoiseGoldenFile, c_preSelImpulseGoldenFile)));
145
 
146
  constant c_outputFile : string := sel_a_b(g_use_uniNoise_file, c_noiseOutputFile,
147
                                    sel_a_b(g_use_sinus_file,    c_sinusOutputFile,
148
                                    sel_a_b(g_use_sinNoise_file, c_sinNoiseOutputFile,       c_preSelImpulseOutputFile)));
149
 
150
  -- signal definitions
151
  signal tb_end         : std_logic := '0';
152
  signal clk            : std_logic := '0';
153
  signal rst            : std_logic := '0';
154
 
155
  signal out_sync       : std_logic:= '0';
156
  signal out_val        : std_logic:= '0';
157
  signal out_re_arr     : t_fft_slv_arr(g_fft.wb_factor-1 downto 0);
158
  signal out_im_arr     : t_fft_slv_arr(g_fft.wb_factor-1 downto 0);
159
 
160
  signal in_file_data   : t_integer_matrix(0 to c_file_len-1, 1 to 2) := (others=>(others=>0));  -- [re, im]
161
  signal in_file_sync   : std_logic_vector(0 to c_file_len-1):= (others=>'0');
162
  signal in_file_val    : std_logic_vector(0 to c_file_len-1):= (others=>'0');
163
 
164
  signal gold_file_data : t_integer_matrix(0 to c_file_len-1, 1 to 2) := (others=>(others=>0));  -- [re, im]
165
  signal gold_file_sync : std_logic_vector(0 to c_file_len-1):= (others=>'0');
166
  signal gold_file_val  : std_logic_vector(0 to c_file_len-1):= (others=>'0');
167
 
168
  signal gold_sync      : std_logic;
169
  signal gold_re_arr    : t_integer_arr(g_fft.wb_factor-1 downto 0);
170
  signal gold_im_arr    : t_integer_arr(g_fft.wb_factor-1 downto 0);
171
 
172
  signal init_waveforms_done   : std_logic;
173
 
174
  signal in_sosi_arr     : t_dp_sosi_arr(g_fft.wb_factor-1 downto 0);
175
  signal in_siso_arr     : t_dp_siso_arr(g_fft.wb_factor-1 downto 0);
176
 
177
  type   t_dp_sosi_matrix  is array (integer range <>) of t_dp_sosi_arr(0 downto 0);
178
  type   t_dp_siso_matrix  is array (integer range <>) of t_dp_siso_arr(0 downto 0);
179
 
180
  signal in_sosi_matrix  : t_dp_sosi_matrix(g_fft.wb_factor-1 downto 0);
181
  signal in_siso_matrix  : t_dp_siso_matrix(g_fft.wb_factor-1 downto 0);
182
 
183
  signal result_sosi_arr : t_dp_sosi_arr(g_fft.wb_factor-1 downto 0);
184
 
185
  signal ram_sst_mosi    : t_mem_mosi := c_mem_mosi_rst;
186
  signal ram_sst_miso    : t_mem_miso := c_mem_miso_rst;
187
 
188
  signal ram_bg_data_mosi_arr : t_mem_mosi_arr(g_fft.wb_factor-1 downto 0) := (others => c_mem_mosi_rst );
189
  signal reg_bg_ctrl_mosi : t_mem_mosi;
190
 
191
  -- Subband Statistics output
192
  -- . DUT result
193
  signal result_sst_arr_temp   : t_slv_64_arr(c_nof_samples_in_packet-1 downto 0);
194
  signal result_sst_arr        : t_slv_64_arr(g_fft.nof_points-1 downto 0);
195
  -- . Expected result
196
  signal expected_sst_arr      : t_slv_64_arr(g_fft.nof_points-1 downto 0) := (others => (others => '0'));
197
 
198
begin
199
 
200
  clk <= (not clk) or tb_end after c_clk_period/2;
201
  rst <= '1', '0' after c_clk_period*7;
202
 
203
  ---------------------------------------------------------------
204
  -- READ STIMULI DATA FROM INPUT FILE
205
  ---------------------------------------------------------------  
206
  proc_read_input_file(clk, in_file_data, in_file_sync, in_file_val, c_inputFile);
207
 
208
  ------------------------------------------------------------------------------
209
  -- WRITE THE WAVEFORMS INTO MEMORY FOR EACH INPUT STREAM.
210
  ------------------------------------------------------------------------------
211
  gen_init_waveforms : for I in 0 to g_fft.wb_factor-1 generate
212
    p_init_waveforms_memory : process
213
      variable v_mem_data : std_logic_vector(c_nof_complex*g_fft.in_dat_w-1 downto 0);
214
    begin
215
      init_waveforms_done <= '0';
216
 
217
      proc_common_wait_until_low(clk, rst);      -- Wait until reset has finished
218
      proc_common_wait_some_cycles(clk, 10);     -- Wait an additional amount of cycles
219
 
220
      for J in 0 to c_bg_mem_size-1 loop
221
        v_mem_data := (others => '0');
222
        v_mem_data := TO_SVEC(in_file_data(I+J*g_fft.wb_factor, 2), g_fft.in_dat_w) & TO_SVEC(in_file_data(I+J*g_fft.wb_factor, 1), g_fft.in_dat_w);  -- two k_bf.in_dat_w = 16 fits in c_word_w = 32 bit
223
        proc_mem_mm_bus_wr(J, v_mem_data, clk, ram_bg_data_mosi_arr(I));
224
      end loop;
225
 
226
      init_waveforms_done <= '1';
227
      wait;
228
    end process;
229
  end generate;
230
 
231
  ------------------------------------------------------------------------------
232
  -- CONFIGURE AND ENABLE THE BLOCK GENERATORS (Start Stimuli)
233
  ------------------------------------------------------------------------------
234
  p_control_input_stream : process
235
  begin
236
    reg_bg_ctrl_mosi <= c_mem_mosi_rst;
237
 
238
    -- Wait until reset is done
239
    proc_common_wait_until_high(clk, rst);
240
    proc_common_wait_some_cycles(clk, 10);
241
    wait until init_waveforms_done = '1';       -- Wait until the waveform data is written. 
242
 
243
    -- Set and enable the waveform generators. All generators are controlled by the same registers
244
    proc_mem_mm_bus_wr(1, c_nof_samples_in_packet, clk, reg_bg_ctrl_mosi);  -- Set the number of samples per block
245
    proc_mem_mm_bus_wr(2, c_nof_accum_per_sync,    clk, reg_bg_ctrl_mosi);  -- Set the number of blocks per sync
246
    proc_mem_mm_bus_wr(3, c_gap,                   clk, reg_bg_ctrl_mosi);  -- Set the gapsize
247
    proc_mem_mm_bus_wr(4, 0,                       clk, reg_bg_ctrl_mosi);  -- Set the start address of the memory
248
    proc_mem_mm_bus_wr(5, c_bg_mem_size-1,         clk, reg_bg_ctrl_mosi);  -- Set the end address of the memory
249
    proc_mem_mm_bus_wr(6, c_bsn_init,              clk, reg_bg_ctrl_mosi);  -- Set the BSNInit low  value
250
    proc_mem_mm_bus_wr(7, 0,                       clk, reg_bg_ctrl_mosi);  -- Set the BSNInit high value
251
    proc_mem_mm_bus_wr(0, 1,                       clk, reg_bg_ctrl_mosi);  -- Enable the BG
252
 
253
    -- Run time is defined by:
254
    --   * the number of sync periods
255
    --   * the number of packets in a sync period (c_nof_accum_per_sync)
256
    --   * the number of samples in a packet
257
    --   * the gap size
258
    proc_common_wait_some_cycles(clk, c_nof_sync_periods*c_nof_accum_per_sync*(c_nof_samples_in_packet+c_gap));
259
 
260
    -- Disable the BG
261
    proc_mem_mm_bus_wr(0, 0, clk, reg_bg_ctrl_mosi);
262
 
263
    -- Wait some additional time in order to let release the pipline stages of the FFT. 
264
    proc_common_wait_some_cycles(clk, 4*g_fft.nof_points);
265
    tb_end <= '1';
266
 
267
    wait;
268
  end process;
269
 
270
  ---------------------------------------------------------------  
271
  -- GENERATE BLOCK GENERATORS FOR STIMULI GENERATION
272
  ---------------------------------------------------------------  
273
  gen_block_gen : for I in 0 to g_fft.wb_factor-1 generate
274
    u_block_generator : entity diag_lib.mms_diag_block_gen
275
    generic map(
276
      g_nof_streams        => 1,
277
      g_buf_dat_w          => c_nof_complex*g_fft.in_dat_w,
278
      g_buf_addr_w         => c_bg_addr_w,
279
      g_file_name_prefix   => c_bg_prefix
280
    )
281
    port map(
282
     -- Clocks and Reset
283
      mm_rst           => rst,
284
      mm_clk           => clk,
285
      dp_rst           => rst,
286
      dp_clk           => clk,
287
      en_sync          => '1',
288
      ram_bg_data_mosi => ram_bg_data_mosi_arr(I),
289
      ram_bg_data_miso => open,
290
      reg_bg_ctrl_mosi => reg_bg_ctrl_mosi,
291
      reg_bg_ctrl_miso => open,
292
      out_siso_arr     => in_siso_matrix(I),
293
      out_sosi_arr     => in_sosi_matrix(I)
294
    );
295
    in_sosi_arr(I)       <= in_sosi_matrix(I)(0);
296
    in_siso_matrix(I)(0) <= c_dp_siso_rdy;
297
  end generate;
298
 
299
  ------------------------------------------------------------------------------  
300
  -- READ THE BEAMLET STATISTICS     
301
  ------------------------------------------------------------------------------
302
  -- Read statistics from the memory interface once every sync interval.
303
  p_read_sst_memory : process
304
    variable c_sync_cnt : natural;
305
  begin
306
    proc_common_wait_until_low(clk, rst);    -- Wait until reset has finished
307
 
308
    -- Skip reading for the initial syncs to save simulation time
309
    for J in 0 to c_bst_skip_nof_sync-2 loop
310
      wait until result_sosi_arr(0).sync = '1';
311
      wait until result_sosi_arr(0).sync = '0';
312
    end loop;
313
 
314
    while(true) loop
315
      wait until result_sosi_arr(0).sync = '1';
316
      proc_common_wait_some_cycles(clk, c_nof_samples_in_packet+10);
317
 
318
      for I in 0 to g_fft.wb_factor-1 loop
319
        proc_fft_read_subband_statistics_memory(I, g_fft, clk, ram_sst_mosi, ram_sst_miso, result_sst_arr_temp);
320
        result_sst_arr((I+1)*c_nof_samples_in_packet-1 downto I*c_nof_samples_in_packet) <= result_sst_arr_temp;  -- can not use result_bst_arr2(I) directly as argument in proc_bf_read_beamlet_statistics_memory()
321
      end loop;
322
    end loop;
323
  end process;
324
 
325
  ---------------------------------------------------------------  
326
  -- DUT = Device Under Test
327
  ---------------------------------------------------------------  
328
  u_dut : entity work.fft_wide_unit
329
  generic map (
330
    g_fft          => g_fft
331
  )
332
  port map (
333
    dp_rst          => rst,
334
    dp_clk          => clk,
335
    mm_rst          => rst,
336
    mm_clk          => clk,
337
    ram_st_sst_mosi => ram_sst_mosi,
338
    ram_st_sst_miso => ram_sst_miso,
339
    in_sosi_arr     => in_sosi_arr,
340
    out_sosi_arr    => result_sosi_arr
341
  );
342
  ---------------------------------------------------------------  
343
  -- REARRANGE THE OUTPUT-DATA FOR VERIFICATION
344
  ---------------------------------------------------------------  
345
  gen_extract_data : for I in 0 to g_fft.wb_factor-1 generate
346
    out_re_arr(I) <= RESIZE_SVEC(result_sosi_arr(I).re, out_re_arr(I)'length);
347
    out_im_arr(I) <= RESIZE_SVEC(result_sosi_arr(I).im, out_im_arr(I)'length);
348
  end generate;
349
  out_val <= result_sosi_arr(0).valid;
350
 
351
  ---------------------------------------------------------------  
352
  -- READ GOLDEN FILE WITH THE EXPECTED DUT OUTPUT
353
  ---------------------------------------------------------------  
354
  proc_read_input_file(clk, gold_file_data, gold_file_sync, gold_file_val, c_goldenFile);
355
 
356
  ---------------------------------------------------------------  
357
  -- CREATE THE GOLDEN ARRAY FOR VERIFICATION
358
  ---------------------------------------------------------------  
359
  p_create_golden_array : process
360
    constant c_sst_in_w       : natural := 16;
361
    variable v_nof_outs       : natural := g_fft.nof_points/g_fft.wb_factor;
362
    variable v_bin_index      : natural := 0;
363
    variable v_spectrum_index : natural := 0;
364
    variable v_list_index     : natural := 0;
365
    variable v_int_time       : integer := 0;
366
    variable v_subband_cnt    : integer := 0;
367
 
368
    variable v_sum_re         : std_logic_vector(c_sst_in_w-1 downto 0);
369
    variable v_sum_im         : std_logic_vector(c_sst_in_w-1 downto 0);
370
 
371
    variable v_sum_pwr        : std_logic_vector(g_fft.stat_data_w-1 downto 0) := (others => '0');
372
    variable v_acc_pwr_arr    : t_slv_64_arr(g_fft.nof_points-1 downto 0) := (others => (others => '0'));
373
  begin
374
    wait until rising_edge(clk);
375
    if(out_val = '1') then
376
      if(v_spectrum_index = v_nof_outs - 1) then
377
        v_spectrum_index := 0;
378
        v_bin_index := v_bin_index + g_fft.nof_points - v_nof_outs;
379
      else
380
        v_spectrum_index := v_spectrum_index + 1;
381
      end if;
382
      v_bin_index := v_bin_index + 1;
383
 
384
      if(v_list_index = c_file_len/g_fft.wb_factor-1) then
385
        v_bin_index    := 0;
386
        v_list_index   := 0;
387
      else
388
        v_list_index := v_list_index + 1;
389
      end if;
390
 
391
      for I in 0 to g_fft.wb_factor-1 loop
392
        -- Calculate the auto correlation power:
393
        v_sum_re := RESIZE_SVEC(TO_SVEC(gold_re_arr(I), c_word_w), v_sum_re'length);
394
        v_sum_im := RESIZE_SVEC(TO_SVEC(gold_im_arr(I), c_word_w), v_sum_im'length);
395
        v_sum_pwr(32 downto 0) := func_complex_multiply(v_sum_re, v_sum_im, v_sum_re, v_sum_im, c_normal, "RE", 33);
396
        v_acc_pwr_arr(I*v_nof_outs + v_subband_cnt) := ADD_UVEC(v_acc_pwr_arr(I*v_nof_outs + v_subband_cnt), v_sum_pwr);
397
      end loop;
398
 
399
      if(v_subband_cnt = v_nof_outs-1) then
400
        v_subband_cnt := 0;
401
      else
402
        v_subband_cnt := v_subband_cnt + 1;
403
      end if;
404
 
405
      ------------------------------------------------------------------------
406
      -- Latch the expected accumulated statistics to the output at the sync
407
      ------------------------------------------------------------------------
408
      if(v_int_time = c_nof_accum_per_sync*v_nof_outs-1) then
409
        v_int_time := 0;
410
        -- Output the expected BST array
411
        expected_sst_arr <= v_acc_pwr_arr;
412
        v_acc_pwr_arr    :=(others => (others => '0'));
413
        assert expected_sst_arr = result_sst_arr   report "Output statistics error" severity error;
414
        assert expected_sst_arr /= result_sst_arr   report "Output statistics OK!!!!" severity note;
415
      else
416
        v_int_time := v_int_time + 1;
417
      end if;
418
    end if;
419
 
420
    for I in 0 to g_fft.wb_factor-1 loop
421
      gold_re_arr(I) <= gold_file_data(v_bin_index + I*v_nof_outs, 1);
422
      gold_im_arr(I) <= gold_file_data(v_bin_index + I*v_nof_outs, 2);
423
    end loop;
424
 
425
    gold_sync  <= gold_file_sync(v_bin_index);
426
 
427
  end process;
428
 
429
  -- Verify the output of the DUT with the expected output from the golden reference file
430
  p_verify_output : process(clk)
431
  begin
432
    -- Compare
433
    if rising_edge(clk) then
434
      if out_val='1' then
435
        -- only write when out_val='1', because then the file is independent of cycles with invalid out_dat
436
        assert out_sync = gold_sync report "Output sync error"  severity error;
437
        for I in 0 to g_fft.wb_factor-1 loop
438
          assert TO_SINT(out_re_arr(I)) = gold_re_arr(I)   report "Output real data error" severity error;
439
          assert TO_SINT(out_im_arr(I)) = gold_im_arr(I)   report "Output imag data error" severity error;
440
        end loop;
441
      end if;
442
    end if;
443
  end process;
444
 
445
end tb;

powered by: WebSVN 2.1.0

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