⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 debug.c

📁 CIRRUS 93XX系列windows mobile 6.0 BSP
💻 C
字号:
//**********************************************************************
//                                                                      
// Filename: debug.c
//                                                                      
// Description: OEM Debug Serial Monitor Routines
//
// 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.
//
// Use of this source code is subject to the terms of the Cirrus 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 
// EULA.RTF on your install media.
//
// Copyright(c) Cirrus Logic Corporation 2005, All Rights Reserved                       
//                                                                      
//**********************************************************************

#include <windows.h>
#include <nkintr.h>
#include <halether.h>
#include <drv_glob.h>
#include <mdppfs.h>
#include "ethdbg.h"
#include <hwdefs.h>
#include <options.h>
#include <clocks.h>

#ifndef DEBUG_UART_PORT
#define DEBUG_UART_PORT     3
#endif // DEBUG_UART_PORT

static DWORD g_dwDebugPort=DEBUG_UART_PORT;
static DWORD dwUARTBase=UART1_BASE;

#ifndef DEBUG_UART_SPEED
#define DEBUG_UART_SPEED        38400    
#endif // DEBUG_UART_SPEED



#define UART_DR                ((volatile ULONG *)(dwUARTBase + 0x00))
#define UART_SR                ((volatile ULONG *)(dwUARTBase + 0x04))
#define UART_LCR_H             ((volatile ULONG *)(dwUARTBase + 0x08))
#define UART_LCR_M             ((volatile ULONG *)(dwUARTBase + 0x0C))
#define UART_LCR_L             ((volatile ULONG *)(dwUARTBase + 0x10))
#define UART_CR                ((volatile ULONG *)(dwUARTBase + 0x14))
#define UART_FR                ((volatile ULONG *)(dwUARTBase + 0x18))
#define UART_IIR               ((volatile ULONG *)(dwUARTBase + 0x1C))
#define UART_ILPR              ((volatile ULONG *)(dwUARTBase + 0x20))
#define UART_MCR               ((volatile ULONG *)(dwUARTBase + 0x100))
#define UART_MCS               ((volatile ULONG *)(dwUARTBase + 0x104))


unsigned int giSerialInitialized=0;
#define SERIAL_INITIALIZED_CHECK     0x12345678

//****************************************************************************
// OEMWriteDebugLED
//****************************************************************************
// 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)
{
    if (wIndex == 0)
    {
        *GPIO_PEDR  = (dwPattern & (GPIOE_RLED | GPIOE_GLED)) |
                      (*GPIO_PEDR & ~(GPIOE_RLED | GPIOE_GLED)) ;
    }        
}

//****************************************************************************
// UART_Stop
//****************************************************************************
// Stop UART 1.
// 
void UART_Stop(void)
{
    //
    // Disable this uart
    //
    *UART_CR    = 0;   

    *UART_LCR_H = 0;
    *UART_LCR_M = 0;
    *UART_LCR_L = 0;
    //
    // Clear status bits.
    //
    *UART_SR = 0;        
    return;
}


//****************************************************************************
// UART_Start
//****************************************************************************
// Start uart1.
// 
void UART_Start(void)
{
    UART_Stop();

    // Set up default baudrate
    //
   *UART_LCR_M = 0 ;                
   *UART_LCR_L = UART_DIVISOR(DEBUG_UART_SPEED); 
    //
    // Setup mode 8 bits, no parity, 1 stop bit, fifo enabled.
    //
    *UART_LCR_H = LCR_H_DATABITS_8 | LCR_H_FIFO_ENABLE;
    
    // Clear old status.
    *UART_SR  = 0;

    //*UART_MCR  = MCR_RTS | MCR_DTR;

    *UART_IIR = 0;
    //
    // enable this uart
    //
    *UART_CR |= CR_UARTE; 

    return;
}//end uart_start
//****************************************************************************
// UART_Write
//****************************************************************************
//
void UART_Write(UCHAR ch) 
{
	int i;
    //
    // txfe  see if the tx fifo is empty
    //
	for( i=0; i< 10000; i++ ){

		if((*UART_FR & FR_TXFE) == FR_TXFE){

		    *UART_DR = (int)ch;
			break;
		}
	}
}

//****************************************************************************
// UART_Read
//****************************************************************************
// Routine to Read Uart 1.
// 
//
int UART_Read(void)
{
    int     nReadChar;
    ULONG   ulFlagRegister; 
    ULONG   ulStatusRegister;

    ulFlagRegister      = *UART_FR;
    ulStatusRegister    = *UART_SR;
    
    if(ulStatusRegister & SR_OE)
    {
        nReadChar = OEM_DEBUG_COM_ERROR;
    }
    else if(!(ulFlagRegister & FR_RXFE))
    {
        nReadChar = (*UART_DR & 0xFF);
    }
    else
    {
        nReadChar = OEM_DEBUG_READ_NODATA;
    }
    
    return nReadChar;
}
//****************************************************************************
// UART_ClearError
//****************************************************************************
// Clears errors for UART1.
// 
//
void UART_ClearError()
{
    //
    // Partial stop and disable this uart
    //
    *UART_CR  = 0;   
    //
    // Clear status bits.
    //
    *UART_SR  = 0;        
    //
    // partial startup,clr interrupts
    //
    *UART_IIR = 0;        
    //
    // enable this uart
    //
    *UART_CR = CR_UARTE; 
}    


void OEMInitDebugSerial(void) 
{
	switch( g_dwDebugPort ) {
		case 1:
			dwUARTBase=UART1_BASE;
			break;
		case 2:
			dwUARTBase=UART2_BASE;
			break;
		case 3:
			dwUARTBase=UART3_BASE;
			break;
		default:
			dwUARTBase=UART3_BASE;
			g_dwDebugPort=0;
			break;
	}
    if(g_dwDebugPort && giSerialInitialized !=SERIAL_INITIALIZED_CHECK)
    {
        UART_Start();
        giSerialInitialized = SERIAL_INITIALIZED_CHECK;
    }
}

//****************************************************************************
// OEMWriteDebugString
//****************************************************************************
// Display string to the monitor port.
// 
// 
void OEMWriteDebugString(unsigned short *str) 
{
	if( g_dwDebugPort )
		while ( *str ){

			OEMWriteDebugByte((unsigned char)*str++);
		}        
}

//****************************************************************************
// OEMWriteDebugByte
//****************************************************************************
// Parameters:  unsigned char 
//              Points to the output Character.
//
void OEMWriteDebugByte(UCHAR ch) 
{
	if( g_dwDebugPort )
		UART_Write(ch);
}


//****************************************************************************
// OEMReadDebugByte
//****************************************************************************
//  Returns the following:
//     OEM_DEBUG_COM_ERROR        Error detected
//     OEM_DEBUG_READ_NODATA      No data is available at the port.
//     ch                         If data is available.
//

int
OEMReadDebugByte() 
{
	if( g_dwDebugPort )
	   return(UART_Read());
	else
		return OEM_DEBUG_READ_NODATA;
}



//****************************************************************************
// OEMClearDebugCommError
//****************************************************************************
// Resets the UART to clear any Uart errors out.
// 
void OEMClearDebugCommError(void) 
{
	if( g_dwDebugPort )
		UART_ClearError();
}


//****************************************************************************
// OEMUartStop
//****************************************************************************
// Stops the UART port.
// 
void OEMUartStop(void) 
{
	if( g_dwDebugPort )
		UART_Stop();

    giSerialInitialized = 0;
}




BOOL DebugPortRedirection( DWORD dwPort )
{
	if( dwPort != g_dwDebugPort ) {
		if( dwPort >=1 && dwPort <=3 ){

			g_dwDebugPort=dwPort;
			RETAILMSG(1,(L" DebugPort will be Redirect to UART %d\r\n", dwPort-1));

			UART_Stop( );
			UART_Start( );
			giSerialInitialized = 0;
			OEMInitDebugSerial ( );
			return TRUE;
		}
		return FALSE;
	}
	return TRUE;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -