debug.c

来自「WinCE 3.0 BSP, 包含Inter SA1110, Intel_815」· C语言 代码 · 共 196 行

C
196
字号
/*++
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.
Copyright (c) 1995, 1996, 1997  Microsoft Corporation

Module Name:  

Abstract:  

Functions:


Notes: 

The original Microsoft version of this file did serial debugging using the
ODO DMA engine to handle all the awkward multiple sends.

--*/

/*****************************************************************************
* 
*   @doc EXTERNAL OEM
*
*   @module debug.c | OEM Debug Serial Monitor Routines
*
******************************************************************************/
#include <windows.h>
#include "nkintr.h"
#include "drv_glob.h"
#include "halether.h"
#include "ethdbg.h"
#include "win_plat.h"


#define pCSRA (DEBUG_SER_BASE + SER_CSR_A)
#define pCSRB (DEBUG_SER_BASE + SER_CSR_B)

#define pDriverGlobals  ((PDRIVER_GLOBALS) DRIVER_GLOBALS_PHYSICAL_MEMORY_START)

// For converting net byte order to host byte order
#define htons( value ) ((UINT16)((((UINT16)value) << 8) | (((UINT16)((UINT16)value)) >> 8)))
#define ntohs( value ) htons( value )      

extern void InitSerial(DWORD) ;
extern void pHALr_SetLEDs(DWORD) ;
extern void pHALr_WriteAlpha(DWORD) ;

// ***************************************************************************
// Note: These two routines are from uHAL/iolib.c, so shouldn't need to change 

/* Routine converts address to real StrongARM address & writes a byte */
void outb(BYTE value, void *address)
{
        IO_WRITE(address, value) ;
}

/* Routine converts address to real StrongARM address & reads a byte */
DWORD inb(void *address)
{
        return (IO_READ(address)) ;
}

/*****************************************************************************
*
*
*   @func   void    |   OEMInitDebugSerial | Initialize debug monitor port.
*
*   NOTE: This function MUST NOT use any global variables!!!!!!
*/
void OEMInitDebugSerial(void) 
{

	InitSerial(VDEBUG_COMPORT) ;
  
#ifdef NOTYET
  // Initialize ethernet debug support.  This requires that the ethernet
  // bootloader (eboot) is loaded.  Check for magic cookie in uninitialized
  // section of driver globals to determine if eboot is present or not.  If
  // not, don't touch the ethernet HW.
  if (pDriverGlobals->eth.EbootMagicNum == EBOOT_MAGIC_NUM) {
      // Eboot is present, attempt to init the ethernet HW.  If the ethernet card
      // is not present, EdbgInit will return failure. Also, this will
      // read our IP and ethernet address from the serial EEPROM on the ethernet board.
  }
#endif

#ifdef PPSH_SERIAL
  // If we're running PPSH over serial, switch now, so that debug messages will get
  // formatted correctly (through lpWriteDebugStringFunc).
  SetKernelCommDev(KERNEL_SVC_PPSH, KERNEL_COMM_SERIAL);
#endif
      
}

/*****************************************************************************
*
*
*   @func   void    |   OEMWriteDebug | Display value to specified LED port.
*
*   The wIndex parameter can be used to specify a write to the discrete LEDS (if
*   0xffff), otherwise is used as an offset (DWORD aligned) for the Alpha LEDS
*   for triggering.
*/
void 
OEMWriteDebugLED(WORD wIndex, DWORD dwPattern)
{
    // Need to make sure this works with all the different RBF files.
    if( 0xFFFF == wIndex )
        pHALr_SetLEDs(dwPattern);
    else
        pHALr_WriteAlpha(dwPattern);
}

/*****************************************************************************
*
*
*   @func   void    |   OEMWriteDebugString | Display string to the monitor port.
*
*   @parm   unsigned short * | str |
*           Points to the receiving buffer.
*/
void 
OEMWriteDebugString(unsigned short *str) {
    // Send message to serial port
    while (*str) 
        OEMWriteDebugByte((unsigned char)*str++);
}

/*****************************************************************************
*
*
*   @func   void    |   OEMWriteDebugByte | Output byte to the monitor port.
*
*   @parm   unsigned char *| str |
*           Points to the output buffer.
*/
void 
OEMWriteDebugByte(UCHAR ch) 
{
	int status ;
	
	do {
		status = GET_STATUS(VDEBUG_COMPORT) ;
	} while(!TX_READY(status));		/* wait until ready */

	PUT_CHAR(VDEBUG_COMPORT, ch) ;
}

/*****************************************************************************
*
*
*   @func   int    |   OEMReadDebugByte | Get a byte from the monitor port.
*
*   @rdesc  Returns: 
*           OEM_DEBUG_COM_ERROR        Error detected
*           OEM_DEBUG_READ_NODATA      No data is available at the port.
*           ch                         If data is available.
*
*/
int
OEMReadDebugByte() 
{
	DWORD Status ;
	DWORD ch ;

	Status = GET_STATUS(VDEBUG_COMPORT) ;
	if (!RX_DATA(Status)) {
		// No data is available at the port.
		return (OEM_DEBUG_READ_NODATA);
	}

	ch = GET_CHAR(VDEBUG_COMPORT) ;
	return((int)ch);

}

/*****************************************************************************
*
*
*   @func   void    |   OEMClearDebugComError | Clear a debug communications error
*
*/
void
OEMClearDebugCommError(void) 
{
	DWORD *comport = (DWORD *)VDEBUG_COMPORT ;
	DWORD *controlReg ;
	
	controlReg = comport + AMBA_UARTCR ;
	// I don't think disabling the port is the answer..
	WRITE_REGISTER_ULONG(controlReg, 0x0) ;
}

⌨️ 快捷键说明

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