In my DUT I have multiple instances of the same register types (i.e. control_reg_0, control_reg_1,…) and I want to use a loop construct in my test to access the registers (and in some cases fields). I have tried using the following syntax, but get compile errors:
for (int i=0; i < 8; i++) begin
slave_rm.get_reg_by_name($sformatf(“control_reg_%0d”, i)).write(status, data, .parent(this));
end
Similarly, if I want to loop through different fields in the same register, I get errors:
for (int i=0; i < 8; i++) begin
slave_rm.status.($sformatf(“m_active%0d”, i)).read(status, data, .parent(this));
end
As a workaround to this error, do I need to get the registers and fields and put them in an array?:
uvm_reg control_regs;
uvm_reg_field status_fields;
for (int i=0; i < 8; i++) begin
control_regs[i] = slave_rm.get_reg_by_name($sformatf(“control_reg_%0d”, i));
control_regs[i].write(status, data, .parent(this));
status_fields[i] = slave_rm.get_field_by_name($sformatf(“m_active%0d”, i));
status_fields[i].read(status, data, .parent(this));
end
Are there any other ways to do this?