library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; ----------------------RAM Entity--------------------------- entity Single_Port_RAM is port( clk : in std_logic; rst : in std_logic; Address_bus : in std_logic_vector(7 downto 0); --From DMA Read_write_Enable : in std_logic_vector(1 downto 0); --From DMA Data_bus_in : in std_logic_vector(7 downto 0); --From Noc Data_bus_out : out std_logic_vector(7 downto 0) --From Noc ); end entity; ----------------------RAM Behaviour------------------------ architecture Single_Port_RAM_behav of Single_Port_RAM is ------- define the new type for the 128x8 RAM type RAM_ARRAY is array (0 to 127 ) of std_logic_vector (7 downto 0); -------- initial values in the RAM to X00 signal RAM: RAM_ARRAY := (others=>x"00"); signal initialized : std_logic; -- Initialization flag begin process(clk, rst) begin if rst = '0' then -- inverted reset Data_bus_out <= (others => '0'); initialized <= '1'; elsif rising_edge(clk) then --Setting value to the RAM to coresponding index if initialized = '1' then for i in 0 to 127 loop RAM(i) <= std_logic_vector(to_unsigned(i,8)); end loop; initialized <= '0'; end if; --Read Write functionality of RAM if (Read_write_Enable(0) = '0' and Read_write_Enable(1) = '1' )then --read enable; [MSB] READ Enable [LSB] WRITE Enable Data_bus_out <= RAM(to_integer(unsigned(Address_bus(6 downto 0 )))); -- read data from RAM elsif (Read_write_Enable(0) = '1' and Read_write_Enable(1) = '0') then --write enable; [MSB] READ Enable [LSB] WRITE Enable RAM(to_integer(unsigned(Address_bus(6 downto 0)))) <= Data_bus_in(7 downto 0); -- Write data to RAM Data_bus_out <= (others => '0'); else Data_bus_out <= (others => '0'); end if; end if; end process; end architecture;