forked from pulp-platform/axi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tb_axi_isolate.sv
221 lines (198 loc) · 7.07 KB
/
tb_axi_isolate.sv
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
// Copyright (c) 2019 ETH Zurich and University of Bologna.
// Copyright and related rights are licensed under the Solderpad Hardware
// License, Version 0.51 (the "License"); you may not use this file except in
// compliance with the License. You may obtain a copy of the License at
// http://solderpad.org/licenses/SHL-0.51. Unless required by applicable law
// or agreed to in writing, software, hardware and materials distributed under
// this License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
// specific language governing permissions and limitations under the License.
// Author: Wolfgang Roenninger <[email protected]>
`include "axi/typedef.svh"
`include "axi/assign.svh"
module tb_axi_isolate #(
parameter int unsigned NoWrites = 50000, // How many writes per master
parameter int unsigned NoReads = 30000 // How many reads per master
);
// Random master no Transactions
localparam int unsigned NoPendingDut = 16;
// Random Master Atomics
localparam int unsigned MaxAW = 32'd30;
localparam int unsigned MaxAR = 32'd30;
localparam bit EnAtop = 1'b1;
// timing parameters
localparam time CyclTime = 10ns;
localparam time ApplTime = 2ns;
localparam time TestTime = 8ns;
// AXI configuration
localparam int unsigned AxiIdWidth = 4;
localparam int unsigned AxiAddrWidth = 32; // Axi Address Width
localparam int unsigned AxiDataWidth = 64; // Axi Data Width
localparam int unsigned AxiUserWidth = 5;
// Sim print config, how many transactions
localparam int unsigned PrintTnx = 1000;
typedef axi_test::rand_axi_master #(
// AXI interface parameters
.AW ( AxiAddrWidth ),
.DW ( AxiDataWidth ),
.IW ( AxiIdWidth ),
.UW ( AxiUserWidth ),
// Stimuli application and test time
.TA ( ApplTime ),
.TT ( TestTime ),
// Maximum number of read and write transactions in flight
.MAX_READ_TXNS ( MaxAR ),
.MAX_WRITE_TXNS ( MaxAW ),
.AXI_ATOPS ( EnAtop )
) rand_axi_master_t;
typedef axi_test::rand_axi_slave #(
// AXI interface parameters
.AW ( AxiAddrWidth ),
.DW ( AxiDataWidth ),
.IW ( AxiIdWidth ),
.UW ( AxiUserWidth ),
// Stimuli application and test time
.TA ( ApplTime ),
.TT ( TestTime )
) rand_axi_slave_t;
// -------------
// DUT signals
// -------------
logic clk;
logic rst_n;
logic end_of_sim;
// DUT signals
logic isolate, isolated;
// interfaces
AXI_BUS #(
.AXI_ADDR_WIDTH ( AxiAddrWidth ),
.AXI_DATA_WIDTH ( AxiDataWidth ),
.AXI_ID_WIDTH ( AxiIdWidth ),
.AXI_USER_WIDTH ( AxiUserWidth )
) master ();
AXI_BUS_DV #(
.AXI_ADDR_WIDTH ( AxiAddrWidth ),
.AXI_DATA_WIDTH ( AxiDataWidth ),
.AXI_ID_WIDTH ( AxiIdWidth ),
.AXI_USER_WIDTH ( AxiUserWidth )
) master_dv (clk);
AXI_BUS #(
.AXI_ADDR_WIDTH ( AxiAddrWidth ),
.AXI_DATA_WIDTH ( AxiDataWidth ),
.AXI_ID_WIDTH ( AxiIdWidth ),
.AXI_USER_WIDTH ( AxiUserWidth )
) slave ();
AXI_BUS_DV #(
.AXI_ADDR_WIDTH ( AxiAddrWidth ),
.AXI_DATA_WIDTH ( AxiDataWidth ),
.AXI_ID_WIDTH ( AxiIdWidth ),
.AXI_USER_WIDTH ( AxiUserWidth )
) slave_dv (clk);
`AXI_ASSIGN ( master, master_dv )
`AXI_ASSIGN ( slave_dv, slave )
//-----------------------------------
// Clock generator
//-----------------------------------
clk_rst_gen #(
.CLK_PERIOD ( CyclTime ),
.RST_CLK_CYCLES( 5 )
) i_clk_gen (
.clk_o (clk),
.rst_no(rst_n)
);
//-----------------------------------
// DUT
//-----------------------------------
axi_isolate_intf #(
.NUM_PENDING ( NoPendingDut ), // number of pending requests
.AXI_ID_WIDTH ( AxiIdWidth ), // AXI ID width
.AXI_ADDR_WIDTH ( AxiAddrWidth ), // AXI address width
.AXI_DATA_WIDTH ( AxiDataWidth ), // AXI data width
.AXI_USER_WIDTH ( AxiUserWidth ) // AXI user width
) i_dut (
.clk_i ( clk ), // clock
.rst_ni ( rst_n ), // asynchronous reset active low
.slv ( master ), // slave port
.mst ( slave ), // master port
.isolate_i ( isolate ), // isolate master port from slave port
.isolated_o ( isolated ) // master port is isolated from slave port
);
initial begin : proc_axi_master
automatic rand_axi_master_t rand_axi_master = new(master_dv);
end_of_sim <= 1'b0;
rand_axi_master.add_memory_region(32'h0000_0000, 32'h1000_0000, axi_pkg::DEVICE_NONBUFFERABLE);
rand_axi_master.add_memory_region(32'h2000_0000, 32'h3000_0000, axi_pkg::WTHRU_NOALLOCATE);
rand_axi_master.add_memory_region(32'h4000_0000, 32'h5000_0000, axi_pkg::WBACK_RWALLOCATE);
rand_axi_master.reset();
@(posedge rst_n);
rand_axi_master.run(NoReads, NoWrites);
end_of_sim <= 1'b1;
repeat (10000) @(posedge clk);
$stop();
end
initial begin : proc_axi_slave
automatic rand_axi_slave_t rand_axi_slave = new(slave_dv);
rand_axi_slave.reset();
@(posedge rst_n);
rand_axi_slave.run();
end
initial begin : proc_sim_ctl
forever begin
isolate <= 1'b0;
repeat ($urandom_range(100000,1)) @(posedge clk);
isolate <= 1'b1;
repeat ($urandom_range(100000,1)) @(posedge clk);
end
end
initial begin : proc_sim_progress
automatic int unsigned aw = 0;
automatic int unsigned ar = 0;
automatic bit aw_printed = 1'b0;
automatic bit ar_printed = 1'b0;
@(posedge rst_n);
forever begin
@(posedge clk);
#TestTime;
if (master.aw_valid && master.aw_ready) begin
aw++;
end
if (master.ar_valid && master.ar_ready) begin
ar++;
end
if ((aw % PrintTnx == 0) && ! aw_printed) begin
$display("%t> Transmit AW %d of %d.", $time(), aw, NoWrites);
aw_printed = 1'b1;
end
if ((ar % PrintTnx == 0) && !ar_printed) begin
$display("%t> Transmit AR %d of %d.", $time(), ar, NoReads);
ar_printed = 1'b1;
end
if (aw % PrintTnx == 1) begin
aw_printed = 1'b0;
end
if (ar % PrintTnx == 1) begin
ar_printed = 1'b0;
end
if (end_of_sim) begin
$info("All transactions completed.");
break;
end
end
end
default disable iff (!rst_n);
aw_unstable: assert property (@(posedge clk)
(slave.aw_valid && !slave.aw_ready) |=> $stable(slave.aw_addr)) else
$fatal(1, "AW is unstable.");
w_unstable: assert property (@(posedge clk)
(slave.w_valid && !slave.w_ready) |=> $stable(slave.w_data)) else
$fatal(1, "W is unstable.");
b_unstable: assert property (@(posedge clk)
(master.b_valid && !master.b_ready) |=> $stable(master.b_resp)) else
$fatal(1, "B is unstable.");
ar_unstable: assert property (@(posedge clk)
(slave.ar_valid && !slave.ar_ready) |=> $stable(slave.ar_addr)) else
$fatal(1, "AR is unstable.");
r_unstable: assert property (@(posedge clk)
(master.r_valid && !master.r_ready) |=> $stable(master.r_data)) else
$fatal(1, "R is unstable.");
endmodule