Skip to content

Commit 1befe5f

Browse files
Create apb_wmonitor.sv
1 parent 14ca8f8 commit 1befe5f

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

apb_wmonitor.sv

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
class apb_wmonitor extends uvm_monitor;
2+
`uvm_component_utils(apb_wmonitor)
3+
4+
5+
apb_transaction trans;
6+
virtual apb_if vif;
7+
uvm_analysis_port#(apb_transaction) wap;
8+
int pr_addr = 0, pa_addr = 0;
9+
integer pr_data, pa_data;
10+
int write_count =0;
11+
12+
//Constructor
13+
function new(string name ="apb_wmonitor", uvm_component parent = null);
14+
super.new(name, parent);
15+
wap = new("wap", this);
16+
endfunction
17+
18+
//Build Phase
19+
function void build_phase(uvm_phase phase);
20+
super.build_phase(phase);
21+
if(!uvm_config_db#(virtual apb_if)::get(this,"","vif",vif)) begin
22+
`uvm_error("build_phase","driver virtual interface failed")
23+
end
24+
25+
endfunction
26+
27+
//Run Phase
28+
task run_phase(uvm_phase phase);
29+
//Creating new transaction object
30+
trans = apb_transaction::type_id::create("trans");
31+
32+
forever begin
33+
//wait for rising edge of clock
34+
@(posedge vif.PCLK) begin
35+
36+
37+
while((!vif.PSEL && !vif.PENABLE) || !vif.PWRITE) begin // wait untill PSEL or PENABLE is not 1
38+
@(posedge vif.PCLK)
39+
`uvm_info("WMONITOR",$sformatf("Wating for write mode or PSEL or PENABLE is not high PSEL =%0d, PENABLE =%0d, PWRITE =%0d",vif.PSEL,vif.PENABLE,vif.PWRITE),UVM_LOW)
40+
end
41+
42+
trans.PRESET = vif.PRESET;
43+
trans.PADDR = vif.PADDR;
44+
trans.PWDATA = vif.PWDATA;
45+
trans.PWRITE = vif.PWRITE;
46+
trans.PSEL = vif.PSEL;
47+
trans.PREADY = vif.PREADY;
48+
trans.PSLVERR = vif.PSLVERR;
49+
trans.PENABLE = vif.PENABLE;
50+
51+
52+
pr_data = trans.PWDATA;
53+
pr_addr = trans.PADDR;
54+
if((pr_addr != pa_addr) || pr_data !== pa_data) begin
55+
//Pass the transaction to analysis port
56+
`uvm_info("WMONITOR",$sformatf("Sent Transaction to SB: PRESET =%0d, PSEL =%0d, PWRITE =%0d, PENABLE =%0d, ADDR =%0d, PWDATA =%0d, PREADY =%0d PSLERR = %0d", trans.PRESET,trans.PSEL,trans.PWRITE,trans.PENABLE,trans.PADDR,trans.PWDATA,trans.PREADY,trans.PSLVERR),UVM_LOW)
57+
wap.write(trans);
58+
pa_addr = pr_addr;
59+
pa_data = pr_data;
60+
end
61+
else
62+
`uvm_info("WMONITOR",$sformatf("Writing same data on same address"),UVM_LOW)
63+
//wait for the write transaction to complete
64+
while(!vif.PREADY && write_count<=10) begin
65+
@(posedge vif.PCLK);
66+
`uvm_info("WMONITOR",$sformatf("Ready signal is not high"),UVM_LOW)
67+
write_count++; end
68+
69+
if(write_count>10) begin
70+
`uvm_error("WMONITOR", "Ready signal was not high since 10 clock cycle")
71+
write_count =0; end
72+
73+
end
74+
#1;
75+
end
76+
endtask
77+
endclass
78+
79+

0 commit comments

Comments
 (0)