-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
--
|
--
|
-- Copyright 2020
|
-- Copyright 2020
|
-- ASTRON (Netherlands Institute for Radio Astronomy) <http://www.astron.nl/>
|
-- ASTRON (Netherlands Institute for Radio Astronomy) <http://www.astron.nl/>
|
-- P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
|
-- P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
|
--
|
--
|
-- Licensed under the Apache License, Version 2.0 (the "License");
|
-- Licensed under the Apache License, Version 2.0 (the "License");
|
-- you may not use this file except in compliance with the License.
|
-- you may not use this file except in compliance with the License.
|
-- You may obtain a copy of the License at
|
-- You may obtain a copy of the License at
|
--
|
--
|
-- http://www.apache.org/licenses/LICENSE-2.0
|
-- http://www.apache.org/licenses/LICENSE-2.0
|
--
|
--
|
-- Unless required by applicable law or agreed to in writing, software
|
-- Unless required by applicable law or agreed to in writing, software
|
-- distributed under the License is distributed on an "AS IS" BASIS,
|
-- distributed under the License is distributed on an "AS IS" BASIS,
|
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
-- See the License for the specific language governing permissions and
|
-- See the License for the specific language governing permissions and
|
-- limitations under the License.
|
-- limitations under the License.
|
--
|
--
|
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
|
|
LIBRARY IEEE, common_pkg_lib, common_components_lib, common_ram_lib;
|
LIBRARY IEEE, common_pkg_lib, common_components_lib, astron_ram_lib;
|
USE IEEE.STD_LOGIC_1164.ALL;
|
USE IEEE.STD_LOGIC_1164.ALL;
|
USE IEEE.numeric_std.ALL;
|
USE IEEE.numeric_std.ALL;
|
USE common_pkg_lib.common_pkg.ALL;
|
USE common_pkg_lib.common_pkg.ALL;
|
USE common_ram_lib.common_ram_pkg.ALL;
|
USE astron_ram_lib.common_ram_pkg.ALL;
|
|
|
-- Derived from LOFAR cfg_single_reg
|
-- Derived from LOFAR cfg_single_reg
|
|
|
-- Purpose: Provide a MM interface to a register vector
|
-- Purpose: Provide a MM interface to a register vector
|
--
|
--
|
-- Description:
|
-- Description:
|
-- The register has g_reg.nof_dat words and each word is g_reg.dat_w bits
|
-- The register has g_reg.nof_dat words and each word is g_reg.dat_w bits
|
-- wide. At the control side the register is accessed per word using the
|
-- wide. At the control side the register is accessed per word using the
|
-- address input wr_adr or rd_adr as index. At the data side the whole
|
-- address input wr_adr or rd_adr as index. At the data side the whole
|
-- register of g_reg.dat_w*g_reg.nof_dat bits is available at once. This is
|
-- register of g_reg.dat_w*g_reg.nof_dat bits is available at once. This is
|
-- the key difference with using a RAM.
|
-- the key difference with using a RAM.
|
-- E.g. for g_reg.nof_dat = 3 and g_reg.dat_w = 32 the addressing accesses
|
-- E.g. for g_reg.nof_dat = 3 and g_reg.dat_w = 32 the addressing accesses
|
-- the register bits as follows:
|
-- the register bits as follows:
|
-- wr_adr[1:0], rd_adr[1:0] = 0 --> reg[31:0]
|
-- wr_adr[1:0], rd_adr[1:0] = 0 --> reg[31:0]
|
-- wr_adr[1:0], rd_adr[1:0] = 1 --> reg[63:32]
|
-- wr_adr[1:0], rd_adr[1:0] = 1 --> reg[63:32]
|
-- wr_adr[1:0], rd_adr[1:0] = 2 --> reg[95:64]
|
-- wr_adr[1:0], rd_adr[1:0] = 2 --> reg[95:64]
|
-- E.g. for wr_adr = 0 and wr_en = '1': out_reg[31:0] = wr_dat[31:0]
|
-- E.g. for wr_adr = 0 and wr_en = '1': out_reg[31:0] = wr_dat[31:0]
|
-- E.g. for rd_adr = 0 and rd_en = '1': rd_dat[31:0] = in_reg[31:0]
|
-- E.g. for rd_adr = 0 and rd_en = '1': rd_dat[31:0] = in_reg[31:0]
|
--
|
--
|
-- The word in the register that got accessed is reported via reg_wr_arr
|
-- The word in the register that got accessed is reported via reg_wr_arr
|
-- or via reg_rd_arr depended on whether it was a write access or an read
|
-- or via reg_rd_arr depended on whether it was a write access or an read
|
-- access.
|
-- access.
|
--
|
--
|
-- Usage:
|
-- Usage:
|
-- 1) Connect out_reg to in_reg for write and readback register.
|
-- 1) Connect out_reg to in_reg for write and readback register.
|
-- 2) Do not connect out_reg to in_reg for seperate write only register and
|
-- 2) Do not connect out_reg to in_reg for seperate write only register and
|
-- read only register at the same address.
|
-- read only register at the same address.
|
-- 3) Leave out_reg OPEN for read only register.
|
-- 3) Leave out_reg OPEN for read only register.
|
-- 4) Connect wr_adr and rd_adr to have a shared address bus register.
|
-- 4) Connect wr_adr and rd_adr to have a shared address bus register.
|
|
|
ENTITY common_reg_r_w IS
|
ENTITY common_reg_r_w IS
|
GENERIC (
|
GENERIC (
|
g_reg : t_c_mem := c_mem_reg;
|
g_reg : t_c_mem := c_mem_reg;
|
g_init_reg : STD_LOGIC_VECTOR(c_mem_reg_init_w-1 DOWNTO 0) := (OTHERS => '0')
|
g_init_reg : STD_LOGIC_VECTOR(c_mem_reg_init_w-1 DOWNTO 0) := (OTHERS => '0')
|
);
|
);
|
PORT (
|
PORT (
|
rst : IN STD_LOGIC := '0';
|
rst : IN STD_LOGIC := '0';
|
clk : IN STD_LOGIC;
|
clk : IN STD_LOGIC;
|
clken : IN STD_LOGIC := '1';
|
clken : IN STD_LOGIC := '1';
|
-- control side
|
-- control side
|
wr_en : IN STD_LOGIC;
|
wr_en : IN STD_LOGIC;
|
wr_adr : IN STD_LOGIC_VECTOR(g_reg.adr_w-1 DOWNTO 0);
|
wr_adr : IN STD_LOGIC_VECTOR(g_reg.adr_w-1 DOWNTO 0);
|
wr_dat : IN STD_LOGIC_VECTOR(g_reg.dat_w-1 DOWNTO 0);
|
wr_dat : IN STD_LOGIC_VECTOR(g_reg.dat_w-1 DOWNTO 0);
|
rd_en : IN STD_LOGIC;
|
rd_en : IN STD_LOGIC;
|
rd_adr : IN STD_LOGIC_VECTOR(g_reg.adr_w-1 DOWNTO 0);
|
rd_adr : IN STD_LOGIC_VECTOR(g_reg.adr_w-1 DOWNTO 0);
|
rd_dat : OUT STD_LOGIC_VECTOR(g_reg.dat_w-1 DOWNTO 0);
|
rd_dat : OUT STD_LOGIC_VECTOR(g_reg.dat_w-1 DOWNTO 0);
|
rd_val : OUT STD_LOGIC;
|
rd_val : OUT STD_LOGIC;
|
-- data side
|
-- data side
|
reg_wr_arr : OUT STD_LOGIC_VECTOR( g_reg.nof_dat-1 DOWNTO 0);
|
reg_wr_arr : OUT STD_LOGIC_VECTOR( g_reg.nof_dat-1 DOWNTO 0);
|
reg_rd_arr : OUT STD_LOGIC_VECTOR( g_reg.nof_dat-1 DOWNTO 0);
|
reg_rd_arr : OUT STD_LOGIC_VECTOR( g_reg.nof_dat-1 DOWNTO 0);
|
out_reg : OUT STD_LOGIC_VECTOR(g_reg.dat_w*g_reg.nof_dat-1 DOWNTO 0);
|
out_reg : OUT STD_LOGIC_VECTOR(g_reg.dat_w*g_reg.nof_dat-1 DOWNTO 0);
|
in_reg : IN STD_LOGIC_VECTOR(g_reg.dat_w*g_reg.nof_dat-1 DOWNTO 0)
|
in_reg : IN STD_LOGIC_VECTOR(g_reg.dat_w*g_reg.nof_dat-1 DOWNTO 0)
|
);
|
);
|
END common_reg_r_w;
|
END common_reg_r_w;
|
|
|
|
|
ARCHITECTURE rtl OF common_reg_r_w IS
|
ARCHITECTURE rtl OF common_reg_r_w IS
|
|
|
CONSTANT c_rd_latency : NATURAL := 1;
|
CONSTANT c_rd_latency : NATURAL := 1;
|
CONSTANT c_pipeline : NATURAL := g_reg.latency - c_rd_latency;
|
CONSTANT c_pipeline : NATURAL := g_reg.latency - c_rd_latency;
|
CONSTANT c_pipe_dat_w : NATURAL := 1 + g_reg.dat_w; -- pipeline rd_val & rd_dat together
|
CONSTANT c_pipe_dat_w : NATURAL := 1 + g_reg.dat_w; -- pipeline rd_val & rd_dat together
|
|
|
SIGNAL pipe_dat_in : STD_LOGIC_VECTOR(c_pipe_dat_w-1 DOWNTO 0);
|
SIGNAL pipe_dat_in : STD_LOGIC_VECTOR(c_pipe_dat_w-1 DOWNTO 0);
|
SIGNAL pipe_dat_out : STD_LOGIC_VECTOR(c_pipe_dat_w-1 DOWNTO 0);
|
SIGNAL pipe_dat_out : STD_LOGIC_VECTOR(c_pipe_dat_w-1 DOWNTO 0);
|
|
|
SIGNAL nxt_reg_wr_arr : STD_LOGIC_VECTOR(reg_wr_arr'RANGE);
|
SIGNAL nxt_reg_wr_arr : STD_LOGIC_VECTOR(reg_wr_arr'RANGE);
|
SIGNAL nxt_reg_rd_arr : STD_LOGIC_VECTOR(reg_rd_arr'RANGE);
|
SIGNAL nxt_reg_rd_arr : STD_LOGIC_VECTOR(reg_rd_arr'RANGE);
|
|
|
SIGNAL i_out_reg : STD_LOGIC_VECTOR(out_reg'RANGE);
|
SIGNAL i_out_reg : STD_LOGIC_VECTOR(out_reg'RANGE);
|
SIGNAL nxt_out_reg : STD_LOGIC_VECTOR(out_reg'RANGE);
|
SIGNAL nxt_out_reg : STD_LOGIC_VECTOR(out_reg'RANGE);
|
|
|
SIGNAL int_rd_dat : STD_LOGIC_VECTOR(rd_dat'RANGE);
|
SIGNAL int_rd_dat : STD_LOGIC_VECTOR(rd_dat'RANGE);
|
SIGNAL int_rd_val : STD_LOGIC;
|
SIGNAL int_rd_val : STD_LOGIC;
|
SIGNAL nxt_rd_dat : STD_LOGIC_VECTOR(rd_dat'RANGE);
|
SIGNAL nxt_rd_dat : STD_LOGIC_VECTOR(rd_dat'RANGE);
|
SIGNAL nxt_rd_val : STD_LOGIC;
|
SIGNAL nxt_rd_val : STD_LOGIC;
|
|
|
BEGIN
|
BEGIN
|
|
|
out_reg <= i_out_reg;
|
out_reg <= i_out_reg;
|
|
|
-- Pipeline to support read data latency > 1
|
-- Pipeline to support read data latency > 1
|
u_pipe_rd : ENTITY common_components_lib.common_pipeline
|
u_pipe_rd : ENTITY common_components_lib.common_pipeline
|
GENERIC MAP (
|
GENERIC MAP (
|
g_pipeline => c_pipeline,
|
g_pipeline => c_pipeline,
|
g_in_dat_w => c_pipe_dat_w,
|
g_in_dat_w => c_pipe_dat_w,
|
g_out_dat_w => c_pipe_dat_w
|
g_out_dat_w => c_pipe_dat_w
|
)
|
)
|
PORT MAP (
|
PORT MAP (
|
clk => clk,
|
clk => clk,
|
clken => clken,
|
clken => clken,
|
in_dat => pipe_dat_in,
|
in_dat => pipe_dat_in,
|
out_dat => pipe_dat_out
|
out_dat => pipe_dat_out
|
);
|
);
|
|
|
pipe_dat_in <= int_rd_val & int_rd_dat;
|
pipe_dat_in <= int_rd_val & int_rd_dat;
|
|
|
rd_dat <= pipe_dat_out(pipe_dat_out'HIGH-1 DOWNTO 0);
|
rd_dat <= pipe_dat_out(pipe_dat_out'HIGH-1 DOWNTO 0);
|
rd_val <= pipe_dat_out(pipe_dat_out'HIGH);
|
rd_val <= pipe_dat_out(pipe_dat_out'HIGH);
|
|
|
|
|
p_reg : PROCESS (rst, clk)
|
p_reg : PROCESS (rst, clk)
|
BEGIN
|
BEGIN
|
IF rst = '1' THEN
|
IF rst = '1' THEN
|
-- Output signals.
|
-- Output signals.
|
reg_wr_arr <= (OTHERS => '0');
|
reg_wr_arr <= (OTHERS => '0');
|
reg_rd_arr <= (OTHERS => '0');
|
reg_rd_arr <= (OTHERS => '0');
|
int_rd_val <= '0';
|
int_rd_val <= '0';
|
int_rd_dat <= (OTHERS => '0');
|
int_rd_dat <= (OTHERS => '0');
|
-- Internal signals.
|
-- Internal signals.
|
i_out_reg <= g_init_reg(out_reg'RANGE);
|
i_out_reg <= g_init_reg(out_reg'RANGE);
|
ELSIF rising_edge(clk) THEN
|
ELSIF rising_edge(clk) THEN
|
-- Output signals.
|
-- Output signals.
|
reg_wr_arr <= nxt_reg_wr_arr;
|
reg_wr_arr <= nxt_reg_wr_arr;
|
reg_rd_arr <= nxt_reg_rd_arr;
|
reg_rd_arr <= nxt_reg_rd_arr;
|
int_rd_val <= nxt_rd_val;
|
int_rd_val <= nxt_rd_val;
|
int_rd_dat <= nxt_rd_dat;
|
int_rd_dat <= nxt_rd_dat;
|
-- Internal signals.
|
-- Internal signals.
|
i_out_reg <= nxt_out_reg;
|
i_out_reg <= nxt_out_reg;
|
END IF;
|
END IF;
|
END PROCESS;
|
END PROCESS;
|
|
|
|
|
p_control : PROCESS (rd_en, int_rd_dat, rd_adr, in_reg, i_out_reg, wr_adr, wr_en, wr_dat)
|
p_control : PROCESS (rd_en, int_rd_dat, rd_adr, in_reg, i_out_reg, wr_adr, wr_en, wr_dat)
|
BEGIN
|
BEGIN
|
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
|
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
|
|
|
nxt_reg_rd_arr <= (OTHERS=>'0');
|
nxt_reg_rd_arr <= (OTHERS=>'0');
|
nxt_rd_dat <= int_rd_dat;
|
nxt_rd_dat <= int_rd_dat;
|
IF rd_en = '1' THEN
|
IF rd_en = '1' THEN
|
FOR i IN 0 TO g_reg.nof_dat-1 LOOP
|
FOR i IN 0 TO g_reg.nof_dat-1 LOOP
|
IF UNSIGNED(rd_adr) = i THEN
|
IF UNSIGNED(rd_adr) = i THEN
|
nxt_reg_rd_arr(I) <= '1';
|
nxt_reg_rd_arr(I) <= '1';
|
nxt_rd_dat <= in_reg((i+1)*g_reg.dat_w-1 DOWNTO i*g_reg.dat_w);
|
nxt_rd_dat <= in_reg((i+1)*g_reg.dat_w-1 DOWNTO i*g_reg.dat_w);
|
END IF;
|
END IF;
|
END LOOP;
|
END LOOP;
|
END IF;
|
END IF;
|
|
|
nxt_reg_wr_arr <= (OTHERS=>'0');
|
nxt_reg_wr_arr <= (OTHERS=>'0');
|
nxt_out_reg <= i_out_reg;
|
nxt_out_reg <= i_out_reg;
|
IF wr_en = '1' THEN
|
IF wr_en = '1' THEN
|
FOR i IN 0 TO g_reg.nof_dat-1 LOOP
|
FOR i IN 0 TO g_reg.nof_dat-1 LOOP
|
IF UNSIGNED(wr_adr) = i THEN
|
IF UNSIGNED(wr_adr) = i THEN
|
nxt_reg_wr_arr(I) <= '1';
|
nxt_reg_wr_arr(I) <= '1';
|
nxt_out_reg((i+1)*g_reg.dat_w-1 DOWNTO i*g_reg.dat_w) <= wr_dat;
|
nxt_out_reg((i+1)*g_reg.dat_w-1 DOWNTO i*g_reg.dat_w) <= wr_dat;
|
END IF;
|
END IF;
|
END LOOP;
|
END LOOP;
|
END IF;
|
END IF;
|
END PROCESS;
|
END PROCESS;
|
|
|
END rtl;
|
END rtl;
|
|
|