-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaxi_agent.sv
307 lines (257 loc) · 8.38 KB
/
axi_agent.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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
class axi_tx extends uvm_sequence_item;
rand bit [3:0] txid;
rand bit [31:0] addr;
rand bit [31:0] dataQ[$];
rand bit [31:0] strbQ[$];
rand bit wr_rd;
rand bit [3:0] burst_len; // 0->1 beat, 1-> 2 beats, so on
rand burst_type_t burst_type;
rand bit [2:0] burst_size;
// rand lock_t lock;
rand bit [1:0] resp;
// valid => handshaking signals should never be party of tx
// prot,cache,lock
`uvm_object_utils_begin(axi_tx)
`uvm_field_int(txid,UVM_ALL_ON)
`uvm_field_int(addr,UVM_ALL_ON)
`uvm_field_queue_int(dataQ,UVM_ALL_ON)
`uvm_field_queue_int(strbQ,UVM_ALL_ON)
`uvm_field_int(wr_rd,UVM_ALL_ON)
`uvm_field_int(burst_len,UVM_ALL_ON)
`uvm_field_enum(burst_type_t,burst_type,UVM_ALL_ON)
`uvm_field_int(burst_size,UVM_ALL_ON)
// // `uvm_field_enum(lock_t,lock,UVM_ALL_ON)
`uvm_field_int(resp,UVM_ALL_ON)
`uvm_object_utils_end
`NEW_OBJ // function new definition
// constraints
constraint dataQ_c {
dataQ.size() == burst_len + 1;
strbQ.size() == burst_len + 1;
}
constraint rsvd_c {
burst_type != RSVD_BT;
// lock != RSVD_LK;
}
constraint soft_c {
soft burst_type == INCR; // default tx type
soft burst_size == 2; // 4 bytes per beat
soft burst_len == 1; // 1 beat per tx
// soft lock == NORMAL; // 4 bytes per beat
soft addr%4 == 0; // Tx is 32 bit aligned
soft wr_rd == 1;
}
endclass
//////////////////////////////////////////////////
class axi_drv extends uvm_driver#(axi_tx);
virtual axi_intf vif;
`uvm_component_utils(axi_drv)
`NEW_COMP
function void build_phase(uvm_phase phase);
super.build_phase(phase);
if (!uvm_resource_db#(virtual axi_intf)::read_by_type("AXI", vif, this)) begin
`uvm_error("RESOURCE_DB_ERROR", "Not able to retrive axi_vif")
end
endfunction
task run_phase(uvm_phase phase);
wait (vif.bfm_cb.arst == 0);
forever begin
seq_item_port.get_next_item(req);
drive_tx(req); //drive the AHB interface with this request
seq_item_port.item_done(); //I am done with this item
end
endtask
//AXI timing diagram is implemented
task drive_tx(axi_tx tx);
if (tx.wr_rd == 1) begin
write_addr(tx);
write_data(tx);
write_resp(tx);
end
else begin
read_addr(tx);
read_data(tx);
end
endtask
task write_addr(axi_tx tx);
`uvm_info("AXI_WR", "write_addr", UVM_LOW)
@(vif.bfm_cb);
vif.bfm_cb.awvalid <= 1;
vif.bfm_cb.awaddr <= tx.addr;
vif.bfm_cb.awlen <= tx.burst_len;
vif.bfm_cb.awsize <= tx.burst_size;
vif.bfm_cb.awburst <= tx.burst_type;
vif.bfm_cb.awid <= tx.txid;
wait (vif.bfm_cb.awready == 1);
@(vif.bfm_cb);
vif.bfm_cb.awvalid <= 0;
vif.bfm_cb.awaddr <= 0;
vif.bfm_cb.awlen <= 0;
vif.bfm_cb.awsize <= 0;
vif.bfm_cb.awburst <= 0;
vif.bfm_cb.awid <= 0;
endtask
task write_data(axi_tx tx);
`uvm_info("AXI_WR", "write_data", UVM_LOW)
for (int i = 0; i < tx.burst_len+1; i++) begin
@(vif.bfm_cb);
vif.bfm_cb.wid <= tx.txid;
vif.bfm_cb.wdata <= tx.dataQ.pop_front();
vif.bfm_cb.wstrb <= tx.strbQ.pop_front();
vif.bfm_cb.wvalid <= 1;
if (i == tx.burst_len) vif.bfm_cb.wlast <= 1'b1;
wait (vif.bfm_cb.wready == 1);
end
@(vif.bfm_cb);
vif.bfm_cb.wid <= 0;
vif.bfm_cb.wdata <= 0;
vif.bfm_cb.wstrb <= 0;
vif.bfm_cb.wvalid <= 0;
vif.bfm_cb.wlast <= 1'b0;
endtask
task write_resp(axi_tx tx);
`uvm_info("AXI_WR", "write_resp", UVM_LOW)
while (vif.bfm_cb.bvalid == 1'b0) begin
@(vif.bfm_cb);
end
vif.bfm_cb.bready <= 1;
@(vif.bfm_cb);
vif.bfm_cb.bready <= 0;
endtask
task read_addr(axi_tx tx);
`uvm_info("AXI_RD", "read_addr", UVM_LOW)
@(vif.bfm_cb);
vif.bfm_cb.arvalid <= 1;
vif.bfm_cb.araddr <= tx.addr;
vif.bfm_cb.arlen <= tx.burst_len;
vif.bfm_cb.arsize <= tx.burst_size;
vif.bfm_cb.arburst <= tx.burst_type;
vif.bfm_cb.arid <= tx.txid;
wait (vif.bfm_cb.arready == 1);
@(vif.bfm_cb);
vif.bfm_cb.arvalid <= 0;
vif.bfm_cb.araddr <= 0;
vif.bfm_cb.arlen <= 0;
vif.bfm_cb.arsize <= 0;
vif.bfm_cb.arburst <= 0;
vif.bfm_cb.arid <= 0;
endtask
task read_data(axi_tx tx);
for (int i = 0; i <= tx.burst_len; i++) begin
`uvm_info("AXI_RD", "read_data", UVM_LOW)
@(vif.bfm_cb);
vif.bfm_cb.rready <= 1;
wait (vif.bfm_cb.rvalid == 1'b1);
end
@(vif.bfm_cb);
@(vif.bfm_cb); //why this is required?
vif.bfm_cb.rready <= 0;
@(vif.bfm_cb); //wait 1 clock cycles before starting new tx
endtask
task set_default_values();
endtask
endclass
//////////////////////////////////////////////////
typedef uvm_sequencer#(axi_tx) axi_sqr;
//////////////////////////////////////////////////
class axi_mon extends uvm_monitor;
virtual axi_intf vif;
axi_tx tx;
uvm_analysis_port#(axi_tx) ap_port;
`uvm_component_utils(axi_mon)
`NEW_COMP
function void build_phase(uvm_phase phase);
super.build_phase(phase);
if (!uvm_resource_db#(virtual axi_intf)::read_by_type("AXI", vif, this)) begin
`uvm_error("RESOURCE_DB_ERROR", "Not able to retrive axi_vif")
end
ap_port = new("ap_port",this);
endfunction
task run_phase(uvm_phase phase);
wait (vif.mon_cb.arst == 0);
forever begin
@(vif.mon_cb);
if (vif.mon_cb.awvalid && vif.mon_cb.awready) begin
tx = axi_tx::type_id::create("tx");
tx.wr_rd = 1'b1;
tx.txid = vif.mon_cb.awid;
tx.addr = vif.mon_cb.awaddr;
tx.burst_len = vif.mon_cb.awlen;
tx.burst_type = burst_type_t'(vif.mon_cb.awburst);
tx.burst_size = vif.mon_cb.awsize;
$display("%t : AXI_MON - Completed write address phase",$time);
end
if (vif.mon_cb.wvalid && vif.mon_cb.wready) begin
tx.dataQ.push_back(vif.mon_cb.wdata);
tx.strbQ.push_back(vif.mon_cb.wstrb);
$display("%t : AXI_MON - Completed write data phase",$time);
end
if (vif.mon_cb.bvalid && vif.mon_cb.bready) begin
tx.resp = vif.mon_cb.bresp;
ap_port.write(tx);
$display("%t : AXI_MON - Completed write response phase",$time);
tx.print();
end
if (vif.mon_cb.arvalid && vif.mon_cb.arready) begin
tx = axi_tx::type_id::create("tx");
tx.wr_rd = 1'b0;
tx.txid = vif.mon_cb.arid;
tx.addr = vif.mon_cb.araddr;
tx.burst_len = vif.mon_cb.arlen;
tx.burst_type = vif.mon_cb.arburst;
tx.burst_size = vif.mon_cb.arsize;
end
if (vif.mon_cb.rvalid && vif.mon_cb.rready) begin
tx.dataQ.push_back(vif.mon_cb.rdata);
tx.resp = vif.mon_cb.rresp;
if (vif.mon_cb.rlast == 1) begin
ap_port.write(tx);
end
end
end
endtask
endclass
//////////////////////////////////////////////////
class axi_cov extends uvm_subscriber#(axi_tx);
axi_tx tx;
`uvm_component_utils(axi_cov);
covergroup tl_axi_cg;
PAYLOAD_SIZE_CP : coverpoint tx.dataQ[0] iff (tx.addr == 32'h1018) {
bins PAYLOAD_SIZE_128 = {128};
bins PAYLOAD_SIZE_256 = {256};
bins PAYLOAD_SIZE_512 = {512};
bins PAYLOAD_SIZE_1024 = {1024};
bins PAYLOAD_SIZE_2048 = {2048};
bins PAYLOAD_SIZE_4096 = {4096};
}
endgroup
function new(string name, uvm_component parent);
super.new(name,parent);
tl_axi_cg = new();
endfunction //new()
function void write(axi_tx t);
$cast (tx,t);
tl_axi_cg.sample();
endfunction
endclass
//////////////////////////////////////////////////
class axi_agent extends uvm_test;
axi_drv drv;
axi_sqr sqr;
axi_mon mon;
axi_cov cov;
`uvm_component_utils(axi_agent);
function new(string name, uvm_component parent);
super.new(name,parent);
endfunction //new()
function void build_phase(uvm_phase phase);
drv = axi_drv::type_id::create("drv",this);
sqr = axi_sqr::type_id::create("sqr",this);
mon = axi_mon::type_id::create("mon",this);
cov = axi_cov::type_id::create("cov",this);
endfunction
function void connect_phase(uvm_phase phase);
drv.seq_item_port.connect(sqr.seq_item_export);
mon.ap_port.connect(cov.analysis_export);
endfunction
endclass