The uvm_sequence_base class provides the interfaces needed to create streams of sequence items and/or other sequences.
A sequence is executed by calling its start method, either directly or invocation of any of the `uvm_do_* macros.
A sequence’s start method has a parent_sequence argument that controls whether pre_do, mid_do, and post_do are called in the parent sequence. It also has a call_pre_post argument that controls whether its pre_body and post_body methods are called. In all cases, its pre_start and post_start methods are always called.
When start is called directly, you can provide the appropriate arguments according to your application.
The sequence execution flow looks like this
User code
sub_seq.randomize(...); // optional sub_seq.start(seqr, parent_seq, priority, call_pre_post)
The following methods are called, in order
sub_seq.pre_start() (task) sub_seq.pre_body() (task) if call_pre_post==1 parent_seq.pre_do(0) (task) if parent_sequence!=null parent_seq.mid_do(this) (func) if parent_sequence!=null sub_seq.body (task) YOUR STIMULUS CODE parent_seq.post_do(this) (func) if parent_sequence!=null sub_seq.post_body() (task) if call_pre_post==1 sub_seq.post_start() (task)
A sequence can also be indirectly started as a child in the body of a parent sequence. The child sequence’s start method is called indirectly by invoking any of the `uvm_do macros. In these cases, start is called with call_pre_post set to 0, preventing the started sequence’s pre_body and post_body methods from being called. During execution of the child sequence, the parent’s pre_do, mid_do, and post_do methods are called.
The sub-sequence execution flow looks like
User code
`uvm_do_with_prior(seq_seq, { constraints }, priority)
The following methods are called, in order
sub_seq.pre_start() (task) parent_seq.pre_do(0) (task) parent_req.mid_do(sub_seq) (func) sub_seq.body() (task) parent_seq.post_do(sub_seq) (func) sub_seq.post_start() (task)
Remember, it is the parent sequence’s pre|mid|post_do that are called, not the sequence being executed.
Items are started in the body of a parent sequence via calls to start_item/finish_item or invocations of any of the `uvm_do macros. The pre_do, mid_do, and post_do methods of the parent sequence will be called as the item is executed.
The sequence-item execution flow looks like
User code
parent_seq.start_item(item, priority); item.randomize(...) [with {constraints}]; parent_seq.finish_item(item); or `uvm_do_with_prior(item, constraints, priority)
The following methods are called, in order
sequencer.wait_for_grant(prior) (task) \ start_item \ parent_seq.pre_do(1) (task) / \ `uvm_do* macros parent_seq.mid_do(item) (func) \ / sequencer.send_request(item) (func) \finish_item / sequencer.wait_for_item_done() (task) / parent_seq.post_do(item) (func) /
Attempting to execute a sequence via start_item/finish_item will produce a run-time error.
uvm_sequence_base | ||||||
The uvm_sequence_base class provides the interfaces needed to create streams of sequence items and/or other sequences. | ||||||
Class Hierarchy | ||||||
| ||||||
Class Declaration | ||||||
| ||||||
do_not_randomize | If set, prevents the sequence from being randomized before being executed by the `uvm_do*() and `uvm_rand_send*() macros, or as a default sequence. | |||||
new | The constructor for uvm_sequence_base. | |||||
is_item | Returns 1 on items and 0 on sequences. | |||||
get_sequence_state | Returns the sequence state as an enumerated value. | |||||
wait_for_sequence_state | Waits until the sequence reaches one of the given state. | |||||
get_tr_handle | Returns the integral recording transaction handle for this sequence. | |||||
Sequence Execution | ||||||
start | Executes this sequence, returning when the sequence has completed. | |||||
pre_start | This task is a user-definable callback that is called before the optional execution of pre_body. | |||||
pre_body | This task is a user-definable callback that is called before the execution of body only when the sequence is started with start. | |||||
pre_do | This task is a user-definable callback task that is called on the parent sequence, if any sequence has issued a wait_for_grant() call and after the sequencer has selected this sequence, and before the item is randomized. | |||||
mid_do | This function is a user-definable callback function that is called after the sequence item has been randomized, and just before the item is sent to the driver. | |||||
body | This is the user-defined task where the main sequence code resides. | |||||
post_do | This function is a user-definable callback function that is called after the driver has indicated that it has completed the item, using either this item_done or put methods. | |||||
post_body | This task is a user-definable callback task that is called after the execution of body only when the sequence is started with start. | |||||
post_start | This task is a user-definable callback that is called after the optional execution of post_body. | |||||
Run-Time Phasing | ||||||
get_starting_phase | Returns the ‘starting phase’. | |||||
set_starting_phase | Sets the ‘starting phase’. | |||||
set_automatic_phase_objection | Sets the ‘automatically object to starting phase’ bit. | |||||
get_automatic_phase_objection | Returns (and locks) the value of the ‘automatically object to starting phase’ bit. | |||||
Sequence Control | ||||||
set_priority | The priority of a sequence may be changed at any point in time. | |||||
get_priority | This function returns the current priority of the sequence. | |||||
is_relevant | The default is_relevant implementation returns 1, indicating that the sequence is always relevant. | |||||
wait_for_relevant | This method is called by the sequencer when all available sequences are not relevant. | |||||
lock | Requests a lock on the specified sequencer. | |||||
grab | Requests a lock on the specified sequencer. | |||||
unlock | Removes any locks or grabs obtained by this sequence on the specified sequencer. | |||||
ungrab | Removes any locks or grabs obtained by this sequence on the specified sequencer. | |||||
is_blocked | Returns a bit indicating whether this sequence is currently prevented from running due to another lock or grab. | |||||
has_lock | Returns 1 if this sequence has a lock, 0 otherwise. | |||||
kill | This function will kill the sequence, and cause all current locks and requests in the sequence’s default sequencer to be removed. | |||||
do_kill | This function is a user hook that is called whenever a sequence is terminated by using either sequence.kill() or sequencer.stop_sequences() (which effectively calls sequence.kill()). | |||||
Sequence Item Execution | ||||||
create_item | Create_item will create and initialize a sequence_item or sequence using the factory. | |||||
start_item | start_item and finish_item together will initiate operation of a sequence item. | |||||
finish_item | finish_item, together with start_item together will initiate operation of a sequence_item. | |||||
wait_for_grant | This task issues a request to the current sequencer. | |||||
send_request | The send_request function may only be called after a wait_for_grant call. | |||||
wait_for_item_done | A sequence may optionally call wait_for_item_done. | |||||
Response API | ||||||
use_response_handler | When called with enable set to 1, responses will be sent to the response handler. | |||||
get_use_response_handler | Returns the state of the use_response_handler bit. | |||||
response_handler | When the use_response_handler bit is set to 1, this virtual task is called by the sequencer for each response that arrives for this sequence. | |||||
set_response_queue_error_report_disabled | By default, if the response_queue overflows, an error is reported. | |||||
get_response_queue_error_report_disabled | When this bit is 0 (default value), error reports are generated when the response queue overflows. | |||||
set_response_queue_depth | The default maximum depth of the response queue is 8. | |||||
get_response_queue_depth | Returns the current depth setting for the response queue. | |||||
clear_response_queue | Empties the response queue for this sequence. |
bit do_not_randomize
If set, prevents the sequence from being randomized before being executed by the `uvm_do*() and `uvm_rand_send*() macros, or as a default sequence.
virtual function bit is_item()
Returns 1 on items and 0 on sequences. As this object is a sequence, is_item will always return 0.
function uvm_sequence_state_enum get_sequence_state()
Returns the sequence state as an enumerated value. Can use to wait on the sequence reaching or changing from one or more states.
wait(get_sequence_state() & (UVM_STOPPED|UVM_FINISHED));
task wait_for_sequence_state( int unsigned state_mask )
Waits until the sequence reaches one of the given state. If the sequence is already in one of the state, this method returns immediately.
wait_for_sequence_state(UVM_STOPPED|UVM_FINISHED);
function integer get_tr_handle()
Returns the integral recording transaction handle for this sequence. Can be used to associate sub-sequences and sequence items as child transactions when calling uvm_component::begin_child_tr.
virtual task start ( uvm_sequencer_base sequencer, uvm_sequence_base parent_sequence = null, int this_priority = -1, bit call_pre_post = 1 )
Executes this sequence, returning when the sequence has completed.
The sequencer argument specifies the sequencer on which to run this sequence. The sequencer must be compatible with the sequence.
If parent_sequence is null, then this sequence is a root parent, otherwise it is a child of parent_sequence. The parent_sequence’s pre_do, mid_do, and post_do methods will be called during the execution of this sequence.
By default, the priority of a sequence is the priority of its parent sequence. If it is a root sequence, its default priority is 100. A different priority may be specified by this_priority. Higher numbers indicate higher priority.
If call_pre_post is set to 1 (default), then the pre_body and post_body tasks will be called before and after the sequence body is called.
virtual task pre_do( bit is_item )
This task is a user-definable callback task that is called on the parent sequence, if any sequence has issued a wait_for_grant() call and after the sequencer has selected this sequence, and before the item is randomized.
Although pre_do is a task, consuming simulation cycles may result in unexpected behavior on the driver.
This method should not be called directly by the user.
virtual function void mid_do( uvm_sequence_item this_item )
This function is a user-definable callback function that is called after the sequence item has been randomized, and just before the item is sent to the driver. This method should not be called directly by the user.
virtual task body()
This is the user-defined task where the main sequence code resides. This method should not be called directly by the user.
virtual function void post_do( uvm_sequence_item this_item )
This function is a user-definable callback function that is called after the driver has indicated that it has completed the item, using either this item_done or put methods. This method should not be called directly by the user.
virtual task post_body()
This task is a user-definable callback task that is called after the execution of body only when the sequence is started with start. If start is called with call_pre_post set to 0, post_body is not called. This task is a user-definable callback task that is called after the execution of the body, unless the sequence is started with call_pre_post=0. This method should not be called directly by the user.
virtual task post_start()
This task is a user-definable callback that is called after the optional execution of post_body. This method should not be called directly by the user.
function uvm_phase get_starting_phase()
Returns the ‘starting phase’.
If non-null, the starting phase specifies the phase in which this sequence was started. The starting phase is set automatically when this sequence is started as the default sequence on a sequencer. See uvm_sequencer_base::start_phase_sequence for more information.
Internally, the uvm_sequence_base uses an uvm_get_to_lock_dap to protect the starting phase value from being modified after the reference has been read. Once the sequence has ended its execution (either via natural termination, or being killed), then the starting phase value can be modified again.
function void set_starting_phase( uvm_phase phase )
Sets the ‘starting phase’.
Internally, the uvm_sequence_base uses a uvm_get_to_lock_dap to protect the starting phase value from being modified after the reference has been read. Once the sequence has ended its execution (either via natural termination, or being killed), then the starting phase value can be modified again.
function void set_automatic_phase_objection( bit value )
Sets the ‘automatically object to starting phase’ bit.
The most common interaction with the starting phase within a sequence is to simply raise the phase’s objection prior to executing the sequence, and drop the objection after ending the sequence (either naturally, or via a call to kill). In order to simplify this interaction for the user, the UVM provides the ability to perform this functionality automatically.
function my_sequence::new(string name="unnamed"); super.new(name); set_automatic_phase_objection(1); endfunction : new
From a timeline point of view, the automatic phase objection looks like:
start() is executed --! Objection is raised !-- pre_start() is executed pre_body() is optionally executed body() is executed post_body() is optionally executed post_start() is executed --! Objection is dropped !-- start() unblocks
This functionality can also be enabled in sequences which were not written with UVM Run-Time Phasing in mind:
my_legacy_seq_type seq = new("seq"); seq.set_automatic_phase_objection(1); seq.start(my_sequencer);
Internally, the uvm_sequence_base uses a uvm_get_to_lock_dap to protect the automatic_phase_objection value from being modified after the reference has been read. Once the sequence has ended its execution (either via natural termination, or being killed), then the automatic_phase_objection value can be modified again.
NEVER set the automatic phase objection bit to 1 if your sequence runs with a forever loop inside of the body, as the objection will never get dropped!
function bit get_automatic_phase_objection()
Returns (and locks) the value of the ‘automatically object to starting phase’ bit.
If 1, then the sequence will automatically raise an objection to the starting phase (if the starting phase is not null) immediately prior to pre_start being called. The objection will be dropped after post_start has executed, or kill has been called.
function void set_priority ( int value )
The priority of a sequence may be changed at any point in time. When the priority of a sequence is changed, the new priority will be used by the sequencer the next time that it arbitrates between sequences.
The default priority value for a sequence is 100. Higher values result in higher priorities.
function int get_priority()
This function returns the current priority of the sequence.
virtual function bit is_relevant()
The default is_relevant implementation returns 1, indicating that the sequence is always relevant.
Users may choose to override with their own virtual function to indicate to the sequencer that the sequence is not currently relevant after a request has been made.
When the sequencer arbitrates, it will call is_relevant on each requesting, unblocked sequence to see if it is relevant. If a 0 is returned, then the sequence will not be chosen.
If all requesting sequences are not relevant, then the sequencer will call wait_for_relevant on all sequences and re-arbitrate upon its return.
Any sequence that implements is_relevant must also implement wait_for_relevant so that the sequencer has a way to wait for a sequence to become relevant.
virtual task wait_for_relevant()
This method is called by the sequencer when all available sequences are not relevant. When wait_for_relevant returns the sequencer attempt to re-arbitrate.
Returning from this call does not guarantee a sequence is relevant, although that would be the ideal. The method provide some delay to prevent an infinite loop.
If a sequence defines is_relevant so that it is not always relevant (by default, a sequence is always relevant), then the sequence must also supply a wait_for_relevant method.
task lock( uvm_sequencer_base sequencer = null )
Requests a lock on the specified sequencer. If sequencer is null, the lock will be requested on the current default sequencer.
A lock request will be arbitrated the same as any other request. A lock is granted after all earlier requests are completed and no other locks or grabs are blocking this sequence.
The lock call will return when the lock has been granted.
task grab( uvm_sequencer_base sequencer = null )
Requests a lock on the specified sequencer. If no argument is supplied, the lock will be requested on the current default sequencer.
A grab request is put in front of the arbitration queue. It will be arbitrated before any other requests. A grab is granted when no other grabs or locks are blocking this sequence.
The grab call will return when the grab has been granted.
function void unlock( uvm_sequencer_base sequencer = null )
Removes any locks or grabs obtained by this sequence on the specified sequencer. If sequencer is null, then the unlock will be done on the current default sequencer.
function void ungrab( uvm_sequencer_base sequencer = null )
Removes any locks or grabs obtained by this sequence on the specified sequencer. If sequencer is null, then the unlock will be done on the current default sequencer.
function bit is_blocked()
Returns a bit indicating whether this sequence is currently prevented from running due to another lock or grab. A 1 is returned if the sequence is currently blocked. A 0 is returned if no lock or grab prevents this sequence from executing. Note that even if a sequence is not blocked, it is possible for another sequence to issue a lock or grab before this sequence can issue a request.
function bit has_lock()
Returns 1 if this sequence has a lock, 0 otherwise.
Note that even if this sequence has a lock, a child sequence may also have a lock, in which case the sequence is still blocked from issuing operations on the sequencer.
function void kill()
This function will kill the sequence, and cause all current locks and requests in the sequence’s default sequencer to be removed. The sequence state will change to UVM_STOPPED, and the post_body() and post_start() callback methods will not be executed.
If a sequence has issued locks, grabs, or requests on sequencers other than the default sequencer, then care must be taken to unregister the sequence with the other sequencer(s) using the sequencer unregister_sequence() method.
virtual function void do_kill()
This function is a user hook that is called whenever a sequence is terminated by using either sequence.kill() or sequencer.stop_sequences() (which effectively calls sequence.kill()).
protected function uvm_sequence_item create_item( uvm_object_wrapper type_var, uvm_sequencer_base l_sequencer, string name )
Create_item will create and initialize a sequence_item or sequence using the factory. The sequence_item or sequence will be initialized to communicate with the specified sequencer.
virtual task start_item ( uvm_sequence_item item, int set_priority = -1, uvm_sequencer_base sequencer = null )
start_item and finish_item together will initiate operation of a sequence item. If the item has not already been initialized using create_item, then it will be initialized here to use the default sequencer specified by m_sequencer. Randomization may be done between start_item and finish_item to ensure late generation
virtual task finish_item ( uvm_sequence_item item, int set_priority = -1 )
finish_item, together with start_item together will initiate operation of a sequence_item. Finish_item must be called after start_item with no delays or delta-cycles. Randomization, or other functions may be called between the start_item and finish_item calls.
virtual task wait_for_grant( int item_priority = -1, bit lock_request = 0 )
This task issues a request to the current sequencer. If item_priority is not specified, then the current sequence priority will be used by the arbiter. If a lock_request is made, then the sequencer will issue a lock immediately before granting the sequence. (Note that the lock may be granted without the sequence being granted if is_relevant is not asserted).
When this method returns, the sequencer has granted the sequence, and the sequence must call send_request without inserting any simulation delay other than delta cycles. The driver is currently waiting for the next item to be sent via the send_request call.
virtual function void send_request( uvm_sequence_item request, bit rerandomize = 0 )
The send_request function may only be called after a wait_for_grant call. This call will send the request item to the sequencer, which will forward it to the driver. If the rerandomize bit is set, the item will be randomized before being sent to the driver.
virtual task wait_for_item_done( int transaction_id = -1 )
A sequence may optionally call wait_for_item_done. This task will block until the driver calls item_done or put. If no transaction_id parameter is specified, then the call will return the next time that the driver calls item_done or put. If a specific transaction_id is specified, then the call will return when the driver indicates completion of that specific item.
Note that if a specific transaction_id has been specified, and the driver has already issued an item_done or put for that transaction, then the call will hang, having missed the earlier notification.
function void use_response_handler( bit enable )
When called with enable set to 1, responses will be sent to the response handler. Otherwise, responses must be retrieved using get_response.
By default, responses from the driver are retrieved in the sequence by calling get_response.
An alternative method is for the sequencer to call the response_handler function with each response.
function bit get_use_response_handler()
Returns the state of the use_response_handler bit.
virtual function void response_handler( uvm_sequence_item response )
When the use_response_handler bit is set to 1, this virtual task is called by the sequencer for each response that arrives for this sequence.
function void set_response_queue_error_report_disabled( bit value )
By default, if the response_queue overflows, an error is reported. The response_queue will overflow if more responses are sent to this sequence from the driver than get_response calls are made. Setting value to 0 disables these errors, while setting it to 1 enables them.
function bit get_response_queue_error_report_disabled()
When this bit is 0 (default value), error reports are generated when the response queue overflows. When this bit is 1, no such error reports are generated.
function void set_response_queue_depth( int value )
The default maximum depth of the response queue is 8. These method is used to examine or change the maximum depth of the response queue.
Setting the response_queue_depth to -1 indicates an arbitrarily deep response queue. No checking is done.
function int get_response_queue_depth()
Returns the current depth setting for the response queue.
virtual function void clear_response_queue()
Empties the response queue for this sequence.
The uvm_void class is the base class for all UVM classes.
virtual class uvm_void
The uvm_object class is the base class for all UVM data and hierarchical classes.
virtual class uvm_object extends uvm_void
The uvm_transaction class is the root base class for UVM transactions.
virtual class uvm_transaction extends uvm_object
The base class for user-defined sequence items and also the base class for the uvm_sequence class.
class uvm_sequence_item extends uvm_transaction
The uvm_sequence_base class provides the interfaces needed to create streams of sequence items and/or other sequences.
class uvm_sequence_base extends uvm_sequence_item
If set, prevents the sequence from being randomized before being executed by the `uvm_do*() and `uvm_rand_send*() macros, or as a default sequence.
bit do_not_randomize
The constructor for uvm_sequence_base.
function new ( string name = "uvm_sequence" )
Returns 1 on items and 0 on sequences.
virtual function bit is_item()
Returns the sequence state as an enumerated value.
function uvm_sequence_state_enum get_sequence_state()
Waits until the sequence reaches one of the given state.
task wait_for_sequence_state( int unsigned state_mask )
Returns the integral recording transaction handle for this sequence.
function integer get_tr_handle()
Executes this sequence, returning when the sequence has completed.
virtual task start ( uvm_sequencer_base sequencer, uvm_sequence_base parent_sequence = null, int this_priority = -1, bit call_pre_post = 1 )
This task is a user-definable callback that is called before the optional execution of pre_body.
virtual task pre_start()
This task is a user-definable callback that is called before the execution of body only when the sequence is started with start.
virtual task pre_body()
This is the user-defined task where the main sequence code resides.
virtual task body()
This task is a user-definable callback task that is called on the parent sequence, if any sequence has issued a wait_for_grant() call and after the sequencer has selected this sequence, and before the item is randomized.
virtual task pre_do( bit is_item )
This function is a user-definable callback function that is called after the sequence item has been randomized, and just before the item is sent to the driver.
virtual function void mid_do( uvm_sequence_item this_item )
This function is a user-definable callback function that is called after the driver has indicated that it has completed the item, using either this item_done or put methods.
virtual function void post_do( uvm_sequence_item this_item )
This task is a user-definable callback task that is called after the execution of body only when the sequence is started with start.
virtual task post_body()
This task is a user-definable callback that is called after the optional execution of post_body.
virtual task post_start()
Returns the ‘starting phase’.
function uvm_phase get_starting_phase()
Sets the ‘starting phase’.
function void set_starting_phase( uvm_phase phase )
Sets the ‘automatically object to starting phase’ bit.
function void set_automatic_phase_objection( bit value )
Returns (and locks) the value of the ‘automatically object to starting phase’ bit.
function bit get_automatic_phase_objection()
The priority of a sequence may be changed at any point in time.
function void set_priority ( int value )
This function returns the current priority of the sequence.
function int get_priority()
The default is_relevant implementation returns 1, indicating that the sequence is always relevant.
virtual function bit is_relevant()
This method is called by the sequencer when all available sequences are not relevant.
virtual task wait_for_relevant()
Requests a lock on the specified sequencer.
task lock( uvm_sequencer_base sequencer = null )
Requests a lock on the specified sequencer.
task grab( uvm_sequencer_base sequencer = null )
Removes any locks or grabs obtained by this sequence on the specified sequencer.
function void unlock( uvm_sequencer_base sequencer = null )
Removes any locks or grabs obtained by this sequence on the specified sequencer.
function void ungrab( uvm_sequencer_base sequencer = null )
Returns a bit indicating whether this sequence is currently prevented from running due to another lock or grab.
function bit is_blocked()
Returns 1 if this sequence has a lock, 0 otherwise.
function bit has_lock()
This function will kill the sequence, and cause all current locks and requests in the sequence’s default sequencer to be removed.
function void kill()
This function is a user hook that is called whenever a sequence is terminated by using either sequence.kill() or sequencer.stop_sequences() (which effectively calls sequence.kill()).
virtual function void do_kill()
Create_item will create and initialize a sequence_item or sequence using the factory.
protected function uvm_sequence_item create_item( uvm_object_wrapper type_var, uvm_sequencer_base l_sequencer, string name )
start_item and finish_item together will initiate operation of a sequence item.
virtual task start_item ( uvm_sequence_item item, int set_priority = -1, uvm_sequencer_base sequencer = null )
finish_item, together with start_item together will initiate operation of a sequence_item.
virtual task finish_item ( uvm_sequence_item item, int set_priority = -1 )
This task issues a request to the current sequencer.
virtual task wait_for_grant( int item_priority = -1, bit lock_request = 0 )
The send_request function may only be called after a wait_for_grant call.
virtual function void send_request( uvm_sequence_item request, bit rerandomize = 0 )
A sequence may optionally call wait_for_item_done.
virtual task wait_for_item_done( int transaction_id = -1 )
When called with enable set to 1, responses will be sent to the response handler.
function void use_response_handler( bit enable )
Returns the state of the use_response_handler bit.
function bit get_use_response_handler()
When the use_response_handler bit is set to 1, this virtual task is called by the sequencer for each response that arrives for this sequence.
virtual function void response_handler( uvm_sequence_item response )
By default, if the response_queue overflows, an error is reported.
function void set_response_queue_error_report_disabled( bit value )
When this bit is 0 (default value), error reports are generated when the response queue overflows.
function bit get_response_queue_error_report_disabled()
The default maximum depth of the response queue is 8.
function void set_response_queue_depth( int value )
Returns the current depth setting for the response queue.
function int get_response_queue_depth()
Empties the response queue for this sequence.
virtual function void clear_response_queue()
This function marks the start of a child transaction, tr, by this component.
function integer begin_child_tr ( uvm_transaction tr, integer parent_handle = 0, string stream_name = "main", string label = "", string desc = "", time begin_time = 0 )
Start the default sequence for this phase, if any.
virtual function void start_phase_sequence( uvm_phase phase )
Provides a ‘Get-To-Lock’ Data Access Policy.
class uvm_get_to_lock_dap#( type T = int ) extends uvm_set_get_dap_base#(T)