📄 debug.c
字号:
/*----------------------------------------------------------------------------
COPYRIGHT (c) 1998 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.
----------------------------------------------------------------------------*/
/*
HISTORY
960925 Tilakraj Roy Organized and added all three types of debugging.
980604 Volker Schildwach Ported to Windows CE
981021 Tilakraj Roy Changes for integrating into common source base
*/
/*----------------------------------------------------------------------------
SYSTEM INCLUDE FILES
----------------------------------------------------------------------------*/
#include <windows.h>
/*----------------------------------------------------------------------------
DRIVER SPECIFIC INCLUDE FILES
----------------------------------------------------------------------------*/
#include "tmmanlib.h"
#include "platform.h"
void debugOutput ( UInt8* pString );
void debugTrace ( UInt8* szString );
Bool debugInit ( debugParameters* Parameters )
{
DebugObject* Debug = &TMManGlobal->Debug;
Debug->DBGLevelBitmap = ((debugParameters*)Parameters)->LevelBitmap;
Debug->DBGType = ((debugParameters*)Parameters)->Type;
Debug->TraceLength = ((debugParameters*)Parameters)->TraceBufferSize ;
Debug->TraceBuffer = Debug->TraceBufferData;
Debug->TracePosition = 0;
Debug->TraceWrapped = False;
return statusSuccess;
}
Bool debugExit ( void )
{
return statusSuccess;
}
Bool debugCheckLevel ( UInt32 Level )
{
DebugObject* Debug = &TMManGlobal->Debug;
if( (( Level) & Debug->DBGLevelBitmap) )
{
return True;
}
return False;
}
UInt32 debugLevel ( UInt32 OptionBits )
{
DebugObject* Debug = &TMManGlobal->Debug;
UInt32 TempOptionBits;
TempOptionBits = Debug->DBGLevelBitmap;
Debug->DBGLevelBitmap = OptionBits;
return TempOptionBits;
}
void debugPrintf(
Int8* FormatString,
... )
{
PVOID pArgument = &FormatString;
USHORT Idx, StrIdx = 0, BufIdx = 0;
UCHAR Char;
DebugObject* Debug = &TMManGlobal->Debug;
// this function is ment for a 32 bit environment.
// modify pointer increment values for 32 bit stack.
((PVOID *)pArgument)++;
for( Idx = 0 ; FormatString[Idx] ; Idx ++ )
{
if( FormatString[Idx] == '%')
{
Char = FormatString[++Idx];
switch( Char )
{
case 'd':
{
ULONG Value = *((ULONG*)pArgument);
ULONG Divisor;
for( Divisor = 1 ; (Value / Divisor) >= 10 ;
Divisor *= 10);
do
//for( ; Value ; Divisor /= 10)
{
Debug->DBGBuffer[StrIdx++] = (UCHAR)
( (Value / Divisor) + '0');
Value = (ULONG)(Value % Divisor);
Divisor /= 10;
} while ( Divisor > 0);
((ULONG*)pArgument)++;
}
break;
case 's':
for ( BufIdx = 0 ;
((UCHAR*)(*((UCHAR**)pArgument)))[BufIdx];
BufIdx++ )
Debug->DBGBuffer[StrIdx++] =
(((UCHAR*)(*((UCHAR**)pArgument)))[BufIdx]);
((PVOID *)pArgument)++;
break;
case 'c':
Debug->DBGBuffer[StrIdx++] = (*((UCHAR*)pArgument));
((ULONG*)pArgument)++;
break;
case 'x':
{
ULONG Value = *((ULONG*)pArgument);
UCHAR Hex[] = "0123456789ABCDEF";
ULONG Divisor;
for( Divisor = 1 ; (Value / Divisor) >= 16 ;
Divisor *= 16);
do
{
Debug->DBGBuffer[StrIdx++] =
(Hex[(Value / Divisor)]);
Value = (ULONG)(Value % Divisor);
Divisor /= 16;
} while ( Divisor > 0);
((ULONG*)pArgument)++;
}
break;
default :
Debug->DBGBuffer[StrIdx++] = ('%');
Debug->DBGBuffer[StrIdx++] = (Char);
break;
}
}
else
{
Debug->DBGBuffer[StrIdx++] = FormatString[Idx];
continue;
}
}
Debug->DBGBuffer[StrIdx] = 0;
switch ( Debug->DBGType )
{
case constTMManDebugTypeTrace :
debugTrace ( Debug->DBGBuffer );
break;
case constTMManDebugTypeOutput :
debugOutput ( Debug->DBGBuffer );
break;
case constTMManDebugTypeNULL :
case constTMManDebugTypeCOM :
case constTMManDebugTypeLPT :
default :
break;
}
}
void debugOutput ( UInt8* szString )
{
// It can dump the output both to monochrone and write it
// to the debug buffer - for offline retrieval
TCHAR* wsString;
wsString = (TCHAR*)LocalAlloc(LMEM_ZEROINIT, 2*strlen(szString)+16 );
//BUGBUG: we have to alllocate one character more than necessary
// and zero it out WINCE UNICODE bug!
MultiByteToWideChar( CP_ACP, // code page
MB_PRECOMPOSED, // character-type options
szString, // address of string to map
strlen(szString), // number of bytes in string
wsString, // address of wide-character buffer
2*strlen(szString));// size of buffer);
OutputDebugString ( wsString );
LocalFree(wsString);
}
void debugTrace ( UInt8* szString )
{
DebugObject* Debug = &TMManGlobal->Debug;
// It can dump the output both to monochrone and write it
// to the debug buffer - for offline retrieval
}
// get the debug buffers on the target(other)processor
Bool debugDPBuffers (
UInt32 HalHandle,
UInt8 **ppFirstHalfPtr,
UInt32 *pFirstHalfSize,
UInt8 **ppSecondHalfPtr,
UInt32 *pSecondHalfSize )
{
UInt8* SDRAMPtr;
UInt32 SDRAMMapped;
UInt32 SDRAMLength;
UInt32 SDRAMPhysical;
DebugControl* DebugPtr;
UInt8* BufferPtr;
UInt32 Idx;
UInt8 MagicString[constDebugMagicSize];
/* initialize them to NULL in case we don't find the MAGIC header */
*ppFirstHalfPtr = NULL;
*ppSecondHalfPtr = NULL;
*pFirstHalfSize = 0;
*pSecondHalfSize = 0;
halGetSDRAMInfo (
HalHandle,
(Pointer*)&SDRAMPhysical,
(Pointer*)&SDRAMMapped,
&SDRAMLength );
SDRAMPtr = (UInt8*)SDRAMMapped;
strcpy ( MagicString, constDebugMagic );
MagicString[0] = 'T';
MagicString[1] = 'M';
MagicString[2] = '-';
MagicString[3] = 'S';
MagicString[4] = 'o';
MagicString[5] = 'f';
MagicString[6] = 't';
// search the entire SDRAM for the magic string
for ( Idx = 0 ;
Idx < SDRAMLength ;
Idx += constDebugMagicSize, SDRAMPtr += constDebugMagicSize )
{
if ( strcmp ( SDRAMPtr, MagicString ) == 0 )
{
break;
}
}
if ( Idx >= SDRAMLength )
{
return False;
}
DebugPtr = (DebugControl*)SDRAMPtr;
/* conver the physical address to mapped address */
BufferPtr = (UInt8*)
( ( halAccess32(HalHandle , (volatile UInt32)DebugPtr->Buffer ) - SDRAMPhysical ) +
SDRAMMapped );
if ( halAccess32( HalHandle, DebugPtr->Wrapped ) ) // wrap around has occured
{
*pFirstHalfSize =
halAccess32( HalHandle, DebugPtr->BufLen ) -
halAccess32( HalHandle, DebugPtr->BufPos );
*ppFirstHalfPtr = BufferPtr + halAccess32( HalHandle, DebugPtr->BufPos );
}
*ppSecondHalfPtr = BufferPtr;
*pSecondHalfSize = halAccess32( HalHandle, DebugPtr->BufPos );
return True;
}
// get the debug TMMan internal buffers on the target(other)processor
Bool debugTargetBuffers (
UInt32 HalHandle,
UInt8 **ppFirstHalfPtr,
UInt32 *pFirstHalfSize,
UInt8 **ppSecondHalfPtr,
UInt32 *pSecondHalfSize )
{
UInt8* SDRAMPtr;
UInt32 SDRAMMapped;
UInt32 SDRAMLength;
UInt32 SDRAMPhysical;
DebugControl* DebugPtr;
UInt8* BufferPtr;
UInt32 Idx;
UInt8 MagicString[constDebugMagicSize];
/* initialize them to NULL in case we don't find the MAGIC header */
*ppFirstHalfPtr = NULL;
*ppSecondHalfPtr = NULL;
*pFirstHalfSize = 0;
*pSecondHalfSize = 0;
halGetSDRAMInfo (
HalHandle,
(Pointer*)&SDRAMPhysical,
(Pointer*)&SDRAMMapped,
&SDRAMLength );
SDRAMPtr = (UInt8*)SDRAMMapped;
strcpy ( MagicString, constDebugTMManMagic );
MagicString[0] = 'T';
MagicString[1] = 'i';
MagicString[2] = 'l';
MagicString[3] = 'a';
MagicString[4] = 'k';
MagicString[5] = 'r';
MagicString[6] = 'a';
MagicString[7] = 'j';
// search the entire SDRAM for the magic string
for ( Idx = 0 ;
Idx < SDRAMLength ;
Idx += constDebugMagicSize, SDRAMPtr += constDebugMagicSize )
{
if ( strcmp ( SDRAMPtr, MagicString ) == 0 )
{
break;
}
}
if ( Idx >= SDRAMLength )
{
return False;
}
DebugPtr = (DebugControl*)SDRAMPtr;
/* conver the physical address to mapped address */
BufferPtr = (UInt8*)
( ( halAccess32(HalHandle , (volatile UInt32)DebugPtr->Buffer ) - SDRAMPhysical ) +
SDRAMMapped );
if ( halAccess32( HalHandle, DebugPtr->Wrapped ) ) // wrap around has occured
{
*pFirstHalfSize =
halAccess32( HalHandle, DebugPtr->BufLen ) -
halAccess32( HalHandle, DebugPtr->BufPos );
*ppFirstHalfPtr = BufferPtr + halAccess32( HalHandle, DebugPtr->BufPos );
}
*ppSecondHalfPtr = BufferPtr;
*pSecondHalfSize = halAccess32( HalHandle, DebugPtr->BufPos );
return True;
}
// get the debug buffer on the host(this)processor
Bool debugHostBuffers (
UInt8 **ppFirstHalfPtr,
UInt32 *pFirstHalfSize,
UInt8 **ppSecondHalfPtr,
UInt32 *pSecondHalfSize )
{
*ppFirstHalfPtr = NULL;
*ppSecondHalfPtr = NULL;
*pFirstHalfSize = 0;
*pSecondHalfSize = 0;
return statusSuccess;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -