文末附本文所有代码。
上次使用SystemVerilog进行验证,现在使用UVM对同一DUT进行验证。
UVM框架如下:
为了保持组件/对象命名的一致性,所有组件/对象的名称都以mem_*开头。
基本组件:
Sequence item
sequence_item是通过扩展uvm_seq_item来编写的:
class mem_seq_item extends uvm_sequence_item; //Utility macro `uvm_object_utils(mem_seq_item) //Constructor function new(string name = "mem_seq_item"); super.new(name); endfunction endclass
在mem_seq_item中声明变量,并声明随机化:
class mem_seq_item extends uvm_sequence_item; //data and control fields rand bit [3:0] addr; rand bit wr_en; rand bit rd_en; rand bit [7:0] wdata; bit [7:0] rdata;
endclass
为了使用uvm_object方法(复制、比较、打包、解包、记录、打印等),所有变量都注册到uvm_field_*宏。
class mem_seq_item extends uvm_sequence_item; //Utility and Field macros, `uvm_object_utils_begin(mem_seq_item) `uvm_field_int(addr,UVM_ALL_ON) `uvm_field_int(wr_en,UVM_ALL_ON) `uvm_field_int(rd_en,UVM_ALL_ON) `uvm_field_int(wdata,UVM_ALL_ON) `uvm_object_utils_end endclass