Skip to content

Instantly share code, notes, and snippets.

@sagar5258
Created September 26, 2018 18:13
Show Gist options
  • Save sagar5258/ddc6fcb8dbacee78a74a23bcf494de75 to your computer and use it in GitHub Desktop.
Save sagar5258/ddc6fcb8dbacee78a74a23bcf494de75 to your computer and use it in GitHub Desktop.
class transaction extends uvm_sequence_item;
rand bit [7:0] data;
rand bit [31:0] addr;
`uvm_object_utils_begin(transaction)
`uvm_field_int(addr, UVM_HEX | UVM_DEFAULT)
`uvm_field_int(data, UVM_HEX | UVM_DEFAULT)
`uvm_object_utils_end
function new(string name = "transaction");
super.new(name);
endfunction : new
function string convert2string();
convert2string = $sformatf("addr:0x%h, data:0x%h", addr, data);
endfunction : convert2string
endclass : transaction
class sequencer extends uvm_sequencer#(transaction);
`uvm_component_utils(sequencer)
function new (string name = "sequencer", uvm_component parent = null);
super.new(name, parent);
endfunction : new
endclass : sequencer
class driver extends uvm_driver#(transaction);
`uvm_component_utils(driver)
function new (string name = "driver", uvm_component parent = null);
super.new(name, parent);
endfunction : new
task run_phase(uvm_phase phase);
forever begin
seq_item_port.get_next_item(req);
#5;
`uvm_info(get_name(), $sformatf("after get_next_item pkt:%s", req.convert2string()), UVM_LOW)
rsp = transaction::type_id::create("rsp");
//Copies the sequence_id and transaction_id from the referenced item into the calling item.
//This routine should always be used by drivers to initialize responses for future compatibility.
//function void set_id_info(uvm_sequence_item item);
// if (item == null) begin
// uvm_report_fatal(get_full_name(), "set_id_info called with null parameter", UVM_NONE);
// end
// this.set_transaction_id(item.get_transaction_id());
// this.set_sequence_id(item.get_sequence_id());
//endfunction
rsp.set_id_info(req);
seq_item_port.item_done(rsp);
end
endtask : run_phase
endclass : driver
class agent extends uvm_agent;
sequencer sqr;
driver drv;
`uvm_component_utils_begin(agent)
`uvm_field_object(sqr, UVM_DEFAULT)
`uvm_field_object(drv, UVM_DEFAULT)
`uvm_component_utils_end
function new (string name = "agent", uvm_component parent = null);
super.new(name, parent);
endfunction : new
function void build_phase(uvm_phase phase);
super.build_phase(phase);
sqr = sequencer::type_id::create("sqr", this);
drv = 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(sqr.seq_item_export);
endfunction : connect_phase
endclass : agent
class environment extends uvm_env;
agent agt;
`uvm_component_utils_begin(environment)
`uvm_field_object(agt, UVM_DEFAULT)
`uvm_component_utils_end
function new (string name = "environment", uvm_component parent = null);
super.new(name, parent);
endfunction : new
function void build_phase(uvm_phase phase);
super.build_phase(phase);
agt = agent::type_id::create("agt", this);
endfunction : build_phase
function void connect_phase(uvm_phase phase);
super.connect_phase(phase);
endfunction : connect_phase
endclass : environment
class my_sequence extends uvm_sequence#(transaction);
`uvm_object_utils(my_sequence)
function new (string name = "my_sequence");
super.new(name);
endfunction : new
task pre_body();
endtask : pre_body
task body();
for (int unsigned i=0; i<5; i++) begin
`uvm_create(req)
if (!req.randomize()) begin
`uvm_fatal(get_name(), $sformatf("Randomization of %s failed", req.get_type_name()))
end
`uvm_send(req)
`uvm_info(get_name(), $sformatf("After uvm_send waiting for get_response with transction_id:%0d", req.get_transaction_id()), UVM_LOW)
get_response(rsp, req.get_transaction_id());
`uvm_info(get_name(), $sformatf("After get_response sequence_id:%0d", get_sequence_id()), UVM_LOW)
end //for
endtask : body
task post_body();
endtask : post_body
endclass : my_sequence
class virtual_sequence extends uvm_sequence;
sequencer sqr;
`uvm_object_utils(virtual_sequence)
function new(string name = "virtual_sequence");
super.new(name);
endfunction : new
task body();
my_sequence seq1;
my_sequence seq2;
seq1 = my_sequence::type_id::create("seq1");
seq2 = my_sequence::type_id::create("seq2");
// for (int unsigned i=0; i<5; i++) begin
seq1.start(sqr);
seq2.start(sqr);
// end
#10;
endtask : body
endclass : virtual_sequence
class test extends uvm_test;
environment env;
`uvm_component_utils_begin(test)
`uvm_field_object(env, UVM_DEFAULT)
`uvm_component_utils_end
function new (string name = "test", uvm_component parent = null);
super.new(name, parent);
endfunction : new
function void build_phase(uvm_phase phase);
super.build_phase(phase);
env = environment::type_id::create("env", this);
endfunction : build_phase
function void connect_phase(uvm_phase phase);
super.connect_phase(phase);
endfunction : connect_phase
task run_phase(uvm_phase phase);
virtual_sequence vseq;
vseq = virtual_sequence::type_id::create("vseq", this);
vseq.sqr = env.agt.sqr;
phase.raise_objection(this);
// for (int unsigned i=0; i<3; i++) begin
vseq.start(null);
// end
#10;
phase.drop_objection(this);
endtask : run_phase
endclass : test
module top();
bit clk;
always #5 clk = ~clk;
initial begin
run_test("test");
end
endmodule : top
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment