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

Subversion Repositories astron_wb_fft

[/] [astron_wb_fft/] [trunk/] [tb_fft_sepa.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: Test bench for fft_sepa
22
-- Features:
23
--
24
-- Usage:
25
-- > as 10
26
-- > run -all    
27
-- > Testbench is selftesting. 
28
-- First frame contains always some errors. 
29
 
30 5 danv
library IEEE, common_pkg_lib, dp_pkg_lib, astron_diagnostics_lib, astron_ram_lib, astron_mm_lib;
31 2 danv
use IEEE.std_logic_1164.ALL;
32
use IEEE.numeric_std.ALL;
33
use common_pkg_lib.common_pkg.ALL;
34 5 danv
use astron_ram_lib.common_ram_pkg.ALL;
35 2 danv
use common_pkg_lib.tb_common_pkg.ALL;
36 5 danv
use astron_mm_lib.tb_common_mem_pkg.ALL;
37 2 danv
use dp_pkg_lib.dp_stream_pkg.ALL;
38 5 danv
use astron_diagnostics_lib.diag_pkg.ALL;
39 2 danv
 
40
entity tb_fft_sepa is
41
end tb_fft_sepa;
42
 
43
architecture tb of tb_fft_sepa is
44
 
45
  constant c_clk_period : time := 10 ns;
46
 
47
  constant c_nof_points   : natural := 8;
48
  constant c_nof_points_b : natural := 1024;
49
  constant c_in_dat_w     : natural := 16;
50
  constant c_bg_addr_w    : natural := ceil_log2(c_nof_points_b);
51
 
52
  type t_input_buf_arr is array (integer range <>) of std_logic_vector(c_in_dat_w-1 downto 0);
53
 
54
  -- BG derived constants
55
  constant c_nof_samples_in_packet     : natural := c_nof_points;
56
  constant c_gap                       : natural := 8;
57
  constant c_bst_skip_nof_sync         : natural := 3;
58
  constant c_nof_accum_per_sync        : natural := 10;
59
  constant c_bsn_init                  : natural := 32;
60
  constant c_bg_prefix                 : string := "data/to_separate";
61
 
62
  signal tb_end    : std_logic := '0';
63
  signal rst       : std_logic;
64
  signal clk       : std_logic := '1';
65
 
66
  signal ram_bg_data_mosi : t_mem_mosi;
67
  signal reg_bg_ctrl_mosi : t_mem_mosi;
68
  signal in_sosi_arr      : t_dp_sosi_arr(0 downto 0);
69
  signal in_siso_arr      : t_dp_siso_arr(0 downto 0);
70
  signal out_sosi         : t_dp_sosi;
71
  signal in_dat           : std_logic_vector(2*c_in_dat_w-1 downto 0);
72
  signal out_dat          : std_logic_vector(2*c_in_dat_w-1 downto 0);
73
  signal out_dat_re       : std_logic_vector(c_in_dat_w-1 downto 0);
74
  signal out_dat_im       : std_logic_vector(c_in_dat_w-1 downto 0);
75
  signal out_val          : std_logic;
76
 
77
  signal buf_input_re     : t_input_buf_arr(c_nof_points-1 downto 0);
78
  signal buf_input_im     : t_input_buf_arr(c_nof_points-1 downto 0);
79
  signal buf_output_a_re  : t_input_buf_arr(c_nof_points/2-1 downto 0);
80
  signal buf_output_a_im  : t_input_buf_arr(c_nof_points/2-1 downto 0);
81
  signal buf_output_b_re  : t_input_buf_arr(c_nof_points/2-1 downto 0);
82
  signal buf_output_b_im  : t_input_buf_arr(c_nof_points/2-1 downto 0);
83
  signal buf_output_re    : t_input_buf_arr(c_nof_points-1 downto 0);
84
  signal buf_output_im    : t_input_buf_arr(c_nof_points-1 downto 0);
85
 
86
begin
87
 
88
  clk <= (not clk) or tb_end after c_clk_period/2;
89
  rst <= '1', '0' after c_clk_period*3;
90
 
91
  p_control_input_stream : process
92
  begin
93
    tb_end <= '0';
94
    reg_bg_ctrl_mosi <= c_mem_mosi_rst;
95
 
96
    -- Wait until reset is done
97
    proc_common_wait_until_high(clk, rst);
98
    proc_common_wait_some_cycles(clk, 10);
99
 
100
    -- Set and enable the waveform generators. All generators are controlled by the same registers
101
    proc_mem_mm_bus_wr(1, c_nof_samples_in_packet,   clk, reg_bg_ctrl_mosi);  -- Set the number of samples per block
102
    proc_mem_mm_bus_wr(2, c_nof_accum_per_sync,      clk, reg_bg_ctrl_mosi);  -- Set the number of blocks per sync
103
    proc_mem_mm_bus_wr(3, c_gap,                     clk, reg_bg_ctrl_mosi);  -- Set the gapsize
104
    proc_mem_mm_bus_wr(4, 0,                         clk, reg_bg_ctrl_mosi);  -- Set the start address of the memory
105
    proc_mem_mm_bus_wr(5, c_nof_samples_in_packet-1, clk, reg_bg_ctrl_mosi);  -- Set the end address of the memory
106
    proc_mem_mm_bus_wr(6, c_bsn_init,                clk, reg_bg_ctrl_mosi);  -- Set the BSNInit low  value
107
    proc_mem_mm_bus_wr(7, 0,                         clk, reg_bg_ctrl_mosi);  -- Set the BSNInit high value
108
    proc_mem_mm_bus_wr(0, 1,                         clk, reg_bg_ctrl_mosi);  -- Enable the BG
109
 
110
    -- Run time
111
    proc_common_wait_some_cycles(clk, 300);
112
 
113
    proc_mem_mm_bus_wr(0, 0, clk, reg_bg_ctrl_mosi);  -- Disable the BG
114
 
115
    -- The end
116
    proc_common_wait_some_cycles(clk, c_nof_points + 20);
117
    tb_end <= '1';
118
    wait;
119
  end process;
120
 
121 5 danv
  u_block_generator : entity astron_diagnostics_lib.mms_diag_block_gen
122 2 danv
  generic map(
123
    g_nof_streams        => 1,
124
    g_buf_dat_w          => c_nof_complex*c_in_dat_w,
125
    g_buf_addr_w         => c_bg_addr_w,              -- Waveform buffer size 2**g_buf_addr_w nof samples
126
    g_file_name_prefix   => c_bg_prefix
127
  )
128
  port map(
129
   -- Clocks and reset
130
    mm_rst           => rst,
131
    mm_clk           => clk,
132
    dp_rst           => rst,
133
    dp_clk           => clk,
134
    en_sync          => '1',
135
    ram_bg_data_mosi => ram_bg_data_mosi,
136
    ram_bg_data_miso => open,
137
    reg_bg_ctrl_mosi => reg_bg_ctrl_mosi,
138
    reg_bg_ctrl_miso => open,
139
    out_siso_arr     => in_siso_arr,
140
    out_sosi_arr     => in_sosi_arr
141
  );
142
  in_siso_arr(0) <= c_dp_siso_rdy;
143
 
144
  -- device under test
145
  u_dut : entity work.fft_sepa
146
  port map (
147
    clk      => clk,
148
    rst      => rst,
149
    in_dat   => in_dat,
150
    in_val   => in_sosi_arr(0).valid,
151
    out_dat  => out_dat,
152
    out_val  => out_val
153
  );
154
 
155
  in_dat <= in_sosi_arr(0).im(c_in_dat_w-1 downto 0) & in_sosi_arr(0).re(c_in_dat_w-1 downto 0);
156
  out_dat_re <= out_dat(c_in_dat_w-1 downto 0);
157
  out_dat_im <= out_dat(2*c_in_dat_w-1 downto c_in_dat_w);
158
  out_sosi.re(c_in_dat_w-1 downto 0) <= out_dat(c_in_dat_w-1 downto 0);
159
  out_sosi.im(c_in_dat_w-1 downto 0) <= out_dat(2*c_in_dat_w-1 downto c_in_dat_w);
160
 
161
  -- verification
162
  p_verify : process
163
    variable I : integer;
164
    variable v_buf_output_a_re : t_input_buf_arr(c_nof_points/2-1 downto 0);
165
    variable v_buf_output_a_im : t_input_buf_arr(c_nof_points/2-1 downto 0);
166
    variable v_buf_output_b_re : t_input_buf_arr(c_nof_points/2-1 downto 0);
167
    variable v_buf_output_b_im : t_input_buf_arr(c_nof_points/2-1 downto 0);
168
 
169
  begin
170
    I := 0;
171
    wait until in_sosi_arr(0).sync = '1';
172
    while I < c_nof_points loop
173
      wait until (rising_edge(clk) and in_sosi_arr(0).valid = '1');
174
      buf_input_re(I) <= in_sosi_arr(0).re(c_in_dat_w-1 downto 0);
175
      buf_input_im(I) <= in_sosi_arr(0).im(c_in_dat_w-1 downto 0);
176
      I := I + 1;
177
    end loop;
178
    proc_common_wait_some_cycles(clk, 1);
179
    for J in 0 to c_nof_points/2-1 loop
180
      v_buf_output_a_re(J) := ADD_SVEC(buf_input_re(2*J+1), buf_input_re(2*J), c_in_dat_w+1)(c_in_dat_w downto 1);
181
      v_buf_output_a_im(J) := SUB_SVEC(buf_input_im(2*J), buf_input_im(2*J+1), c_in_dat_w+1)(c_in_dat_w downto 1);
182
      v_buf_output_b_re(J) := ADD_SVEC(buf_input_im(2*J+1), buf_input_im(2*J), c_in_dat_w+1)(c_in_dat_w downto 1);
183
      v_buf_output_b_im(J) := SUB_SVEC(buf_input_re(2*J+1), buf_input_re(2*J), c_in_dat_w+1)(c_in_dat_w downto 1);
184
      buf_output_re(2*J)   <= v_buf_output_a_re(J);
185
      buf_output_im(2*J)   <= v_buf_output_a_im(J);
186
      buf_output_re(2*J+1) <= v_buf_output_b_re(J);
187
      buf_output_im(2*J+1) <= v_buf_output_b_im(J);
188
    end loop;
189
    wait;
190
  end process;
191
 
192
  ------------------------------------------------------------------------  
193
  -- Simples process that does the final test.                     
194
  ------------------------------------------------------------------------ 
195
  p_tester : process(rst, clk)
196
    variable I : integer;
197
  begin
198
    if rst='0' then
199
      if rising_edge(clk) and out_val = '1' then
200
        assert buf_output_re(I) = out_dat_re report "Error: wrong RTL result in real path" severity ERROR;
201
        assert buf_output_im(I) = out_dat_im report "Error: wrong RTL result in imag path" severity ERROR;
202
        if(I = c_nof_points - 1 ) then
203
          I := 0;
204
        else
205
          I := I + 1;
206
        end if;
207
      end if;
208
    else
209
      I := 0;
210
    end if;
211
  end process p_tester;
212
 
213
end tb;
214
 
215
 
216
 

powered by: WebSVN 2.1.0

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