[UVM源代码研究] 聊聊uvm_sequence中常用的宏以及方法
1. 引言
我们在sequence中往driver发包时,最常用的方法就是使用uvm_do()系列宏,偶尔会使用方法start_item()和finish_item()的组合,极个别场景下会 使用uvm_create()和uvm_send()宏,极极个别场景下还会看到create_item()方法的使用,这些宏和方法有什么区别,各自使用场景有什么局限和注意事项,他们分别定义在了UVM源代码中的哪个类中,本文尝试结合UVM源代码一次讲清楚。
2. 源代码分析
首先我们看下UVM源代码中uvm_sequence相关类的继承关系,如图1所示。
图1 UVM中uvm_sequnece类的继承关系

uvm_sequence从uvm_object继承而来,所以它不具备uvm_component的phase机制,它的生命周期从创建到执行完成后就结束了,有可能在一个phase内完成,也可能横跨多个phase.
下面我们再看看其父类链条中的uvm_transaction、uvm_sequence_item、uvm_sequence_base以及uvm_sequence本身分别提供了哪些属性和方法,方便我们从整体上把握引言中提到的那几个宏和方法的使用。
2.1 uvm_transaction
UVM源代码 /src/base/uvm_transaction.svh 中关于uvm_transaction的描述如下:
//------------------------------------------------------------------------------
//
// 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> 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_tr), trigger the
// corresponding event (<begin_event> and <end_event>, and, if enabled,
// record the transaction contents to a vendor-specific transaction database.
//
// Note that start_item/finish_item (or `uvm_do* macro) executed from a
// <uvm_sequence #(REQ,RSP)> 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 to control
// sequence item timestamps, events, and recording, you must add
// +define+UVM_DISABLE_AUTO_ITEM_RECORDING when compiling the UVM package.
// Alternatively, users may 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 begining of the address and data
// phases of transaction execution could be implemented via the
// <events> pool.
概括的讲,就是说uvm_transaction这个类中主要提供了一些记录transaction相关时间戳的功能,在uvm_sequence中调用相关宏或者方法时会自动调用相关时间戳方法,如图2所示。
图2 src/seq/uvm_sequence_base.svh中的相关代码截图

正如uvm_transaction类描述中所提到的,我们可以用过+define+UVM_DISABLE_AUTO_ITEM_RECORDING这个宏的方式不让uvm_sequence来主动记录transaction相关时间戳,而是在uvm_driver中手动的记录,但是通常我们也不会这么做。
这么看来uvm_transaction这个类中提供的功能我们基本上不会显式的调用的,所以基本上不太需要关心。
uvm_trsanction.svh这个文件是在 src/base 目录下的,其他几个文件都是定义在 src/seq/ 目录下的,由此可见UVM的sequence机制uvm_trsanction参与的并不多,主要靠下面介绍的3个类来实现的。
深入解析UVM源代码:uvm_sequence中的宏与方法使用详解

本文详细探讨了UVM源代码中uvm_sequence中的常用宏(如uvm_do系列)和方法(如start_item和finish_item),包括它们的区别、应用场景、源代码位置以及它们在UVM序列执行流程中的作用。通过实例解析,帮助读者更好地理解和应用这些工具。
最低0.47元/天 解锁文章
1012

被折叠的 条评论
为什么被折叠?



