If the tool supports the $setup, then you could use that.
// $setup ( data_event , reference_event , timing_check_limit [ , [ notifier ] ] ) ;
// $setup( data, posedge clk, 10, notifier ) ;
specify
// Define timing check specparam values
// Specify timing check variable must be a port.
specparam tSU = 2, tHD = 1, tPW = 25, tWPC = 10, tREC = 5;
$setup(in1, posedge clk, tSU);
endspecify
With assertions, you could do what I have below; basically create an event 2ns prior to @(posedge clk), and check that the signal has the same value @event and @(posedge clk)
module setup1(input bit clk, in1);
event e;
parameter PERIOD=10ns;
/*There is a clock called clk.
There is an input signal called in1.
in1 has to be stable for at least 2 ns before the posedge of clk.
i.e. in1 cannot change within 2 ns before the posedge of clk.
How do I write an assertion/checker for this? */
ap_setup0: assert property(@e !in1 |-> @(posedge clk) !in1 );
ap_setup1: assert property(@e in1 |-> @(posedge clk) in1 );
always @(posedge clk) begin
# (PERIOD -2ns);
-> e;
end
endmodule : setup1
module top;
bit clk, in1;
event e;
parameter PERIOD=10ns;
setup1 setup1_ins(.*);
initial forever #(PERIOD/2) clk=!clk;
initial begin
repeat(200) begin
@(posedge clk);
if (!randomize(in1)) $error();
end
end
endmodule : top