📄 debug.c
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
/*
* The content of this file or document is CONFIDENTIAL and PROPRIETARY
* to Jade Technologies Co., Ltd. It is subjected to the terms of a
* License Agreement between Licensee and Jade Technologies Co., Ltd.
* restricting among other things, the use, reproduction, distribution
* and transfer. Each of the embodiments, including this information
* and any derivative work shall retain this copyright notice.
*
* Copyright (c) 2004 - 2005 Jade Technologies Co., Ltd.
* All rights reserved.
* ----------------------------------------------------------------
* File: debug.c,v
* Revision: 1.0
* ----------------------------------------------------------------
* $
*/
/*
* Some of the code here is duplicated elsewhere in the platform OAL code.
* This isn't ideal, but given that the OAL operates on virtual addresses and
* the eboot loader requires physical addresses, sharing the code is a bit
* messy.
*/
#include <windows.h>
#include <nkintr.h>
#include "win_plat.h"
#include "oalfuncs.h"
#include "PL011.h"
//#include "apcharlcd.h"
// Internal functions
//void apCHARLCD_Write(unsigned char dat, unsigned char rs);
/*
* @func void OEMInitDebugSerial - Initialize debug monitor port.
*
* NOTE: This function MUST NOT use any global variables!!!!!!
*/
void OEMInitDebugSerial(void)
{
ULONG value;
//close pin_multi/UART0
//GPIO4_0/1
WRITE_REGISTER_ULONG(0x2002B420, 0x0000000F);
/* First we disable the UART before changing its settings */
/* Read the current Control register value */
value = READ_REGISTER_ULONG(DEBUG_COMPORT + PL011_CR);
/* Disable the UART */
value = value & ~PL011_CR_UARTEN;
WRITE_REGISTER_ULONG(DEBUG_COMPORT + PL011_CR, value);
/* Set baud rate */
/* Write out integer baud part first */
WRITE_REGISTER_ULONG(DEBUG_COMPORT + PL011_IBRD, (ARMVPB_BAUD_38400 >> BAUD_BRDI_SHIFTRIGHT));
/* Now write out fractional baud part */
WRITE_REGISTER_ULONG(DEBUG_COMPORT + PL011_FBRD, (ARMVPB_BAUD_38400 & BAUD_BRDF_MASK));
/* set the UART to be 8 bits, 1 stop bit, no parity, fifo enabled */
value = PL011_LCR_H_WLEN_8 | PL011_LCR_H_FEN;
WRITE_REGISTER_ULONG(DEBUG_COMPORT + PL011_LCR_H, value);
/* Set the UART to no h/w flow control, transmit and receive enabled, assert RTS and DTR */
value = PL011_CR_RTS | PL011_CR_DTR | PL011_CR_RXE | PL011_CR_TXE;
WRITE_REGISTER_ULONG(DEBUG_COMPORT + PL011_CR, value);
/* Ensure all interrupts are masked off */
WRITE_REGISTER_ULONG(DEBUG_COMPORT + PL011_IMSC, 0);
/* All DMA configuration disabled */
WRITE_REGISTER_ULONG(DEBUG_COMPORT + PL011_DMACR, 0);
/* Clear any errors */
WRITE_REGISTER_ULONG(DEBUG_COMPORT + PL011_ECR, PL011_ECR_ALLERRORS);
/* Finally, enable the uart */
value = READ_REGISTER_ULONG(DEBUG_COMPORT + PL011_CR);
value = value | PL011_CR_UARTEN;
WRITE_REGISTER_ULONG(DEBUG_COMPORT + PL011_CR, value);
}
/*
* @func void OEMWriteDebugByte - Output byte to the monitor port.
*
* @parm unsigned char ch
* character to send
*/
void OEMWriteDebugByte(BYTE ch)
{
// Wait until the flag register indicates the UART has room for another character
while ((READ_REGISTER_ULONG(DEBUG_COMPORT + PL011_FR) & PL011_FR_TXFF) != 0)
{ ; }
WRITE_REGISTER_ULONG(DEBUG_COMPORT + PL011_DR, ch);
}
/*
* @func void OEMWriteDebugString - Display string to the monitor
* port.
*
* @parm unsigned short *str
* Points to the output buffer.
*/
void OEMWriteDebugString(unsigned short *str)
{
while (*str)
OEMWriteDebugByte((BYTE)*str++);
}
void ARMPutHex(long value);
/*
* @func int OEMReadDebugByte - Get a byte from the monitor port.
*
* @rdesc Returns:
* OEM_DEBUG_READ_NODATA No data is available at the port.
* OEM_DEBUG_COM_ERROR An error has been detected.
* ch If data is available.
*
*/
int OEMReadDebugByte(void)
{
ULONG ulReg;
/* Read the flag register to see if the FIFO is empty */
if ((READ_REGISTER_ULONG(DEBUG_COMPORT + PL011_FR) & PL011_FR_RXFE) != 0)
return OEM_DEBUG_READ_NODATA;
// Read the data register (mask off receive error bits)
ulReg = READ_REGISTER_ULONG(DEBUG_COMPORT + PL011_DR) & 0xFF;
/* Read receive status register to see if there is an error */
if ((READ_REGISTER_ULONG(DEBUG_COMPORT + PL011_RSR) & PL011_RSR_ALLERRORS) != 0)
return OEM_DEBUG_COM_ERROR;
return (int)ulReg;
}
/**********************************************************************/
void ARMInitSerial(void)
{
OEMInitDebugSerial();
}
void ARMWriteByte(unsigned char ch)
{
OEMWriteDebugByte(ch);
}
void ARMWriteString(unsigned char *str)
{
while (*str)
ARMWriteByte(*str++);
}
void ARMPutHex(long value)
{
unsigned char c;
int i;
ARMWriteByte('0');
ARMWriteByte('x');
for (i = 7; i >= 0; i--)
{
/* Strip next nibble */
c = (unsigned char)((value >> (i * 4)) & 0xf);
if ((c >= 0) && (c <= 9))
c = c + '0';
else
c = (c - 10) + 'a';
ARMWriteByte(c);
}
}
/* EOF debug.c */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -