-
Notifications
You must be signed in to change notification settings - Fork 11
/
WatchDog.pas
145 lines (116 loc) · 2.77 KB
/
WatchDog.pas
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
(*
说明:全志A20的WatchDog底层操作封装类。单例。
作者:tjCFeng
邮箱:tjCFeng@163.com
更新日期:2014.12.06
*)
unit WatchDog;
{$mode objfpc}{$H+}
interface
uses SysUtils, A20, Clock;
type
TInterval = (S0_5, S1, S2, S3, S4, S5, S6, S8, S10, S12, S14, S16);
TWDOG = class
private
class var FInstance: TWDOG;
class function GetInstance: TWDOG; static;
public
class procedure Release;
class property Instance: TWDOG read GetInstance;
private
FWDOG_BASE: ^LongWord;
constructor Create;
destructor Destroy; override;
procedure SetInterval(Value: TInterval);
function GetInterval: TInterval;
procedure SetForceRestart(Value: Boolean);
function GetForceRestart: Boolean;
protected
FWDOG_CTRL: TGROUP1_REG;
FWDOG_MODE: TGROUP1_REG;
public
procedure Start;
procedure Stop;
procedure Reset;
public
property Interval: TInterval read GetInterval write SetInterval;
property ForceRestart: Boolean read GetForceRestart write SetForceRestart;
property WDOG_CTRL: TGROUP1_REG read FWDOG_CTRL;
property WDOG_MODE: TGROUP1_REG read FWDOG_MODE;
end;
implementation
const
WDOG_BASE = $01C20C90;
class function TWDOG.GetInstance: TWDOG;
begin
if FInstance = nil then FInstance:= TWDOG.Create;
Result:= FInstance;
end;
class procedure TWDOG.Release;
begin
FreeAndNil(FInstance);
end;
constructor TWDOG.Create;
var Base: LongWord;
begin
inherited Create;
FWDOG_BASE:= TA20.Instance.GetMMap(WDOG_BASE);
Base:= LongWord(FWDOG_BASE) + TA20.Instance.BaseOffset(WDOG_BASE);
FWDOG_CTRL:= Pointer(Base + $00);
FWDOG_MODE:= Pointer(Base + $04);
end;
destructor TWDOG.Destroy;
begin
TA20.Instance.FreeMMap(FWDOG_BASE);
inherited Destroy;
end;
procedure TWDOG.SetInterval(Value: TInterval);
begin
FWDOG_MODE^:= FWDOG_MODE^ and not ($F shl 3);
FWDOG_MODE^:= FWDOG_MODE^ or (Ord(Value) shl 3);
end;
function TWDOG.GetInterval: TInterval;
var Value: Byte;
begin
Value:= (FWDOG_MODE^ and ($F shl 3)) shr 3;
case Value of
0: Result:= S0_5;
1: Result:= S1;
2:Result:= S2;
3: Result:= S3;
4: Result:= S4;
5: Result:= S5;
6: Result:= S6;
7: Result:= S8;
8: Result:= S10;
9: Result:= S12;
10: Result:= S14;
11: Result:= S16;
end;
end;
procedure TWDOG.SetForceRestart(Value: Boolean);
begin
case Value of
False: FWDOG_MODE^:= FWDOG_MODE^ and not ($1 shl 1);
True: FWDOG_MODE^:= FWDOG_MODE^ or ($1 shl 1);
end;
end;
function TWDOG.GetForceRestart: Boolean;
begin
Result:= (FWDOG_MODE^ and ($1 shl 1)) > 0;
end;
procedure TWDOG.Start;
begin
FWDOG_MODE^:= FWDOG_MODE^ or ($1 shl 0);
end;
procedure TWDOG.Stop;
begin
FWDOG_MODE^:= FWDOG_MODE^ and not ($1 shl 0);
end;
procedure TWDOG.Reset;
begin
FWDOG_CTRL^:= 1;
end;
finalization
TWDOG.Instance.Release;
end.