【SystemVerilog断言学习笔记5】“##”的解读与运用
0赞
发表于 5/7/2015 7:29:29 PM
阅读(4896)
有时候,我们需要检查几个时钟周期才能完成的事务。在SVA中,可以用“##”表示时钟周期延迟,如“ a ##2 b”即当a为高电平时,2个时钟周期之后b应为高电平。下面举个简单的例子来说明:
测试代码:
/******************************************************* 作者 : CrazyBird 文件 : assert_test2.sv 日期 : 2015-5-7 功能 : 时钟周期延时“##”的测试 ********************************************************/ `timescale 1ns/1ps module assert_test2( output reg clk, output reg a, output reg b ); // 产生时钟 parameter PERIOD = 10; initial begin clk = 0; forever #(PERIOD/2) clk = ~clk; end // 产生激励 initial begin a = 1; b = 1; repeat(20)@(negedge clk) begin a = {$random()}%2; b = {$random()}%2; end @(negedge clk); $stop; end //建立序列 sequence s1; a ##2 b; endsequence // 建立属性 property p1; @(posedge clk) s1; endproperty // 断言属性 a1 : assert property(p1); endmodule
按照代码的描述,其任务是检查信号a在给定的时钟上升沿是否为高电平。若a为低电平,断言直接失败;若a为高电平,则延迟2个时钟周期后检查b是否为高电平。若b为高电平,表示断言成功;若b为低电平,表示断言失败。
其仿真结果如下所示:
# ** Error: Assertion error. # Time: 15 ns Started: 15 ns Scope: assert_test2.a1 File: D:/electron/modelsim/assert_test2/assert_test2.sv Line: 49 # ** Error: Assertion error. # Time: 45 ns Started: 25 ns Scope: assert_test2.a1 File: D:/electron/modelsim/assert_test2/assert_test2.sv Line: 49 # ** Error: Assertion error. # Time: 65 ns Started: 65 ns Scope: assert_test2.a1 File: D:/electron/modelsim/assert_test2/assert_test2.sv Line: 49 # ** Error: Assertion error. # Time: 75 ns Started: 55 ns Scope: assert_test2.a1 File: D:/electron/modelsim/assert_test2/assert_test2.sv Line: 49 # ** Error: Assertion error. # Time: 95 ns Started: 75 ns Scope: assert_test2.a1 File: D:/electron/modelsim/assert_test2/assert_test2.sv Line: 49 # ** Error: Assertion error. # Time: 115 ns Started: 115 ns Scope: assert_test2.a1 File: D:/electron/modelsim/assert_test2/assert_test2.sv Line: 49 # ** Error: Assertion error. # Time: 125 ns Started: 125 ns Scope: assert_test2.a1 File: D:/electron/modelsim/assert_test2/assert_test2.sv Line: 49 # ** Error: Assertion error. # Time: 125 ns Started: 105 ns Scope: assert_test2.a1 File: D:/electron/modelsim/assert_test2/assert_test2.sv Line: 49 # ** Error: Assertion error. # Time: 135 ns Started: 135 ns Scope: assert_test2.a1 File: D:/electron/modelsim/assert_test2/assert_test2.sv Line: 49 # ** Error: Assertion error. # Time: 145 ns Started: 145 ns Scope: assert_test2.a1 File: D:/electron/modelsim/assert_test2/assert_test2.sv Line: 49 # ** Error: Assertion error. # Time: 175 ns Started: 175 ns Scope: assert_test2.a1 File: D:/electron/modelsim/assert_test2/assert_test2.sv Line: 49 # ** Error: Assertion error. # Time: 175 ns Started: 155 ns Scope: assert_test2.a1 File: D:/electron/modelsim/assert_test2/assert_test2.sv Line: 49 # ** Error: Assertion error. # Time: 185 ns Started: 185 ns Scope: assert_test2.a1 File: D:/electron/modelsim/assert_test2/assert_test2.sv Line: 49 # ** Error: Assertion error. # Time: 195 ns Started: 195 ns Scope: assert_test2.a1 File: D:/electron/modelsim/assert_test2/assert_test2.sv Line: 49
待续~~~