1 |
145 |
lanttu |
-------------------------------------------------------------------------------
|
2 |
|
|
-- File : tb_fifo1.vhdl
|
3 |
|
|
-- Description : Test bench for Fifo buffer, fifo length = 1!
|
4 |
|
|
-- Author : Erno Salminen
|
5 |
|
|
-- Date : 29.04.2002
|
6 |
|
|
-- Modified : 02.05.2002 Vesa Lahtinen Tests added
|
7 |
|
|
--
|
8 |
|
|
--
|
9 |
|
|
-------------------------------------------------------------------------------
|
10 |
|
|
library ieee;
|
11 |
|
|
use ieee.std_logic_1164.all;
|
12 |
|
|
use ieee.std_logic_arith.all;
|
13 |
|
|
|
14 |
|
|
entity tb_fifo1 is
|
15 |
|
|
end tb_fifo1;
|
16 |
|
|
|
17 |
|
|
architecture behavioral of tb_fifo1 is
|
18 |
|
|
|
19 |
|
|
|
20 |
|
|
component fifo
|
21 |
|
|
|
22 |
|
|
generic (
|
23 |
|
|
width : integer := 0;
|
24 |
|
|
depth : integer := 0
|
25 |
|
|
);
|
26 |
|
|
|
27 |
|
|
port (
|
28 |
|
|
Clk : in std_logic;
|
29 |
|
|
Rst_n : std_logic;
|
30 |
|
|
Data_In : in std_logic_vector (width-1 downto 0);
|
31 |
|
|
Write_Enable : in std_logic;
|
32 |
|
|
One_Place_Left : out std_logic;
|
33 |
|
|
Full : out std_logic;
|
34 |
|
|
Data_Out : out std_logic_vector (width-1 downto 0);
|
35 |
|
|
Read_Enable : in std_logic;
|
36 |
|
|
Empty : out std_logic;
|
37 |
|
|
One_Data_Left : out std_logic
|
38 |
|
|
);
|
39 |
|
|
end component;
|
40 |
|
|
|
41 |
|
|
constant width : integer := 16;
|
42 |
|
|
constant depth : integer := 1; -- !!!
|
43 |
|
|
constant PERIOD : time := 10 ns;
|
44 |
|
|
|
45 |
|
|
signal Clk : std_logic;
|
46 |
|
|
signal Rst_n : std_logic;
|
47 |
|
|
signal Data_In : std_logic_vector (width-1 downto 0);
|
48 |
|
|
signal Data_Out : std_logic_vector (width-1 downto 0);
|
49 |
|
|
signal Write_Enable : std_logic;
|
50 |
|
|
signal Read_Enable : std_logic;
|
51 |
|
|
signal Full : std_logic;
|
52 |
|
|
signal One_Place_Left : std_logic;
|
53 |
|
|
signal Empty : std_logic;
|
54 |
|
|
signal One_Data_Left : std_logic;
|
55 |
|
|
|
56 |
|
|
signal Read_Data : std_logic_vector (width-1 downto 0);
|
57 |
|
|
|
58 |
|
|
signal Test_Phase : integer range 0 to 20;
|
59 |
|
|
|
60 |
|
|
begin -- behavioral
|
61 |
|
|
|
62 |
|
|
|
63 |
|
|
DUT : fifo
|
64 |
|
|
generic map (
|
65 |
|
|
width => width,
|
66 |
|
|
depth => depth)
|
67 |
|
|
port map (
|
68 |
|
|
Clk => Clk,
|
69 |
|
|
Rst_n => Rst_n,
|
70 |
|
|
Data_In => Data_In,
|
71 |
|
|
Write_Enable => Write_Enable,
|
72 |
|
|
Full => Full,
|
73 |
|
|
One_Place_Left => One_Place_Left,
|
74 |
|
|
Data_Out => Data_Out,
|
75 |
|
|
Read_Enable => Read_Enable,
|
76 |
|
|
Empty => Empty,
|
77 |
|
|
One_Data_Left => One_Data_Left );
|
78 |
|
|
|
79 |
|
|
Generate_input : process
|
80 |
|
|
|
81 |
|
|
-----------------------------------------------------------------------------
|
82 |
|
|
-- Two procedures for writing to and for reading the fifo
|
83 |
|
|
-----------------------------------------------------------------------------
|
84 |
|
|
procedure WriteToFifo (
|
85 |
|
|
Data_To_Fifo : in integer;
|
86 |
|
|
wait_time : in integer) is
|
87 |
|
|
begin --procedure
|
88 |
|
|
Read_Enable <= '0'; -- 24.05 es
|
89 |
|
|
Data_In <= conv_std_logic_vector (Data_To_Fifo, width);
|
90 |
|
|
Write_Enable <= '1';
|
91 |
|
|
if Full = '1' then
|
92 |
|
|
assert false report "Fifo full. Cannot write" severity note;
|
93 |
|
|
end if;
|
94 |
|
|
wait for PERIOD;
|
95 |
|
|
Write_Enable <= '0';
|
96 |
|
|
Data_In <= (others => 'Z');
|
97 |
|
|
wait for (wait_time)* PERIOD;
|
98 |
|
|
end WriteToFifo;
|
99 |
|
|
|
100 |
|
|
|
101 |
|
|
procedure ReadFifo (
|
102 |
|
|
wait_time : in integer) is
|
103 |
|
|
begin --procedure
|
104 |
|
|
Write_Enable <= '0'; -- 24.05 es
|
105 |
|
|
Read_Enable <= '1';
|
106 |
|
|
|
107 |
|
|
if Empty = '1' then
|
108 |
|
|
assert false report "Fifo empty. Cannot read." severity note;
|
109 |
|
|
end if;
|
110 |
|
|
wait for PERIOD;
|
111 |
|
|
Read_Enable <= '0';
|
112 |
|
|
wait for (wait_time)* PERIOD;
|
113 |
|
|
|
114 |
|
|
end ReadFifo;
|
115 |
|
|
|
116 |
|
|
procedure WriteAndReadFifo (
|
117 |
|
|
Data_To_Fifo : in integer;
|
118 |
|
|
wait_time : in integer) is
|
119 |
|
|
begin --procedure
|
120 |
|
|
Read_Enable <= '1';
|
121 |
|
|
if Empty = '1' then
|
122 |
|
|
assert false report "Fifo empty. Cannot read. Writing possible." severity note;
|
123 |
|
|
end if;
|
124 |
|
|
|
125 |
|
|
Data_In <= conv_std_logic_vector (Data_To_Fifo, width);
|
126 |
|
|
Write_Enable <= '1';
|
127 |
|
|
if Full = '1' then
|
128 |
|
|
assert false report "Fifo full. Cannot write. Reading possible." severity note;
|
129 |
|
|
end if;
|
130 |
|
|
|
131 |
|
|
|
132 |
|
|
wait for PERIOD;
|
133 |
|
|
Read_Enable <= '0';
|
134 |
|
|
Write_Enable <= '0';
|
135 |
|
|
Data_In <= (others => 'Z'); -- 24.05 es
|
136 |
|
|
wait for (wait_time)* PERIOD;
|
137 |
|
|
|
138 |
|
|
end WriteAndReadFifo;
|
139 |
|
|
-----------------------------------------------------------------------------
|
140 |
|
|
|
141 |
|
|
|
142 |
|
|
|
143 |
|
|
begin -- process Generate_input
|
144 |
|
|
-- test sequence
|
145 |
|
|
-- 0 wait for reset
|
146 |
|
|
-- 1 write to empty fifo and read so that it is empty again
|
147 |
|
|
-- 2 write to fifo until there is only one place left
|
148 |
|
|
-- 3 write to fifo so that it becomes full
|
149 |
|
|
-- 4 read from full fifo and continue until there is only one data left
|
150 |
|
|
-- 5 read the last data
|
151 |
|
|
-- write and read the empty fifo at the same time, only write is succesful!
|
152 |
|
|
-- 6 write to fifo, write and read at the same time, both should be succesful!
|
153 |
|
|
-- 7 write until fifo is full
|
154 |
|
|
-- 8 write and read full fifo, only reading succesful!
|
155 |
|
|
-- read until fifo is empty
|
156 |
|
|
-- 9 make sure fifo is empty
|
157 |
|
|
|
158 |
|
|
|
159 |
|
|
-- 0 Wait for reset
|
160 |
|
|
Write_Enable <= '0';
|
161 |
|
|
Read_Enable <= '0';
|
162 |
|
|
Data_In <= (others => 'Z');
|
163 |
|
|
Test_Phase <= 0;
|
164 |
|
|
wait for (6+2)*PERIOD;
|
165 |
|
|
wait for PERIOD/2;
|
166 |
|
|
wait for PERIOD/3;
|
167 |
|
|
|
168 |
|
|
|
169 |
|
|
-- At the beginning
|
170 |
|
|
-- Full = 0
|
171 |
|
|
-- Empty = 1
|
172 |
|
|
-- One_Place_Left = 1
|
173 |
|
|
-- One_Data_Left = 0
|
174 |
|
|
-- NOTE! Empty = One_Place_Left and Full = One_Data_Left
|
175 |
|
|
assert Full = '0' report "0: Full not correct" severity error;
|
176 |
|
|
assert Empty = '1' report "0: Empty not correct" severity error;
|
177 |
|
|
assert One_Data_Left = '0' report "0: One_Data_Left not correct" severity error;
|
178 |
|
|
assert One_Place_Left = '1' report "0: One_Place_Left not correct" severity error;
|
179 |
|
|
|
180 |
|
|
-- 1) Write to empty fifo
|
181 |
|
|
Test_Phase <= Test_Phase +1;
|
182 |
|
|
WriteToFifo (5, 1);
|
183 |
|
|
assert Full = '1' report "1: Full not correct" severity error;
|
184 |
|
|
assert Empty = '0' report "1: Empty not correct" severity error;
|
185 |
|
|
assert One_Data_Left = '1' report "1: One_Data_Left not correct" severity error;
|
186 |
|
|
assert One_Place_Left = '0' report "1: One_Place_Left not correct" severity error;
|
187 |
|
|
assert Data_Out = conv_std_logic_vector (5, width) report "1: data not stored correctly" severity error;
|
188 |
|
|
|
189 |
|
|
-- 2 )write to full fifo
|
190 |
|
|
Test_Phase <=Test_Phase +1;
|
191 |
|
|
WriteToFifo (10, 1);
|
192 |
|
|
WriteToFifo (11, 1);
|
193 |
|
|
WriteToFifo (12, 1);
|
194 |
|
|
WriteToFifo (13, 1);
|
195 |
|
|
assert Full = '1' report "2: Full not correct" severity error;
|
196 |
|
|
assert Empty = '0' report "2: Empty not correct" severity error;
|
197 |
|
|
assert One_Data_Left = '1' report "2: One_Data_Left not correct" severity error;
|
198 |
|
|
assert One_Place_Left = '0' report "2: One_Place_Left not correct" severity error;
|
199 |
|
|
assert Data_Out = conv_std_logic_vector (5, width) report "2: data not stored correctly" severity error;
|
200 |
|
|
|
201 |
|
|
|
202 |
|
|
-- 3) write and read full fifo
|
203 |
|
|
-- only read succesful
|
204 |
|
|
Test_Phase <= Test_Phase +1;
|
205 |
|
|
WriteAndReadFifo (14,2);
|
206 |
|
|
assert Full = '0' report "3: Full not correct" severity error;
|
207 |
|
|
assert Empty = '1' report "3: Empty not correct" severity error;
|
208 |
|
|
assert One_Data_Left = '0' report "3: One_Data_Left not correct" severity error;
|
209 |
|
|
assert One_Place_Left = '1' report "3: One_Place_Left not correct" severity error;
|
210 |
|
|
|
211 |
|
|
|
212 |
|
|
-- 4 read empty fifo
|
213 |
|
|
Test_Phase <= Test_Phase +1;
|
214 |
|
|
ReadFifo (1);
|
215 |
|
|
ReadFifo (1);
|
216 |
|
|
ReadFifo (1);
|
217 |
|
|
assert Full = '0' report "4: Full not correct" severity error;
|
218 |
|
|
assert Empty = '1' report "4: Empty not correct" severity error;
|
219 |
|
|
assert One_Data_Left = '0' report "4: One_Data_Left not correct" severity error;
|
220 |
|
|
assert One_Place_Left = '1' report "4: One_Place_Left not correct" severity error;
|
221 |
|
|
|
222 |
|
|
-- 5 write and read empty fifo
|
223 |
|
|
Test_Phase <= Test_Phase +1;
|
224 |
|
|
WriteAndReadFifo (15,2);
|
225 |
|
|
assert Full = '1' report "5: Full not correct" severity error;
|
226 |
|
|
assert Empty = '0' report "5: Empty not correct" severity error;
|
227 |
|
|
assert One_Data_Left = '1' report "5: One_Data_Left not correct" severity error;
|
228 |
|
|
assert One_Place_Left = '0' report "5: One_Place_Left not correct" severity error;
|
229 |
|
|
assert Data_Out = conv_std_logic_vector (15, width) report "5: data not stored correctly" severity error;
|
230 |
|
|
|
231 |
|
|
-- 6 read full fifo
|
232 |
|
|
Test_Phase <= Test_Phase +1;
|
233 |
|
|
ReadFifo (2);
|
234 |
|
|
assert Full = '0' report "6: Full not correct" severity error;
|
235 |
|
|
assert Empty = '1' report "6: Empty not correct" severity error;
|
236 |
|
|
assert One_Data_Left = '0' report "6: One_Data_Left not correct" severity error;
|
237 |
|
|
assert One_Place_Left = '1' report "6: One_Place_Left not correct" severity error;
|
238 |
|
|
|
239 |
|
|
-- 7 other shit
|
240 |
|
|
-- ReadFifo (2);
|
241 |
|
|
-- WriteToFifo (52, 1);
|
242 |
|
|
-- ReadFifo (2);
|
243 |
|
|
|
244 |
|
|
-- WriteToFifo (14, 1);
|
245 |
|
|
-- WriteToFifo (15, 1);
|
246 |
|
|
-- WriteToFifo (16, 1);
|
247 |
|
|
|
248 |
|
|
-- WriteToFifo (17, 1);
|
249 |
|
|
-- ReadFifo (1);
|
250 |
|
|
-- ReadFifo (1);
|
251 |
|
|
-- ReadFifo (4);
|
252 |
|
|
|
253 |
|
|
-- WriteAndReadFifo (67,2);
|
254 |
|
|
-- wait for 5*PERIOD;
|
255 |
|
|
-- ReadFifo (1);
|
256 |
|
|
|
257 |
|
|
-- Test completed
|
258 |
|
|
Test_Phase <= 0;
|
259 |
|
|
wait;
|
260 |
|
|
end process Generate_input;
|
261 |
|
|
|
262 |
|
|
|
263 |
|
|
|
264 |
|
|
Read_Data_from_fifo : process (Clk, Rst_n)
|
265 |
|
|
begin -- process Read_Data_from_fifo
|
266 |
|
|
if Rst_n = '0' then -- asynchronous reset (active low)
|
267 |
|
|
Read_Data <= (others => '0');
|
268 |
|
|
elsif Clk'event and Clk = '1' then -- rising clock edge
|
269 |
|
|
if Read_Enable = '1' then
|
270 |
|
|
Read_Data <= Data_Out;
|
271 |
|
|
else
|
272 |
|
|
Read_Data <= Read_Data;
|
273 |
|
|
end if;
|
274 |
|
|
end if;
|
275 |
|
|
end process Read_Data_from_fifo;
|
276 |
|
|
|
277 |
|
|
|
278 |
|
|
|
279 |
|
|
|
280 |
|
|
CLOCK1: process -- generate clock signal for design
|
281 |
|
|
variable clktmp: std_logic := '0';
|
282 |
|
|
begin
|
283 |
|
|
wait for PERIOD/2;
|
284 |
|
|
clktmp := not clktmp;
|
285 |
|
|
Clk <= clktmp;
|
286 |
|
|
end process CLOCK1;
|
287 |
|
|
|
288 |
|
|
RESET: process
|
289 |
|
|
begin
|
290 |
|
|
Rst_n <= '0'; -- Reset the testsystem
|
291 |
|
|
wait for 6*PERIOD; -- Wait
|
292 |
|
|
Rst_n <= '1'; -- de-assert reset
|
293 |
|
|
wait;
|
294 |
|
|
end process RESET;
|
295 |
|
|
|
296 |
|
|
|
297 |
|
|
|
298 |
|
|
end behavioral;
|
299 |
|
|
|
300 |
|
|
|
301 |
|
|
|
302 |
|
|
|
303 |
|
|
|
304 |
|
|
configuration basic_cfg of tb_fifo1 is
|
305 |
|
|
|
306 |
|
|
for behavioral
|
307 |
|
|
for all : fifo
|
308 |
|
|
--use entity work.fifo (inout_mux);
|
309 |
|
|
use entity work.fifo (in_mux);
|
310 |
|
|
--use entity work.fifo (shift_reg);
|
311 |
|
|
end for;
|
312 |
|
|
|
313 |
|
|
end for;
|
314 |
|
|
|
315 |
|
|
|
316 |
|
|
end basic_cfg;
|