I am trying to create an assertion which checks whether a signal has been stable over the last n cycles (from when the assertion is evaluated).
I am trying to “parametrize the assertion” so that it can be applied to a signal of any width. I also want to put it in some package so that I can utilize it in any of my projects.
I am a beginner so I do not know SystemVerilog syntax extensively. I found an entry on stackoverflow relating to “Passing parameters to a Verilog function”. I drew some inspiration from it and came up with this:
package verification_pkg;
virtual class extended_stable # (parameter int n = 1, int WIDTH = 1);
static function automatic logic stable_for_n_cycles (
input logic [WIDTH-1:0] sig
);
if (n <= 1) begin
return 1'b1;
end
for (int i = 1; i < n; i++) begin
if ($past(sig, i) !== $past(sig, i-1)) begin
return 1'b0;
end
end
return 1'b1;
endfunction
endclass
endpackage
I know this won’t work. Among other reasons why, when sig is passed into stable_for_n_cycles, the function sees it as a logic value and no longer as a signal, so it no longer has a history and therefore it would not make sense to call $past from within the function.
That said, I still do not have any other idea on how to do this.
Hi @dave_59
I want to know how it will execute, can you please elaborate more on it syntax. As i know past returns num of cycles and stable will true or false basses on past one clock cycle.
$past is simply a shortcut for creating a shift register of N cycles for a particular value. So $stable($past(signal,N)) compares the value of signal N cycles in the past with N-1 cycles in the past.