LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.NUMERIC_STD.ALL;

ENTITY rom_wb IS
	Port
	(
		CLK_I		: in  STD_LOGIC;
		RST_I		: in  STD_LOGIC;
		CYC_I		: in  STD_LOGIC;
		WE_I		: in  STD_LOGIC;
		STB_I		: in  STD_LOGIC;
		ACK_O		: out STD_LOGIC;
		MRDY_I		: in  STD_LOGIC;
		SRDY_O		: out STD_LOGIC;
		ADDR_I		: in  unsigned(31 downto 0);
		DAT_O		: out unsigned(31 downto 0)
	);
END rom_wb;

ARCHITECTURE behavior OF rom_wb IS

	COMPONENT rom
	PORT
	(
		clk		: in  STD_LOGIC;
		ce		: in  STD_LOGIC;
		addr	: in  unsigned(31 downto 0);
		dout	: out unsigned(31 downto 0)
	);
	END COMPONENT;

	signal data_en : std_logic;

begin

	data_en	<= CYC_I and STB_I and MRDY_I;
	SRDY_O	<= CYC_I;
	
data_valid_register:
	process(CLK_I)
	begin
		if rising_edge(CLK_I) then
			if RST_I = '1' then
				ACK_O	<= '0';
			else
				ACK_O	<= data_en and not WE_I;
			end if;
		end if;
	end process;

inst_rom : rom
	PORT MAP
	(
		clk		=> CLK_I,
		ce		=> data_en,
		addr	=> ADDR_I,
		dout	=> DAT_O
	);


end behavior;
