UVM——普通TLM端口的用法

TLM——Transaction Level Modeling(事务级建模)
通信信道
在这里插入图片描述
在这里插入图片描述
为需要通信的两个组件建立专门的通信通道,保证数据只能从发起方到接收方。

put模式

producer调用consumer中重载的put方法,把数据发送到consumer。代码示例如下。
此处的代码示例为monitor向reference model发送数据。

monitor

class my_monitor extends uvm_monitor;

    `uvm_component_utils(my_monitor);

    virtual dut_interface m_vif;

    uvm_blocking_put_port #(my_transaction) m2r_port;

    function new(string name = "", uvm_component parent);
        super.new(name, parent);
        this.m2r_port = new("m2r_port", this);
    endfunction

    virtual function void build_phase(uvm_phase phase);
        super.build_phase(phase);
        `uvm_info("TRACE", $sformatf("%m"), UVM_HIGH)
        if(!uvm_config_db#(virtual dut_interface)::get(this, "", "vif", m_vif))begin
            `uvm_fatal("CONFIG_FATAL", "Monitor can not get the interface !!!")
        end
    endfunction

    virtual task run_phase(uvm_phase phase);
        my_transaction tr;
        ...

        `uvm_info("Monitor", "Now monitor send the transaction to the reference model!", UVM_MEDIUM)
        this.m2r_port.put(tr);
        
    endtask

endclass

reference model

在reference model中重载了put任务。该任务在monitor中被调用。

class my_reference_model extends uvm_component;

    `uvm_component_utils(my_reference_model)
    uvm_blocking_put_imp #(my_transaction, my_reference_model) i_m2r_imp;

    function new(string name = "", uvm_component parent);
        super.new(name, parent);
        this.i_m2r_imp = new("i_m2r_imp", this);
    endfunction

    task put(my_transaction tr);
        `uvm_info("REF_REPORT", {"\n", "master agent have been sent a transaction:\n", tr.sprint()}, UVM_MEDIUM)
    endtask

endclass

在env中连接两个端口。

virtual function void connect_phase(uvm_phase phase);
        super.connect_phase(phase);
        `uvm_info("ENV", "Connect the agent and reference model...", UVM_MEDIUM)
        m_agent.m_a2r_export.connect(ref_model.i_m2r_imp);
    endfunction

get模式

monitor

class my_monitor extends uvm_monitor;

    `uvm_component_utils(my_monitor);

    virtual dut_interface m_vif;

    uvm_blocking_get_imp #(my_transaction, my_monitor) m2r_imp;
    my_transaction tr_fifo[$];

    function new(string name = "", uvm_component parent);
        super.new(name, parent);
        this.m2r_imp = new("m2r_imp", this);
    endfunction

    virtual function void build_phase(uvm_phase phase);
        super.build_phase(phase);
        `uvm_info("TRACE", $sformatf("%m"), UVM_HIGH)
        if(!uvm_config_db#(virtual dut_interface)::get(this, "", "vif", m_vif))begin
            `uvm_fatal("CONFIG_FATAL", "Monitor can not get the interface !!!")
        end
    endfunction

    virtual task run_phase(uvm_phase phase);
        my_transaction tr;
        ...
        `uvm_info("Monitor", {"\n", "Monitor Got An Input Transaction: \n", tr.sprint()}, UVM_MEDIUM)

        tr_fifo.push_back(tr);
    endtask

    task get(output my_transaction s_tr);
        while(tr_fifo.size() == 0) @(m_vif.imonitor_cb);
        s_tr = tr_fifo.pop_front();
        `uvm_info("Monitor", {"\n", "Now monitor send the transaction to the reference model: \n",s_tr.sprint()}, UVM_MEDIUM)
    endtask

endclass

此处在monitor中重载get方法,在reference model中调用。

reference model

class my_reference_model extends uvm_component;

    `uvm_component_utils(my_reference_model)
    uvm_blocking_get_port #(my_transaction) i_m2r_port;

    function new(string name = "", uvm_component parent);
        super.new(name, parent);
        this.i_m2r_port = new("i_m2r_port", this);
    endfunction

    virtual task run_phase(uvm_phase phase);
        `uvm_info("REF_MODEL_RUN", "reference model running !",  UVM_MEDIUM)
        forever begin
            my_transaction item;
            i_m2r_port.get(item);
            `uvm_info("REF_REPORT", {"\n", "master agent have been sent a transaction:\n", item.sprint()}, UVM_MEDIUM)
        end
    endtask

endclass

在reference model中调用get方法。
在env中连接

	virtual function void connect_phase(uvm_phase phase);
        super.connect_phase(phase);
        `uvm_info("ENV", "Connect the agent and reference model...", UVM_MEDIUM)
        ref_model.i_m2r_port.connect(m_agent.m_a2r_export);
    endfunction

FIFO模式

monitor中端口定义和put模式一样
reference model中端口定义和get模式一样
在env中定义一个fifo,将两个端口连接起来。

env

class my_env extends uvm_env;

    `uvm_component_utils(my_env)

    master_agent m_agent;
    env_config m_env_cfg;
    my_reference_model ref_model;
    uvm_tlm_analysis_fifo #(my_transaction) magt2ref_fifo;

    function new(string name = "", uvm_component parent);
        super.new(name, parent);
        magt2ref_fifo = new("magt2ref_fifo", this);
    endfunction

	...

    virtual function void connect_phase(uvm_phase phase);
        super.connect_phase(phase);
        `uvm_info("ENV", "Connect the agent to fifo...", UVM_MEDIUM)
        m_agent.m_a2r_export.connect(this.magt2ref_fifo.blocking_put_export);

        `uvm_info("ENV", "Connect the reference model to fifo...", UVM_MEDIUM)
        ref_model.i_m2r_port.connect(this.magt2ref_fifo.blocking_get_export);
    endfunction

endclass

事务的主动方为port类型端口,被动方为import类型,中间连接为export。

测试平台的分析组件
scoredboard
reference model

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值