-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtimer.v
More file actions
59 lines (47 loc) · 1.39 KB
/
timer.v
File metadata and controls
59 lines (47 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
`default_nettype none
module timer(
input clk,
input reset,
input load,
input [15:0] cycles,
output busy
);
reg [15:0] counter;
always @(posedge clk) begin
if(reset)
counter <= 0;
else if (load)
counter <= cycles;
else if (counter > 0)
counter <= counter - 1'b1;
end
assign busy = counter > 0;
`ifdef FORMAL
// register for knowing if we have just started
reg f_past_valid = 0;
// start in reset
initial assume(reset);
always @(posedge clk) begin
// assume timer won't get loaded with a 0
assume(cycles > 0);
// update past_valid reg so we know it's safe to use $past()
f_past_valid <= 1;
// cover the counter getting loaded and starting to count
_busy_: cover(busy && !reset);
// cover timer finishing
if(f_past_valid && !$past(reset))
_finish_: cover($past(busy) && busy == 0);
// busy
if(counter)
_busy_prove_: assert(busy);
// load works
if(f_past_valid)
if($past(load) && !$past(reset))
_load_prove_: assert(counter == $past(cycles));
// counts down
if(f_past_valid)
if(!$past(load) && busy)
_counting_prove_: assert(counter == $past(counter) - 1);
end
`endif
endmodule