debug.c.org
来自「WinCE 3.0 BSP, 包含Inter SA1110, Intel_815」· ORG 代码 · 共 568 行 · 第 1/2 页
ORG
568 行
#ifdef USE_EDBG_SERVICES
#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).
EdbgOutputDebugString("Reading pDriverGlobals (0x%x) as 0x%x\n",
&pDriverGlobals->eth.EbootMagicNum, pDriverGlobals->eth.EbootMagicNum);
pDriverGlobals->eth.EbootMagicNum = EBOOT_MAGIC_NUM ;
pDriverGlobals->eth.etherFlags = EDBG_FL_DBGMSG | EDBG_FL_PPSH | EDBG_FL_KDBG;
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
#endif USE_EDBG_SERVICES
}
/*****************************************************************************
*
*
* @func void | OEMWriteDebugString | Display string to the monitor port.
*
* @parm unsigned short * | str |
* Points to the receiving buffer.
*/
void
OEMWriteDebugString(unsigned short *str) {
if (DEBUG_SERIAL_ON)
{
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 timeout = 0;
if (DEBUG_SERIAL_ON) {
if(DEBUG_SERIAL_PORT & SCI) {
// Wait for SCI to get ready for transmittal.
while(!(SCSSR & SCI_TDRE)) { // Wait for TDFE
if(timeout ++ >= 5000) {
HandleError(SCI);
return;
}
}
SCTDR = ch;
SCSSR &= ~SCI_TDRE; // Clear TDFE
}
#if 0
waitTX:
DummyDelay();
if((SCSSR & 0x80)==0x80)
{
// *(UCHAR *)(0xa6e00000) = ~0x25;
SCTDR = ch;
DummyDelay();
SCSSR &= 0x7F;
DummyDelay();
if((SCSSR & 0x04)==0x04) {
// *(UCHAR *)(0xa6e00000) = ~0x26;
}
goto out;
}
goto waitTX;
}
out:
#endif
if(DEBUG_SERIAL_PORT & SCIF) {
while(!(SCFSR2 & SCIF_TDFE)) { // Wait for TDFE
if(timeout ++ >= 5000) {
HandleError(SCIF);
return;
}
}
SCFTDR2 = ch;
SCFSR2 &= ~SCIF_TDFE; // Clear TDFE
}
}
}
/*****************************************************************************
*
*
* @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()
{
#if 0
UCHAR ch;
if (DEBUG_SERIAL_ON)
{
// *(UCHAR *)(0xa6e00000) = ~0x01;
if (SCSSR & 0x38) // See if there is an error
HandleError();
DummyDelay();
// *(UCHAR *)(0xa6e00000) = ~0x03;
DummyDelay();
// *(UCHAR *)(0xa6e00000) = ~0x07;
if( !( SCSSR & 0x40 ) ) // See if RDRF = 1
{
// *(UCHAR *)(0xa6e00000) = ~0x0f;
return OEM_DEBUG_READ_NODATA;
}
ch = SCRDR;
DummyDelay();
// *(UCHAR *)(0xa6e00000) = ~0x1f;
SCSSR &= ~0x40; // Clear RDF
// *(UCHAR *)(0xa6e00000) = ~0x3f;
return ch;
}
return (0);
#else
// Modified by Naresh Gupta.
// pp 15-33 SH4 hardware reference manual.
UCHAR ch;
if (DEBUG_SERIAL_ON) {
if(DEBUG_SERIAL_PORT & SCI) {
while(TRUE) {
ch = (SCSSR & (SCI_ORER | SCI_PER | SCI_FER));
if(ch) {
HandleError(SCI);
continue;
}
if(!(SCSSR & SCI_RDRF))
continue;
ch = SCRDR;
SCSSR &= ~SCI_RDRF;
// OutputFormatString("SCRDR=0x%x, ch=0x%x, SCSSR=0x%x\r\n", SCRDR, ch, SCSSR);
return((int)ch);
}
}
if(DEBUG_SERIAL_PORT & SCIF) {
while(TRUE) {
ch = (SCFSR2 & (SCIF_DR | SCIF_ER | SCIF_BRK | SCIF_FER | SCIF_PER));
ch |= (SCLSR2 & SCIF_ORER);
if(ch) {
// OutputFormatString("Error in Serial Receiption. Error Flag = %B\r\n", ch);
HandleError(SCIF);
continue;
}
if(!(SCFSR2 & SCIF_RDF))
continue;
ch = SCFRDR2;
SCFSR2 &= ~SCIF_RDF;
return((int)ch);
}
}
}
#endif
}
void HandleError(int port)
{
// OutputFormatString("+HandleError\r\n");
if(port == SCI) {
SCSSR &= ~(SCI_ORER | SCI_FER | SCI_PER);
}
if(port == SCIF) {
SCFSR2 &= ~(SCIF_ER | SCIF_BRK | SCIF_DR | SCIF_PER | SCIF_FER);
SCLSR2 &= ~SCIF_ORER;
}
}
/*****************************************************************************
*
*
* @func void | OEMClearDebugComError | Clear a debug communications error
*
*/
void
OEMClearDebugCommError(void)
{
// Clears error on all the enabled debug ports.
// use HandleError if you want to clear only one of the ports.
if (DEBUG_SERIAL_ON) {
if(DEBUG_SERIAL_PORT & SCI)
HandleError(SCI);
if(DEBUG_SERIAL_PORT & SCIF)
HandleError(SCIF);
}
}
/* This function will Assert the RTS# pin */
OEMStopSerialInput(void)
{
#if (FLOW_CONTROL == FLOW_HW)
SCFCR2 &= ~0x08; // Modem control Disable
SCSPTR2 |= 0x00C0;
#endif (FLOW_CONTROL == FLOW_HW)
return 0;
}
/* This function will De-assert the RTS# pin */
OEMStartSerialInput(void)
{
#if (FLOW_CONTROL == FLOW_HW)
SCSPTR2 &= ~0x00C0;
SCFCR2 |= 0x08; // Modem control Enable
#endif (FLOW_CONTROL == FLOW_HW)
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?