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

Subversion Repositories astron_wb_fft

[/] [astron_wb_fft/] [trunk/] [fft_sepa_wide.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 : pepping at astron.nl: 2012
3
--   Copyright (C) 2009-2011
4
--   ASTRON (Netherlands Institute for Radio Astronomy)
5
--   P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
6
--
7
--   This file is part of the UniBoard software suite.
8
--   The file 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
-- Purpose: The fft_sepa_wide unit performs the separate function on the
23
--          output of a complex wideband fft in order to extract the spectrum
24
--          of the two real inputs A and B. Where A was fed to the real input 
25
--          of the complext wfft and B was fed to the imaginary input.
26
--          
27
--
28
-- Description: The incoming data is stored in a dual paged ram. For each output 
29
--              of the complex wfft a unique dual paged ram is instantiated. Once
30
--              the first page is written, the unit will read the data from the 
31
--              memory. 
32
--              The read process reads the memories in such a way that pairs of 
33
--              data are created that are required to generate the correct outputs. 
34
--              The data pairs are offered to the ZIP units that serialize the pairs. 
35
--              The serialized data is then offered to the separate units that outputs
36
--              the separated data in an interleaved stream: A, B, A, B etc (for both real and imaginary part) 
37
--              The last stage contains pipeline stages that are required for allignment
38
--              and additional pipeling.  
39
--
40
 
41
library ieee, common_pkg_lib, common_counter_lib, common_components_lib, common_ram_lib, common_multiplexer_lib;
42
use IEEE.std_logic_1164.all;
43
use IEEE.numeric_std.all;
44
use common_pkg_lib.common_pkg.all;
45
use work.fft_pkg.all;
46
 
47
entity fft_sepa_wide is
48
  generic (
49
    g_fft      : t_fft   := c_fft  -- generics for the FFT
50
  );
51
  port (
52
    clk        : in  std_logic;
53
    rst        : in  std_logic := '0';
54
    in_re_arr  : in  t_fft_slv_arr(g_fft.wb_factor-1 downto 0);
55
    in_im_arr  : in  t_fft_slv_arr(g_fft.wb_factor-1 downto 0);
56
    in_val     : in  std_logic := '1';
57
    out_re_arr : out t_fft_slv_arr(g_fft.wb_factor-1 downto 0);
58
    out_im_arr : out t_fft_slv_arr(g_fft.wb_factor-1 downto 0);
59
    out_val    : out std_logic
60
  );
61
 
62
end entity fft_sepa_wide;
63
 
64
architecture rtl of fft_sepa_wide is
65
 
66
  constant c_pipeline_output : natural := 0;    -- no need for extra pipeline output, because output is already registered
67
 
68
  constant c_page_size   : natural := g_fft.nof_points/g_fft.wb_factor;    -- Size of the memories
69
  constant c_nof_pages   : natural := 2;                                   -- The number of pages in each ram. 
70
  constant c_dat_w       : natural := c_nof_complex*g_fft.stage_dat_w;     -- Data width for the internal vectors where real and imag are combined. 
71
  constant c_adr_w       : natural := ceil_log2(c_page_size);              -- Address width of the rams
72
  constant c_nof_streams : natural := 2;                                   -- Number of inputstreams for the zip units
73
 
74
  type   t_dat_arr       is array(integer range <> ) of std_logic_vector(c_dat_w-1 downto 0);
75
  type   t_rd_adr_arr    is array(integer range <> ) of std_logic_vector(c_adr_w-1 downto 0);
76
  type   t_zip_in_matrix is array(integer range <> ) of t_slv_64_arr(1 downto 0);             -- Every Zip unit has two inputs. 
77
 
78
  signal next_page       : std_logic;                                    -- Active high signal to force a page-swap in the memories
79
  signal wr_en           : std_logic;                                    -- The write enable signal for the memories
80
  signal wr_adr          : std_logic_vector(c_adr_w-1 downto 0);         -- The write address
81
  signal wr_dat          : t_dat_arr(g_fft.wb_factor-1 downto 0);        -- Array of data to be written to memory
82
 
83
  signal rd_dat_arr      : t_dat_arr(g_fft.wb_factor-1 downto 0);        -- Array of data that is read from memory
84
  signal rd_adr_arr      : t_rd_adr_arr(1 downto 0);                     -- There are two different read addresses. 
85
 
86
  signal zip_in_matrix   : t_zip_in_matrix(g_fft.wb_factor-1 downto 0);  -- Matrix that contains the inputs for zip units
87
  signal zip_in_val      : std_logic_vector(g_fft.wb_factor-1 downto 0); -- Vector that holds the data input valids for the zip units
88
  signal zip_out_dat_arr : t_dat_arr(g_fft.wb_factor-1 downto 0);        -- Array that holds the outputs of all zip units. 
89
  signal zip_out_val     : std_logic_vector(g_fft.wb_factor-1 downto 0); -- Vector that holds the output valids of the zip units
90
 
91
  signal sep_out_dat_arr : t_dat_arr(g_fft.wb_factor-1 downto 0);        -- Array that holds the outputs of the separation blocks
92
  signal sep_out_val_vec : std_logic_vector(g_fft.wb_factor-1 downto 0); -- Vector containing the datavalids from the separation blocks
93
  signal out_dat_arr     : t_dat_arr(g_fft.wb_factor-1 downto 0);        -- Array that holds the ouput values, where real and imag are concatenated 
94
 
95
  type state_type is (s_idle, s_read);
96
  type reg_type   is record
97
    switch      : std_logic;   -- Toggle register used for separate functionalilty
98
    count_up    : natural range 0 to c_page_size; -- An upwards counter for read addressing
99
    count_down  : natural range 0 to c_page_size; -- A downwards counter for read addressing
100
    val_odd     : std_logic;   -- Register that drives the in_valid of the odd zip units
101
    val_even    : std_logic;   -- Register that drives the in_valid of the even zip units
102
    state       : state_type;  -- The state machine. 
103
  end record;
104
 
105
  signal r, rin : reg_type;
106
 
107
begin
108
 
109
  ---------------------------------------------------------------
110
  -- DUAL PAGED RAMS
111
  ---------------------------------------------------------------
112
  -- Prepare the data for the dual paged memory. Real and imaginary part are concatenated into one vector. 
113
  gen_prep_write_data : for I in 0 to g_fft.wb_factor-1 generate
114
    wr_dat(I) <= in_im_arr(I)(g_fft.stage_dat_w-1 downto 0) & in_re_arr(I)(g_fft.stage_dat_w-1 downto 0);
115
  end generate;
116
 
117
  -- Prepare the write control signals for the memories. 
118
  wr_en     <= in_val;
119
  next_page <= '1' when unsigned(wr_adr) = c_page_size-1 and wr_en='1' else '0';
120
 
121
  -- Counter will generate the write address  
122
  u_wr_adr_cnt : entity common_counter_lib.common_counter
123
  generic map(
124
    g_latency   => 1,
125
    g_init      => 0,
126
    g_width     => c_adr_w
127
  )
128
  port map (
129
    rst     => rst,
130
    clk     => clk,
131
    cnt_en  => in_val,
132
    count   => wr_adr
133
  );
134
 
135
  -- Instantiation of the rams. 
136
  gen_dual_paged_rams : for I in g_fft.wb_factor - 1 downto 0 generate
137
    u_buff : entity common_ram_lib.common_paged_ram_r_w
138
    generic map (
139
      g_str             => "use_adr",
140
      g_data_w          => c_dat_w,
141
      g_nof_pages       => c_nof_pages,
142
      g_page_sz         => c_page_size,
143
      g_wr_start_page   => 0,
144
      g_rd_start_page   => 1,
145
      g_rd_latency      => 1
146
    )
147
    port map (
148
      rst          => rst,
149
      clk          => clk,
150
      wr_next_page => next_page,
151
      wr_adr       => wr_adr,
152
      wr_en        => wr_en,
153
      wr_dat       => wr_dat(I),
154
      rd_next_page => next_page,
155
      rd_adr       => rd_adr_arr(I/(g_fft.wb_factor/2)),
156
      rd_en        => '1',
157
      rd_dat       => rd_dat_arr(I),
158
      rd_val       => open
159
    );
160
  end generate;
161
 
162
  -- Compose the read-addresses for the memories. 
163
  -- The first address toggles between the value of count_up and the value of count_up + offset. 
164
  -- The second address toggles between the value of count_down and the value of count_down + offset.  
165
  -- Note that the RESIZE_UVEC function generates the modulo(N) addressing.(The MSB is thrown away).  
166
  rd_adr_arr(0) <= RESIZE_UVEC(TO_UVEC(r.count_up,   c_adr_w+1), c_adr_w) when r.switch = '0' else RESIZE_UVEC(TO_UVEC(r.count_up   + c_page_size/2, c_adr_w+1), c_adr_w);
167
  rd_adr_arr(1) <= RESIZE_UVEC(TO_UVEC(r.count_down, c_adr_w+1), c_adr_w) when r.switch = '0' else RESIZE_UVEC(TO_UVEC(r.count_down + c_page_size/2, c_adr_w+1), c_adr_w);
168
 
169
  ---------------------------------------------------------------
170
  -- ZIP UNITS AND SEPARATORS
171
  ---------------------------------------------------------------
172
  -- Compose the input matrix for the zip units. Each zip unit receives the
173
  -- data of two different memories at the same time in order to allign the data 
174
  -- properly (in serial) for the separation units. Every zip unit receives data 
175
  -- once every two clock cylces. 
176
  gen_compose_zip_matrix : for I in g_fft.wb_factor/2 - 1 downto 0 generate
177
    zip_in_matrix(2*I)(0)  (c_dat_w-1 downto 0) <= rd_dat_arr(I);
178
    zip_in_matrix(2*I)(1)  (c_dat_w-1 downto 0) <= rd_dat_arr((g_fft.wb_factor-I) rem g_fft.wb_factor) when r.count_up = 0 else rd_dat_arr(g_fft.wb_factor-1-I);
179
    zip_in_matrix(2*I+1)(0)(c_dat_w-1 downto 0) <= rd_dat_arr(I);
180
    zip_in_matrix(2*I+1)(1)(c_dat_w-1 downto 0) <= rd_dat_arr(g_fft.wb_factor-1-I);
181
    zip_in_val(2*I)   <= r.val_even;
182
    zip_in_val(2*I+1) <= r.val_odd;
183
  end generate;
184
 
185
  -- The instantiation of the zip units and the separation units. 
186
  -- The output of the zip units is connected to the input of the 
187
  -- adjacent separate unit. 
188
  gen_separators : for I in g_fft.wb_factor - 1 downto 0 generate
189
    u_zipper : entity common_multiplexer_lib.common_zip
190
    generic map (
191
      g_nof_streams => c_nof_streams,
192
      g_dat_w       => c_dat_w
193
    )
194
    port map (
195
      rst        => rst,
196
      clk        => clk,
197
      in_val     => zip_in_val(I),
198
      in_dat_arr => zip_in_matrix(I),
199
      out_val    => zip_out_val(I),
200
      out_dat    => zip_out_dat_arr(I)
201
    );
202
 
203
    u_separate : entity work.fft_sepa
204
    port map (
205
      clk     => clk,
206
      rst     => rst,
207
      in_dat  => zip_out_dat_arr(I),
208
      in_val  => zip_out_val(I),
209
      out_dat => sep_out_dat_arr(I),
210
      out_val => sep_out_val_vec(I)
211
    );
212
  end generate;
213
 
214
  ---------------------------------------------------------------
215
  -- READ MEMORIES PROCESS
216
  ---------------------------------------------------------------
217
  -- This process creates the read addresses for the dual page memories and 
218
  -- the fellow toggle signals. It also controls the starting and stopping 
219
  -- of the data stream. 
220
  comb : process(r, rst, next_page)
221
    variable v : reg_type;
222
  begin
223
 
224
    v := r;
225
 
226
    case r.state is
227
            when s_idle =>
228
        v.switch     := '0';
229
        v.val_odd    := '0';
230
        v.val_even   := '0';
231
        v.count_up   := 0;
232
        v.count_down := c_page_size;
233
        if(next_page = '1') then               -- Check if next page is asserted, meaning first page is written)
234
          v.state    := s_read;
235
        end if;
236
 
237
            when s_read =>
238
        if(r.switch = '0') then                -- Toggle the switch register from 0 to 1
239
          v.switch   := '1';
240
        end if;
241
 
242
        if(r.switch = '1') then                -- Toggle the switch register from 1 to 0
243
          v.switch     := '0';
244
          v.count_up   := r.count_up + 1;      -- Increment the upwards counter 
245
          v.count_down := r.count_down - 1;    -- Decrease the downwards counter
246
        end if;
247
 
248
        if(next_page = '1') then               -- Both counters are reset on page turn. 
249
          v.count_up   := 0;
250
          v.count_down := c_page_size;
251
        elsif(v.count_up = c_page_size/2) then -- Pagereading is done, but there is not yet new data available (Note that the value of variable v is checked here) 
252
          v.state      := s_idle;              -- then go back to idle. 
253
        end if;
254
 
255
        v.val_odd  := r.switch;                -- Assignment of the odd and even markers
256
        v.val_even := not(r.switch);
257
 
258
            when others =>
259
                  v.state := s_idle;
260
 
261
          end case;
262
 
263
    if(rst = '1') then
264
      v.switch     := '0';
265
      v.count_up   := 0;
266
      v.count_down := 0;
267
      v.val_odd    := '0';
268
      v.val_even   := '0';
269
      v.state      := s_idle;
270
    end if;
271
 
272
    rin <= v;
273
 
274
  end process comb;
275
 
276
  regs : process(clk)
277
  begin
278
    if rising_edge(clk) then
279
      r <= rin;
280
    end if;
281
  end process;
282
 
283
  ---------------------------------------------------------------
284
  -- OUTPUT STAGE: ALIGNMENT AND PIPELINE STAGES
285
  ---------------------------------------------------------------
286
  gen_align_and_pipeline_stages : for I in g_fft.wb_factor/2 - 1 downto 0 generate
287
    u_output_pipeline_align : entity common_components_lib.common_pipeline
288
    generic map (
289
      g_pipeline  => c_pipeline_output + 1,                       -- Pipeline + one stage for allignment
290
      g_in_dat_w  => c_dat_w,
291
      g_out_dat_w => c_dat_w
292
    )
293
    port map (
294
      clk     => clk,
295
      in_dat  => sep_out_dat_arr(2*I),
296
      out_dat => out_dat_arr(2*I)
297
    );
298
 
299
    u_output_pipeline : entity common_components_lib.common_pipeline
300
    generic map (
301
      g_pipeline  => c_pipeline_output,                           -- Only pipeline stage
302
      g_in_dat_w  => c_dat_w,
303
      g_out_dat_w => c_dat_w
304
    )
305
    port map (
306
      clk     => clk,
307
      in_dat  => sep_out_dat_arr(2*I+1),
308
      out_dat => out_dat_arr(2*I+1)
309
    );
310
  end generate;
311
 
312
  u_out_val_pipeline : entity common_components_lib.common_pipeline_sl
313
  generic map (
314
    g_pipeline => c_pipeline_output
315
  )
316
  port map (
317
    clk     => clk,
318
    in_dat  => sep_out_val_vec(1),
319
    out_dat => out_val
320
  );
321
 
322
  -- Split the concatenated array into a real and imaginary array for the output
323
  gen_output_arrays : for I in g_fft.wb_factor-1 downto 0 generate
324
    out_re_arr(I) <= resize_fft_svec(out_dat_arr(I)(              g_fft.stage_dat_w-1 downto                 0));
325
    out_im_arr(I) <= resize_fft_svec(out_dat_arr(I)(c_nof_complex*g_fft.stage_dat_w-1 downto g_fft.stage_dat_w));
326
  end generate;
327
 
328
end rtl;
329
 
330
 

powered by: WebSVN 2.1.0

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