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