📄 rtal.c
字号:
/*----------------------------------------------------------------------------
COPYRIGHT (c) 1997 by Philips Semiconductors
THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY ONLY BE USED AND COPIED IN
ACCORDANCE WITH THE TERMS AND CONDITIONS OF SUCH A LICENSE AND WITH THE
INCLUSION OF THE THIS COPY RIGHT NOTICE. THIS SOFTWARE OR ANY OTHER COPIES
OF THIS SOFTWARE MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY OTHER
PERSON. THE OWNERSHIP AND TITLE OF THIS SOFTWARE IS NOT TRANSFERRED.
THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT ANY PRIOR NOTICE
AND SHOULD NOT BE CONSTRUED AS A COMMITMENT BY Philips Semiconductor.
PHILIPS ASSUMES NO RESPONSIBILITY FOR THE USE OR RELIABILITY OF THIS SOFTWARE
ON PLATFORMS OTHER THAN THE ONE ON WHICH THIS SOFTWARE IS FURNISHED.
----------------------------------------------------------------------------*/
/*
FILE : RTAL.c
HISTORY
960510 Tilakraj Roy Created
980604 Volker Schildwach Ported to Windows CE
981021 Tilakraj Roy Changes for integrating into common source base
ABSTRACT
Contains support functions that are OS / Platform dependent.
This file should be in the platform specific directories,
However most platforms can use this file exactly as it is,
so this file is kept in the common area.
Platforms that require these functions to be overridden can
ignore this file and make a local platform specific copy in
the platform specific directory.
*/
/*----------------------------------------------------------------------------
SYSTEM INCLUDE FILES
----------------------------------------------------------------------------*/
/* tm1 specific includes */
#include <windows.h>
#include "ceddk.h"
#include "stdio.h"
#include "stdarg.h"
/*----------------------------------------------------------------------------
DRIVER SPECIFIC INCLUDE FILES
----------------------------------------------------------------------------*/
#include "tmtypes.h"
#include "tmmanlib.h"
#include "platform.h"
// read this field from the registry
#define MAX_MEM_AREAS 32
Pointer memAllocate( UInt32 Size )
{
Pointer Memory;
Memory = (Pointer)LocalAlloc ( LPTR, Size );
memset ( Memory, 0, Size);
return Memory;
}
void memFree( Pointer Memory )
{
LocalFree ( Memory );
}
void memCopy( Pointer Destination, Pointer Source, UInt32 Size )
{
memcpy ( Destination, Source, Size );
}
void memSet ( Pointer Memory, UInt8 Value, UInt32 Size )
{
memset ( Memory, Value, Size);
}
// functions for dealing with ANSI strings.
UInt32 strCmp ( Pointer String1, Pointer String2 )
{
while ( *((UInt8*)String1) )
{
if ( *((UInt8*)String1) == *((UInt8*)String2) )
{
((UInt8*)String1)++;
((UInt8*)String2)++;
continue;
}
return ( *((UInt8*)String1) - *((UInt8*)String2) );
}
return 0;
}
Pointer strCopy ( Pointer Destination, Pointer Source )
{
while ( *((UInt8*)Destination)++ = *((UInt8*)Source)++ );
*((UInt8*)Destination)++ = *((UInt8*)Source)++;
return Destination;
}
UInt32 strLen ( Pointer String )
{
UInt32 Length = 0;
while ( *((UInt8*)String)++ ) Length++;
return ( Length + 1 );
}
void strSprintf (
Int8* BufferString,
Int8* FormatString,
... )
{
va_list va;
va_start(va, FormatString);
vsprintf( BufferString, FormatString, va);
va_end(va);
}
typedef struct tagtmmanSharedMem
{
PHYSICAL_ADDRESS PhysAddr;
PVOID VirtAddr;
DWORD dwSize;
}tmmanSharedMem;
static BYTE* pLockedMem = NULL;
static tmmanSharedMem MemArray[MAX_MEM_AREAS] = {0};
static DWORD gdwFixedSize = 0;
PVOID
MmAllocateContiguousMemory (
DWORD dwSize)
{
int i;
DWORD dwUsedSize = 0;
DWORD dwAreaStart = 0;
DWORD dwPysAddr;
DWORD dwOemSize;
dwPysAddr = TMManGlobal->PageLockedMemoryBase;
dwOemSize = TMManGlobal->PageLockedMemorySize;
if (!pLockedMem)
{
DPF(8,("MmAllocateContiguousMemory:Allocating for First Time\n" ));
DPF(0,("MMmAllocateContiguousMemory:FirstTime:dwPysAddr=%x\n",dwPysAddr));
DPF(0,("MMmAllocateContiguousMemory:FirstTime:dwOemSize=%x\n",dwOemSize));
// create new block of memory
if ((pLockedMem=(BYTE*)VirtualAlloc(0,dwOemSize,MEM_RESERVE,PAGE_NOACCESS))==NULL)
{
DPF(0,("MmAllocateContiguousMemory: VirtualAlloc FAILED\n"));
return NULL;
}
if(!VirtualCopy((void *)pLockedMem,(void *)dwPysAddr,dwOemSize,PAGE_READWRITE|PAGE_NOCACHE))
{
DPF(0,("MMmAllocateContiguousMemory: VirtualCopy FAILED\n"));
VirtualFree(pLockedMem,0,MEM_RELEASE);
return NULL;
}
// init mem
memset(pLockedMem,0,dwOemSize);
gdwFixedSize = dwOemSize;
}
// memory size ha to be constant until next VirtualFree
if (gdwFixedSize<dwSize)
{
DPF(0,("MMmAllocateContiguousMemory: FixedSize[%x]:RequestedSize[%x] \n",gdwFixedSize, dwSize ));
return NULL;
}
// search free slot
for (i = 0; i< MAX_MEM_AREAS; i++)
{
if (MemArray[i].dwSize == 0)
{
break;
}
dwAreaStart+=MemArray[i].dwSize;
}
// make sure we found a free slot
if (i == MAX_MEM_AREAS)
{
DPF(0,("MmAllocateContiguousMemory:ERROR out of slots\n"));
return NULL;
}
MemArray[i].PhysAddr.LowPart = (dwPysAddr &0x7fffffff)+dwAreaStart;
MemArray[i].VirtAddr = pLockedMem+dwAreaStart;
MemArray[i].dwSize = dwSize;
DPF(0,("MMmAllocateContiguousMemory:Size[%x]:PhysHi[%x]:PhysLo[%x]:Virt[%x]:OK\n",
MemArray[i].dwSize, MemArray[i].PhysAddr.HighPart, MemArray[i].PhysAddr.LowPart ));
// return virtual pointer if allocation was successfull
return MemArray[i].VirtAddr;
}
BOOL
MmFreeContiguousMemory(
PVOID BaseAddress)
{
DWORD dwUsedSize=0;
int i;
//search slot
for (i = 0; i< MAX_MEM_AREAS; i++)
{
if (MemArray[i].VirtAddr == BaseAddress)
break;
}
// make sure we found a the slot
if (i == MAX_MEM_AREAS)
return FALSE;
// delete slot
MemArray[i].PhysAddr.LowPart = 0;
MemArray[i].VirtAddr = 0;
MemArray[i].dwSize = 0;
for (i = 0; i < MAX_MEM_AREAS; i++)
{
dwUsedSize+=MemArray[i].dwSize;
}
if (dwUsedSize == 0)
{
if (pLockedMem)
{
VirtualFree(pLockedMem,0,MEM_RELEASE);
pLockedMem = NULL;
}
}
return TRUE;
}
PHYSICAL_ADDRESS
MmGetPhysicalAddress (
PVOID BaseAddress)
{
PHYSICAL_ADDRESS ResultAdress;
DWORD dwOffset;
int i;
ResultAdress.LowPart = 0;
ResultAdress.HighPart = 0;
//search slot
for (i = 0; i< MAX_MEM_AREAS; i++)
{
if (((DWORD)BaseAddress >= (DWORD)MemArray[i].VirtAddr )
&& ( (DWORD)BaseAddress < ((DWORD)(MemArray[i].VirtAddr) + MemArray[i].dwSize)))
break;
}
// make sure we found a the slot
if (i == MAX_MEM_AREAS)
{
DPF(0,("MmGetPhysicalAddress:Base[%x]:Not Found:ERROR\n", BaseAddress ));
return ResultAdress;
}
// calculate offset and add it to physical address
dwOffset = (DWORD)BaseAddress - (DWORD)(MemArray[i].VirtAddr);
ResultAdress.LowPart = MemArray[i].PhysAddr.LowPart + dwOffset ;
DPF(8,("MmGetPhysicalAddress:Base[%x]:Mem[%x]:Phys[%x]:Size[%x]:OK\n",
BaseAddress, MemArray[i].VirtAddr, MemArray[i].PhysAddr.LowPart, MemArray[i].dwSize ));
DPF(8,("MmGetPhysicalAddress:Offset[%x]:PhysHi[%x]:PhysLo[%x]:OK\n",
dwOffset, ResultAdress.HighPart, ResultAdress.LowPart ));
return ResultAdress;
}
Pointer PsGetCurrentProcess()
{
return (Pointer)GetCurrentProcess();
}
VOID KeQuerySystemTime ( PLARGE_INTEGER Time )
{
SYSTEMTIME WinCeSystemTime;
GetSystemTime ( &WinCeSystemTime );
SystemTimeToFileTime (&WinCeSystemTime, (FILETIME*)Time);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -