Index: App/Contollers/Buttons.c =================================================================== diff -u -r0cb75584d8a588f5392a5c54343c4ebca5079d40 -r614cd0625ac1f98edea2fe3ab2c3d0005f6fc8e0 --- App/Contollers/Buttons.c (.../Buttons.c) (revision 0cb75584d8a588f5392a5c54343c4ebca5079d40) +++ App/Contollers/Buttons.c (.../Buttons.c) (revision 614cd0625ac1f98edea2fe3ab2c3d0005f6fc8e0) @@ -30,9 +30,18 @@ NUM_OF_BUTTON_STATES } BUTTON_STATE_T; +typedef enum Button_Self_Test_States +{ + BUTTON_SELF_TEST_STATE_START = 0, + BUTTON_SELF_TEST_STATE_IN_PROGRESS, + BUTTON_SELF_TEST_STATE_COMPLETE, + NUM_OF_BUTTON_SELF_TEST_STATES +} BUTTON_SELF_TEST_STATE_T; + #define OFF_REQUEST_PULSE_COUNT 4 #define OFF_REQUEST_PULSE_INTVL 50 // ms #define STOP_BUTTON_PENDING_TIMEOUT 500 // ms +#define STUCK_BUTTON_TIMEOUT 1000 // ms // ********** private data ********** @@ -48,6 +57,9 @@ static U32 offRequestPulseCount = 0; static U32 offRequestPulseTimer = 0; +static BUTTON_SELF_TEST_STATE_T buttonSelfTestState = BUTTON_SELF_TEST_STATE_START; +static U32 buttonSelfTestTimerCount = 0; + // ********** private function prototypes ********** static void handleOffButtonProcessing( void ); @@ -76,6 +88,9 @@ offRequestPulseCount = 0; offRequestPulseTimer = 0; + + buttonSelfTestState = BUTTON_SELF_TEST_STATE_START; + buttonSelfTestTimerCount = 0; } /************************************************************************* @@ -180,6 +195,57 @@ } /************************************************************************* + * @brief execStuckButtonTest + * The execStuckButtonTest function executes the stuck button test. \n + * This function should be called periodically until a pass or fail \n + * result is returned. + * @details + * Inputs : + * Outputs : + * @param none + * @return in progress, passed, or failed + *************************************************************************/ +SELF_TEST_STATUS_T execStuckButtonTest( void ) +{ + SELF_TEST_STATUS_T result = SELF_TEST_STATUS_IN_PROGRESS; + + switch ( buttonSelfTestState ) + { + case BUTTON_SELF_TEST_STATE_START: + buttonSelfTestState = BUTTON_SELF_TEST_STATE_IN_PROGRESS; + buttonSelfTestTimerCount = getMSTimerCount(); + // no break here so we pass through directly to in progress processing + + case BUTTON_SELF_TEST_STATE_IN_PROGRESS: + if ( ( offButtonState == BUTTON_STATE_RELEASED ) && ( stopButtonState == BUTTON_STATE_RELEASED ) ) + { + result = SELF_TEST_STATUS_PASSED; + buttonSelfTestState = BUTTON_SELF_TEST_STATE_COMPLETE; + } + else if ( TRUE == didTimeout( buttonSelfTestTimerCount, STUCK_BUTTON_TIMEOUT ) ) + { + result = SELF_TEST_STATUS_FAILED; + // TODO - trigger stuck button POST failure + buttonSelfTestState = BUTTON_SELF_TEST_STATE_COMPLETE; + } + // else just stay in progress and wait for next call + break; + + case BUTTON_SELF_TEST_STATE_COMPLETE: + // if we get called in this state, assume we're doing self test again + buttonSelfTestState = BUTTON_SELF_TEST_STATE_START; + break; + + default: + result = SELF_TEST_STATUS_FAILED; + // TODO - s/w fault + break; + } + + return result; +} + +/************************************************************************* * @brief isCurrentOpModeOkToTurnOff * The isCurrentOpModeOkToTurnOff function determines whether the system can \n * be turned off in current operation mode.