/
latch.adb
179 lines (165 loc) · 6.42 KB
/
latch.adb
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
------------------------------------------------------------------
-- Tokeneer ID Station Core Software
--
-- Copyright (2003) United States Government, as represented
-- by the Director, National Security Agency.All rights reserved.
--
-- This material was originally developed by Praxis High Integrity
-- Systems Ltd.under contract to the National Security Agency.
------------------------------------------------------------------
------------------------------------------------------------------
-- Latch
--
-- Implementation Notes:
-- None
--
------------------------------------------------------------------
with Latch.Interfac,
AuditLog,
AuditTypes;
package body Latch
with Refined_State => (State => (CurrentLatch,
LatchTimeout),
Output => Latch.Interfac.Output)
is
function LatchIsLocked return Boolean is (Latch.Interfac.IsLocked);
------------------------------------------------------------------
-- Init
--
-- Implementation Notes:
-- None
--
------------------------------------------------------------------
procedure Init
with Refined_Global => (Output => (CurrentLatch,
LatchTimeout)),
Refined_Depends => ((CurrentLatch,
LatchTimeout) => null)
is
begin
CurrentLatch := Locked;
LatchTimeout := Clock.ZeroTime;
end Init;
------------------------------------------------------------------
-- UpdateInternalLatch
--
-- Implementation Notes:
-- None
--
------------------------------------------------------------------
procedure UpdateInternalLatch
with Refined_Global => (Input => (Clock.CurrentTime,
Clock.Now,
ConfigData.State,
LatchTimeout),
In_Out => (AuditLog.FileState,
AuditLog.State,
CurrentLatch)),
Refined_Depends => ((AuditLog.FileState,
AuditLog.State) => (AuditLog.FileState,
AuditLog.State,
Clock.CurrentTime,
Clock.Now,
ConfigData.State,
CurrentLatch,
LatchTimeout),
CurrentLatch => (Clock.CurrentTime,
LatchTimeout)),
Refined_Post => IsLocked = Clock.GreaterThanOrEqual
(Clock.TheCurrentTime,
LatchTimeout)
is
LocalLatch : T;
ID : AuditTypes.ElementT;
begin
if Clock.GreaterThanOrEqual(Left => Clock.TheCurrentTime,
Right => LatchTimeout) then
LocalLatch := Locked;
ID := AuditTypes.LatchLocked;
else
LocalLatch := Unlocked;
ID := AuditTypes.LatchUnlocked;
end if;
if CurrentLatch /= LocalLatch then
AuditLog.AddElementToLog(
ElementID => ID,
Severity => AuditTypes.Information,
User => AuditTypes.NoUser,
Description => AuditTypes.NoDescription
);
end if;
CurrentLatch := LocalLatch;
end UpdateInternalLatch;
------------------------------------------------------------------
-- UpdateDevice
--
-- Implementation Notes:
-- None
--
------------------------------------------------------------------
procedure UpdateDevice (SystemFault : out Boolean)
with Refined_Global => (Input => (Clock.Now,
ConfigData.State,
CurrentLatch),
Output => Interfac.Output,
In_Out => (AuditLog.FileState,
AuditLog.State)),
Refined_Depends => ((AuditLog.FileState,
AuditLog.State) => (AuditLog.FileState,
AuditLog.State,
Clock.Now,
ConfigData.State,
CurrentLatch),
(Interfac.Output,
SystemFault) => CurrentLatch),
Refined_Post => (IsLocked = Interfac.IsLocked) or SystemFault
is
begin
if CurrentLatch = Locked then
Interfac.Lock(Fault => SystemFault);
else
Interfac.Unlock(Fault => SystemFault);
end if;
if SystemFault then
-- Door is in error state - raise a critical system fault
AuditLog.AddElementToLog(
ElementID => AuditTypes.SystemFault,
Severity => AuditTypes.Critical,
User => AuditTypes.NoUser,
Description => "LATCH STATE CANNOT BE DETERMINED."
);
end if;
end UpdateDevice;
------------------------------------------------------------------
-- SetTimeout
--
-- Implementation Notes:
-- None
--
------------------------------------------------------------------
procedure SetTimeout (Time : Clock.TimeT)
with Refined_Global => (Output => LatchTimeout),
Refined_Depends => (LatchTimeout => Time),
Refined_Post => LatchTimeout = Time
is
begin
LatchTimeout := Time;
end SetTimeout;
------------------------------------------------------------------
-- Failure
--
-- Implementation Notes:
-- None
--
------------------------------------------------------------------
procedure Failure
with Refined_Global => (Output => (CurrentLatch,
LatchTimeout)),
Refined_Depends => ((CurrentLatch,
LatchTimeout) => null)
is
begin
CurrentLatch := Locked;
LatchTimeout := Clock.ZeroTime;
end Failure;
end Latch;