I am collecting a coverage of value of register fields, which is defined as
uvm_reg_field reg_fields[string];
For some reason, the covergroup could only be defined in another class with respect to reg_fields.
The obstacle I met is that the bit width of each field is different. I tried like this
class field_coverage;
covergroup field_cg (input cg_name) with function sample (int field_value);
valid_value: coverpoint field_value;
option.name = cg_name;
option.per_instance = 1;
endgroup
function new(string name="");
field_cg = new(name);
endfunction
endclass
class A;
uvm_reg_field reg_fields[string];
field_coverage field_cg_inst[string];
....
function init_cov (string name="");
foreach (reg_fields[field_name]) begin
field_cg_inst[field_name] = new(field_name);
end
endfunction
task collect_cov ();
foreach (reg_fields[field_name]) begin
field_cg_inst[field_name].field_cg.sample(reg_fields[field_name].value());
end
endtask
endclass
It works, but by the auto_bin_max
with input of sample function defined as int
, there are always 64 bins with a large range, even though the field is only a 1 bit value.
Then I change the covergroup to this
covergroup field_cg (input cg_name, int bit_width) with function sample (int field_value);
valid_value: coverpoint field_value { bins fv[64] = {[0:2**bit_width-1]}; }
option.name = cg_name;
option.per_instance = 1;
endgroup
It turns out that coverpoint only shows fv[0], fv[1]
. When field width is larger than 6, it’s hard to review the coverage. For example, with width = 8, fv[8] is actually correspondent to value 32~35.
What I want to do is when the bit width is less than 6, it only shows its possible value to each bins. Like fv[0], fv[1], fv[2], ... fv[7]
when bit width = 3. When the bit width is larger than 6, it shows 64 bins with auto_bins like auto[0:3], auto[4:7], ...
Is there any method to write the coverage to achieve this?