Module 1: Reusable Stimulus | Intermediate UVM

Layered Sequences

Build reusable stimulus by composing high-level scenarios from lower-level protocol sequences without duplicating driver-level transaction logic.

Learning objectives

  • Explain why layered sequences improve stimulus reuse and maintainability.
  • Distinguish a parent sequence from the child sequences it composes.
  • Start child sequences correctly from a parent sequence.
  • Understand the difference between sequence layering and multi-agent orchestration.
  • Use sequence layering to separate scenario intent from protocol-level stimulus.
  • Debug a layered sequence by tracing control from the parent sequence to the driver.

Step 1: Understand the concept

A layered sequence is a sequence architecture in which a higher-level sequence builds a meaningful scenario by composing lower-level sequences.

The important idea is separation of intent from implementation. A high-level sequence should describe what scenario should happen, while lower-level sequences encapsulate how the required protocol transactions are generated.

For example, imagine a bus agent that supports read and write transactions. Instead of writing every bus transaction directly inside every test, we can build reusable layers:

Test scenario
 |
 v


+-----------------------+
| high-level sequence   |
| "write configuration" |
+-----------------------+
|
v
+-----------------------+
| write sequence        |
| creates bus writes    |
+-----------------------+
|
v
+-----------------------+
| bus sequence item     |
| address/data/control  |
+-----------------------+
|
v
+-----------------------+
| sequencer -> driver   |
+-----------------------+

The higher layer should not need to duplicate the details required to construct every individual bus transaction. If the protocol changes, the lower-level sequence can often be updated without rewriting every scenario.

Core principle: A layered sequence should make the higher-level sequence easier to understand, not merely add another class between the test and the driver.

Step 2: Know what a layer owns

Before creating a sequence hierarchy, decide what each layer is responsible for. A useful division is:

Layer Typical responsibility
Scenario sequence Expresses the verification intent and business-level operation.
Protocol sequence Translates that operation into legal protocol transactions.
Sequence item Represents one transaction consumed by the sequencer/driver.
Driver Converts sequence items into pin-level interface activity.

Consider a memory-mapped bus. A scenario might say:

write register 0x20 with value 0x55

The scenario sequence should not need to know every handshake detail of the bus. A reusable write sequence can translate the operation into the appropriate transaction.

This gives us a clean dependency direction:

Scenario intent
  |
  v


Reusable protocol sequence
|
v
Sequence item
|
v
Driver implementation

Step 3: Build a reusable child sequence

Start with a small protocol-level sequence. Assume the environment has a bus_sequencer that accepts bus_item transactions.

class bus_write_seq extends uvm_sequence #(bus_item);


`uvm_object_utils(bus_write_seq)

rand bit [31:0] addr;
rand bit [31:0] data;

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

task body();
bus_item req;


req = bus_item::type_id::create("req");

start_item(req);

req.write = 1'b1;
req.addr  = addr;
req.data  = data;

finish_item(req);


endtask

endclass

This sequence owns the mechanics of creating a bus write transaction. A higher-level scenario does not need to repeat the start_item(), field assignment, and finish_item() pattern.

Why this matters: If ten different scenarios need to perform a bus write, they can reuse this sequence instead of implementing ten slightly different versions of the same transaction generation logic.

Step 4: Compose the child sequence from a parent sequence

Now create a higher-level sequence that represents a meaningful verification operation.

Suppose the scenario is:

1. Write 0x55 to address 0x20.


2. Write 0xAA to address 0x24.
3. Continue with the rest of the test scenario.

The parent sequence can create and start two instances of the reusable write sequence.

class configure_block_seq extends uvm_sequence #(bus_item);


`uvm_object_utils(configure_block_seq)

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

task body();
bus_write_seq write_seq;


write_seq = bus_write_seq::type_id::create("write_seq_1");
write_seq.addr = 'h20;
write_seq.data = 'h55;
write_seq.start(m_sequencer);

write_seq = bus_write_seq::type_id::create("write_seq_2");
write_seq.addr = 'h24;
write_seq.data = 'hAA;
write_seq.start(m_sequencer);


endtask

endclass

The parent sequence expresses the scenario, while bus_write_seq owns the details of generating a bus write.

The important control flow is:

configure_block_seq
   |
   +----> bus_write_seq(addr=0x20, data=0x55)
   |
   +----> bus_write_seq(addr=0x24, data=0xAA)
                     |
                     v
                bus_item
                     |
                     v
                  driver

Step 5: Understand sequence execution

When a parent sequence calls:

write_seq.start(m_sequencer);

the child sequence executes on the selected sequencer. Its body() generates sequence items, and those items participate in the normal sequencer-driver handshake.

The parent sequence normally waits for the child sequence to complete before continuing. Therefore:

write_seq.start(m_sequencer);


next_operation();

means that next_operation() is reached after the child sequence finishes.

Debugging insight: If a parent sequence appears to "stop" at a child sequence, investigate the child sequence and the sequencer-driver handshake before assuming the parent sequence is broken.

Step 6: Sequence layering is not the same as a virtual sequence

These concepts are related, but they solve different problems.

Layered sequences are useful when one sequence can build a higher-level operation from lower-level sequences on the same stimulus path.

A virtual sequence is typically used when higher-level stimulus must coordinate activity across multiple sequencers or agents.

Problem Typical solution
Build a register-write operation from reusable bus transactions Layered sequences
Build a packet operation from reusable lower-level packet sequences Layered sequences
Coordinate traffic on APB and an interrupt interface Virtual sequence
Coordinate stimulus across several protocol agents Virtual sequence / virtual sequencer architecture

Do not introduce a virtual sequencer simply because a parent sequence exists. First identify whether the scenario actually needs to coordinate multiple sequencers.

Step 7: Avoid hard-coded protocol knowledge at the wrong layer

A common design mistake is allowing every high-level sequence to manipulate protocol fields directly.

For example, this can become difficult to maintain:

req.valid = 1;


req.write = 1;
req.addr  = 'h20;
req.data  = 'h55;
req.wait_states = 3;
// repeated in many scenario sequences

If protocol rules change, many sequences must then be modified.

A better architecture centralizes protocol-specific construction in reusable sequences:

configure_block_seq
    |
    v


bus_write_seq
|
v
bus_item
|
v
driver

The higher-level sequence can remain focused on intent while the lower-level sequence handles protocol construction.

Step 8: Improve the design with parameters and randomization

Once the deterministic version works, make the child sequence reusable across more scenarios.

class bus_write_seq extends uvm_sequence #(bus_item);


`uvm_object_utils(bus_write_seq)

rand bit [31:0] addr;
rand bit [31:0] data;

constraint aligned_addr_c {
addr[1:0] == 2'b00;
}

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

task body();
bus_item req;


req = bus_item::type_id::create("req");

start_item(req);
req.write = 1'b1;
req.addr  = addr;
req.data  = data;
finish_item(req);


endtask

endclass

The parent sequence can now control the scenario while the child sequence retains reusable protocol constraints.

A useful development order is:

  1. Make one deterministic child sequence work.
  2. Compose it from a parent sequence.
  3. Verify that the expected transactions reach the driver.
  4. Add constraints and controlled randomization.
  5. Only then generalize the sequence for broader reuse.

Step 9: Debug a layered sequence systematically

When layered stimulus fails, do not immediately modify every sequence involved. Trace the hierarchy one level at a time.

  1. Did the parent sequence start?
    Add a clear uvm_info message at the beginning of its body().
  2. Did the child sequence start?
    Report its name, address, data, or other important parameters.
  3. Did the child generate a sequence item?
    Check the transaction immediately before and after finish_item().
  4. Did the driver receive the item?
    Confirm the driver's get_next_item() or equivalent handshake.
  5. Did the monitor observe the expected protocol activity?
    Use the monitor transaction as independent evidence.

This produces a useful verification chain:

Parent started
  |
  v


Child started
|
v
Sequence item generated
|
v
Driver received item
|
v
DUT activity occurred
|
v
Monitor observed transaction

Each step gives you evidence about where the problem actually exists.

Step 10: Recognize common layering mistakes

Mistake 1: Making the parent sequence too low-level. If the parent contains every protocol detail, the abstraction boundary has failed.
Mistake 2: Creating unnecessary layers. A sequence hierarchy should solve a reuse or abstraction problem. Do not create five sequence classes when one reusable sequence is sufficient.
Mistake 3: Randomizing everything immediately. First prove the sequence hierarchy with deterministic stimulus. Randomization should increase scenario space, not hide architectural problems.
Mistake 4: Using a virtual sequence for a single-sequencer problem. Multi-agent coordination is a different architectural problem and will be covered later.
Mistake 5: Ignoring the sequencer relationship. A child sequence must execute on a compatible sequencer. If the sequence item type or sequencer relationship is wrong, the problem is architectural rather than merely a randomization issue.

Try it yourself

Create a small layered stimulus architecture for a memory-mapped peripheral.

  1. Create a reusable bus_write_seq.
  2. Create a reusable bus_read_seq.
  3. Create a higher-level configure_block_seq.
  4. Make configure_block_seq perform two writes followed by one read.
  5. Run the sequence on a single bus sequencer.
  6. Use the monitor output to confirm that the expected three transactions occurred in order.

Challenge: Modify the child sequences so that the addresses and data are configurable without changing the structure of configure_block_seq.

Verification checkpoint

You should be able to answer these questions before moving on:

  1. Why is a layered sequence more reusable than putting all transaction generation in a test?
  2. What responsibility belongs in the high-level sequence?
  3. What responsibility belongs in the protocol-level sequence?
  4. What happens when a parent sequence calls child_seq.start(m_sequencer)?
  5. When would a virtual sequence be more appropriate than simple sequence layering?
Expected reasoning: The high-level sequence should express scenario intent, the lower-level sequence should encapsulate reusable protocol stimulus, and the driver should remain responsible for translating sequence items into pin-level activity.

Key takeaways

  • Layered sequences separate high-level scenario intent from lower-level protocol stimulus.
  • A parent sequence can compose reusable child sequences instead of duplicating transaction-generation code.
  • Child sequences should execute on compatible sequencers and participate in the normal sequencer-driver handshake.
  • Deterministic layered stimulus should be validated before adding extensive randomization.
  • Sequence layering and virtual sequences are related but solve different architectural problems.
  • Good layering reduces duplication while preserving a clear abstraction boundary between scenario intent and protocol implementation.
  • Debug layered stimulus by tracing evidence from parent sequence to child sequence, sequence item, driver, and monitor.