TO Be coming

Nov 24, 2026

UVM Course :Day 21: Week 3 Review + RAL Integration — Add a Register Block to a Real Testbench

Day 21: Week 3 Review + RAL Integration — Add a Register Block to a Real Testbench
Advertisement
Top banner — drop your 728×90 or responsive ad unit here.

Day 21: Week 3 Review + RAL Integration — Add a Register Block to a Real Testbench

A 30-day SystemVerilog/UVM verification series. Six days of RAL. Today they have to fit into a working DUT testbench and prove their worth.

Week 3 is behind you. You can build a register model, map it to the bus, connect it through an adapter, update it via a predictor, run the standard sequences, and extend it with callbacks. Each was small. Together they form the register file verification layer that every real DUT testbench needs.

Today's mini-project is the checkpoint before Week 4. It has one question: can you add a register block to a working testbench without breaking what already worked? The answer is usually "yes, but only if you do it in the right order." The wrong order gives you a testbench where nothing passes and no individual component is obviously wrong.


1. The Week 3 Checklist

Audit yourself before you build. If any answer is "not sure," reread that day.

FromConceptCan you explain it?
Day 15The four RAL classesWhat does each of uvm_reg, uvm_reg_field, uvm_reg_block, uvm_mem model?
Day 16Access types, configure(), resetWhy is declaring W1C as RW a bug?
Day 17create_map, add_reg, lock_modelHow does a register's address resolve?
Day 18Adapter, predictor, auto-predictWhy does auto-predict alone fail with volatile fields?
Day 19read, write, mirror, update, poke, peekWhen is mirror(status, UVM_CHECK) the right operation?
Day 20Built-in sequences, callbacks, register coverageWhat does uvm_reg_bit_bash_seq prove?
The failure mode to watch for: each piece works in isolation but not together. The most common cause is a timing mismatch — the DUT and the model are not reset at the same time, so the model's mirror diverges from the DUT before any stimulus runs. Everything looks broken and nothing is.

2. What You Are Building

Start with the Day 14 testbench (FIFO agents, virtual sequence, advanced scoreboard, coverage) and add a register block to the DUT. For this exercise, that means either:

  • Use the FIFO as-is and add a register block next to it — the FIFO stays a direct interface, and a new register block (CTRL, STATUS, INT_ENABLE, SCRATCH) is added on its own bus.
  • Wrap the FIFO in an APB register file — the DUT becomes "APB register block that controls a FIFO," and the testbench talks to it via APB register accesses.

The first option is simpler. The second is closer to what a real DUT looks like. This mini-project uses the first option; the second is essentially what the capstone in Week 4 becomes.

Same directory as Day 14, plus:

fifo_tb/
├── ... (everything from Day 14) ...
├── dut_reg_block.sv          // NEW: the block
├── ctrl_reg.sv               // NEW: CTRL register
├── status_reg.sv             // NEW: STATUS register
├── fifo_reg_adapter.sv       // NEW: adapter
├── fifo_ral_seq_lib.sv       // NEW: custom RAL sequences
├── fifo_ral_test.sv          // NEW: test that runs the RAL sequences

3. Build Order

Same incremental discipline as Weeks 1 and 2. Each step compiles and runs on its own.

  1. Baseline. Confirm the Day 14 test still passes. Note the pass line in the log so you can compare after each step.
  2. Add the register model classes. Build the DUT without RAL code yet. Compile-only: ctrl_reg, status_reg, dut_reg_block. No testbench changes.
  3. Add the adapter. Compile-only. Verify the reg2bus/bus2reg types match the bus item class.
  4. Add the block to the env. Instantiate the model and adapter. Wire set_sequencer. Do not run any register accesses yet. The base test should still pass unchanged.
  5. Print and cross-check the map. Call reg_model.print() and reg_model.default_map.print(). Cross-reference against your register spec. Fix any wrong address before writing a register test.
  6. Run uvm_reg_hw_reset_seq. If it passes, reset values are correct. If it fails, the model or the DUT reset values are wrong — fix before continuing.
  7. Write one custom RAL sequence. Something small — a pattern write/read/read on CTRL. Run it. Confirm the register behaves as specified.
  8. Add a register callback. Enforce one invariant (e.g., CTRL.ENABLE cannot be cleared while STATUS.BUSY is set). The base test should still pass.
  9. Add the end-of-test block mirror check. reg_model.mirror(status, UVM_CHECK) at the end of every RAL test.
  10. Run the full Day 14 smoke test. Confirm it still passes. RAL should be invisible to tests that do not use it.
Step 4 is where most people break things. Adding a register model to the env changes the timing of build_phase and connect_phase. If the base test starts failing after step 4, the most likely cause is that the model's construction delayed the agent's construction, or the model's default_map got connected to the wrong sequencer. Check those before looking at the agents.

4. Reference Implementation (skeletons)

ctrl_reg.sv — one register with three fields:

class ctrl_reg extends uvm_reg;
    `uvm_object_utils(ctrl_reg)

    rand uvm_reg_field enable;
    rand uvm_reg_field mode;
    rand uvm_reg_field clr;

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

    virtual function void build();
        enable = uvm_reg_field::type_id::create("enable");
        enable.configure(this, 1, 0, "RW", 0, 1'b0, 1, 1, 0);

        mode = uvm_reg_field::type_id::create("mode");
        mode.configure(this, 2, 1, "RW", 0, 2'b00, 1, 1, 0);

        clr = uvm_reg_field::type_id::create("clr");
        clr.configure(this, 1, 3, "WO", 0, 1'b0, 1, 1, 0);
    endfunction
endclass

dut_reg_block.sv — the container:

class dut_reg_block extends uvm_reg_block;
    `uvm_object_utils(dut_reg_block)

    rand ctrl_reg   ctrl;
    rand status_reg status;

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

    virtual function void build();
        default_map = create_map("default_map", 0, 4, UVM_LITTLE_ENDIAN);
        add_hdl_path("tb.dut", "RTL");

        ctrl = ctrl_reg::type_id::create("ctrl");
        ctrl.configure(this, "regs.ctrl_reg", "");
        ctrl.add_hdl_path_slice("q", 0, 32);
        ctrl.build();
        default_map.add_reg(ctrl, 'h00, "RW");

        status = status_reg::type_id::create("status");
        status.configure(this, "regs.status_reg", "");
        status.add_hdl_path_slice("q", 0, 32);
        status.build();
        default_map.add_reg(status, 'h04, "RO");
    endfunction
endclass

fifo_reg_adapter.sv — the same shape as Day 18, adjusted to the bus item:

class fifo_reg_adapter extends uvm_reg_adapter;
    `uvm_object_utils(fifo_reg_adapter)

    function new(string name = "fifo_reg_adapter");
        super.new(name);
        supports_byte_enable = 0;
        provides_responses    = 1;
    endfunction

    virtual function uvm_sequence_item reg2bus(const ref uvm_reg_bus_op rw);
        bus_item item = bus_item::type_id::create("item");
        item.addr = rw.addr;
        item.data = rw.data;
        item.we   = (rw.kind == UVM_WRITE);
        return item;
    endfunction

    virtual function void bus2reg(uvm_sequence_item bus_item,
                                  ref uvm_reg_bus_op rw);
        bus_item item;
        if (!$cast(item, bus_item)) begin
            `uvm_fatal("NOT_BUS", "adapter got wrong item type")
            return;
        end
        rw.kind   = item.we ? UVM_WRITE : UVM_READ;
        rw.addr   = item.addr;
        rw.data   = item.data;
        rw.status = UVM_IS_OK;
    endfunction
endclass

fifo_ral_test.sv — the test that runs the standard sequences:

class fifo_ral_test extends fifo_base_test;
    `uvm_component_utils(fifo_ral_test)

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

    virtual task run_phase(uvm_phase phase);
        uvm_reg_hw_reset_seq reset_seq;
        fifo_ctrl_pattern_seq pat_seq;
        uvm_status_e status;

        phase.raise_objection(this);
        phase.phase_done.set_drain_time(this, 500ns);

        // 1. Reset DUT and model together
        fork
            begin
                env.vif.rst_n = 0;
                repeat (5) @(posedge env.vif.clk);
                env.vif.rst_n = 1;
            end
            env.reg_model.reset();
        join
        @(posedge env.vif.clk);

        // 2. Standard 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);

        // 3. Custom pattern sequence
        pat_seq = fifo_ctrl_pattern_seq::type_id::create("pat_seq");
        pat_seq.model = env.reg_model;
        pat_seq.start(env.bus_agent.sqr);

        // 4. End-of-test: verify every register matches the model
        env.reg_model.mirror(status, UVM_CHECK);
        if (status != UVM_IS_OK)
            `uvm_error("RAL", "post-test mirror failed")

        phase.drop_objection(this);
    endtask
endclass

fifo_ctrl_pattern_seq.sv — a custom RAL sequence (Day 20's pattern):

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

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

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

        // Write ENABLE=1, MODE=2 -> expected 0x05
        model.ctrl.write(status, 8'h05);
        model.ctrl.read(status, value);
        if (value[2:0] != 3'b101)
            `uvm_error("PAT", $sformatf("expected 3'b101, got 3'b%0b", value[2:0]))

        // Change MODE to 3, keep ENABLE=1 -> expected 0x07
        model.ctrl.write(status, 8'h07);
        model.ctrl.read(status, value);
        if (value[2:0] != 3'b111)
            `uvm_error("PAT", $sformatf("expected 3'b111, got 3'b%0b", value[2:0]))
    endtask
endclass

5. Week 3 Self-Assessment

Before Day 22, every one of these should be true:

  • The register model compiles, locks, and prints a map that matches the spec's register table.
  • uvm_reg_hw_reset_seq passes with zero UVM_ERROR.
  • The custom pattern sequence passes with zero UVM_ERROR.
  • The end-of-test mirror(status, UVM_CHECK) reports UVM_IS_OK.
  • The Day 14 smoke test still passes with the register model present in the env.
  • Deliberately changing a reset value in the model causes uvm_reg_hw_reset_seq to fail with a specific mismatch message.
  • Running ten seeds produces ten passes. If any fail, you have a race condition — most often the DUT/model reset alignment, or the drain time being too short for the standard RAL sequences.

If any of these is not true, fix it before Day 22. The Week 4 protocol and capstone work builds on the register layer; a buggy RAL model makes protocol-level debugging impossible.


6. What Day 22 Will Add

Tomorrow begins Week 4 with Protocol Layer Verification (APB / AXI-Lite). You will apply everything from Weeks 1–3 to a real bus protocol — the timing requirements, the handshake, the assertions, and the register block that sits behind it. This is what verification of a real DUT looks like.


7. Quiz

Ten questions spanning Week 3.

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

    Coming Up Next: Day 22 — Protocol Layer Verification (APB / AXI-Lite)

    • Bus timing requirements — setup, access, hold phases, and where they live in the driver.
    • Protocol assertions — checking the bus handshake from the monitor side, without coupling to the driver.
    • Register block behind the bus — the same RAL model from Week 3, now talking through a real bus protocol.
    • VIP versus hand-written agent — when to reuse a protocol agent and when to write your own.
    ← Back to the 30-Day UVM Course
    See all 30 days, week by week.

    Series: 30 days of SystemVerilog/UVM verification. Day 21 — Week 3's checkpoint.

    No comments:

    Post a Comment

    SiteMap