Skip to content

Instantly share code, notes, and snippets.

@sagar5258
Created November 6, 2018 03:05
Show Gist options
  • Save sagar5258/98b5f9d6285668f75842da4c89aae4db to your computer and use it in GitHub Desktop.
Save sagar5258/98b5f9d6285668f75842da4c89aae4db 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)
//Dropping objection from driver after #105 timeunit
fork
begin
#100;
`uvm_info(get_name(), $sformatf("in drive, dropping objection"), UVM_LOW)
phase.drop_objection(this);
end
join_none
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
// After #50 timeunit wants to move to next phase (extract_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 extract_phase(uvm_phase phase);
// Expecting to execute at timeunit #50, but executing at #105
`uvm_info(get_name(), $sformatf("Executing extract_phase"), UVM_LOW)
endfunction : extract_phase
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 objection_dropped_after_timeout.sv(67) @ 5: uvm_test_top.agent.drv [drv] in drive method req:
// addr:0x82, data:0x5455120d
// UVM_INFO objection_dropped_after_timeout.sv(73) @ 105: uvm_test_top.agent.drv [drv] in drive, dropping objection
// UVM_INFO /opt/uvm-1.2/src/base/uvm_objection.svh(1270) @ 105: reporter [TEST_DONE] 'run' phase is ready to proceed to the 'extract' phase
// UVM_INFO objection_dropped_after_timeout.sv(132) @ 105: uvm_test_top [uvm_test_top] Executing extract_phase
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment