Index: firmware/App/Modes/ModeInitPOST.c =================================================================== diff -u -r6287441e188e7a245f59d3d0d47cdc77808cdb91 -rc137d3c7cb17b0364d745e10ff6dbd1901eb1baa --- firmware/App/Modes/ModeInitPOST.c (.../ModeInitPOST.c) (revision 6287441e188e7a245f59d3d0d47cdc77808cdb91) +++ firmware/App/Modes/ModeInitPOST.c (.../ModeInitPOST.c) (revision c137d3c7cb17b0364d745e10ff6dbd1901eb1baa) @@ -1,17 +1,17 @@ /************************************************************************** * -* Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. +* Copyright (c) 2019-2021 Diality Inc. - All Rights Reserved. * * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. * -* @file ModeInitPOST.c +* @file ModeInitPOST.c * -* @author (last) Sean Nash -* @date (last) 14-Oct-2020 +* @author (last) Dara Navaei +* @date (last) 10-Nov-2021 * -* @author (original) Dara Navaei -* @date (original) 05-Nov-2019 +* @author (original) Dara Navaei +* @date (original) 05-Nov-2019 * ***************************************************************************/ @@ -42,6 +42,8 @@ // ********** private definitions ********** +#define START_POST_DELAY_COUNT ( ( 1 * MS_PER_SECOND ) / TASK_GENERAL_INTERVAL ) ///< Start POST delay in count. + /// Delay (in task intervals) after POST completes. #define POST_COMPLETED_DELAY ( 2 * MS_PER_SECOND / TASK_GENERAL_INTERVAL ) @@ -64,10 +66,12 @@ static UI_VERSIONS_T uiVersion = { 0, 0, 0, 0, 0 }; ///< Version and compatibility information reported by UI. static DG_VERSIONS_T dgVersion = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; ///< Version and compatibility information reported by DG. +static U32 startPOSTDelayCounter = 0; ///< Start POST delay counter. // ********** private function prototypes ********** static HD_POST_STATE_T handlePOSTStatus( SELF_TEST_STATUS_T testStatus ); +static HD_POST_STATE_T handlePOSTStateStart( void ); static SELF_TEST_STATUS_T execFWCompatibilityTest( void ); static SELF_TEST_STATUS_T execUITest( void ); @@ -80,16 +84,17 @@ *************************************************************************/ void initInitAndPOSTMode( void ) { - postState = POST_STATE_START; - postCompleted = FALSE; - postPassed = FALSE; - tempPOSTPassed = TRUE; - uiPOSTPassed = FALSE; - dgPOSTPassed = FALSE; - uiPOSTResultReceived = FALSE; - dgPOSTResultReceived = FALSE; - waitForUIPostTimerCtr = 0; + postState = POST_STATE_START; + postCompleted = FALSE; + postPassed = FALSE; + tempPOSTPassed = TRUE; + uiPOSTPassed = FALSE; + dgPOSTPassed = FALSE; + uiPOSTResultReceived = FALSE; + dgPOSTResultReceived = FALSE; + waitForUIPostTimerCtr = 0; postCompleteDelayTimerCtr = 0; + startPOSTDelayCounter = 0; } /*********************************************************************//** @@ -98,14 +103,16 @@ * initialize & POST mode. * @details Inputs: none * @details Outputs: none - * @return none + * @return initial state *************************************************************************/ -void transitionToInitAndPOSTMode( void ) +U32 transitionToInitAndPOSTMode( void ) { // Set user alarm recovery actions allowed in this mode setAlarmUserActionEnabled( ALARM_USER_ACTION_RESUME, FALSE ); setAlarmUserActionEnabled( ALARM_USER_ACTION_RINSEBACK, FALSE ); setAlarmUserActionEnabled( ALARM_USER_ACTION_END_TREATMENT, FALSE ); + + return postState; } /*********************************************************************//** @@ -130,16 +137,25 @@ switch ( postState ) { case POST_STATE_START: - sendUIVersionRequest(); - postState = POST_STATE_FW_INTEGRITY; + postState = handlePOSTStateStart(); break; case POST_STATE_FW_INTEGRITY: testStatus = execIntegrityTest(); - testStatus = SELF_TEST_STATUS_PASSED; postState = handlePOSTStatus( testStatus ); break; + case POST_STATE_AC: + if ( getMonitoredLineLevel( MONITORED_LINE_24V ) < MIN_24V_MEASURED_FOR_AC ) + { + initiatePowerOff(); + } + else + { + postState = POST_STATE_WATCHDOG; + } + break; + case POST_STATE_WATCHDOG: testStatus = execWatchdogTest(); postState = handlePOSTStatus( testStatus ); @@ -294,13 +310,13 @@ * The signalDGPOSTFinalResult function records the final POST result for * the DG. * @details Inputs: none - * @details Outputs: dgPOSTPassed + * @details Outputs: dgPOSTPassed, dgPOSTResultReceived * @param passed TRUE if DG POST tests all passed, FALSE if any DG POST test failed * @return none *************************************************************************/ void signalDGPOSTFinalResult( BOOL passed ) { - dgPOSTPassed = passed; + dgPOSTPassed = passed; dgPOSTResultReceived = TRUE; } @@ -361,8 +377,8 @@ * @brief * The handlePOSTStatus function handles a status result returned by a * POST function. - * @details Inputs: postPassed - * @details Outputs: none + * @details Inputs: testStatus + * @details Outputs: tempPOSTPassed * @param testStatus status reported by last test * @return recommended next POST state *************************************************************************/ @@ -397,6 +413,38 @@ /*********************************************************************//** * @brief + * The handlePOSTStateStart function handles the POST start state. + * @details Inputs: startPOSTDelayCounter + * @details Outputs: startPOSTDelayCounter + * @return next POST state + *************************************************************************/ +static HD_POST_STATE_T handlePOSTStateStart( void ) +{ + HD_POST_STATE_T state = POST_STATE_START; + + // There is a delay before starting POST to make sure the CAN bus is up and listening so + // when the event data can be sent + if ( ++startPOSTDelayCounter > START_POST_DELAY_COUNT ) + { + sendUIVersionRequest(); + + // Send the startup event + SEND_EVENT_WITH_2_U32_DATA( HD_EVENT_STARTUP, 0, 0 ) + // Send the first submode change event. It is the mode Init and it does not start from a previous + // mode previous and current are both published as Init + SEND_EVENT_WITH_2_U32_DATA( HD_EVENT_OP_MODE_CHANGE, MODE_INIT, MODE_INIT ) + state = POST_STATE_FW_INTEGRITY; +#ifdef SKIP_POST + state = DG_POST_STATE_COMPLETED; +#endif + startPOSTDelayCounter = 0; + } + + return state; +} + +/*********************************************************************//** + * @brief * The execFWCompatibilityTest function executes the firmware compatibility test. * @details Inputs: none * @details Outputs: none