[systemverilog] cover group在class中的应用

Q:

class cg ;

int skew_val_vl[20];

   covergroup skew_val_cg (int skew_val_vl);

     coverpoint skew_val_vl {

      bins skew_range_1 ={[124:0]};

      bins skew_range_2 ={[325:125]};

      bins skew_range_3 ={[526:326]};

      bins skew_range_oor ={[1100:929]};

     }

   endgroup: skew_val_cg

   function new(string name, uvm_component parent =null);

      super.new(name, parent);

      foreach(skew_val_vl[i])

         skew_val_cg skew_cg[i]=new(skew_val_vl[i]);  //getting error for this line

   endfunction// new

endclass

A:

 上面写法会报error ,因为

A covergroup declaration within a class is an embedded covergroup declaration. An embedded
covergroup declaration declares an anonymous covergroup type and an instance variable of the
anonymous type. The covergroup_identifier defines the name of the instance variable. In the above
example, a variable skew_val_cg (of the anonymous coverage group) is implicitly declared.


推荐用法:(covergroup写在class外面)

  covergroup skew_val_cg ( ref int skew_val_vl);    //一定要加ref

      coverpoint skew_val_vl {

      bins skew_range_1 ={[124:0]};

      bins skew_range_2 ={[325:125]};

      bins skew_range_3 ={[526:326]};

      bins skew_range_oor ={[1100:929]};

      bins d = default;

      }

   endgroup: skew_val_cg

default bins所cover的值是coverpoint变量所没有在其它bins中出现过的值,default bins 不会被用于计算covergroup覆盖率值

class cg;

            glb_cfg  cfg;

   int skew_val_vl[20];

   skew_val_cg  sv_cg[20];  

   function new(string name, uvm_component parent =null);

       super.new(name, parent);

       foreach(sv_cg[ii])

           sv_cg[ii]=new(skew_val_vl[ii]);  

   endfunction// new

  function sample_sig();       

       foreach(sv_cg[ii]) begin

           skew_val_vl[ii] = cfg.skew_val_vl[ii];    //先更新变量的值,再sample

           sv_cg[ii].sample();  

       end

  endfunction

 endclass


另外一种用法:override sample function 

covergroup test_grp with function sample(bt_trans tr);

  option.per_instance = 1;

  aa:coverpoint(tr.aa){
    bins aa = {1};
  }
endgroup

class sub extends uvm_subscriber;
 test_grp test_grp1;

 function new(string name = "sub",uvm_component parent);
   super.new(name,parent);
   test_grp1 = new();
 endfunction

 ...

 task aa_cov(bt_trans tr);

   if(vif.a_re ==1)begin
     test_grp1.sample(tr);
   end
 endtask

endclass

通过给sample 函数传参数来实现

再来一个例子,传interface

covergroup fifo_depth(int fifo_d) with function sample(bit wcs,bit waddr);

  option.per_instance = 1;

  aa:coverpoint(waddr)iff(wcs ==1){
    bins udb[] = {[0:fifo_d-1]};
  }
endgroup

class sub extends uvm_subscriber;
 fifo_depth test_grp1;

 function new(string name = "sub",uvm_component parent);
   super.new(name,parent);
   test_grp1 = new(10);
 endfunction

 ...

 task aa_cov(bt_trans tr);

   if(vif.a_re ==1)begin
     test_grp1.sample(vif.wr_en,vif.waddr);
   end
 endtask

endclass

  • 1
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值