debug_org.c
来自「WinCE 3.0 BSP, 包含Inter SA1110, Intel_815」· C语言 代码 · 共 207 行
C
207 行
/*
Copyright(c) 1998,1999 SIC/Hitachi,Ltd.
Module Name:
debug.c
Revision History:
26th April 1999 Released
1st July 1999 Removed unnecessary function
6st July 1999 Changed baudrate setting
*/
#include <windows.h>
#include <nkintr.h>
#include <ethdbg.h>
#include <halether.h>
#include "shx.h"
#include "platform.h"
#include "drv_glob.h"
#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 )
static BOOL DebugEtherPresent;
#define SCSMR *(UCHAR volatile *)(SCI_SCSMR1) /* */
#define SCBRR *(UCHAR volatile *)(SCI_SCBRR1) /* */
#define SCSCR *(UCHAR volatile *)(SCI_SCSCR1) /* */
#define SCTDR *(UCHAR volatile *)(SCI_SCTDR1) /* */
#define SCSSR *(UCHAR volatile *)(SCI_SCSSR1) /* */
#define SCRDR *(UCHAR volatile *)(SCI_SCRDR1) /* */
#define SCSCMR *(UCHAR volatile *)(SCI_SCSCMR1) /* */
#define SCSPTR *(UCHAR volatile *)(SCI_SCSPTR1) /* */
/*****************************************************************************
*
*
* @func void | OEMInitDebugSerial | Initialize debug monitor port.
*
* NOTE: This function MUST NOT use any global variables!!!!!!
*/
void OEMInitDebugSerial(void)
{
if (ENABLE_DEBUG_SERIAL)
{
SCSMR = 0x00; /* n=0 */
SCBRR = 0x27; /* Baud rate 38400; P=50MHz: Refer to SH7750 Hardware mamual 15.2.9*/
SCSCR = 0x70; /* TIE,RIE,TE,RE=2 enabled */
SCTDR = 0x41;
SCSSR = 0x80;
SCRDR = 0x00;
SCSPTR = 0;
}
#ifndef BOOT_LOADER
OEMWriteDebugString(TEXT("Initialize ethernet debug support.\r\n"));
// 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 (will hang if FPGA doesn't have ether support).
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.
EdbgOutputDebugString("Ethernet bootloader present, peer IP address: %s\r\n",
inet_ntoa(pDriverGlobals->eth.DownloadHostAddr.dwIP));
if ( EdbgInit() ) {
OEMWriteDebugString(TEXT("Debug ethernet card initialized\r\n"));
DebugEtherPresent = 1;
EdbgOutputDebugString("pDriverGlobals->eth.etherFlags = %B\r\n", pDriverGlobals->eth.etherFlags);
// Attempt to configure debug services over ethernet. SetKernelCommDev will block
// (calling EdbgRegisterDfltClient) until the desktop application is started, and
// will set up the necessary kernel hooks to route data to the peer.
if ( (pDriverGlobals->eth.etherFlags & EDBG_FL_DBGMSG) &&
SetKernelCommDev(KERNEL_SVC_DBGMSG,KERNEL_COMM_ETHER) ) {
EdbgOutputDebugString("Switched to ethernet for debug messages, host: %s, port: %d\r\n",
inet_ntoa(pDriverGlobals->eth.DbgHostAddr.dwIP),
ntohs(pDriverGlobals->eth.DbgHostAddr.wPort));
}
if ( (pDriverGlobals->eth.etherFlags & EDBG_FL_PPSH) &&
SetKernelCommDev(KERNEL_SVC_PPSH,KERNEL_COMM_ETHER) ) {
EdbgOutputDebugString("Switched to ethernet for PPSH, host: %s, port: %d\r\n",
inet_ntoa(pDriverGlobals->eth.PpshHostAddr.dwIP),
ntohs(pDriverGlobals->eth.PpshHostAddr.wPort));
}
if ( (pDriverGlobals->eth.etherFlags & EDBG_FL_KDBG) &&
SetKernelCommDev(KERNEL_SVC_KDBG,KERNEL_COMM_ETHER) ) {
EdbgOutputDebugString("Switched to ethernet for KDBG, host: %s, port: %d\r\n",
inet_ntoa(pDriverGlobals->eth.KdbgHostAddr.dwIP),
ntohs(pDriverGlobals->eth.KdbgHostAddr.wPort));
}
} else
OEMWriteDebugString(TEXT("Debug ethernet card not present or failed init\r\n"));
pDriverGlobals->eth.EbootMagicNum = 0;
} else if ( DebugEtherPresent ) {
// This is the case where we are resuming from OEMPowerOff. Just reinitialize the HW here..
EdbgInit();
}
#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
#endif // BOOT_LOADER
}
/*****************************************************************************
*
*
* @func void | OEMWriteDebugString | Display string to the monitor port.
*
* @parm unsigned short * | str |
* Points to the receiving buffer.
*/
void OEMWriteDebugString(unsigned short *str)
{
if (ENABLE_DEBUG_SERIAL)
{
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)
{
if (ENABLE_DEBUG_SERIAL)
{
waitTX:
if((SCSSR & 0x80)==0x80)
{
SCTDR = ch;
SCSSR &= 0x7F;
return;
}
goto waitTX;
}
}
/*****************************************************************************
*
*
* @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()
{
UCHAR ch;
if (ENABLE_DEBUG_SERIAL)
{
if (SCSSR & 0x38) // See if there is an error
{
OEMClearDebugCommError();
}
if( !( SCSSR & 0x40 ) ) // See if RDRF = 1
{
return OEM_DEBUG_READ_NODATA;
}
ch = SCRDR;
SCSSR &= ~0x40; // Clear RDF
return ch;
}
return (0);
}
/*****************************************************************************
*
*
* @func void | OEMClearDebugComError | Clear a debug communications error
*
*/
void OEMClearDebugCommError(void)
{
if (ENABLE_DEBUG_SERIAL)
{
SCSSR &= ~0x38; // Clear ORER,PER,FER
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?