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

📄 ddk_gpio.c

📁 freescale i.mx31 BSP CE5.0全部源码
💻 C
字号:
//------------------------------------------------------------------------------
//
//  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:  ddk_gpio.c
//
//  This file contains the SoC-specific DDK interface for the GPIO module.
//
//-----------------------------------------------------------------------------
#include <windows.h>
#include <ceddk.h>
#include "csp.h"

//-----------------------------------------------------------------------------
// External Functions


//-----------------------------------------------------------------------------
// External Variables


//-----------------------------------------------------------------------------
// Defines


//-----------------------------------------------------------------------------
// Types


//-----------------------------------------------------------------------------
// Global Variables


//-----------------------------------------------------------------------------
// Local Variables
PCSP_GPIO_REGS g_pGPIO[DDK_GPIO_PORT3+1];


//-----------------------------------------------------------------------------
// Local Functions
BOOL GpioAlloc(void);
BOOL GpioDealloc(void);


//-----------------------------------------------------------------------------
//
// Function:  GpioAlloc
//
// This function allocates the data structures required for interaction
// with the GPIO hardware.
//
// Parameters:
//      None.
//
// Returns:
//      Returns TRUE if successful, otherwise returns FALSE.
//
//-----------------------------------------------------------------------------
BOOL GpioAlloc(void)
{
    BOOL rc = FALSE;
    PHYSICAL_ADDRESS phyAddr;
         
    if (g_pGPIO[DDK_GPIO_PORT1] == NULL)
    {
        phyAddr.QuadPart = CSP_BASE_REG_PA_GPIO1;

        // Map peripheral physical address to virtual address
        g_pGPIO[DDK_GPIO_PORT1] = (PCSP_GPIO_REGS) MmMapIoSpace(phyAddr, sizeof(CSP_GPIO_REGS),
            FALSE);

        // Check if virtual mapping failed
        if (g_pGPIO[DDK_GPIO_PORT1] == NULL)
        {
            DBGCHK((_T("CSPDDK")),  FALSE);
            ERRORMSG(1, (_T("GpioAlloc:  MmMapIoSpace failed!\r\n")));
            goto cleanUp;
        }
    }

    if (g_pGPIO[DDK_GPIO_PORT2] == NULL)
    {
        phyAddr.QuadPart = CSP_BASE_REG_PA_GPIO2;

        // Map peripheral physical address to virtual address
        g_pGPIO[DDK_GPIO_PORT2] = (PCSP_GPIO_REGS) MmMapIoSpace(phyAddr, sizeof(CSP_GPIO_REGS),
            FALSE);

        // Check if virtual mapping failed
        if (g_pGPIO[DDK_GPIO_PORT2] == NULL)
        {
            DBGCHK((_T("CSPDDK")),  FALSE);
            ERRORMSG(1, (_T("GpioAlloc:  MmMapIoSpace failed!\r\n")));
            goto cleanUp;
        }
    }

    if (g_pGPIO[DDK_GPIO_PORT3] == NULL)
    {
        phyAddr.QuadPart = CSP_BASE_REG_PA_GPIO3;

        // Map peripheral physical address to virtual address
        g_pGPIO[DDK_GPIO_PORT3] = (PCSP_GPIO_REGS) MmMapIoSpace(phyAddr, sizeof(CSP_GPIO_REGS),
            FALSE);

        // Check if virtual mapping failed
        if (g_pGPIO[DDK_GPIO_PORT3] == NULL)
        {
            DBGCHK((_T("CSPDDK")),  FALSE);
            ERRORMSG(1, (_T("GpioAlloc:  MmMapIoSpace failed!\r\n")));
            goto cleanUp;
        }
    }

    rc = TRUE;
 
cleanUp:

    if (!rc) GpioDealloc();

    return rc;
    
}


//-----------------------------------------------------------------------------
//
// Function:  GpioDealloc
//
// This function deallocates the data structures required for interaction
// with the GPIO hardware.
//
// Parameters:
//      None.
//
// Returns:
//      Returns TRUE.
//
//-----------------------------------------------------------------------------
BOOL GpioDealloc(void)
{
    // Unmap peripheral address space
    if (g_pGPIO[DDK_GPIO_PORT1] != NULL)
    {
        MmUnmapIoSpace(g_pGPIO[DDK_GPIO_PORT1], sizeof(CSP_GPIO_REGS));
        g_pGPIO[DDK_GPIO_PORT1] = NULL;
    }

    if (g_pGPIO[DDK_GPIO_PORT2] != NULL)
    {
        MmUnmapIoSpace(g_pGPIO[DDK_GPIO_PORT2], sizeof(CSP_GPIO_REGS));
        g_pGPIO[DDK_GPIO_PORT2] = NULL;
    }

    if (g_pGPIO[DDK_GPIO_PORT3] != NULL)
    {
        MmUnmapIoSpace(g_pGPIO[DDK_GPIO_PORT3], sizeof(CSP_GPIO_REGS));
        g_pGPIO[DDK_GPIO_PORT3] = NULL;
    }

    return TRUE;
    
}

⌨️ 快捷键说明

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