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

📄 aclink.c.svn-base

📁 PXA270 平台 Windows Mobile 5。0 UCB1400 触摸屏驱动
💻 SVN-BASE
字号:
//
// 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.
//
/* 
** 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.
*/

#include <windows.h>
#include <xllp_ac97.h>
#include <bsp.h>
#include "aclink.h"

static volatile BULVERDE_AC97_REG   *g_pAc97Regs  = NULL;
static volatile BULVERDE_OST_REG    *g_pOSTRegs   = NULL;
static volatile BULVERDE_INTR_REG   *g_pICRegs    = NULL;
static volatile BULVERDE_GPIO_REG   *g_pGPIORegs  = NULL;
static volatile BULVERDE_CLKMGR_REG *g_pClockRegs = NULL;

static XLLP_AC97_CONTEXT_T g_AC97CtxStruct;

static BOOL g_IsAC97Configured = FALSE;

static volatile AC97_GLOBALS *g_pAc97Shared = NULL;

BOOL InitializeACLink(BOOL InPowerHandler, UINT8 DevId)
{

    // Allocate AC link control resources.
    //
    //NKDbgPrintfW(TEXT("before AllocateACLinkResources\r\n"));
    
    if (!AllocateACLinkResources(DevId))
    {
        return(FALSE);
    }
    //NKDbgPrintfW(TEXT("after AllocateACLinkResources\r\n"));
    // Data structure used by XLLP routines.
    //
    g_AC97CtxStruct.pGpioReg          = (P_XLLP_GPIO_T)   g_pGPIORegs;
    g_AC97CtxStruct.pClockReg         = (P_XLLP_CLKMGR_T) g_pClockRegs;
    g_AC97CtxStruct.pAc97Reg          = (P_XLLP_AC97_T)   g_pAc97Regs;
    g_AC97CtxStruct.pOstRegs          = (P_XLLP_OST_T)    g_pOSTRegs;
    g_AC97CtxStruct.pIntcReg          = (P_XLLP_INTC_T)   g_pICRegs;
    g_AC97CtxStruct.maxSetupTimeOutUs = 1000;
    g_AC97CtxStruct.useSecondaryCodec = 0;

    XllpOstDelayMicroSeconds((P_XLLP_OST_T) g_pOSTRegs, 1);

    // Configure the AC97 controller.
    //
    //NKDbgPrintfW(TEXT("before ConfigureAC97Control\r\n"));
    if (!ConfigureAC97Control())
    {
        return(FALSE);
    }
    //NKDbgPrintfW(TEXT("after ConfigureAC97Control\r\n"));
    return(TRUE);
}

BOOL DeInitializeACLink(BOOL InPowerHandler, UINT8 DevId)
{
    if (!DeAllocateACLinkResources(DevId))
    {
        return(FALSE);
    }

    return(TRUE);
}

BOOL AllocateACLinkResources(UINT8 DevId)
{
    PHYSICAL_ADDRESS RegPA;

    if (g_pICRegs == NULL)
    {
        RegPA.QuadPart = BULVERDE_BASE_REG_PA_INTC;
        g_pICRegs = (volatile BULVERDE_INTR_REG *) MmMapIoSpace(RegPA, 0x400, FALSE);
    }

    if (g_pAc97Regs == NULL)
    {
        RegPA.QuadPart = BULVERDE_BASE_REG_PA_AC97;
        g_pAc97Regs = (volatile BULVERDE_AC97_REG *) MmMapIoSpace(RegPA, 0x400, FALSE);
    }

    if (g_pClockRegs == NULL)
    {
        RegPA.QuadPart = BULVERDE_BASE_REG_PA_CLKMGR;
        g_pClockRegs = (volatile BULVERDE_CLKMGR_REG *) MmMapIoSpace(RegPA, 0x400, FALSE);
    }

    if (g_pGPIORegs == NULL)
    {
        RegPA.QuadPart = BULVERDE_BASE_REG_PA_GPIO;
        g_pGPIORegs = (volatile BULVERDE_GPIO_REG *) MmMapIoSpace(RegPA, 0x400, FALSE);
    }

    if (g_pOSTRegs == NULL)
    {
        RegPA.QuadPart = BULVERDE_BASE_REG_PA_OST;
        g_pOSTRegs = (volatile BULVERDE_OST_REG *) MmMapIoSpace(RegPA, 0x400, FALSE);
    }

    if (hACLinkControlMutex == NULL)
    {
        hACLinkControlMutex = CreateMutex(NULL, FALSE, ACLINK_MUTEX_NAME);
    }

    if (NULL == g_pAc97Shared)
    {
    	HANDLE hShareMap;
    	DWORD dwError;
	    hShareMap = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE,
									0, sizeof(AC97_GLOBALS), AC97_SHARED_FILENAME );
		dwError = GetLastError();
    	if((0 == dwError) || (ERROR_ALREADY_EXISTS == dwError))
	    {
        	// Get a valid process pointer to the buffer mapped above.
	        g_pAc97Shared = (volatile AC97_GLOBALS *)MapViewOfFile( hShareMap, FILE_MAP_ALL_ACCESS, 0, 0, 0 );
    	    //handle is not needed because mapped view has an internal open handle to the object
    	    CloseHandle(hShareMap);
	    }
	    if ((0 == dwError) && (g_pAc97Shared))
	    {//touch driver is the first to create file mapping. Initialize it.
            g_pAc97Shared->acLinkTouchInit = FALSE;
            g_pAc97Shared->acLinkAudioInit = FALSE;        
        }
    }
    
    if (!g_pICRegs || !g_pAc97Regs || !g_pClockRegs || !g_pGPIORegs || !g_pOSTRegs || !hACLinkControlMutex 
    || !g_pAc97Shared)
    {
        DEBUGMSG(TRUE, (TEXT("ERROR:  Failed to allocate AC Link resources.\r\n")));
        DeAllocateACLinkResources(DevId);
        return(FALSE);
    }

    return(TRUE);
}

BOOL DeAllocateACLinkResources(UINT8 DevId)
{

    if (g_pAc97Regs)
    {
        VirtualFree((void *)g_pAc97Regs, 0, MEM_RELEASE);
        g_pAc97Regs = NULL;
    }

    if (g_pICRegs)
    {
        VirtualFree((void *)g_pICRegs, 0, MEM_RELEASE);
        g_pICRegs = NULL;
    }

    if (g_pClockRegs)
    {
        VirtualFree((void *)g_pClockRegs, 0, MEM_RELEASE);
        g_pClockRegs = NULL;
    }

    if (g_pGPIORegs)
    {
        VirtualFree((void *)g_pGPIORegs, 0, MEM_RELEASE);
        g_pGPIORegs = NULL;
    }

    if (g_pOSTRegs)
    {
        VirtualFree((void *)g_pOSTRegs, 0, MEM_RELEASE);
        g_pOSTRegs = NULL;
    }

    if (hACLinkControlMutex)
    {
        CloseHandle(hACLinkControlMutex);
    }

    if (g_pAc97Shared)    
    {
        g_pAc97Shared->acLinkTouchInit = FALSE;            
        UnmapViewOfFile((void *)g_pAc97Shared);
        g_pAc97Shared = NULL;
    }
    return(TRUE);
}

BOOL ConfigureAC97Control(void)
{
    if (g_IsAC97Configured)
    {
        return(TRUE);
    }

    if (FALSE == g_pAc97Shared->acLinkAudioInit)
    {//audio driver isn't here or it has not powered on aclink
        if (XllpAc97Init(&g_AC97CtxStruct) != XLLP_AC97_NO_ERROR)
        {
            return(FALSE);
        }
    }
    g_pAc97Shared->acLinkTouchInit = TRUE;

    g_IsAC97Configured = TRUE;

    return(TRUE);
}

BOOL UnConfigureAC97Control(void)
{
    if (!g_IsAC97Configured)
    {
        return(TRUE);
    }

    if (FALSE == g_pAc97Shared->acLinkAudioInit)
    {//audio driver isn't here or it has already been powered down
        if (XllpAc97DeInit(&g_AC97CtxStruct) != XLLP_AC97_NO_ERROR)
        {
            return(FALSE);
        }
    }
    g_pAc97Shared->acLinkTouchInit = FALSE;
    
    g_IsAC97Configured = FALSE;

    return(TRUE);
}

BOOL GetAC97Lock(void)
{   

    if (WaitForSingleObject(hACLinkControlMutex, 3000) == WAIT_OBJECT_0)
    {
        return(TRUE);
    }
    else
    {
        return(FALSE);
    }
}

BOOL ReleaseAC97Lock(void)
{

    if (!g_pAc97Regs) return(FALSE);

    g_pAc97Regs->car &= ~AC97CAR_CAIP;
    ReleaseMutex(hACLinkControlMutex);

    return(TRUE);
}

BOOL ReadAC97Raw(UINT8 Offset, UINT16 *pData, UINT8 DevId)
{

    if (XllpAc97Read((XLLP_UINT16_T)   Offset,
                     (XLLP_UINT16_T *) pData,
                     (P_XLLP_AC97_T)   g_pAc97Regs, 
                     (P_XLLP_OST_T)    g_pOSTRegs,
                     5000, 
                     XLLP_AC97_CODEC_PRIMARY) != XLLP_AC97_NO_ERROR)
    {
        return(FALSE);
    }

    return(TRUE);
}

BOOL ReadAC97(UINT8 Offset, UINT16 *pData, UINT8 DevId)
{
    BOOL retVal = FALSE;

    if (GetAC97Lock() == TRUE)
    {
        retVal = ReadAC97Raw(Offset, pData, DevId);
        ReleaseAC97Lock();
    }

    return(retVal);
}

BOOL WriteAC97Raw(UINT8 Offset, UINT16 Data, UINT8 DevId)
{

    if (XllpAc97Write((XLLP_UINT16_T) Offset,
                      (XLLP_UINT16_T) Data, 
                      (P_XLLP_AC97_T) g_pAc97Regs, 
                      (P_XLLP_OST_T)  g_pOSTRegs,
                      5000, 
                      XLLP_AC97_CODEC_PRIMARY) != XLLP_AC97_NO_ERROR)
    {
        return(FALSE);
    }

    return(TRUE);
}

BOOL WriteAC97(UINT8 Offset, UINT16 Data, UINT8 DevId)
{
    BOOL retVal = FALSE;

    if (GetAC97Lock() == TRUE)
    {
        retVal = WriteAC97Raw(Offset, Data, DevId);
        ReleaseAC97Lock();
    }

    return(retVal);
}


BOOL ColdResetAC97Control(void)
{

    if (XllpAc97ColdReset(&g_AC97CtxStruct) != XLLP_AC97_NO_ERROR)
    {
        return(FALSE);
    }

    return(TRUE);
}

⌨️ 快捷键说明

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