?? hal.c
字號:
}
//-----------------------------------------------------------------------------
// FUNCTION: halWriteReg8( )
//
// DESCRIPTION:
// These routines write the S1D13700 control registers at the width
// indicated in the function name.
//
// PARAMETERS:
// Index - Offset to the register to read. The index value is zero based
// from the beginning of register address space.
// Value - The value to write to the register indicated by offset.
//
// Be very cautious in interpretting the index and values to write
// to registers using the halWriteReg8() and halWriteReg16()
// functions, to ensure the correct meaning is programmed into the
// register. Differing endians will move relative register offsets.
//
// RETURNS: Nothing
//
// MODIFIES: The register(s) indicated in the function name.
//-----------------------------------------------------------------------------
void halWriteReg8( UInt16 Index, UInt8 Value )
{
if ( HalInfo.dwFlags & fPCCARD_INTERFACE )
{
if( HalInfo.dwFlags&fINDIRECT_INTERFACE )
{
halIndRegWrite8( Index, Value );
}
else
{
*((pvUInt8)((UInt32)gHD.RegisterAddress + Index*2)) = Value;
}
}
else
{
if( HalInfo.dwFlags&fINDIRECT_INTERFACE )
{
halIndRegWrite8( Index, Value );
}
else
{
*((pvUInt8)((UInt32)gHD.RegisterAddress + Index)) = Value;
}
}
}
void halWriteReg16( UInt16 Index, UInt16 Value )
{
if ( HalInfo.dwFlags & fPCCARD_INTERFACE )
{
if( HalInfo.dwFlags&fINDIRECT_INTERFACE )
{
halIndRegWrite16( Index, Value );
}
else
{
UInt8* pReg = (UInt8*)(gHD.RegisterAddress + Index*2);
*((pvUInt8)(pReg)) = (UInt8) Value;
*((pvUInt8)(pReg+2)) = (UInt8) (Value>>8);
}
}
else
{
if( HalInfo.dwFlags&fINDIRECT_INTERFACE )
{
halIndRegWrite16( Index, Value );
}
else
{
UInt8* pReg = (UInt8*)(gHD.RegisterAddress + Index);
*((pvUInt8)(pReg )) = (UInt8) Value;
*((pvUInt8)(pReg+1)) = (UInt8)(Value>>8);
}
}
}
void halWriteReg32( UInt16 Index, UInt32 Value )
{
if ( HalInfo.dwFlags & fPCCARD_INTERFACE )
{
if( HalInfo.dwFlags&fINDIRECT_INTERFACE )
{
halIndRegWrite32( Index, Value );
}
else
{
UInt8* pReg = (UInt8*)(gHD.RegisterAddress + Index*2);
*((pvUInt8)(pReg )) = (UInt8) Value;
*((pvUInt8)(pReg+2)) = (UInt8)(Value>>8 );
*((pvUInt8)(pReg+4)) = (UInt8)(Value>>16);
*((pvUInt8)(pReg+6)) = (UInt8)(Value>>24);
}
}
else
{
if( HalInfo.dwFlags&fINDIRECT_INTERFACE )
{
halIndRegWrite32( Index, Value );
}
else
{
UInt8* pReg = (UInt8*)(gHD.RegisterAddress + Index);
*((pvUInt8)(pReg )) = (UInt8) Value;
*((pvUInt8)(pReg+1)) = (UInt8)(Value>>8 );
*((pvUInt8)(pReg+2)) = (UInt8)(Value>>16);
*((pvUInt8)(pReg+3)) = (UInt8)(Value>>24);
}
}
}
/*=========================================================================*/
/* Miscellaneous */
/*=========================================================================*/
//---------------------------------------------------------------------------
// FUNCTION: halGetVersionInfo()
//
// DESCRIPTION:
// This routine takes program specific information and merges it with
// HAL specific information and a standardized copyright notice.
// The newly formulated string is returned to the caller for display.
//
// The final formatted string will resemble:
//
// 13700PROGRAM - Internal test and diagnostic program - Build: 1234 [HAL: 1234]
// Copyright (c) Seiko Epson Corporation 2003-2005.
// All Rights Reserved.
//
// PARAMETERS:
// szProgName - Pointer to an ASCIIZ string containing the name of
// the program.
// (eg. "PROGRAM")
// szDesc - Pointer to an ASCIIZ string containing a description
// of what this program is intended to do.
// (eg. "Internal test and diagnostic program")
// szVersion - Pointer to an ASCIIZ string containg the build number
// of the program.
// (eg. "$Revision: 10 $")
// szInfoString - Pointer to a buffer into which the product and version
// information will be formatted into.
// Length - Total number of bytes in the string pointed to by
// pszInfoString. This function will write nLength or
// fewer bytes to the buffer pointed to by pszInfoString.
//
// RETURNS: Nothing.
//
// MODIFIES: Nothing.
//---------------------------------------------------------------------------
static char szCopyright[] = "Copyright (c) Seiko Epson Corporation 2003-2005.\n"
"All rights reserved.\n";
void halGetVersionInfo( const char * szProgName, const char * szDesc, const char * szVersion, char * szRetStr, int Length )
{
char szTmp[3*256+sizeof(HalInfo.szConfigString)]; // Allow for 3 LONG lines of text, plus config description string.
unsigned AppBuild, HalBuild;
int iTmp;
// From the HAL revision string, extract just the numerical value.
HalBuild = (strchr(gszHALRevision,':')) ? atoi(strchr(gszHALRevision,':')+1) : 0;
// From the application revision string, extract the numerical value.
AppBuild = (strchr(szVersion,':')) ? atoi(strchr(szVersion,':')+1) : 0;
iTmp = sprintf(szTmp, "%s%s - %s - Build %u [HAL: %u]\n"
"%s\n",
HalInfo.szChipId, szProgName, szDesc, AppBuild, HalBuild,
szCopyright);
// Tack on the configuration description if it's not an empty string.
if (HalInfo.szConfigString[0])
sprintf(szTmp+iTmp-1, ", Description:\n%s\n", HalInfo.szConfigString);
strncpy(szRetStr, szTmp, Length);
szRetStr[Length-1] = 0; // Terminate string in case of buffer overflow.
}
//-----------------------------------------------------------------------------
// FUNCTION: halGetLastError();
//
// DESCRIPTION:
// This routine retrieves information about the last error detected by the
// HAL.
//
// PARAMETERS:
// ErrMsg - String pointer to receive the textual error message.
// If ErrMsg is NULL then only the error code is be returned.
// MaxSize Maximum number of bytes that can be copied into the string
// pointed to by ErrMsg.
//
// RETURNS:
// The return value consists of the numerical error value which indexes
// into szErrMsg[]. Each string in szErrMsg[] describes a specific error.
//
// MODIFIES:
//-----------------------------------------------------------------------------
// IMPORTANT - IMPORTANT - IMPORTANT
// The messages in this array MUST correspond to
// the error codes contained in the HAL.H enumeration.
// IMPORTANT - IMPORTANT - IMPORTANT
static char * szErrMsg[ERR_FAILED + 1] =
{
"There was no error detected", // ERR_NONE
"Unable to find/load the S1D13xxx driver", // ERR_PCI_DRIVER_NOT_FOUND
"Unable to locate an S1D13xxx controller", // ERR_PCI_ADAPTER_NOT_FOUND
"This program has not been configured", // ERR_NOT_CONFIGURED
"Config CRC does not match configureation", // ERR_BAD_CFG_DATA
"The programmable clock cannot be set", // ERR_CANNOT_SET_CLOCK
"The requested clock frequency is too high", // ERR_CLK_FREQ_TOO_HIGH
"The requested clock frequency is too low", // ERR_CLK_FREQ_TOO_LOW
"An unspecified error occured" // ERR_FAILED
};
int halGetLastError( char * ErrMsg, int MaxSize )
{
char szTmp[160];
if (NULL != ErrMsg)
{
// Format a suitable error message,
// just don't prefix 'no error' with "ERROR: ..."
if (ERR_NONE == gnHalErrCode)
strncpy(ErrMsg, szErrMsg[gnHalErrCode], MaxSize);
else
{
sprintf(szTmp, "ERROR: %s", szErrMsg[gnHalErrCode]);
strncpy(ErrMsg, szTmp, MaxSize);
}
}
return gnHalErrCode;
}
//----------------------------------------------------------------------------
// OS FUNCTION: halpDelayUS()
//----------------------------------------------------------------------------
Boolean halDelayUS( UInt32 Microseconds )
{
__int64 SysClockCount, SysClockTarget;
// If requested delay is zero, just leave quickly.
if ( Microseconds == 0 )
return TRUE;
// Init the ps/Tick constant if this is the first time here.
if ( !gSysClockPS )
CalibrateSystemClock();
// Get the starting initial counter value now.
RDTSC( SysClockTarget );
// Calculate the terminal count of ticks required for requested delay.
SysClockTarget += (Microseconds*1000000i64)/gSysClockPS;
// Loop until the counter exceeds the number of ticks in the requested delay.
do
{
RDTSC( SysClockCount );
} while ( SysClockCount < SysClockTarget );
return TRUE;
}
//---------------------------------------------------------------------------
// PRIVATE FUNCTION: ClearVideoMemory()
//---------------------------------------------------------------------------
static void ClearVideoMemory( void )
{
halWriteDisplay8( 0x0, 0x0, HAL_DISPLAYMEMSIZE );
}
//---------------------------------------------------------------------------
// PRIVATE FUNCTION: InitRegisters()
//---------------------------------------------------------------------------
static void InitRegisters( void )
{
if ( HalInfo.dwFlags & fPCCARD_INTERFACE )
{
if( HalInfo.dwFlags & fINDIRECT_INTERFACE )
halpIndInitRegisters();
else
{
UInt16 i;
UInt8 bT;
*((pvUInt8)(gHD.RegisterAddress + REG0008_SLEEPIN * 2 )) = 0;
for( i=0; HalInfo.Regs[i].Index!=REGFLAG_ENDOFTABLE; i++ )
{
*((pvUInt8)(gHD.RegisterAddress + HalInfo.Regs[i].Index*2 )) = (UInt8)HalInfo.Regs[i].Value;
bT = *((pvUInt8)(gHD.RegisterAddress + HalInfo.Regs[i].Index*2));
}
}
}
else
{
if( HalInfo.dwFlags & fINDIRECT_INTERFACE )
halpIndInitRegisters();
else
{
UInt16 i;
UInt8 bT;
*((pvUInt8)(gHD.RegisterAddress + REG0008_SLEEPIN)) = 0;
for( i=0; HalInfo.Regs[i].Index!=REGFLAG_ENDOFTABLE; i++ )
{
*((pvUInt8)(gHD.RegisterAddress + HalInfo.Regs[i].Index)) = (UInt8)HalInfo.Regs[i].Value;
bT = *((pvUInt8)(gHD.RegisterAddress + HalInfo.Regs[i].Index));
}
}
}
}
//---------------------------------------------------------------------------
// PRIVATE FUNCTION: CalibrateSystemClock()
//---------------------------------------------------------------------------
static Boolean CalibrateSystemClock( void )
{
#define SYSCLOCK_CALIBRATE_US 500 // Time (in us) to use to calibrate system clock.
__int64 PerfCountPS;
__int64 PerfCount, PerfTarget;
__int64 SysClockCount;
HANDLE hProcess = GetCurrentProcess();
HANDLE hThread = GetCurrentThread();
DWORD ClassPriority = GetPriorityClass( hProcess );
int ThreadPriority = GetThreadPriority( hThread );
if ( QueryPerformanceFrequency((PLARGE_INTEGER)&PerfCount) )
PerfCountPS = 1000000000000i64/PerfCount;
else
{
return FALSE;
}
SetPriorityClass( hProcess, REALTIME_PRIORITY_CLASS );
SetThreadPriority( hThread, THREAD_PRIORITY_TIME_CRITICAL );
QueryPerformanceCounter( (PLARGE_INTEGER)&PerfTarget );
PerfTarget += (SYSCLOCK_CALIBRATE_US*1000000i64)/PerfCountPS;
RDTSC( gSysClockBase );
do
{
QueryPerformanceCounter( (PLARGE_INTEGER)&PerfCount );
} while ( PerfCount < PerfTarget );
RDTSC( SysClockCount );
SetThreadPriority( hThread, ThreadPriority );
SetPriorityClass( hProcess, ClassPriority );
gSysClockPS = (SYSCLOCK_CALIBRATE_US*1000000i64)/(SysClockCount-gSysClockBase);
return TRUE;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -