This exercise has a walk: One register write, end to end. It plays step by step beside the code.
blk’s map runs with auto-prediction off (set_auto_predict(0), in the test), as real testbenches do when something besides the register model can touch the DUT and the mirror has to follow observed bus traffic. blk.r.write(...) still writes over the bus but leaves the mirror alone. Only a uvm_reg_predictor updates it, and only once it has .map and .adapter set and bus transactions arriving on bus_in.
predictor is already constructed in env::build_phase (in the test), but not configured or connected.
RequirementsIn env::connect_phase
predictor.map and predictor.adapter are the map and adapter the bus uses.drv.ap, where the driver broadcasts every access it completes, is connected to predictor.bus_in.Right nowmirror=0 after first write, want aa. Setting .map and .adapter alone isn’t enough: the predictor’s write() is never called until bus_in has a connection.
Done whenAfter each of the two writes in the test, blk.r.get_mirrored_value() equals what was just written. Missing either piece leaves the mirror at its reset value, 0.
One working answer: brokenbench's own fix for this exercise. Try a few runs first.
What changes, against the code you started with:
csr.write(status, 'h005): EN = 1, MODE = 2. The first thing write() does is set(), so the desired value becomes ‘h005 before anything moves. The mirrored value stays at ‘h000: nothing has reached the hardware yet.
UVM RAL Fundamentalspre_write callbacks run, the fields’ first and then the register’s. A callback can change the value about to be written, or set the status to UVM_NOT_OK, which ends the write here with nothing on the bus.
Register Callbacks in Depthuvm_reg_bus_op and calls the adapter’s reg2bus(), which turns it into an APB item. Only the adapter knows the protocol, so swapping the bus means writing a new adapter, not touching the tests.
UVM RAL Fundamentalsstart_item and finish_item on the APB sequencer, from inside the calling sequence. The item waits in line behind any other traffic on that sequencer, like any other item.
SoC-Level Register Stress Patternsget_next_item.item_done, which lets the map’s finish_item return. And the monitor, which watches the same pins, publishes the transfer it saw on its analysis port.bus2reg() on the finished item to get the status: UVM_IS_OK, since PSLVERR was low. With the predictor doing the predicting, the map’s auto-predict is off, so the mirror is not touched here.
UVM RAL Fundamentalsbus_in export.bus2reg(), finds CTRL by address ‘h10 and calls its do_predict(). Each field applies its access policy: EN and MODE take the written value; DONE was written 0, and writing 0 to a W1C bit changes nothing, so it stays 0. Mirrored and desired both become ‘h005.
Register Access Types Aren't Symmetricpost_write callbacks run, the register’s and then each field’s. They see the final status.
Register Callbacks in Depthwrite() returns UVM_IS_OK to the sequence. Nothing in UVM orders this return against the predictor’s update: both happen in the same time step, so code that reads the mirror straight after write() is relying on scheduling luck.
Volatile Registers and the Predictor Problemset() makes desired ‘h003, and the pre_write callbacks run as before.
UVM RAL Fundamentalsdocker run --pull always --rm -p 127.0.0.1:8787:8787 ghcr.io/adibis/brokenbench-runnerLooking for a runner on this computer…
The first start downloads about 250 MB; after that it starts in seconds and only downloads again when there's an update. Your code goes to the runner on your computer, not to chipdv.io.