In reply to Kamran:
Driver code:
class mem_driver extends uvm_driver #(mem_seq_item);
`uvm_component_utils(mem_driver)
// Virtual Interface
virtual mem_if intf;
mem_seq_item item;
// Constructor
function new (string name = "mem_driver", uvm_component parent);
super.new(name, parent);
endfunction : new
function void build_phase(uvm_phase phase);
super.build_phase(phase);
if(!uvm_config_db #(virtual mem_if)::get(null,"*","vif",intf))
begin
`uvm_error("Driver Class","Failed to get vif from config_db")
end
endfunction: build_phase
function void connect_phase(uvm_phase phase);
super.connect_phase(phase);
`uvm_info("DRIVER_CLASS", "Connect Phase!", UVM_HIGH)
endfunction: connect_phase
// run phase
task run_phase(uvm_phase phase);
item = mem_seq_item::type_id::create("item");
super.run_phase(phase);
`uvm_info("DRIVER_CLASS", "Inside Run Phase!", UVM_HIGH)
forever begin
seq_item_port.get_next_item(item);
drive(item);
seq_item_port.item_done();
end
endtask : run_phase
// drive
virtual task drive(mem_seq_item item);
`uvm_info(get_type_name(), "before Posedge", UVM_MEDIUM)
@(posedge intf.a,intf.b,intf.cin)
`uvm_info(get_type_name(), "before Posedge", UVM_MEDIUM)
if(intf.a==8'bxxxxxxxx && intf.b==8'bxxxxxxxx && intf.cin==1'bx)
begin
intf.a = item.a;
intf.b = item.b;
intf.cin = item.cin;
end
`uvm_info(get_type_name(),"Before Dont care",UVM_NONE)
`uvm_info(get_type_name(),$sformatf("a =%d,b=%d,cin=%d",intf.a,intf.b,intf.cin),UVM_NONE)
if(intf.a != 8'bxxxxxxxx && intf.b != 8'bxxxxxxxx && intf.cin != 1'bx)
begin
intf.a = item.a;
intf.b = item.b;
intf.cin = item.cin;
end
`uvm_info(get_type_name(),"After Dont care",UVM_NONE)
`uvm_info(get_type_name(),$sformatf("a =%d,b=%d,cin=%d",intf.a,intf.b,intf.cin),UVM_NONE)
$display("------------------------------------------------------------------");
endtask : drive
endclass : mem_driver
Monitor1 code:
class mem_monitor extends uvm_monitor;
`uvm_component_utils(mem_monitor)
// Virtual Interface
virtual mem_if intf;
bit[7:0] q[$]; // a
//bit[7:0] q2[$]; // b
//bit q3[$]; //cin
uvm_analysis_port #(mem_seq_item) item_collected_port; // port for mon to scb
mem_seq_item item;
// new - constructor
function new (string name = "mem_monitor", uvm_component parent);
super.new(name, parent);
item_collected_port = new("item_collected_port", this);
endfunction : new
function void build_phase(uvm_phase phase);
super.build_phase(phase);
if(!uvm_config_db #(virtual mem_if)::get(null,"*","vif",intf))
begin
`uvm_error("Monitor1 Class","Failed to get vif from config_db")
end
endfunction: build_phase
//connect
function void connect_phase(uvm_phase phase);
super.connect_phase(phase);
`uvm_info("MONITOR1_CLASS", "Connect Phase!", UVM_NONE)
endfunction: connect_phase
// run phase
task run_phase(uvm_phase phase);
item = mem_seq_item::type_id::create("item");
super.run_phase(phase);
forever begin
//sample inputs
`uvm_info(get_type_name(), "before Posedge", UVM_MEDIUM)
@(posedge intf.a,intf.b,intf.cin)
`uvm_info(get_type_name(), "after Posedge", UVM_MEDIUM)
if(intf.a==8'bxxxxxxxx && intf.b==8'bxxxxxxxx && intf.cin==1'bx)
begin
item.a = intf.a ;
item.b = intf.b;
item.cin = intf.cin;
end
`uvm_info(get_type_name(),"Before Dont Care",UVM_NONE)
if(intf.a != 8'b00000000 && intf.b != 8'b00000000 && intf.cin != 1'b0)
begin
item.a = intf.a ;
item.b = intf.b;
item.cin = intf.cin;
end
`uvm_info(get_type_name(),"After Dont care",UVM_NONE)
q.push_front(item.a);
q.push_front(item.b);
q.push_front(item.cin);
if(intf.a== 8'bxxxxxxxx && intf.b== 8'bxxxxxxxx && intf.cin == 1'bx )
begin
item.s=8'bxxxxxxxx;
item.cout = 1'bx;
end
else
begin
item.s=q.pop_front();
item.cout=q.pop_front();
end
`uvm_info(get_type_name(),$sformatf("a =%d,b=%d,cin=%d",intf.a,intf.b,intf.cin),UVM_NONE)
`uvm_info(get_type_name(),"------------------------------------------------------",UVM_NONE)
item_collected_port.write(item);
end
endtask : run_phase
endclass : mem_monitor
My output log is: