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

UVM环境介绍
HEAD commitID: 1f968ef

1. core-v-verif/lib/uvm_agents/uvma_axi/src/comps/uvma_axi_r_agent/uvma_axi_r_agent.sv

// Copyright 2022 Thales DIS SAS
//
// Licensed under the Solderpad Hardware Licence, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// SPDX-License-Identifier: Apache-2.0 WITH SHL-2.0
// You may obtain a copy of the License at https://solderpad.org/licenses/
//
// Original Author: Alae Eddine EZ ZEJJARI (alae-eddine.ez-zejjari@external.thalesgroup.com)
// Co-Author: Abdelaali Khardazi

/**** AXI4 agent for read ****/

`ifndef __UVMA_AXI_R_AGENT_SV__
`define __UVMA_AXI_R_AGENT_SV__

class uvma_axi_r_agent_c extends uvm_agent;

   uvma_axi_r_mon_c monitor;
   uvma_axi_r_sqr_c sequencer;
   uvma_axi_r_drv_c driver;
   uvma_axi_cfg_c   cfg;

   `uvm_component_utils_begin(uvma_axi_r_agent_c)
      `uvm_field_object(monitor, UVM_ALL_ON)
      `uvm_field_object(sequencer, UVM_ALL_ON)
      `uvm_field_object(driver, UVM_ALL_ON)
   `uvm_component_utils_end

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

   function void build_phase(uvm_phase phase);

      super.build_phase(phase);

      void'(uvm_config_db#(uvma_axi_cfg_c)::get(this, "", "cfg", cfg));
      if (cfg == null) begin
         `uvm_fatal("CFG", "Configuration handle is null")
      end

      if( cfg.is_active == UVM_ACTIVE) begin
         sequencer = uvma_axi_r_sqr_c::type_id::create("sequencer", this);
         driver    = uvma_axi_r_drv_c::type_id::create("driver", this);
      end
      monitor = uvma_axi_r_mon_c::type_id::create("monitor", this);

   endfunction

   function void connect_phase(uvm_phase phase);

      super.connect_phase(phase);
      //connect sequencer to driver
      if( cfg.is_active == UVM_ACTIVE) begin
         this.driver.seq_item_port.connect(this.sequencer.seq_item_export);
      end

   endfunction

endclass  : uvma_axi_r_agent_c

`endif

1. 简要介绍

uvma_axi_r_agent.sv 文件定义了 uvma_axi_r_agent_c 类,该类继承自 uvm_agent,是 UVM(通用验证方法学)中用于 AXI4 读通道的代理类。代理类在验证环境里负责管理和协调多个组件,如监视器(monitor)、序列器(sequencer)和驱动(driver),并能依据配置决定以主动或被动模式运行。

2. 接口介绍

2.1 UVM 配置数据库接口
void'(uvm_config_db#(uvma_axi_cfg_c)::get(this, "", "cfg", cfg));
  • 代码介绍:借助 uvm_config_db 从 UVM 配置数据库获取 uvma_axi_cfg_c 类型的配置对象 cfgvoid'() 用于忽略 get 函数的返回值。
  • 逻辑分析:配置对象 cfg 包含控制代理行为的关键参数,像 is_active 字段,可决定代理是否以主动模式运行。此接口能让代理获取运行所需的配置信息。
2.2 组件连接接口
this.driver.seq_item_port.connect(this.sequencer.seq_item_export);
  • 代码介绍:把驱动(driver)的序列项端口(seq_item_port)和序列器(sequencer)的序列项导出端口(seq_item_export)连接起来。
  • 逻辑分析:建立驱动和序列器之间的通信通道,使序列器生成的事务序列项能传递给驱动,驱动依据这些序列项驱动硬件接口。

3. 参数介绍

uvma_axi_r_mon_c  monitor;
uvma_axi_r_sqr_c  sequencer;
uvma_axi_r_drv_c  driver;
uvma_axi_cfg_c    cfg;
  • monitoruvma_axi_r_mon_c 类型的监视器对象,用于监视 AXI4 读通道的信号,捕获并记录事务信息。无论代理处于主动还是被动模式,该组件都会被创建。
  • sequenceruvma_axi_r_sqr_c 类型的序列器对象,负责生成和管理读通道的事务序列,仅在代理处于主动模式时创建。
  • driveruvma_axi_r_drv_c 类型的驱动对象,根据序列器发送的序列项驱动 AXI4 读通道的硬件接口,同样仅在代理处于主动模式时创建。
  • cfguvma_axi_cfg_c 类型的配置对象,包含控制代理行为的参数,例如 is_active 决定代理的工作模式。

4. 模块实现介绍

4.1 版权声明与开源协议
//
// Licensed under the Solderpad Hardware Licence, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// SPDX-License-Identifier: Apache-2.0 WITH SHL-2.0
// You may obtain a copy of the License at https://solderpad.org/licenses/
//
// Original Author: Alae Eddine EZ ZEJJARI (alae-eddine.ez-zejjari@external.thalesgroup.com)
// Co-Author: Abdelaali Khardazi
  • 代码介绍:声明文件遵循的开源硬件许可证,指明版权信息以及文件的原始作者和共同作者。
  • 逻辑分析:保证文件的使用和分发符合开源协议规范,同时明确知识产权归属。
4.2 条件编译
`ifndef __UVMA_AXI_R_AGENT_SV__
`define __UVMA_AXI_R_AGENT_SV__
// ... 类定义代码 ...
`endif
  • 代码介绍:使用条件编译指令,若 __UVMA_AXI_R_AGENT_SV__ 宏未定义,则定义该宏并编译后续代码;若已定义,则跳过。
  • 逻辑分析:防止文件被重复包含,避免编译时出现类重复定义的错误。
4.3 类定义与 UVM 注册
class uvma_axi_r_agent_c extends uvm_agent;

   `uvm_component_utils_begin(uvma_axi_r_agent_c)
      `uvm_field_object(monitor, UVM_ALL_ON)
      `uvm_field_object(sequencer, UVM_ALL_ON)
      `uvm_field_object(driver, UVM_ALL_ON)
   `uvm_component_utils_end
  • 代码介绍:定义 uvma_axi_r_agent_c 类,继承自 uvm_agent,表明它是 UVM 验证环境中的代理组件。使用 uvm_component_utils_beginuvm_component_utils_end 宏将该类注册到 UVM 组件工厂,并把 monitorsequencerdriver 三个对象注册为可被 UVM 管理的字段。
  • 逻辑分析:通过继承和注册,使该类能够在 UVM 验证环境中被动态创建、配置和管理。
4.4 构造函数
function new(string name = "uvma_axi_r_agent_c", uvm_component parent = null);
   super.new(name, parent);
endfunction
  • 代码介绍:定义构造函数,接受 nameparent 两个参数,默认名称为 "uvma_axi_r_agent_c",默认父组件为 null。调用父类 uvm_agent 的构造函数完成初始化。
  • 逻辑分析:初始化 uvma_axi_r_agent_c 类的对象,为后续的构建和连接操作做准备。
4.5 build_phase 函数
function void build_phase(uvm_phase phase);

   super.build_phase(phase);

   void'(uvm_config_db#(uvma_axi_cfg_c)::get(this, "", "cfg", cfg));
   if (cfg == null) begin
      `uvm_fatal("CFG", "Configuration handle is null")
   end

   if( cfg.is_active == UVM_ACTIVE) begin
      sequencer = uvma_axi_r_sqr_c::type_id::create("sequencer", this);
      driver    = uvma_axi_r_drv_c::type_id::create("driver", this);
   end
   monitor = uvma_axi_r_mon_c::type_id::create("monitor", this);

endfunction
  • 代码介绍
    • super.build_phase(phase);:调用父类的 build_phase 方法,确保父类的构建操作正常执行。
    • void'(uvm_config_db#(uvma_axi_cfg_c)::get(this, "", "cfg", cfg));:从 UVM 配置数据库中获取配置对象 cfg。若 cfg 为空,则使用 uvm_fatal 输出致命错误信息,终止仿真。
    • if( cfg.is_active == UVM_ACTIVE):判断代理是否处于主动模式。若为主动模式,则使用 UVM 工厂机制创建 sequencerdriver 对象。
    • monitor = uvma_axi_r_mon_c::type_id::create("monitor", this);:无论代理是否处于主动模式,都创建 monitor 对象。
  • 逻辑分析:在 UVM 的 build_phase 阶段,根据配置信息创建相应的组件,保证代理能够按照预期模式工作。
4.6 connect_phase 函数
function void connect_phase(uvm_phase phase);

   super.connect_phase(phase);
   //connect sequencer to driver
   if( cfg.is_active == UVM_ACTIVE) begin
      this.driver.seq_item_port.connect(this.sequencer.seq_item_export);
   end

endfunction
  • 代码介绍
    • super.connect_phase(phase);:调用父类的 connect_phase 方法,确保父类的连接操作正常执行。
    • if( cfg.is_active == UVM_ACTIVE):判断代理是否处于主动模式。若为主动模式,则将驱动的 seq_item_port 与序列器的 seq_item_export 连接。
  • 逻辑分析:在 UVM 的 connect_phase 阶段,根据代理的工作模式建立驱动和序列器之间的通信连接,实现事务序列项的传递。

5. 总结

uvma_axi_r_agent.sv 文件实现了 AXI4 读通道的 UVM 代理类 uvma_axi_r_agent_c。该类通过 UVM 配置数据库获取配置信息,在 build_phase 阶段依据配置创建相应的组件,在 connect_phase 阶段完成组件间的连接。代理类可以根据配置在主动模式和被动模式下工作,主动模式下包含序列器和驱动组件,被动模式下仅包含监视器组件。这种设计让该代理类能够灵活地集成到不同的 AXI4 验证环境中,提升了验证的可维护性和可扩展性。

2. core-v-verif/lib/uvm_agents/uvma_axi/src/comps/uvma_axi_r_agent/uvma_axi_r_drv.sv

// Copyright 2022 Thales DIS SAS
//
// Licensed under the Solderpad Hardware Licence, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// SPDX-License-Identifier: Apache-2.0 WITH SHL-2.0
// You may obtain a copy of the License at https://solderpad.org/licenses/
//
// Original Author: Alae Eddine EZ ZEJJARI (alae-eddine.ez-zejjari@external.thalesgroup.com)
// Co-Author: Abdelaali Khardazi

/**** AXI4 slave driver for read ****/

`ifndef __UVMA_AXI_R_DRV_SV__
`define __UVMA_AXI_R_DRV_SV__

class uvma_axi_r_drv_c extends uvm_driver #(uvma_axi_r_item_c);

   `uvm_component_utils(uvma_axi_r_drv_c)

   uvma_axi_cntxt_c      cntxt;

   uvma_axi_r_item_c     r_item;

   // Handles to virtual interface modport
   virtual uvma_axi_intf.slave  slave_mp;

   extern function new(string name = "uvma_axi_r_drv_c", uvm_component parent);
   extern virtual function void build_phase(uvm_phase phase
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值