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 |
4 |
danv |
LIBRARY IEEE, common_pkg_lib, common_components_lib, astron_ram_lib;
|
22 |
2 |
danv |
USE IEEE.STD_LOGIC_1164.ALL;
|
23 |
|
|
USE IEEE.numeric_std.ALL;
|
24 |
|
|
USE common_pkg_lib.common_pkg.ALL;
|
25 |
4 |
danv |
USE astron_ram_lib.common_ram_pkg.ALL;
|
26 |
2 |
danv |
|
27 |
|
|
-- Derived from LOFAR cfg_single_reg
|
28 |
|
|
|
29 |
|
|
-- Purpose: Provide a MM interface to a register vector
|
30 |
|
|
--
|
31 |
|
|
-- Description:
|
32 |
|
|
-- The register has g_reg.nof_dat words and each word is g_reg.dat_w bits
|
33 |
|
|
-- wide. At the control side the register is accessed per word using the
|
34 |
|
|
-- address input wr_adr or rd_adr as index. At the data side the whole
|
35 |
|
|
-- register of g_reg.dat_w*g_reg.nof_dat bits is available at once. This is
|
36 |
|
|
-- the key difference with using a RAM.
|
37 |
|
|
-- E.g. for g_reg.nof_dat = 3 and g_reg.dat_w = 32 the addressing accesses
|
38 |
|
|
-- the register bits as follows:
|
39 |
|
|
-- wr_adr[1:0], rd_adr[1:0] = 0 --> reg[31:0]
|
40 |
|
|
-- wr_adr[1:0], rd_adr[1:0] = 1 --> reg[63:32]
|
41 |
|
|
-- wr_adr[1:0], rd_adr[1:0] = 2 --> reg[95:64]
|
42 |
|
|
-- E.g. for wr_adr = 0 and wr_en = '1': out_reg[31:0] = wr_dat[31:0]
|
43 |
|
|
-- E.g. for rd_adr = 0 and rd_en = '1': rd_dat[31:0] = in_reg[31:0]
|
44 |
|
|
--
|
45 |
|
|
-- The word in the register that got accessed is reported via reg_wr_arr
|
46 |
|
|
-- or via reg_rd_arr depended on whether it was a write access or an read
|
47 |
|
|
-- access.
|
48 |
|
|
--
|
49 |
|
|
-- Usage:
|
50 |
|
|
-- 1) Connect out_reg to in_reg for write and readback register.
|
51 |
|
|
-- 2) Do not connect out_reg to in_reg for seperate write only register and
|
52 |
|
|
-- read only register at the same address.
|
53 |
|
|
-- 3) Leave out_reg OPEN for read only register.
|
54 |
|
|
-- 4) Connect wr_adr and rd_adr to have a shared address bus register.
|
55 |
|
|
|
56 |
|
|
ENTITY common_reg_r_w IS
|
57 |
|
|
GENERIC (
|
58 |
|
|
g_reg : t_c_mem := c_mem_reg;
|
59 |
|
|
g_init_reg : STD_LOGIC_VECTOR(c_mem_reg_init_w-1 DOWNTO 0) := (OTHERS => '0')
|
60 |
|
|
);
|
61 |
|
|
PORT (
|
62 |
|
|
rst : IN STD_LOGIC := '0';
|
63 |
|
|
clk : IN STD_LOGIC;
|
64 |
|
|
clken : IN STD_LOGIC := '1';
|
65 |
|
|
-- control side
|
66 |
|
|
wr_en : IN STD_LOGIC;
|
67 |
|
|
wr_adr : IN STD_LOGIC_VECTOR(g_reg.adr_w-1 DOWNTO 0);
|
68 |
|
|
wr_dat : IN STD_LOGIC_VECTOR(g_reg.dat_w-1 DOWNTO 0);
|
69 |
|
|
rd_en : IN STD_LOGIC;
|
70 |
|
|
rd_adr : IN STD_LOGIC_VECTOR(g_reg.adr_w-1 DOWNTO 0);
|
71 |
|
|
rd_dat : OUT STD_LOGIC_VECTOR(g_reg.dat_w-1 DOWNTO 0);
|
72 |
|
|
rd_val : OUT STD_LOGIC;
|
73 |
|
|
-- data side
|
74 |
|
|
reg_wr_arr : OUT STD_LOGIC_VECTOR( g_reg.nof_dat-1 DOWNTO 0);
|
75 |
|
|
reg_rd_arr : OUT STD_LOGIC_VECTOR( g_reg.nof_dat-1 DOWNTO 0);
|
76 |
|
|
out_reg : OUT STD_LOGIC_VECTOR(g_reg.dat_w*g_reg.nof_dat-1 DOWNTO 0);
|
77 |
|
|
in_reg : IN STD_LOGIC_VECTOR(g_reg.dat_w*g_reg.nof_dat-1 DOWNTO 0)
|
78 |
|
|
);
|
79 |
|
|
END common_reg_r_w;
|
80 |
|
|
|
81 |
|
|
|
82 |
|
|
ARCHITECTURE rtl OF common_reg_r_w IS
|
83 |
|
|
|
84 |
|
|
CONSTANT c_rd_latency : NATURAL := 1;
|
85 |
|
|
CONSTANT c_pipeline : NATURAL := g_reg.latency - c_rd_latency;
|
86 |
|
|
CONSTANT c_pipe_dat_w : NATURAL := 1 + g_reg.dat_w; -- pipeline rd_val & rd_dat together
|
87 |
|
|
|
88 |
|
|
SIGNAL pipe_dat_in : STD_LOGIC_VECTOR(c_pipe_dat_w-1 DOWNTO 0);
|
89 |
|
|
SIGNAL pipe_dat_out : STD_LOGIC_VECTOR(c_pipe_dat_w-1 DOWNTO 0);
|
90 |
|
|
|
91 |
|
|
SIGNAL nxt_reg_wr_arr : STD_LOGIC_VECTOR(reg_wr_arr'RANGE);
|
92 |
|
|
SIGNAL nxt_reg_rd_arr : STD_LOGIC_VECTOR(reg_rd_arr'RANGE);
|
93 |
|
|
|
94 |
|
|
SIGNAL i_out_reg : STD_LOGIC_VECTOR(out_reg'RANGE);
|
95 |
|
|
SIGNAL nxt_out_reg : STD_LOGIC_VECTOR(out_reg'RANGE);
|
96 |
|
|
|
97 |
|
|
SIGNAL int_rd_dat : STD_LOGIC_VECTOR(rd_dat'RANGE);
|
98 |
|
|
SIGNAL int_rd_val : STD_LOGIC;
|
99 |
|
|
SIGNAL nxt_rd_dat : STD_LOGIC_VECTOR(rd_dat'RANGE);
|
100 |
|
|
SIGNAL nxt_rd_val : STD_LOGIC;
|
101 |
|
|
|
102 |
|
|
BEGIN
|
103 |
|
|
|
104 |
|
|
out_reg <= i_out_reg;
|
105 |
|
|
|
106 |
|
|
-- Pipeline to support read data latency > 1
|
107 |
|
|
u_pipe_rd : ENTITY common_components_lib.common_pipeline
|
108 |
|
|
GENERIC MAP (
|
109 |
|
|
g_pipeline => c_pipeline,
|
110 |
|
|
g_in_dat_w => c_pipe_dat_w,
|
111 |
|
|
g_out_dat_w => c_pipe_dat_w
|
112 |
|
|
)
|
113 |
|
|
PORT MAP (
|
114 |
|
|
clk => clk,
|
115 |
|
|
clken => clken,
|
116 |
|
|
in_dat => pipe_dat_in,
|
117 |
|
|
out_dat => pipe_dat_out
|
118 |
|
|
);
|
119 |
|
|
|
120 |
|
|
pipe_dat_in <= int_rd_val & int_rd_dat;
|
121 |
|
|
|
122 |
|
|
rd_dat <= pipe_dat_out(pipe_dat_out'HIGH-1 DOWNTO 0);
|
123 |
|
|
rd_val <= pipe_dat_out(pipe_dat_out'HIGH);
|
124 |
|
|
|
125 |
|
|
|
126 |
|
|
p_reg : PROCESS (rst, clk)
|
127 |
|
|
BEGIN
|
128 |
|
|
IF rst = '1' THEN
|
129 |
|
|
-- Output signals.
|
130 |
|
|
reg_wr_arr <= (OTHERS => '0');
|
131 |
|
|
reg_rd_arr <= (OTHERS => '0');
|
132 |
|
|
int_rd_val <= '0';
|
133 |
|
|
int_rd_dat <= (OTHERS => '0');
|
134 |
|
|
-- Internal signals.
|
135 |
|
|
i_out_reg <= g_init_reg(out_reg'RANGE);
|
136 |
|
|
ELSIF rising_edge(clk) THEN
|
137 |
|
|
-- Output signals.
|
138 |
|
|
reg_wr_arr <= nxt_reg_wr_arr;
|
139 |
|
|
reg_rd_arr <= nxt_reg_rd_arr;
|
140 |
|
|
int_rd_val <= nxt_rd_val;
|
141 |
|
|
int_rd_dat <= nxt_rd_dat;
|
142 |
|
|
-- Internal signals.
|
143 |
|
|
i_out_reg <= nxt_out_reg;
|
144 |
|
|
END IF;
|
145 |
|
|
END PROCESS;
|
146 |
|
|
|
147 |
|
|
|
148 |
|
|
p_control : PROCESS (rd_en, int_rd_dat, rd_adr, in_reg, i_out_reg, wr_adr, wr_en, wr_dat)
|
149 |
|
|
BEGIN
|
150 |
|
|
nxt_rd_val <= rd_en; -- rd_val depends only on rd_en, so for an out of range address the old rd_dat is output
|
151 |
|
|
|
152 |
|
|
nxt_reg_rd_arr <= (OTHERS=>'0');
|
153 |
|
|
nxt_rd_dat <= int_rd_dat;
|
154 |
|
|
IF rd_en = '1' THEN
|
155 |
|
|
FOR i IN 0 TO g_reg.nof_dat-1 LOOP
|
156 |
|
|
IF UNSIGNED(rd_adr) = i THEN
|
157 |
|
|
nxt_reg_rd_arr(I) <= '1';
|
158 |
|
|
nxt_rd_dat <= in_reg((i+1)*g_reg.dat_w-1 DOWNTO i*g_reg.dat_w);
|
159 |
|
|
END IF;
|
160 |
|
|
END LOOP;
|
161 |
|
|
END IF;
|
162 |
|
|
|
163 |
|
|
nxt_reg_wr_arr <= (OTHERS=>'0');
|
164 |
|
|
nxt_out_reg <= i_out_reg;
|
165 |
|
|
IF wr_en = '1' THEN
|
166 |
|
|
FOR i IN 0 TO g_reg.nof_dat-1 LOOP
|
167 |
|
|
IF UNSIGNED(wr_adr) = i THEN
|
168 |
|
|
nxt_reg_wr_arr(I) <= '1';
|
169 |
|
|
nxt_out_reg((i+1)*g_reg.dat_w-1 DOWNTO i*g_reg.dat_w) <= wr_dat;
|
170 |
|
|
END IF;
|
171 |
|
|
END LOOP;
|
172 |
|
|
END IF;
|
173 |
|
|
END PROCESS;
|
174 |
|
|
|
175 |
|
|
END rtl;
|