1 Star 196 Fork 1

Alancheng86 / ClassA20

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
A20.pas 1.83 KB
一键复制 编辑 原始数据 按行查看 历史
tjCFeng 提交于 2014-12-06 10:39 . Update A20.pas
(*
说明:全志A20的地址映射封装类。
单例,请勿在程序中使用。
作者:tjCFeng
邮箱:tjCFeng@163.com
更新日期:2014.12.06
*)
unit A20;
{$mode objfpc}{$H+}
interface
uses Unix, BaseUnix, SysUtils;
type
TGROUP1_REG = ^LongWord;
TGROUP2_REG = array [0..1] of ^LongWord;
TGROUP4_REG = array [0..3] of ^LongWord;
TGROUP5_REG = array [0..4] of ^LongWord;
TGROUP6_REG = array [0..5] of ^LongWord;
TGROUP16_REG = array [0..15] of ^LongWord;
type
TA20 = class
private
class var FInstance: TA20;
class function GetInstance: TA20; static;
public
class procedure Release;
class property Instance: TA20 read GetInstance;
private
FhMEM: Integer;
constructor Create;
destructor Destroy; override;
public
function GetMMap(BaseAddr: LongWord): PLongWord;
function BaseOffset(BaseAddr: LongWord): LongWord;
procedure FreeMMap(MMapAddr: PLongWord);
end;
implementation
const
PAGE_SIZE = 4096;
BLOCK_SIZE = 4096;
class function TA20.GetInstance: TA20;
begin
if FInstance = nil then FInstance:= TA20.Create;
Result:= FInstance;
end;
class procedure TA20.Release;
begin
FreeAndNil(FInstance);
end;
constructor TA20.Create;
begin
inherited Create;
FhMEM:= fpopen('/dev/mem', O_RdWr);
if (FhMEM < 0) then Exit;
end;
destructor TA20.Destroy;
begin
fpclose(FhMEM);
inherited Destroy;
end;
function TA20.GetMMap(BaseAddr: LongWord): PLongWord;
var MEM: LongWord;
begin
MEM:= (BaseAddr and $FFFFF000) div PAGE_SIZE;
Result:= fpMmap(nil, PAGE_SIZE, PROT_READ or PROT_WRITE, MAP_SHARED, FhMem, MEM);
end;
function TA20.BaseOffset(BaseAddr: LongWord): LongWord;
begin
Result:= (BaseAddr and $00000FFF);
end;
procedure TA20.FreeMMap(MMapAddr: PLongWord);
begin
if (MMapAddr <> nil) then fpMUnmap(MMapAddr, PAGE_SIZE);
end;
finalization
TA20.Instance.Release;
end.
Pascal
1
https://gitee.com/Alancheng86/ClassA20.git
git@gitee.com:Alancheng86/ClassA20.git
Alancheng86
ClassA20
ClassA20
master

搜索帮助