SVA——与设计的连接(bind关键字用法)


  SVA检验器与设计(DUT)的连接方式主要有两种方式:

  1. 直接将SVA检验器定义在模块(module)中
  2. 将SVA检验器与模块、模块的实例或者一个模块的多个实例进行bind绑定

一、SVA 定义在模块中

  示例:

module inline(clk, a, b, d1, d2);

  input  logic         clk, a, b;
  input  logic  [7:0]  d1, d2;
  output logic  [7:0]  d1;

  always@(posedge clk) begin
    if(a)
      d <= d1;
    if(b)
      d <= d2;
  end

  property p_mutex;
    @(posedge clk) not(a && b);              // not关键字后的序列不能出现
  endproperty

  a_mutex: assert property(p_mutex);         // DUT module中内嵌SVA检验器

endmodule

二、SVA检验器与设计的bind绑定

  SVA检验器通过关键字bind可以与设计中的任何模块(module)或者实例(instance)绑定实现绑定时,使用的是设计中的实际信号,语法如下:

bind  <module_name or instance_name>  <checker_name>  <checker_instance_name><design_signals>;

2.1、通过模块名实现绑定

  示例:

//1、设计模块
module inline(clk, a, b, d1, d2);

  input  logic         clk, a, b;
  input  logic  [7:0]  d1, d2;
  output logic  [7:0]  d1;

  always@(posedge clk) begin
    if(a)
      d <= d1;
    if(b)
      d <= d2;
  end

endmodule
//2、检验器模块——施加bind绑定设计module
module mutex_chk(a, b, clk);

  input  logic  a, b, clk;
  property p_mutex;
    @(posedge clk)  not(a && b);
  endproperty

  a_mutex: assert property(p_mutex);
  
endmodule

bind  inline  mutex_chk  m_mutex_xhk(a,b,clk);        //bind绑定语句在SVA模块外部

   注: 通过bind语句将SVA检验器与设计module绑定,等价于将SVA例化到设计module中

2.2、通过模块例化名实现绑定

  示例:(top.u1

// top层用以连接SVA与设计模块
module top(..);
  ...
  inline  u1(clk, a,b ,in1, in2, out1);
  ...
endmodule
//1、设计模块
module inline(clk, a, b, d1, d2);

  input  logic         clk, a, b;
  input  logic  [7:0]  d1, d2;
  output logic  [7:0]  d1;

  always@(posedge clk) begin
    if(a)
      d <= d1;
    if(b)
      d <= d2;
  end

endmodule
//2、检验器模块——施加bind绑定设计module
module mutex_chk(a, b, clk);

  input  logic  a, b, clk;
  property p_mutex;
    @(posedge clk)  not(a && b);
  endproperty

  a_mutex: assert property(p_mutex);
  
endmodule

bind  top.u1  mutex_chk  m_mutex_xhk(a,b,clk);        //bind绑定语句在SVA模块外部, 绑定时的信号为设计中的实际信号

   注:bind语句除了可以将将SVA检验器与设计module绑定,同样 可以实现其他任意两个模块之间的绑定。如:

bind  top  mutex_chk  m_mutex_xhk(a,b,clk);        //bind语句将SVA模块绑定在top层, 此时,mutex_chk与inline模块处于同一层级,都位于top层下

三、典型DFF与MUX的断言

示例:
      在这里插入图片描述

module simple_seq;

  reg        clk,rst;
  reg        sel1,sel2,sel3;
  reg[15:0]  d,q;
  integer    i;

  initial    begin clk = 1'b0; forever #25 clk = ~clk; end
  initial    begin rst = 1; #10; rst = 0; #100; rst = 1; end

  initial begin
    for(i=0; i<2000; i++)begin
      d    = $random();
      sel1 = $random();
      sel2 = sel1 ? 1'b0 : $random();
      sel3 = (sel1 | sel2) ? 1'b0 : $random();
      in1  = $random();
      in2  = $random();
      in3  = $random();      
      @(posedge clk);
    end
    $finish;
  end

//####################DFF assertion###########################
always@(posedge clk or negedge rst)
  if(!rst)begin
    q <= 'h0;
  end
  else begin
    q <= d;
  end

property p_dff;
  @(posedge clk)
  disable iff(!rst)
  rst |=> (q == $past(d));
endproperty
a_dff : assert property(p_dff) else $error("[DFF]DFF Check error for a_dff");

//###################MUX and DFF assertion###########################################
reg[15:0]    sel_reg_out;
wire[15:0]   sel_out;

assign  sel_out = ({16{sel1}} & in1) | ({16{sel3}} & in3) | ({16{sel2}} & in2);

always@(posedge clk or negedge rst)
  if(!rst)begin
    sel_reg_out <= 'h0;
  end
  else begin
    sel_reg_out <= sel_reg_out;
  end

sequence s_sel;
  sel_reg_out == $past(sel1 ? in1:
                      (sel2 ? in2:
                      (sel3 ? in3: 0)));
endsequence

property p_sel;
  @(posedge clk)
  disable iff(!rst)
  rst |=> s_sel;
endproperty
a_sel : assert property(p_sel) else $error("[SELECT]SELECT Check error for a_sel");

endmodule
  • 30
    点赞
  • 178
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

SD.ZHAI

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值