Integrating RAL with the Environment

How to connect the abstract Register Model to the physical Bus Sequencer using Adapters and Predictors.

The Register Adapter

The adapter is a bridge. It converts a Generic Register Transaction (`uvm_reg_bus_op`) into a Bus Specific Sequence Item (e.g., `ahb_item`), and vice versa.


class my_adapter extends uvm_reg_adapter;
   virtual function uvm_sequence_item reg2bus(const ref uvm_reg_bus_op rw);
      ahb_item pkt = ahb_item::type_id::create("pkt");
      pkt.addr = rw.addr;
      pkt.data = rw.data;
      pkt.write = (rw.kind == UVM_WRITE);
      return pkt;
   endfunction
   virtual function void bus2reg(uvm_sequence_item bus_item, ref uvm_reg_bus_op rw);
      ahb_item pkt;
      $cast(pkt, bus_item);
      rw.addr = pkt.addr;
      rw.data = pkt.data;
      rw.kind = pkt.write ? UVM_WRITE : UVM_READ;
   endfunction
endclass
                            

Connecting in Environment

In the `connect_phase` of your Environment (or Agent), you must link the Register Map to the Sequencer and Adapter.


function void connect_phase(uvm_phase phase);
    // 1. Set the sequencer for the default map
    reg_model.default_map.set_sequencer(agent.sqr, adapter);
    // 2. Connect Predictor (Explicit prediction)
    predictor.map = reg_model.default_map;
    predictor.adapter = adapter;
    agent.monitor.ap.connect(predictor.bus_in);
endfunction
                            

Implicit vs Explicit Prediction (Interview Essential)

Frequently Asked: "What's the difference between implicit and explicit prediction in RAL?"

Mode How Mirror Updates Pros Cons
Implicit (Auto) After reg.write() completes Simple setup Misses external writes
Explicit (Predictor) Monitor observes transactions Catches all bus activity Requires predictor setup
Setting Prediction Mode

// IMPLICIT (Auto) - RAL updates itself after write()
reg_model.default_map.set_auto_predict(1);
// EXPLICIT (Recommended) - Predictor watches the bus
reg_model.default_map.set_auto_predict(0);
// Requires: predictor.map = reg_model.default_map;
//           agent.monitor.ap.connect(predictor.bus_in);
                            

Production Recommendation

Use Explicit Prediction in production environments. It catches writes from other masters, DMA engines, and hardware-triggered updates that implicit prediction would miss.