📄 debug.c
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
//------------------------------------------------------------------------------
//
// File: debug.c
//
// This module is provides the interface to the serial port.
//
#include <bsp.h>
#include <nkintr.h>
#define UART1BaudRate 115200
#if (SIR || FAST_IR)
#define S3C24A0_BASE_REG_PA_UART S3C24A0_BASE_REG_PA_UART0
#else
#define S3C24A0_BASE_REG_PA_UART S3C24A0_BASE_REG_PA_UART1
#endif
//------------------------------------------------------------------------------
// Defines
//------------------------------------------------------------------------------
// Externs
//------------------------------------------------------------------------------
// Global Variables
//------------------------------------------------------------------------------
// Local Variables
static volatile S3C24A0_UART_REG *g_pUARTReg;
//------------------------------------------------------------------------------
// Local Functions
//------------------------------------------------------------------------------
//
// Function: OEMInitDebugSerial
//
// Initializes the debug serial port
//
VOID OEMInitDebugSerial()
{
volatile S3C24A0_IOPORT_REG *pIOPortReg;
UINT32 logMask;
// At this moment we must suppress logging.
//
logMask = g_oalLogMask;
g_oalLogMask = 0x0;
// Configure port H for UART1.
//
pIOPortReg = (S3C24A0_IOPORT_REG*)OALPAtoVA(S3C24A0_BASE_REG_PA_IOPORT, FALSE);
// Configure port for UART1.
//
#if (S3C24A0_BASE_REG_PA_UART==S3C24A0_BASE_REG_PA_UART1)
pIOPortReg->GPCON_U &= ~((3 << 24)|(3 << 22)); // Configure GP31 and GP30 for UART1 Tx and Rx, respectively.
pIOPortReg->GPCON_U |= ((2 << 24)|(2 << 22)); //
pIOPortReg->GPCON_U &= ~((3 << 20)|(3 << 18)); // Configure GP29 and GP28 for UART1 Tx and Rx, respectively.
pIOPortReg->GPCON_U |= ((2 << 20)|(2 << 18)); //
pIOPortReg->GPPU |= (1 << 31)|(1 << 30); // Disable pull-up on TXD1 and RXD1.
//RETAILMSG(TRUE, (TEXT("debug.c::gpio\r\n")));
#endif
//RETAILMSG(TRUE, (TEXT("debug.c::above line didn't execute\r\n")));
// UART1 (TXD1 & RXD1) used for debug serial.
//
g_pUARTReg = (S3C24A0_UART_REG *)OALPAtoVA(S3C24A0_BASE_REG_PA_UART, FALSE);
// g_pUARTReg = (S3C24A0_UART_REG *)OALPAtoVA(S3C24A0_BASE_REG_PA_UART0, FALSE);
// Configure UART1.
//
g_pUARTReg->UFCON = 0x0; // Disable the FIFO (TODO: do we need to enable the FIFO?)
g_pUARTReg->UMCON = 0x0; // Disable AFC.
g_pUARTReg->ULCON = 0x3; // Normal mode, N81.
g_pUARTReg->UCON = 0x245; // Rx pulse interrupt, Tx level interrupt, Rx error status interrupt enabled.
g_pUARTReg->UBRDIV = ( (int)(S3C24A0_PCLK / 16.0 / UART1BaudRate + 0.5) - 1 ); // Set up baudrate.
// Restore the logging mask.
//
g_oalLogMask = logMask;
}
//------------------------------------------------------------------------------
//
// Function: OEMWriteDebugByte
//
// Transmits a character out the debug serial port.
//
VOID OEMWriteDebugByte(UINT8 ch)
{
// Wait for transmit buffer to be empty
while ((g_pUARTReg->UTRSTAT & 0x02) == 0);
// Send character
g_pUARTReg->UTXH = 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 status, ch;
status = g_pUARTReg->UTRSTAT;
if ((status & 0x01) != 0) {
ch = g_pUARTReg->URXH;
// if ((status & UART_LINESTAT_RF) != 0) ch = OEM_DEBUG_COM_ERROR;
} else {
ch = OEM_DEBUG_READ_NODATA;
}
return (int)ch;
}
/*
@func void | OEMWriteDebugLED | Writes specified pattern to debug LEDs 1-4.
@rdesc None.
@comm
@xref
*/
void OEMWriteDebugLED(UINT16 Index, DWORD Pattern)
{
//volatile S3C24A0_IOPORT_REG *s24A0IOP = (S3C24A0_IOPORT_REG *)OALPAtoVA(S3C24A0_BASE_REG_PA_IOPORT, FALSE);
//volatile S3C24A0_IOPORT_REG *s24A0IOP = (S3C24A0_IOPORT_REG *)0x91300000;
// The S24x0X01 Eval platform supports 4 LEDs..
//
//s24A0IOP->GPDAT=(s24A0IOP->GPDAT & 0xf) | ((Pattern & 0xf)<<4);
}
//------------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -