您的位置:首页 > 文旅 > 美景 > 爱采购网_网站设计便宜_seo是付费还是免费推广_淄博网站营销与推广

爱采购网_网站设计便宜_seo是付费还是免费推广_淄博网站营销与推广

2025/3/18 2:37:41 来源:https://blog.csdn.net/weixin_46163885/article/details/145723911  浏览:    关键词:爱采购网_网站设计便宜_seo是付费还是免费推广_淄博网站营销与推广
爱采购网_网站设计便宜_seo是付费还是免费推广_淄博网站营销与推广

文章目录

  • 前言
  • 1. `extract_phase` 的作用与特点
  • 2. 在验证项目中的应用
    • 2.1 提取 DUT 输出
      • 示例代码
    • 2.2 收集覆盖率数据
      • 示例代码
    • 2.3 检查 DUT 状态
      • 示例代码
  • 3. 层次化提取与数据传递
    • 示例代码
  • 4. 调试与优化
  • 5. 完整示例:通信协议验证环境
    • Testbench 顶层
    • Test 用例
    • Env 集成


前言

在 UVM 验证环境中,extract_phase 是用于提取仿真结果并进行后处理的关键阶段。以下是如何在具体验证项目中应用 extract_phase 的详细说明和示例:


1. extract_phase 的作用与特点

  • 功能
    • 提取仿真结果(如 DUT 输出、覆盖率数据、事务记录等)。
    • 检查仿真环境的状态和 DUT 的状态。
    • 为后续的 check_phasereport_phase 提供数据支持。
  • 执行顺序
    • extract_phaserun_phase 之后执行,属于 后仿真阶段
    • 执行顺序为 自底向上(Bottom-Up),子组件的 extract_phase 先于父组件执行。
  • 典型应用场景
    • 提取通信协议中的数据包。
    • 收集覆盖率数据。
    • 检查 DUT 输出的正确性。

2. 在验证项目中的应用

2.1 提取 DUT 输出

场景:在通信协议验证中,提取接收到的数据包并检查其完整性。

示例代码

class protocol_monitor extends uvm_monitor;`uvm_component_utils(protocol_monitor)uvm_analysis_port #(protocol_packet) ap;protocol_packet pkt;virtual task run_phase(uvm_phase phase);// 监控 DUT 接口,捕获数据包forever begin@(posedge vif.clk);if (vif.valid && vif.ready) beginpkt = protocol_packet::type_id::create("pkt");pkt.data = vif.data;ap.write(pkt);  // 广播数据包endendendtaskvirtual function void extract_phase(uvm_phase phase);super.extract_phase(phase);// 提取捕获的数据包并检查完整性if (pkt != null) beginif (!pkt.check_integrity()) begin`uvm_error("PKT_ERR", "Packet integrity check failed!")endendendfunction
endclass

2.2 收集覆盖率数据

场景:在功能覆盖率验证中,提取覆盖率数据并生成报告。

示例代码

class coverage_collector extends uvm_component;`uvm_component_utils(coverage_collector)protocol_packet pkt;covergroup cg;// 定义覆盖率点coverpoint pkt.data {bins low = {[0:127]};bins mid = {[128:255]};}function new(string name, uvm_component parent);super.new(name, parent);cg = new();endfunctionvirtual function void write(protocol_packet pkt);this.pkt = pkt;cg.sample();  // 采样覆盖率endfunctionvirtual function void extract_phase(uvm_phase phase);super.extract_phase(phase);// 提取覆盖率数据`uvm_info("COV", $sformatf("Coverage: %.2f%%", cg.get_coverage()), UVM_MEDIUM)endfunction
endclass

2.3 检查 DUT 状态

场景:在存储器验证中,提取 DUT 的状态并检查其正确性。

示例代码

class memory_checker extends uvm_component;`uvm_component_utils(memory_checker)bit [31:0] mem_data [0:1023];  // 存储器模型virtual function void extract_phase(uvm_phase phase);super.extract_phase(phase);// 提取 DUT 的存储器内容for (int i = 0; i < 1024; i++) beginmem_data[i] = vif.mem_read(i);end// 检查存储器内容是否正确foreach (mem_data[i]) beginif (mem_data[i] != expected_data[i]) begin`uvm_error("MEM_ERR", $sformatf("Address 0x%h: Expected=0x%h, Actual=0x%h",i, expected_data[i], mem_data[i]))endendendfunction
endclass

3. 层次化提取与数据传递

场景:在 SoC 验证中,从子组件提取数据并传递到顶层环境进行汇总。

示例代码

class soc_env extends uvm_env;`uvm_component_utils(soc_env)protocol_agent  agent;soc_scoreboard  scoreboard;virtual function void extract_phase(uvm_phase phase);super.extract_phase(phase);// 从 Agent 提取数据并传递给 Scoreboardagent.monitor.extract();scoreboard.extract();endfunction
endclassclass protocol_agent extends uvm_agent;`uvm_component_utils(protocol_agent)protocol_monitor monitor;virtual function void extract_phase(uvm_phase phase);super.extract_phase(phase);monitor.extract();  // 调用 Monitor 的 extract 方法endfunction
endclass

4. 调试与优化

  1. 调试技巧
    • 使用 uvm_info 打印提取的数据:
      `uvm_info("EXTRACT", $sformatf("Extracted data: %h", data), UVM_MEDIUM)
      
    • 使用 uvm_error 标记错误状态。
  2. 性能优化
    • 避免在 extract_phase 中执行耗时操作(如复杂计算)。
    • 将数据提取任务分散到多个子组件中并行执行。

5. 完整示例:通信协议验证环境

Testbench 顶层

module top;protocol_if vif();protocol_dut dut(.clk(vif.clk), .data(vif.data), .valid(vif.valid), .ready(vif.ready));initial beginuvm_config_db#(virtual protocol_if)::set(null, "uvm_test_top.env*", "vif", vif);run_test("protocol_test");end
endmodule

Test 用例

class protocol_test extends uvm_test;`uvm_component_utils(protocol_test)protocol_env env;virtual function void build_phase(uvm_phase phase);super.build_phase(phase);env = protocol_env::type_id::create("env", this);endfunctionvirtual task run_phase(uvm_phase phase);phase.raise_objection(this);#1000;  // 等待仿真完成phase.drop_objection(this);endtask
endclass

Env 集成

class protocol_env extends uvm_env;`uvm_component_utils(protocol_env)protocol_agent  agent;protocol_checker checker;virtual function void extract_phase(uvm_phase phase);super.extract_phase(phase);agent.monitor.extract();  // 提取数据checker.extract();        // 检查数据endfunction
endclass

通过合理设计 extract_phase,可以高效提取仿真结果并完成数据检查,为验证环境的正确性和覆盖率分析提供支持。

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com