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

📄 wmxscalessp.c

📁 WM9713 audio codec driver for WinCE 5.0
💻 C
字号:
/*-----------------------------------------------------------------------------
 * 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: WMXScaleSSP.c 1918 2005-07-18 06:48:56Z fb $
 *
 * Functionality for configuring and using Synchronous Serial Protocol (SSP)
 * serial ports.
 *
 * Warning:
 *  This driver is specifically written for Wolfson Codecs. It is not a 
 *  general CODEC device driver.
 *
 * --------------------------------------------------------------------------*/

/*
 * Include files
 */
#include "WMCommon.h"
#include "WMDevice.h"
#include "WMPlatformDeviceContext.h"
#include "WMPlatformSSP.h"

/*
 * Only build this if we need Audio SSP support.
 */
#if WM_AUDIO && WM_VOICE

/*
 * Global definitions
 */

/* SSP rates */
#define WM_SSP_8K       101
#define WM_SSP_12K      66
#define WM_SSP_16K      50
#define WM_SSP_24K      33
#define WM_SSP_32K      24
#define WM_SSP_48K      16
#define WM_SSP_96K      7

#define SSCR0_SCR(_div)     ((_div) << 8)
#define SSPSP_SFRMP         (1<<2)
#define SSPSP_SCMODE(_m)    ((_m) & 0x3)

#define WM_SSP_MODE 	SSCRO_FRF(SSP_MODE_PSP) | SSCR0_DSS(0x0) | SSCR0_EDSS

#ifndef XLLP_SSCR0_DSS_17BIT
#   define XLLP_SSCR0_DSS_17BIT     ( XLLP_SSCR0_EDSS | 0 )
#endif

#define SSCR1_TFT_VAL(_thresh) ( ((_thresh) & 0xF ) << 6 )
#define SSCR1_RFT_VAL(_thresh) ( ((_thresh) & 0xF ) << 10 )

/*
 * Function prototypes
 */

/*-----------------------------------------------------------------------------
 * Function:    WMPlatformSSPInit
 *
 * Initialise the platform specific part of the SSP port 2 interface.
 *
 * Parameters:
 *      hDevice     handle to the device (from WMOpenDevice)
 *
 * Returns:     none
 *---------------------------------------------------------------------------*/
void WMPlatformSSPInit( WM_DEVICE_HANDLE hDevice )
{
    WM_XSCALE_DEVICE_CONTEXT *pDeviceContext = 
								(WM_XSCALE_DEVICE_CONTEXT*) hDevice;

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

    pDeviceContext->v_pClkRegs->cken |= XLLP_CLKEN_SSP2;

    /*
     * Enable USB On The Go (OTG).
     * This needs to be done as we are sharing a line and the UART will interfere
     * with the Voice DAC interface if it is not disabled.
     */
    SSP_MUX_USE_USB( pDeviceContext );
    USB_OTG_ENABLE( pDeviceContext );
    USB_OTG_DISABLE_EXTERNAL_TRANSCEIVER( pDeviceContext );

    /*
     * Configure the GPIOs so that the XScale is the slave.
     * NOTE: see WMPlatform_Raw.h for SSP2 GPIO defines.
     */

    /* SSPTXD2 is an output */
    pDeviceContext->v_pGPIORegs->SSP2_TX_GPIO_REG(GPDR) |= GPIO_BIT_SSP_TX;

    /* SSPSCLK2, SSPRXD2 and SSPFRM2 are inputs */
    pDeviceContext->v_pGPIORegs->SSP2_SCLK_GPIO_REG(GPDR) &= ~GPIO_BIT_SSP_SCLK;
    pDeviceContext->v_pGPIORegs->SSP2_RX_GPIO_REG(GPDR) &= ~GPIO_BIT_SSP_RX;
    pDeviceContext->v_pGPIORegs->SSP2_FRM_GPIO_REG(GPDR) &= ~GPIO_BIT_SSP_FRM;

    /* Set up the correct alternate functions */
    pDeviceContext->v_pGPIORegs->SSP2_TX_ALTFN_REG =
                            (pDeviceContext->v_pGPIORegs->SSP2_TX_ALTFN_REG & ~SSP2_TX_ALTFN_MASK)|
                            GPIO_ALTFN_SSP_TX;
    pDeviceContext->v_pGPIORegs->SSP2_SCLK_ALTFN_REG =
                            (pDeviceContext->v_pGPIORegs->SSP2_SCLK_ALTFN_REG & ~SSP2_SCLK_ALTFN_MASK)|
                            GPIO_ALTFN_SSP_SCLK;
    pDeviceContext->v_pGPIORegs->SSP2_RX_ALTFN_REG =
                            (pDeviceContext->v_pGPIORegs->SSP2_RX_ALTFN_REG & ~SSP2_RX_ALTFN_MASK)|
                            GPIO_ALTFN_SSP_RX;
    pDeviceContext->v_pGPIORegs->SSP2_FRM_ALTFN_REG =
                            (pDeviceContext->v_pGPIORegs->SSP2_FRM_ALTFN_REG & ~SSP2_FRM_ALTFN_MASK)|
                            GPIO_ALTFN_SSP_FRM;
}

/*-----------------------------------------------------------------------------
 * Function:    WMPlatformSSPEnable
 *
 * Platform specific code for initialising and opening the SSP Serial Port 2
 * as a slave.
 *
 * Parameters:
 *      hDevice     handle to the device (from WMOpenDevice)
 *
 * Returns:     WMSTATUS
 *      See WMStatus.h
 *---------------------------------------------------------------------------*/
void WMPlatformSSPEnable( WM_DEVICE_HANDLE hDevice )
{
    WM_XSCALE_DEVICE_CONTEXT *pDeviceContext = 
								(WM_XSCALE_DEVICE_CONTEXT*) hDevice;

    pDeviceContext->v_pClkRegs->cken |= XLLP_CLKEN_SSP2;

    pDeviceContext->v_pSSP2Regs->sscr0 = 0;
    pDeviceContext->v_pSSP2Regs->sscr1 = 0;
    pDeviceContext->v_pSSP2Regs->sspsp = 0;

    pDeviceContext->v_pSSP2Regs->sscr0 = XLLP_SSCR0_DSS_17BIT   |
                                         XLLP_SSCR0_FRF_PSP;

    pDeviceContext->v_pSSP2Regs->sscr1 = SSCR1_TFT_VAL(7)       | 
                                         SSCR1_RFT_VAL(14)      |
                                         XLLP_SSCR1_TRAIL       |
                                         XLLP_SSCR1_TSRE        |
                                         XLLP_SSCR1_RSRE        |
                                         XLLP_SSCR1_TIE         |
                                         XLLP_SSCR1_RIE         |
                                         XLLP_SSCR1_RWOT        |
                                         XLLP_SSCR1_SCLKDIR     |
                                         XLLP_SSCR1_SFRMDIR;

    pDeviceContext->v_pSSP2Regs->sspsp = SSPSP_SCMODE(3)        |
                                         SSPSP_SFRMP;

    pDeviceContext->v_pSSP2Regs->ssitr = 0;
    pDeviceContext->v_pSSP2Regs->ssto  = 0x1000;
}

/*-----------------------------------------------------------------------------
 * Function:    WMPlatformSSPDisable
 *
 * Disable the SSP serial port.
 *
 * Parameters:
 *      hDevice     handle to the device (from WMOpenDevice)
 *
 * Returns:     none
 *---------------------------------------------------------------------------*/
void WMPlatformSSPDisable( WM_DEVICE_HANDLE hDevice )
{
    WM_XSCALE_DEVICE_CONTEXT *pDeviceContext =
								(WM_XSCALE_DEVICE_CONTEXT*) hDevice;

    pDeviceContext->v_pClkRegs->cken &= ~XLLP_CLKEN_SSP2;
}

/*-----------------------------------------------------------------------------
 * Function:    WMPlatformSSPStart
 *
 * Start the SSP Serial Port 2 running.
 *
 * Parameters:
 *      hDevice     handle to the device (from WMOpenDevice)
 *
 * Returns:     none
 *---------------------------------------------------------------------------*/
void WMPlatformSSPStart( WM_DEVICE_HANDLE hDevice )
{
    WM_XSCALE_DEVICE_CONTEXT *pDeviceContext = 
								(WM_XSCALE_DEVICE_CONTEXT*) hDevice;

    pDeviceContext->v_pSSP2Regs->sscr0 |= XLLP_SSCR0_SSE;
}

/*-----------------------------------------------------------------------------
 * Function:    WMPlatformSSPStop
 *
 * Stop the SSP Serial Port 2.
 *
 * Parameters:
 *      hDevice     handle to the device (from WMOpenDevice)
 *
 * Returns:     none
 *---------------------------------------------------------------------------*/
void WMPlatformSSPStop( WM_DEVICE_HANDLE hDevice )
{
    WM_XSCALE_DEVICE_CONTEXT *pDeviceContext = 
								(WM_XSCALE_DEVICE_CONTEXT*) hDevice;

    pDeviceContext->v_pSSP2Regs->sscr0 &= ~XLLP_SSCR0_SSE;
}

#endif /* WM_AUDIO && WM_VOICE */

/*------------------------------ END OF FILE ---------------------------------*/

⌨️ 快捷键说明

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