Tutorials
Learn More
Port -> Port -> Export -> Export -> Imp_port Example
`include "uvm_macros.svh"
import uvm_pkg::*;
`include "seq_item.sv"
class producer extends uvm_component;
seq_item req;
uvm_blocking_put_port #(seq_item) tlm_put;
`uvm_component_utils(producer)
function new(string name = "producer", uvm_component parent = null);
super.new(name, parent);
tlm_put = new("tlm_put", this);
endfunction
task run_phase(uvm_phase phase);
super.run_phase(phase);
req = seq_item::type_id::create("req");
assert(req.randomize());
`uvm_info(get_type_name(), $sformatf("Send value = %0h", req.value), UVM_NONE);
tlm_put.put(req);
endtask
endclass
class producer_wrapper extends uvm_component;
seq_item req;
producer pro;
uvm_blocking_put_port #(seq_item) tlm_put;
`uvm_component_utils(producer_wrapper)
function new(string name = "producer_wrapper", uvm_component parent = null);
super.new(name, parent);
endfunction
function void build_phase(uvm_phase phase);
super.build_phase(phase);
tlm_put = new("tlm_put", this);
pro = producer::type_id::create("pro", this);
endfunction
endclass
class consumer extends uvm_component;
seq_item req;
//uvm_put_imp #(seq_item, consumer) tlm_imp;
uvm_blocking_put_imp #(seq_item, consumer) tlm_imp;
`uvm_component_utils(consumer)
function new(string name = "consumer", uvm_component parent = null);
super.new(name, parent);
tlm_imp = new("tlm_imp", this);
endfunction
virtual task put(seq_item req);
`uvm_info(get_type_name(), $sformatf("Received value = %0h", req.value), UVM_NONE);
endtask
endclass
class consumer_sub_w extends uvm_component;
seq_item req;
consumer con;
uvm_blocking_put_export #(seq_item) tlm_export;
`uvm_component_utils(consumer_sub_w)
function new(string name = "consumer_sub_w", uvm_component parent = null);
super.new(name, parent);
endfunction
function void build_phase(uvm_phase phase);
super.build_phase(phase);
tlm_export = new("tlm_export", this);
con = consumer::type_id::create("con", this);
endfunction
endclass
class consumer_wrapper extends uvm_component;
seq_item req;
consumer_sub_w con_sw;
uvm_blocking_put_export #(seq_item) tlm_export;
`uvm_component_utils(consumer_wrapper)
function new(string name = "consumer_wrapper", uvm_component parent = null);
super.new(name, parent);
endfunction
function void build_phase(uvm_phase phase);
super.build_phase(phase);
tlm_export = new("tlm_export", this);
con_sw = consumer_sub_w::type_id::create("con_sw", this);
endfunction
endclass
class env extends uvm_env;
producer_wrapper pro_wrapper;
consumer_wrapper con_wrapper;
`uvm_component_utils(env)
function new(string name = "env", uvm_component parent = null);
super.new(name, parent);
endfunction
function void build_phase(uvm_phase phase);
super.build_phase(phase);
pro_wrapper = producer_wrapper::type_id::create("pro_wrapper", this);
con_wrapper = consumer_wrapper::type_id::create("con_wrapper", this);
endfunction
function void connect_phase(uvm_phase phase);
super.connect_phase(phase);
pro_wrapper.tlm_put.connect(pro_wrapper.pro.tlm_put); //
pro_wrapper.pro.tlm_put.connect(con_wrapper.tlm_export);
con_wrapper.tlm_export.connect(con_wrapper.con_sw.tlm_export);
con_wrapper.con_sw.tlm_export.connect(con_wrapper.con_sw.con.tlm_imp);
endfunction
endclass
class test extends uvm_test;
env env_o;
`uvm_component_utils(test)
function new(string name = "test", uvm_component parent = null);
super.new(name, parent);
endfunction
function void build_phase(uvm_phase phase);
super.build_phase(phase);
env_o = env::type_id::create("env_o", this);
endfunction
task run_phase(uvm_phase phase);
phase.raise_objection(this);
#50;
phase.drop_objection(this);
endtask
endclass
module tb_top;
initial begin
run_test("test");
end
endmodule
Output:
UVM_INFO testbench.sv(22) @ 0: uvm_test_top.env_o.pro_wrapper.pro [producer] Send value = e
UVM_INFO testbench.sv(58) @ 0: uvm_test_top.env_o.con_wrapper.con_sw.con [consumer] Received value = e
TLM Tutorials