# Sequence-Related Macros

Summary

Sequence-Related Macros
Sequence Action Macros | These macros are used to start sequences and sequence items on the default sequencer, m_sequencer.
`uvm_create |
`uvm_do |
`uvm_do_pri |
`uvm_do_with |
`uvm_do_pri_with |
Sequence on Sequencer Action Macros | These macros are used to start sequences and sequence items on a specific sequencer.
`uvm_create_on |
`uvm_do_on |
`uvm_do_on_pri |
`uvm_do_on_with |
`uvm_do_on_pri_with |
Sequence Action Macros for Pre-Existing Sequences | These macros are used to start sequences and sequence items that do not need to be created.
`uvm_send |
`uvm_send_pri |
`uvm_rand_send |
`uvm_rand_send_pri |
`uvm_rand_send_with |
`uvm_rand_send_pri_with |
`uvm_add_to_sequence_library | Adds the given sequence TYPE to the given sequence library LIBTYPE
`uvm_sequence_library_utils |
Sequencer Subtypes |
`uvm_declare_p_sequencer | This macro is used to declare a variable p_sequencer whose type is specified by SEQUENCER.

### Sequence Action Macros

These macros are used to start sequences and sequence items on the default sequencer, m_sequencer. This is determined a number of ways.

- the sequencer handle provided in the uvm_sequence_base::start method
- the sequencer used by the parent sequence
- the sequencer that was set using the uvm_sequence_item::set_sequencer method

### `uvm_create

>     `uvm_create(SEQ_OR_ITEM)

This action creates the item or sequence using the factory. It intentionally does zero processing. After this action completes, the user can manually set values, manipulate rand_mode and constraint_mode, etc.

### `uvm_do

>     `uvm_do(SEQ_OR_ITEM)

This macro takes as an argument a uvm_sequence_item variable or object. The argument is created using `uvm_create if necessary, then randomized. In the case of an item, it is randomized after the call to uvm_sequence_base::start_item() returns. This is called late-randomization. In the case of a sequence, the sub-sequence is started using uvm_sequence_base::start() with call_pre_post set to 0. In the case of an item, the item is sent to the driver through the associated sequencer.

For a sequence item, the following are called, in order

>     `uvm_create(item)
>     sequencer.wait_for_grant(prior) (task)
>     this.pre_do(1)                  (task)
>     item.randomize()
>     this.mid_do(item)               (func)
>     sequencer.send_request(item)    (func)
>     sequencer.wait_for_item_done()  (task)
>     this.post_do(item)              (func)

For a sequence, the following are called, in order

>     `uvm_create(sub_seq)
>     sub_seq.randomize()
>     sub_seq.pre_start()         (task)
>     this.pre_do(0)              (task)
>     this.mid_do(sub_seq)        (func)
>     sub_seq.body()              (task)
>     this.post_do(sub_seq)       (func)
>     sub_seq.post_start()        (task)

### `uvm_do_pri

>     `uvm_do_pri(SEQ_OR_ITEM, PRIORITY)

This is the same as `uvm_do except that the sequence item or sequence is executed with the priority specified in the argument

### `uvm_do_with

>     `uvm_do_with(SEQ_OR_ITEM, CONSTRAINTS)

This is the same as `uvm_do except that the constraint block in the 2nd argument is applied to the item or sequence in a randomize with statement before execution.

### `uvm_do_pri_with

>     `uvm_do_pri_with(SEQ_OR_ITEM, PRIORITY, CONSTRAINTS)

This is the same as `uvm_do_pri except that the given constraint block is applied to the item or sequence in a randomize with statement before execution.

### Sequence on Sequencer Action Macros

These macros are used to start sequences and sequence items on a specific sequencer. The sequence or item is created and executed on the given sequencer.

### `uvm_create_on

>     `uvm_create_on(SEQ_OR_ITEM, SEQR)

This is the same as `uvm_create except that it also sets the parent sequence to the sequence in which the macro is invoked, and it sets the sequencer to the specified SEQR argument.

### `uvm_do_on

>     `uvm_do_on(SEQ_OR_ITEM, SEQR)

This is the same as `uvm_do except that it also sets the parent sequence to the sequence in which the macro is invoked, and it sets the sequencer to the specified SEQR argument.

### `uvm_do_on_pri

>     `uvm_do_on_pri(SEQ_OR_ITEM, SEQR, PRIORITY)

This is the same as `uvm_do_pri except that it also sets the parent sequence to the sequence in which the macro is invoked, and it sets the sequencer to the specified SEQR argument.

### `uvm_do_on_with

>     `uvm_do_on_with(SEQ_OR_ITEM, SEQR, CONSTRAINTS)

This is the same as `uvm_do_with except that it also sets the parent sequence to the sequence in which the macro is invoked, and it sets the sequencer to the specified SEQR argument. The user must supply brackets around the constraints.

### `uvm_do_on_pri_with

>     `uvm_do_on_pri_with(SEQ_OR_ITEM, SEQR, PRIORITY, CONSTRAINTS)

This is the same as `uvm_do_pri_with except that it also sets the parent sequence to the sequence in which the macro is invoked, and it sets the sequencer to the specified SEQR argument.

### Sequence Action Macros for Pre-Existing Sequences

These macros are used to start sequences and sequence items that do not need to be created.

### `uvm_send

>     `uvm_send(SEQ_OR_ITEM)

This macro processes the item or sequence that has been created using `uvm_create. The processing is done without randomization. Essentially, an `uvm_do without the create or randomization.

### `uvm_send_pri

>     `uvm_send_pri(SEQ_OR_ITEM, PRIORITY)

This is the same as `uvm_send except that the sequence item or sequence is executed with the priority specified in the argument.

### `uvm_rand_send

>     `uvm_rand_send(SEQ_OR_ITEM)

This macro processes the item or sequence that has been already been allocated (possibly with `uvm_create). The processing is done with randomization. Essentially, an `uvm_do without the create.

### `uvm_rand_send_pri

>     `uvm_rand_send_pri(SEQ_OR_ITEM, PRIORITY)

This is the same as `uvm_rand_send except that the sequence item or sequence is executed with the priority specified in the argument.

### `uvm_rand_send_with

>     `uvm_rand_send_with(SEQ_OR_ITEM, CONSTRAINTS)

This is the same as `uvm_rand_send except that the given constraint block is applied to the item or sequence in a randomize with statement before execution.

### `uvm_rand_send_pri_with

>     `uvm_rand_send_pri_with(SEQ_OR_ITEM, PRIORITY, CONSTRAINTS)

This is the same as `uvm_rand_send_pri except that the given constraint block is applied to the item or sequence in a randomize with statement before execution.

### `uvm_add_to_sequence_library

Adds the given sequence TYPE to the given sequence library LIBTYPE

>     `uvm_add_to_seq_lib(TYPE,LIBTYPE)

Invoke any number of times within a sequence declaration to statically add that sequence to one or more sequence library types. The sequence will then be available for selection and execution in all instances of the given sequencer types.

>     class seqA extends uvm_sequence_base #(simple_item);

>        function new(string name=`"TYPE`");
>          super.new(name);
>        endfunction

>        `uvm_object_utils(seqA)

>        `uvm_add_to_seq_lib(seqA, simple_seq_lib_RST)
>        `uvm_add_to_seq_lib(seqA, simple_seq_lib_CFG)

>        virtual task body(); \
>          `uvm_info("SEQ_START", {"Executing sequence '", get_full_name(),
>                                 "' (",get_type_name(),")"},UVM_HIGH)
>          #10;
>        endtask

>      endclass

### `uvm_sequence_library_utils

>     `uvm_sequence_library_utils(TYPE)

Declares the infrastructure needed to define extensions to the uvm_sequence_library class. You define new sequence library subtypes to statically specify sequence membership from within sequence definitions. See also `uvm_add_to_sequence_library for more information.

>     typedef simple_seq_lib uvm_sequence_library #(simple_item);

>     class simple_seq_lib_RST extends simple_seq_lib;

>       `uvm_object_utils(simple_seq_lib_RST)

>       `uvm_sequence_library_utils(simple_seq_lib_RST)

>       function new(string name="");
>         super.new(name);
>       endfunction

>     endclass

Each library, itself a sequence, can then be started independently on different sequencers or in different phases of the same sequencer. See uvm_sequencer_base::start_phase_sequence for information on starting default sequences.

### Sequencer Subtypes

### `uvm_declare_p_sequencer

This macro is used to declare a variable p_sequencer whose type is specified by SEQUENCER.

>     `uvm_declare_p_sequencer(SEQUENCER)

The example below shows using the `uvm_declare_p_sequencer macro along with the uvm_object_utils macros to set up the sequence but not register the sequence in the sequencer’s library.

>     class mysequence extends uvm_sequence#(mydata);
>       `uvm_object_utils(mysequence)
>       `uvm_declare_p_sequencer(some_seqr_type)
>       task body;
>         //Access some variable in the user's custom sequencer
>         if(p_sequencer.some_variable) begin
>           ...
>         end
>       endtask
>     endclass

> 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.

> virtual function void set_sequencer(
> | uvm_sequencer_base | sequencer
> )

Sets the default sequencer for the sequence to 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.

> class uvm_sequence_library #(
> | type | REQ | = | uvm_sequence_item,
> |  | RSP | = | REQ
> ) extends uvm_sequence #(REQ,RSP)

The uvm_sequence_library is a sequence that contains a list of registered sequence types.
Adds the given sequence TYPE to the given sequence library LIBTYPE

> virtual function void start_phase_sequence(
> | uvm_phase | phase
> )

Start the default sequence for this phase, if any.