2

I am trying to create a bin in my coverage group to sample values that are multiple of n (where n is a constant integer in my case 15). So far, I have came up with the following code:

class rx_port;
      int unsigned rx_rates[];
      ...
      covergroup rx_cov with function sample (int unsigned rate);
           coverpoint rate{
               bins no_rate    = {0};
               bins mul_of_15  = {SOME_PRE_DEFINED_PATTERN};
           }
      endgroup;
      ....
endclass

Where SOME_PRE_DEFINED_PATTERN is an array of int from 0 to a system macro with the step of 15. I am not sure if this is the correct/best way of generating this bin. Any better suggestion?

2 Answers 2

3

How about writing some helper functions:

module FIFTEEN;

  class rx_port;

    typedef enum {IS_ZERO, IS_DIVISIBLE_BY_15, IS_NOT_DIVISIBLE_BY_15} rate_type;

    function new;
      rx_cov=new;
    endfunction

    local function rate_type covergroup_helper(input int unsigned i);
      if (i==0)    return IS_ZERO;
      if (i%15==0) return IS_DIVISIBLE_BY_15;
      return IS_NOT_DIVISIBLE_BY_15;
    endfunction

    function sample (input int unsigned i);
      rx_cov.sample(covergroup_helper(i));
    endfunction

    covergroup rx_cov with function sample (rate_type rate);
      coverpoint rate;
    endgroup;
  endclass

  rx_port R = new;

  initial
    begin
      void'(R.sample(0));
      void'(R.sample(30));
      void'(R.sample(31));
      $display("coverage R.rx_cov.get_coverage= %f", R.rx_cov.get_coverage);
    end

endmodule

https://www.edaplayground.com/x/65v7

Here I've written a function that determines whether its input is divisible by 15 or not and another function which calls that to do the sampling. You could combine those functions together, but I like the division of labour in my example.

Sign up to request clarification or add additional context in comments.

Comments

2

It turns out that there is a better way:

module FIFTEEN;

  class rx_port;

    function new;
      rx_cov=new;
    endfunction

    function sample (input int unsigned i);
      rx_cov.sample(i);
    endfunction

    covergroup rx_cov with function sample (int unsigned rate);
      coverpoint rate { 
        bins IS_ZERO                = {0}; 
        bins IS_DIVISIBLE_BY_15     = {[1:$]} with ((item % 15)==0); 
        bins IS_NOT_DIVISIBLE_BY_15 = {[1:$]} with ((item % 15)!=0); 
      }
    endgroup;
  endclass

  rx_port R = new;

  initial
    begin
      void'(R.sample(0));
      void'(R.sample(30));
      void'(R.sample(31));
      $display("coverage R.rx_cov.get_coverage= %f", R.rx_cov.get_coverage);
    end

endmodule

https://www.edaplayground.com/x/3T5v

You can use with to specify bins. So

bins IS_DIVISIBLE_BY_15     = {[1:$]} with ((item % 15)==0); 

gives you a bin that is hit whenever the value is divisible by 15 (but not 0) and

bins IS_NOT_DIVISIBLE_BY_15 = {[1:$]} with ((item % 15)!=0); 

gives you a bin that is hit whenever the value is not divisible by 15.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.