How to add user defined functions in uvm_reg and access it from uvm_block with the handle generated by get_registers()

Hi ,
I have register definition as below, i have added two user defined functions , 1 is set_default() and other is get_storage(), example code is shown below

class reg_DP_SHIP_LOCK_CONTROL extends uvm_reg;

rand uvm_reg_field lock_control;
function new(string name = “reg_DP_SHIP_LOCK_CONTROL”);
super.new(name,16,UVM_NO_COVERAGE);
endfunction: new

virtual function void build();
lock_control = uvm_reg_field::type_id::create(“lock_control”,get_full_name());
lock_control.configure(this, 16, 0, “RW”, 0, 16’hbeef, 1, 1, 0);
this.add_hdl_path_slice(“lock_control”, 0, 16);
endfunction: build

function void set_default();
lock_control.set(16’hbeef);
endfunction: set_default

function string get_storage();
return “m3_rom”;
endfunction: get_storage

 `uvm_object_utils(reg_DP_SHIP_LOCK_CONTROL)

endclass: reg_DP_SHIP_LOCK_CONTROL

I have a reg block where i have instantiated the register as shown below

class block_DP_SHIP extends uvm_reg_block;
rand reg_DP_SHIP_LOCK_CONTROL LOCK_CONTROL;
function new (string name = “block_DP_SHIP”);
super.new(name,UVM_NO_COVERAGE);
endfunction: new

virtual function void build();
default_map = create_map(“default_map”, 0, 4, UVM_BIG_ENDIAN, 0);
LOCK_CONTROL = reg_DP_SHIP_LOCK_CONTROL::type_id::create(“LOCK_CONTROL”);
LOCK_CONTROL.configure(this);
LOCK_CONTROL.build();
default_map.add_reg (LOCK_CONTROL, 'h3010, “RW”);
lock_model();

endfunction: build

function void set_default();
LOCK_CONTROL.set_default();
endfunction: set_default
`uvm_object_utils(block_DP_SHIP)

endclass: block_DP_SHIP

i Have reg read write sequence where I want to access get_storage() function to return the string “m3_rom”

if I do top_reg_block.LOCK_CONTROL.get_storage() i’m getting m3_rom returned by the function,
if i try to do recursively using get_registers() as shown below i’m not able to compile my code only

uvm_reg_block model;
module_reg_block top_reg_block;
task pre_body();
$cast(top_reg_block, model);
//$display(“CASTING IS SUCCESS”);
endtask
vitual tasl body();
top_reg_block.get_registers(data_regs);
data_regs.shuffle();
foreach(data_regs[i]) begin
if(data_regs[i].get_name() == “LOCK_CONTROL”) begin
$display(" storage is %s", data_regs[i].get_storage());
end
end
endtask
Error i’m getting
ncvlog: *E,NOTCLM (…/registers/i2c_read_write_sequence.sv,74|58): get_storage is not a class item.
$display(" SET VALUE %s", data_regs[i].get_storage());

In reply to maheshkumar.onsemi:

You need to downcast the handle to the proper class variable that can reference the get_storage() method. And the dynamic cast can replace your string name compare

vitual task body();
  reg_DP_SHIP_LOCK_CONTROL lock_control_h;
  top_reg_block.get_registers(data_regs);
  data_regs.shuffle();
  foreach(data_regs[i]) begin
    if($cast(lock_control_h, data_regs[I])) begin
      $display(" storage is %s", lock_control_h.get_storage());
    end
endtask