SystemVerilog Assertions应用指南 Chapter1.39将SVA与设计连接

        有两种方法可以将SVA检验器连接到设计中。
        (1)在模块( module)定义中内建或者内联检验器
        (2)将检验器与模块、模块的实例或者一个模块的多个实例绑定
        有的工程师不喜欢在设计中加任何验证代码。在这种情况下,在外部绑定SVA检验器是很好的选择。SVA代码可以内建在模块定义中的任何地方。下面的例子显示了内联在模块中的SVA。

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

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

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


endmodule

module top(clk, a, b, c, d, in1, in2, in3, in4, out1, out2);

input logic clk, a, b, c, d;
input logic [7:0] in1, in2, in3, in4;
output logic [7:0] out1, out2;

inline u1 (clk, a, b, in1, in2, out1);
inline u2 (clk, c, d, in3, in4, out2);

endmodule


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);
c_mutex: cover property(p_mutex);

endmodule

// bind inline mutex_chk i2 (a, b, clk);
bind top mutex_chk i3 (a, b, clk);
bind top mutex_chk i4 (c, d, clk);

module tb;

logic clk, a, b, c, d;
// logic [7:0] d1, d2;
// logic [7:0] d;

logic [7:0] in1, in2, in3, in4;
logic [7:0] out1, out2;

// inline i1 (clk, a, b, d1, d2, d);

top top1 (clk, a, b, c, d, in1, in2, in3, in4, out1, out2);

initial $vcdpluson();

initial
begin
clk=1'b0; a=1'b0; b=1'b0;
// #100 d1 = 8'd10; d2 = 8'd25;
#100 in1 = 8'd10; in2 = 8'd25;
#100 a=1'b1;
#100 b=1'b1; a=1'b0;
#100 a=1'b1;
#100 a=1'b0; b=1'b0;
#100
$finish;
end

initial forever clk = #25 ~clk;

endmodule

// c_mutex, 12 attempts, 12 match, 0 vacuous match

        如果用户决定将SVA检验器与设计代码分离,那么就需要建立一个独立的检验器模块。定义独立的检验器模块,增强了检验器的可重用性。下面所示的是一个检验器模块的代码实例。

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);
c_mutex: cover property(p_mutex);

endmodule

        注意,定义检验器模块时,它是一个独立的实体。检验器用来检验一组通用的信号,检验器可以与设计中任何的模块( module或者实例( instance)绑定,绑定的语法如下所示

bind 
	 
		;

在上面的检验器例子中,绑定可以用下面的方式实现。

bind inline mutex_chk i2 (a,b,clk);
module top(...);
	inline u1 (clk,a,b,in1,in2,out1);
	inline u2 (clk,c,d,in3,in4,out2);

endmodule

        检验器 mutex_chk可以用下面的方式与顶层模块中内联( inline)的两个模块实例绑定。

bind top.u1 mutex_chk i1 (a,b,clk);
bind top.u2 mutex_chk i2(c,d,clk);

        与检验器绑定的设计信号可以包含绑定实例中的任何信号的跨模块引用(cross module reference)。
 

你可能感兴趣的:(Systemverilog,systemverilog断言)