-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
--
|
--
|
-- 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.
|
--
|
--
|
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
|
|
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
--
|
--
|
-- Purpose: Combines an array of MM interfaces into a single MM interface.
|
-- Purpose: Combines an array of MM interfaces into a single MM interface.
|
-- Description:
|
-- Description:
|
-- The common_mem_mux unit combines an array of mosi's and miso's to one
|
-- The common_mem_mux unit combines an array of mosi's and miso's to one
|
-- single set of mosi and miso. Should be used to decrease the amount of
|
-- single set of mosi and miso. Should be used to decrease the amount of
|
-- slave memory interfaces to the MM bus.
|
-- slave memory interfaces to the MM bus.
|
--
|
--
|
-- g_rd_latency
|
-- g_rd_latency
|
-- ______________
|
-- ______________
|
-- strip index: | |
|
-- strip index: | |
|
-- mosi.address[h:w] ---+-->| delay line |--\
|
-- mosi.address[h:w] ---+-->| delay line |--\
|
-- | |____________| |
|
-- | |____________| |
|
-- | |
|
-- | |
|
-- selected v |
|
-- selected v |
|
-- mosi -------> mosi_arr.wr[ ]-----------------------------> mosi_arr
|
-- mosi -------> mosi_arr.wr[ ]-----------------------------> mosi_arr
|
-- rd |
|
-- rd |
|
-- selected v
|
-- selected v
|
-- miso <-------------------------------miso_arr[ ]<--------- miso_arr
|
-- miso <-------------------------------miso_arr[ ]<--------- miso_arr
|
--
|
--
|
-- . not selected mosi_arr get mosi but with wr='0', rd='0'
|
-- . not selected mosi_arr get mosi but with wr='0', rd='0'
|
-- . not selected miso_arr are ignored
|
-- . not selected miso_arr are ignored
|
--
|
--
|
-- Use default g_broadcast=FALSE for multiplexed individual MM access to
|
-- Use default g_broadcast=FALSE for multiplexed individual MM access to
|
-- each mosi_arr/miso_arr MM port. When g_broadcast=TRUE then a write
|
-- each mosi_arr/miso_arr MM port. When g_broadcast=TRUE then a write
|
-- access to MM port [0] is passed on to all ports and a read access is
|
-- access to MM port [0] is passed on to all ports and a read access is
|
-- done from MM port [0]. The other ports cannot be read.
|
-- done from MM port [0]. The other ports cannot be read.
|
--
|
--
|
-- Remarks:
|
-- Remarks:
|
-- . In simulation selecting an unused element address will cause a simulation
|
-- . In simulation selecting an unused element address will cause a simulation
|
-- failure. Therefore the element index is only accepted when it is in the
|
-- failure. Therefore the element index is only accepted when it is in the
|
-- g_nof_mosi-1 DOWNTO 0 range.
|
-- g_nof_mosi-1 DOWNTO 0 range.
|
-- . In case multiple common_mem_mux would be used in series, then only the
|
-- . In case multiple common_mem_mux would be used in series, then only the
|
-- top one needs to account for g_rd_latency>0, the rest can use 0.
|
-- top one needs to account for g_rd_latency>0, the rest can use 0.
|
--
|
--
|
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
|
|
|
|
LIBRARY IEEE, common_pkg_lib, common_ram_lib;
|
LIBRARY IEEE, common_pkg_lib, astron_ram_lib;
|
USE IEEE.STD_LOGIC_1164.ALL;
|
USE IEEE.STD_LOGIC_1164.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;
|
|
|
ENTITY common_mem_mux IS
|
ENTITY common_mem_mux IS
|
GENERIC (
|
GENERIC (
|
g_broadcast : BOOLEAN := FALSE;
|
g_broadcast : BOOLEAN := FALSE;
|
g_nof_mosi : POSITIVE := 256; -- Number of memory interfaces in the array.
|
g_nof_mosi : POSITIVE := 256; -- Number of memory interfaces in the array.
|
g_mult_addr_w : POSITIVE := 8; -- Address width of each memory-interface element in the muliplexed array.
|
g_mult_addr_w : POSITIVE := 8; -- Address width of each memory-interface element in the muliplexed array.
|
g_rd_latency : NATURAL := 0
|
g_rd_latency : NATURAL := 0
|
);
|
);
|
PORT (
|
PORT (
|
clk : IN STD_LOGIC := '0'; -- only used when g_rd_latency > 0
|
clk : IN STD_LOGIC := '0'; -- only used when g_rd_latency > 0
|
mosi : IN t_mem_mosi;
|
mosi : IN t_mem_mosi;
|
miso : OUT t_mem_miso;
|
miso : OUT t_mem_miso;
|
mosi_arr : OUT t_mem_mosi_arr(g_nof_mosi - 1 DOWNTO 0);
|
mosi_arr : OUT t_mem_mosi_arr(g_nof_mosi - 1 DOWNTO 0);
|
miso_arr : IN t_mem_miso_arr(g_nof_mosi - 1 DOWNTO 0) := (OTHERS=>c_mem_miso_rst)
|
miso_arr : IN t_mem_miso_arr(g_nof_mosi - 1 DOWNTO 0) := (OTHERS=>c_mem_miso_rst)
|
);
|
);
|
END common_mem_mux;
|
END common_mem_mux;
|
|
|
ARCHITECTURE rtl OF common_mem_mux IS
|
ARCHITECTURE rtl OF common_mem_mux IS
|
|
|
CONSTANT c_index_w : NATURAL := ceil_log2(g_nof_mosi);
|
CONSTANT c_index_w : NATURAL := ceil_log2(g_nof_mosi);
|
CONSTANT c_total_addr_w : NATURAL := c_index_w + g_mult_addr_w;
|
CONSTANT c_total_addr_w : NATURAL := c_index_w + g_mult_addr_w;
|
|
|
SIGNAL index_arr : t_natural_arr(0 TO g_rd_latency);
|
SIGNAL index_arr : t_natural_arr(0 TO g_rd_latency);
|
SIGNAL index_rw : NATURAL; -- read or write access
|
SIGNAL index_rw : NATURAL; -- read or write access
|
SIGNAL index_rd : NATURAL; -- read response
|
SIGNAL index_rd : NATURAL; -- read response
|
|
|
BEGIN
|
BEGIN
|
|
|
gen_single : IF g_broadcast=FALSE AND g_nof_mosi=1 GENERATE
|
gen_single : IF g_broadcast=FALSE AND g_nof_mosi=1 GENERATE
|
mosi_arr(0) <= mosi;
|
mosi_arr(0) <= mosi;
|
miso <= miso_arr(0);
|
miso <= miso_arr(0);
|
END GENERATE;
|
END GENERATE;
|
|
|
gen_multiple : IF g_broadcast=FALSE AND g_nof_mosi>1 GENERATE
|
gen_multiple : IF g_broadcast=FALSE AND g_nof_mosi>1 GENERATE
|
-- The activated element of the array is detected here
|
-- The activated element of the array is detected here
|
index_arr(0) <= TO_UINT(mosi.address(c_total_addr_w-1 DOWNTO g_mult_addr_w));
|
index_arr(0) <= TO_UINT(mosi.address(c_total_addr_w-1 DOWNTO g_mult_addr_w));
|
|
|
-- Pipeline the index of the activated element to account for the read latency
|
-- Pipeline the index of the activated element to account for the read latency
|
p_clk : PROCESS(clk)
|
p_clk : PROCESS(clk)
|
BEGIN
|
BEGIN
|
IF rising_edge(clk) THEN
|
IF rising_edge(clk) THEN
|
index_arr(1 TO g_rd_latency) <= index_arr(0 TO g_rd_latency-1);
|
index_arr(1 TO g_rd_latency) <= index_arr(0 TO g_rd_latency-1);
|
END IF;
|
END IF;
|
END PROCESS;
|
END PROCESS;
|
|
|
index_rw <= index_arr(0);
|
index_rw <= index_arr(0);
|
index_rd <= index_arr(g_rd_latency);
|
index_rd <= index_arr(g_rd_latency);
|
|
|
-- Master access, can be write or read
|
-- Master access, can be write or read
|
p_mosi_arr : PROCESS(mosi, index_rw)
|
p_mosi_arr : PROCESS(mosi, index_rw)
|
BEGIN
|
BEGIN
|
FOR I IN 0 TO g_nof_mosi-1 LOOP
|
FOR I IN 0 TO g_nof_mosi-1 LOOP
|
mosi_arr(I) <= mosi;
|
mosi_arr(I) <= mosi;
|
mosi_arr(I).rd <= '0';
|
mosi_arr(I).rd <= '0';
|
mosi_arr(I).wr <= '0';
|
mosi_arr(I).wr <= '0';
|
IF I = index_rw THEN
|
IF I = index_rw THEN
|
mosi_arr(I).rd <= mosi.rd;
|
mosi_arr(I).rd <= mosi.rd;
|
mosi_arr(I).wr <= mosi.wr;
|
mosi_arr(I).wr <= mosi.wr;
|
END IF;
|
END IF;
|
END LOOP;
|
END LOOP;
|
END PROCESS;
|
END PROCESS;
|
|
|
-- Slave response to read access after g_rd_latency clk cycles
|
-- Slave response to read access after g_rd_latency clk cycles
|
p_miso : PROCESS(miso_arr, index_rd)
|
p_miso : PROCESS(miso_arr, index_rd)
|
BEGIN
|
BEGIN
|
miso <= c_mem_miso_rst;
|
miso <= c_mem_miso_rst;
|
FOR I IN 0 TO g_nof_mosi-1 LOOP
|
FOR I IN 0 TO g_nof_mosi-1 LOOP
|
IF I = index_rd THEN
|
IF I = index_rd THEN
|
miso <= miso_arr(I);
|
miso <= miso_arr(I);
|
END IF;
|
END IF;
|
END LOOP;
|
END LOOP;
|
END PROCESS;
|
END PROCESS;
|
END GENERATE;
|
END GENERATE;
|
|
|
gen_broadcast : IF g_broadcast=TRUE GENERATE
|
gen_broadcast : IF g_broadcast=TRUE GENERATE
|
mosi_arr <= (OTHERS=>mosi); -- broadcast write to all [g_nof_mosi-1:0] MM ports
|
mosi_arr <= (OTHERS=>mosi); -- broadcast write to all [g_nof_mosi-1:0] MM ports
|
miso <= miso_arr(0); -- broadcast read only from MM port [0]
|
miso <= miso_arr(0); -- broadcast read only from MM port [0]
|
END GENERATE;
|
END GENERATE;
|
|
|
END rtl;
|
END rtl;
|
|
|