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

📄 wmcontrollink.c

📁 WM9713 audio codec driver for WinCE 5.0
💻 C
📖 第 1 页 / 共 4 页
字号:

            /* Set our sample rates to their default values */
            pDeviceContext->v_pWMData->audioData.ADCRate = pChipDef->defADCRate;
            pDeviceContext->v_pWMData->audioData.hifiDACRate = pChipDef->defHiFiDACRate;
#   if WM_VOICE
            pDeviceContext->v_pWMData->audioData.voiceDACRate = pChipDef->defVoiceDACRate;
#   endif 
#   ifdef WM_MONODAC
            pDeviceContext->v_pWMData->audioData.monoDACRate = pChipDef->defMonoDACRate;
#   endif
#endif /* WM_AUDIO */       
            
            /* Let other threads in again */
            WMUnlockGlobalData( hDevice );
        }
    }

finish:
    return;
}

/*-----------------------------------------------------------------------------
 * Function:    WMWake
 *
 * Forces a warm reset of the WM97xx device, waking it up again but leaving it
 * in its previous state (with all the register settings as they were before
 * the sleep).
 *
 * Parameters:
 *      hDevice             handle to the device (from WMOpenDevice)
 *
 * Returns:     WMSTATUS
 *      TRUE if the WM97 device is responding (codec ready set).
 *---------------------------------------------------------------------------*/
WMSTATUS WMWake( WM_DEVICE_HANDLE hDevice )
{
#if WM_CACHE_POWER_STATE
    WM_DEVICE_CONTEXT   *pDeviceContext = WMHANDLE_TO_DEVICE( hDevice );
#endif
    WMSTATUS            status = WMS_SUCCESS;

    /*
     * Lock our global data.
     */
    if ( !WMLockGlobalData( hDevice ) )
    {
        status = WMS_LOCK_TIMED_OUT;
        goto error0;
    }

    /*
     * If the link's not running, start it.
     */
#if WM_CACHE_POWER_STATE
    if ( !pDeviceContext->v_pWMData ||
        !(pDeviceContext->v_pWMData->WmPower & WM_POWER_LINK )
       )
#endif
    {
        status = WMPlatformWake( hDevice );
        if ( WM_ERROR( status ) )
        {
            goto error1;
        }
        
#if WM_CACHE_POWER_STATE
        if ( pDeviceContext->v_pWMData )
        {
            pDeviceContext->v_pWMData->WmPower |= WM_POWER_LINK;
        }
#endif
    }
    
    /* Let other threads in again */
    WMUnlockGlobalData( hDevice );

    return WMS_SUCCESS;
    
error1:
    WMUnlockGlobalData( hDevice );
    
error0:
    return status;
}

#if WM_USE_SHADOW_REGISTERS
/*-----------------------------------------------------------------------------
 * Function:    WMIsDefaultRegValue
 *
 * Check to see if this is the default register value.
 * Note : This function will only work if shadow registers are defined in the
 *        approprate chipdef.
 *
 * Parameters:
 *      hDevice             handle to the device (from WMOpenDevice)
 *		reg                 register to check
 *      value               current value to compare against the default
 *
 * Returns:     WM_BOOL
 *      TRUE if it is the default reg value, FALSE if not.
 *---------------------------------------------------------------------------*/
WM_BOOL WMIsDefaultRegValue( WM_DEVICE_HANDLE hDevice,
                             WM_REGTYPE	      reg,
                             WM_REGVAL        value
                            )
{
    WM_BOOL   isDefault = FALSE;
    WM_REGVAL defaultRegVal = 0;
    WMSTATUS  status;

    /* Get default from the default shadow register if available */
    status = private_ReadDefaultShadowRegister( hDevice, reg, &defaultRegVal );

    if( defaultRegVal == value && WM_SUCCESS(status) )
    {
        isDefault = TRUE;
    }

    return isDefault;
}
#endif /* WM_USE_SHADOW_REGISTERS */


/*-----------------------------------------------------------------------------
 * Function:    WMPlatformLinkInit
 *
 * Initialises the use of the control link by a given driver.
 *
 * Parameters:
 *      hDevice             handle to the device (from WMOpenDevice)
 *      driverId            The driver ID (e.g. WM_DRIVER_AUDIO)
 *
 * Returns:     WMSTATUS
 *      See WMStatus.h.
 *---------------------------------------------------------------------------*/
WM_INLINE WMSTATUS WMPlatformLinkInit( WM_DEVICE_HANDLE hDevice, 
                                       WM_DRIVER_ID driverId 
                                     )
{
    WMSTATUS            status          = WMS_UNSUPPORTED;
    WM_DEVICE_CONTEXT   *pDeviceContext = WMHANDLE_TO_DEVICE( hDevice );

    WM_ASSERT( hDevice, NULL != pDeviceContext );
    WM_ASSERT( hDevice, NULL != pDeviceContext->fnLinkInit );
    if ( pDeviceContext->fnLinkInit )
    {
        status = pDeviceContext->fnLinkInit( hDevice );
    }

    return status;
}

/*-----------------------------------------------------------------------------
 * Function:    WMPlatformLinkShutdown
 *
 * Marks the end of use of the control link by this driver.
 *
 * Parameters:
 *      hDevice             handle to the device (from WMOpenDevice)
 *      driverId            The driver ID (e.g. WM_DRIVER_AUDIO)
 *
 * Returns:     void
 *---------------------------------------------------------------------------*/
WM_INLINE void WMPlatformLinkShutdown( WM_DEVICE_HANDLE hDevice,
                                       WM_DRIVER_ID driverId
                                     )
{
    WM_DEVICE_CONTEXT *pDeviceContext = WMHANDLE_TO_DEVICE( hDevice );

    WM_ASSERT( hDevice, NULL != pDeviceContext );
    WM_ASSERT( hDevice, NULL != pDeviceContext->fnLinkShutdown );
    if ( pDeviceContext->fnLinkShutdown )
    {
        pDeviceContext->fnLinkShutdown( hDevice );
    }
}

/*-----------------------------------------------------------------------------
 * Function:    WMPlatformRead
 *
 * Reads the value from the given register.
 *
 * Parameters:
 *      hDevice             handle to the device (from WMOpenDevice)
 *      reg                 register to read from
 *      pValue              variable to receive value
 *
 * Returns:     WMSTATUS
 *      See WMStatus.h.
 *---------------------------------------------------------------------------*/
WM_INLINE WMSTATUS WMPlatformRead( WM_DEVICE_HANDLE hDevice,
                                   WM_REGTYPE reg, 
                                   WM_REGVAL *pValue
                                 )
{
    WMSTATUS            status          = WMS_UNSUPPORTED;
    WM_DEVICE_CONTEXT   *pDeviceContext = WMHANDLE_TO_DEVICE( hDevice );
    WM_REGVAL value = 0;

    WM_ASSERT( hDevice, NULL != pDeviceContext );
    if ( pDeviceContext->fnCodecRead )
    {
        status = pDeviceContext->fnCodecRead( hDevice, reg, &value );
        *pValue = value;
    }

    return status;
}

/*-----------------------------------------------------------------------------
 * Function:    WMPlatformWrite
 *
 * Writes the value to the given register.
 *
 * Parameters:
 *      hDevice             handle to the device (from WMOpenDevice)
 *      reg                 register to write to
 *      value               value to write
 *
 * Returns:     WMSTATUS
 *      See WMStatus.h.
 *---------------------------------------------------------------------------*/
WM_INLINE WMSTATUS WMPlatformWrite( WM_DEVICE_HANDLE hDevice,
                                    WM_REGTYPE reg,
                                    WM_REGVAL value
                                  )
{
    WMSTATUS            status          = WMS_UNSUPPORTED;
    WM_DEVICE_CONTEXT   *pDeviceContext = WMHANDLE_TO_DEVICE( hDevice );

    WM_ASSERT( hDevice, NULL != pDeviceContext );
    WM_ASSERT( hDevice, NULL != pDeviceContext->fnCodecWrite );
    if ( pDeviceContext->fnCodecWrite )
    {
        status = pDeviceContext->fnCodecWrite( hDevice, reg, value );
    }

    return status;
}

#if WM_AUXADC && WM_STREAM_AUXADC
/*-----------------------------------------------------------------------------
 * Function:    WMPlatformReadCTCAuxADC
 *
 * Reads the next ADC value from the stream in continuous conversion mode (CTC).
 *
 * Parameters:
 *      hDevice             handle to the device (from WMOpenDevice)
 *      pValue              variable to receive value
 *
 * Returns:     WMSTATUS
 *      See WMStatus.h
 *---------------------------------------------------------------------------*/
WMSTATUS WMPlatformReadCTCAuxADC( WM_DEVICE_HANDLE hDevice,
                                  WM_REGVAL *pValue
                                )
{
    WMSTATUS            status = WMS_UNSUPPORTED;
    const WM_CHIPDEF    *pChipDef;

    pChipDef = WMGetChipDef( hDevice );
    WM_ASSERT( hDevice, NULL != pChipDef );
    if ( !pChipDef )
    {
        status = WMS_NO_SUPPORTED_DEVICE;
        goto finish;
    }

    if ( WM_IS_AUXADC_SUPPORTED( hDevice ) &&
         NULL != pChipDef->vtable.fnReadCTCAuxADC
       )
    {
        status = pChipDef->vtable.fnReadCTCAuxADC( hDevice, pValue );
    }
    
finish:
    return status;
}
#endif /* WM_AUXADC && WM_STREAM_AUXADC */

/*-----------------------------------------------------------------------------
 * Function:    WMPlatformReset
 *
 * Forces a cold reset of the device, restoring everything to its
 * default startup condition.
 *
 * Parameters:
 *      hDevice             handle to the device (from WMOpenDevice)
 *
 * Returns:     WMSTATUS
 *      See WMStatus.h.
 *---------------------------------------------------------------------------*/
WM_INLINE WMSTATUS WMPlatformReset( WM_DEVICE_HANDLE hDevice )
{
    WMSTATUS            status          = WMS_UNSUPPORTED;
    WM_DEVICE_CONTEXT   *pDeviceContext = WMHANDLE_TO_DEVICE( hDevice );

    WM_ASSERT( hDevice, NULL != pDeviceContext );
    WM_ASSERT( hDevice, NULL != pDeviceContext->fnCodecReset );
    if ( pDeviceContext->fnCodecReset )
    {
        status = pDeviceContext->fnCodecReset( hDevice );
    }

    return status;
}

/*-----------------------------------------------------------------------------
 * Function:    WMPlatformWake
 *
 * Forces a warm reset of the device, waking it up again but leaving it
 * in its previous state (with all the register settings as they were before
 * the sleep).
 *
 * Parameters:
 *      hDevice             handle to the device (from WMOpenDevice)
 *
 * Returns:     WMSTATUS
 *      See WMStatus.h.
 *---------------------------------------------------------------------------*/
WM_INLINE WMSTATUS WMPlatformWake( WM_DEVICE_HANDLE hDevice )
{
    WMSTATUS            status;
    WM_DEVICE_CONTEXT   *pDeviceContext = WMHANDLE_TO_DEVICE( hDevice );

    WM_ASSERT( hDevice, NULL != pDeviceContext );
    if ( pDeviceContext->fnCodecWake )
    {
        status = pDeviceContext->fnCodecWake( hDevice );
    }
    else
    {
        /*
         * It's probably an I2S codec which is implicitly awake.
         */
        status = WMS_SUCCESS;
    }

    return status;
}

/*-----------------------------------------------------------------------------
 * Function:    private_IsValidRegister
 *
 * Checks whether the given register is valid for the given device.
 *
 * Parameters:
 *      hDevice     handle to the device (from WMOpenDevice)
 *      reg         the register to check
 *
 * Returns:     WM_BOOL
 *      TRUE = valid, FALSE = invalid
 *---------------------------------------------------------------------------*/
static WM_BOOL private_IsValidRegister( WM_DEVICE_HANDLE hDevice,
                                       WM_REGTYPE       reg
                                     )
{
    const WM_CHIPDEF    *pChipDef;
    WM_REGTYPE          regNum;
    unsigned short      regOffset;

    /*
     * Look up our chipdef.
     */
    pChipDef = WMGetChipDef( hDevice );

    /*
     * We need to check for a valid chipdef as it may not have been
     * set up yet. The first few reads may be checking the the devices
     * Id so that it can set up the chipdef.
     */
    if ( !pChipDef )
    {
        /* We can't tell - just say it's okay for now */
        return TRUE;
    }

    /* The invalid register is never valid */
    if ( WM_REG_INVALID == reg )
    {
        return FALSE;
    }

    /* Make sure the register is in range */
    if ( reg > pChipDef->maxRegister )
    {
        return FALSE;
    }
    
    /* Check it's not a value in the gap between registers */
    regOffset = pChipDef->regOffset;
    regNum = reg / regOffset;
    if ( regOffset > 1 && ( (regNum * regOffset) != reg ) )
    {
        return FALSE;
    }
    
    /* All checks pass.  It's valid. */
    return TRUE;
}

#if WM_USE_SHADOW_REGISTERS

/*-----------------------------------------------------------------------------
 * Function:    private_InitShadowRegisters
 *
 * Initialise the shadow registers with their default values.
 *
 * Parameters:
 *      hDevice             handle to the device (from WMOpenDevice)
 *
 * Returns:     WMSTATUS
 *      See WMStatus.h.
 *---------------------------------------------------------------------------*/
static WMSTATUS private_InitShadowRegisters( WM_DEVICE_HANDLE hDevice )
{
    unsigned int            shadow;
    const WM_CHIPDEF        *pChipDef       = NULL;
    WM_DEVICE_CONTEXT       *pDeviceContext = WMHANDLE_TO_DEVICE( hDevice );
    volatile WM_SHARED_DATA *v_pWMData;
    WMSTATUS                status          = WMS_SUCCESS;

    WM_ASSERT( hDevice, NULL != pDeviceContext );
    WM_ASSERT( hDevice, NULL != pDeviceContext->v_pWMData );

    /*
     * Look up our chipdef.
     */
    pChipDef = WMGetChipDef( hDevice );
    if ( !pChipDef )

⌨️ 快捷键说明

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