Verification #53 · 2026-11-15 · UVM bus driver and register model · Medium · about 35 min
Build the testbench for an APB register block
apb_regs.sv is a block of four 8-bit registers behind an APB-style bus (apb_if). A transfer starts with a setup clock (psel = 1, penable = 0), followed by access clocks (psel = penable = 1). It completes on the clock edge where pready = 1 during an access clock. Registers 0, 1 and 2 are ready in the first access clock, but register 3 inserts one wait state, so the driver has to hold the transfer until pready. On a read, prdata is valid in the completing clock. The registers:
| Reg | Behavior |
|---|---|
| 0 | read/write. Every write also ORs its data into register 3 |
| 1 | read/write, but only the low 4 bits are kept: the upper bits read as 0 |
| 2 | read-only: the number of completed writes to any address so far, modulo 256. A write to 2 changes nothing but is still counted |
| 3 | sticky flags: a write clears the bits it writes as 1 |
All registers are 0 after reset.
Write the verification components in components.sv. The monitor and environment in env.sv are provided, and they use your four classes by name. The monitor sends one apb_item for every completed transfer, with write, addr, data (the write data) and rdata (the data read).
apb_item: randomwrite,addr,data, andidle(clocks to wait before the transfer). Transfers should often follow each other with no idle clock, and reads and writes should both be common.apb_seq: sendscountrandom items.apb_driver: waits out reset, then for each item waitsidleclocks and runs one transfer: setup clock, then access clocks untilpreadyis 1 at a clock edge. Then it dropspselandpenableand takes the next item. The next item may start in the very next clock.apb_scoreboard: keeps a model of the four registers and applies every write the monitor reports. It checks the data of every read. Every item the monitor sends counts inchecked, and every mismatch counts inerrors; report the first few withuvm_error.
Run uses tb.sv: 60 random transfers on the correct block. Submit runs your testbench on the correct block (100 and then 1500 transfers) and on four faulty blocks. The test also fails if some of the transfers you asked for never complete on the bus. Your scoreboard must stay quiet on the correct block and catch each fault.
Write and run your answer in the browser. The hidden tests check it, and it’s free.