Index: .settings/org.eclipse.core.resources.prefs =================================================================== diff -u -r9685f9c824cfa92bf2aabbc5f34111a7ee477dba -r614cd0625ac1f98edea2fe3ab2c3d0005f6fc8e0 --- .settings/org.eclipse.core.resources.prefs (.../org.eclipse.core.resources.prefs) (revision 9685f9c824cfa92bf2aabbc5f34111a7ee477dba) +++ .settings/org.eclipse.core.resources.prefs (.../org.eclipse.core.resources.prefs) (revision 614cd0625ac1f98edea2fe3ab2c3d0005f6fc8e0) @@ -5,6 +5,8 @@ encoding//Debug/App/Drivers/subdir_vars.mk=UTF-8 encoding//Debug/App/Modes/subdir_rules.mk=UTF-8 encoding//Debug/App/Modes/subdir_vars.mk=UTF-8 +encoding//Debug/App/Services/subdir_rules.mk=UTF-8 +encoding//Debug/App/Services/subdir_vars.mk=UTF-8 encoding//Debug/App/Tasks/subdir_rules.mk=UTF-8 encoding//Debug/App/Tasks/subdir_vars.mk=UTF-8 encoding//Debug/makefile=UTF-8 Index: App/Common.h =================================================================== diff -u -r894b734327eb6e7cfa6bf651623576bc10214195 -r614cd0625ac1f98edea2fe3ab2c3d0005f6fc8e0 --- App/Common.h (.../Common.h) (revision 894b734327eb6e7cfa6bf651623576bc10214195) +++ App/Common.h (.../Common.h) (revision 614cd0625ac1f98edea2fe3ab2c3d0005f6fc8e0) @@ -40,6 +40,14 @@ NUM_OF_PIN_SIGNAL_STATES } PIN_SIGNAL_STATE_T; +typedef enum Self_Test_Status +{ + SELF_TEST_STATUS_IN_PROGRESS = 0, + SELF_TEST_STATUS_PASSED, + SELF_TEST_STATUS_FAILED, + NUM_OF_SELF_TEST_STATUS +} SELF_TEST_STATUS_T; + // *** Common Definitions *** #define NEARLY_ZERO 0.00001 Index: App/Contollers/AlarmLamp.c =================================================================== diff -u -r1748019d93f9e95a125b0c6181c695b17fb63241 -r614cd0625ac1f98edea2fe3ab2c3d0005f6fc8e0 --- App/Contollers/AlarmLamp.c (.../AlarmLamp.c) (revision 1748019d93f9e95a125b0c6181c695b17fb63241) +++ App/Contollers/AlarmLamp.c (.../AlarmLamp.c) (revision 614cd0625ac1f98edea2fe3ab2c3d0005f6fc8e0) @@ -17,6 +17,7 @@ #include "Common.h" #include "CPLD.h" #include "TaskGeneral.h" +#include "Timers.h" #include "AlarmLamp.h" // ********** private definitions ********** @@ -37,6 +38,18 @@ LAMP_STATE_T red[NUM_OF_LAMP_STATES]; // red lamp state 1 and 2 }; +typedef enum Alarm_Lamp_Self_Test_States +{ + ALARM_LAMP_SELF_TEST_STATE_START = 0, + ALARM_LAMP_SELF_TEST_STATE_RED, + ALARM_LAMP_SELF_TEST_STATE_YELLOW, + ALARM_LAMP_SELF_TEST_STATE_GREEN, + ALARM_LAMP_SELF_TEST_STATE_COMPLETE, + NUM_OF_ALARM_LAMP_SELF_TEST_STATES +} ALARM_LAMP_SELF_TEST_STATE_T; + +#define POST_LAMP_STEP_TIME_MS 1000 // ms for each lamp color + // ********** private data ********** static LAMP_PATTERN_T currentLampPattern = LAMP_PATTERN_OFF; @@ -54,6 +67,9 @@ { { 0, 0 }, { LAMP_STATE_OFF, LAMP_STATE_OFF }, { LAMP_STATE_OFF, LAMP_STATE_OFF }, { LAMP_STATE_OFF, LAMP_STATE_OFF } } // LAMP_PATTERN_MANUAL }; +static ALARM_LAMP_SELF_TEST_STATE_T alarmLampSelfTestState = ALARM_LAMP_SELF_TEST_STATE_START; +static U32 alarmLampSelfTestStepTimerCount = 0; + // ********** private function prototypes ********** static void setAlarmLampToPatternStep( void ); @@ -73,6 +89,9 @@ pendingLampPattern = LAMP_PATTERN_OFF; currentLampPatternStep = 0; lampPatternStepTimer = 0; + + alarmLampSelfTestState = ALARM_LAMP_SELF_TEST_STATE_START; + alarmLampSelfTestStepTimerCount = 0; } /************************************************************************* @@ -157,6 +176,72 @@ } /************************************************************************* + * @brief execAlarmLampTest + * The execAlarmLampTest function executes the alarm lamp 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 execAlarmLampTest( void ) +{ + SELF_TEST_STATUS_T result = SELF_TEST_STATUS_IN_PROGRESS; + + switch ( alarmLampSelfTestState ) + { + case ALARM_LAMP_SELF_TEST_STATE_START: + alarmLampSelfTestState = ALARM_LAMP_SELF_TEST_STATE_RED; + alarmLampSelfTestStepTimerCount = getMSTimerCount(); + setCPLDLampRed( PIN_SIGNAL_HIGH ); + break; + + case ALARM_LAMP_SELF_TEST_STATE_RED: + if ( TRUE == didTimeout( alarmLampSelfTestStepTimerCount, POST_LAMP_STEP_TIME_MS ) ) + { + alarmLampSelfTestState = ALARM_LAMP_SELF_TEST_STATE_YELLOW; + alarmLampSelfTestStepTimerCount = getMSTimerCount(); + setCPLDLampRed( PIN_SIGNAL_LOW ); + setCPLDLampYellow( PIN_SIGNAL_HIGH ); + } + break; + + case ALARM_LAMP_SELF_TEST_STATE_YELLOW: + if ( TRUE == didTimeout( alarmLampSelfTestStepTimerCount, POST_LAMP_STEP_TIME_MS ) ) + { + alarmLampSelfTestState = ALARM_LAMP_SELF_TEST_STATE_GREEN; + alarmLampSelfTestStepTimerCount = getMSTimerCount(); + setCPLDLampYellow( PIN_SIGNAL_LOW ); + setCPLDLampGreen( PIN_SIGNAL_HIGH ); + } + break; + + case ALARM_LAMP_SELF_TEST_STATE_GREEN: + if ( TRUE == didTimeout( alarmLampSelfTestStepTimerCount, POST_LAMP_STEP_TIME_MS ) ) + { + alarmLampSelfTestState = ALARM_LAMP_SELF_TEST_STATE_COMPLETE; + setCPLDLampGreen( PIN_SIGNAL_LOW ); + result = SELF_TEST_STATUS_PASSED; + } + break; + + case ALARM_LAMP_SELF_TEST_STATE_COMPLETE: + // if we get called in this state, assume we're doing self test again + alarmLampSelfTestState = ALARM_LAMP_SELF_TEST_STATE_START; + break; + + default: + result = SELF_TEST_STATUS_FAILED; + // TODO - s/w fault + break; + } + + return result; +} + +/************************************************************************* * @brief setAlarmLampToPatternStep * The setAlarmLampToPatternStep function sets the lamps according to the \n * current lamp pattern and lamp pattern step. Index: App/Contollers/AlarmLamp.h =================================================================== diff -u -radd7eb956a7d2c124434541e1f06ca5ae158716f -r614cd0625ac1f98edea2fe3ab2c3d0005f6fc8e0 --- App/Contollers/AlarmLamp.h (.../AlarmLamp.h) (revision add7eb956a7d2c124434541e1f06ca5ae158716f) +++ App/Contollers/AlarmLamp.h (.../AlarmLamp.h) (revision 614cd0625ac1f98edea2fe3ab2c3d0005f6fc8e0) @@ -17,6 +17,8 @@ #ifndef __ALARM_LAMP_H__ #define __ALARM_LAMP_H__ +#include "Common.h" + // ********** public definitions ********** typedef enum LampPatternEnum @@ -37,5 +39,6 @@ void execAlarmLamp( void ); void requestAlarmLampPattern( LAMP_PATTERN_T lampPattern ); LAMP_PATTERN_T getCurrentAlarmLampPattern( void ); +SELF_TEST_STATUS_T execAlarmLampTest( void ); #endif 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. Index: App/Contollers/Buttons.h =================================================================== diff -u -r894b734327eb6e7cfa6bf651623576bc10214195 -r614cd0625ac1f98edea2fe3ab2c3d0005f6fc8e0 --- App/Contollers/Buttons.h (.../Buttons.h) (revision 894b734327eb6e7cfa6bf651623576bc10214195) +++ App/Contollers/Buttons.h (.../Buttons.h) (revision 614cd0625ac1f98edea2fe3ab2c3d0005f6fc8e0) @@ -35,5 +35,6 @@ BOOL isStopButtonPressed( void ); BOOL isButtonPressedRaw( BUTTON_T button ); void userConfirmOffButton( void ); +SELF_TEST_STATUS_T execStuckButtonTest( void ); #endif Index: App/Modes/ModeInitPOST.c =================================================================== diff -u -radd7eb956a7d2c124434541e1f06ca5ae158716f -r614cd0625ac1f98edea2fe3ab2c3d0005f6fc8e0 --- App/Modes/ModeInitPOST.c (.../ModeInitPOST.c) (revision add7eb956a7d2c124434541e1f06ca5ae158716f) +++ App/Modes/ModeInitPOST.c (.../ModeInitPOST.c) (revision 614cd0625ac1f98edea2fe3ab2c3d0005f6fc8e0) @@ -19,12 +19,33 @@ #include "Buttons.h" #include "CPLD.h" #include "OperationModes.h" +#include "WatchdogMgmt.h" #include "ModeInitPOST.h" +// ********** private definitions ********** + +typedef enum POST_States +{ + POST_STATE_START = 0, + POST_STATE_ALARM_LAMP, + POST_STATE_STUCK_BUTTON, + POST_STATE_WATCHDOG, + POST_STATE_COMPLETED, + POST_STATE_FAILED, + NUM_OF_POST_STATES +} POST_STATE_T; + // ********** private data ********** +static POST_STATE_T postState = POST_STATE_START; +static BOOL postCompleted = FALSE; +static BOOL postPassed = FALSE; +static BOOL tempPOSTPassed = TRUE; + // ********** private function prototypes ********** +static POST_STATE_T handlePOSTStatus( SELF_TEST_STATUS_T testStatus ); + /************************************************************************* * @brief initInitAndPOSTMode * The initInitAndPOSTMode function initializes the Initialize & POST Mode module. @@ -36,6 +57,10 @@ *************************************************************************/ void initInitAndPOSTMode( void ) { + postState = POST_STATE_START; + postCompleted = FALSE; + postPassed = FALSE; + tempPOSTPassed = TRUE; } /************************************************************************* @@ -52,7 +77,7 @@ { // temporary test code - solid red alarm lamp requestAlarmLampPattern( LAMP_PATTERN_MANUAL ); - setCPLDLampRed( PIN_SIGNAL_HIGH ); + //setCPLDLampRed( PIN_SIGNAL_HIGH ); } /************************************************************************* @@ -66,11 +91,121 @@ *************************************************************************/ void execInitAndPOSTMode( void ) { - BOOL stop = isStopButtonPressed(); + SELF_TEST_STATUS_T testStatus = SELF_TEST_STATUS_IN_PROGRESS; + // // TODO - temporary test code - remove later + BOOL stop = isStopButtonPressed(); if ( TRUE == stop ) { requestNewOperationMode( MODE_STAN ); } + + // execute current POST state + switch ( postState ) + { + case POST_STATE_START: + postState = POST_STATE_ALARM_LAMP; + break; + + case POST_STATE_ALARM_LAMP: + testStatus = execAlarmLampTest(); + postState = handlePOSTStatus( testStatus ); + break; + + case POST_STATE_STUCK_BUTTON: + testStatus = execStuckButtonTest(); + postState = handlePOSTStatus( testStatus ); + break; + + case POST_STATE_WATCHDOG: + testStatus = execWatchdogTest(); + handlePOSTStatus( testStatus ); // ignoring return value because last test + if ( TRUE == tempPOSTPassed ) + { + postState = POST_STATE_COMPLETED; + } + else + { + postState = POST_STATE_FAILED; + } + break; + + case POST_STATE_COMPLETED: + // set overall HD POST status to "passed" + postPassed = TRUE; + // set overall HD POST completed status to TRUE + postCompleted = TRUE; + // TODO - send POST status on CAN + // go to standby mode + requestNewOperationMode( MODE_STAN ); + break; + + case POST_STATE_FAILED: + // TODO - send POST status on CAN + // will want POST faults to wait for us to get here before sending us to fault mode + requestNewOperationMode( MODE_FAUL ); + break; + + default: + postState = POST_STATE_FAILED; + // TODO - s/w fault + break; + } } +/************************************************************************* + * @brief isPOSTCompleted + * The isPOSTCompleted function determines whether all HD POST have \n + * been run and completed. If true, call the isPOSTPassed() to see final \n + * result (pass/fail). + * @details + * Inputs : postCompleted + * Outputs : none + * @param none + * @return true if all HD POST tests have completed, false if not + *************************************************************************/ +BOOL isPOSTCompleted( void ) +{ + return postCompleted; +} + +/************************************************************************* + * @brief isPOSTPassed + * The isPOSTPassed function determines whether all HD POST have passed. \n + * Call this function after POST is complete (call isPOSTCompleted function). + * @details + * Inputs : postPassed + * Outputs : none + * @param none + * @return true if all HD POST tests have passed, false if not + *************************************************************************/ +BOOL isPOSTPassed( void ) +{ + return postPassed; +} + +/************************************************************************* + * @brief handlePOSTStatus + * The handlePOSTStatus function handles a status result returned by a + * POST function. + * @details + * Inputs : postPassed + * Outputs : none + * @param testStatus + * @return recommended next POST state + *************************************************************************/ +static POST_STATE_T handlePOSTStatus( SELF_TEST_STATUS_T testStatus ) +{ + POST_STATE_T result = postState; + + if ( ( testStatus == SELF_TEST_STATUS_PASSED ) || ( testStatus == SELF_TEST_STATUS_FAILED ) ) + { + result = (POST_STATE_T)((int)postState + 1); // move on to next POST test + if ( testStatus == SELF_TEST_STATUS_FAILED ) + { + tempPOSTPassed = FALSE; + } + } + + return result; +} Index: App/Modes/ModeInitPOST.h =================================================================== diff -u -r894b734327eb6e7cfa6bf651623576bc10214195 -r614cd0625ac1f98edea2fe3ab2c3d0005f6fc8e0 --- App/Modes/ModeInitPOST.h (.../ModeInitPOST.h) (revision 894b734327eb6e7cfa6bf651623576bc10214195) +++ App/Modes/ModeInitPOST.h (.../ModeInitPOST.h) (revision 614cd0625ac1f98edea2fe3ab2c3d0005f6fc8e0) @@ -19,8 +19,10 @@ // ********** private function prototypes ********** -void initInitAndPOSTMode( void ); // initialize this module -void transitionToInitAndPOSTMode( void ); // prepares for transition to init. & POST mode -void execInitAndPOSTMode( void ); // execute the init. & POST mode state machine (call from OperationModes) +void initInitAndPOSTMode( void ); // initialize this module +void transitionToInitAndPOSTMode( void ); // prepares for transition to init. & POST mode +void execInitAndPOSTMode( void ); // execute the init. & POST mode state machine (call from OperationModes) +BOOL isPOSTCompleted( void ); +BOOL isPOSTPassed( void ); #endif Index: App/Services/WatchdogMgmt.c =================================================================== diff -u -r0cb75584d8a588f5392a5c54343c4ebca5079d40 -r614cd0625ac1f98edea2fe3ab2c3d0005f6fc8e0 --- App/Services/WatchdogMgmt.c (.../WatchdogMgmt.c) (revision 0cb75584d8a588f5392a5c54343c4ebca5079d40) +++ App/Services/WatchdogMgmt.c (.../WatchdogMgmt.c) (revision 614cd0625ac1f98edea2fe3ab2c3d0005f6fc8e0) @@ -23,12 +23,25 @@ #define MIN_WATCHDOG_PET_INTERVAL_MS 45 +typedef enum Button_Self_Test_States +{ + WATCHDOG_SELF_TEST_STATE_START = 0, + WATCHDOG_SELF_TEST_STATE_IN_PROGRESS, + WATCHDOG_SELF_TEST_STATE_COMPLETE, + NUM_OF_BUTTON_SELF_TEST_STATES +} BUTTON_SELF_TEST_STATE_T; + +#define WATCHDOG_POST_TIMEOUT_MS 100 // ms + // ********** private data ********** static BOOL watchdogExpired = FALSE; static BOOL lastWatchdogPetTime = 0; static BOOL watchdogTaskCheckedIn[NUM_OF_TASKS]; +static BUTTON_SELF_TEST_STATE_T watchdogSelfTestState = WATCHDOG_SELF_TEST_STATE_START; +static U32 watchdogSelfTestTimerCount = 0; + // ********** private function prototypes ********** static void resetWDTaskCheckIns( void ); @@ -48,6 +61,8 @@ { watchdogExpired = FALSE; lastWatchdogPetTime = getMSTimerCount(); + watchdogSelfTestState = WATCHDOG_SELF_TEST_STATE_START; + watchdogSelfTestTimerCount = 0; resetWDTaskCheckIns(); } @@ -118,6 +133,59 @@ } /************************************************************************* + * @brief execWatchdogTest + * The execWatchdogTest function executes the watchdog 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 execWatchdogTest( void ) +{ + SELF_TEST_STATUS_T result = SELF_TEST_STATUS_IN_PROGRESS; + + switch ( watchdogSelfTestState ) + { + case WATCHDOG_SELF_TEST_STATE_START: + watchdogSelfTestState = WATCHDOG_SELF_TEST_STATE_IN_PROGRESS; + watchdogSelfTestTimerCount = getMSTimerCount(); + // no break here so we pass through directly to in progress processing + + case WATCHDOG_SELF_TEST_STATE_IN_PROGRESS: + while ( FALSE == didTimeout( watchdogSelfTestTimerCount, WATCHDOG_POST_TIMEOUT_MS ) ) + { + // waiting here for w.d. test period to prevent this task from checking in - watchdog should expire + } + if ( getCPLDWatchdogExpired() == PIN_SIGNAL_HIGH ) + { + result = SELF_TEST_STATUS_PASSED; + } + else + { + result = SELF_TEST_STATUS_FAILED; + // TODO - trigger watchdog POST failure + } + watchdogSelfTestState = WATCHDOG_SELF_TEST_STATE_COMPLETE; + break; + + case WATCHDOG_SELF_TEST_STATE_COMPLETE: + // if we get called in this state, assume we're doing self test again + watchdogSelfTestState = WATCHDOG_SELF_TEST_STATE_START; + break; + + default: + result = SELF_TEST_STATUS_FAILED; + // TODO - s/w fault + break; + } + + return result; +} + +/************************************************************************* * @brief resetWDTaskCheckIns * The resetWDTaskCheckIns function resets the task check-ins with the watchdog. * @details Index: App/Services/WatchdogMgmt.h =================================================================== diff -u -radd7eb956a7d2c124434541e1f06ca5ae158716f -r614cd0625ac1f98edea2fe3ab2c3d0005f6fc8e0 --- App/Services/WatchdogMgmt.h (.../WatchdogMgmt.h) (revision add7eb956a7d2c124434541e1f06ca5ae158716f) +++ App/Services/WatchdogMgmt.h (.../WatchdogMgmt.h) (revision 614cd0625ac1f98edea2fe3ab2c3d0005f6fc8e0) @@ -36,5 +36,6 @@ void execWatchdogMgmt( void ); void checkInWithWatchdogMgmt( TASK_T task ); BOOL hasWatchdogExpired( void ); +SELF_TEST_STATUS_T execWatchdogTest( void ); #endif