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

Subversion Repositories boundaries

[/] [boundaries/] [trunk/] [bench/] [verilog/] [oc_fifo_basic_tb.v] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 esquehill
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
//// oc_fifo_basic_tb.v                                           ////
4
////                                                              ////
5
//// This file is part of the boundaries opencores effort.        ////
6
//// <http://www.opencores.org/cores/boundaries/>                 ////
7
////                                                              ////
8
//// Module Description:                                          ////
9
//// One Clock Fifo Testbench                                     ////
10
////                                                              ////
11
//// To Do:                                                       ////
12
//// Done.                                                        ////
13
////                                                              ////
14
//// Author(s):                                                   ////
15
//// - Shannon Hill                                               ////
16
////                                                              ////
17
//////////////////////////////////////////////////////////////////////
18
////                                                              ////
19
//// Copyright (C) 2004 Shannon Hill and OPENCORES.ORG            ////
20
////                                                              ////
21
//// This source file may be used and distributed without         ////
22
//// restriction provided that this copyright statement is not    ////
23
//// removed from the file and that any derivative work contains  ////
24
//// the original copyright notice and the associated disclaimer. ////
25
////                                                              ////
26
//// This source file is free software; you can redistribute it   ////
27
//// and/or modify it under the terms of the GNU Lesser General   ////
28
//// Public License as published by the Free Software Foundation; ////
29
//// either version 2.1 of the License, or (at your option) any   ////
30
//// later version.                                               ////
31
////                                                              ////
32
//// This source is distributed in the hope that it will be       ////
33
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
34
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
35
//// PURPOSE. See the GNU Lesser General Public License for more  ////
36
//// details.                                                     ////
37
////                                                              ////
38
//// You should have received a copy of the GNU Lesser General    ////
39
//// Public License along with this source; if not, download it   ////
40
//// from <http://www.opencores.org/lgpl.shtml>                   ////
41
////                                                              ////
42
//////////////////////////////////////////////////////////////////////
43
//
44
// $Id: oc_fifo_basic_tb.v,v 1.1 2004-07-07 12:39:14 esquehill Exp $
45
//
46
// CVS Revision History
47
//
48
// $Log: not supported by cvs2svn $
49
//
50
//
51
 
52
`timescale 1ns/1ps
53
 
54
module oc_fifo_basic_tb();
55
 
56
parameter AW = 3;
57
parameter DW = 8;
58
 
59
reg            clk_i;
60
reg            rst_i;
61
 
62
reg            give;
63
reg  [DW-1:0]  give_di;
64
 
65
reg            take;
66
wire [DW-1:0]  take_do;
67
 
68
reg  [DW-1:0]  exp_do;
69
 
70
reg  [7:0]     take_timeout;
71
reg  [7:0]     give_timeout;
72
 
73
wire           have;
74
wire           need;
75
 
76
reg            give_allow;
77
 
78
real           period;
79
 
80
integer        passes;
81
 
82
initial
83
begin
84
 
85
 rst_i       <= 1;
86
 clk_i       <= 0;
87
 give        <= 0;
88
 give_di     <= 0;
89
 take        <= 0;
90
 exp_do      <= 0;
91
#200;
92
 
93
 rst_i       <= 0;
94
end
95
 
96
initial
97
begin
98
 
99
 passes = 0;
100
 period = 4.0;
101
 
102
 give_allow <= 0;
103
 
104
 forever
105
 begin
106
 
107
    @( posedge clk_i );
108
    @( posedge clk_i );
109
    @( posedge clk_i );
110
    @( posedge clk_i );
111
    @( posedge clk_i );
112
    @( posedge clk_i );
113
    @( posedge clk_i );
114
    @( posedge clk_i );
115
 
116
    give_allow <= 1;
117
    #5000;
118
    give_allow <= 0;
119
 
120
    @( posedge clk_i );
121
    @( posedge clk_i );
122
    @( posedge clk_i );
123
    @( posedge clk_i );
124
    @( posedge clk_i );
125
    @( posedge clk_i );
126
    @( posedge clk_i );
127
    @( posedge clk_i );
128
 
129
    passes = passes + 1;
130
 
131
    if( passes > 256 )
132
    begin
133
     $display("OK");
134
     $finish;
135
    end
136
 end
137
end
138
 
139
always #(period/2.0) clk_i = ~clk_i;
140
 
141
always @( posedge clk_i )
142
begin
143
 
144
     give   <= 0;
145
 
146
if( ~rst_i & need & give_allow ) give <= 1;
147
if(          need & give       ) give_di <= give_di + 1;
148
end
149
 
150
always @( posedge clk_i )
151
begin
152
 
153
    take <= have & ~rst_i;
154
 
155
if( take & have )
156
begin
157
   if( exp_do !== take_do )
158
    begin
159
    $display( "%d: expected != actual; exp_do=%x take_do=%x", $time,exp_do,take_do);
160
    $stop;
161
    end
162
    exp_do <= exp_do + 1;
163
end
164
end
165
 
166
oc_fifo_basic #(AW,DW) u_fifo( /*AUTOINST*/
167
                              // Outputs
168
                              .have     (have),
169
                              .take_do  (take_do[DW-1:0]),
170
                              .need     (need),
171
                              // Inputs
172
                              .rst_i    (rst_i),
173
                              .clk_i    (clk_i),
174
                              .take     (take),
175
                              .give     (give),
176
                              .give_di  (give_di[DW-1:0]));
177
 
178
always @( posedge clk_i )
179
begin
180
if( &take_timeout )
181
begin
182
 $display( "%d: take inactive for too long.", $time);
183
 $stop;
184
end
185
 
186
if( take | rst_i )
187
     take_timeout <= 0;
188
else take_timeout <= take_timeout + 1;
189
end
190
 
191
always @( posedge clk_i )
192
begin
193
if( &give_timeout )
194
begin
195
 $display( "%d: give inactive too long.", $time);
196
 $stop;
197
end
198
 
199
if( give | rst_i )
200
     give_timeout <= 0;
201
else give_timeout <= give_timeout + 1;
202
end
203
 
204
endmodule

powered by: WebSVN 2.1.0

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