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

Subversion Repositories astron_wb_fft

[/] [astron_wb_fft/] [trunk/] [tb_fft_reorder_sepa_pipe.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
-- Author: Harm Jan Pepping : HJP at astron.nl: April 2012
3
--
4
-- Copyright (C) 2011
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: Test bench for fft_reorder_sepa_pipe
24
-- Features:
25
--
26
-- Usage:
27
-- > as 10
28
-- > run -all
29
-- Testbench is selftesting. 
30
-- Run testbench for different values of c_seperate and c_reorder. (Recompile is required) 
31
 
32
library IEEE, common_pkg_lib, dp_pkg_lib, diag_lib, mm_lib, common_ram_lib;
33
use IEEE.std_logic_1164.ALL;
34
use IEEE.numeric_std.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 diag_lib.diag_pkg.ALL;
42
 
43
entity tb_fft_reorder_sepa_pipe is
44
end tb_fft_reorder_sepa_pipe;
45
 
46
architecture tb of tb_fft_reorder_sepa_pipe is
47
 
48
  constant c_clk_period   : time    := 10 ns;
49
  constant c_nof_points   : natural := 16;   -- Number of points should be a power of 2
50
  constant c_in_dat_w     : natural := 16;
51
  constant c_separate     : boolean := true;   -- When true the seperate function is enabled
52
  constant c_reorder      : boolean := true;   -- When enabled the reordering is performed
53
  constant c_nof_chan     : natural := 1;
54
  constant c_nof_channels : natural := 2**c_nof_chan;
55
 
56
  type t_input_buf_arr is array (integer range <>) of std_logic_vector(c_in_dat_w-1 downto 0);
57
 
58
  -- BG derived constants
59
  constant c_bg_mem_size           : natural := 1024;
60
  constant c_bg_addr_w             : natural := ceil_log2(c_bg_mem_size);
61
  constant c_nof_samples_in_packet : natural := c_nof_channels*c_nof_points;
62
  constant c_gap                   : natural := 0;    -- Gapsize is set to 0 in order to generate a continuous stream of packets. 
63
  constant c_bst_skip_nof_sync     : natural := 3;
64
  constant c_nof_accum_per_sync    : natural := 10;
65
  constant c_bsn_init              : natural := 32;
66
  constant c_bg_prefix             : string := "data/to_separate";
67
 
68
  signal tb_end    : std_logic := '0';
69
  signal rst       : std_logic;
70
  signal clk       : std_logic := '1';
71
 
72
  signal ram_bg_data_mosi : t_mem_mosi;
73
  signal reg_bg_ctrl_mosi : t_mem_mosi;
74
  signal in_sosi_arr      : t_dp_sosi_arr(0 downto 0);
75
  signal in_siso_arr      : t_dp_siso_arr(0 downto 0);
76
  signal out_sosi         : t_dp_sosi;
77
  signal in_dat           : std_logic_vector(2*c_in_dat_w-1 downto 0);
78
  signal out_dat          : std_logic_vector(2*c_in_dat_w-1 downto 0);
79
  signal out_dat_re       : std_logic_vector(c_in_dat_w-1 downto 0);
80
  signal out_dat_im       : std_logic_vector(c_in_dat_w-1 downto 0);
81
  signal out_val          : std_logic;
82
 
83
  signal buf_input_re     : t_input_buf_arr(c_nof_channels*c_nof_points-1 downto 0);
84
  signal buf_input_im     : t_input_buf_arr(c_nof_channels*c_nof_points-1 downto 0);
85
  signal buf_output_a_re  : t_input_buf_arr(c_nof_channels*c_nof_points/2-1 downto 0);
86
  signal buf_output_a_im  : t_input_buf_arr(c_nof_channels*c_nof_points/2-1 downto 0);
87
  signal buf_output_b_re  : t_input_buf_arr(c_nof_channels*c_nof_points/2-1 downto 0);
88
  signal buf_output_b_im  : t_input_buf_arr(c_nof_channels*c_nof_points/2-1 downto 0);
89
  signal buf_output_re    : t_input_buf_arr(c_nof_channels*c_nof_points-1 downto 0);
90
  signal buf_output_im    : t_input_buf_arr(c_nof_channels*c_nof_points-1 downto 0);
91
 
92
BEGIN
93
 
94
  clk <= (not clk) or tb_end after c_clk_period/2;
95
  rst <= '1', '0' after c_clk_period*3;
96
 
97
  p_control_input_stream : process
98
  begin
99
    tb_end <= '0';
100
    reg_bg_ctrl_mosi <= c_mem_mosi_rst;
101
 
102
    -- Wait until reset is done
103
    proc_common_wait_until_high(clk, rst);
104
    proc_common_wait_some_cycles(clk, 10);
105
 
106
    -- Set and enable the waveform generators. All generators are controlled by the same registers
107
    proc_mem_mm_bus_wr(1, c_nof_samples_in_packet,   clk, reg_bg_ctrl_mosi);  -- Set the number of samples per block
108
    proc_mem_mm_bus_wr(2, c_nof_accum_per_sync,      clk, reg_bg_ctrl_mosi);  -- Set the number of blocks per sync
109
    proc_mem_mm_bus_wr(3, c_gap,                     clk, reg_bg_ctrl_mosi);  -- Set the gapsize
110
    proc_mem_mm_bus_wr(4, 0,                         clk, reg_bg_ctrl_mosi);  -- Set the start address of the memory
111
    proc_mem_mm_bus_wr(5, c_nof_samples_in_packet-1, clk, reg_bg_ctrl_mosi);  -- Set the end address of the memory
112
    proc_mem_mm_bus_wr(6, c_bsn_init,                clk, reg_bg_ctrl_mosi);  -- Set the BSNInit low  value
113
    proc_mem_mm_bus_wr(7, 0,                         clk, reg_bg_ctrl_mosi);  -- Set the BSNInit high value
114
    proc_mem_mm_bus_wr(0, 1,                         clk, reg_bg_ctrl_mosi);  -- Enable the BG
115
 
116
    -- Run time
117
    proc_common_wait_some_cycles(clk, 10*c_nof_points);
118
    proc_mem_mm_bus_wr(0, 0, clk, reg_bg_ctrl_mosi);      -- Disable the BG
119
 
120
    -- The end
121
    proc_common_wait_some_cycles(clk, c_nof_points + 20);
122
    tb_end <= '1';
123
    wait;
124
  end process;
125
 
126
  u_block_generator : entity diag_lib.mms_diag_block_gen
127
  generic map(
128
    g_nof_streams        => 1,
129
    g_buf_dat_w          => c_nof_complex*c_in_dat_w,
130
    g_buf_addr_w         => c_bg_addr_w,              -- Waveform buffer size 2**g_buf_addr_w nof samples
131
    g_file_name_prefix   => c_bg_prefix
132
  )
133
  port map(
134
   -- Clocks and reset
135
    mm_rst           => rst,
136
    mm_clk           => clk,
137
    dp_rst           => rst,
138
    dp_clk           => clk,
139
    en_sync          => '1',
140
    ram_bg_data_mosi => ram_bg_data_mosi,
141
    ram_bg_data_miso => open,
142
    reg_bg_ctrl_mosi => reg_bg_ctrl_mosi,
143
    reg_bg_ctrl_miso => open,
144
    out_siso_arr     => in_siso_arr,
145
    out_sosi_arr     => in_sosi_arr
146
  );
147
  in_siso_arr(0) <= c_dp_siso_rdy;
148
 
149
  -- device under test
150
  u_dut : entity work.fft_reorder_sepa_pipe
151
  generic map (
152
    g_separate    => c_separate,
153
    g_nof_points  => c_nof_points,
154
    g_bit_flip    => c_reorder,
155
    g_nof_chan    => c_nof_chan
156
  )
157
  port map (
158
    clk     => clk,
159
    rst     => rst,
160
    in_dat  => in_dat,
161
    in_val  => in_sosi_arr(0).valid,
162
    out_dat => out_dat,
163
    out_val => out_val
164
  );
165
 
166
  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);
167
  out_dat_re <= out_dat(c_in_dat_w-1 downto 0);
168
  out_dat_im <= out_dat(2*c_in_dat_w-1 downto c_in_dat_w);
169
 
170
  -- verification
171
  p_verify : process
172
    variable I : integer;
173
    variable v_buf_input_re_temp : t_input_buf_arr(c_nof_channels*c_nof_points-1   downto 0);
174
    variable v_buf_input_im_temp : t_input_buf_arr(c_nof_channels*c_nof_points-1   downto 0);
175
    variable v_buf_output_a_re   : t_input_buf_arr(c_nof_channels*c_nof_points/2-1 downto 0);
176
    variable v_buf_output_a_im   : t_input_buf_arr(c_nof_channels*c_nof_points/2-1 downto 0);
177
    variable v_buf_output_b_re   : t_input_buf_arr(c_nof_channels*c_nof_points/2-1 downto 0);
178
    variable v_buf_output_b_im   : t_input_buf_arr(c_nof_channels*c_nof_points/2-1 downto 0);
179
  begin
180
    I := 0;
181
    wait until in_sosi_arr(0).sync = '1';
182
    while I < c_nof_channels*c_nof_points loop
183
      wait until (rising_edge(clk) and in_sosi_arr(0).valid = '1');
184
      buf_input_re(I) <= in_sosi_arr(0).re(c_in_dat_w-1 downto 0);  -- The first dataframe is latched in and used as reference
185
      buf_input_im(I) <= in_sosi_arr(0).im(c_in_dat_w-1 downto 0);
186
      I := I + 1;
187
    end loop;
188
    proc_common_wait_some_cycles(clk, 1);
189
    -- Perform re-order function to the reference data if re-ordering is enabled
190
    if(c_reorder=true) then
191
      for H in 0 to c_nof_channels-1 loop
192
        for J in 0 to c_nof_points-1 loop
193
          v_buf_input_re_temp(c_nof_channels*J + H) := buf_input_re(TO_UINT(TO_UVEC(H, c_nof_chan) & FLIP(TO_UVEC(J, ceil_log2(c_nof_points)))));
194
          v_buf_input_im_temp(c_nof_channels*J + H) := buf_input_im(TO_UINT(TO_UVEC(H, c_nof_chan) & FLIP(TO_UVEC(J, ceil_log2(c_nof_points)))));
195
        end loop;
196
      end loop;
197
    else
198
      for H in 0 to c_nof_channels-1 loop
199
        for J in 0 to c_nof_points-1 loop
200
          v_buf_input_re_temp(H*c_nof_points + J) := buf_input_re(c_nof_channels*J + H);
201
          v_buf_input_im_temp(H*c_nof_points + J) := buf_input_im(c_nof_channels*J + H);
202
        end loop;
203
      end loop;
204
    end if;
205
    -- Do the separate function on the reference data if separata is enabled.                            
206
    if(c_separate=true) then
207
      for H in 0 to c_nof_channels-1 loop
208
        for J in 0 to c_nof_points/2-1 loop
209
          if(J = 0) then
210
            v_buf_output_a_re(H*c_nof_points/2 + J) := v_buf_input_re_temp(H*c_nof_points);
211
            v_buf_output_a_im(H*c_nof_points/2 + J) := (others => '0');
212
            v_buf_output_b_re(H*c_nof_points/2 + J) := v_buf_input_im_temp(H*c_nof_points);
213
            v_buf_output_b_im(H*c_nof_points/2 + J) := (others => '0');
214
            buf_output_re(H*c_nof_points)         <= v_buf_output_a_re(H*c_nof_points/2 + J);
215
            buf_output_im(H*c_nof_points)         <= v_buf_output_a_im(H*c_nof_points/2 + J);
216
            buf_output_re(H*c_nof_points + 1)     <= v_buf_output_b_re(H*c_nof_points/2 + J);
217
            buf_output_im(H*c_nof_points + 1)     <= v_buf_output_b_im(H*c_nof_points/2 + J);
218
          else
219
            v_buf_output_a_re(H*c_nof_points/2 + J) := ADD_SVEC(v_buf_input_re_temp(H*c_nof_points + c_nof_points-J), v_buf_input_re_temp(H*c_nof_points + J), c_in_dat_w+1)(c_in_dat_w downto 1);
220
            v_buf_output_a_im(H*c_nof_points/2 + J) := SUB_SVEC(v_buf_input_im_temp(H*c_nof_points + J), v_buf_input_im_temp(H*c_nof_points + c_nof_points-J), c_in_dat_w+1)(c_in_dat_w downto 1);
221
            v_buf_output_b_re(H*c_nof_points/2 + J) := ADD_SVEC(v_buf_input_im_temp(H*c_nof_points + c_nof_points-J), v_buf_input_im_temp(H*c_nof_points + J), c_in_dat_w+1)(c_in_dat_w downto 1);
222
            v_buf_output_b_im(H*c_nof_points/2 + J) := SUB_SVEC(v_buf_input_re_temp(H*c_nof_points + c_nof_points-J), v_buf_input_re_temp(H*c_nof_points + J), c_in_dat_w+1)(c_in_dat_w downto 1);
223
            buf_output_re(H*c_nof_points + 2*J)   <= v_buf_output_a_re(H*c_nof_points/2 + J);
224
            buf_output_im(H*c_nof_points + 2*J)   <= v_buf_output_a_im(H*c_nof_points/2 + J);
225
            buf_output_re(H*c_nof_points + 2*J+1) <= v_buf_output_b_re(H*c_nof_points/2 + J);
226
            buf_output_im(H*c_nof_points + 2*J+1) <= v_buf_output_b_im(H*c_nof_points/2 + J);
227
          end if;
228
        end loop;
229
      end loop;
230
    else
231
      buf_output_re <= v_buf_input_re_temp;
232
      buf_output_im <= v_buf_input_im_temp;
233
    end if;
234
    wait;
235
  end process;
236
 
237
  ------------------------------------------------------------------------  
238
  -- Simple process that does the final test.                     
239
  ------------------------------------------------------------------------ 
240
  p_tester : process(rst, clk)
241
    variable I : integer;
242
  begin
243
    if rst='0' then
244
      if rising_edge(clk) and out_val = '1' then
245
        assert buf_output_re(I) = out_dat_re report "Error: wrong RTL result in real path" severity error;
246
        assert buf_output_im(I) = out_dat_im report "Error: wrong RTL result in imag path" severity error;
247
        if(I = c_nof_channels*c_nof_points - 1 ) then
248
          I := 0;
249
        else
250
          I := I + 1;
251
        end if;
252
      end if;
253
    else
254
      I := 0;
255
    end if;
256
  end process p_tester;
257
 
258
end tb;

powered by: WebSVN 2.1.0

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