TLM——Transaction Level Modeling(事务级建模)
通信信道
为需要通信的两个组件建立专门的通信通道,保证数据只能从发起方到接收方。
put模式
producer调用consumer中重载的put方法,把数据发送到consumer。代码示例如下。
此处的代码示例为monitor向reference model发送数据。
monitor
class my_monitor extends uvm_monitor;
`uvm_component_utils(my_monitor);
virtual dut_interface m_vif;
uvm_blocking_put_port #(my_transaction) m2r_port;
function new(string name = "", uvm_component parent);
super.new(name, parent);
this.m2r_port = new("m2r_port", this);
endfunction
virtual function void build_phase(uvm_phase phase);
super.build_phase(phase);
`uvm_info("TRACE", $sformatf("%m"), UVM_HIGH)
if(!uvm_config_db#(virtual dut_interface)::get(this, "", "vif", m_vif))begin
`uvm_fatal("CONFIG_FATAL", "Monitor can not get the interface !!!")
end
endfunction
virtual task run_phase(uvm_phase phase);
my_transaction tr;
...
`uvm_info("Monitor", "Now monitor send the transaction to the reference model!", UVM_MEDIUM)
this.m2r_port.put(tr);
endtask
endclass
reference model
在reference model中重载了put任务。该任务在monitor中被调用。
class my_reference_model extends uvm_component;
`uvm_component_utils(my_reference_model)
uvm_blocking_put_imp #(my_transaction, my_reference_model) i_m2r_imp;
function new(string name = "", uvm_component parent);
super.new(name, parent);
this.i_m2r_imp = new("i_m2r_imp", this);
endfunction
task put(my_transaction tr);
`uvm_info("REF_REPORT", {"\n", "master agent have been sent a transaction:\n", tr.sprint()}, UVM_MEDIUM)
endtask
endclass
在env中连接两个端口。
virtual function void connect_phase(uvm_phase phase);
super.connect_phase(phase);
`uvm_info("ENV", "Connect the agent and reference model...", UVM_MEDIUM)
m_agent.m_a2r_export.connect(ref_model.i_m2r_imp);
endfunction
get模式
monitor
class my_monitor extends uvm_monitor;
`uvm_component_utils(my_monitor);
virtual dut_interface m_vif;
uvm_blocking_get_imp #(my_transaction, my_monitor) m2r_imp;
my_transaction tr_fifo[$];
function new(string name = "", uvm_component parent);
super.new(name, parent);
this.m2r_imp = new("m2r_imp", this);
endfunction
virtual function void build_phase(uvm_phase phase);
super.build_phase(phase);
`uvm_info("TRACE", $sformatf("%m"), UVM_HIGH)
if(!uvm_config_db#(virtual dut_interface)::get(this, "", "vif", m_vif))begin
`uvm_fatal("CONFIG_FATAL", "Monitor can not get the interface !!!")
end
endfunction
virtual task run_phase(uvm_phase phase);
my_transaction tr;
...
`uvm_info("Monitor", {"\n", "Monitor Got An Input Transaction: \n", tr.sprint()}, UVM_MEDIUM)
tr_fifo.push_back(tr);
endtask
task get(output my_transaction s_tr);
while(tr_fifo.size() == 0) @(m_vif.imonitor_cb);
s_tr = tr_fifo.pop_front();
`uvm_info("Monitor", {"\n", "Now monitor send the transaction to the reference model: \n",s_tr.sprint()}, UVM_MEDIUM)
endtask
endclass
此处在monitor中重载get方法,在reference model中调用。
reference model
class my_reference_model extends uvm_component;
`uvm_component_utils(my_reference_model)
uvm_blocking_get_port #(my_transaction) i_m2r_port;
function new(string name = "", uvm_component parent);
super.new(name, parent);
this.i_m2r_port = new("i_m2r_port", this);
endfunction
virtual task run_phase(uvm_phase phase);
`uvm_info("REF_MODEL_RUN", "reference model running !", UVM_MEDIUM)
forever begin
my_transaction item;
i_m2r_port.get(item);
`uvm_info("REF_REPORT", {"\n", "master agent have been sent a transaction:\n", item.sprint()}, UVM_MEDIUM)
end
endtask
endclass
在reference model中调用get方法。
在env中连接
virtual function void connect_phase(uvm_phase phase);
super.connect_phase(phase);
`uvm_info("ENV", "Connect the agent and reference model...", UVM_MEDIUM)
ref_model.i_m2r_port.connect(m_agent.m_a2r_export);
endfunction
FIFO模式
monitor中端口定义和put模式一样
reference model中端口定义和get模式一样
在env中定义一个fifo,将两个端口连接起来。
env
class my_env extends uvm_env;
`uvm_component_utils(my_env)
master_agent m_agent;
env_config m_env_cfg;
my_reference_model ref_model;
uvm_tlm_analysis_fifo #(my_transaction) magt2ref_fifo;
function new(string name = "", uvm_component parent);
super.new(name, parent);
magt2ref_fifo = new("magt2ref_fifo", this);
endfunction
...
virtual function void connect_phase(uvm_phase phase);
super.connect_phase(phase);
`uvm_info("ENV", "Connect the agent to fifo...", UVM_MEDIUM)
m_agent.m_a2r_export.connect(this.magt2ref_fifo.blocking_put_export);
`uvm_info("ENV", "Connect the reference model to fifo...", UVM_MEDIUM)
ref_model.i_m2r_port.connect(this.magt2ref_fifo.blocking_get_export);
endfunction
endclass
事务的主动方为port类型端口,被动方为import类型,中间连接为export。
测试平台的分析组件
scoredboard
reference model