📄 serial.c
字号:
//
// Copyright (c) Special Computing. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//------------------------------------------------------------------------------
//
// File: serial.c
//
#include <windows.h>
#include <omap2420.h>
#include <bsp.h>
//------------------------------------------------------------------------------
//
// Function: OEMDebugInit
//
// Initialize debug serial port
//
BOOL OEMDebugInit()
{
OMAP3_UART_REGS *pUartRegs = (OMAP3_UART_REGS *)DEBUG_UART_REGS_PA;
// Reset UART & wait until it completes
OUTREG8(&pUartRegs->SYSC, UART_SYSC_RST);
while ((INREG8(&pUartRegs->SYSS) & UART_SYSS_RST_DONE) == 0);
// Set baud rate
OUTREG8(&pUartRegs->LCR, UART_LCR_DLAB);
OUTREG8(&pUartRegs->DLL, BSP_UART_DSIUDLL);
OUTREG8(&pUartRegs->DLH, BSP_UART_DSIUDLH);
// 8 bit, 1 stop bit, no parity
OUTREG8(&pUartRegs->LCR, BSP_UART_LCR);
// Enable FIFO
OUTREG8(&pUartRegs->FCR, UART_FCR_FIFO_EN);
// Pool
OUTREG8(&pUartRegs->IER, 0);
// Set DTR/RTS signals
OUTREG8(&pUartRegs->MCR, UART_MCR_DTR|UART_MCR_RTS);
// Configuration complete so select UART 16x mode
OUTREG8(&pUartRegs->MDR1, UART_MDR1_UART16);
return TRUE;
}
//------------------------------------------------------------------------------
//
// Function: OEMDebugDeinit
//
// Close debug serial port
//
VOID OEMDebugDeinit()
{
OMAP3_UART_REGS *pUartRegs = (OMAP3_UART_REGS *)DEBUG_UART_REGS_PA;
// Wait while FIFO isn't empty
while ((INREG8(&pUartRegs->LSR) & UART_LSR_TX_FIFO_E) == 0);
}
//------------------------------------------------------------------------------
//
// Function: OEMWriteDebugByte
//
// Write byte to debug serial port.
//
VOID OEMWriteDebugByte(UINT8 ch)
{
OMAP3_UART_REGS *pUartRegs = (OMAP3_UART_REGS *)DEBUG_UART_REGS_PA;
// Wait if FIFO is full
while ((INREG8(&pUartRegs->SSR) & UART_SSR_TX_FIFO_FULL) != 0);
// Send
OUTREG8(&pUartRegs->THR, ch);
}
//------------------------------------------------------------------------------
//
// Function: OEMReadDebugByte
//
// Input character/byte from debug serial port
//
INT OEMReadDebugByte()
{
OMAP3_UART_REGS *pUartRegs = (OMAP3_UART_REGS *)DEBUG_UART_REGS_PA;
UINT8 ch = OEM_DEBUG_READ_NODATA;
UINT8 status;
status = INREG8(&pUartRegs->LSR);
if ((status & UART_LSR_RX_FIFO_E) != 0) {
ch = INREG8(&pUartRegs->RHR);
if ((status & UART_LSR_RX_ERROR) != 0) ch = OEM_DEBUG_COM_ERROR;
}
return (INT)ch;
}
static BOOL g_debugLedState;
//------------------------------------------------------------------------------
//
// 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 = (OMAP3_GPIO_REGS *)OMAP3_GPIO5_REGS_PA;
if (data == DEBUG_LED_TOGGLE)
{ // toggle
if (TRUE == g_debugLedState)
{
OUTREG32(&pGPIO5Regs->ulGPIO_CLEARDATAOUT, DEBUG_LED_GPIO5);
g_debugLedState = FALSE;
}
else
{
OUTREG32(&pGPIO5Regs->ulGPIO_SETDATAOUT, DEBUG_LED_GPIO5);
g_debugLedState = TRUE;
}
}
else
{ // ON or OFF
data ? (OUTREG32(&pGPIO5Regs->ulGPIO_SETDATAOUT, DEBUG_LED_GPIO5)) : (OUTREG32(&pGPIO5Regs->ulGPIO_CLEARDATAOUT, DEBUG_LED_GPIO5));
data ? (g_debugLedState = TRUE) : (g_debugLedState = FALSE);
}
}
//------------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -