⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mpldebug.c

📁 NATIONAL公司DP83816芯片Linux下驱动
💻 C
字号:

//******************************************************************************
//
//  MPLDEBUG.C
//
//  Copyright (c) 2004 National Semiconductor Corporation.
//  All Rights Reserved
//
//  MPL Debug
//
//  This file contains the API implementations for
//     o MPL Capabilities and MTU reporting 
//
//******************************************************************************

#include <mplinternal.h>

// These functions are defined on a retail build but they don't
// do anything.
#ifndef MPL_CHECKED_BUILD
NS_VOID  
    MplDebDumpBuffer(
        IN NS_UINT8 *buffer,
        IN NS_UINT length) { return; }
NS_VOID  
    MplDebDumpWords(
        IN NS_UINT32 *buffer,
        IN NS_UINT length) { return; }
NS_VOID  
    MplDebEnablePathTracing(
        IN NS_UINT zones) { return; }
NS_VOID  
    MplDebEnableMsgsAndChecks(
        IN NS_UINT zones) { return; }
NS_VOID 
    MplDebDumpAdapterRegisters(
        IN NS_VOID *pEplContext) { return; }
#endif //!MPL_CHECKED_BUILD


// These routines are only included/compiled in a checked build.
#ifdef MPL_CHECKED_BUILD

// This is a global variable that is used by the MPL_CENTER, MPL_CEXIT
// macros that are defined in epldebug.h
NS_UINT MplDebugZonePathTracing = DZONE_ENABLED_PATH;

// This is a global variable that is used to control whether verbose
// messages are displays and whether ASSERTS are enabled.
NS_UINT MplDebugZoneMsgAndChecks = DZONE_ENABLED_MSG_CHECKS;

static NS_CHAR * MplDebLogAddrToStr( IN NS_VOID *logAddr, IN NS_CHAR *outBuffer);

//**********************************************************************
//  MplDebDumpBuffer
//
//  Displays the contents of the specified memory buffer using
//  the OAI defined debug trace facility.
//
//  Parameters:
//      buffer  The memory buffer to display
//      length  The number of bytes to display
//  
//  Return:
//      Nothing
//  
//**********************************************************************
NS_VOID
    MplDebDumpBuffer(
        IN NS_UINT8 *buffer,
        IN NS_UINT   length)
{
#define DEB_BYTES_PER_LINE  16

NS_UINT x, y, numLines, remainder;
NS_UINT8 asciBuf[ DEB_BYTES_PER_LINE+1 ];
NS_CHAR logAddrStr[ NS_LOG_ADDR_BUF_SIZE ];

    MPL_TRACE(("Address %s, length %d bytes:\n\n", 
                MplDebLogAddrToStr( buffer, logAddrStr),
                length));

    if ( length == 0)
        return;

    numLines = (length-1) / DEB_BYTES_PER_LINE + 1;
    remainder = (length-1) % DEB_BYTES_PER_LINE + 1;

    for ( x = 0; x < numLines; x++)
    {
        MPL_TRACE(("%08X: ", x * DEB_BYTES_PER_LINE));

        for ( y = 0;
              y < ( (x != (numLines - 1)) ? DEB_BYTES_PER_LINE : remainder);
              y++, buffer++)
        {
            asciBuf[y+0] = (NS_UINT8)
                           ((*buffer >= '!' && *buffer <= '~') ? *buffer : '.');
            asciBuf[y+1] = '\0';

            MPL_TRACE(( "%02X ", (NS_UINT) *buffer));
            if ( y == (DEB_BYTES_PER_LINE-1))
                MPL_TRACE(( " "));
        }

        MPL_TRACE(( "%s\n", asciBuf));
    }
}

//**********************************************************************
//  MplDebDumpWords
//
//  Displays the contents in hexadecimal of the specified memory buffer
//  using the OAI defined debug trace facility.  Output is a list of
//  32-bit words.
//
//  Parameters:
//      buffer  The memory buffer to display
//      length  The number of 32-bit words to display
//  
//  Return:
//      Nothing
//  
//**********************************************************************
NS_VOID
MplDebDumpWords(
    IN NS_UINT32 *buffer,
    IN NS_UINT length
)
{
    NS_UINT i;
    NS_CHAR logAddrStr[ NS_LOG_ADDR_BUF_SIZE ];

    MPL_TRACE(("Address %s, length %d words:\n\n", 
                MplDebLogAddrToStr( buffer, logAddrStr),
                length));

    for (i=0;i<length;i++,buffer++) {
        MPL_TRACE(("%s: %x\n",MplDebLogAddrToStr(buffer,logAddrStr),
                    (NS_UINT)*buffer));
    }
}

//**********************************************************************
//  MplDebEnablePathTracing
//
//  Enables or disables the traceouts in ELI and EHI components when
//  a function is entered and when it is exited. 
//
//  The system defaults to the value of DZONE_ENABLED_PATH found 
//  in elidebug.h
//
//  zones
//      A bit-wise OR of zero or more of the following values (default is 0):
//  
//  Return:
//      Nothing
//  
//**********************************************************************
NS_VOID  
    MplDebEnablePathTracing(
        IN NS_UINT zones)
{
    MplDebugZonePathTracing = zones;
    return;
}



//**********************************************************************
//  MplDebEnableMsgsAndChecks
//
//  Enables or disables diagnostic trace out messages and consistency 
//  checks inside MPL modules. This will enable asserts and verbose 
//  message output for the specified zones. This function does nothing 
//  in a "Retail Build".
//
//  The system defaults to the value of DZONE_ENABLED_MSG_CHECKS
//  found in elidebug.h
//
//  zones
//      A bit-wise OR of zero or more of the following values (default is 0):
//  
//  Return:
//      Nothing
//  
//**********************************************************************
NS_VOID  
    MplDebEnableMsgsAndChecks(
        IN NS_UINT zones)
{
    MplDebugZoneMsgAndChecks = zones;
    return;
}


//**********************************************************************
//  MplDebDumpAdapterRegisters
//
//  Dumps the contents of the EMX10110 chip registers.
//
//  Parameters:
//      pMplCtx Pointer to MPL context.
//  
//  Return:
//      Nothing
//  
//**********************************************************************
NS_VOID 
    MplDebDumpAdapterRegisters(
        IN NS_VOID *pMplCtx)
{
    MPL_TRACE(("MPL Registers\n"));
    return;
}

 
//**********************************************************************
//  MplDebLogAddrToStr
//
//  Converts a logical address (32-bit or 64-bit) to its string
//  representation. For example, an address of 0x12345678 would
//  be converted to the string "12345678".
//
//  logAddr
//      Logical address to convert.
//  outBuffer
//      Caller allocated string buffer of size NS_LOG_ADDR_BUF_SIZE.
//
//  Returns:
//      Pointer to outBuffer
//**********************************************************************
static 
NS_CHAR *
    MplDebLogAddrToStr(
        IN NS_VOID *logAddr,
        IN NS_CHAR *outBuffer)
{
NS_UINT i;
NS_CHAR val;
NS_ADDR addr = *(NS_ADDR*)&logAddr;

    // Do it a nibble at a time.
    for ( i = 0; i < (2 * sizeof( NS_VOID *)); i++)
    {
        val = (NS_CHAR)((NS_UINT8)addr & 0x0F);
        
        outBuffer[ 2 * sizeof( NS_VOID *) - i - 1 ] = 
            (NS_CHAR)((val <= 9) ? val + '0' : val - 10 + 'A');
            
        addr >>= 4;
    }
    
    outBuffer[ 2 * sizeof( NS_VOID *) ] = '\0';
    return outBuffer;
}



//**********************************************************************
//  MplDebPhysAddrToStr
//
//  Converts a physical address (32-bit or 64-bit) to it string
//  representation. For example, an address of 0x12345678 would 
//  be converted to the string "12345678".
//
//  physAddr
//      Physical address to convert.
//  outBuffer
//      Caller allocated string buffer of size NS_PHYS_ADDR_BUF_SIZE.
//
//  Returns:
//      Pointer to outBuffer
//**********************************************************************
NS_CHAR *
    MplDebPhysAddrToStr(
        IN NS_ADDR physAddr,
        IN NS_CHAR *outBuffer)
{
NS_UINT i;
NS_CHAR val;

    // Do it a nibble at a time.
    for ( i = 0; i < (2 * sizeof( NS_ADDR)); i++)
    {
        val = (NS_CHAR)(physAddr & 0x0F);
        
        outBuffer[ 2 * sizeof( NS_ADDR) - i - 1 ] = 
            (NS_CHAR)((val <= 9) ? val + '0' : val - 10 + 'A');

        physAddr >>= 4;
    }
    
    outBuffer[ 2 * sizeof( NS_ADDR) ] = '\0';
    return outBuffer;
}


#endif // MPL_CHECKED_BUILD

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -