Multiple instances of covergroup based on parameter

56 Views Asked by At

I want to create multiple instances of a covergroup based on a parameter (preferably with different names so as to sample each instance accordingly). And then I want to sample those covergroups using sample() function. Is it possible to create them using for loop? I tried with generate loop, but got error since coverage collector is class based coverage & not a module.

Pseudo code of what I want:

covergroup cg_unit(int i);
  coverpoint(signal[i])
  { bins xyz={1'b1}; }
endgroup

function new();
  for(int i=0;i<PARAM;i++)
  begin
    cg_unit[i] = new(i);      //It shouldn't necessarily be an array, but I want different names for each instance
  end
endfunction

...

task write();
   for(int i=0;i<PARAM;i++)
  begin
    cg_unit[i].sample();
  end
endtask
1

There are 1 best solutions below

0
bcassell On

Each covergroup has an option.name , which you can access, but I don't recommend writing it, because every group is already named uniquely. What you're asking sounds like one of the following, but if you already had a separate coverage collector for each instance, then the problem is already solved.

// Declare covergroup inside class

class fcov_c #(parameter NUM);
  covergroup cg(string _comment);
    option.comment = _comment;
    // ...
  endgroup

  function new();
    cg = new($sformatf("MY COMMENT NUM: %0d", NUM));
  endfunction

endclass

class other_class_c;
  fcov_c#(1) cov1;
  fcov_c#(2) cov2;
  fcov_c#(4) cov4;

  function new();
    cov1 = new();
    cov2 = new();
    cov4 = new();
  endfunction
endclass

or

// Define covergroup outside class (but still in package)

covergroup cg(string _comment);
  option.comment = _comment;
  // ...
endgroup

class fcov_c #(parameter NUM);

  cg my_cg[NUM];

  function new();
    for (int idx=0; idx<NUM; idx++) begin
      my_cg[idx] = new($sformatf("MY COMMENT NUM: %0d", idx));
    end
  endfunction

endclass

FYI neither of these examples require "_comment" to be derived from a parameter