how can I write an SVA assertion checks the following behavior:
If B occurred, A must occurred within [1:20] cycles, this it can be easily checked via:
p1: assert property(
@(posedge clk)
B |-> ##[1:20] A;)
I want to check the other direction, if A occured
how can I check that it was due to B event, I thought to use $past() but it gives the previous value in a specific previously cycle how can predict a previous value within a window of time?
p2: assert property(
@(posedge clk)
A |-> B occurred in the past [1:20] window)
In this way the assertion will check B in each cycle in the window, consider the case when A is triggered by only one B event during the window [1:20].
In reply to ben@SystemVerilog.us:
In this way the assertion will check B in each cycle in the window, consider the case when A is triggered by only one B event during the window [1:20].
Again, this assertion is far better, and is more expressive
p1: assert property(@(posedge clk)
b |-> ##[1:20] a); // better
With the generate, you end up with 20 separate assertions, one or more of which may succeed if b was true at 1 or more previous cycles, and the others will fail.
There is no $past with a range.
The $past function provides the sampled value that an expression held in a previous nth cycle. The syntax of the function is: [1]
$past( expression1 [, number_of_ticks] [, expression2] [, clocking_event])
generate for (genvar i=1; i<=20; i++)
p1: assert property(@(posedge clk)
a |-> $past(b, i));
endgenerate
The nature of the beast!
I don’t understand what do you mean by better and more expressive, the p1 checks one direction and it’s OK, my issue with p2 which check the other direction, I want to be sure that A must be triggered only by B, I can’t use the same approach of p1 since I need to go back in time and check if A occurred there was B occurred before it within the window of time [1:20],
I understand your solution based on loop generate, it needs a special filter to bypass the wrong failed assertions, it’s not easy I think.
sequence b_happened;
##[1:20] b; // an end point at ##1 b==1, ##2 b==1, .. ##20 b=1
endsequence
A |-> B occurred in the past [1:20] window)
property p_BAD_STYLE;
@(posedge clk)
$rose(a) |-> ##1 b_happened.triggered;
endproperty[/quote]
// I rarely use the end points; it's an awkward way to look at things.
// Better
B |-> ##[1:20] A)