📄 wmgpiotests.c
字号:
* Finally set it back to the original setting.
*/
WMTEST_CALL( WMWrite( hDevice, WM97_GPIO_PIN_CONFIG, originalConfigVal ) );
WMTEST_CALL( WMWrite( hDevice, WM97_GPIO_PIN_ASSIGN, originalAltVal ) );
}
}
WMTEST_END
/*-----------------------------------------------------------------------------
* Function: WMTestGPIOInvertIRQ
*
* Test WMGPIOInvertIRQ function.
*
* Parameters:
* hDevice handle to the device (from WMOpenDevice)
*
* Returns: WM_BOOL
* TRUE if it passed, FALSE if it failed.
*---------------------------------------------------------------------------*/
WMTEST_START( WMTestGPIOInvertIRQ( WM_DEVICE_HANDLE hDevice ) )
{
const WM_CHIPDEF *pChipDef;
WM_REGTYPE addFuncReg = 0;
WM_REGVAL originalVal;
/*
* Look up our chipdef.
*/
pChipDef = WMGetChipDef( hDevice );
WMTEST_NOTNULL( pChipDef );
switch ( pChipDef->deviceType )
{
case WM_CHIP_WM9712:
addFuncReg = WM97_ADD_FUN;
break;
case WM_CHIP_WM9713:
addFuncReg = WM9713_ADD_FUN1;
break;
default:
WMTEST_ASSERT( pChipDef->deviceType == 0 );
}
if ( addFuncReg )
{
/*
* Get the current setting.
*/
WMTEST_CALL( WMRead( hDevice, addFuncReg, &originalVal ) );
/*
* Invert the IRQ.
*/
WMTEST_CALL_STATUS( WMGPIOInvertIRQ( hDevice, TRUE ),
WMS_SUCCESS
);
/*
* Uninvert the IRQ.
*/
WMTEST_CALL_STATUS( WMGPIOInvertIRQ( hDevice, FALSE ),
WMS_SUCCESS
);
/*
* Finally set it back to the original setting.
*/
WMTEST_CALL( WMWrite( hDevice, addFuncReg, originalVal ) );
}
}
WMTEST_END
/*-----------------------------------------------------------------------------
* Function: WMTestGPIOEnableGlobalWake
*
* Test WMGPIOEnableGlobalWake function.
*
* Parameters:
* hDevice handle to the device (from WMOpenDevice)
*
* Returns: WM_BOOL
* TRUE if it passed, FALSE if it failed.
*---------------------------------------------------------------------------*/
WMTEST_START( WMTestGPIOEnableGlobalWake( WM_DEVICE_HANDLE hDevice ) )
{
const WM_CHIPDEF *pChipDef;
WM_REGTYPE addFuncReg = 0;
WM_REGVAL originalVal;
/*
* Look up our chipdef.
*/
pChipDef = WMGetChipDef( hDevice );
WMTEST_NOTNULL( pChipDef );
switch ( pChipDef->deviceType )
{
case WM_CHIP_WM9712:
addFuncReg = WM97_ADD_FUN;
break;
case WM_CHIP_WM9713:
addFuncReg = WM9713_ADD_FUN1;
break;
default:
WMTEST_ASSERT( pChipDef->deviceType == 0 );
}
if ( addFuncReg )
{
/*
* Get the current setting.
*/
WMTEST_CALL( WMRead( hDevice, addFuncReg, &originalVal ) );
/*
* Set the global wake enable bit.
*/
WMTEST_CALL_STATUS( WMGPIOEnableGlobalWake( hDevice, TRUE ),
WMS_SUCCESS
);
/*
* Clear the global wake enable bit.
*/
WMTEST_CALL_STATUS( WMGPIOEnableGlobalWake( hDevice, FALSE ),
WMS_SUCCESS
);
/*
* Finally set it back to the original setting.
*/
WMTEST_CALL( WMWrite( hDevice, addFuncReg, originalVal ) );
}
}
WMTEST_END
/*-----------------------------------------------------------------------------
* Function: WMTestGPIOSetOutputLevel
*
* Test WMGPIOSetOutputLevel function.
*
* Parameters:
* hDevice handle to the device (from WMOpenDevice)
*
* Returns: WM_BOOL
* TRUE if it passed, FALSE if it failed.
*---------------------------------------------------------------------------*/
WMTEST_START( WMTestGPIOSetOutputLevel( WM_DEVICE_HANDLE hDevice ) )
{
const WM_CHIPDEF *pChipDef;
GPIOSetLevelTest *pTests = NULL;
int nTests = 0;
int test;
WM_REGVAL originalConfigVal;
/*
* Look up our chipdef.
*/
pChipDef = WMGetChipDef( hDevice );
WMTEST_NOTNULL( pChipDef );
switch ( pChipDef->deviceType )
{
case WM_CHIP_WM9712:
case WM_CHIP_WM9713:
pTests = s_GPIOSetLevelTest;
nTests = WM_ARRAY_COUNT( s_GPIOSetLevelTest );
break;
default:
WMTEST_ASSERT( pChipDef->deviceType == 0 );
}
if ( pTests )
{
/*
* Get the current setting.
*/
WMTEST_CALL( WMRead( hDevice, WM97_GPIO_PIN_CONFIG, &originalConfigVal ) );
/*
* Now run through each test.
*/
for ( test = 0; test < nTests; test++ )
{
WM_GPIO_PIN gpioPin;
unsigned short direction;
unsigned short level;
WMSTATUS expectedStatus;
gpioPin = pTests[test].gpioPin;
direction = pTests[test].direction;
level = pTests[test].level;
expectedStatus = pTests[test].expectedStatus;
/*
* Set the GPIO pin to be an input,
* but only for a valid GPIO pin.
*/
if ( WM_GPIO_NONE != gpioPin )
{
WMTEST_CALL( WMGPIOConfig( hDevice, gpioPin, direction ) );
}
/*
* Try set polarity.
*/
WMTEST_CALL_STATUS( WMGPIOSetOutputLevel( hDevice, gpioPin, level ),
expectedStatus
);
}
/*
* Finally set it back to the original setting.
*/
WMTEST_CALL( WMWrite( hDevice, WM97_GPIO_PIN_CONFIG, originalConfigVal ) );
}
}
WMTEST_END
/*-----------------------------------------------------------------------------
* Function: WMTestGPIOGetOutputLevel
*
* Test WMGPIOGetOutputLevel function.
*
* Parameters:
* hDevice handle to the device (from WMOpenDevice)
*
* Returns: WM_BOOL
* TRUE if it passed, FALSE if it failed.
*---------------------------------------------------------------------------*/
WMTEST_START( WMTestGPIOGetOutputLevel( WM_DEVICE_HANDLE hDevice ) )
{
const WM_CHIPDEF *pChipDef;
GPIOGetLevelTest *pTests = NULL;
int nTests = 0;
int test;
WM_REGVAL originalConfigVal;
/*
* Look up our chipdef.
*/
pChipDef = WMGetChipDef( hDevice );
WMTEST_NOTNULL( pChipDef );
switch ( pChipDef->deviceType )
{
case WM_CHIP_WM9712:
case WM_CHIP_WM9713:
pTests = s_GPIOGetLevelTest;
nTests = WM_ARRAY_COUNT( s_GPIOGetLevelTest );
break;
default:
WM_ASSERT( hDevice, pChipDef->deviceType == 0 );
}
if ( pTests )
{
/*
* Get the current setting.
*/
WMTEST_CALL( WMRead( hDevice,
WM97_GPIO_PIN_CONFIG,
&originalConfigVal
)
);
/*
* Now run through each test.
*/
for ( test = 0; test < nTests; test++ )
{
WM_GPIO_PIN gpioPin;
unsigned short level;
unsigned short actualLevel;
unsigned short expectedLevel;
gpioPin = pTests[test].gpioPin;
level = pTests[test].expectedLevel;
expectedLevel = pTests[test].expectedLevel;
WMTEST_CALL( WMGPIOConfig( hDevice, gpioPin, WM_GPIO_OUTPUT ) );
WMTEST_CALL( WMGPIOSetOutputLevel( hDevice, gpioPin, level ) );
/*
* Check to see if the GPIO output level is correct.
*/
WMTEST_CALL( WMGPIOGetOutputLevel( hDevice,
gpioPin,
&actualLevel
)
);
WMTEST_EQUALS( actualLevel, expectedLevel );
}
/*
* Finally set it back to the original setting.
*/
WMTEST_CALL( WMWrite( hDevice,
WM97_GPIO_PIN_CONFIG,
originalConfigVal
)
);
}
}
WMTEST_END
#if WM_AUTOTEST_GPIO_CONTROL_ADVANCED
/*-----------------------------------------------------------------------------
* Function: WMTestGPIOStatus
*
* Test WMGPIOIsSignalled and WMGPIOClearInput functions.
*
* Parameters:
* hDevice handle to the device (from WMOpenDevice)
* outputGPIO the GPIO to be tested as an output
* inputGPIO the GPIO to be tested as an input
*
* Returns: WM_BOOL
* TRUE if it passed, FALSE if it failed.
*---------------------------------------------------------------------------*/
WMTEST_START( WMTestGPIOStatus( WM_DEVICE_HANDLE hDevice,
WM_GPIO_PIN outputGPIO,
WM_GPIO_PIN inputGPIO ) )
{
WM_REGVAL originalConfigVal;
WM_REGVAL originalPolarityVal;
WM_REGVAL originalStickyVal;
WM_REGVAL originalWakeVal;
/*
* Get the current setting.
*/
WMTEST_CALL( WMRead( hDevice, WM97_GPIO_PIN_CONFIG, &originalConfigVal ) );
WMTEST_CALL( WMRead( hDevice, WM97_GPIO_PIN_POLARITY, &originalPolarityVal ) );
WMTEST_CALL( WMRead( hDevice, WM97_GPIO_STICKY, &originalStickyVal ) );
WMTEST_CALL( WMRead( hDevice, WM97_GPIO_WAKEUP, &originalWakeVal ) );
/*
* Configure the output GPIO and set it low.
*/
WMTEST_CALL( WMGPIOConfig( hDevice, outputGPIO, WM_GPIO_OUTPUT ) );
WMTEST_CALL( WMGPIOSetOutputLevel( hDevice, outputGPIO, WM_GPIO_OUTPUT_LOW ) );
/*
* Configure the input GPIO as an active high interrupt.
*/
WMTEST_CALL( WMGPIOConfig( hDevice, inputGPIO, WM_GPIO_INPUT ) );
WMTEST_CALL( WMGPIOSetInputPolarity( hDevice, inputGPIO, WM_GPIO_ACTIVE_HIGH ) );
/*
* Make sure that the interupt is cleared before we start.
*/
WMTEST_CALL_STATUS( WMGPIOClearInput( hDevice, inputGPIO ), WMS_SUCCESS );
/*
* Enable the sticky bit for the input GPIO.
*/
WMTEST_CALL( WMGPIOEnableSticky( hDevice, inputGPIO, TRUE ) );
/*
* Enable the wake up bit for the input GPIO.
*/
WMTEST_CALL( WMGPIOEnableWakeUp( hDevice, inputGPIO, TRUE ) );
/*
* Globally enable GPIO interrupts.
*/
WMTEST_CALL( WMGPIOEnableGlobalWake( hDevice, TRUE ) );
/*
* Check the status bit which should _not_ be set at this point.
*/
WMTEST_CALL_CHECK_RETURN( ( WMGPIOIsSignalled( hDevice, inputGPIO ) ), FALSE );
/*
* Set the output GPIO high.
*/
WMTEST_CALL( WMGPIOSetOutputLevel( hDevice, outputGPIO, WM_GPIO_OUTPUT_HIGH ) );
/*
* Wait a little while ...
*/
MicroSleep( hDevice, 100 );
/*
* Check the status bit which should be set at this point.
*/
WMTEST_CALL_CHECK_RETURN( ( WMGPIOIsSignalled( hDevice, inputGPIO ) ), TRUE );
/*
* Change the polarity of the input GPIO to active low.
*/
WMTEST_CALL( WMGPIOSetInputPolarity( hDevice, inputGPIO, WM_GPIO_ACTIVE_LOW ) );
/*
* Clear the status bit.
*/
WMTEST_CALL_STATUS( WMGPIOClearInput( hDevice, inputGPIO ), WMS_SUCCESS );
/*
* Wait a little while ...
*/
MicroSleep( hDevice, 100 );
/*
* Check the status bit which should _not_ be set at this point.
*/
WMTEST_CALL_CHECK_RETURN( ( WMGPIOIsSignalled( hDevice, inputGPIO ) ), FALSE );
/*
* Set the output GPIO low.
*/
WMTEST_CALL( WMGPIOSetOutputLevel( hDevice, outputGPIO, WM_GPIO_OUTPUT_LOW ) );
/*
* Wait a little while ...
*/
MicroSleep( hDevice, 100 );
/*
* Check the status bit which should be set at this point.
*/
WMTEST_CALL_CHECK_RETURN( ( WMGPIOIsSignalled( hDevice, inputGPIO ) ), TRUE );
/*
* Change the polarity of the input GPIO to active high.
*/
WMTEST_CALL( WMGPIOSetInputPolarity( hDevice, inputGPIO, WM_GPIO_ACTIVE_HIGH ) );
/*
* Cleared the status bit.
*/
WMTEST_CALL_STATUS( WMGPIOClearInput( hDevice, inputGPIO ), WMS_SUCCESS );
/*
* Wait a little while ...
*/
MicroSleep( hDevice, 100 );
/*
* Read the status bit which should _not_ be set at this point.
*/
WMTEST_CALL_CHECK_RETURN( ( WMGPIOIsSignalled( hDevice, inputGPIO ) ), FALSE );
/*
* Finally set it back to the original setting.
*/
WMTEST_CALL( WMWrite( hDevice, WM97_GPIO_PIN_CONFIG, originalConfigVal ) );
WMTEST_CALL( WMWrite( hDevice, WM97_GPIO_PIN_POLARITY, originalPolarityVal ) );
WMTEST_CALL( WMWrite( hDevice, WM97_GPIO_STICKY, originalStickyVal ) );
WMTEST_CALL( WMWrite( hDevice, WM97_GPIO_WAKEUP, originalWakeVal ) );
}
WMTEST_END
#endif /* WM_AUTOTEST_GPIO_CONTROL_ADVANCED */
#endif /* WM_TESTING && WM_GPIO_CONTROL && WM_GPIO_CONTROL */
/*------------------------------ END OF FILE ---------------------------------*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -