-
Notifications
You must be signed in to change notification settings - Fork 0
/
fifo_tb.v
217 lines (205 loc) · 4.2 KB
/
fifo_tb.v
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company: Wissance (https://wissance.com)
// Engineer: EvilLord666 (Ushakov MV - https://github.com/EvilLord666)
//
// Create Date: 09.10.2016
// Design Name:
// Module Name: fifo_tb
// Project Name: QuickRS232
// Target Devices: Any
// Tool Versions: Quartus Prime Lite 18.1
// Description: Fifo module testbench
//
// Dependencies: No
//
// Revision: 1.0
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
`define ASSERT(signal, value) \
if (signal !== value) begin \
$display("ASSERTION FAILED in %m: expected: %b, actual is : %b", value, signal); \
$finish; \
end \
else \
begin \
$display("ASSERTION SUCCEDED"); \
end \
module fifo_tb();
wire enable;
reg clear;
reg push;
reg pop;
reg [7:0] in_data;
wire [7:0] out_data;
wire popped_last;
wire pushed_last;
supply1 vcc;
reg clk;
assign enable = vcc;
reg [31:0] counter;
fifo #(.FIFO_SIZE(3), .DATA_WIDTH(8)) simple_fifo (.clk(clk), .clear(clear), .push(push), .pop(pop),
.in_data(in_data), .out_data(out_data),
.popped_last(popped_last), .pushed_last(pushed_last));
initial
begin
in_data <= 0;
counter <= 0;
push <= 0;
pop <= 0;
clk <= 0;
clear <= 0;
#100
clear <= 1;
#100
clear <= 0;
end
always
begin
#20 clk <= ~clk;
counter <= counter + 1;
// 1. push first
// 1.1 setting data first
if (counter == 20)
begin
in_data <= 8'b10101100;
end
// 1.2 push clock is up
if (counter == 22)
begin
push <= 1;
end
// 1.3 push clock is down
if (counter == 23)
begin
push <= 0;
//`ASSERT(pushed_last, 1'b0)
end
// 2. push first
// 2.1 setting data first
if (counter == 30)
begin
in_data <= 8'b01100001;
end
// 2.2 push clock is up
if (counter == 32)
begin
push <= 1;
end
// 2.3 push clock is down
if (counter == 33)
begin
push <= 0;
end
if (counter == 36)
begin
push <= 0;
`ASSERT(pushed_last, 1'b0)
end
// 3. pop first byte
if (counter == 40)
begin
pop <= 1;
end
if (counter == 42)
begin
pop <= 0;
end
if (counter == 44)
begin
`ASSERT(out_data, 8'b10101100)
end
if (counter == 47)
begin
`ASSERT(popped_last, 1'b0)
end
// 4. pop second byte
if (counter == 50)
begin
pop <= 1;
end
if (counter == 52)
begin
pop <= 0;
end
if (counter == 56)
begin
`ASSERT(out_data, 8'b01100001)
end
if (counter == 56)
begin
`ASSERT(popped_last, 1'b1)
end
// 5. push again (b0)
if (counter == 60)
begin
in_data <= 8'b00010001;
end
// push clock is up
if (counter == 62)
begin
push <= 1;
end
// push clock is down
if (counter == 63)
begin
push <= 0;
end
if (counter == 65)
begin
//`ASSERT(pushed_last, 1'b0)
end
// 6. push again (b1)
if (counter == 70)
begin
in_data <= 8'b00111001;
end
// push clock is up
if (counter == 72)
begin
push <= 1;
end
// push clock is down
if (counter == 73)
begin
push <= 0;
end
if (counter == 75)
begin
//`ASSERT(pushed_last, 1'b0)
end
// 7. push again (b0)
if (counter == 80)
begin
in_data <= 8'b01111101;
end
// push clock is up
if (counter == 82)
begin
push <= 1;
end
// push clock is down
if (counter == 83)
begin
push <= 0;
end
if (counter == 86)
begin
`ASSERT(pushed_last, 1'b1)
end
// 8. pop b0
if (counter == 90)
begin
pop <= 1;
end
if (counter == 92)
begin
pop <= 0;
end
if (counter == 95)
begin
`ASSERT(pushed_last, 1'b0)
end
end
endmodule