-
Notifications
You must be signed in to change notification settings - Fork 0
/
close_timer.sv
110 lines (89 loc) · 2.39 KB
/
close_timer.sv
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// When the close timer receives a session close signal, it will hold the program for a period of time before closing the session.
module closeTimer (
input clk,
input rst,
input [31:0] interval,
input [2:0] sessionID,
output reg pktOut // send packet out
);
reg [31:0] intervalReg;
reg closeActive [0:2];
reg [31:0] globalTimer;
reg [1:0] state;
reg [2:0] sessionIDReg;
reg [31:0] closeSession;
parameter minInterval = 30,
maxInterval = minInterval*2,
totalCycles = minInterval*3+5;
//absolute timer
always @(posedge clk) begin
if(rst)begin
globalTimer <= 0;
end
else begin
globalTimer <= globalTimer + 1;
end
end
always @(posedge clk) begin
if(rst)begin
pktOut <= 1;
end
else begin
if(closeActive[0] && closeActive[1] && closeActive[2] ) pktOut <= 0;
else pktOut<= 1;
end
end
always @(posedge clk) begin
if(rst) begin
closeActive[0]<=0;
closeActive[1]<=0;
closeActive[2]<=0;
closeSession <= 0;
intervalReg <= 0;
state <= 0;
end
else begin //!rst
case(state)
0: begin
if(~closeActive[sessionID]) begin
if(interval<minInterval)intervalReg <= minInterval;
else intervalReg <= interval;
sessionIDReg <= sessionID;
state <= 1;
end
end
1: begin
if(intervalReg == 0) begin
closeActive[sessionIDReg] <= 1;
closeSession <= closeSession + 1;
state <= 0;
end
else begin
intervalReg <= intervalReg - 1;
end
end
endcase
end
end
`ifdef FORMAL
always @(posedge clk) begin
if(!$initstate) begin
assume(rst == 0);
//Constraints
assume(sessionID<=2);
//assume(interval>=minInterval);
//assume(interval<=maxInterval);
//-----//
//Invariant
assume(closeSession>=closeActive[0] && closeSession>=closeActive[1] && closeSession>=closeActive[2]);
//assume(closeSession<=closeActive[0]+closeActive[1]+closeActive[2]);
//-----//
// a timing property
if(globalTimer == totalCycles) assert(closeSession < 3);
end
else begin
assume(rst);
end
end
`endif
endmodule