-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtb_fifo.vhd
103 lines (86 loc) · 2.57 KB
/
tb_fifo.vhd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
-- fifo testbench
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity tb_fifo is
end tb_fifo;
architecture rtl of tb_fifo is
constant M : integer := 4;
constant N : integer := 8;
signal rst, clk_wr, wr_en, clk_rd, rd_en : std_logic := '0';
signal din : std_logic_vector(N - 1 downto 0) := (others => '0');
signal empty_async, full_async : std_logic;
signal empty_sync, full_sync : std_logic;
signal dout_async : std_logic_vector(N - 1 downto 0) := (others => '0');
signal dout_sync : std_logic_vector(N - 1 downto 0) := (others => '0');
constant clk_wr_time : time := 20 ns;
constant clk_rd_time : time := 10 ns;
begin
f0: entity work.fifo_sync(rtl)
generic map ( M=>M, N=>N )
port map (
i_rst=>rst, i_clk=>clk_rd, i_wr_en=>wr_en,
i_din=>din, i_rd_en=>rd_en,
o_dout=>dout_sync, o_empty=>empty_sync, o_full=>full_sync
);
f2: entity work.fifo_async(rtl)
generic map ( M=>M, N=>N )
port map (
i_rst=>rst, i_clk_wr=>clk_wr, i_wr_en=>wr_en,
i_din=>din, i_clk_rd=>clk_rd, i_rd_en=>rd_en,
o_dout=>dout_async, o_empty=>empty_async, o_full=>full_async
);
-- write clock
gen_wr_clk: process
begin
for i in 0 to 100 loop
wait for clk_wr_time/2;
clk_wr <= '1';
wait for clk_wr_time/2;
clk_wr <= '0';
end loop;
wait;
end process;
-- read clock
gen_rd_clk: process
begin
for i in 0 to 200 loop
wait for clk_rd_time/2;
clk_rd <= '1';
wait for clk_rd_time/2;
clk_rd <= '0';
end loop;
wait;
end process;
-- stimulus
stimulus: process
begin
rst <= '1';
wait for 20 * clk_rd_time;
rst <= '0';
for i in 1 to 20 loop
din <= std_logic_vector(to_unsigned(i, N));
wait for clk_wr_time;
wr_en <= '1';
wait for clk_wr_time;
wr_en <= '0';
end loop;
wait until clk_rd = '0';
rd_en <= '1';
wait for 3 * clk_rd_time;
rd_en <= '0';
for i in 1 to 5 loop
din <= std_logic_vector(to_unsigned(i, N));
wait for clk_wr_time;
wr_en <= '1';
wait for clk_wr_time;
wr_en <= '0';
end loop;
wait until clk_rd = '0';
for i in 1 to 20 loop
rd_en <= '1';
wait for clk_rd_time;
end loop;
wait;
end process;
end rtl;