-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfifo_buffer_tb.v
More file actions
120 lines (95 loc) · 2.03 KB
/
Copy pathfifo_buffer_tb.v
File metadata and controls
120 lines (95 loc) · 2.03 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
// Testbench for the FIFO memory module. During the
// test, it fills with the cyclic generated data, and
// after that, all the data is read from the module
// and automatically checked.
`timescale 1us / 1ns
module fifo_buffer_tb;
// Testbench uses a 1 MHz clock
parameter CLK_PERIOD = 1.0; // In us
parameter ENDSIM = 100;
reg clock;
reg reset;
reg write_enable;
reg [23:0] data_in;
reg read_enable;
wire [23:0] data_out;
wire full;
wire empty;
integer i = 0;
// Test module
fifo_buffer fifo_buffer_dut (
.clock (clock),
.reset (reset),
// Write and read data ports
.write_data (write_enable),
.data_in (data_in),
.read_data (read_enable),
.data_out (data_out),
// Status outputs
.full (full),
.empty (empty)
);
// Clock signal
always #(CLK_PERIOD/2) clock <= ~clock;
// Initialisation
task init();
begin
clock <= 0;
reset <= 0;
write_enable <= 0;
read_enable <= 0;
data_in <= 0;
end
endtask
// Reset
task reset_pulse();
begin
#(CLK_PERIOD) reset <= 1;
#(CLK_PERIOD) reset <= 0;
#(CLK_PERIOD/2);
end
endtask
// Write data in the fifo module untill it full
task write_data();
begin
write_enable <= 1;
data_in <= 0;
for (i=0; i<31; i=i+1) begin
#(CLK_PERIOD);
data_in <= data_in + 1'b1;
end
write_enable <= 0;
data_in <= 0;
end
endtask
// Read some data and compare wthem
task read_data();
begin
read_enable <= 1;
data_in <= 0;
for (i=0; i<34; i=i+1) begin
if (!empty) begin
// Check readed data
if (data_out == data_in) $display("Readed data okay.");
else $display("Error!");
// Calculate data to compare
data_in <= data_in + 1'b1;
end else begin
read_enable <= 0;
$display("Buffer is empty");
end
#(CLK_PERIOD);
end
read_enable <= 0;
end
endtask
// Main simulation cycle
initial begin
init();
reset_pulse();
write_data();
#(CLK_PERIOD);
read_data();
$stop(ENDSIM);
end
endmodule