Index: firmware/App/Modes/ModeInitPOST.c =================================================================== diff -u -r2e21405574597474db0ebae86cdd7fa2d517f71c -r7d4711edd7b40cd3e29f43e766f79a8a09586fe9 --- firmware/App/Modes/ModeInitPOST.c (.../ModeInitPOST.c) (revision 2e21405574597474db0ebae86cdd7fa2d517f71c) +++ firmware/App/Modes/ModeInitPOST.c (.../ModeInitPOST.c) (revision 7d4711edd7b40cd3e29f43e766f79a8a09586fe9) @@ -1,20 +1,23 @@ /************************************************************************** * -* Copyright (c) 2019-2022 Diality Inc. - All Rights Reserved. +* Copyright (c) 2019-2024 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 * -* @author (last) Dara Navaei -* @date (last) 12-Aug-2022 +* @author (last) Michael Garthwaite +* @date (last) 16-May-2023 * * @author (original) Dara Navaei * @date (original) 05-Nov-2019 * ***************************************************************************/ +#include "reg_crc.h" // Used to hold reset reason code at startup before bits get cleared +#include "reg_system.h" // Used to access exception status registers for reset reason code at startup + #include "Accel.h" #include "ConcentratePumps.h" #include "ConductivitySensors.h" @@ -50,11 +53,11 @@ // ********** 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 U32 startPOSTDelayCounter = 0; ///< Start POST delay counter. +static DG_POST_STATE_T postState; ///< Currently active initialize & POST state. +static BOOL postCompleted; ///< Flag indicating POST completed. +static BOOL postPassed; ///< Flag indicating all POST tests passed. +static BOOL tempPOSTPassed; ///< Temporary flag indicating all POST tests completed so far have passed. +static U32 startPOSTDelayCounter; ///< Start POST delay counter. // ********** private function prototypes ********** @@ -92,6 +95,14 @@ { initInitAndPOSTMode(); setCPLDCleanLEDColor( CPLD_CLEAN_LED_OFF ); + setCurrentSubState( NO_SUB_STATE ); + resetRTCPOSTState(); + resetNVDataMgmtPOSTState(); + resetAccelPOSTState(); + resetPressuresPOSTState(); + resetUVReactorsPOSTState(); + resetWatchdogPOSTState(); + resetSafetyShutdownPOSTState(); return postState; } @@ -259,6 +270,8 @@ postCompleted = TRUE; // Broadcast final POST passed sendPOSTFinalResult( TRUE ); + // Request whether we are in the RO only mode from UI + requestROOnlyModeStatusFromUI(); // Go to standby mode requestNewOperationMode( DG_MODE_STAN ); break; @@ -332,8 +345,8 @@ /*********************************************************************//** * @brief * The handlePOSTStateStart function handles the POST start state. - * @details Inputs: startPOSTDelayCounter - * @details Outputs: startPOSTDelayCounter + * @details Inputs: startPOSTDelayCounter, systemREG1 + * @details Outputs: startPOSTDelayCounter, systemREG1 * @return next POST state *************************************************************************/ static DG_POST_STATE_T handlePOSTStateStart( void ) @@ -344,8 +357,13 @@ // when the event data can be sent if ( ++startPOSTDelayCounter > START_POST_DELAY_COUNT ) { + U32 resetReason = systemREG1->SYSESR | crcREG->PSA_SIGREGL1; // power-on reset bit preserved in an unused CRC register + + systemREG1->SYSESR = systemREG1->SYSESR; // clear reset bit(s) after logging event so subsequent resets can be properly identified as not being power-on resets. + // Send the startup event - SEND_EVENT_WITH_2_U32_DATA( DG_EVENT_STARTUP, 0, 0 ) + SEND_EVENT_WITH_2_U32_DATA( DG_EVENT_STARTUP, systemREG1->DEV, 0x12345678 ) // log startup event w/ device ID bits + SEND_EVENT_WITH_2_U32_DATA( DG_EVENT_STARTUP, resetReason, systemREG1->GBLSTAT ) // log startup event w/ reset reason(s) bits // 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 )