uvm_transaction——事物

UVM Transaction详解
本文介绍了UVM框架中uvm_transaction类的基本概念及其作用。uvm_transaction作为uvm_sequence_item的基类,提供时间戳属性、通知事件及交易记录等功能。文章还详细探讨了如何在驱动程序中使用这些功能。
文件:
src/base/uvm_transaction.svh
类: 
uvm_transaction
 
  uvm_transaction继承自uvm_object,添加了timing和recording接口,该类是uvm_sequence_item的基类。这个类提供了时间戳属性(timestamp properties),通知事件(notification events),和交易记录(transaction recording)支持。其子类uvm_sequence_item应当作为基类为所有用户定义的事务类型。

//------------------------------------------------------------------------------
//
// CLASS: uvm_transaction
//
// The uvm_transaction class is the root base class for UVM transactions.
// Inheriting all the methods of <uvm_object>, uvm_transaction adds a timing and
// recording interface.
//
// This class provides timestamp properties, notification events, and transaction
// recording support. 
//
// Use of this class as a base for user-defined transactions
// is deprecated. Its subtype, <uvm_sequence_item>, shall be used as the
// base class for all user-defined transaction types. 
// 
// The intended use of this API is via a <uvm_driver #(REQ,RSP)> to call <uvm_component::accept_tr>,
// <uvm_component::begin_tr>, and <uvm_component::end_tr> during the course of
// sequence item execution. These methods in the component base class will
// call into the corresponding methods in this class to set the corresponding
// timestamps (~accept_time~, ~begin_time~, and ~end_time~), trigger the
// corresponding event (<begin_event> and <end_event>, and, if enabled,
// record the transaction contents to a vendor-specific transaction database.
//
// Note that get_next_item/item_done when called on a uvm_seq_item_pull_port
// will automatically trigger the begin_event and end_events via calls to begin_tr and end_tr.
// While convenient, it is generally the responsibility of drivers to mark a
// transaction's progress during execution.  To allow the driver or layering sequence
// to control sequence item timestamps, events, and recording, you must call
// <uvm_sqr_if_base#(REQ,RSP)::disable_auto_item_recording> at the beginning
// of the driver's ~run_phase~ task.
//
// Users may also use the transaction's event pool, <events>,
// to define custom events for the driver to trigger and the sequences to wait on. Any
// in-between events such as marking the beginning of the address and data
// phases of transaction execution could be implemented via the
// <events> pool.
// 
// In pipelined protocols, the driver may release a sequence (return from
// finish_item() or it's `uvm_do macro) before the item has been completed.
// If the driver uses the begin_tr/end_tr API in uvm_component, the sequence can
// wait on the item's <end_event> to block until the item was fully executed,
// as in the following example.
//
//| task uvm_execute(item, ...);
//|     // can use the `uvm_do macros as well
//|     start_item(item);
//|     item.randomize();
//|     finish_item(item);
//|     item.end_event.wait_on();
//|     // get_response(rsp, item.get_transaction_id()); //if needed
//| endtask
//|
//
// A simple two-stage pipeline driver that can execute address and
// data phases concurrently might be implemented as follows: 
//
//| task run();
//|     // this driver supports a two-deep pipeline
//|     fork
//|       do_item();
//|       do_item();
//|     join
//| endtask
//| 
//| 
//| task do_item();
//|     
//|   forever begin
//|     mbus_item req;
//|
//|     lock.get();
//|
//|     seq_item_port.get(req); // Completes the sequencer-driver handshake
//|
//|     accept_tr(req);
//|
//|       // request bus, wait for grant, etc.
//| 
//|     begin_tr(req);
//|
//|       // execute address phase
//|
//|     // allows next transaction to begin address phase
//|     lock.put();
//| 
//|       // execute data phase
//|       // (may trigger custom "data_phase" event here)
//| 
//|     end_tr(req);
//| 
//|   end
//| 
//| endtask: do_item
//
//------------------------------------------------------------------------------
virtual class uvm_transaction extends uvm_object;

  // Function: new
  //
  // Creates a new transaction object. The name is the instance name of the
  // transaction. If not supplied, then the object is unnamed.
  
  extern function new (string name="", uvm_component initiator=null);

   ......

endclass

 

参考文献:

2 UVM基础之———uvm_transaction.  http://www.cnblogs.com/bob62/p/3871858.html

转载于:https://www.cnblogs.com/dpc525/p/7930518.html

### 自定义事务类 `my_transaction` 的代码分析 在 UVM(Universal Verification Methodology)中,事务类是验证平台中数据建模和交互的核心组成部分。通过继承 `uvm_sequence_item` 类,用户可以定义自定义事务类来封装通信协议中的关键信息字段,并支持随机化、序列化、复制等操作。 以下是一个典型的自定义事务类 `my_transaction` 的实现: ```systemverilog class my_transaction extends uvm_sequence_item; rand bit [31:0] address; rand bit [31:0] data; constraint c_data_range { data >= 0; data <= 1024; } `uvm_object_utils_begin(my_transaction) `uvm_field_int(address, UVM_ALL_ON) `uvm_field_int(data, UVM_ALL_ON) `uvm_object_utils_end function new(string name = "my_transaction"); super.new(name); endfunction endclass ``` #### 字段定义与随机化支持 该事务类定义了两个关键字段:`address` 和 `data`,它们均被声明为 `rand` 类型,表示这些字段可以参与约束随机生成过程。这种设计使得事务对象能够在测试用例中生成符合特定约束条件的数据组合,从而提高测试覆盖率并发现边界情况问题。 同时,类中引入了一个约束块 `c_data_range`,限制 `data` 字段的取值范围在 0 到 1024 之间。这一机制确保生成的事务数据符合实际硬件行为或协议规范的要求[^4]。 #### 元信息注册与字段处理 宏 `uvm_object_utils_begin` 和 `uvm_field_int` 用于注册事务类的元信息,并指定字段如何参与复制、比较、打印等操作。例如,`UVM_ALL_ON` 标志表示该字段将参与所有默认操作,包括打印、比较和序列化。这些宏扩展了类的功能,使其能够无缝集成到 UVM 框架中[^1]。 #### 构造函数与命名支持 构造函数 `new` 接收一个字符串参数作为实例名称,并将其传递给基类 `uvm_sequence_item` 的构造函数。这允许事务对象在调试和日志输出中显示其名称,便于跟踪和分析。 --- ### 集成与使用场景 此类事务对象可广泛应用于 UVM 平台的多个组件中,如 agent、sequencer、driver 和 monitor。例如,在 agent 中使用 `uvm_slave_agent #(my_transaction)` 可以明确指定该 agent 处理的数据类型为 `my_transaction` 实例,从而保证平台各组件之间的数据一致性,并在连接端口时进行类型检查,避免运行时错误[^1]。 此外,事务类还可以通过 TLM 接口(如 `uvm_analysis_port`)在不同组件之间传输,支持非阻塞式广播,适用于多观察者模式下的事务分发[^2]。 --- ### 总结 通过继承 `uvm_sequence_item` 并结合 UVM 提供的宏机制,`my_transaction` 实现了高效、灵活且结构清晰的事务建模方式。它不仅支持字段的随机化和约束,还具备良好的可扩展性和兼容性,能够适应复杂的验证需求。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值