📄 debug.c
字号:
//
// Copyright (c) Special Computing. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//------------------------------------------------------------------------------
//
// File: debug.c
//
#include <bsp.h>
//------------------------------------------------------------------------------
// Static variables.
// Virtual uncached address of debug UART registers.
static OMAP3_UART_REGS *g_pUartRegs;
static BOOL g_debugLedState;
//------------------------------------------------------------------------------
//
// Function: OEMInitDebugSerial
//
// Initialize debug serial port.
//
VOID OEMInitDebugSerial()
{
// TBD: set UART PADs and module clocks
// Get UART virtual address
g_pUartRegs = OALPAtoUA(DEBUG_UART_REGS_PA);
// Reset UART & wait until it completes
OUTREG8(&g_pUartRegs->SYSC, UART_SYSC_RST);
while ((INREG8(&g_pUartRegs->SYSS) & UART_SYSS_RST_DONE) == 0);
// Set baud rate
OUTREG8(&g_pUartRegs->LCR, UART_LCR_DLAB);
OUTREG8(&g_pUartRegs->DLL, BSP_UART_DSIUDLL);
OUTREG8(&g_pUartRegs->DLH, BSP_UART_DSIUDLH);
// 8 bit, 1 stop bit, no parity
OUTREG8(&g_pUartRegs->LCR, BSP_UART_LCR);
// Enable FIFO
OUTREG8(&g_pUartRegs->FCR, UART_FCR_FIFO_EN);
// Pool
OUTREG8(&g_pUartRegs->IER, 0);
// Set DTR/RTS signals
OUTREG8(&g_pUartRegs->MCR, UART_MCR_DTR|UART_MCR_RTS);
// Configuration complete so select UART 16x mode
OUTREG8(&g_pUartRegs->MDR1, UART_MDR1_UART16);
return;
}
//------------------------------------------------------------------------------
//
// Function: OEMWriteDebugByte
//
// Write byte to debug serial port.
//
VOID OEMWriteDebugByte(UINT8 ch)
{
if (g_pUartRegs != NULL) {
// Wait if FIFO is full
while ((INREG8(&g_pUartRegs->SSR) & UART_SSR_TX_FIFO_FULL) != 0);
// Send
OUTREG8(&g_pUartRegs->THR, ch);
}
}
//------------------------------------------------------------------------------
//
// Function: OEMReadDebugByte
//
// Input character/byte from debug serial port
//
INT OEMReadDebugByte()
{
UINT8 ch = OEM_DEBUG_READ_NODATA;
UINT8 status;
if (g_pUartRegs != NULL) {
status = INREG8(&g_pUartRegs->LSR);
if ((status & UART_LSR_RX_FIFO_E) != 0) {
ch = INREG8(&g_pUartRegs->RHR);
if ((status & UART_LSR_RX_ERROR) != 0) ch = OEM_DEBUG_COM_ERROR;
}
}
return (INT)ch;
}
//------------------------------------------------------------------------------
//
// Function: OEMWriteDebugLED
//
// This function is called via OALLED macro to display debug information.
// Writes to debug LED.
// Turns off LED if data 0
// Turns on LED if data 1
// Toggle LED if data 2
// Index not used.
//
VOID OEMWriteDebugLED(WORD index, DWORD data)
{
OMAP3_GPIO_REGS *pGPIO5Regs = OALPAtoUA(OMAP3_GPIO5_REGS_PA);
if (data == DEBUG_LED_TOGGLE)
{ // toggle
if (TRUE == g_debugLedState)
{
pGPIO5Regs->ulGPIO_CLEARDATAOUT = DEBUG_LED_GPIO5;
g_debugLedState = FALSE;
}
else
{
pGPIO5Regs->ulGPIO_SETDATAOUT = DEBUG_LED_GPIO5;
g_debugLedState = TRUE;
}
}
else
{ // ON or OFF
data ? (pGPIO5Regs->ulGPIO_SETDATAOUT = DEBUG_LED_GPIO5) : (pGPIO5Regs->ulGPIO_CLEARDATAOUT = DEBUG_LED_GPIO5);
data ? (g_debugLedState = TRUE) : (g_debugLedState = FALSE);
}
}
//------------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -