UVM——configuration机制

这是一个强大的属性配置工具
传递值
传递对象
传递interface
组成:
设置配置资源
获取配置资源
在这里插入图片描述

这里使用三个示例具体介绍uvm_config_db的用法

配置sequence产生transaction的数量

1、添加控制变量item_num
2、使用get()获取控制变量item_num的配置

获取:

class my_sequence extends uvm_sequence #(my_transaction_da3);

    `uvm_object_utils(my_sequence)

    int item_num = 10;

    function new(string name = "my_sequence");
        super.new(name);
    endfunction

    function void pre_randomize();
        uvm_config_db#(int)::get(m_sequencer, "", "item_num", item_num);
    endfunction

    virtual task body();
        
        if(starting_phase != null)
            starting_phase.raise_objection(this);

        repeat(item_num) begin
            `uvm_do(req);
        end
	   
        #100;
    	if(starting_phase != null)
            starting_phase.drop_objection(this);
    endtask

endclass

设置:

class my_test extends uvm_test;

    `uvm_component_utils(my_test)

    my_env m_env;

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

    virtual function void build_phase(uvm_phase phase);
        super.build_phase(phase);
        m_env = my_env::type_id::create("m_env", this);

        uvm_config_db#(uvm_object_wrapper)::set(
                        this, "*.m_seqr.run_phase",
                        "default_sequence", my_sequence::get_type());
        uvm_config_db#(int)::set(this, "*.m_seqr", "item_num", 20);
    endfunction

    virtual function void start_of_simulation_phase(uvm_phase phase);
        super.start_of_simulation_phase(phase);
        uvm_top.print_topology(uvm_default_tree_printer);
    endfunction

endclass

配置interface

加入DUT,在driver中创建虚接口。

class my_driver extends uvm_driver #(my_transaction);

    `uvm_component_utils(my_driver)

    virtual dut_interface m_vif;

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

    virtual function void build_phase(uvm_phase phase);
        super.build_phase(phase);
        uvm_config_db#(virtual dut_interface)::get(this, "", "vif", m_vif);
    endfunction

    virtual task pre_reset_phase(uvm_phase phase);
        super.pre_reset_phase(phase);
        `uvm_info("TRACE", $sformatf("%m"), UVM_HIGH)
        phase.raise_objection(this);
            m_vif.driver_cb.frame_n <= 'x; 
            m_vif.driver_cb.valid_n <= 'x; 
            m_vif.driver_cb.din     <= 'x; 
            m_vif.driver_cb.reset_n <= 'x; 
        phase.drop_objection(this);
    endtask

    ...

endclass

在top中配置接口

uvm_config_db#(virtual dut_interface)::set(null, "*.m_agent.*", "vif", inf);

上述两者可见代码lab04。

配置用户自定义的config类

定义两个配置类
1、agent_config

class agent_config extends uvm_object;

    uvm_active_passive_enum is_active = UVM_ACTIVE;
    int unsigned pad_cycles = 5;
    virtual dut_interface m_vif;

    `uvm_object_utils_begin(agent_config)
        `uvm_field_enum(uvm_active_passive_enum, is_active, UVM_ALL_ON)
        `uvm_field_int(pad_cycles, UVM_ALL_ON)
    `uvm_object_utils_end

    function new(string name = "agent_config");
        super.new(name);
    endfunction

endclass

2、env_config

class env_config extends uvm_object;

    int is_coverage = 0;
    int is_check = 0;

    agent_config m_agent_cfg;

    `uvm_object_utils_begin(env_config)
        `uvm_field_int(is_coverage, UVM_ALL_ON)
        `uvm_field_int(is_check, UVM_ALL_ON)
        `uvm_field_object(m_agent_cfg, UVM_ALL_ON)
    `uvm_object_utils_end

    function new(string name = "env_config");
        super.new(name);
        m_agent_cfg = new("m_agent_cfg");
    endfunction

endclass

在top、my_test、my_env、master_agent、my_driver中依次配置。具体可见代码lab05。

使用步骤

1、定义控制变量或控制对象。
2、在使用这些控制变量或对象之前,使用uvm_config_db#(type)::get来从高层次获取配置。
3、使用这些控制变量或对象来配置平台或行为。
4、在高层使用uvm_config_db#(type)::set来配置这些控制变量或对象。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值