-
Notifications
You must be signed in to change notification settings - Fork 11
/
GP.pas
92 lines (70 loc) · 1.78 KB
/
GP.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
(*
说明:全志A20的General Purpose底层操作封装类。单例。
当RTC电池电压大于1.0V时可以保存数据
作者:tjCFeng
邮箱:tjCFeng@163.com
更新日期:2014.12.06
*)
unit GP;
{$mode objfpc}{$H+}
interface
uses SysUtils, A20;
type
TChannel =
(GP_0, GP_1, GP_2, GP_3, GP_4, GP_5, GP_6, GP_7,
GP_8, GP_9, GP_10, GP_11, GP_12, GP_13, GP_14, GP_15);
TGP = class
private
class var FInstance: TGP;
class function GetInstance: TGP; static;
public
class procedure Release;
class property Instance: TGP read GetInstance;
private
FGP_BASE: ^LongWord;
constructor Create;
destructor Destroy; override;
protected
FTMR_GP: TGROUP16_REG;
public
procedure SetGP(Channel: TChannel; Value: LongWord);
function GetGP(Channel: TChannel): LongWord;
public
property TMR_GP: TGROUP16_REG read FTMR_GP;
end;
implementation
const
GP_BASE = $01C20D20;
class function TGP.GetInstance: TGP;
begin
if FInstance = nil then FInstance:= TGP.Create;
Result:= FInstance;
end;
class procedure TGP.Release;
begin
FreeAndNil(FInstance);
end;
constructor TGP.Create;
var Base: LongWord; I: Byte;
begin
inherited Create;
FGP_BASE:= TA20.Instance.GetMMap(GP_BASE);
Base:= LongWord(FGP_BASE) + TA20.Instance.BaseOffset(GP_BASE);
for I:= 0 to 15 do FTMR_GP[I]:= Pointer(Base + I * $04);
end;
destructor TGP.Destroy;
begin
TA20.Instance.FreeMMap(FGP_BASE);
inherited Destroy;
end;
procedure TGP.SetGP(Channel: TChannel; Value: LongWord);
begin
FTMR_GP[Ord(Channel)]^:= Value;
end;
function TGP.GetGP(Channel: TChannel): LongWord;
begin
Result:= FTMR_GP[Ord(Channel)]^;
end;
finalization
TGP.Instance.Release;
end.