core-v-verif系列之lib<46>

UVM环境介绍
HEAD commitID: 1f968ef

1. core-v-verif/lib/uvm_agents/uvma_core_cntrl/seq/uvma_core_cntrl_base_seq.sv

// Copyright 2020 OpenHW Group
// Copyright 2020 Datum Technology Corporation
// 
// Licensed under the Solderpad Hardware Licence, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     https://solderpad.org/licenses/
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.


`ifndef __UVMA_CORE_CNTRL_BASE_SEQ_SV__
`define __UVMA_CORE_CNTRL_BASE_SEQ_SV__


/**
 * Abstract object from which all other Core_cntrl agent sequences must extend.
 * Subclasses must be run on Core_cntrl sequencer (uvma_core_cntrl_sqr_c) instance.
 */
class uvma_core_cntrl_base_seq_c extends uvm_sequence;

   `uvm_object_utils(uvma_core_cntrl_base_seq_c)
   `uvm_declare_p_sequencer(uvma_core_cntrl_sqr_c)
   
   /**
    * Default constructor.
    */
   extern function new(string name="uvma_core_cntrl_base_seq");
   
endclass : uvma_core_cntrl_base_seq_c


`pragma protect begin


function uvma_core_cntrl_base_seq_c::new(string name="uvma_core_cntrl_base_seq");
   
   super.new(name);
   
endfunction : new


`pragma protect end


`endif // __UVMA_CORE_CNTRL_BASE_SEQ_SV__

2. 接口介绍

2.1 类定义与继承
class uvma_core_cntrl_base_seq_c extends uvm_sequence;
  • 代码介绍:定义了一个名为 uvma_core_cntrl_base_seq_c 的抽象基类,继承自 UVM 的 uvm_sequence 基类。该基类是所有 Core Control Agent 序列必须继承的父类。
  • 逻辑分析:通过继承 uvm_sequence,该类获得了 UVM 序列的基本功能,同时作为抽象基类为子类提供了统一的接口规范。
2.2 UVM 工具宏
`uvm_object_utils(uvma_core_cntrl_base_seq_c)
`uvm_declare_p_sequencer(uvma_core_cntrl_sqr_c)
  • 代码介绍
    • uvm_object_utils 宏将类注册到 UVM 对象工厂
    • uvm_declare_p_sequencer 宏声明了一个指向 uvma_core_cntrl_sqr_c 类型序列器的指针
  • 逻辑分析:这些宏是 UVM 的标准实践,使序列能够被工厂创建并与特定类型的序列器交互。

3. 参数介绍

3.1 构造函数参数
extern function new(string name="uvma_core_cntrl_base_seq");
  • 代码介绍:构造函数接收一个字符串参数 name,默认值为 "uvma_core_cntrl_base_seq"
  • 逻辑分析:提供默认名称简化对象创建,同时允许自定义名称以满足特定需求。

4. 模块实现介绍

4.1 头文件保护
`ifndef __UVMA_CORE_CNTRL_BASE_SEQ_SV__
`define __UVMA_CORE_CNTRL_BASE_SEQ_SV__
// ... 类定义 ...
`endif // __UVMA_CORE_CNTRL_BASE_SEQ_SV__
  • 代码介绍:标准头文件保护宏,防止重复包含。
  • 逻辑分析:确保类定义在编译时只被包含一次。
4.2 构造函数实现
function uvma_core_cntrl_base_seq_c::new(string name="uvma_core_cntrl_base_seq");
   super.new(name);
endfunction : new
  • 代码介绍:简单调用父类构造函数完成初始化。
  • 逻辑分析:基础初始化逻辑,确保对象正确构建。

5. 总结

uvma_core_cntrl_base_seq_c 是一个 UVM 序列基类,为 Core Control Agent 的所有序列提供基础框架。通过继承 uvm_sequence 并添加必要的 UVM 宏,它确保了子类能够正确集成到 UVM 验证环境中。简洁的实现专注于提供核心功能,同时保持足够的扩展性。

2. core-v-verif/lib/uvm_agents/uvma_core_cntrl/uvma_core_cntrl_agent.sv

// 
// Copyright 2020 OpenHW Group
// Copyright 2020 Datum Technology Corporation
// Copyright 2020 Silicon Labs, Inc.
//
// Licensed under the Solderpad Hardware Licence, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     https://solderpad.org/licenses/
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 


`ifndef __UVMA_CORE_CNTRL_AGENT_SV__
`define __UVMA_CORE_CNTRL_AGENT_SV__

/**
 * Virtual base class agent for Core Control
 * Encapsulates:
 * - Paraameter sampling
 * - Bootstrap pin randomization and driving
 * - Core configuration and randomization
 */
virtual class uvma_core_cntrl_agent_c extends uvm_agent;
   
   // Objects
   uvma_core_cntrl_cfg_c    cfg;
   uvma_core_cntrl_cntxt_c  cntxt;

   // Components   
   uvma_core_cntrl_sqr_c    sequencer;
   uvma_core_cntrl_drv_c    driver;   

   `uvm_field_utils_begin(uvma_core_cntrl_agent_c)
      `uvm_field_object(cfg  , UVM_DEFAULT)
      `uvm_field_object(cntxt, UVM_DEFAULT)
   `uvm_field_utils_end
   
   /**
    * Default constructor.
    */
   extern function new(string name="uvma_core_cntrl_agent", uvm_component parent=null);
   
   /**
    * 1. Ensures cfg & cntxt handles are not null
    * 2. Builds all components
    */
   extern virtual function void build_phase(uvm_phase phase);
   
   /**
    * 1. Links agent's analysis ports to sub-components'
    * 2. Connects coverage models and loggers
    */
   extern virtual function void connect_phase(uvm_phase phase);

   /**
    *  run_phase will kick off the control sequence that runs the duration
    *  of the simulation (if this agent is active)
    */
   extern virtual task run_phase(uvm_phase phase);

   /**
    * Uses uvm_config_db to retrieve cfg and hand out to sub-components.
    */
   extern virtual function void get_and_set_cfg();
   
   /**
    * Uses uvm_config_db to retrieve cntxt and hand out to sub-components.
    */
   extern virtual function void get_and_set_cntxt();
   
   /**
    * Uses uvm_config_db to retrieve the Virtual Interface (vif) associated with this
    * agent.
    */
   extern virtual function void retrieve_vif();
   
   /**
    * Creates sub-components.
    */
   extern virtual function void create_components();
   
   /**
    * Connects sequencer and driver's TLM port(s).
    */
   extern virtual function void connect_sequencer_and_driver();
   
   /**
    * Connects agent's TLM ports to driver's and monitor's.
    */
   extern virtual function void connect_analysis_ports();
   
   /**
    * Connects coverage model to monitor and driver's analysis ports.
    */
   extern virtual function void connect_cov_model();
   
   /**
    * Connects transaction loggers to monitor and driver's analysis ports.
    */
   extern virtual function void connect_trn_loggers();
   
endclass : uvma_core_cntrl_agent_c


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

function void uvma_core_cntrl_agent_c::build_phase(uvm_phase phase);
   
   super.build_phase(phase);
   
   get_and_set_cfg  ();
   get_and_set_cntxt();
   retrieve_vif     ();
   create_components();

endfunction : build_phase

function void uvma_core_cntrl_agent_c::connect_phase(uvm_phase phase);
   
   super.connect_phase(phase);
   
   connect_sequencer_and_driver();
   connect_analysis_ports();
   
   if (cfg.cov_model_enabled) begin
      connect_cov_model();
   end
   if (cfg.trn_log_enabled) begin
      connect_trn_loggers();
   end
   
endfunction: connect_phase

task uvma_core_cntrl_agent_c::run_phase(uvm_phase phase);

endtask : run_phase

function void uvma_core_cntrl_agent_c::retrieve_vif();

endfunction : retrieve_vif

function void uvma_core_cntrl_agent_c::get_and_set_cfg();
   
   if (uvm_config_db#(uvma_core_cntrl_cfg_c)::get(this, "", "cfg", cfg)) begin
      `uvm_info("CFG", $sformatf("Found configuration handle:\n%s", cfg.sprint()), UVM_DEBUG)
      uvm_config_db#(uvma_core_cntrl_cfg_c)::set(this, "*", "cfg", cfg);
   end
   else begin
      `uvm_fatal("CFG", $sformatf("%s: Could not find configuration handle", this.get_full_name()));
   end
   
endfunction : get_and_set_cfg


function void uvma_core_cntrl_agent_c::get_and_set_cntxt();
   
   if (uvm_config_db#(uvma_core_cntrl_cntxt_c)::get(this, "", "cntxt", cntxt)) begin
      uvm_config_db#(uvma_core_cntrl_cntxt_c)::set(this, "*", "cntxt", cntxt);
   end
   else begin
      `uvm_fatal("CNTXT", $sformatf("%s: Could not find context handle", this.get_full_name()));
   end
   
endfunction : get_and_set_cntxt


function void uvma_core_cntrl_agent_c::create_components();

   if (cfg.is_active == UVM_ACTIVE) begin
      sequencer = uvma_core_cntrl_sqr_c::type_id::create("sequencer", this);
      driver = uvma_core_cntrl_drv_c::type_id::create("driver", this);
   end

endfunction : create_components


function void uvma_core_cntrl_agent_c::connect_sequencer_and_driver();

   if (cfg.is_active == UVM_ACTIVE) begin
      driver.seq_item_port.connect(sequencer.seq_item_export);      
   end

endfunction : connect_sequencer_and_driver


function void uvma_core_cntrl_agent_c::connect_analysis_ports();
         
endfunction : connect_analysis_ports


function void uvma_core_cntrl_agent_c::connect_cov_model();
      
endfunction : connect_cov_model


function void uvma_core_cntrl_agent_c::connect_trn_loggers();
   
endfunction : connect_trn_loggers


`endif // __UVMA_CORE_CNTRL_AGENT_SV__

2. 接口介绍

2.1 类定义与继承
virtual class uvma_core_cntrl_agent_c extends uvm_agent;
  • 代码介绍:定义了一个名为uvma_core_cntrl_agent_c的虚基类,继承自UVM的uvm_agent基类。
  • 逻辑分析:作为虚基类,它不能被直接实例化,主要用于为具体实现类提供接口规范。继承uvm_agent使其具备UVM agent的标准功能。
2.2 成员变量
uvma_core_cntrl_cfg_c    cfg;
uvma_core_cntrl_cntxt_c  cntxt;
uvma_core_cntrl_sqr_c    sequencer;
uvma_core_cntrl_drv_c    driver;
  • 代码介绍
    • cfg:配置对象,类型为uvma_core_cntrl_cfg_c
    • cntxt:上下文对象,类型为uvma_core_cntrl_cntxt_c
    • sequencer:序列器组件
    • driver:驱动器组件
  • 逻辑分析:这些成员变量构成了agent的核心组件,分别负责配置管理、状态维护、序列调度和驱动控制。
2.3 UVM字段宏
`uvm_field_utils_begin(uvma_core_cntrl_agent_c)
   `uvm_field_object(cfg  , UVM_DEFAULT)
   `uvm_field_object(cntxt, UVM_DEFAULT)
`uvm_field_utils_end
  • 代码介绍:使用UVM字段宏注册配置和上下文对象。
  • 逻辑分析:这些宏使配置和上下文对象支持UVM的自动复制、比较、打印等操作。

3. 参数介绍

3.1 构造函数参数
extern function new(string name="uvma_core_cntrl_agent", uvm_component parent=null);
  • 代码介绍:构造函数接收组件名称和父组件两个参数,都有默认值。
  • 逻辑分析:默认参数值简化了对象创建,同时保留了自定义命名的灵活性。

4. 模块实现介绍

4.1 构造函数实现
function uvma_core_cntrl_agent_c::new(string name="uvma_core_cntrl_agent", uvm_component parent=null);
   super.new(name, parent);
endfunction : new
  • 代码介绍:简单调用父类构造函数完成初始化。
  • 逻辑分析:基础初始化逻辑,确保对象正确构建。
4.2 build_phase实现
function void uvma_core_cntrl_agent_c::build_phase(uvm_phase phase);
   super.build_phase(phase);
   get_and_set_cfg();
   get_and_set_cntxt();
   retrieve_vif();
   create_components();
endfunction : build_phase
  • 代码介绍:依次执行:
    1. 调用父类build_phase
    2. 获取配置对象
    3. 获取上下文对象
    4. 获取虚拟接口
    5. 创建子组件
  • 逻辑分析:标准UVM构建流程,确保各组件按正确顺序初始化。
4.3 connect_phase实现
function void uvma_core_cntrl_agent_c::connect_phase(uvm_phase phase);
   super.connect_phase(phase);
   connect_sequencer_and_driver();
   connect_analysis_ports();
   if (cfg.cov_model_enabled) connect_cov_model();
   if (cfg.trn_log_enabled) connect_trn_loggers();
endfunction: connect_phase
  • 代码介绍:完成端口连接和可选组件(覆盖率模型、事务日志)的连接。
  • 逻辑分析:条件判断使这些可选组件只在配置启用时才被连接。

5. 总结

uvma_core_cntrl_agent_c是一个标准的UVM agent虚基类,提供了核心控制agent的基本框架。它通过清晰的阶段方法划分(build_phase、connect_phase等)实现了组件的创建和连接。配置和上下文对象的管理机制完善,支持灵活的组件扩展。作为虚基类,它为具体实现类提供了良好的扩展基础,同时通过UVM标准接口确保了与其他组件的兼容性。

3. core-v-verif/lib/uvm_agents/uvma_core_cntrl/uvma_core_cntrl_cfg.sv

//
// Copyright 2020 OpenHW Group
// Copyright 2020 Datum Technology Corporation
// Copyright 2020 Silicon Labs, Inc.
//
// Licensed under the Solderpad Hardware Licence, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://solderpad.org/licenses/
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

`ifndef __UVMA_CORE_CNTRL_CFG_SV__
`define __UVMA_CORE_CNTRL_CFG_SV__


/**
 * Object encapsulating all parameters for creating, connecting and running all
 * Clock & Reset agent (uvma_core_cntrl_agent_c) components.
 */

 virtual class uvma_core_cntrl_cfg_c extends uvm_object;

   string                        core_name;
    // Major mode enable controls
   rand bit                      enabled;
   rand uvm_active_passive_enum  is_active;
   rand bit                      scoreboard_enabled;
   bit                           disable_all_csr_checks;
   bit [CSR_MASK_WL-1:0]         disable_csr_check_mask;
   rand bit                      cov_model_enabled;
   rand bit                      trn_log_enabled;

   // ISS configuration
   bit                           use_iss;
   string                        iss_control_file = "ovpsim.ic";

   // RISC-V ISA Configuration
   rand corev_mxl_t              xlen;
   rand int unsigned             ilen;

   rand bit                      ext_i_supported;
   rand bit                      ext_a_supported;
   rand bit                      ext_m_supported;
   rand bit                      ext_c_supported;
   rand bit                      ext_p_supported;
   rand bit                      ext_v_supported;
   rand bit                      ext_f_supported;
   rand bit                      ext_d_supported;
   rand bit                      ext_zba_supported;
   rand bit                      ext_zbb_supported;
   rand bit                      ext_zbc_supported;
   rand bit                      ext_zbe_supported;
   rand bit                      ext_zbf_supported;
   rand bit                      ext_zbm_supported;
   rand bit                      ext_zbp_supported;
   rand bit                      ext_zbr_supported;
   rand bit                      ext_zbs_supported;
   rand bit                      ext_zbt_supported;
   rand bit                      ext_zcb_supported;
   rand bit                      ext_zifencei_supported;
   rand bit                      ext_zicsr_supported;
   rand bit                      ext_zicntr_supported;
   rand bit                      ext_xcvxif_supported;

   // Core specific extensions
   rand bit                      ext_cv32a60x_supported
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值