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 4

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

powered by: WebSVN 2.1.0

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