-
Notifications
You must be signed in to change notification settings - Fork 23
/
tb_gzip_compressor.v
174 lines (150 loc) · 7.43 KB
/
tb_gzip_compressor.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
module tb_gzip_compressor ();
//initial $dumpvars(1, tb_gzip_compressor);
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
// signals
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
reg clk = 1'b0;
always #5 clk = ~clk;
wire i_tready;
wire i_tvalid;
wire [ 7:0] i_tdata;
wire i_tlast;
reg o_tready = 1'b0;
wire o_tvalid;
wire [31:0] o_tdata;
wire o_tlast;
wire [ 3:0] o_tkeep;
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
// let simulation end when AXI stream have no any actions for a long time
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
reg [31:0] count = 0;
always @ (posedge clk)
if (i_tvalid === 1'b1 || o_tvalid === 1'b1) begin
count <= 0;
end else if (count < 100000) begin
count <= count + 1;
end else begin
$stop;
end
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
// generate random data packets to input to gzip_compressor_top
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
tb_random_data_source u_tb_random_data_source (
.clk ( clk ),
.tready ( i_tready ),
.tvalid ( i_tvalid ),
.tdata ( i_tdata ),
.tlast ( i_tlast )
);
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
// design under test
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
gzip_compressor_top # (
.SIMULATION ( 1 )
) u_gzip_compressor (
.rstn ( 1'b1 ),
.clk ( clk ),
.i_tready ( i_tready ),
.i_tvalid ( i_tvalid ),
.i_tdata ( i_tdata ),
.i_tlast ( i_tlast ),
.o_tready ( o_tready ),
.o_tvalid ( o_tvalid ),
.o_tdata ( o_tdata ),
.o_tlast ( o_tlast ),
.o_tkeep ( o_tkeep )
);
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
// save output stream of gzip_compressor_top to files, getting .gz files
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
tb_save_result_to_file u_tb_save_result_to_file (
.clk ( clk ),
.tready ( o_tready ),
.tvalid ( o_tvalid ),
.tdata ( o_tdata ),
.tlast ( o_tlast ),
.tkeep ( o_tkeep )
);
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
// calculate and print CRC32 of input data stream. You can compare this CRC with the CRC of the saved. gz file
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
tb_print_crc32 u_tb_print_crc32 (
.clk ( clk ),
.tready ( i_tready ),
.tvalid ( i_tvalid ),
.tdata ( i_tdata ),
.tlast ( i_tlast )
);
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
// generate different tready behavior for output stream of gzip_compressor_top, to simulate receiver's handshake
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
initial begin
while (1) begin
repeat ( 1000000 ) begin
@ (posedge clk);
o_tready <= 1'b1;
end
repeat ( 500000 ) begin
repeat (1) begin
@ (posedge clk);
o_tready <= 1'b0;
end
@ (posedge clk);
o_tready <= 1'b1;
end
repeat ( 200000 ) begin
repeat (2) begin
@ (posedge clk);
o_tready <= 1'b0;
end
@ (posedge clk);
o_tready <= 1'b1;
end
repeat ( 50000 ) begin
repeat (10) begin
@ (posedge clk);
o_tready <= 1'b0;
end
@ (posedge clk);
o_tready <= 1'b1;
end
repeat ( 10000 ) begin
repeat (50) begin
@ (posedge clk);
o_tready <= 1'b0;
end
@ (posedge clk);
o_tready <= 1'b1;
end
end
end
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
// assert AXI stream behavior
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
tb_assert_axi_stream #(
.ASSERT_SENDER_NOT_CHANGE_WHEN_HANDSHAKE_FAILED ( 1 ),
.ASSERT_RECEIVER_NOT_CHANGE_WHEN_HANDSHAKE_FAILED ( 1 ),
.DWIDTH ( 8 )
) u_tb_assert_axi_stream_input (
.rstn ( 1'b1 ),
.clk ( clk ),
.tready ( i_tready ),
.tvalid ( i_tvalid ),
.tdata ( i_tdata ),
.tlast ( i_tlast ),
.tkeep ( 1'b1 )
);
tb_assert_axi_stream #(
.ASSERT_SENDER_NOT_CHANGE_WHEN_HANDSHAKE_FAILED ( 1 ),
.ASSERT_RECEIVER_NOT_CHANGE_WHEN_HANDSHAKE_FAILED ( 0 ),
.DWIDTH ( 32 )
) u_tb_assert_axi_stream_output (
.rstn ( 1'b1 ),
.clk ( clk ),
.tready ( o_tready ),
.tvalid ( o_tvalid ),
.tdata ( o_tdata ),
.tlast ( o_tlast ),
.tkeep ( o_tkeep )
);
endmodule