Skip to content

Instantly share code, notes, and snippets.

@sagar5258
Created November 6, 2018 02:56
Show Gist options
  • Select an option

  • Save sagar5258/2e39d35e4e91b2ebcfaa81afe0783c19 to your computer and use it in GitHub Desktop.

Select an option

Save sagar5258/2e39d35e4e91b2ebcfaa81afe0783c19 to your computer and use it in GitHub Desktop.
class my_seq_item extends uvm_sequence_item;
rand bit [31:0] data;
rand bit [7:0] addr;
`uvm_object_utils_begin(my_seq_item)
`uvm_field_int(addr, UVM_DEFAULT | UVM_HEX)
`uvm_field_int(data, UVM_DEFAULT | UVM_HEX)
`uvm_object_utils_end
function new (string name = "my_seq_item");
super.new(name);
endfunction : new
function string convert2string();
convert2string = $sformatf("addr:0x%h, data:0x%h", addr, data);
return convert2string;
endfunction : convert2string
endclass : my_seq_item
class my_seq extends uvm_sequence#(my_seq_item);
`uvm_object_utils(my_seq)
function new (string name = "my_seq");
super.new(name);
endfunction : new
task body();
`uvm_create(req)
start_item(req);
if (!req.randomize()) begin
`uvm_fatal(get_name(), $sformatf("Randomization of %s failed", req.get_type_name()))
end
finish_item(req);
endtask : body
endclass : my_seq
class my_seqr extends uvm_sequencer#(my_seq_item);
`uvm_component_utils(my_seqr)
function new (string name = "my_seqr", uvm_component parent = null);
super.new(name, parent);
endfunction : new
endclass : my_seqr
class my_driver extends uvm_driver#(my_seq_item);
`uvm_component_utils(my_driver)
function new (string name = "my_driver", uvm_component parent = null);
super.new(name, parent);
endfunction : new
function void build_phase(uvm_phase phase);
super.build_phase(phase);
endfunction : build_phase
task run_phase(uvm_phase phase);
forever begin
seq_item_port.get_next_item(req);
drive(phase);
seq_item_port.item_done();
end
endtask : run_phase
task drive(uvm_phase phase);
phase.raise_objection(this);
#5;
`uvm_info(get_name(), $sformatf("in drive method req:\n%s", req.convert2string()), UVM_LOW)
// Objection is not dropped
//phase.drop_objection(this);
endtask : drive
endclass : my_driver
class my_agent extends uvm_agent;
my_seqr seqr;
my_driver drv;
`uvm_component_utils(my_agent)
function new (string name = "my_agent", uvm_component parent = null);
super.new(name, parent);
endfunction : new
function void build_phase(uvm_phase phase);
super.build_phase(phase);
seqr = my_seqr :: type_id :: create ("seqr", this);
drv = my_driver :: type_id :: create ("drv", this);
endfunction : build_phase
function void connect_phase (uvm_phase phase);
super.connect_phase(phase);
drv.seq_item_port.connect(seqr.seq_item_export);
endfunction : connect_phase
endclass : my_agent
class my_test extends uvm_test;
my_agent agent;
`uvm_component_utils(my_test)
function new (string name = "my_test", uvm_component parent = null);
super.new(name, parent);
endfunction : new
function void build_phase(uvm_phase phase);
super.build_phase(phase);
agent = my_agent :: type_id :: create ("agent", this);
endfunction : build_phase
task run_phase(uvm_phase phase);
my_seq seq;
fork
begin
#50; //Timer
drop_all_objection(phase);
end
join_none
seq = my_seq :: type_id :: create("seq");
phase.raise_objection(this);
seq.start(agent.seqr);
phase.drop_objection(this);
endtask : run_phase
function void drop_all_objection(uvm_phase phase);
uvm_objection objection;
uvm_object object_q[$];
// Get objection handle for current phase
objection = phase.get_objection();
// Get list of the uvm_components which doesn't drop the objection
objection.get_objectors(object_q);
// Dropping all the objection from all the objectors
foreach(object_q[i]) begin
while (objection.get_objection_count(object_q[i]) > 0) begin
`uvm_info(get_type_name(),$sformatf("Dropping objection:%0d for object:%s", i, object_q[i].get_full_name()), UVM_LOW)
objection.drop_objection(object_q[i]);
end
end
endfunction : drop_all_objection
endclass : my_test
module top();
initial begin
run_test("my_test");
end
endmodule : top
//Output:
// UVM_INFO @ 0: reporter [RNTST] Running test my_test...
// UVM_INFO drop_all_objection.sv(67) @ 5: uvm_test_top.agent.drv [drv] in drive method req:
// addr:0x82, data:0x5455120d
// UVM_INFO drop_all_objection.sv(137) @ 50: uvm_test_top [my_test] Dropping objection:1 for object:uvm_test_top.agent.drv
// UVM_INFO /opt/uvm-1.2/src/base/uvm_objection.svh(1270) @ 50: reporter [TEST_DONE] 'run' phase is ready to proceed to the 'extract' phase
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment