UVM Agent

2023-12-04
UVM

What is a UVM agent?

AgentSequencerDriverMonitor封裝到單一instance中,並透過TLM interface將這些component連接起來。Agent也有類似將UVM agent設定為主動(active)或被動(passive)的設置,也有類似開關的config可以開啟/關閉functional coverage或類似更改parameter的config。

Types of Agents

  • Active:
    • 會產生Sequencer, Driver, Monitor全部的instance
    • 會將data透過Driver驅動至DUT
  • Passive:
    • 只會產生Monitor的instance
    • 只有checking和coverage,並不會送任何資料到DUT
    • 如果沒有任何資料要驅動到DUT的話,可以用Passive mode

How to find out if a UVM agent is active or passive?

繼承uvm_agent的class會有一個get_is_active()的function可以得到UVM agent是Active mode還是Passive mode。

1
2
3
4
5
6
7
8
9
10
class my_agent extends uvm_agent;
virtual function void build_phase (uvm_phase phase);

if (get_is_active()) begin
// Build driver and sequencer
end

// Build monitor
endfunction
endclass

Steps to create a UVM agent

  1. 建立一個繼承uvm_agent的class,然後註冊到factory上

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    class my_agent extends uvm_agent;

    `uvm_component_utils (my_agent)

    function new (string name = "my_agent", uvm_component parent = null);
    super.new (name, parent);
    endfunction

    ...
    endclass
  2. 宣告agent內要用的component

    1
    2
    3
    4
    5
    6
    7
    8
    class my_agent extends uvm_agent;
    ...
    my_driver drv_0;
    my_monitor mon_0;
    uvm_sequencer #(my_data) seqr_0;
    agent_cfg agt_cfg_0;
    ...
    endclass
  3. 在build phase將component實例化

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    class my_agent extends uvm_agent;
    ...
    virtual function void build_phase (uvm_phase phase);
    if (get_is_active()) begin
    m_seqr0 = uvm_sequencer#(my_data)::type_id::create ("m_seqr0", this);
    m_drv0 = my_driver::type_id::create ("m_drv0", this);
    end

    m_mon0 = my_monitor::type_id::create ("m_mon0", this);
    endfunction
    ...
    endclass
  4. 將agent元件連接在一起

    1
    2
    3
    4
    5
    6
    7
    class my_agent extends uvm_agent;
    virtual function void connect_phase (uvm_phase phase);

    if (get_is_active())
    m_drv0.seq_item_port.connect (m_seqr0.seq_item_export);
    endfunction
    endclass

What does a UVM agent do?

通常會建立一個agent來提供特定於protocol的task來產生transactions、檢查結果和執行覆蓋。例如,可以為 WishBone protocol建立 UVM agent,其sequencer將產生可傳送至driver的 data item。然後,driver將這些data item的object轉換為實際pin level的signal並將它們驅動到 DUT。monitor可以被動的只接收來自 DUT 的輸出,將它們轉換回另一個data item class object ,並將其分發到testbench中等待該data item的所有components中。

How to configure a UVM agent as active or passive?

A user-defined agent derived from uvm_agent has an internal variable called is_active which is of enum type uvm_active_passive_enum. By default, all agents are active.

從繼承uvm_agent自己定義的agent有一個 is_active 的變量,enum type為 uvm_active_passive_enum。default值為Active狀態。

1
2
3
4
5
// set to passive
uvm_config_db #(int) :: set (this, "path_to_agent", "is_active", UVM_PASSIVE);
// or
// set to active
uvm_config_db #(int) :: set (this, "path_to_agent", "is_active", UVM_ACTIVE);