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

📄 wmxscalemisc.c

📁 WM9713 audio codec driver for WinCE 5.0
💻 C
📖 第 1 页 / 共 2 页
字号:
/*-----------------------------------------------------------------------------
 * Copyright (c) Wolfson Microelectronics plc.  All rights reserved.
 *
 * This software as well as any related documentation is furnished under 
 * license and may only be used or copied in accordance with the terms of the 
 * license. The information in this file is furnished for informational use 
 * only, is subject to change without notice, and should not be construed as 
 * a commitment by Wolfson Microelectronics plc. Wolfson Microelectronics plc
 * assumes no responsibility or liability for any errors or inaccuracies that
 * may appear in this document or any software that may be provided in
 * association with this document. 
 *
 * Except as permitted by such license, no part of this document may be 
 * reproduced, stored in a retrieval system, or transmitted in any form or by 
 * any means without the express written consent of Wolfson Microelectronics plc. 
 *
 * $Id: WMXScaleMisc.c 2924 2006-04-12 12:50:25Z fb $
 *
 * This file contains the Windows CE/XScale platform layer for the drivers for
 * the Wolfson chips.
 *
 * Warning:
 *  This driver is specifically written for Wolfson Codecs. It is not a 
 *  general CODEC device driver.
 *
 *  This platform file is specifically designed to work with the Lubbock and 
 *  Mainstone XScale platforms from Intel.  There is no guarantee of correct 
 * operation with other platforms/controllers.
 *
 * -----------------------------------------------------------------------------*/

/*
 * IMPORTANT
 *
 * The functions in this file must obey two rules:
 *
 * 1. They do not use any memory other than stack space and parameters passed in.
 * 2. They do not make system calls, unless WMSystemCallsAllowed returns TRUE.
 *
 * All functions take a context parameter, which passes in pointers to the virtual
 * addresses of memory-mapped registers, and stores what type of device is being
 * accessed.
 * 
 * Some client functions provide shared memory via the v_pWMData member of the
 * context structure.  This cannot be relied on.
 */
 
/*
 * Include files
 */
#include "WMCommon.h"
#include "WMInterrupts.h"
#include "WMDevice.h"
#include "WMPlatformDeviceContext.h"
#include "WMControlLink.h"
#include "WMPlatformDebug.h"

/*
 * Global definitions
 */

/*-----------------------------------------------------------------------------
 * Function:    MicroSleep
 *
 * Sleeps for the given number of microseconds.
 *
 * Parameters:
 *      hDevice             handle to the device (from WMOpenDevice)
 *      microSeconds        The number of microseconds to sleep.
 *
 * Returns:     void
 *---------------------------------------------------------------------------*/
void MicroSleep( WM_DEVICE_HANDLE hDevice, unsigned microSeconds )
{
    WM_XSCALE_DEVICE_CONTEXT	*pDeviceContext = 
									(WM_XSCALE_DEVICE_CONTEXT*) hDevice;
	unsigned                    tEnd;

    if ( microSeconds != 0 )
    {
        /* The timer ticks at 3.6864 MHz = 0x384000Hz */
        tEnd = pDeviceContext->v_pOSTimerRegs->oscr0 + (microSeconds * XLLP_OST_TICKS_MS / 1000);
        while ( pDeviceContext->v_pOSTimerRegs->oscr0 < tEnd )
        {
            /* Allow other threads to continue if we can */
			WMBeNice( hDevice );
        }
    }
}

/*-----------------------------------------------------------------------------
 * Function:    GetMillisecondTimestamp
 *
 * Returns a 32-bit number containing the number of milliseconds since an
 * arbitrary point.  This is used for relative comparisons.
 *
 * Parameters:
 *      hDevice             handle to the device (from WMOpenDevice)
 *
 * Returns:     unsigned int
 *      The timestamp.
 *---------------------------------------------------------------------------*/
unsigned int GetMillisecondTimestamp( WM_DEVICE_HANDLE hDevice )
{
    WM_XSCALE_DEVICE_CONTEXT *pDeviceContext = 
								(WM_XSCALE_DEVICE_CONTEXT*) hDevice;
    
    return pDeviceContext->v_pOSTimerRegs->oscr0 / XLLP_OST_TICKS_MS;
}

/*-----------------------------------------------------------------------------
 * Function: WMPlatformOutputToHexLeds
 * 
 * Purpose: Output a value to the hex leds 
 *  
 * Parameters:
 *      hDevice     handle to the device (from WMOpenDevice).
 *      value       value to output to the hex leds.
 *
 * Returns:      void.
 *
 ----------------------------------------------------------------------------*/
void WMPlatformOutputToHexLeds( WM_DEVICE_HANDLE hDevice, unsigned long value )
{
    WM_XSCALE_DEVICE_CONTEXT *pDeviceContext = 
								(WM_XSCALE_DEVICE_CONTEXT*) hDevice;
    WM_OUTPUT_TO_HEX_LEDS( pDeviceContext, value );
}

/*-----------------------------------------------------------------------------
 * Function:    WMPlatformEnterSleep
 *
 * Enters sleep mode - powers down the device and does any state preservation
 * needed for restoring later.
 *
 * NB This works by configuring the RESET GPIO as an input during sleep.
 * This tristates the RESETB line.  For this to work, you require a pull-up
 * resistor on the RESETB line to hold it high during sleep.
 *
 * Parameters:
 *      hDevice     handle to the device (from WMOpenDevice)
 *
 * Returns:     void
 *---------------------------------------------------------------------------*/
void WMPlatformEnterSleep( WM_DEVICE_HANDLE hDevice )
{
    WM_XSCALE_DEVICE_CONTEXT *pDeviceContext = 
								(WM_XSCALE_DEVICE_CONTEXT*) hDevice;

    /* Set our RESET line to be an input so it won't get driven while we're asleep */
    pDeviceContext->v_pGPIORegs->RESET_GPIO_REG(GPDR) &= ~RESET_GPIO_MASK;

	/* Remember that XLLP has pulled the rug out from underneath us */
    pDeviceContext->fnLinkShutdown( hDevice );
}

/*-----------------------------------------------------------------------------
 * Function:    WMPlatformLeaveSleep
 *
 * Leaves sleep mode - powers the device back on again and restores any
 * settings which couldn't be preserved.
 *
 * Parameters:
 *      hDevice     handle to the device (from WMOpenDevice)
 *
 * Returns:     void
 *---------------------------------------------------------------------------*/
void WMPlatformLeaveSleep( WM_DEVICE_HANDLE hDevice )
{
    WM_XSCALE_DEVICE_CONTEXT *pDeviceContext = 
								(WM_XSCALE_DEVICE_CONTEXT*) hDevice;

	WMSTATUS                 status;

	if ( pDeviceContext->v_pWMData->powerStateFlags & WM_ASLEEP )
    {
        /* It's an output */
        pDeviceContext->v_pGPIORegs->RESET_GPIO_REG(GPDR) |= RESET_GPIO_MASK;

        /* Make sure Link is now up */
        status = pDeviceContext->fnLinkInit( hDevice );
    }
}

#if WM_TOUCH
/*-----------------------------------------------------------------------------
 * Function:    WMPlatformConfigureTouchGPIO
 *
 * This function configures the GPIO pins for the touch panel.
 *
 * Parameters:
 *      hDevice             handle to the device (from WMOpenDevice)
 *
 * Returns:     WMSTATUS
 *      See WMStatus.h
 *---------------------------------------------------------------------------*/
WMSTATUS WMPlatformConfigureTouchGPIO( WM_DEVICE_HANDLE hDevice )
{
#if WM_BOARD_MAINSTONEII  && !WM_PENIRQ_INVERTED && !WM_USE_VIRTUAL_PENDOWN
    WM_XSCALE_DEVICE_CONTEXT *pDeviceContext = 
								(WM_XSCALE_DEVICE_CONTEXT*) hDevice;
    
    /* Set it to active high */
    pDeviceContext->v_pBLRegs->MISCWR3 |= XLLP_BCR_MISCWR3_PEN_ACTIVE_HIGH;
#endif

    return WMS_SUCCESS;
}

/*-----------------------------------------------------------------------------
 * Function:    WMPlatformUnconfigureTouchGPIO
 *
 * This function unconfigures the GPIO pins for the touch driver.
 *
 * Parameters:
 *      hDevice             handle to the device (from WMOpenDevice)
 *
 * Returns:     WMSTATUS
 *      See WMStatus.h
 *---------------------------------------------------------------------------*/
WMSTATUS WMPlatformUnconfigureTouchGPIO( WM_DEVICE_HANDLE hDevice )
{
    /* Disable the interrupt */
    WMDisablePenInterrupt( hDevice );

    return WMS_SUCCESS;
}

/*-----------------------------------------------------------------------------
 * Function:    WMPlatformIsTouchGPIOSignalled
 *
 * This function returns whether the touch GPIO line is currently indicating
 * pen down.
 *
 * Parameters:
 *      hDevice             handle to the device (from WMOpenDevice)
 *
 * Returns:     WM_BOOL
 *      TRUE    - pen detect GPIO is signalled.
 *      FALSE   - pen detect GPIO not signalled.
 *---------------------------------------------------------------------------*/
WM_BOOL WMPlatformIsTouchGPIOSignalled( WM_DEVICE_HANDLE hDevice )
{
    return WMIsPenInterruptTriggered( hDevice );
}
#endif /* WM_TOUCH */

/*-----------------------------------------------------------------------------
 * Function:    WMPlatformEnableAmplifiers
 *
 * This function enables the onboard op amps.
 *
 * Parameters:
 *      hDevice             handle to the device (from WMOpenDevice)
 *
 * Returns:     void
 *---------------------------------------------------------------------------*/
void WMPlatformEnableAmplifiers( WM_DEVICE_HANDLE hDevice )
{
    WM_XSCALE_DEVICE_CONTEXT *pDeviceContext =
								(WM_XSCALE_DEVICE_CONTEXT *) hDevice;  

    WM97_TURN_ON_AMPLIFER_1( pDeviceContext );
    WM97_TURN_ON_AMPLIFER_2( pDeviceContext );
}

/*-----------------------------------------------------------------------------
 * Function:    WMPlatformDisableAmplifiers
 *
 * This function disables the onboard op amps.
 *
 * Parameters:
 *      hDevice             handle to the device (from WMOpenDevice)
 *
 * Returns:     void
 *---------------------------------------------------------------------------*/
void WMPlatformDisableAmplifiers( WM_DEVICE_HANDLE hDevice )
{
    WM_XSCALE_DEVICE_CONTEXT *pDeviceContext =
								(WM_XSCALE_DEVICE_CONTEXT *) hDevice;  

    WM97_TURN_OFF_AMPLIFER_1( pDeviceContext );
    WM97_TURN_OFF_AMPLIFER_2( pDeviceContext );
}

#if XLLP_AVAILABLE
/*-----------------------------------------------------------------------------
 * Function:    XllpStatusToWMStatus
 *
 * Convert an XLLP_STATUS_T to a WMSTATUS.
 *
 * Parameters:
 *      xllpStatus    the XLLP_STATUS_T to convert.
 *
 * Returns:     WMSTATUS
 *      The corresponding Wolfson status value.
 *---------------------------------------------------------------------------*/
WMSTATUS XllpStatusToWMStatus( XLLP_STATUS_T xllpStatus )
{
    WMSTATUS   wmStatus;
    
    switch ( xllpStatus )
    {
    case XLLP_STATUS_SUCCESS:
        wmStatus = WMS_SUCCESS;
        break;

    case XLLP_STATUS_UNSUPPORTED:
        wmStatus = WMS_UNSUPPORTED;
        break;

    case XLLP_STATUS_WRONG_PARAMETER:
        wmStatus = WMS_INVALID_PARAMETER;
        break;

    case XLLP_STATUS_TIME_OUT:
        wmStatus = WMS_DATA_TIMED_OUT;
        break;

    case XLLP_STATUS_NO_RESOURCES:
        wmStatus = WMS_RESOURCE_FAIL;
        break;

    case XLLP_STATUS_HW_ERROR:
        wmStatus = WMS_HW_ERROR;
        break;

    case XLLP_STATUS_NO_RESPONSE:
        wmStatus = WMS_DATA_TIMED_OUT;
        break;

    case XLLP_STATUS_DATA_UNDERRUN:
    case XLLP_STATUS_DATA_OVERRUN:
    case XLLP_STATUS_DATA_ERROR:
        wmStatus = WMS_NO_DATA;
        break;

    case XLLP_STATUS_INVALID_STATE:

⌨️ 快捷键说明

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