Adapter class

,

in adapter class, reg2bus method is having only one argument, while bus2reg method is having 2 arguments. why??

In reply to rhariprasad:

For understanding this you need to know how these two methods are used in RAL.
Reg2bus method is used whenever a RAL transaction (read/write) is issued by your env or test, reg2bus will get uvm_reg_bus_op structure and form an bus transactions based on data provided in the op struct. The reg2bus return the bus sequence item that can be axi/ahb or any other type. The final transaction is sent on the bus_sequencer instance you had provided while initializing RAL.

Bus2Reg method translates transaction from sequence item type to uvm_reg_bus_op type which are passed as arguments to the function.

See the example code in uvm_reg_adapter for better understanding:

//|  virtual function uvm_sequence_item reg2bus(uvm_reg_bus_op rw);
//|    apb_item apb = apb_item::type_id::create("apb_item");
//|    apb.op   = (rw.kind == UVM_READ) ? apb::READ : apb::WRITE;
//|    apb.addr = rw.addr;
//|    apb.data = rw.data;
//|    return apb;
//|  endfunction
//|
//|  virtual function void bus2reg(uvm_sequencer_item bus_item,
//|                                uvm_reg_bus_op rw);
//|    apb_item apb;
//|    if (!$cast(apb,bus_item)) begin
//|      `uvm_fatal("CONVERT_APB2REG","Bus item is not of type apb_item")
//|    end
//|    rw.kind  = apb.op==apb::READ ? UVM_READ : UVM_WRITE;
//|    rw.addr = apb.addr;
//|    rw.data = apb.data;
//|    rw.status = UVM_IS_OK;
//|  endfunction

Hope this helps.

Thanks,
Rohit

In reply to rhariprasad:

We need to create sequence_item to send it to the driver. reg2bus() does that,

function uvm_sequence_item reg2bus(const ref uvm_reg_bus_op rw);

reg2bus() takes reference argument of type uvm_reg_bus_op and creates a sequence_item. So, here no need of 2nd argument.

Whereas bus2reg() needs two arguments,

function void bus2reg(uvm_sequence_item bus_item,
                                     ref uvm_reg_bus_op rw);
  • Where first argument is sequence item to convert and second argument is reference to uvm_reg_bus_op type available in parent class. So, here we update register by reference.
  • For bus2reg() there’s no return type of uvm_reg_bus_op because uvm_reg_bus_op is a Structure and not Class. So, creation and return statement cannot be used there.