2018-04-24 21:28:02 +02:00
|
|
|
library ieee;
|
|
|
|
|
|
|
|
use ieee.std_logic_1164.all;
|
|
|
|
use ieee.std_logic_unsigned.all;
|
|
|
|
use ieee.numeric_std.all;
|
|
|
|
|
2018-04-25 22:55:39 +02:00
|
|
|
entity ram_2port is
|
|
|
|
generic (
|
|
|
|
WIDTH_BITS: integer;
|
|
|
|
DEPTH_BITS: integer
|
|
|
|
);
|
2018-04-24 21:28:02 +02:00
|
|
|
port (
|
|
|
|
clk: in std_logic;
|
|
|
|
we: in std_logic;
|
2018-04-25 22:55:39 +02:00
|
|
|
wa: in std_logic_vector(DEPTH_BITS-1 downto 0);
|
|
|
|
ra: in std_logic_vector(DEPTH_BITS-1 downto 0);
|
|
|
|
di: in std_logic_vector(WIDTH_BITS-1 downto 0);
|
|
|
|
do: out std_logic_vector(WIDTH_BITS-1 downto 0)
|
2018-04-24 21:28:02 +02:00
|
|
|
);
|
2018-04-25 22:55:39 +02:00
|
|
|
end ram_2port;
|
2018-04-24 21:28:02 +02:00
|
|
|
|
2018-04-25 22:55:39 +02:00
|
|
|
architecture syn of ram_2port is
|
|
|
|
type ram_type is array((2**DEPTH_BITS - 1) downto 0) of
|
|
|
|
std_logic_vector(WIDTH_BITS-1 downto 0);
|
2018-04-24 21:28:02 +02:00
|
|
|
signal RAM: ram_type;
|
|
|
|
signal read_a: std_logic_vector(ra'range);
|
|
|
|
begin
|
|
|
|
|
|
|
|
process(clk)
|
|
|
|
begin
|
|
|
|
if rising_edge(clk) then
|
|
|
|
if we = '1' then
|
|
|
|
RAM(to_integer(unsigned(wa))) <= di;
|
|
|
|
end if;
|
|
|
|
|
|
|
|
read_a <= ra;
|
|
|
|
end if;
|
|
|
|
end process;
|
|
|
|
|
|
|
|
do <= RAM(to_integer(unsigned(read_a)));
|
|
|
|
|
|
|
|
end syn;
|