forked from gregani/la16fw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_fifo.vhd
158 lines (133 loc) · 4.39 KB
/
test_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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
--
-- This file is part of the lafw16 project.
--
-- Copyright (C) 2014-2015 Gregor Anich
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 2 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
--
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity test_fifo is
end test_fifo;
architecture behavior of test_fifo is
-- Component Declaration for the Unit Under Test (UUT)
component fifo
port(
reset : in std_logic;
clk_read : in std_logic;
clk_write : in std_logic;
data_in : in std_logic_vector(15 downto 0);
enable_write : in std_logic;
enable_read : in std_logic;
data_out : out std_logic_vector(15 downto 0);
full : out std_logic;
empty : out std_logic
);
end component;
--Inputs
signal reset : std_logic := '0';
signal clk_read : std_logic := '0';
signal clk_write : std_logic := '0';
signal data_in : std_logic_vector(15 downto 0) := (others => '0');
signal enable_write : std_logic := '0';
signal enable_read : std_logic := '0';
--Outputs
signal data_out : std_logic_vector(15 downto 0);
signal full : std_logic;
signal empty : std_logic;
signal last_empty : std_logic := '1';
-- Clock period definitions
constant clk_read_period : time := 20.83 ns;
constant clk_write_period : time := 100 ns;
signal write_count : unsigned(15 downto 0) := (0=>'1',others=>'0');
signal read_count : unsigned(15 downto 0) := (0=>'1',others=>'0');
signal do_read : std_logic := '0';
signal read_toggle : std_logic := '0';
begin
-- Instantiate the Unit Under Test (UUT)
uut: fifo
port map(
reset => reset,
clk_read => clk_read,
clk_write => clk_write,
data_in => data_in,
enable_write => enable_write,
enable_read => enable_read,
data_out => data_out,
full => full,
empty => empty
);
-- Clock process definitions
clk_read_process :process
begin
read_toggle <= not read_toggle;
--read_toggle <= '1';
clk_read <= '0';
wait for clk_read_period/2;
clk_read <= '1';
if (enable_read = '1') and (empty = '0') then
read_count <= read_count + 1;
assert data_out = std_logic_vector(read_count)
report "wrong data"
severity failure;
-- severity warning;
end if;
wait for clk_read_period/2;
enable_read <= read_toggle and do_read;
end process;
clk_write_process :process
begin
clk_write <= '0';
wait for clk_write_period/2;
clk_write <= '1';
if (enable_write = '1') and (full = '0') then
write_count <= write_count + 1;
end if;
wait for clk_write_period/2;
end process;
data_in <= std_logic_vector(write_count);
-- Stimulus process
stim_proc: process
begin
-- hold reset state for 100 ns.
reset <= '1';
wait for 100 ns;
reset <= '0';
wait for clk_read_period*10;
-- fill fifo
wait until full = '0';
wait until rising_edge(clk_write);
wait for clk_write_period/4;
enable_write <= '1';
wait until full = '1';
enable_write <= '0';
wait for 5 us;
-- read fifo
--wait until empty = '0';
wait until rising_edge(clk_read);
wait for clk_read_period/4;
do_read <= '1';
wait for 5*clk_read_period;
do_read <= '0';
wait for 5*clk_read_period;
do_read <= '1';
-- wait for clk_read_period;
-- wait until empty = '1';
-- do_read <= '0';
-- wait for 1 us;
wait;
end process;
end;