synth/wave/square_test.vhdl

133 lines
2.8 KiB
VHDL
Raw Normal View History

2021-03-09 02:58:52 +00:00
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use std.textio.all;
entity square_test is
end square_test;
architecture rtl of square_test is
component square is
port
(
clk : in std_logic;
rst : in std_logic;
-- bus slave interface
s_we : in std_logic;
s_addr : in std_logic_vector(15 downto 0);
s_din : in std_logic_vector(15 downto 0);
-- bus master interface (DMA!!)
m_busy : in std_logic;
m_we : out std_logic;
m_addr : out std_logic_vector(15 downto 0);
m_dout : out std_logic_vector(15 downto 0)
);
end component;
signal finished, clk, rst: std_logic := '0';
signal s_we, m_busy, m_we: std_logic;
signal s_addr, s_din, m_addr, m_dout: std_logic_vector(15 downto 0);
2021-04-24 15:55:23 +00:00
constant period: integer := 7;
constant half_time: time := 1280 ns * period;
2021-03-09 02:58:52 +00:00
begin
dut: square port map(clk => clk, rst => rst,
s_we => s_we, s_addr => s_addr, s_din => s_din,
m_busy => m_busy, m_we => m_we, m_addr => m_addr, m_dout => m_dout);
-- tick tock
process
begin
if finished = '0' then
clk <= not clk;
wait for 5 ns;
else
clk <= '0';
wait;
end if;
end process;
process
begin
rst <= '1';
wait for 1 ns;
assert(m_we='0') report "Fail rst" severity error;
rst <= '0';
m_busy <= '0';
wait for 10 ns;
s_we <= '1';
s_addr <= x"0000"; -- period
2021-04-24 15:55:23 +00:00
s_din <= std_logic_vector(to_unsigned(period, 16));
2021-03-09 02:58:52 +00:00
wait for 10 ns;
s_we <= '1';
s_addr <= x"0002"; -- high
s_din <= x"0042";
wait for 10 ns;
s_we <= '1';
s_addr <= x"0004"; -- low
s_din <= x"0037";
wait for 10 ns;
s_we <= '1';
2021-04-24 15:55:23 +00:00
s_addr <= x"0006"; -- DMA address
2021-03-09 02:58:52 +00:00
s_din <= x"babe";
wait for 10 ns;
s_we <= '1';
s_addr <= x"0008"; -- enable
s_din <= x"0001";
wait for 20 ns;
2021-04-24 15:55:23 +00:00
-- assert(m_addr = x"babe") report "Fail to write to mem addr" severity error;
-- assert(m_we = '1') report "Fail to write to mem we" severity error;
-- assert(m_dout = x"0037") report "Fail to write to mem dout" severity error;
2021-03-09 02:58:52 +00:00
wait for 20 ns;
2021-04-24 15:55:23 +00:00
-- assert(m_we = '0') report "Fail to stop m_we" severity error;
wait for half_time;
assert(m_dout = x"0037") report "Fail to write to mem dout" severity error;
m_busy <= '1';
2021-03-09 02:58:52 +00:00
2021-04-24 15:55:23 +00:00
wait for half_time;
2021-03-09 02:58:52 +00:00
2021-04-24 15:55:23 +00:00
assert(m_we = '0') report "Blarg" severity error;
assert(m_dout = x"0037") report "Fail to write to mem dout" severity error;
m_busy <= '0';
wait for 10 ns;
assert(m_we = '1') report "Blarg" severity error;
2021-03-09 02:58:52 +00:00
assert(m_dout = x"0042") report "Fail to write to mem dout" severity error;
2021-04-24 15:55:23 +00:00
wait for 100 us;
2021-03-09 02:58:52 +00:00
assert false report "Test done." severity note;
finished <= '1';
wait;
end process;
end rtl;