📄 wmgpiotests.c
字号:
WM_REGVAL originalConfigVal, originalPolarityVal;
/*
* Look up our chipdef.
*/
pChipDef = WMGetChipDef( hDevice );
WMTEST_NOTNULL( pChipDef );
switch ( pChipDef->deviceType )
{
case WM_CHIP_WM9712:
case WM_CHIP_WM9713:
pTests = s_GPIOPolarityTest;
nTests = WM_ARRAY_COUNT( s_GPIOPolarityTest );
break;
default:
WMTEST_ASSERT( pChipDef->deviceType == 0 );
}
if ( pTests )
{
/*
* Get the current setting.
*/
WMTEST_CALL( WMRead( hDevice, WM97_GPIO_PIN_CONFIG, &originalConfigVal ) );
WMTEST_CALL( WMRead( hDevice, WM97_GPIO_PIN_POLARITY, &originalPolarityVal ) );
/*
* Now run through each test.
*/
for ( test = 0; test < nTests; test++ )
{
WM_GPIO_PIN gpioPin;
unsigned short direction;
unsigned short polarity;
WMSTATUS expectedStatus;
gpioPin = pTests[test].gpioPin;
direction = pTests[test].direction;
polarity = pTests[test].polarity;
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( WMGPIOSetInputPolarity( hDevice, gpioPin, polarity ),
expectedStatus
);
}
/*
* 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_END
/*-----------------------------------------------------------------------------
* Function: WMTestGPIOEnableSticky
*
* Test WMGPIOEnableSticky function.
*
* Parameters:
* hDevice handle to the device (from WMOpenDevice)
*
* Returns: WM_BOOL
* TRUE if it passed, FALSE if it failed.
*---------------------------------------------------------------------------*/
WMTEST_START( WMTestGPIOEnableSticky( WM_DEVICE_HANDLE hDevice ) )
{
const WM_CHIPDEF *pChipDef;
GPIODirectionTest *pTests = NULL;
int nTests = 0;
int test;
WM_REGVAL originalConfigVal, originalStickyVal;
/*
* Look up our chipdef.
*/
pChipDef = WMGetChipDef( hDevice );
WMTEST_NOTNULL( pChipDef );
switch ( pChipDef->deviceType )
{
case WM_CHIP_WM9712:
case WM_CHIP_WM9713:
pTests = s_GPIODirectionTest;
nTests = WM_ARRAY_COUNT( s_GPIODirectionTest );
break;
default:
WMTEST_ASSERT( pChipDef->deviceType == 0 );
}
if ( pTests )
{
/*
* Get the current setting.
*/
WMTEST_CALL( WMRead( hDevice, WM97_GPIO_PIN_CONFIG, &originalConfigVal ) );
WMTEST_CALL( WMRead( hDevice, WM97_GPIO_PIN_STICKY, &originalStickyVal ) );
/*
* Now run through each test.
*/
for ( test = 0; test < nTests; test++ )
{
WM_GPIO_PIN gpioPin;
WM_USHORT direction;
WMSTATUS expectedStatus;
gpioPin = pTests[test].gpioPin;
direction = pTests[test].direction;
expectedStatus = pTests[test].expectedStatus;
/*
* Set the GPIO pin direction,
* but only for a valid GPIO pin.
*/
if ( WM_GPIO_NONE != gpioPin )
{
WMTEST_CALL( WMGPIOConfig( hDevice, gpioPin, direction ) );
}
/*
* Try set the sticky bit.
*/
WMTEST_CALL_STATUS( WMGPIOEnableSticky( hDevice, gpioPin, TRUE ),
expectedStatus
);
/*
* Try clear the sticky bit.
*/
WMTEST_CALL_STATUS( WMGPIOEnableSticky( hDevice, gpioPin, FALSE ),
expectedStatus
);
}
/*
* Finally set it back to the original setting.
*/
WMTEST_CALL( WMWrite( hDevice, WM97_GPIO_PIN_CONFIG, originalConfigVal ) );
WMTEST_CALL( WMWrite( hDevice, WM97_GPIO_PIN_STICKY, originalStickyVal ) );
}
}
WMTEST_END
/*-----------------------------------------------------------------------------
* Function: WMTestGPIOWakeUp
*
* Test WMGPIOEnableWakeUp function.
*
* Parameters:
* hDevice handle to the device (from WMOpenDevice)
*
* Returns: WM_BOOL
* TRUE if it passed, FALSE if it failed.
*---------------------------------------------------------------------------*/
WMTEST_START( WMTestGPIOWakeUp( WM_DEVICE_HANDLE hDevice ) )
{
const WM_CHIPDEF *pChipDef;
GPIODirectionTest *pTests = NULL;
int nTests = 0;
int test;
WM_REGVAL originalConfigVal, originalWakeVal;
/*
* Look up our chipdef.
*/
pChipDef = WMGetChipDef( hDevice );
WMTEST_NOTNULL( pChipDef );
switch ( pChipDef->deviceType )
{
case WM_CHIP_WM9712:
case WM_CHIP_WM9713:
pTests = s_GPIODirectionTest;
nTests = WM_ARRAY_COUNT( s_GPIODirectionTest );
break;
default:
WMTEST_ASSERT( pChipDef->deviceType == 0 );
}
if ( pTests )
{
/*
* Get the current setting.
*/
WMTEST_CALL( WMRead( hDevice, WM97_GPIO_PIN_CONFIG, &originalConfigVal ) );
WMTEST_CALL( WMRead( hDevice, WM97_GPIO_PIN_WAKEUP, &originalWakeVal ) );
/*
* Now run through each test.
*/
for ( test = 0; test < nTests; test++ )
{
WM_GPIO_PIN gpioPin;
unsigned short direction;
WMSTATUS expectedStatus;
gpioPin = pTests[test].gpioPin;
direction = pTests[test].direction;
expectedStatus = pTests[test].expectedStatus;
/*
* Set the GPIO pin direction,
* but only for a valid GPIO pin.
*/
if ( WM_GPIO_NONE != gpioPin )
{
WMTEST_CALL( WMGPIOConfig( hDevice, gpioPin, direction ) );
}
/*
* Try set the wake-up bit.
*/
WMTEST_CALL_STATUS( WMGPIOEnableWakeUp( hDevice, gpioPin, TRUE ),
expectedStatus
);
/*
* Try clear the wake-up bit.
*/
WMTEST_CALL_STATUS( WMGPIOEnableWakeUp( hDevice, gpioPin, FALSE ),
expectedStatus
);
}
/*
* Finally set it back to the original setting.
*/
WMTEST_CALL( WMWrite( hDevice, WM97_GPIO_PIN_CONFIG, originalConfigVal ) );
WMTEST_CALL( WMWrite( hDevice, WM97_GPIO_PIN_WAKEUP, originalWakeVal ) );
}
}
WMTEST_END
/*-----------------------------------------------------------------------------
* Function: WMTestGPIOHasAltFunc
*
* Test WMGPIOHasAltFunc function.
*
* Parameters:
* hDevice handle to the device (from WMOpenDevice)
*
* Returns: WM_BOOL
* TRUE if it passed, FALSE if it failed.
*---------------------------------------------------------------------------*/
WMTEST_START( WMTestGPIOHasAltFunc( WM_DEVICE_HANDLE hDevice ) )
{
const WM_CHIPDEF *pChipDef;
GPIOHasAltFuncTest *pTests = NULL;
int nTests = 0;
int test;
/*
* Look up our chipdef.
*/
pChipDef = WMGetChipDef( hDevice );
WMTEST_NOTNULL( pChipDef );
switch ( pChipDef->deviceType )
{
case WM_CHIP_WM9712:
case WM_CHIP_WM9713:
pTests = s_GPIOHasAltFuncTest;
nTests = WM_ARRAY_COUNT( s_GPIOHasAltFuncTest );
break;
default:
WMTEST_ASSERT( pChipDef->deviceType == 0 );
}
if ( pTests )
{
/*
* Now run through each test.
*/
for ( test = 0; test < nTests; test++ )
{
WM_GPIO_PIN gpioPin;
WM_BOOL expectedStatus;
gpioPin = pTests[test].gpioPin;
expectedStatus = pTests[test].expectedRetVal;
/*
* Check to see if this GPIO can be used as an alternate function.
*/
WMTEST_CALL_CHECK_RETURN( WMGPIOHasAltFunc( hDevice, gpioPin ),
expectedStatus
);
}
}
}
WMTEST_END
/*-----------------------------------------------------------------------------
* Function: WMTestGPIOHasVirtualGPIO
*
* Test WMGPIOHasVirtualGPIO function.
*
* Parameters:
* hDevice handle to the device (from WMOpenDevice)
*
* Returns: WM_BOOL
* TRUE if it passed, FALSE if it failed.
*---------------------------------------------------------------------------*/
WMTEST_START( WMTestGPIOHasVirtualGPIO( WM_DEVICE_HANDLE hDevice ) )
{
const WM_CHIPDEF *pChipDef;
GPIOHasVirtualGPIOTest *pTests = NULL;
int nTests = 0;
int test;
/*
* Look up our chipdef.
*/
pChipDef = WMGetChipDef( hDevice );
WMTEST_NOTNULL( pChipDef );
switch ( pChipDef->deviceType )
{
case WM_CHIP_WM9712:
case WM_CHIP_WM9713:
pTests = s_GPIOHasVirtualGPIOTest;
nTests = WM_ARRAY_COUNT( s_GPIOHasVirtualGPIOTest );
break;
default:
WMTEST_ASSERT( pChipDef->deviceType == 0 );
}
if ( pTests )
{
/*
* Now run through each test.
*/
for ( test = 0; test < nTests; test++ )
{
WM_GPIO_PIN gpioPin;
WM_BOOL expectedStatus;
gpioPin = pTests[test].gpioPin;
expectedStatus = pTests[test].expectedRetVal;
/*
* Check to see if this GPIO can be used as an alternate function.
*/
WMTEST_CALL_CHECK_RETURN( WMGPIOHasVirtualGPIO( hDevice, gpioPin ),
expectedStatus
);
}
}
}
WMTEST_END
/*-----------------------------------------------------------------------------
* Function: WMTestGPIOEnableAlternateFunction
*
* Test WMGPIOEnableAlternateFunction function.
*
* Parameters:
* hDevice handle to the device (from WMOpenDevice)
*
* Returns: WM_BOOL
* TRUE if it passed, FALSE if it failed.
*---------------------------------------------------------------------------*/
WMTEST_START( WMTestGPIOEnableAlternateFunction( WM_DEVICE_HANDLE hDevice ) )
{
const WM_CHIPDEF *pChipDef;
GPIOAltFuncTest *pTests = NULL;
int nTests = 0;
int test;
WM_REGVAL originalConfigVal, originalAltVal;
/*
* Look up our chipdef.
*/
pChipDef = WMGetChipDef( hDevice );
WMTEST_NOTNULL( pChipDef );
switch ( pChipDef->deviceType )
{
case WM_CHIP_WM9712:
case WM_CHIP_WM9713:
pTests = s_GPIOAltFuncTest;
nTests = WM_ARRAY_COUNT( s_GPIOAltFuncTest );
break;
default:
WMTEST_ASSERT( pChipDef->deviceType == 0 );
}
if ( pTests )
{
/*
* Get the current setting.
*/
WMTEST_CALL( WMRead( hDevice, WM97_GPIO_PIN_CONFIG, &originalConfigVal ) );
WMTEST_CALL( WMRead( hDevice, WM97_GPIO_PIN_ASSIGN, &originalAltVal ) );
/*
* Now run through each test.
*/
for ( test = 0; test < nTests; test++ )
{
WM_GPIO_PIN gpioPin;
unsigned short direction;
WMSTATUS expectedStatus;
gpioPin = pTests[test].gpioPin;
direction = pTests[test].direction;
expectedStatus = pTests[test].expectedStatus;
/*
* Set the GPIO pin direction,
* but only if the GPIO pin is valid and can
* be set up as an alternate function.
*/
if ( ( WM_GPIO_NONE != gpioPin ) &&
( WMS_RETURN_TRUE == WMGPIOHasAltFunc( hDevice, gpioPin) )
)
{
WMTEST_CALL( WMGPIOConfig( hDevice, gpioPin, direction ) );
}
/*
* Try set the alternate function bit.
*/
WMTEST_CALL_STATUS( WMGPIOEnableAlternateFunction( hDevice, gpioPin, TRUE ),
expectedStatus
);
/*
* Try clear the alternate function bit.
*/
WMTEST_CALL_STATUS( WMGPIOEnableAlternateFunction( hDevice, gpioPin, FALSE ),
expectedStatus
);
}
/*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -