上一节虽然输出了“main_phase is called”,但没有“data is drived”输出。而main_phase看上去被外力杀死了。
UVM通过objection机制来控制验证平台的关闭,在每个phase中,都会检查是否有objection被提起(raise_objection),如果有被提起,就会等待这个objection被撤销(drop_objection)后停止仿真,如果没有,就会马上停止该仿真。所以上一节没有检查到有raise_objection,仿真开始后立刻又被停止了下来。
加入object机制的driver如下所示:
class my_driver extends uvm_driver;
`uvm_component_utils(my_driver)
function new(string name = "my_driver",uvm_component parent = null);
super.new(name,parent);
`uvm_info("my_driver","new is called",UVM_LOW);
endfunction
extern virtual task main_phase(uvm_phase phase);
endclass
task my_driver::main_phase(uvm_phase phase);
phase.raise_objection(this);
`uvm_info("my_driver","main_phase is called",UVM_LOW);
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;
phase.drop_objection(this);
endtask
这样运行可以发现data is drived这条语句被打印了256次。
raise_objection语句必须在main_phase中的第一个消耗仿真时间的语句之前,如uvm_info宏语句,但是如果其之前有消耗了仿真时间的语句如@(posedge top.clk),那么这个raise将无法起作用。