验证平台的组成
其他概念:agent、sequence
1、driver模块
class my_driver extends uvm_driver;
function new(string name = "my_driver", uvm_component parent = null);
super.new(name, parent);
endfunction
extern virtual task main_phase(uvm_phase phase);
endclass
task my_driver::main_phase(uvm_phase phase);
top_tb.rxd <= 8'b0;
top_tb.rx_dv <= 1'b0;
while(!top_tb.rst_n)
@(posedge top_tb.clk);
for(int i = 0; i < 256; i++)begin
@(posedge top_tb.clk);
top_tb.rxd <= $urandom_range(0, 255);
top_tb.rx_dv <= 1'b1;
`uvm_info("my_driver", "data is drived", UVM_LOW)
end
@(posedge top_tb.clk);
top_tb.rx_dv <= 1'b0;
endtask
生成的driver是uvm_driver的一个类。其中的new()函数有两个参数,一个是string类型的name,一个是uvm_component类型的parent。另外代码中还有
`uvm_info("my_driver", "data is drived", UVM_LOW)
2、factory机制
`uvm_info("my_driver", "data is drived", UVM_LOW)
加入一个宏,相当于把这个类注册到表中。到时候在top模块可隐式调用直接生成一个my_driver。
initial begin
run_test("my_driver");
end
3、objection机制
phase.raise_objection(this);
……
phase.drop_objection(this);
两个语句成对出现,初学可简单理解为$finish函数的替代。
4、virtual interface中的config_db机制
在config_db机制中,分为set和get两步操作。这个机制的主要作用是连接不同模块和类之间的接口。所谓“set”可以理解为寄信,而“get”可理解为收信。
initial begin
uvm_config_db#(virtual my_if)::set(null, "uvm_test_top", "vif", input_if);
end
……
virtual function void build_phase(uvm_phase phase);
super.build_phase(phase);
`uvm_info("my_driver", "build_phase is called", UVM_LOW);
if(!uvm_config_db#(virtual my_if)::get(this, "", "vif", vif))
`uvm_fatal("my_driver", "virtual interface must be set for vif!!!")
endfunction
其中set和get都有四个参数。第一个参数后文说明;第二参数是路径索引,而之前用
run_test("my_driver");
创建的my_driver实例,它的实例名字是uvm_test_top(默认的,用run_test语句就生成该名字的实例);第三个函数参数必须完全一致;第四个参数,set函数表示要将哪个interface通过config_db传递给my_driver,get函数的第四个参数表示吧得到的interface传递给哪个my_driver的成员。
如若想传递多个不同类型数据,可按如下办法:
initial begin
uvm_config_db#(virtual my_if)::set(null, "uvm_test_top", "vif", input_if);
uvm_config_db#(virtual my_if)::set(null, "uvm_test_top", "vif2", output_if);
end
……
virtual my_if vif;
virtual my_if vif2;
virtual function void build_phase(uvm_phase phase);
super.build_phase(phase);
`uvm_info("my_driver", "build_phase is called", UVM_LOW);
if(!uvm_config_db#(virtual my_if)::get(this, "", "vif", vif))
`uvm_fatal("my_driver", "virtual interface must be set for vif!!!")
if(!uvm_config_db#(virtual my_if)::get(this, "", "vif2", vif2))
`uvm_fatal("my_driver", "virtual interface must be set for vif2!!!")
endfunction