TO Be coming

Nov 23, 2026

UVM Course :Day 20: RAL Sequences and Callbacks — Built-in UVM RAL Sequences and uvm_reg_cbs

Day 20: RAL Sequences and Callbacks — Built-in UVM RAL Sequences and uvm_reg_cbs
Advertisement
Top banner — drop your 728×90 or responsive ad unit here.

Day 20: RAL Sequences and Callbacks — Built-in UVM RAL Sequences and uvm_reg_cbs

A 30-day SystemVerilog/UVM verification series. UVM ships a set of register sequences that would take you weeks to write correctly. Today you learn to use them, then how to write your own.

Yesterday you learned the six RAL operations. Writing them by hand in a test is fine for two registers. For a register file with two hundred, hand-written sequences are a waste of time and a source of typos. UVM ships a set of standard register sequences that verify a register block against a model. Plug them in, run them, get pass/fail. Then, for the specific behaviours the standard sequences do not cover, write your own uvm_reg_sequence.


1. The Built-in Sequences

These sequences live in uvm_reg_sequence's subclasses under uvm_reg built-in tests. Each targets a specific class of register bug.

SequenceWhat it checks
uvm_reg_hw_reset_seqEvery register's value after reset matches the model's reset value.
uvm_reg_bit_bash_seqEvery writable bit can be set to 0 and 1 independently. Catches stuck bits and adjacent-bit shorts.
uvm_reg_access_seqFrontdoor and backdoor reads return the same value. Catches mismatches between the bus and the RTL's internal value.
uvm_reg_shared_access_seqVerifies that a register reachable by multiple paths behaves identically on all of them.
uvm_mem_walk_seqWalking-1s and walking-0s through a memory array to catch address and data line faults.

Running them from a test:

class fifo_ral_smoke_test extends uvm_test;
    `uvm_component_utils(fifo_ral_smoke_test)
    fifo_env env;

    function new(string name, uvm_component parent);
        super.new(name, parent);
    endfunction

    virtual function void build_phase(uvm_phase phase);
        super.build_phase(phase);
        env = fifo_env::type_id::create("env", this);
    endfunction

    virtual task run_phase(uvm_phase phase);
        phase.raise_objection(this);
        phase.phase_done.set_drain_time(this, 500ns);

        uvm_reg_hw_reset_seq reset_seq;
        uvm_reg_bit_bash_seq  bash_seq;

        // 1. Reset-value check
        reset_seq = uvm_reg_hw_reset_seq::type_id::create("reset_seq");
        reset_seq.model = env.reg_model;
        reset_seq.start(env.bus_agent.sqr);

        // 2. Bit-bash every writable bit
        bash_seq = uvm_reg_bit_bash_seq::type_id::create("bash_seq");
        bash_seq.model = env.reg_model;
        bash_seq.start(env.bus_agent.sqr);

        phase.drop_objection(this);
    endtask
endclass

Three things to notice:

  • The sequence's model field points at the block to test. The sequence walks that block automatically.
  • The sequence starts on the bus agent's sequencer, not on a virtual sequencer. The register operations travel through the adapter to the bus.
  • The drain time lets any in-flight transactions finish before the test ends. RAL sequences can be slow because they do many individual register accesses.
What "pass" means for these sequences: the test's UVM_ERROR count is zero. These sequences use uvm_error for every mismatch, so a clean run means every register they touch matches the model. That is a very strong statement and worth running on every regression.

2. The Reset Sequence and Reset Value

uvm_reg_hw_reset_seq is the most valuable built-in. It drives reset, then reads every register through the frontdoor and compares against the model's reset value. If any register's reset value in the model is wrong, this sequence reports it as a mismatch on the first comparison — before any test writes to it.

// Before running the sequence, the test must have reset the DUT
// and the model together. See Day 16, section 3.
phase.raise_objection(this);
fork
    // DUT reset
    begin
        vif.rst_n = 0;
        repeat (5) @(posedge vif.clk);
        vif.rst_n = 1;
    end
    // Model reset — same delta
    begin
        env.reg_model.reset();
    end
join
@(posedge vif.clk);

// Then run the sequence — it reads every register and compares
uvm_reg_hw_reset_seq reset_seq = uvm_reg_hw_reset_seq::type_id::create("reset_seq");
reset_seq.model = env.reg_model;
reset_seq.start(env.bus_agent.sqr);
phase.drop_objection(this);
Do not run uvm_reg_hw_reset_seq without resetting first. The sequence assumes the DUT is freshly reset. If the test has already written to some registers, those writes are still in place when the sequence reads them, and the sequence reports them as reset-value mismatches. Reset, then run.

3. Writing a Custom RAL Sequence

Custom RAL sequences extend uvm_reg_sequence and set their model field. The body() uses the model directly — no start_item, no sequence item, just register operations.

class fifo_write_pattern_seq extends uvm_reg_sequence #(uvm_sequence #(bus_item));
    `uvm_object_utils(fifo_write_pattern_seq)

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

    virtual task body();
        uvm_status_e   status;
        uvm_reg_data_t value;

        // A specific pattern that catches ordering bugs:
        // write 0xAA, read it, write 0x55, read it, read again.
        model.ctrl.write(status, 8'hAA);
        model.ctrl.read(status, value);
        if (value[7:0] != 8'hAA)
            `uvm_error("RSEQ", $sformatf("expected 0xAA, got 0x%0h", value))

        model.ctrl.write(status, 8'h55);
        model.ctrl.read(status, value);
        if (value[7:0] != 8'h55)
            `uvm_error("RSEQ", $sformatf("expected 0x55, got 0x%0h", value))

        // Read again without a write — should still be 0x55
        model.ctrl.read(status, value);
        if (value[7:0] != 8'h55)
            `uvm_error("RSEQ", $sformatf("expected 0x55 (stable), got 0x%0h", value))
    endtask
endclass

Start it the same way as the built-in sequences:

fifo_write_pattern_seq seq = fifo_write_pattern_seq::type_id::create("seq");
seq.model = env.reg_model;
seq.start(env.bus_agent.sqr);

This pattern is worth generalizing: write a pattern, read it back, verify stability across two reads, repeat for the next pattern. It catches most register-storage bugs without the overhead of bit-bash.


4. uvm_reg_cbs — Callbacks on Register Accesses

Callbacks on registers let you attach behaviour to every read and write of a register — pre-access checks, post-access side effects, coverage sampling. They are the register equivalent of the component callbacks from Day 11.

Declare a callback class with a virtual method for the hook point:

class ctrl_reg_cb extends uvm_reg_cbs;
    `uvm_object_utils(ctrl_reg_cb)

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

    // Called before the write hits the bus
    virtual function void pre_write(uvm_reg_item rw);
        if (rw.value[0] == 1'b0 && ctrl_enabled_elsewhere)
            `uvm_error("REG_CB", "cannot clear ENABLE while MODE is running")
    endfunction

    // Called after the write completes on the bus
    virtual function void post_write(uvm_reg_item rw);
        `uvm_info("REG_CB", $sformatf("CTRL written to 0x%0h", rw.value), UVM_HIGH)
    endfunction
endclass

Attach it to the register in the test's build_phase:

ctrl_reg_cb cb = ctrl_reg_cb::type_id::create("cb");
uvm_reg_cb::add(env.reg_model.ctrl, cb);

Now every write to ctrl through the model invokes pre_write and post_write. The register does not know the callback exists; the callback does not need a handle to the register beyond what the callback framework provides.

What callbacks are good for on registers: validating that a write is legal given the current state, sampling coverage on field transitions, logging field-level changes, and injecting specific error conditions on a subset of writes. They are not a substitute for a proper scoreboard — they are a place to add checks that are specific to one register's semantics.

5. Register Coverage

RAL can auto-generate coverage for each register — every field's value range becomes a set of bins, and every access path (frontdoor, backdoor) is tracked. Enable it by passing UVM_CVR_REG_BITS to the register's constructor instead of UVM_NO_COVERAGE:

function new(string name = "ctrl_reg");
    super.new(name, 32, UVM_CVR_REG_BITS);
endfunction

Then in check_phase or report_phase, dump the coverage:

function void report_phase(uvm_phase phase);
    `uvm_info("COV", $sformatf("REG coverage = %0.2f%%",
              reg_model.get_coverage()), UVM_LOW)
endfunction

For most DUTs, register coverage is a small fraction of overall coverage — the interesting coverage is behavioural (write-then-read patterns, wrap-around, simultaneous access). Use register coverage as a sanity check, not as a closure target.


6. What Day 21 Will Add

Tomorrow is the Week 3 Review + RAL Integration. You will take everything from Days 15–20 and integrate a register block into a working DUT testbench. The mini-project is the checkpoint before Week 4's protocol and capstone work.


7. Quiz

Ten questions on RAL sequences and callbacks.

Question 1 of 10
Loading…
    0 / 10
    Advertisement
    Bottom banner — drop your 728×90 or responsive ad unit here.

    Coming Up Next: Day 21 — Week 3 Review + RAL Integration

    • Integrate RAL into the FIFO testbench — add a register block to the Day 14 environment.
    • Run the standard RAL sequences — reset, bit-bash, access.
    • Write a custom RAL sequence — verify a specific register's semantics that the standard sequences do not cover.
    • Add register callbacks — enforce an invariant and sample coverage.
    ← Back to the 30-Day UVM Course
    See all 30 days, week by week.

    Series: 30 days of SystemVerilog/UVM verification. Day 20's RAL sequences and callbacks.

    No comments:

    Post a Comment

    SiteMap