--Ejemplo de diseño de una RAM
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity ramsp is
generic (addrWidth : integer := 2; -- Tamaño bus de direcciones
dataWidth : integer := 4); -- Tamaño de palabra
port( ck, rdNwr, cs : in std_logic;
addr : in integer range 0 to 2**addrWidth - 1;
data : inout std_logic_vector(dataWidth - 1 downto 0));
end;
architecture rtl of ramsp is
-- La memoria se define como un array de palabras
type mem is array(0 to 2
** addrWidth - 1) of std_logic_vector(dataWidth - 1 downto
0);
signal ram : mem;
begin
process (ck)
beginwait until ck = '1';
if (cs = '0') then data <= (others => 'Z'); -- Sin uso la memoria deja el bus de datos en tristate
elseif rdNwr='1' then data <= ram(addr); -- Lectura
else ram(addr) <= data; -- Escritura
end if;end if;
end process;
end;