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

Subversion Repositories astron_statistics

[/] [astron_statistics/] [trunk/] [st_acc.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_components_lib, common_add_sub_lib;
23
USE IEEE.std_logic_1164.ALL;
24
USE IEEE.numeric_std.ALL;
25
USE common_pkg_lib.common_pkg.ALL;
26
 
27
 
28
-- Purpose:
29
--   Accumulate input data to an accumulator that is stored externally. In this
30
--   way blocks of input samples (e.g. subband products) can be accumulated to
31
--   a set of external accumulators. At the in_load the accumulator input value
32
--   is ignored so that the accumulation restarts with the in_dat.
33
--
34
-- Description:
35
--   if in_load = '1' then
36
--     out_acc = in_dat + 0         -- restart accumulation
37
--   else
38
--     out_acc = in_dat + in_acc    -- accumulate
39
--
40
-- Remarks:
41
-- . in_val propagates to out_val after the pipeline latency but does not 
42
--   affect the sum
43
 
44
ENTITY st_acc IS
45
  GENERIC (
46
    g_dat_w            : NATURAL;
47
    g_acc_w            : NATURAL;  -- g_acc_w >= g_dat_w
48
    g_hold_load        : BOOLEAN := TRUE;
49
    g_pipeline_input   : NATURAL;  -- 0 no input registers, else register input after in_load
50
    g_pipeline_output  : NATURAL   -- pipeline for the adder
51
  );
52
  PORT (
53
    clk         : IN  STD_LOGIC;
54
    clken       : IN  STD_LOGIC := '1';
55
    in_load     : IN  STD_LOGIC;
56
    in_dat      : IN  STD_LOGIC_VECTOR(g_dat_w-1 DOWNTO 0);
57
    in_acc      : IN  STD_LOGIC_VECTOR(g_acc_w-1 DOWNTO 0);
58
    in_val      : IN  STD_LOGIC := '1';
59
    out_acc     : OUT STD_LOGIC_VECTOR(g_acc_w-1 DOWNTO 0);
60
    out_val     : OUT STD_LOGIC
61
  );
62
END st_acc;
63
 
64
 
65
ARCHITECTURE rtl OF st_acc IS
66
 
67
  CONSTANT c_pipeline  : NATURAL := g_pipeline_input + g_pipeline_output;
68
 
69
  -- Input signals
70
  SIGNAL hld_load        : STD_LOGIC := '0';
71
  SIGNAL nxt_hld_load    : STD_LOGIC;
72
  SIGNAL acc_clr        : STD_LOGIC;
73
 
74
  SIGNAL reg_dat        : STD_LOGIC_VECTOR(g_acc_w-1 DOWNTO 0) := (OTHERS=>'0');
75
  SIGNAL nxt_reg_dat    : STD_LOGIC_VECTOR(g_acc_w-1 DOWNTO 0);
76
  SIGNAL reg_acc        : STD_LOGIC_VECTOR(g_acc_w-1 DOWNTO 0) := (OTHERS=>'0');
77
  SIGNAL nxt_reg_acc    : STD_LOGIC_VECTOR(g_acc_w-1 DOWNTO 0);
78
 
79
  -- Pipeline control signals, map to slv to be able to use common_pipeline
80
  SIGNAL in_val_slv     : STD_LOGIC_VECTOR(0 DOWNTO 0);
81
  SIGNAL out_val_slv    : STD_LOGIC_VECTOR(0 DOWNTO 0);
82
 
83
BEGIN
84
 
85
  ASSERT NOT(g_acc_w < g_dat_w)
86
    REPORT "st_acc: output accumulator width must be >= input data width"
87
    SEVERITY FAILURE;
88
 
89
  ------------------------------------------------------------------------------
90
  -- Input load control
91
  ------------------------------------------------------------------------------
92
 
93
  p_clk : PROCESS(clk)
94
  BEGIN
95
    IF rising_edge(clk) THEN
96
      IF clken='1' THEN
97
        hld_load <= nxt_hld_load;
98
      END IF;
99
    END IF;
100
  END PROCESS;
101
 
102
  nxt_hld_load <= in_load WHEN in_val='1' ELSE hld_load;
103
 
104
  -- Hold in_load to save power by avoiding unneccessary out_acc toggling when in_val goes low  
105
  -- . For g_pipeline_input>0 this is fine
106
  -- . For g_pipeline_input=0 this may cause difficulty in achieving timing closure for synthesis
107
  use_in_load : IF g_hold_load = FALSE GENERATE
108
    acc_clr <= in_load;  -- the in_load may already be extended during in_val
109
  END GENERATE;
110
  use_hld_load : IF g_hold_load = TRUE GENERATE
111
    acc_clr <= in_load OR (hld_load AND NOT in_val);
112
  END GENERATE;
113
 
114
  -- Do not use g_pipeline_input of u_adder, to allow registered acc clear if g_pipeline_input=1
115
  nxt_reg_dat <= RESIZE_SVEC(in_dat, g_acc_w);
116
  nxt_reg_acc <= in_acc WHEN acc_clr='0' ELSE (OTHERS=>'0');
117
 
118
  no_input_reg : IF g_pipeline_input=0 GENERATE
119
    reg_dat <= nxt_reg_dat;
120
    reg_acc <= nxt_reg_acc;
121
  END GENERATE;
122
  gen_input_reg : IF g_pipeline_input>0 GENERATE
123
    p_reg : PROCESS(clk)
124
    BEGIN
125
      IF rising_edge(clk) THEN
126
        IF clken='1' THEN
127
          reg_dat <= nxt_reg_dat;
128
          reg_acc <= nxt_reg_acc;
129
        END IF;
130
      END IF;
131
    END PROCESS;
132
  END GENERATE;
133
 
134
 
135
  ------------------------------------------------------------------------------
136
  -- Adder for the external accumulator
137
  ------------------------------------------------------------------------------
138
 
139
  u_adder : ENTITY common_add_sub_lib.common_add_sub
140
  GENERIC MAP (
141
    g_direction       => "ADD",
142
    g_representation  => "SIGNED",  -- not relevant because g_out_dat_w = g_in_dat_w
143
    g_pipeline_input  => 0,
144
    g_pipeline_output => g_pipeline_output,
145
    g_in_dat_w        => g_acc_w,
146
    g_out_dat_w       => g_acc_w
147
  )
148
  PORT MAP (
149
    clk     => clk,
150
    clken   => clken,
151
    in_a    => reg_dat,
152
    in_b    => reg_acc,
153
    result  => out_acc
154
  );
155
 
156
 
157
  ------------------------------------------------------------------------------
158
  -- Parallel output control pipeline
159
  ------------------------------------------------------------------------------
160
 
161
  in_val_slv(0) <= in_val;
162
  out_val       <= out_val_slv(0);
163
 
164
  u_out_val : ENTITY common_components_lib.common_pipeline
165
  GENERIC MAP (
166
    g_representation => "UNSIGNED",
167
    g_pipeline       => c_pipeline,
168
    g_reset_value    => 0,
169
    g_in_dat_w       => 1,
170
    g_out_dat_w      => 1
171
  )
172
  PORT MAP (
173
    clk     => clk,
174
    clken   => clken,
175
    in_dat  => slv(in_val),
176
    out_dat => out_val_slv
177
  );
178
 
179
END rtl;

powered by: WebSVN 2.1.0

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