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

📄 debug.c

📁 freescale i.mx31 BSP CE5.0全部源码
💻 C
📖 第 1 页 / 共 2 页
字号:
//-----------------------------------------------------------------------------
//
// 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.
//
//-----------------------------------------------------------------------------
//
//  Copyright (C) 2004, Freescale Semiconductor, Inc. All Rights Reserved
//  THIS SOURCE CODE IS CONFIDENTIAL AND PROPRIETARY AND MAY NOT
//  BE USED OR DISTRIBUTED WITHOUT THE WRITTEN PERMISSION OF
//  FREESCALE SEMICONDUCTOR, INC.
//
//-----------------------------------------------------------------------------
//
//  File:  debug.c
//
//  This module is provides the interface to the serial port.
//
//-----------------------------------------------------------------------------
#include <bsp.h>
#include <nkintr.h>

#if (DEBUG_PORT == DBG_SC16C652_PORTA) || (DEBUG_PORT == DBG_SC16C652_PORTB)
#include "sc16c652.h"
#endif


//------------------------------------------------------------------------------
// Defines
#define DEBUG_SERIAL_ENABLE_IOMUX_PIN    DDK_IOMUX_PIN_DTR_DTE1
#define DEBUG_SERIAL_ENABLE_GPIO_PORT    DDK_GPIO_PORT2
#define DEBUG_SERIAL_ENABLE_GPIO_PIN       12


#define OEM_DEBUG_PIN_ENABLE                     1

#define MAX_DEBUG_GPIO_PIN_NUM                4

#define OEM_DEBUG_IOMUX_PIN0                     DDK_IOMUX_PIN_KEY_COL4
#define OEM_DEBUG_IOMUX_PIN1                     DDK_IOMUX_PIN_KEY_COL5
#define OEM_DEBUG_IOMUX_PIN2                     DDK_IOMUX_PIN_KEY_COL6
#define OEM_DEBUG_IOMUX_PIN3                     DDK_IOMUX_PIN_KEY_COL7

#define OEM_DEBUG_GPIO_PORT                       DDK_GPIO_PORT2
#define OEM_DEBUG_GPIO_PIN0                        22
#define OEM_DEBUG_GPIO_PIN1                        23
#define OEM_DEBUG_GPIO_PIN2                        24
#define OEM_DEBUG_GPIO_PIN3                        25

//------------------------------------------------------------------------------
// Externs

//------------------------------------------------------------------------------
// Global Variables
UINT16 g_PBCversion;
PCSP_PBC_REGS g_pPBC;
PCSP_IOMUX_REGS g_pIOMUX;
UINT32 g_oalPerClkFreq;
PCSP_CCM_REGS g_pCCM;

//------------------------------------------------------------------------------
// Local Variables
static PCSP_UART_REG g_pUART;

#if (DEBUG_PORT == DBG_SC16C652_PORTA) || (DEBUG_PORT == DBG_SC16C652_PORTB)
static PBSP_SC16C652_REGS g_pExtUART;
#endif

static PCSP_GPIO_REGS   g_pGPIO2;

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

#if OEM_DEBUG_PIN_ENABLE
//------------------------------------------------------------------------------
//
//  Function:        OEMInitDebugPin
//
//  This function init GPIO Debug pin
//
//  Parameters:
//
//  Returns:
//             none
//------------------------------------------------------------------------------
void OEMInitDebugPin(void)
{
    OAL_IOMUX_SET_MUX(g_pIOMUX, OEM_DEBUG_IOMUX_PIN0, DDK_IOMUX_OUT_GPIO, DDK_IOMUX_IN_GPIO);
    OAL_IOMUX_SET_MUX(g_pIOMUX, OEM_DEBUG_IOMUX_PIN1, DDK_IOMUX_OUT_GPIO, DDK_IOMUX_IN_GPIO);
    OAL_IOMUX_SET_MUX(g_pIOMUX, OEM_DEBUG_IOMUX_PIN2, DDK_IOMUX_OUT_GPIO, DDK_IOMUX_IN_GPIO);
    OAL_IOMUX_SET_MUX(g_pIOMUX, OEM_DEBUG_IOMUX_PIN3, DDK_IOMUX_OUT_GPIO, DDK_IOMUX_IN_GPIO);

    // output & low
    OUTREG32(&g_pGPIO2->GDIR, (INREG32(&g_pGPIO2->GDIR) | (1 << OEM_DEBUG_GPIO_PIN0)));
    OUTREG32(&g_pGPIO2->DR, (INREG32(&g_pGPIO2->DR) & ~(1 << OEM_DEBUG_GPIO_PIN0)));

    OUTREG32(&g_pGPIO2->GDIR, (INREG32(&g_pGPIO2->GDIR) | (1 << OEM_DEBUG_GPIO_PIN1)));
    OUTREG32(&g_pGPIO2->DR, (INREG32(&g_pGPIO2->DR) & ~(1 << OEM_DEBUG_GPIO_PIN1)));

    OUTREG32(&g_pGPIO2->GDIR, (INREG32(&g_pGPIO2->GDIR) | (1 << OEM_DEBUG_GPIO_PIN2)));
    OUTREG32(&g_pGPIO2->DR, (INREG32(&g_pGPIO2->DR) & ~(1 << OEM_DEBUG_GPIO_PIN2)));

    OUTREG32(&g_pGPIO2->GDIR, (INREG32(&g_pGPIO2->GDIR) | (1 << OEM_DEBUG_GPIO_PIN3)));
    OUTREG32(&g_pGPIO2->DR, (INREG32(&g_pGPIO2->DR) & ~(1 << OEM_DEBUG_GPIO_PIN3)));

}

//------------------------------------------------------------------------------
//
//  Function:        OEMWriteDebugPin
//
//  This function write GPIO Debug pin
//
//  Parameters:
//            index    Debug pin index 
//            data     Debug pin data
//  Returns:
//             none
//------------------------------------------------------------------------------

void OEMWriteDebugPin(UINT32 index,  UINT32 data)
{
    UINT32 pin;

    if(index >= MAX_DEBUG_GPIO_PIN_NUM){
        return;
    }

    pin = OEM_DEBUG_GPIO_PIN0 + index;
    OUTREG32(&g_pGPIO2->DR, (INREG32(&g_pGPIO2->DR) & ~(1 << pin) | ((data & 1) << pin)));
}

//------------------------------------------------------------------------------
//
//  Function:        OEMWriteDebugPin
//
//  This function toggle GPIO Debug pin
//
//  Parameters:
//            index    Debug pin index 
//  Returns:
//             none
//------------------------------------------------------------------------------

void OEMToggleDebugPin(UINT32 index)
{
    UINT32 pin;

    if(index >= MAX_DEBUG_GPIO_PIN_NUM){
        return;
    }

    pin = OEM_DEBUG_GPIO_PIN0 + index;

    OUTREG32(&g_pGPIO2->DR, (INREG32(&g_pGPIO2->DR) ^ (1 << pin)));
}

#endif 
//------------------------------------------------------------------------------
//
//  Function:        OEMRemapPBC
//
//  This function remap PBC memory space into last 1M in DDR memory
//    the debug transport over UART.
//
//  Parameters:
//
//  Returns:
//             none
//------------------------------------------------------------------------------
void OEMRemapPBC(void)
{
    OAL_ADDRESS_TABLE *pTable = g_oalAddressTable;

    int i;

    i = 0; 
    while(g_oalAddressTable[i].CA){
        if(g_oalAddressTable[i].PA == CSP_BASE_MEM_PA_CS4){
            g_oalAddressTable[i].CA = 0x8FF00000;
            g_oalAddressTable[i].size = 1;
            break;
        }
        i++;
    }    
}

//------------------------------------------------------------------------------
//
//  Function: OEMInitDebugSerial
//
//  Initializes the debug serial port
//
//------------------------------------------------------------------------------
VOID OEMInitDebugSerial()
{
#if DEBUG_PORT == DBG_UART1
    UINT32 refClkFreq;
#endif

    //zhongtao@
    OEMRemapPBC();
    //zhongtao#

    
    // Disable all OAL log zones until serial debug properly configured
    OALLogSetZones(0);

    g_pPBC = (PCSP_PBC_REGS) OALPAtoUA(BSP_BASE_REG_PA_PBC_BASE);
    if (g_pPBC == NULL)
    {
        return;
    }

    g_pIOMUX = (PCSP_IOMUX_REGS) OALPAtoUA(CSP_BASE_REG_PA_IOMUXC);
    if (g_pIOMUX == NULL)
    {
        return;
    }

    g_pCCM = (PCSP_CCM_REGS) OALPAtoUA(CSP_BASE_REG_PA_CCM);
    if (g_pCCM == NULL)
    {
        return;
    }

    g_pGPIO2 = (PCSP_GPIO_REGS) OALPAtoUA(CSP_BASE_REG_PA_GPIO2);
    if (g_pGPIO2 == NULL)
    {
        return;
    }

    //zhongtao@
#if OEM_DEBUG_PIN_ENABLE    
    OEMInitDebugPin();
#endif
    //zhongtao#

#if DEBUG_PORT == DBG_UART1

    g_pUART = (PCSP_UART_REG) OALPAtoUA(CSP_BASE_REG_PA_UART1);
    if (g_pUART == NULL)
    {
        return;
    }

    // Configure IOMUX for UART1
    OAL_IOMUX_SET_MUX(g_pIOMUX, DDK_IOMUX_PIN_RXD1, DDK_IOMUX_OUT_FUNC, DDK_IOMUX_IN_FUNC);
    OAL_IOMUX_SET_MUX(g_pIOMUX, DDK_IOMUX_PIN_TXD1, DDK_IOMUX_OUT_FUNC, DDK_IOMUX_IN_FUNC);
    OAL_IOMUX_SET_MUX(g_pIOMUX, DDK_IOMUX_PIN_RTS1, DDK_IOMUX_OUT_FUNC, DDK_IOMUX_IN_FUNC);

⌨️ 快捷键说明

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