-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathASYNCH_FIFO_TB.v
164 lines (128 loc) · 3.04 KB
/
ASYNCH_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
`timescale 1ns/1ps
module ASYNCH_FIFO_TB ();
parameter PTR_WIDTH_TB=4;
parameter WIDTH_TB=8;
parameter reading_clk_period=25;
parameter writing_clk_period=10;
parameter burst_length=10;
parameter FIFO_MIN_DEPTH=6;
reg W_CLK_TB;
reg W_RST_TB;
reg W_INC_TB;
reg R_CLK_TB;
reg R_RST_TB;
reg R_INC_TB;
reg [WIDTH_TB-1:0] WR_DATA_TB;
wire [WIDTH_TB-1:0] RD_DATA_TB;
wire FULL_TB;
wire EMPTY_TB;
//top module instantiation
ASYNCH_FIFO DUT
(
.W_CLK(W_CLK_TB),
.W_RST(W_RST_TB),
.W_INC(W_INC_TB),
.R_CLK(R_CLK_TB),
.R_RST(R_RST_TB),
.R_INC(R_INC_TB),
.WR_DATA(WR_DATA_TB),
.RD_DATA(RD_DATA_TB),
.FULL(FULL_TB),
.EMPTY(EMPTY_TB)
);
/*
task set_fifo depth;
begin
end
endtask
*/
//reading clock generation//
always #(reading_clk_period/2) R_CLK_TB=~R_CLK_TB;
//writing clock generation//
always #(writing_clk_period/2) W_CLK_TB=~W_CLK_TB;
// tasks
task reset_write;
begin
#(writing_clk_period)
W_RST_TB='b0;
#(writing_clk_period)
W_RST_TB='b1;
#(writing_clk_period);
end
endtask
task reset_read;
begin
#(reading_clk_period)
R_RST_TB='b0;
#(reading_clk_period)
R_RST_TB='b1;
#(reading_clk_period);
end
endtask
task intialize ;
begin
W_CLK_TB=1'b0;
W_RST_TB=1'b1;
W_INC_TB=1'b0; //only intializing the inputs
R_CLK_TB=1'b0;
R_RST_TB=1'b1;
R_INC_TB=1'b0;
WR_DATA_TB=8'h00;
end
endtask
task data_writing ;
input [WIDTH_TB-1:0] data_in;
begin
WR_DATA_TB = data_in;
W_INC_TB=1'b1;
#(writing_clk_period)
W_INC_TB=1'b0;
end
endtask
task data_reading;
begin
R_INC_TB=1'b1;
#(reading_clk_period)
R_INC_TB=1'b0;
end
endtask
initial
begin
intialize (); //intialize the inputs
reset_write(); //reset the write operation
reset_read();//reset the write operation
data_writing(8'hA3);
data_writing(8'hB4);
data_writing(8'h1D);
data_writing(8'hA3);
// Check for FULL flag
if (FULL_TB) $display("Test failed: FULL flag should not be set.");
else $display("Test passed: FULL flag is not set.");
//reading the inserted data
repeat (4) begin
data_reading();
$display("Read Data: %h", RD_DATA_TB);
end
// Check for EMPTY flag
if (EMPTY_TB) $display("Test passed: EMPTY flag is set after reading all data.");
else $display("Test failed: EMPTY flag should be set after reading all data.");
//inserting new data
data_writing(8'h3A);
data_writing(8'h2D);
data_writing(8'h4B);
data_writing(8'hA5);
data_writing(8'h22);
data_writing(8'h3F);
data_writing(8'h45);
data_writing(8'h35);
data_writing(8'h55);
// Check if FULL flag is set
if (FULL_TB) $display("Test passed: FULL flag is set on overflow.");
else $display("Test failed: FULL flag should be set on overflow.");
reset_write();
reset_read();
if (EMPTY_TB) $display("Test passed: FIFO reset correctly, EMPTY flag is set.");
else $display("Test failed: FIFO reset did not clear correctly.");
$stop;
end
endmodule