| 1 |
library ieee ; |
| 2 |
use ieee.std_logic_1164.all ; |
| 3 |
use ieee.numeric_std.all ; |
| 4 |
|
| 5 |
entity handshake_tb is |
| 6 |
end entity ; |
| 7 |
|
| 8 |
architecture arch of handshake_tb is |
| 9 |
|
| 10 |
-- Constants |
| 11 |
constant DATA_WIDTH : positive := 32 ; |
| 12 |
|
| 13 |
-- Source signals |
| 14 |
signal source_reset : std_logic := '1' ; |
| 15 |
signal source_clock : std_logic := '1' ; |
| 16 |
signal source_data : std_logic_vector(DATA_WIDTH-1 downto 0) := (others =>'0') ; |
| 17 |
|
| 18 |
signal dest_reset : std_logic := '1' ; |
| 19 |
signal dest_clock : std_logic := '1' ; |
| 20 |
signal dest_data : std_logic_vector(DATA_WIDTH-1 downto 0) ; |
| 21 |
signal dest_req : std_logic := '0' ; |
| 22 |
signal dest_ack : std_logic ; |
| 23 |
|
| 24 |
procedure nop( signal clock : in std_logic ; count : natural ) is |
| 25 |
begin |
| 26 |
for i in 1 to count loop |
| 27 |
wait until rising_edge(clock) ; |
| 28 |
end loop ; |
| 29 |
end procedure ; |
| 30 |
|
| 31 |
begin |
| 32 |
|
| 33 |
source_clock <= not source_clock after 100 ns ; |
| 34 |
dest_clock <= not dest_clock after 3 ns ; |
| 35 |
|
| 36 |
U_handshake : entity work.handshake |
| 37 |
generic map ( |
| 38 |
DATA_WIDTH => DATA_WIDTH |
| 39 |
) port map ( |
| 40 |
source_reset => source_reset, |
| 41 |
source_clock => source_clock, |
| 42 |
source_data => source_data, |
| 43 |
|
| 44 |
dest_reset => dest_reset, |
| 45 |
dest_clock => dest_clock, |
| 46 |
dest_data => dest_data, |
| 47 |
dest_req => dest_req, |
| 48 |
dest_ack => dest_ack |
| 49 |
) ; |
| 50 |
|
| 51 |
increment_source_data : process(source_reset, source_clock) |
| 52 |
begin |
| 53 |
if( source_reset = '1' ) then |
| 54 |
source_data <= (others =>'0') ; |
| 55 |
elsif( rising_edge(source_clock) ) then |
| 56 |
source_data <= std_logic_vector(unsigned(source_data) + 1) ; |
| 57 |
end if ; |
| 58 |
end process ; |
| 59 |
|
| 60 |
source_tb : process |
| 61 |
begin |
| 62 |
source_reset <= '1' ; |
| 63 |
nop( source_clock, 100 ) ; |
| 64 |
source_reset <= '0' ; |
| 65 |
wait ; |
| 66 |
end process ; |
| 67 |
|
| 68 |
dest_tb : process |
| 69 |
begin |
| 70 |
dest_reset <= '1' ; |
| 71 |
nop( dest_clock, 100 ) ; |
| 72 |
dest_reset <= '0' ; |
| 73 |
nop( dest_clock, 100 ) ; |
| 74 |
|
| 75 |
for i in 1 to 100 loop |
| 76 |
dest_req <= '1' ; |
| 77 |
wait until rising_edge(dest_clock) and dest_ack = '1' ; |
| 78 |
dest_req <= '0' ; |
| 79 |
wait until rising_edge(dest_clock) and dest_ack = '0' ; |
| 80 |
for x in 1 to 10 loop |
| 81 |
wait until rising_edge(source_clock) ; |
| 82 |
end loop ; |
| 83 |
end loop ; |
| 84 |
|
| 85 |
report "-- End of Simulation --" severity failure ; |
| 86 |
end process ; |
| 87 |
|
| 88 |
end architecture ; |
| 89 |
|