📄 wmtesthelpers.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: WMTestHelpers.c 2656 2006-01-27 08:03:53Z fb $
*
* This file contains helper functions for the tests.
*
* 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 "WMDeviceContext.h"
#include "WMControlLink.h"
#include "WMRegisterDefs.h"
#include "WMPower.h"
#include "Test/WMTestCommon.h"
#include "Test/WMTestHelpers.h"
/*
* Only build this if we are asked to.
*/
#if WM_TESTING
/*
* Global definitions
*/
/*
* Private data
*/
/*
* Function prototypes
*/
/*-----------------------------------------------------------------------------
* Function: WMTest_TraceRegisters
*
* Prints the contents of all registers.
*
* Parameters:
* hDevice handle to the device (from WMOpenDevice)
*
* Returns: WM_BOOL
* TRUE if they passed, FALSE if any failed.
*---------------------------------------------------------------------------*/
WMTEST_START_UNTITLED( WMTest_TraceRegisters( WM_DEVICE_HANDLE hDevice ) )
{
WM_REGTYPE reg;
WM_REGVAL regVal;
int maxReg, offset, maxRegCount;
const WM_CHIPDEF *pChipDef;
WMSTATUS status = WMS_SUCCESS;
WMTEST_NOTNULL( hDevice );
if ( WM_IS_GENERIC_FAMILY( hDevice ) )
{
WMTEST_SKIP();
}
/*
* Look up our chipdef.
*/
pChipDef = WMGetChipDef( hDevice );
WMTEST_NOTNULL( pChipDef );
/*
* Print a header.
*/
WMTEST_TRACE(( "Registers on %s device\r\n", WM_DEVICE_NAME( hDevice ) ));
if ( WM_IS_I2S( hDevice ) )
{
WMTEST_TRACE(( "Note: These are shadow values as we cannot read back from this device\r\n",
WM_DEVICE_NAME( hDevice ) ));
}
/*
* Work out how many register we have.
*/
maxReg = pChipDef->maxRegister;
offset = pChipDef->regOffset;
/*
* Check to make sure that the total number of registers
* this device has does not exceed MAX_REGISTER_COUNT.
*/
maxRegCount = pChipDef->maxRegister/pChipDef->regOffset;
WMTEST_LESS_EQUAL( maxRegCount, MAX_REGISTER_COUNT );
/*
* Try reading all the registers.
*/
for ( reg = 0; reg <= maxReg; reg += offset )
{
/* Make the call */
status = WMRead( hDevice, reg, ®Val );
WMTEST_ASSERT( WMS_UNSUPPORTED == status || WM_SUCCESS( status ) );
/* If we get here, we succeeded. */
WMTEST_TRACE(( " register %02X=0x%04X\r\n", reg, regVal ));
}
}
WMTEST_END
/*-----------------------------------------------------------------------------
* Function: WMTest_SaveState
*
* Helper function for the tests - gets the current register settings and
* global state for restoring after the test.
* If WM_CACHE_POWER_STATE is defined as TRUE this function will also
* save the cached power settings.
*
* Parameters:
* hDevice handle to the device (from WMOpenDevice)
* pSavedRegs array to receive the valid register values
* powerRegs array of size MAX_GLOBAL_POWER_REGS to receive
* the power register values
* powerRequirements array of size WM_MAX_DRIVERS to receive
* each driver's power requirements
* WmPower what everyone wants to be powered up.
*
* Returns: WM_BOOL
* TRUE iff it worked.
*---------------------------------------------------------------------------*/
WMTEST_START_UNTITLED( WMTest_SaveState( WM_DEVICE_HANDLE hDevice,
savedRegister *pSavedRegs,
WM_REGVAL *powerRegs,
WM_POWERFLAG *powerRequirements,
WM_POWERFLAG *WmPower
) )
{
int reg, maxReg, maxRegCount;
int offset;
const WM_CHIPDEF *pChipDef;
#if WM_CACHE_POWER_STATE
WM_DEVICE_CONTEXT *pDeviceContext = WMHANDLE_TO_DEVICE( hDevice );
int i;
#endif
WMSTATUS status = WMS_SUCCESS;
WMTEST_NOTNULL( hDevice );
if ( WM_IS_GENERIC_FAMILY( hDevice ) )
{
WMTEST_SKIP();
}
/*
* Look up our chipdef.
*/
pChipDef = WMGetChipDef( hDevice );
WMTEST_NOTNULL( pChipDef );
maxReg = pChipDef->maxRegister;
offset = pChipDef->regOffset;
/*
* Check to make sure that the total number of registers
* this device has does not exceed MAX_REGISTER_COUNT.
*/
maxRegCount = pChipDef->maxRegister/pChipDef->regOffset;
WMTEST_LESS_EQUAL( maxRegCount, MAX_REGISTER_COUNT );
for ( reg = 0; reg <= maxReg; reg += offset )
{
unsigned int regIndex = reg/offset;
status = WMRead( hDevice, reg, &pSavedRegs[regIndex].value );
WMTEST_ASSERT( WMS_UNSUPPORTED == status || WM_SUCCESS( status ) );
if( WM_SUCCESS(status) )
{
pSavedRegs[regIndex].valid = TRUE;
}
else
{
pSavedRegs[regIndex].valid = FALSE;
}
}
#if WM_CACHE_POWER_STATE
for ( i = 0; i < MAX_GLOBAL_POWER_REGS; i++ )
{
powerRegs[i] = pDeviceContext->v_pWMData->powerReg[i];
}
for ( i = 0; i < WM_MAX_DRIVERS; i++ )
{
powerRequirements[i] = pDeviceContext->v_pWMData->powerRequirements[i];
}
*WmPower = pDeviceContext->v_pWMData->WmPower;
#endif /* WM_CACHE_POWER_STATE */
}
WMTEST_END
/*-----------------------------------------------------------------------------
* Function: WMTest_RestoreState
*
* Restores a previously saved set of register settings and global state.
* If WM_CACHE_POWER_STATE is defined as TRUE this function will also
* restore the cached power settings.
*
* Parameters:
* hDevice handle to the device (from WMOpenDevice)
* pSavedRegs array containing the valid register values
* powerRegs array containing the power register values
* powerRequirements array containing each driver's power requirements
* WmPower what everyone wants to be powered up.
*
* Returns: WM_BOOL
* TRUE iff it worked.
*---------------------------------------------------------------------------*/
WMTEST_START_UNTITLED( WMTest_RestoreState( WM_DEVICE_HANDLE hDevice,
const savedRegister *pSavedRegs,
WM_REGVAL *powerRegs,
WM_POWERFLAG *powerRequirements,
WM_POWERFLAG *WmPower
) )
{
int reg, maxReg, maxRegCount, resetReg;
int offset;
const WM_CHIPDEF *pChipDef;
#if WM_CACHE_POWER_STATE
WM_DEVICE_CONTEXT *pDeviceContext = WMHANDLE_TO_DEVICE( hDevice );
int i;
#endif
WMSTATUS status = WMS_SUCCESS;
WMTEST_NOTNULL( hDevice );
if ( WM_IS_GENERIC_FAMILY( hDevice ) )
{
WMTEST_SKIP();
}
/*
* Look up our chipdef.
*/
pChipDef = WMGetChipDef( hDevice );
WMTEST_NOTNULL( pChipDef );
maxReg = pChipDef->maxRegister;
offset = pChipDef->regOffset;
resetReg = pChipDef->resetReg;
/*
* Check to make sure that the total number of registers
* this device has does not exceed MAX_REGISTER_COUNT.
*/
maxRegCount = pChipDef->maxRegister/pChipDef->regOffset;
WMTEST_LESS_EQUAL( maxRegCount, MAX_REGISTER_COUNT );
for ( reg = 0; reg <= maxReg; reg += offset )
{
/*
* Only restore vaild registers that we were able to read and
* do not restore the reset register as this will set all
* registers to default values.
*/
unsigned int regIndex = reg/offset;
if ( ( TRUE == pSavedRegs[regIndex].valid ) && ( reg != resetReg ) )
{
WMWrite( hDevice, reg, pSavedRegs[regIndex].value );
WMTEST_ASSERT( WMS_UNSUPPORTED == status || WM_SUCCESS( status ) );
}
}
#if WM_CACHE_POWER_STATE
for ( i = 0; i < MAX_GLOBAL_POWER_REGS; i++ )
{
pDeviceContext->v_pWMData->powerReg[i] = powerRegs[i];
}
for ( i = 0; i < WM_MAX_DRIVERS; i++ )
{
pDeviceContext->v_pWMData->powerRequirements[i] =
powerRequirements[i];
}
pDeviceContext->v_pWMData->WmPower = *WmPower;
#endif /* WM_CACHE_POWER_STATE */
}
WMTEST_END
/*-----------------------------------------------------------------------------
* Function: WMTest_CheckRegisters
*
* Helper function for the tests - checks that the current register settings
* match those provided.
*
* Parameters:
* hDevice handle to the device (from WMOpenDevice)
* pRegisters array of expected register values
*
* Returns: WM_BOOL
* TRUE iff it worked.
*---------------------------------------------------------------------------*/
WMTEST_START_UNTITLED( WMTest_CheckRegisters( WM_DEVICE_HANDLE hDevice,
const WM_REGVAL *pExpected
) )
{
int reg, maxReg, maxRegCount;
WM_REGVAL regVal;
int errors = 0;
int offset;
const WM_CHIPDEF *pChipDef;
WMSTATUS status = WMS_SUCCESS;
WMTEST_NOTNULL( hDevice );
if ( WM_IS_GENERIC_FAMILY( hDevice ) )
{
WMTEST_SKIP();
}
/*
* Look up our chipdef.
*/
pChipDef = WMGetChipDef( hDevice );
WMTEST_NOTNULL( pChipDef );
if ( WM_IS_I2S( hDevice ) )
{
WMTEST_TRACE(( "Note: These are shadow values as we cannot read back from this device\r\n",
WM_DEVICE_NAME( hDevice ) ));
}
maxReg = pChipDef->maxRegister;
offset = pChipDef->regOffset;
/*
* Check to make sure that the total number of registers
* this device has does not exceed MAX_REGISTER_COUNT.
*/
maxRegCount = pChipDef->maxRegister/pChipDef->regOffset;
WMTEST_LESS_EQUAL( maxRegCount, MAX_REGISTER_COUNT );
/*
* Print a header.
*/
WMTEST_TRACE(( "Checking registers on %s device\r\n", WM_DEVICE_NAME( hDevice ) ));
for ( reg = 0; reg <= maxReg; reg += offset )
{
unsigned int regIndex = reg/offset;
status = WMRead( hDevice, reg, ®Val );
WMTEST_ASSERT( WMS_UNSUPPORTED == status || WM_SUCCESS( status ) );
if ( pExpected[regIndex] != regVal )
{
WMTEST_TRACE(( "Error in register %02X: expected 0x%04X, actual 0x%04X\r\n",
reg,
pExpected[regIndex],
regVal
));
errors++;
}
}
WMTEST_EQUALS( errors, 0 );
}
WMTEST_END
#endif /* WM_TESTING */
/*------------------------------ END OF FILE ---------------------------------*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -