Index: firmware/App/Modes/ModeInitPOST.c =================================================================== diff -u -rce20c155091cd03f6ec01c0316a428b8b612492f -rdcd360fb4dc37db2dcbeb7fb14fb327fe68235f4 --- firmware/App/Modes/ModeInitPOST.c (.../ModeInitPOST.c) (revision ce20c155091cd03f6ec01c0316a428b8b612492f) +++ firmware/App/Modes/ModeInitPOST.c (.../ModeInitPOST.c) (revision dcd360fb4dc37db2dcbeb7fb14fb327fe68235f4) @@ -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) Quang Nguyen -* @date (last) 27-Aug-2020 +* @author (last) Dara Navaei +* @date (last) 06-Nov-2021 * -* @author (original) Dara Navaei -* @date (original) 05-Nov-2019 +* @author (original) Dara Navaei +* @date (original) 05-Nov-2019 * ***************************************************************************/ @@ -34,6 +34,7 @@ #include "RTC.h" #include "SafetyShutdown.h" #include "SystemCommMessages.h" +#include "TaskGeneral.h" #include "TemperatureSensors.h" #include "Thermistors.h" #include "UVReactors.h" @@ -44,31 +45,40 @@ * @{ */ +// ********** private definitions ********** + +#define START_POST_DELAY_COUNT ( ( 1 * MS_PER_SECOND ) / TASK_GENERAL_INTERVAL ) ///< Start POST delay in count. + // ********** private data ********** -static DG_POST_STATE_T postState = DG_POST_STATE_START; ///< Currently active initialize & POST state. -static BOOL postCompleted = FALSE; ///< Flag indicating POST completed. -static BOOL postPassed = FALSE; ///< Flag indicating all POST tests passed. -static BOOL tempPOSTPassed = TRUE; ///< Temporary flag indicating all POST tests completed so far have passed. +static DG_POST_STATE_T postState = DG_POST_STATE_START; ///< Currently active initialize & POST state. +static BOOL postCompleted = FALSE; ///< Flag indicating POST completed. +static BOOL postPassed = FALSE; ///< Flag indicating all POST tests passed. +static BOOL tempPOSTPassed = TRUE; ///< Temporary flag indicating all POST tests completed so far have passed. +static U32 startPOSTDelayCounter = 0; ///< Start POST delay counter. // ********** private function prototypes ********** static DG_POST_STATE_T handlePOSTStatus( SELF_TEST_STATUS_T testStatus ); +static DG_POST_STATE_T handlePOSTStateStart( void ); static SELF_TEST_STATUS_T execFWCompatibilityTest( void ); /*********************************************************************//** * @brief - * The initInitAndPOSTMode function initializes the Initialization and POST mode module. + * The initInitAndPOSTMode function initializes the Initialization and POST + * mode module. * @details Inputs: none - * @details Outputs: Initialization and POST mode module initialized + * @details Outputs: postState, postCompleted, tempPOSTPassed, + * startPOSTDelayCounter * @return none *************************************************************************/ void initInitAndPOSTMode( void ) { - postState = DG_POST_STATE_START; - postCompleted = FALSE; - postPassed = FALSE; - tempPOSTPassed = TRUE; + postState = DG_POST_STATE_START; + postCompleted = FALSE; + postPassed = FALSE; + tempPOSTPassed = TRUE; + startPOSTDelayCounter = 0; } /*********************************************************************//** @@ -77,11 +87,13 @@ * initialization and POST mode. * @details Inputs: none * @details Outputs: none - * @return none + * @return initial state *************************************************************************/ -void transitionToInitAndPOSTMode( void ) +U32 transitionToInitAndPOSTMode( void ) { - // TODO - anything needed here? + initInitAndPOSTMode(); + + return postState; } /*********************************************************************//** @@ -100,11 +112,7 @@ switch ( postState ) { case DG_POST_STATE_START: - SEND_EVENT_WITH_2_U32_DATA( DG_EVENT_STARTUP, 0, 0 ) - postState = DG_POST_STATE_FW_COMPATIBILITY; -#ifdef SKIP_POST - postState = DG_POST_STATE_COMPLETED; -#endif + postState = handlePOSTStateStart(); break; case DG_POST_STATE_FW_COMPATIBILITY: @@ -289,15 +297,15 @@ { DG_POST_STATE_T result = postState; - if ( ( testStatus == SELF_TEST_STATUS_PASSED ) || ( testStatus == SELF_TEST_STATUS_FAILED ) ) + if ( ( SELF_TEST_STATUS_PASSED == testStatus ) || ( SELF_TEST_STATUS_FAILED == testStatus ) ) { - BOOL passed = ( testStatus == SELF_TEST_STATUS_PASSED ? TRUE : FALSE ); + BOOL passed = ( SELF_TEST_STATUS_PASSED == testStatus ? TRUE : FALSE ); // Broadcast passed POST result sendPOSTTestResult( (DG_POST_STATE_T)((int)postState), passed ); // Move on to next POST test result = (DG_POST_STATE_T)((int)postState + 1); - if ( testStatus == SELF_TEST_STATUS_FAILED ) + if ( SELF_TEST_STATUS_FAILED == testStatus ) { tempPOSTPassed = FALSE; } @@ -308,6 +316,36 @@ /*********************************************************************//** * @brief + * The handlePOSTStateStart function handles the POST start state. + * @details Inputs: startPOSTDelayCounter + * @details Outputs: startPOSTDelayCounter + * @return next POST state + *************************************************************************/ +static DG_POST_STATE_T handlePOSTStateStart( void ) +{ + DG_POST_STATE_T state = DG_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 ) + { + // Send the startup event + SEND_EVENT_WITH_2_U32_DATA( DG_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( DG_EVENT_OP_MODE_CHANGE, DG_MODE_INIT, DG_MODE_INIT ) + state = DG_POST_STATE_FW_COMPATIBILITY; +#ifdef SKIP_POST + state = DG_POST_STATE_COMPLETED; +#endif + startPOSTDelayCounter = 0; + } + + return state; +} + +/*********************************************************************//** + * @brief * The getCurrentInitAndPOSTState function returns the current state of the * initialization and POST mode. * @details Inputs: postState