module mb;
logic [3:0] i,o;
ma #(.p1(3), .p2(int)) u1(i,o); //redefines p2 to a type of int
endmodule
$ can be assigned to parameters of integer
types. A parameter to which $ is assigned shall only be used wherever $
can be specified as a literal constant.
For example, $ represents unbounded range specification,
where the upper index can be any integer.
parameter r2 = $;
property inq1(r1,r2);
@(posedge clk) a ##[r1:r2] b ##1 c |=>
d;
endproperty
assert inq1(3);
ma #(.p1(3), .p2(int)) u1(i,o); //redefines p2 to a type of int
endmodule
To support
whether a constant is $, a system function is provided to test whether a
constant is a $. The syntax of the system function is
$isunbounded(const_expression);
$isunbounded
returns true if const_expression is unbounded. Typically, $isunbounded would be used as a condition in the
generate statement.
The example
below illustrates the benefit of using $ in writing properties concisely
where the range is parameterized. The checker in the example ensures that a bus
driven by signal en remains 0, i.e, quiet for the specified
minimum (min_quiet) and maximum (max_quiet)
quiet time.
Note that
function $isunbounded is used for checking the
validity actual arguments.
interface quiet_time_checker( clk, reset_n,
en);
input reset_n;
input clk;
input [1:0] en;
parameter min_quiet = 0;
parameter max_quiet = 0;
generate
if ( max_quiet
== 0) begin
property quiet_time;
@(posedge clk) reset_n
|-> ($countones(en) == 1);
endproperty
a1: assert property (quiet_time);
end
else begin
property quiet_time;
@(posedge clk)
(reset_n
&& ($past(en) != 0) && en == 0)
|->(en ==
0)[*min_quiet:max_quiet]
##1 ($countones(en) == 1);
endproperty
a1: assert property (quiet_time);
end
if ((min_quiet
== 0) && ($isunbounded(max_quiet))
$display(warning_msg);
endgenerate
endinterface
quiet_time_checker #(0, 0) quiet_never (clk,1,enables);
quiet_time_checker #(2, 4) quiet_in_window (clk,1,enables);
quiet_time_checker #(0, $) quiet_any (clk,1,enables);
Another example
below illustrates that by testing for $, a property can be configured
according to the requirements. When parameter max_cks is unbounded, it is not required to test for expr to become false.
interface width_checker(clk, reset_n, expr);
input clk;
input reset_n;
input expr;
parameter min_cks = 1;
parameter max_cks = 1;
generate begin
if ($isunbounded(max_cks)) begin
property width;
@(posedge clk)
(reset_n
&& $rose(expr))
|-> (expr [* min_cks]);
endproperty
a2: assert property (width);
end
else begin
property assert_width_p;
@(posedge clk)
(reset_n
&& $rose(expr))
|-> (expr[* min_cks:max_cks])
##1 (!expr);
endproperty
a2: assert property (width);
end
endgenerate
endinterface
width_checker #(3, $) max_width_unspecified
(clk,1,enables);
width_checker #(2, 4) width_specified
(clk,1,enables);