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

UVM环境介绍
HEAD commitID: 1f968ef

lib/uvm_agents/uvma_obi_memory/src/comps

//
// Copyright 2021 OpenHW Group
// Copyright 2021 Datum Technology Corporation
// SPDX-License-Identifier: Apache-2.0 WITH SHL-2.1
//
// Licensed under the Solderpad Hardware License v 2.1 (the "License"); you may
// not use this file except in compliance with the License, or, at your option,
// the Apache License version 2.0. You may obtain a copy of the License at
//
//     https://solderpad.org/licenses/SHL-2.1/
//
// Unless required by applicable law or agreed to in writing, any work
// 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_OBI_MEMORY_MON_TRN_LOGGER_SV__
`define __UVMA_OBI_MEMORY_MON_TRN_LOGGER_SV__


/**
 * Component writing Open Bus Interface monitor transactions debug data to disk as plain text.
 */
class uvma_obi_memory_mon_trn_logger_c extends uvml_logs_mon_trn_logger_c#(
   .T_TRN  (uvma_obi_memory_mon_trn_c),
   .T_CFG  (uvma_obi_memory_cfg_c    ),
   .T_CNTXT(uvma_obi_memory_cntxt_c  )
);


   `uvm_component_utils(uvma_obi_memory_mon_trn_logger_c)

   /**
    * Default constructor.
    */
   function new(string name="uvma_obi_memory_mon_trn_logger", uvm_component parent=null);

      super.new(name, parent);

   endfunction : new

   /**
    * Writes contents of t to disk
    */
   virtual function void write(uvma_obi_memory_mon_trn_c t);

      string format_header_str_1p1 = "%15s | %6s | %2s | %8s | %4s | %8s";
      string format_header_str_1p2 = "%15s | %6s | %2s | %8s | %4s | %8s | %2s | %2s | %2s | %2s | %2s | %2s | %2s";
      string log_msg;

      // Log the 1p1 signals
      log_msg = $sformatf("%15s | %6s | %2s | %08x |  %1x | %8s",
                          $sformatf("%t", $time),
                          cfg.mon_logger_name,
                          t.access_type == UVMA_OBI_MEMORY_ACCESS_READ ? "R" : "W",
                          t.address,
                          t.be,
                          t.get_data_str());


      if (cfg.version == UVMA_OBI_MEMORY_VERSION_1P2) begin
         log_msg = $sformatf("%s | %2x |    %1x |   %2x | %3s",
                             log_msg,
                             t.aid,
                             t.prot,
                             t.atop,
                             t.err ? "ERR" : "OK");
         if (cfg.auser_width > 0)
            log_msg = $sformatf("%s |     %1x", log_msg, t.auser);
         if (cfg.wuser_width > 0)
            log_msg = $sformatf("%s |     %1x", log_msg, t.wuser);
         if (cfg.ruser_width > 0)
            log_msg = $sformatf("%s |     %1x", log_msg, t.ruser);
      end

      fwrite(log_msg);

   endfunction : write

   /**
    * Writes log header to disk
    */
   virtual function void print_header();

      if (cfg.version == UVMA_OBI_MEMORY_VERSION_1P1) begin
         string banner_str = {
   80{
   "-"}};
         string format_header_str_1p1 = "%15s | %6s | %2s | %8s | %2s | %8s";


         fwrite(banner_str);
         fwrite($sformatf(format_header_str_1p1,
                          "TIME", "OBI", "RW", "ADDR", "BE", "DATA"));
         fwrite(banner_str);
      end
      else begin
         string banner_str = {
   106{
   "-"}};
         string format_header_str_1p2 = "%15s | %6s | %2s | %8s | %2s | %8s | %2s | %2s | %2s | %2s";
         string header_str;

         header_str = $sformatf(format_header_str_1p2,
                                "TIME", "OBI", "RW", "ADDR", "BE", "DATA",
                                "ID", "PROT", "ATOP", "ERR");

         if (cfg.auser_width > 0)
            header_str = $sformatf("%s | %2s", header_str, "AUSER");
         if (cfg.ruser_width > 0)
            header_str = $sformatf("%s | %2s", header_str, "RUSER");
         if (cfg.wuser_width > 0)
            header_str = $sformatf("%s | %2s", header_str, "WUSER");

         fwrite(banner_str);
         fwrite(header_str);
         fwrite(banner_str);
      end

   endfunction : print_header

endclass : uvma_obi_memory_mon_trn_logger_c


/**
 * Component writing OBI monitor transactions debug data to disk as JavaScript Object Notation (JSON).
 */
class uvma_obi_memory_mon_trn_logger_json_c extends uvma_obi_memory_mon_trn_logger_c;

   `uvm_component_utils(uvma_obi_memory_mon_trn_logger_json_c)


   /**
    * Set file extension to '.json'.
    */
   function new(string name="uvma_obi_memory_mon_trn_logger_json", uvm_component parent=null);

      super.new(name, parent);
      fextension = "json";

   endfunction : new

   /**
    * Writes contents of t to disk.
    */
   virtual function void write(uvma_obi_memory_mon_trn_c t);

      // TODO Implement uvma_obi_memory_mon_trn_logger_json_c::write()
      // Ex: fwrite({"{",
      //       $sformatf("\"time\":\"%0t\",", $realtime()),
      //       $sformatf("\"a\":%h,"        , t.a        ),
      //       $sformatf("\"b\":%b,"        , t.b        ),
      //       $sformatf("\"c\":%d,"        , t.c        ),
      //       $sformatf("\"d\":%h,"        , t.c        ),
      //     "},"});

   endfunction : write

   /**
    * Empty function.
    */
   virtual function void print_header();

      // Do nothing: JSON files do not use headers.

   endfunction : print_header

endclass : uvma_obi_memory_mon_trn_logger_json_c


`endif // __UVMA_OBI_MEMORY_MON_TRN_LOGGER_SV__

uvma_obi_memory_mon_trn_logger.sv

1. 简要介绍

该文件是OBI内存监控事务日志记录组件,主要功能包括:

  1. 将监控事务数据写入磁盘
  2. 支持文本和JSON两种格式
  3. 根据协议版本动态调整输出格式
  4. 作为验证环境的调试辅助组件

2. 接口介绍

2.1 类定义
class uvma_obi_memory_mon_trn_logger_c extends uvml_logs_mon_trn_logger_c#(
   .T_TRN(uvma_obi_memory_mon_trn_c),
   .T_CFG(uvma_obi_memory_cfg_c)
);
  • 代码介绍:定义OBI监控事务日志记录类
  • 继承关系:继承自参数化基础日志记录类
  • 特点:支持协议特定字段记录

3. 参数介绍

3.1 日志格式定义
string format_header_str_1p1 = "%15s | %6s | %2s | %8s | %4s | %8s";
string format_header_str_1p2 = "%15s | %6s | %2s | %8s | %4s | %8s | %2s | %2s | %2s | %2s";
  • 参数说明
    • 1p1格式:基础协议字段
    • 1p2格式:扩展协议字段

4. 模块实现介绍

4.1 写入函数
function void write(uvma_obi_memory_mon_trn_c t);
   log_msg = $sformatf("%15s | %6s | %2s | %08x |  %1x | %8s",
                       $sformatf("%t", $time),
                       cfg.mon_logger_name,
                       t.access_type == UVMA_OBI_MEMORY_ACCESS_READ ? "R" : "W",
                       t.address,
                       t.be,
                       t.get_data_str());
endfunction
  • 代码分析
    1. 格式化时间戳
    2. 记录操作类型(R/W)
    3. 输出地址和数据
    4. 根据协议版本扩展字段
4.2 JSON日志类
class uvma_obi_memory_mon_trn_logger_json_c extends uvma_obi_memory_mon_trn_logger_c;
   function new();
      fextension = "json";
   endfunction
endclass
  • 代码分析
    1. 继承基础日志类
    2. 设置文件扩展名为json
    3. 预留JSON格式实现

5. 总结

该OBI监控事务日志记录组件具有以下特点:

  1. 灵活的多格式支持
  2. 协议版本自适应
  3. 清晰的输出格式
  4. 可扩展的JSON实现

作为验证环境的调试辅助工具,它为OBI接口的调试和分析提供了直观的事务记录能力,确保能够方便地追踪接口行为。

//
// Copyright 2021 OpenHW Group
// Copyright 2021 Datum Technology Corporation
// SPDX-License-Identifier: Apache-2.0 WITH SHL-2.1
//
// Licensed under the Solderpad Hardware License v 2.1 (the "License"); you may
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值