-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
188 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
library ieee; | ||
use ieee.std_logic_1164.all; | ||
use ieee.numeric_std.all; | ||
|
||
entity RAM is | ||
port ( | ||
i_Clk : in std_logic; | ||
i_Addr : in std_logic_vector(3 downto 0); | ||
i_Data : in std_logic_vector(7 downto 0); | ||
i_Write : in std_logic; | ||
o_Data : out std_logic_vector(7 downto 0) | ||
); | ||
end entity RAM; | ||
|
||
architecture rtl of RAM is | ||
type ram_type is array(0 to 15) of std_logic_vector(7 downto 0); | ||
signal r_RAM : ram_type := (others => (others => '0')); | ||
begin | ||
process (i_Clk) | ||
begin | ||
if rising_edge(i_Clk) then | ||
if i_Write = '1' then | ||
r_RAM(to_integer(unsigned(i_Addr))) <= i_Data; | ||
end if; | ||
o_Data <= r_RAM(to_integer(unsigned(i_Addr))); | ||
end if; | ||
end process; | ||
end rtl; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
library ieee; | ||
use ieee.std_logic_1164.all; | ||
use ieee.numeric_std.all; | ||
|
||
library vunit_lib; | ||
context vunit_lib.vunit_context; | ||
|
||
entity RAM_TB is | ||
generic (runner_cfg : string); | ||
end entity; | ||
|
||
architecture tb of RAM_TB is | ||
|
||
signal r_Clk : std_logic := '0'; | ||
signal r_Reg_MAR : std_logic_vector(3 downto 0) := (others => '0'); | ||
signal r_Bus : std_logic_vector(7 downto 0) := (others => '0'); | ||
signal w_RAM_Out : std_logic_vector(7 downto 0); | ||
signal r_RAM_Write : std_logic := '0'; | ||
|
||
begin | ||
-- Instantiate the UUT | ||
UUT : entity work.RAM | ||
port map( | ||
i_Clk => r_Clk, | ||
i_Addr => r_Reg_MAR, | ||
i_Data => r_Bus, | ||
o_Data => w_RAM_Out, | ||
i_Write => r_RAM_Write | ||
); | ||
|
||
-- Clock | ||
-- r_Clk <= not r_Clk after 5 ns; | ||
|
||
main : process | ||
begin | ||
test_runner_setup(runner, runner_cfg); | ||
r_Clk <= '0'; | ||
wait for 10 ns; | ||
r_Clk <= '1'; | ||
wait for 10 ns; | ||
|
||
-- Simulation starts here | ||
|
||
-- Check all addresses should be 0 | ||
for i in 0 to 15 loop | ||
r_Reg_MAR <= std_logic_vector(to_unsigned(i, 4)); | ||
r_RAM_Write <= '0'; | ||
wait for 10 ns; | ||
r_Clk <= '0'; | ||
wait for 10 ns; | ||
r_Clk <= '1'; | ||
wait for 10 ns; | ||
assert w_RAM_Out = "00000000" report "RAM output is not 0" severity failure; | ||
end loop; | ||
|
||
-- Write to RAM | ||
wait for 10 ns; | ||
r_RAM_Write <= '1'; | ||
r_Reg_MAR <= "0000"; | ||
r_Bus <= "10101010"; | ||
wait for 10 ns; | ||
r_Clk <= '0'; | ||
wait for 10 ns; | ||
r_Clk <= '1'; | ||
wait for 10 ns; | ||
|
||
-- Write to another location | ||
r_RAM_Write <= '1'; | ||
r_Reg_MAR <= "1111"; | ||
r_Bus <= "01010101"; | ||
wait for 10 ns; | ||
r_Clk <= '0'; | ||
wait for 10 ns; | ||
r_Clk <= '1'; | ||
wait for 10 ns; | ||
|
||
-- Read from RAM | ||
r_RAM_Write <= '0'; | ||
r_Reg_MAR <= "0000"; | ||
wait for 10 ns; | ||
r_Clk <= '0'; | ||
wait for 10 ns; | ||
r_Clk <= '1'; | ||
wait for 10 ns; | ||
assert w_RAM_Out = "10101010" report "RAM output is not 10101010" severity failure; | ||
|
||
-- Read from another location | ||
r_RAM_Write <= '0'; | ||
r_Reg_MAR <= "1111"; | ||
wait for 10 ns; | ||
r_Clk <= '0'; | ||
wait for 10 ns; | ||
r_Clk <= '1'; | ||
wait for 10 ns; | ||
assert w_RAM_Out = "01010101" report "RAM output is not 01010101" severity failure; | ||
|
||
wait for 10 ns; | ||
|
||
test_runner_cleanup(runner); -- Simulation ends here | ||
end process; | ||
end architecture; |