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

📄 dbgserial.c

📁 Windows CE 6.0 BSP for VOIPAC Board (PXA270) Version 2b.
💻 C
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES.
//
//------------------------------------------------------------------------------
//
//  File:  dbgserial.c            
//
//  This module is provides the interface to the serial port.
//
#include <bsp.h>
#include <nkintr.h>
#include <dbgserial.h>
 
//------------------------------------------------------------------------------
// Defines 
//
#define DEBUG_BAUD_38400      0x00000018
 
//------------------------------------------------------------------------------
// Externs
//
 
//------------------------------------------------------------------------------
// Global Variables 
 
//------------------------------------------------------------------------------
// Local Variables 
//
static volatile BULVERDE_UART_REG    *g_pDebugUARTPort = NULL;
//static volatile MAINSTONEII_BLR_REGS *g_pBLRegs        = NULL;

//------------------------------------------------------------------------------
// Local Functions 
//


//------------------------------------------------------------------------------
//
//  Function: OEMInitDebugSerial
//
//  Initializes the debug serial port
//

VOID InitDebugSerial(UINT32 DbgSerPhysAddr, BOOL bUsePhysAddresses) 
{
    UINT32 logMask = 0;
    volatile BULVERDE_GPIO_REG *pGPIO_REGS = NULL;
    volatile BULVERDE_CLKMGR_REG *pCLKMGR_REGS = NULL;

#ifdef DEBUG
    // At this moment we must suppress logging.
    //
    logMask = dpCurSettings.ulZoneMask;
    dpCurSettings.ulZoneMask = 0;
#endif

    // Use physical addresses to initialize the serial port?
    //
    if (bUsePhysAddresses)
    {
        // Yes.
        //
        g_pDebugUARTPort = (volatile BULVERDE_UART_REG *)   DbgSerPhysAddr;
        pGPIO_REGS       = (volatile BULVERDE_GPIO_REG *)   BULVERDE_BASE_REG_PA_GPIO;
        pCLKMGR_REGS     = (volatile BULVERDE_CLKMGR_REG *) BULVERDE_BASE_REG_PA_CLKMGR;

        // Map the Mainstone board-level registers which are used in the OEMWriteDebugLED routine.
        //
//        g_pBLRegs = (volatile MAINSTONEII_BLR_REGS *) MAINSTONEII_BASE_REG_PA_FPGA;
    }
    else
    {
        // No - get virtual addresses.
        //
        g_pDebugUARTPort = (volatile BULVERDE_UART_REG *) OALPAtoVA(DbgSerPhysAddr, FALSE);
        pGPIO_REGS       = (volatile BULVERDE_GPIO_REG *) OALPAtoVA(BULVERDE_BASE_REG_PA_GPIO, FALSE);
        pCLKMGR_REGS     = (volatile BULVERDE_CLKMGR_REG *) OALPAtoVA(BULVERDE_BASE_REG_PA_CLKMGR, FALSE);

        // Map the Mainstone board-level registers which are used in the OEMWriteDebugLED routine.
        //
//        g_pBLRegs = (volatile MAINSTONEII_BLR_REGS *) OALPAtoVA(MAINSTONEII_BASE_REG_PA_FPGA, FALSE);
    }

    // Ensure that UART interrupts are turned off.
    //
    g_pDebugUARTPort->lcr     = 0x0;    // Clear DLAB.
    g_pDebugUARTPort->ier_dlh = 0x0;    // IER_DLH = 0x0.

    // Set the Baud Rate (Divisor low = DEBUG_BAUD_38400).
    // The divisor latches are at offsets 0 and 1, which are 
    // receive/transmit data and ier registers.
    //
    g_pDebugUARTPort->lcr         = 0x80;                // Access Divisor.
    g_pDebugUARTPort->thr_rbr_dll = DEBUG_BAUD_38400;    // Low byte divisor.
    g_pDebugUARTPort->ier_dlh     = 0x00;                // High byte divisor.
    g_pDebugUARTPort->lcr         = 0x0;                 // Clear DLAB.

    //Setting UART properties to 8N1 
    //
    g_pDebugUARTPort->lcr         = 0x3;     // 8 bits, 1 stop, no parity. Also LCR DLAB bit = 0.

    g_pDebugUARTPort->iir_fcr     = 0x01;    // Enable the FIFO.
    g_pDebugUARTPort->iir_fcr     = 0x07;    // Clear Rx,Tx FIFOs.

    // Don't enable UART interrupts - we'll poll for the data.
    //
    g_pDebugUARTPort->ier_dlh     = 0x0;  

    // Ensure loop-back test mode is off even though MCR reset value is 0x0. 
    //
    g_pDebugUARTPort->mcr         = 0x0;    // UART is in normal mode.

    // Configure GPIO pins for FFUART
    //
    if (DbgSerPhysAddr == BULVERDE_BASE_REG_PA_FFUART)
    {
/*
        // 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 );
*/
        // Enable the FFUART clock.
        //
        pCLKMGR_REGS->cken |= XLLP_CLKEN_FFUART ;

    }
    else if (DbgSerPhysAddr == BULVERDE_BASE_REG_PA_BTUART)
    {
/*
        // Initialize GPIO pins.
	    // Write 0 on GPIO pins 43 and 45 before configuring them as outputs.
        //
	    pGPIO_REGS->GPCR1 = (XLLP_GPIO_BIT_BTTXD | XLLP_GPIO_BIT_BTRTS);

	    // Configure direction of GPIO pins 42 and 44 as input 
	    // and GPIO pins 43 and 45 as output.
        //
	    pGPIO_REGS->GPDR1 &= ~( XLLP_GPIO_BIT_BTRXD | XLLP_GPIO_BIT_BTCTS); 
	    pGPIO_REGS->GPDR1 |=  ( XLLP_GPIO_BIT_BTTXD | XLLP_GPIO_BIT_BTRTS);

	    // Configure GPIO pins 42 and 44 for Alt_fn1. And pins 43 and 45 for Alt_fn2.
        //
	    pGPIO_REGS->GAFR1_L |= ( XLLP_GPIO_AF_BIT_BTRXD | XLLP_GPIO_AF_BIT_BTCTS |
                                 XLLP_GPIO_AF_BIT_BTTXD | XLLP_GPIO_AF_BIT_BTRTS );
*/
        // Turn on the BTUART transceiver.
        //
//        g_pBLRegs->misc_wr |= nBT_OFF_MASK; 


        // Enable the BTUART clock.
        //
        pCLKMGR_REGS->cken |= XLLP_CLKEN_BTUART ;

    }

    // Enable the UART.
    //
    g_pDebugUARTPort->ier_dlh = 0x40;

#ifdef DEBUG
    // Restore the logging mask.
    //
    dpCurSettings.ulZoneMask = logMask;
#endif

}


//------------------------------------------------------------------------------
//
//  Function: OEMWriteDebugByte
//
//  Transmits a character out the debug serial port.
//
VOID OEMWriteDebugByte(UINT8 ch) 
{

    if (!g_pDebugUARTPort)
    {
        return;
    }

    // Spin if FIFO has more than half data.
    //
    while(!(g_pDebugUARTPort->lsr & 0x020));

    // Write a character byte to the FIFO.
    //
    g_pDebugUARTPort->thr_rbr_dll = (unsigned char)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 data = OEM_DEBUG_READ_NODATA;
    UINT32 LSR;

    if (!g_pDebugUARTPort)
    {
        return(data);
    }

    // Read LSR.
    //
    LSR = g_pDebugUARTPort->lsr;

    // Return if no data.
    //
    if(!(LSR & 0x1))
    {
        return(data);
    }

    // Read data.
    //
    data = g_pDebugUARTPort->thr_rbr_dll;

    // Signal error if PE or FE was set.
    // Do nothing if BI or OE was set.
    //
    if(LSR & 0x0c)
    {
        data = OEM_DEBUG_COM_ERROR;
    }

    return(data);

}


//------------------------------------------------------------------------------
//
//  Function: OEMWriteDebugLED
//
//  Writes a pattern to the on-board hex LEDs.
//
void OEMWriteDebugLED(UINT16 Index, DWORD Pattern)
{

/*    if (g_pBLRegs)
    {
        g_pBLRegs->hex_led = Pattern;
    }*/

}


//------------------------------------------------------------------------------
//
//  Function: OEMClearDebugCommError
//
//  Clears communications errors (flushes the serial FIFO).
//
void OEMClearDebugCommError(void) 
{
    while(OEMReadDebugByte() == OEM_DEBUG_COM_ERROR);
}

//------------------------------------------------------------------------------

⌨️ 快捷键说明

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