Tutorials
Learn More
Port -> Export -> Imp port Example
`include "uvm_macros.svh"
import uvm_pkg::*;
`include "seq_item.sv"
class producer extends uvm_component;
seq_item req;
//uvm_put_port#(seq_item) tlm_put;
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 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_wrapper extends uvm_component;
seq_item req;
consumer con;
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 = consumer::type_id::create("con", this);
endfunction
/*function void connect_phase(uvm_phase phase);
super.connect_phase(phase);
tlm_export.connect(con.tlm_imp);
endfunction
*/
endclass
class env extends uvm_env;
producer pro;
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 = producer::type_id::create("pro", this);
con_wrapper = consumer_wrapper::type_id::create("con_wrapper", this);
endfunction
function void connect_phase(uvm_phase phase);
super.connect_phase(phase);
pro.tlm_put.connect(con_wrapper.tlm_export);
con_wrapper.tlm_export.connect(con_wrapper.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(23) @ 0: uvm_test_top.env_o.pro [producer] Send value = 0
UVM_INFO testbench.sv(41) @ 0: uvm_test_top.env_o.con_wrapper.con [consumer] Received value = 0
TLM Tutorials