-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestBench Code
More file actions
261 lines (172 loc) · 5.47 KB
/
Copy pathTestBench Code
File metadata and controls
261 lines (172 loc) · 5.47 KB
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
`timescale 1ns/1ps
module tb_async_fifo_ecc;
reg wr_clk;
reg rd_clk;
reg wr_rst_n;
reg rd_rst_n;
reg [7:0] s_data;
reg s_valid;
wire s_ready;
wire [7:0] m_data;
wire m_valid;
reg m_ready;
wire full;
wire empty;
wire ecc_corrected;
wire ecc_error;
// ========================================================
// DUT
// ========================================================
async_fifo_ecc dut (
.wr_clk(wr_clk),
.wr_rst_n(wr_rst_n),
.s_data(s_data),
.s_valid(s_valid),
.s_ready(s_ready),
.rd_clk(rd_clk),
.rd_rst_n(rd_rst_n),
.m_data(m_data),
.m_valid(m_valid),
.m_ready(m_ready),
.full(full),
.empty(empty),
.ecc_corrected(ecc_corrected),
.ecc_error(ecc_error)
);
// ========================================================
// Clocks
// ========================================================
initial begin
wr_clk = 0;
forever #5 wr_clk = ~wr_clk;
end
initial begin
rd_clk = 0;
forever #7 rd_clk = ~rd_clk;
end
// ========================================================
// Reset
// ========================================================
initial begin
wr_rst_n = 0;
rd_rst_n = 0;
s_data = 0;
s_valid = 0;
m_ready = 0;
#40;
wr_rst_n = 1;
rd_rst_n = 1;
$display("========================================");
$display("RESET RELEASED");
$display("========================================");
end
// ========================================================
// Write Task
// ========================================================
task write_data;
input [7:0] data;
begin
@(posedge wr_clk);
while (!s_ready)
@(posedge wr_clk);
s_data <= data;
s_valid <= 1'b1;
@(posedge wr_clk);
s_valid <= 1'b0;
$display(
"[WRITE] Time=%0t Data=%02h",
$time,
data
);
end
endtask
// ========================================================
// Read Monitor
// ========================================================
always @(posedge rd_clk) begin
if (m_valid && m_ready) begin
$display(
"[READ ] Time=%0t Data=%02h Corrected=%b Error=%b",
$time,
m_data,
ecc_corrected,
ecc_error
);
end
end
// ========================================================
// Main Test
// ========================================================
integer i;
initial begin
wait(wr_rst_n && rd_rst_n);
#20;
// Enable output
m_ready = 1'b1;
// ----------------------------------------------------
// Basic FIFO test
// ----------------------------------------------------
$display("");
$display("========================================");
$display("BASIC FIFO TEST");
$display("========================================");
for (i = 0; i < 10; i = i + 1) begin
write_data(8'h10 + i);
end
// ----------------------------------------------------
// Backpressure test
// ----------------------------------------------------
$display("");
$display("========================================");
$display("BACKPRESSURE TEST");
$display("========================================");
m_ready = 1'b0;
#100;
m_ready = 1'b1;
// ----------------------------------------------------
// More data
// ----------------------------------------------------
$display("");
$display("========================================");
$display("ADDITIONAL DATA TEST");
$display("========================================");
for (i = 0; i < 6; i = i + 1) begin
write_data(8'hA0 + i);
end
#500;
$display("");
$display("========================================");
$display("TEST COMPLETE");
$display("========================================");
$finish;
end
// ========================================================
// ECC Fault Injection
// ========================================================
//
// After some data has been written, deliberately flip
// one bit in the FIFO memory.
//
// This demonstrates single-bit correction.
// ========================================================
initial begin
wait(wr_rst_n && rd_rst_n);
#120;
$display("");
$display("========================================");
$display("ECC SINGLE-BIT FAULT INJECTION");
$display("========================================");
// Flip one encoded bit
dut.mem[2][3] = ~dut.mem[2][3];
$display(
"Injected single-bit error into FIFO memory"
);
end
// ========================================================
// Waveform Dump
// ========================================================
initial begin
$dumpfile("async_fifo_ecc.vcd");
$dumpvars(0, tb_async_fifo_ecc);
end
endmodule