OpenCores
URL https://opencores.org/ocsvn/funbase_ip_library/funbase_ip_library/trunk

Subversion Repositories funbase_ip_library

[/] [funbase_ip_library/] [trunk/] [TUT/] [ip.hwp.storage/] [fifos/] [synch_fifos/] [1.0/] [tb/] [tb_fifo2.vhd] - Blame information for rev 145

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.