DMA_for_RoCC/SINGLE_PORT_RAM.vhd

60 lines
2.8 KiB
VHDL
Raw Normal View History

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
2024-12-16 23:26:48 +01:00
----------------------ram Entity---------------------------
entity single_port_ram is
2024-12-09 21:09:33 +01:00
generic (
2024-12-16 23:26:48 +01:00
DATA_SIZE : natural := 7; -- Default source ID should be changed
ADDRESS_SIZE : natural := 6 -- Default destination ID should be changed
2024-12-09 21:09:33 +01:00
);
--constant DATA_SIZE : integer := 7; -- Define constant for vector size for data of 8 bits
--constant ADDRESS_SIZE : integer := 6; -- Define constant for vector size for address 7 bits
port(
clk : in std_logic;
rst : in std_logic;
2024-12-16 23:26:48 +01:00
address_bus : in std_logic_vector(ADDRESS_SIZE downto 0); -- From DMA
read_enable : in std_logic; -- From DMA
write_enable : in std_logic; -- From DMA
data_bus_in : in std_logic_vector(DATA_SIZE downto 0); -- From NoC
data_bus_out : out std_logic_vector(DATA_SIZE downto 0) -- From NoC
2024-12-09 21:09:33 +01:00
);
end entity;
2024-12-16 23:26:48 +01:00
----------------------ram Behaviour------------------------
architecture single_port_ram_behav of single_port_ram is
2024-12-16 23:26:48 +01:00
------- define the new type for the 128x8 ram
type ram_array is array (0 to 127 ) of std_logic_vector (DATA_SIZE 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
2024-12-09 21:09:33 +01:00
if rst = '0' then -- inverted reset
2024-12-16 23:26:48 +01:00
data_bus_out <= (others => '0');
initialized <= '1';
elsif rising_edge(clk) then
2024-12-16 23:26:48 +01:00
--Setting value to the ram to coresponding index_testing purpouse
2024-12-09 21:09:33 +01:00
-- synthesis translate_off
if initialized = '1' then
for i in 0 to 127 loop
2024-12-16 23:26:48 +01:00
ram(i) <= std_logic_vector(to_unsigned(i,8));
end loop;
initialized <= '0';
end if;
2024-12-09 21:09:33 +01:00
-- synthesis translate_on
2024-12-16 23:26:48 +01:00
--Read Write functionality of ram
if (read_enable = '1' and write_enable = '0' )then --read enable; [MSB] READ Enable [LSB] WRITE Enable
data_bus_out <= ram(to_integer(unsigned(address_bus(ADDRESS_SIZE downto 0 )))); -- read data from ram
elsif (read_enable = '0' and write_enable = '1') then --write enable; [MSB] READ Enable [LSB] WRITE Enable
ram(to_integer(unsigned(address_bus(ADDRESS_SIZE downto 0)))) <= data_bus_in(DATA_SIZE downto 0); -- Write data to ram
data_bus_out <= (others => '0');
else
2024-12-16 23:26:48 +01:00
data_bus_out <= (others => '0');
end if;
end if;
end process;
end architecture;