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

Subversion Repositories astron_statistics

[/] [astron_statistics/] [trunk/] [st_calc.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
--
3
-- Copyright (C) 2010
4
-- ASTRON (Netherlands Institute for Radio Astronomy) <http://www.astron.nl/>
5
-- P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
6
--
7
-- This program is free software: you can redistribute it and/or modify
8
-- it under the terms of the GNU General Public License as published by
9
-- the Free Software Foundation, either version 3 of the License, or
10
-- (at your option) any later version.
11
--
12
-- This program is distributed in the hope that it will be useful,
13
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
14
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
-- GNU General Public License for more details.
16
--
17
-- You should have received a copy of the GNU General Public License
18
-- along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
--
20
-------------------------------------------------------------------------------
21
 
22
LIBRARY IEEE, common_pkg_lib, common_ram_lib, common_mult_lib, technology_lib;
23
USE IEEE.std_logic_1164.ALL;
24
USE technology_lib.technology_select_pkg.ALL;
25
USE common_pkg_lib.common_pkg.ALL;
26
USE common_ram_lib.common_ram_pkg.ALL;
27
 
28
-- Purpose:
29
--   Maintain a set of accumulators and output their values at every in_sync.
30
-- Description:
31
-- . The products of two input streams are accumulated per block. The block
32
--   size is g_nof_mux*g_nof_stat. The nof accumulators is equal to the block
33
--   size. The nof blocks that get accumulated depends on in_sync, because a
34
--   new accumulation starts every time when in_sync pulses. Also when in_sync
35
--   pulses then after some latency the accumulation values of the previous
36
--   in_sync interval become available at the out_* ports.
37
-- . If g_complex = FALSE then only the real power statistic out_re is calculated,
38
--   else also the imaginary power statistic out_im. The real power statistic
39
--   is used for auto power calulations of a complex input, by connecting the
40
--   signal to both input a and b. The imaginary is power statistic is used when
41
--   the cross power needs to be calculated between 2 different complex inputs.
42
-- Remarks:
43
-- . The required accumulator width depends the input data width and the nof of
44
--   block, i.e. the nof accumulations. E.g. for 18b*18b = 36b products and
45
--   200000 accumulations yielding 18b bit growth so in total 36b+18b = 54b for
46
--   the accumulators.
47
-- . The nof accumulators determines the size (c_mem_acc) of the internal
48
--   accumulator memory.
49
-- . Using g_nof_mux>1 allows distinghuising different streams with a block.
50
--   The g_nof_mux does not impact the address range instead it impacts the
51
--   out_val_m strobes that can be used as wr_en to the corresponding statistics
52
--   output register in a range of g_nof_mux statistics output registers.
53
 
54
ENTITY st_calc IS
55
  GENERIC (
56
    g_technology   : NATURAL := c_tech_select_default;
57
    g_nof_mux      : NATURAL := 1;
58
    g_nof_stat     : NATURAL := 512;
59
    g_in_dat_w     : NATURAL := 18;  -- = input data width
60
    g_out_dat_w    : NATURAL := 54;  -- = accumulator width for the input data products, so >> 2*g_in_dat_w
61
    g_out_adr_w    : NATURAL := 9;   -- = ceil_log2(g_nof_stat)
62
    g_complex      : BOOLEAN := FALSE
63
  );
64
  PORT (
65
    rst            : IN   STD_LOGIC;
66
    clk            : IN   STD_LOGIC;
67
    clken          : IN   STD_LOGIC := '1';
68
    in_ar          : IN   STD_LOGIC_VECTOR(g_in_dat_w-1 DOWNTO 0);
69
    in_ai          : IN   STD_LOGIC_VECTOR(g_in_dat_w-1 DOWNTO 0);
70
    in_br          : IN   STD_LOGIC_VECTOR(g_in_dat_w-1 DOWNTO 0);
71
    in_bi          : IN   STD_LOGIC_VECTOR(g_in_dat_w-1 DOWNTO 0);
72
    in_val         : IN   STD_LOGIC;
73
    in_sync        : IN   STD_LOGIC;
74
    out_adr        : OUT  STD_LOGIC_VECTOR(g_out_adr_w-1 DOWNTO 0);
75
    out_re         : OUT  STD_LOGIC_VECTOR(g_out_dat_w-1 DOWNTO 0);
76
    out_im         : OUT  STD_LOGIC_VECTOR(g_out_dat_w-1 DOWNTO 0);
77
    out_val        : OUT  STD_LOGIC;                                -- Use when g_nof_mux = 1, else leave OPEN
78
    out_val_m      : OUT  STD_LOGIC_VECTOR(g_nof_mux-1 DOWNTO 0)    -- Use when g_nof_mux > 1, else leave OPEN
79
  );
80
END;
81
 
82
 
83
ARCHITECTURE str OF st_calc IS
84
 
85
  CONSTANT c_mux_w           : NATURAL := true_log2(g_nof_mux);
86
  CONSTANT c_adr_w           : NATURAL := c_mux_w+g_out_adr_w;   -- = = ceil_log2(g_nof_mux*g_nof_stat)
87
 
88
  CONSTANT c_dly_rd          : NATURAL := 2;
89
  CONSTANT c_dly_mul         : NATURAL := 3;
90
  CONSTANT c_dly_acc         : NATURAL := 2;
91
  CONSTANT c_dly_out         : NATURAL := 0;
92
 
93
  CONSTANT c_mult_w          : NATURAL := 2*g_in_dat_w;
94
 
95
  CONSTANT c_acc_w           : NATURAL := g_out_dat_w;
96
  CONSTANT c_acc_hold_load   : BOOLEAN := TRUE;
97
 
98
  CONSTANT c_rd_latency      : NATURAL := 2;
99
  CONSTANT c_mem_acc         : t_c_mem := (c_rd_latency, c_adr_w,  c_acc_w, g_nof_mux*g_nof_stat, 'X');  -- 1 M9K
100
 
101
 
102
  SIGNAL mult_re       : STD_LOGIC_VECTOR(c_mult_w-1 DOWNTO 0);
103
  SIGNAL mult_im       : STD_LOGIC_VECTOR(c_mult_w-1 DOWNTO 0);
104
 
105
  SIGNAL reg_ar        : STD_LOGIC_VECTOR(in_ar'RANGE);
106
  SIGNAL reg_ai        : STD_LOGIC_VECTOR(in_ai'RANGE);
107
  SIGNAL reg_br        : STD_LOGIC_VECTOR(in_br'RANGE);
108
  SIGNAL reg_bi        : STD_LOGIC_VECTOR(in_bi'RANGE);
109
  SIGNAL reg_val       : STD_LOGIC;
110
  SIGNAL reg_sync      : STD_LOGIC;
111
 
112
  SIGNAL nxt_reg_ar    : STD_LOGIC_VECTOR(in_ar'RANGE);
113
  SIGNAL nxt_reg_ai    : STD_LOGIC_VECTOR(in_ai'RANGE);
114
  SIGNAL nxt_reg_br    : STD_LOGIC_VECTOR(in_br'RANGE);
115
  SIGNAL nxt_reg_bi    : STD_LOGIC_VECTOR(in_bi'RANGE);
116
  SIGNAL nxt_reg_val   : STD_LOGIC;
117
  SIGNAL nxt_reg_sync  : STD_LOGIC;
118
 
119
  SIGNAL acc_load      : STD_LOGIC;
120
 
121
  SIGNAL rd_en         : STD_LOGIC;
122
  SIGNAL rd_adr        : STD_LOGIC_VECTOR(c_adr_w-1 DOWNTO 0);
123
  SIGNAL rd_re         : STD_LOGIC_VECTOR(c_acc_w-1 DOWNTO 0);
124
  SIGNAL rd_im         : STD_LOGIC_VECTOR(c_acc_w-1 DOWNTO 0);
125
 
126
  SIGNAL wr_en         : STD_LOGIC;
127
  SIGNAL wr_adr        : STD_LOGIC_VECTOR(c_adr_w-1 DOWNTO 0);
128
  SIGNAL wr_re         : STD_LOGIC_VECTOR(c_acc_w-1 DOWNTO 0);
129
  SIGNAL wr_im         : STD_LOGIC_VECTOR(c_acc_w-1 DOWNTO 0);
130
 
131
  SIGNAL out_adr_m     : STD_LOGIC_VECTOR(c_adr_w-1 DOWNTO 0);
132
 
133
BEGIN
134
 
135
  regs: PROCESS(rst,clk)
136
  BEGIN
137
    IF rst='1' THEN
138
      reg_ar   <= (OTHERS => '0');
139
      reg_ai   <= (OTHERS => '0');
140
      reg_br   <= (OTHERS => '0');
141
      reg_bi   <= (OTHERS => '0');
142
      reg_val  <= '0';
143
      reg_sync <= '0';
144
    ELSIF rising_edge(clk) THEN
145
      reg_ar   <= nxt_reg_ar;
146
      reg_ai   <= nxt_reg_ai;
147
      reg_br   <= nxt_reg_br;
148
      reg_bi   <= nxt_reg_bi;
149
      reg_val  <= nxt_reg_val;
150
      reg_sync <= nxt_reg_sync;
151
    END IF;
152
  END PROCESS;
153
 
154
  nxt_reg_ar   <= in_ar WHEN in_val='1' ELSE reg_ar;
155
  nxt_reg_ai   <= in_ai WHEN in_val='1' ELSE reg_ai;
156
  nxt_reg_br   <= in_br WHEN in_val='1' ELSE reg_br;
157
  nxt_reg_bi   <= in_bi WHEN in_val='1' ELSE reg_bi;
158
  nxt_reg_val  <= in_val;
159
  nxt_reg_sync <= in_sync;
160
 
161
  -- ctrl block: generates all ctrl signals   
162
  ctrl: ENTITY work.st_ctrl
163
  GENERIC MAP (
164
    g_nof_mux    => g_nof_mux,
165
    g_nof_stat   => g_nof_stat,
166
    g_adr_w      => c_adr_w,
167
    g_dly_rd     => c_dly_rd,
168
    g_dly_mul    => c_dly_mul,
169
    g_dly_acc    => c_dly_acc,
170
    g_dly_out    => c_dly_out
171
  )
172
  PORT MAP (
173
    rst          => rst,
174
    clk          => clk,
175
    in_sync      => reg_sync,
176
    in_val       => reg_val,
177
    rd_en        => rd_en,
178
    rd_adr       => rd_adr,
179
    rd_val       => OPEN,
180
    mult_val     => OPEN,
181
    acc_load     => acc_load,
182
    wr_en        => wr_en,
183
    wr_adr       => wr_adr,
184
    out_val      => out_val,
185
    out_val_m    => out_val_m,
186
    out_adr      => out_adr_m
187
  );
188
 
189
  out_adr <= out_adr_m(c_adr_w-1 DOWNTO c_mux_w);
190
 
191
  -- complex multiplier: computes a * conj(b)
192
  --mul: ENTITY common_lib.common_complex_mult(str)
193
  mul: ENTITY common_mult_lib.common_complex_mult
194
  GENERIC MAP (
195
    g_technology       => g_technology,
196
    g_variant          => "IP",
197
    g_in_a_w           => in_ar'LENGTH,
198
    g_in_b_w           => in_br'LENGTH,
199
    g_out_p_w          => mult_re'LENGTH,
200
    g_conjugate_b      => TRUE,  -- use conjugate product for cross power
201
    g_pipeline_input   => 1,
202
    g_pipeline_product => 0,
203
    g_pipeline_adder   => 1,
204
    g_pipeline_output  => 1   -- 1+0+1+1 = 3 = c_dly_mul
205
  )
206
  PORT MAP (
207
    clk        => clk,
208
    clken      => clken,
209
    in_ar      => reg_ar,
210
    in_ai      => reg_ai,
211
    in_br      => reg_br,
212
    in_bi      => reg_bi,
213
    out_pr     => mult_re,
214
    out_pi     => mult_im
215
  );
216
 
217
  -- accumulator for real part  
218
  acc_re: ENTITY work.st_acc
219
  GENERIC MAP (
220
    g_dat_w           => c_mult_w,
221
    g_acc_w           => c_acc_w,
222
    g_hold_load       => c_acc_hold_load,
223
    g_pipeline_input  => 1,
224
    g_pipeline_output => c_dly_acc-1
225
  )
226
  PORT MAP (
227
    clk         => clk,
228
    clken       => clken,
229
    in_load     => acc_load,
230
    in_dat      => mult_re,
231
    in_acc      => rd_re,
232
    out_acc     => wr_re
233
  );
234
 
235
  -- accumulator memory for real part  
236
  ram_re: ENTITY common_ram_lib.common_ram_r_w
237
  GENERIC MAP (
238
    g_technology => g_technology,
239
    g_ram        => c_mem_acc,
240
    g_init_file  => "UNUSED"
241
  )
242
  PORT MAP (
243
    rst       => rst,
244
    clk       => clk,
245
    clken     => clken,
246
    wr_en     => wr_en,
247
    wr_adr    => wr_adr,
248
    wr_dat    => wr_re,
249
    rd_en     => rd_en,
250
    rd_adr    => rd_adr,
251
    rd_dat    => rd_re,
252
    rd_val    => OPEN
253
  );
254
 
255
  out_re <= rd_re;  -- c_dly_out = 0
256
 
257
  -- imaginary part is optional  
258
  no_im: IF g_complex=FALSE GENERATE
259
    out_im <= (OTHERS => '0');
260
  END GENERATE;
261
 
262
  gen_im: IF g_complex=TRUE GENERATE
263
    -- accumulator
264
    acc_im: ENTITY work.st_acc
265
    GENERIC MAP (
266
      g_dat_w           => c_mult_w,
267
      g_acc_w           => c_acc_w,
268
      g_hold_load       => c_acc_hold_load,
269
      g_pipeline_input  => 1,
270
      g_pipeline_output => c_dly_acc-1
271
    )
272
    PORT MAP (
273
      clk         => clk,
274
      clken       => clken,
275
      in_load     => acc_load,
276
      in_dat      => mult_im,
277
      in_acc      => rd_im,
278
      out_acc     => wr_im
279
    );
280
 
281
    -- dual port memory
282
    ram_im: ENTITY common_ram_lib.common_ram_r_w
283
    GENERIC MAP (
284
      g_technology => g_technology,
285
      g_ram        => c_mem_acc,
286
      g_init_file  => "UNUSED"
287
    )
288
    PORT MAP (
289
      rst       => rst,
290
      clk       => clk,
291
      clken     => clken,
292
      wr_en     => wr_en,
293
      wr_adr    => wr_adr,
294
      wr_dat    => wr_im,
295
      rd_en     => rd_en,
296
      rd_adr    => rd_adr,
297
      rd_dat    => rd_im,
298
      rd_val    => OPEN
299
    );
300
 
301
    out_im <= rd_im;  -- c_dly_out = 0
302
  END GENERATE;
303
 
304
END str;

powered by: WebSVN 2.1.0

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