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

📄 wmlinktests.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: WMLinkTests.c 2112 2005-08-31 18:25:18Z ian $
 *
 * This file contains tests for the basic link operations.
 *
 * Warning:
 *  This driver is specifically written for Wolfson Codecs. It is not a 
 *  general CODEC device driver.
 *
 * -----------------------------------------------------------------------------*/

/*
 * Include files
 */
#include "WMCommon.h"
#include "WMControlLink.h"
#include "WMAudio.h"
#include "Test/WMTestCommon.h"
#include "Test/WMLinkTests.h"
#include "Test/WMTestHelpers.h"

/*
 * Only build this if we are asked to.
 */
#if WM_TESTING

/*
 * Global definitions
 */
#define WM_TEST_VAL_1           0x00
#define WM_TEST_VAL_2           0x55
#define WM_TEST_VAL_3           0xAA
#define WM_TEST_VAL_4           0x5A
#define WM_TEST_VAL_5           0xA5
#define WM_TEST_VAL_6           0x1FF
#define WM8753_DAC_DEFAULT_VAL  0xFF
/*
 * Private data
 */

/*
 * Function prototypes
 */

/*-----------------------------------------------------------------------------
 * Function:    WMTestLink
 *
 * Basic sanity tests for the control link.
 *
 * Parameters:
 *      hDevice     handle to the device (from WMOpenDevice)
 *
 * Returns:     WM_BOOL
 *      TRUE if they passed, FALSE if any failed.
 *---------------------------------------------------------------------------*/
WMTEST_START( WMTestLink( WM_DEVICE_HANDLE hDevice ) )
{
    /*
     * Test register operations.
     */
	if ( WM_IS_AC97( hDevice ) )
	{
		WMTEST_RUN( WMTestACLinkRegisterReads( hDevice ) );
		WMTEST_RUN( WMTestACLinkRegisterWrites( hDevice ) );
	}
	else if ( WM_IS_I2S( hDevice ) )
    {
		WMTEST_RUN( WMTest2WireRegisterWrites( hDevice ) );
    }
    else
    {
    	WMTEST_SKIP();
    }

}
WMTEST_END

/*-----------------------------------------------------------------------------
 * Function:    WMTestACLinkRegisterReads
 *
 * Tries to read from all registers.
 *
 * Parameters:
 *      hDevice     handle to the device (from WMOpenDevice)
 *
 * Returns:     WM_BOOL
 *      TRUE if they passed, FALSE if any failed.
 *---------------------------------------------------------------------------*/
WMTEST_START( WMTestACLinkRegisterReads( WM_DEVICE_HANDLE hDevice ) )
{
    WMTest_TraceRegisters( hDevice );
}
WMTEST_END

/*-----------------------------------------------------------------------------
 * Function:    WMTestACLinkRegisterWrites
 *
 * Tries register writing.
 *
 * Parameters:
 *      hDevice     handle to the device (from WMOpenDevice)
 *
 * Returns:     WM_BOOL
 *      TRUE if it passes, FALSE if it failed.
 *---------------------------------------------------------------------------*/
WMTEST_START( WMTestACLinkRegisterWrites( WM_DEVICE_HANDLE hDevice ) )
{
    WM_REGVAL       adcRate, dacRate;
    WM_REGVAL       audioControl;
    
    /*
     * For these tests to work, we need the VRA bit set.
     * Save the previous value and set it.
     */
    WMTEST_CALL( WMRead( hDevice, WM97_AUDIO_CONTROL, &audioControl ) );
    WMTEST_CALL( WMSetField( hDevice,
                             WM97_AUDIO_CONTROL,
                             WM97_VRA_ENABLED,
                             WM97_VRA_ENABLED
                           ) );

    /*
     * We use the sample rate registers because we know we can write them
     * benignly.  Save the initial values.
     */
    WMTEST_CALL( WMRead( hDevice, WM97_ADC_RATE, &adcRate ) );
    WMTEST_CALL( WMRead( hDevice, WM97_DAC_RATE, &dacRate ) );
    
    /*
     * Write a standard value.
     */
    WMTEST_CALL( WMWrite( hDevice, WM97_DAC_RATE, WM_SAMPLE_RATE_32K ) );
    
    /*
     * Check it took.
     */
    WMTEST_REGVAL( hDevice, WM97_DAC_RATE, WM_SAMPLE_RATE_32K );

    /*
     * Try a different value to make sure we didn't just fluke the right one.
     */
    WMTEST_CALL( WMWrite( hDevice, WM97_DAC_RATE, WM_SAMPLE_RATE_11K025 ) );
    WMTEST_REGVAL( hDevice, WM97_DAC_RATE, WM_SAMPLE_RATE_11K025 );
    
    /*
     * Two writes in succession.
     */
    WMTEST_CALL( WMWrite( hDevice, WM97_DAC_RATE, WM_SAMPLE_RATE_22K05 ) );
    WMTEST_CALL( WMWrite( hDevice, WM97_ADC_RATE, WM_SAMPLE_RATE_32K ) );
    
    /*
     * Check they both took.
     */
    WMTEST_REGVAL( hDevice, WM97_DAC_RATE, WM_SAMPLE_RATE_22K05 );
    WMTEST_REGVAL( hDevice, WM97_ADC_RATE, WM_SAMPLE_RATE_32K );

    /*
     * Write a non-standard value.  This should get rounded to the nearest
     * standard value.  This checks we really are talking to the codec, since
     * we are checking for a different value to the one we wrote.
     */
    WMTEST_CALL( WMWrite( hDevice, WM97_DAC_RATE, WM_SAMPLE_RATE_44K1 - 100 ) );
    WMTEST_REGVAL( hDevice, WM97_DAC_RATE, WM_SAMPLE_RATE_44K1 );
    
    /*
     * And restore the original values.
     */
    WMTEST_CALL( WMWrite( hDevice, WM97_ADC_RATE, adcRate ) );    
    WMTEST_CALL( WMWrite( hDevice, WM97_DAC_RATE, dacRate ) );  
    WMTEST_CALL( WMWrite( hDevice, WM97_AUDIO_CONTROL, audioControl ) );
}
WMTEST_END

#if WM_I2S
/*-----------------------------------------------------------------------------
 * Function:    WMTest2WireRegisterWrites
 *
 * Tries register writing.
 *
 * Parameters:
 *      hDevice     handle to the device (from WMOpenDevice)
 *
 * Returns:     WM_BOOL
 *      TRUE if it passes, FALSE if it fails.
 *---------------------------------------------------------------------------*/
WMTEST_START( WMTest2WireRegisterWrites( WM_DEVICE_HANDLE hDevice ) )
{
    const WM_CHIPDEF    *pChipDef;
    WM_REGTYPE          resetReg;

    /*
     * Look up our chipdef and our reset register.
     */    
    pChipDef = WMGetChipDef( hDevice );
    WMTEST_NOTNULL( pChipDef );
    resetReg = pChipDef->resetReg;
    
    if ( WM_REG_INVALID == pChipDef->maxRegister)
    {
    	WMTEST_TRACE(( "\r\n There are No available registers " ));
    	WMTEST_SKIP();
    }
    
	if ( WM_REG_INVALID != resetReg )
	{
		/*
		 * Writing to the reset register will set all registers to default values.
		 */
		WMTEST_CALL( WMWrite( hDevice, resetReg, WM_TEST_VAL_1 ) );
		WMTEST_CALL( WMWrite( hDevice, resetReg, WM_TEST_VAL_2 ) );
		WMTEST_CALL( WMWrite( hDevice, resetReg, WM_TEST_VAL_3 ) );
		WMTEST_CALL( WMWrite( hDevice, resetReg, WM_TEST_VAL_4 ) );
		WMTEST_CALL( WMWrite( hDevice, resetReg, WM_TEST_VAL_5 ) );
		WMTEST_CALL( WMWrite( hDevice, resetReg, WM_TEST_VAL_6 ) );
	}

    if ( IS_WM8753_FAMILY( hDevice ) )
    {
        /*
         * Write to the Left and Right DAC Volumes.
         */
        WMTEST_CALL( WMWrite( hDevice, WM8753_LEFT_DAC_VOLUME, WM_TEST_VAL_2 ) );
        WMTEST_CALL( WMWrite( hDevice, WM8753_RIGHT_DAC_VOLUME, WM_TEST_VAL_3 ) );
    
        /*
         * Check the values are the same.
         */
        WMTEST_REGVAL( hDevice, WM8753_LEFT_DAC_VOLUME, WM_TEST_VAL_2 );
        WMTEST_REGVAL( hDevice, WM8753_RIGHT_DAC_VOLUME, WM_TEST_VAL_3 );
    }
    
	if ( WM_REG_INVALID != resetReg )
	{
		/*
		 * Now reset all the registers to their default values.
		 */
		WMTEST_CALL( WMReset( hDevice ) );
	}

    if ( IS_WM8753_FAMILY( hDevice ) )
    {
        /*
         * Check the values are back to default.
         */
        WMTEST_REGVAL( hDevice, WM8753_LEFT_DAC_VOLUME, WM8753_DAC_DEFAULT_VAL );
        WMTEST_REGVAL( hDevice, WM8753_RIGHT_DAC_VOLUME, WM8753_DAC_DEFAULT_VAL );
    }
}
WMTEST_END
#endif /* WM_I2S */

#endif  /* WM_TESTING */
/*------------------------------ END OF FILE ---------------------------------*/

⌨️ 快捷键说明

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