📄 debug.c
字号:
/*++
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.
Copyright (c) 1995, 1996, 1997 Microsoft Corporation
*/
/*
** INTEL CONFIDENTIAL
** Copyright 2000-2003 Intel Corporation All Rights Reserved.
**
** The source code contained or described herein and all documents
** related to the source code (Material) are owned by Intel Corporation
** or its suppliers or licensors. Title to the Material remains with
** Intel Corporation or its suppliers and licensors. The Material contains
** trade secrets and proprietary and confidential information of Intel
** or its suppliers and licensors. The Material is protected by worldwide
** copyright and trade secret laws and treaty provisions. No part of the
** Material may be used, copied, reproduced, modified, published, uploaded,
** posted, transmitted, distributed, or disclosed in any way without Intel抯
** prior express written permission.
**
** No license under any patent, copyright, trade secret or other intellectual
** property right is granted to or conferred upon you by disclosure or
** delivery of the Materials, either expressly, by implication, inducement,
** estoppel or otherwise. Any license under such intellectual property rights
** must be express and approved by Intel in writing.
*/
/*
Module Name:
Abstract:
Functions:
Notes:
--*/
/*****************************************************************************
*
* @doc EXTERNAL OEM
*
* @module debug.c | OEM Debug Serial Monitor Routines
*
******************************************************************************/
#include <windows.h>
#include "nkintr.h"
#include "drv_glob.h"
#include "halether.h"
#include "ethdbg.h"
#include "bvd1.h"
#include "bvd1bd.h"
// For converting net byte order to host byte order
#define htons( value ) ((UINT16)((((UINT16)value) << 8) | (((UINT16)((UINT16)value)) >> 8)))
#define ntohs( value ) htons( value )
#ifdef BSP_MAINSTONE
// For now, no config. Will re-address as needed.
//
#define DEBUG_PORT_ADDRESS (FFUART_BASE_U_VIRTUAL)
#define DEBUG_PORT_IRQ INTC_FFUART
//#define DEBUG_PORT_ADDRESS (BTUART_BASE_U_VIRTUAL) //hzh, use BTUART
//#define DEBUG_PORT_IRQ INTC_BTUART
#define DEBUG_OUT_STRING "OEMInitDebugSerial using UART1\r\n"
#else
#define DEBUG_PORT_ADDRESS (FFUART_BASE_U_VIRTUAL)
#define DEBUG_PORT_IRQ INTC_FFUART
#define DEBUG_OUT_STRING "OEMInitDebugSerial using UART1\r\n"
#endif
#define DEBUG_BAUD_38400 0x00000018
#define DEBUG_BAUD_115200 0x00000008 //hzh
#undef PRODUCT_SERIAL_ENABLED //hzh, use BTUART so needn't this
//To be used by OEMWriteDebugByte and OEMReadDebugByte
//
volatile GEN_UART *g_pDebugUartPort = (volatile GEN_UART *) DEBUG_PORT_ADDRESS;
//To be used by OEMWriteDebugLED
//Currently, setup for MAINSTONE only
//
#ifdef BSP_MAINSTONE
//volatile BLR_REGS *g_pBLReg = (volatile BLR_REGS *) FPGA_REGS_BASE_U_VIRTUAL; //commented by hzh
#endif
/*****************************************************************************
*
*
* @func void | OEMInitDebugSerial | Initialize debug monitor port.
* @helper func void | OEMInitDebugSerialKernel (void)
*
* NOTE: This function MUST NOT use any global variables!!!!!!
*/
void OEMInitDebugSerialKernel (void)
{
volatile GEN_UART *pDebugUartPort;
PDRIVER_GLOBALS pDriverGlobals;
volatile XLLP_GPIO_T *pGPIO_REGS;
static BOOL DebugEtherPresent;
pDriverGlobals = (PDRIVER_GLOBALS)DRIVER_GLOBALS_PHYSICAL_MEMORY_START;
pDebugUartPort=(volatile GEN_UART *)DEBUG_PORT_ADDRESS;
pGPIO_REGS = (volatile XLLP_GPIO_T *)GPIO_BASE_U_VIRTUAL;
//
// This UART initialization needs to be tested...
//
// Ensuring UART and interrupts are off before configuring
// even though LCR and IER reset values are 0x0.
//
pDebugUartPort->lcr = 0x0; // clearing DLAB
pDebugUartPort->ier_dlh = 0x0; // IER_DLH = 0x0
// Set the Baud Rate (Divisor low = DEBUG_BAUD_38400)
// Divisor latches are at offsets 0 and 1, which are
// receive/transmit data and ier registers.
//
pDebugUartPort->lcr = 0x80; // Access Divisor
pDebugUartPort->thr_rbr_dll = DEBUG_BAUD_115200;// low byte divisor, hzh use 115200
pDebugUartPort->ier_dlh = 0x00; // high byte divisor
pDebugUartPort->lcr = 0x0; // clearing DLAB
//Setting UART properties to 8N1
//
pDebugUartPort->lcr = 0x3; // 8 bits, 1 stop, no parity. Also LCR DLAB bit = 0
pDebugUartPort->iir_fcr=0x01; // Enable FIFO
pDebugUartPort->iir_fcr=0x07; // Clear Rx,Tx FIFOs
// Don't enable UART, place in polled mode
// UART is not enabled till GPIO pins are configured also.
// We don't have to configure INTC_REGS to use IRQ and enable interrupt
// as UART is used in polling mode only.
//
pDebugUartPort->ier_dlh = 0x0;
//Ensuring loop back test mode is off
//even though MCR reset value is 0x0.
//
pDebugUartPort->mcr = 0x0; //UART is in normal mode.
// Configuring GPIO pins for FFUART
//
if(DEBUG_PORT_ADDRESS == FFUART_BASE_U_VIRTUAL)
{
// Initialize GPIO pins
// Write 0 on GPIO pins 39, 40 and 41 before configuring them as outputs.
//
pGPIO_REGS->GPCR1 = ( XLLP_GPIO_BIT_FFDTR | XLLP_GPIO_BIT_FFTXD |
XLLP_GPIO_BIT_FFRTS );
// Configure direction of GPIO pins 34, 35, 36, 37 and 38 as input
// and GPIO pins 39, 40 and 41 as output
//
pGPIO_REGS->GPDR1 &= ~( XLLP_GPIO_BIT_FFRXD | XLLP_GPIO_BIT_FFCTS |
XLLP_GPIO_BIT_FFDCD | XLLP_GPIO_BIT_FFDSR |
XLLP_GPIO_BIT_FFRI );
pGPIO_REGS->GPDR1 |= ( XLLP_GPIO_BIT_FFTXD | XLLP_GPIO_BIT_FFDTR |
XLLP_GPIO_BIT_FFRTS );
// Configure GPIO pins 34, 35, 36, 37 and 38 for Alt_fn1. And pins 39, 40 and 41 for Alt_fn2.
//
pGPIO_REGS->GAFR1_L |= ( XLLP_GPIO_AF_BIT_FFRXD | XLLP_GPIO_AF_BIT_FFCTS |
XLLP_GPIO_AF_BIT_FFDCD | XLLP_GPIO_AF_BIT_FFDSR |
XLLP_GPIO_AF_BIT_FFRI | XLLP_GPIO_AF_BIT_FFTXD |
XLLP_GPIO_AF_BIT_FFDTR | XLLP_GPIO_AF_BIT_FFRTS );
}
//UART is enabled here
//
pDebugUartPort->ier_dlh = 0x40; //Enabling UART
} // OEMInitDebugSerialKernel ()
void OEMInitDebugSerial(void)
{
#ifdef BSP_MAINSTONE
volatile BLR_REGS *v_pBLReg = (volatile BLR_REGS *) FPGA_REGS_BASE_U_VIRTUAL;
#endif
// WRITE_HEX_LEDS(0xDEBB1234);
// Do the real work. Separated out so that output is not forced on resume.
// We don't want to change state.
#ifdef SIMULATETHIS
OEMInitDebugSerialKernel (); // bman: since i do this in fw, skip for simulation.
#endif
OEMWriteDebugString(TEXT("\r\n"));
OEMWriteDebugString(TEXT("******************************************************\r\n"));
OEMWriteDebugString(TEXT("******************************************************\r\n"));
OEMWriteDebugString(TEXT("******************************************************\r\n"));
OEMWriteDebugString(TEXT("******************************************************\r\n"));
OEMWriteDebugString(TEXT("******************************************************\r\n"));
OEMWriteDebugString(TEXT(DEBUG_OUT_STRING));
} // OEMInitDebugSerial()
/*****************************************************************************
*
*
* @func void | OEMWriteDebug | Display value to specified LED port.
*
* The wIndex parameter can be used to specify a write to the discrete LEDS (if
* 0xffff), otherwise is used as an offset (DWORD aligned) for the Alpha LEDS
* for triggering.
*/
void
OEMWriteDebugLED(WORD wIndex, DWORD dwPattern)
{
#ifdef BSP_MAINSTONE
// g_pBLReg initialized to FPGA_REGS_BASE_U_VIRTUAL
// Ignoring wIndex for now
//g_pBLReg->hex_led = dwPattern; //commented by hzh
#endif
}
/*****************************************************************************
*
*
* @func void | OEMWriteDebugString | Display string to the monitor port.
*
* @parm unsigned short * | str |
* Points to the receiving buffer.
*/
void OEMWriteDebugString(unsigned short *str)
{
#ifdef PRODUCT_SERIAL_ENABLED
#else
// Send message to serial port
while(*str)
OEMWriteDebugByte((unsigned char)*str++);
#endif
}
/*****************************************************************************
*
*
* @func void | OEMWriteDebugByte | Output byte to the monitor port.
*
* @parm unsigned char *| str |
* Points to the output buffer.
*/
void OEMWriteDebugByte(unsigned char c)
{
#ifdef PRODUCT_SERIAL_ENABLED
#else
//Spin if FIFO has more than half data
while(!(g_pDebugUartPort->lsr & 0x020)); // tdrq : default method
g_pDebugUartPort->thr_rbr_dll=(unsigned char)c;
#endif
}
/*****************************************************************************
*
*
* @func int | OEMReadDebugByte | Get a byte from the monitor port.
*
* @rdesc Returns:
* OEM_DEBUG_COM_ERROR Error detected
* OEM_DEBUG_READ_NODATA No data is available at the port.
* ch If data is available.
*
*/
int OEMReadDebugByte()
{
#ifdef PRODUCT_SERIAL_ENABLED
return(OEM_DEBUG_COM_ERROR);
#else
int data;
ULONG LSR;
//OEMWriteDebugString(TEXT("*****OEMReadDebugByte Called by Someone\r\n"));
data = OEM_DEBUG_READ_NODATA;
LSR = 0x0; //Ignoring RESET value
//Read LSR
LSR = g_pDebugUartPort->lsr;
//Return if no data
if(!(LSR & 0x1))
return(data);
//Read data
data = g_pDebugUartPort->thr_rbr_dll;
//Signalling error if PE or FE was set
//Doing nothing, if BI or OE was set
if(LSR & 0x0c)
{
//Erroneous byte was read
data = OEM_DEBUG_COM_ERROR;
}
return(data);
#endif
}
/*****************************************************************************
*
*
* @func void | OEMClearDebugComError | Clear a debug communications error
*
*/
void OEMClearDebugCommError(void)
{
while(OEMReadDebugByte() == OEM_DEBUG_COM_ERROR);
}
/*****************************************************************************
*
*
* @func void | OsSpecificDebugCommsResume |
* - at end of OEMPowerOff, invoke this to re-init debug communications
*
*/
void OsSpecificDebugCommsResume(void)
{
#ifdef IMGKITL
#if (WINCEOSVER >= 400)
EDBG_ADAPTER Adapter;
#endif
#endif
OEMInitDebugSerialKernel ();
#ifdef IMGKITL
#if (WINCEOSVER >= 400)
memset (&Adapter, 0, sizeof(Adapter));
OEMEthInit(&Adapter);
#endif
#endif
} // OsSpecificDebugCommsResume()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -