uvm中的monitor

uvm中的monitor的作用主要是捕捉interface上面的信号, 转换成transaction, 然后发送给其他的component。因此需要下面2个要素:

  • 要观测的virtual interface
  • 申明tlm_analysis_port, 然后广播要传输的数据。

monitor的作用

monitor由[uvm_monitor]这个class派生出来, 基本的作用如下:

  • 通过virtual interface收集总线信号;
  • 收集用于cheker和coverage分析的数据;
  • 通过analysis_port传输数据

如下图所示:

创建monitor

  1. 由[uvm_monitor]创建一个自定义的class, 注册, 然后创建new函数:
1
2
3
4
5
6
7
8
9
10
11
12
13
// my_monitor is user-given name for this class that has been derived from "uvm_monitor"
class my_monitor extends uvm_monitor;

// [Recommended] Makes this monitor more re-usable
`uvm_component_utils (my_monitor)

// This is standard code for all components
function new (string name = "my_monitor", uvm_component parent = null);
super.new (name, parent);
endfunction

// Rest of the steps come here
endclass
  1. 申明analysisport和virtual interface
1
2
3
4
5
6
// Actual interface object is later obtained by doing a get() call on uvm_config_db
virtual if_name vif;

// my_data is a custom class object used to encapsulate signal information
// and can be sent to other components
uvm_analysis_port #(my_data) mon_analysis_port;
  1. 在build_phase中实例化analysis_port并且配置virtual interface。
1
2
3
4
5
6
7
8
9
10
11
virtual function void build_phase (uvm_phase phase);
super.build_phase (phase);

// Create an instance of the declared analysis port
mon_analysis_port = new ("mon_analysis_port", this);

// Get virtual interface handle from the configuration DB
if (! uvm_config_db #(virtual if_name) :: get (this, "", "vif", vif)) begin
`uvm_error (get_type_name (), "DUT interface not found")
end
endfunction
  1. 编写run_phase
1
2
3
4
5
6
7
8
9
10
11
12
13
// This is the main piece of monitor code which decides how it has to decode 
// signal information. For example, AXI monitors need to follow AXI protocol
virtual task run_phase (uvm_phase phase);
// Fork off multiple threads "if" required to monitor the interface, for example:
fork
// Thread 1: Monitor address channel
// Thread 2: Monitor data channel, populate "obj" data object
// Thread 3: Monitor control channel, decide if transaction is over
// Thread 4: When data transfer is complete, send captured information
// through the declared analysis port
mon_analysis_port.write(obj);
join_none
endtask

参考

本文图片和code来源于网站: http://www.chipverify.com/uvm/monitor