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

powered by: WebSVN 2.1.0

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