Sampling query when merging different protocols into one single covergroup

Hi. Let’s say my design has three different protocols A, B, C. My requirement is to check if all three protocols are being exercised at the same time. I have created one single cover group and have three variables A_active, B_active, and C_active which describe if the protocol is being exercised. I currently have three monitors for A, B, C in my setup. The analysis ports for all three monitors are connected to their corresponding implementation ports in the functional coverage model. In the write method for each and every protocol, we set the variable corresponding to the particular protocol as mentioned in the code below. cg is the single cover group which has three variables A_active, B_active, C_active;

covergroup cg();
  // Global parameters
  option.name = {get_full_name(), "cg"};
  option.goal         = 100;
  option.weight       = 1;
  option.per_instance = 1;
  option.comment      = "coverage";

  cp_a_active : coverpoint a_active;
  cp_b_active : coverpoint b_active;
  cp_c_active : coverpoint c_active;
  cr_a_active_x_b_active_x_c_active : cross cp_a_active, cp_b_active, cp_c_active;
endgroup

// Inside my functional coverage model.
function void write_A(A trans);
    A_active = 1'b1;
    cg.sample();
   A_active = 1'b0;
endfunction
function void write_B(B trans);
    B_active = 1'b1;
    cg.sample();
    B_active = 1'b0;
endfunction

function void write_C(C trans);
    C_active = 1'b1;
    cg.sample();
    C_active = 1'b0;
endfunction

The Problem with the above code is that I have to make the A_active, B_active, C_active to 0 after the sample is done. Let’s say all the three interfaces A, B, C are exercised at the same time. The corresponding write functions have to execute concurrently. However, in the same time slot depending on the simulator, it could be that write function of A executes first followed by write function B followed by write function C. In this case since i have set A_active 0 before write function B is executed, the cross coverage does not hit. I need a way to first sample the cover points and after all the sampling has occurred, at the end of the time slot, need to make all the cover points set to 0.
Can anyone kindly help me as to how to achieve this?

You can use a non-blocking trigger to schedule your covergroup sampling.

event sample_trig;
function void write_A(A trans);
    A_active = 1'b1;
    ->>sample_trig;
endfunction
function void write_B(B trans);
    B_active = 1'b1;
    ->>sample_trig;
endfunction

function void write_C(C trans);
    C_active = 1'b1;
    ->>sample_trig;
endfunction
task sampleing
forever @sample_trig begin
   cg.sample();
    A_active = 1'b0;
    B_active = 1'b0;
    C_active = 1'b0;
end
endtask


1 Like

Thanks a lot @dave_59 .