Writing to reg field

I want to write all ones to the fields of a register.
Eg:
space = uvm_reg_field::type_id::create(“space”);
sky = uvm_reg_field::type_id::create(“sky”);
gravity = uvm_reg_field::type_id::create(“gravity”);
mass = uvm_reg_field::type_id::create(“mass”);
space.configure(this,2,2,“RW”,0,2’b11,1,1,0);
sky.configure(this,4,4,“RW”,0,4’b0,1,1,0);
gravity.configure(this,4,8,“RW”,0,4’b0,1,1,0);
mass.configure(this,4,12,“RW”,0,4’b0,1,1,0);
Lets say we have the above fields, having different field width.
I use get_fields() method to get the field list. get_n_bits() to get the field width,once I get the field width I want to write all ones to the field width.
say the field width for SPACE is 2, I want to write 2’b11 to space field of the register, similarly sky being 4 bit wide I want to write 4’b1111 to that register field.
How should I proceed??

In reply to 100rabhh:

Hello, I’m quite sure you wanna select which field has to hold all 1, rather then writing all ones into the register. So you wanna just:

  1. Check the access_policy (RW or so)
  2. Create a mask containing 1s based on the width
  3. Use the mask to gate the FFFFFF in order to write 1s only to that specific field

// Get the register's fields first
register_t.get_fields(fields);
// check if your provided field is in the register targeted 
idxs = fields.find_first with(item.get_full_name == "name you provide");
if(idx.size() > 0) begin
`uvm_error("......") 
end
else begin
// Create the mask
foreach(idx[ii]) begin
if(fields[idx[ii]].get_access() == "RW") begin
    // This is for all the fields
    for (int j = fields[idx[ii]].get_lsb_pos(); j < fields[idx[ii]].get_lsb_pos()+fields[idx[ii]].get_n_bits(); j++)
       mask[j] = 1'b0;
end
end
end
// Create write data mask has been previously init to 0
wr_data = 32hFFFF_FFFF & mask;