📄 dbgserial.c
字号:
// Copyright (c) David Vescovi. All rights reserved.
// Part of Project DrumStix
// Windows Embedded Developers Interest Group (WE-DIG) community project.
// http://www.we-dig.org
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------------------------
//
// File: dbgserial.c
//
// This module is provides the interface to the debug serial port.
//
//------------------------------------------------------------------------------
#include "bsp.h"
#include <nkintr.h>
//------------------------------------------------------------------------------
// Defines
//
//------------------------------------------------------------------------------
// Externs
//
//------------------------------------------------------------------------------
// Global Variables
//------------------------------------------------------------------------------
// Local Variables
//
static volatile UART_REG_T *g_pDebugUARTPort = NULL;
//------------------------------------------------------------------------------
// Local Functions
//
//------------------------------------------------------------------------------
//
// Function: InitDebugSerial
//
// Initializes the debug serial port
//
VOID InitDebugSerial(UINT32 DbgSerPhysAddr)
{
UINT32 logMask = 0;
#ifdef DEBUG
// At this moment we must suppress logging.
//
logMask = dpCurSettings.ulZoneMask;
dpCurSettings.ulZoneMask = 0;
#endif
g_pDebugUARTPort = (volatile UART_REG_T *) OALPAtoVA(DbgSerPhysAddr, FALSE);
OEMInitUart(DbgSerPhysAddr);
#ifdef DEBUG
// Restore the logging mask.
//
dpCurSettings.ulZoneMask = logMask;
#endif
}
//------------------------------------------------------------------------------
//
// Function: OEMWriteDebugByte
//
// Transmits a character out the debug serial port.
//
VOID OEMWriteDebugByte(UINT8 ch)
{
if (!g_pDebugUARTPort)
{
return;
}
// Spin if FIFO has more than half data.
//
while(!(g_pDebugUARTPort->LSR & 0x020));
// Write a character byte to the FIFO.
//
g_pDebugUARTPort->THR_RBR_DLL = (unsigned char)ch;
}
//------------------------------------------------------------------------------
//
// Function: OEMReadDebugByte
//
// Reads a byte from the debug serial port. Does not wait for a character.
// If a character is not available function returns "OEM_DEBUG_READ_NODATA".
//
int OEMReadDebugByte()
{
UINT32 data = OEM_DEBUG_READ_NODATA;
UINT32 lsr;
if (!g_pDebugUARTPort)
{
return(data);
}
// Read LSR.
//
lsr = g_pDebugUARTPort->LSR;
// Return if no data.
//
if(!(lsr & 0x1))
{
return(data);
}
// Read data.
//
data = g_pDebugUARTPort->THR_RBR_DLL;
// Signal error if PE or FE was set.
// Do nothing if BI or OE was set.
//
if(lsr & 0x0c)
{
data = OEM_DEBUG_COM_ERROR;
}
return(data);
}
//------------------------------------------------------------------------------
//
// Function: SpinForDebugKey
//
// Never ending loop waiting for any key on debug port.
//
void SpinForDebugKey(void)
{
while (1)
{
if (OEMReadDebugByte() != OEM_DEBUG_READ_NODATA) break;
}
}
//------------------------------------------------------------------------------
//
// Function: OEMClearDebugCommError
//
// Clears communications errors (flushes the serial FIFO).
//
void OEMClearDebugCommError(void)
{
while(OEMReadDebugByte() == OEM_DEBUG_COM_ERROR);
}
//------------------------------------------------------------------------------
//
// Function: OutputDebugStringW
//
// Output unicode string to debug serial port.
//
//void OutputDebugStringW(LPCWSTR string)
//{
// while (*string != L'\0') OEMWriteDebugByte((UINT8)*string++);
//}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -