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

Subversion Repositories astron_statistics

[/] [astron_statistics/] [trunk/] [st_ctrl.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;
23
USE IEEE.std_logic_1164.ALL;
24
USE IEEE.numeric_std.ALL;
25
USE common_pkg_lib.common_pkg.ALL;
26
 
27
 
28
ENTITY st_ctrl IS
29
  GENERIC (
30
    g_nof_mux    : NATURAL := 1;
31
    g_nof_stat   : NATURAL := 512;
32
    g_adr_w      : NATURAL := 9;     -- ceil_log2(g_nof_mux*g_nof_stat)
33
    g_dly_rd     : NATURAL := 1;
34
    g_dly_mul    : NATURAL := 4;
35
    g_dly_acc    : NATURAL := 2;
36
    g_dly_out    : NATURAL := 2
37
  );
38
  PORT (
39
    rst          : IN  STD_LOGIC;
40
    clk          : IN  STD_LOGIC;
41
 
42
    in_sync      : IN  STD_LOGIC;
43
    in_val       : IN  STD_LOGIC;
44
 
45
    rd_en        : OUT STD_LOGIC;
46
    rd_adr       : OUT STD_LOGIC_VECTOR(g_adr_w-1 DOWNTO 0);
47
    rd_val       : OUT STD_LOGIC;
48
 
49
    mult_val     : OUT STD_LOGIC;
50
    acc_load     : OUT STD_LOGIC;
51
 
52
    wr_en        : OUT STD_LOGIC;
53
    wr_adr       : OUT STD_LOGIC_VECTOR(g_adr_w-1 DOWNTO 0);
54
 
55
    out_val      : OUT STD_LOGIC;
56
    out_val_m    : OUT STD_LOGIC_VECTOR(g_nof_mux-1 DOWNTO 0);
57
    out_adr      : OUT STD_LOGIC_VECTOR(g_adr_w-1 DOWNTO 0)
58
  );
59
END;
60
 
61
 
62
ARCHITECTURE rtl OF st_ctrl IS
63
 
64
 CONSTANT c_mux_w     : NATURAL := true_log2(g_nof_mux);
65
 
66
 CONSTANT c_tin_mul   : NATURAL := 0;
67
 CONSTANT c_tot_mul   : NATURAL := c_tin_mul + g_dly_mul;
68
 
69
 CONSTANT c_tin_acc   : NATURAL := c_tot_mul;
70
 CONSTANT c_tot_acc   : NATURAL := c_tin_acc + g_dly_acc;
71
 
72
 CONSTANT c_tin_wr    : NATURAL := c_tot_acc;
73
 
74
 CONSTANT c_tin_rd    : NATURAL := c_tin_acc - g_dly_rd;
75
 CONSTANT c_tot_rd    : NATURAL := c_tin_acc;
76
 
77
 CONSTANT c_tin_out   : NATURAL := c_tot_rd;
78
 CONSTANT c_tot_out   : NATURAL := c_tin_out + g_dly_out;
79
 
80
 SIGNAL dly_val       : STD_LOGIC_VECTOR(0 TO c_tin_wr);
81
 SIGNAL dly_sync      : STD_LOGIC_VECTOR(0 TO c_tin_wr);
82
 SIGNAL dly_load      : STD_LOGIC_VECTOR(c_tin_rd TO c_tin_wr);
83
 
84
 SIGNAL i_rd_adr      : STD_LOGIC_VECTOR(rd_adr'RANGE);
85
 SIGNAL nxt_rd_adr    : STD_LOGIC_VECTOR(rd_adr'RANGE);
86
 
87
 SIGNAL i_wr_adr      : STD_LOGIC_VECTOR(wr_adr'RANGE);
88
 SIGNAL nxt_wr_adr    : STD_LOGIC_VECTOR(wr_adr'RANGE);
89
 
90
 SIGNAL i_out_adr     : STD_LOGIC_VECTOR(out_adr'RANGE);
91
 SIGNAL nxt_out_adr   : STD_LOGIC_VECTOR(out_adr'RANGE);
92
 
93
 SIGNAL i_out_val     : STD_LOGIC;
94
 
95
 SIGNAL nxt_load      : STD_LOGIC;
96
 
97
BEGIN
98
 
99
  -- hardwired
100
 
101
  dly_val (0) <= in_val;
102
  dly_sync(0) <= in_sync;
103
 
104
  rd_en    <= dly_val (c_tin_rd);
105
  rd_val   <= dly_val (c_tot_rd);
106
 
107
  mult_val <= dly_val(c_tin_acc);
108
  acc_load <= dly_load(c_tin_acc) OR (NOT dly_val(c_tin_acc));
109
 
110
  wr_en     <= dly_val(c_tin_wr);
111
  i_out_val <= dly_load(c_tot_out) AND dly_val(c_tot_out);
112
 
113
  rd_adr   <= i_rd_adr;
114
  wr_adr   <= i_wr_adr;
115
  out_adr  <= i_out_adr;
116
  out_val  <= i_out_val;
117
 
118
  no_mux : IF g_nof_mux = 1 GENERATE
119
    out_val_m <= (OTHERS => 'X');
120
  END GENERATE;
121
 
122
  gen_mux : IF g_nof_mux > 1 GENERATE
123
    p_out_val_m: PROCESS (i_out_val, i_out_adr)
124
    BEGIN
125
      out_val_m <= (OTHERS => '0');
126
      FOR i IN 0 TO g_nof_mux-1 LOOP
127
        IF UNSIGNED(i_out_adr(c_mux_w-1 DOWNTO 0)) = i THEN
128
          out_val_m(i) <= i_out_val;
129
        END IF;
130
      END LOOP;
131
    END PROCESS;
132
  END GENERATE;
133
 
134
  -- registers
135
  regs: PROCESS(rst,clk)
136
  BEGIN
137
    IF rst='1' THEN
138
      i_rd_adr  <= (OTHERS => '0');
139
      i_wr_adr  <= (OTHERS => '0');
140
      i_out_adr <= (OTHERS => '0');
141
      dly_load  <= (OTHERS => '1');
142
      dly_val (dly_val 'LOW+1 TO dly_val 'HIGH)  <= (OTHERS => '0');
143
      dly_sync(dly_sync'LOW+1 TO dly_sync'HIGH)  <= (OTHERS => '0');
144
    ELSIF rising_edge(clk) THEN
145
      i_rd_adr  <= nxt_rd_adr;
146
      i_wr_adr  <= nxt_wr_adr;
147
      i_out_adr <= nxt_out_adr;
148
      dly_load  <= nxt_load & dly_load(dly_load'LOW TO dly_load'HIGH-1);
149
      dly_val (dly_val 'LOW+1 TO dly_val 'HIGH) <= dly_val  (dly_val 'LOW to dly_val 'HIGH-1);
150
      dly_sync(dly_sync'LOW+1 TO dly_sync'HIGH) <= dly_sync (dly_sync'LOW to dly_sync'HIGH-1);
151
    END IF;
152
  END PROCESS;
153
 
154
  rd_ctrl: PROCESS(i_rd_adr, dly_load, dly_val, dly_sync)
155
  BEGIN
156
    nxt_load   <= dly_load(dly_load'LOW);
157
    nxt_rd_adr <= i_rd_adr;
158
    IF dly_sync(c_tin_rd)='1' THEN
159
      nxt_rd_adr <= (OTHERS => '0');
160
      nxt_load   <= '1';
161
    ELSIF dly_val(c_tin_rd)='1' THEN
162
      IF UNSIGNED(i_rd_adr)=g_nof_mux*g_nof_stat-1 THEN
163
        nxt_rd_adr <= (OTHERS => '0');
164
        nxt_load   <= '0';
165
      ELSE
166
        nxt_rd_adr <= STD_LOGIC_VECTOR(UNSIGNED(i_rd_adr)+1);
167
      END IF;
168
    END IF;
169
  END PROCESS;
170
 
171
  out_ctrl: PROCESS(i_out_adr, dly_val, dly_sync)
172
  BEGIN
173
    nxt_out_adr   <= i_out_adr;
174
    IF dly_sync(c_tot_out)='1' THEN
175
      nxt_out_adr <= (OTHERS => '0');
176
    ELSIF dly_val(c_tot_out)='1' THEN
177
      IF UNSIGNED(i_out_adr)=g_nof_mux*g_nof_stat-1 THEN
178
        nxt_out_adr <= (OTHERS => '0');
179
      ELSE
180
        nxt_out_adr <= STD_LOGIC_VECTOR(UNSIGNED(i_out_adr)+1);
181
      END IF;
182
    END IF;
183
  END PROCESS;
184
 
185
  wr_ctrl: PROCESS(i_wr_adr,dly_val,dly_sync)
186
  BEGIN
187
    nxt_wr_adr   <= i_wr_adr;
188
    IF dly_sync(c_tin_wr)='1' THEN
189
      nxt_wr_adr <= (OTHERS => '0');
190
    ELSIF dly_val(c_tin_wr)='1' THEN
191
      IF UNSIGNED(i_wr_adr)=g_nof_mux*g_nof_stat-1 THEN
192
        nxt_wr_adr <= (OTHERS => '0');
193
      ELSE
194
        nxt_wr_adr <= STD_LOGIC_VECTOR(UNSIGNED(i_wr_adr)+1);
195
      END IF;
196
    END IF;
197
  END PROCESS;
198
 
199
END rtl;

powered by: WebSVN 2.1.0

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