--
|
--
|
-- Synchronous dual-port RAM with separate clocks for read and write ports.
|
-- Synchronous two-port RAM with separate clocks for read and write ports.
|
-- The synthesizer for Xilinx Spartan-3 will infer Block RAM for this entity.
|
-- The synthesizer for Xilinx Spartan-3 will infer Block RAM for this entity.
|
--
|
--
|
|
|
library ieee;
|
library ieee;
|
use ieee.std_logic_1164.all;
|
use ieee.std_logic_1164.all;
|
use ieee.numeric_std.all;
|
use ieee.numeric_std.all;
|
|
|
entity spwram is
|
entity spwram is
|
|
|
generic (
|
generic (
|
abits: integer;
|
abits: integer;
|
dbits: integer );
|
dbits: integer );
|
|
|
port (
|
port (
|
rclk: in std_logic;
|
rclk: in std_logic;
|
wclk: in std_logic;
|
wclk: in std_logic;
|
ren: in std_logic;
|
ren: in std_logic;
|
raddr: in std_logic_vector(abits-1 downto 0);
|
raddr: in std_logic_vector(abits-1 downto 0);
|
rdata: out std_logic_vector(dbits-1 downto 0);
|
rdata: out std_logic_vector(dbits-1 downto 0);
|
wen: in std_logic;
|
wen: in std_logic;
|
waddr: in std_logic_vector(abits-1 downto 0);
|
waddr: in std_logic_vector(abits-1 downto 0);
|
wdata: in std_logic_vector(dbits-1 downto 0) );
|
wdata: in std_logic_vector(dbits-1 downto 0) );
|
|
|
end entity spwram;
|
end entity spwram;
|
|
|
architecture spwram_arch of spwram is
|
architecture spwram_arch of spwram is
|
|
|
type mem_type is array(0 to (2**abits - 1)) of
|
type mem_type is array(0 to (2**abits - 1)) of
|
std_logic_vector(dbits-1 downto 0);
|
std_logic_vector(dbits-1 downto 0);
|
|
|
signal s_mem: mem_type;
|
signal s_mem: mem_type;
|
|
|
begin
|
begin
|
|
|
-- read process
|
-- read process
|
process (rclk) is
|
process (rclk) is
|
begin
|
begin
|
if rising_edge(rclk) then
|
if rising_edge(rclk) then
|
if ren = '1' then
|
if ren = '1' then
|
rdata <= s_mem(to_integer(unsigned(raddr)));
|
rdata <= s_mem(to_integer(unsigned(raddr)));
|
end if;
|
end if;
|
end if;
|
end if;
|
end process;
|
end process;
|
|
|
-- write process
|
-- write process
|
process (wclk) is
|
process (wclk) is
|
begin
|
begin
|
if rising_edge(wclk) then
|
if rising_edge(wclk) then
|
if wen = '1' then
|
if wen = '1' then
|
s_mem(to_integer(unsigned(waddr))) <= wdata;
|
s_mem(to_integer(unsigned(waddr))) <= wdata;
|
end if;
|
end if;
|
end if;
|
end if;
|
end process;
|
end process;
|
|
|
end architecture;
|
end architecture;
|
|
|
|
|