-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfifo_test1.v
132 lines (124 loc) · 2.3 KB
/
fifo_test1.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
module test_fifo #(
parameter integer C_DATA_WIDTH = 8,
parameter integer C_FIFO_DEPTH = 1
) ();
reg clk = 0;
reg resetn = 0;
wire read_valid;
reg read_ready;
wire [C_DATA_WIDTH-1:0] read_data;
reg write_valid;
wire write_ready;
reg [C_DATA_WIDTH-1:0] write_data;
wire full;
wire empty;
wire write_committed = write_ready && write_valid;
wire read_committed = read_ready && read_valid;
myfifo #(C_DATA_WIDTH,C_FIFO_DEPTH,0) fifo_dut(
.clk(clk),
.resetn(resetn),
.read_valid(read_valid),
.read_ready(read_ready),
.read_data(read_data),
.write_valid(write_valid),
.write_ready(write_ready),
.write_data(write_data),
.full(full),
.empty(empty)
);
reg disp_log = 0;
always begin
#5
clk <= ~clk;
end
always @ (posedge resetn) begin
$display("reset released");
end
always @ (posedge clk) begin
if(disp_log) begin
$display("===> clk");
if(empty) $display("empty");
if(full) $display("full");
if(write_committed) $display("write : %c",write_data);
if(read_committed) $display("read : %c",read_data);
#1
$display("----");
end
end
initial begin
$display("fifo depth is %d(%dbit)",C_FIFO_DEPTH,$clog2(C_FIFO_DEPTH));
end
initial begin
#5
disp_log = 1;
@(posedge clk) resetn = 1;
#10
@(negedge clk) begin
read_ready = 1; // this read should not work
write_data = "a";
write_valid = 1;
end
#5
@(negedge clk) begin
read_ready = 0;
write_data = "b";
write_valid = 1;
end
#5
@(negedge clk) begin
read_ready = 0;
write_data = "c";
write_valid = 1;
end
#5
@(negedge clk) begin
read_ready = 1;
write_data = "d";
write_valid = 1;
end
#5
@(negedge clk) begin
read_ready = 1;
write_data = "e";
write_valid = 0;
end
#5
@(negedge clk) begin
read_ready = 1;
write_data = "f";
write_valid = 0;
end
#5
@(negedge clk) begin
read_ready = 1;
write_data = "0";
write_valid = 0;
end
#5
@(negedge clk) begin
read_ready = 0;
write_data = "a";
write_valid = 1;
end
#5
@(negedge clk) begin
read_ready = 1;
write_data = "b";
write_valid = 1;
end
#5
@(negedge clk) begin
read_ready = 1;
write_data = "c";
write_valid = 1;
end
#5
@(negedge clk) begin
read_ready = 1;
write_data = "0";
write_valid = 0;
end
#20
$finish;
end
endmodule