`ifndef MY_ENV__SV
`define MY_ENV__SV
class my_env extends uvm_env;
my_agent i_agt; // 输入代理
my_agent o_agt; // 输出代理
my_model mdl; // 模型
my_scoreboard scb; // 记分板
uvm_tlm_analysis_fifo #(my_transaction) agt_scb_fifo; // 代理到记分板的FIFO通道
uvm_tlm_analysis_fifo #(my_transaction) agt_mdl_fifo; // 代理到模型的FIFO通道
uvm_tlm_analysis_fifo #(my_transaction) mdl_scb_fifo; // 模型到记分板的FIFO通道
function new(string name = "my_env", uvm_component parent);
super.new(name, parent);
endfunction
virtual function void build_phase(uvm_phase phase);
super.build_phase(phase);
i_agt = my_agent::type_id::create("i_agt", this); // 创建输入代理对象
o_agt = my_agent::type_id::create("o_agt", this); // 创建输出代理对象
i_agt.is_active = UVM_ACTIVE;
o_agt.is_active = UVM_PASSIVE;
mdl = my_model::type_id::create("mdl", this); // 创建模型对象
scb = my_scoreboard::type_id::create("scb", this); // 创建记分板对象
agt_scb_fifo = new("agt_scb_fifo", this); // 创建代理到记分板的FIFO通道
agt_mdl_fifo = new("agt_mdl_fifo", this); // 创建代理到模型的FIFO通道
mdl_scb_fifo = new("mdl_scb_fifo", this); // 创建模型到记分板的FIFO通道
endfunction
extern virtual function void connect_phase(uvm_phase phase);
`uvm_component_util(my_env)
endclass
function void my_env::connect_phase(uvm_phase phase);
super.connect_phase(phase);
i_agt.ap.connect(agt_mdl_fifo.analysis_export); // 输入代理连接到代理到模型的FIFO通道
mdl.port.connect(agt_mdl_fifo.analysis_export); // 模型连接到代理到模型的FIFO通道
mdl.ap.connect(mdl_scb_fifo.analysis_export); // 模型连接到模型到记分板的FIFO通道
scb.exp_port.connect(mdl_scb_fifo.analysis_export); // 记分板连接到模型到记分板的FIFO通道
o_agt.ap.connect(agt_scb_fifo.analysis_export); // 输出代理连接到代理到记分板的FIFO通道
scb.act_port.connect(agt_scb_fifo.blocking_get_export); // 记分板连接到代理到记分板的FIFO通道
endfunction
`endif
上述代码是一个SystemVerilog类my_env的定义,它是一个UVM环境(uvm_env)的子类。该类包含了输入代理、输出代理、模型和记分板等组件,并定义了多个通信通道(FIFO)用于在这些组件之间进行交互。
在build_phase阶段,通过调用相应的create函数创建了输入代理、输出代理、模型和记分板等对象,并对它们进行了一些初始化设置。
在connect_phase阶段,通过连接各个组件的端口,实现了它们之间的通信。具体地,输入代理与代理到模型的FIFO通道相连,模型与代理到模型的FIFO通道相连,模型与模型到记分板的FIFO通道相连,记分板与模型到记分板的FIFO通道相连,输出代理与代理到记分板的FIFO通道相连,记分板与代理到记分板的FIFO通道相连。
文章描述了一个SystemVerilog中的UVM环境类my_env,包含输入、输出代理、模型和记分板组件,以及它们之间的FIFO通信连接过程。build_phase用于创建和初始化组件,connect_phase负责连接端口实现通信。
1229





