Index: firmware/App/Modes/ModeInitPOST.c =================================================================== diff -u -r406b3ea2507978267a519af0e9cbfbaaf03027c7 -r37a9fd8f15e413db5337371a7d1a1cb65567af7c --- firmware/App/Modes/ModeInitPOST.c (.../ModeInitPOST.c) (revision 406b3ea2507978267a519af0e9cbfbaaf03027c7) +++ firmware/App/Modes/ModeInitPOST.c (.../ModeInitPOST.c) (revision 37a9fd8f15e413db5337371a7d1a1cb65567af7c) @@ -1,34 +1,46 @@ /************************************************************************** * -* Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. +* Copyright (c) 2019-2022 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) Darren Cox +* @date (last) 10-Mar-2022 * -* @author (original) Dara Navaei -* @date (original) 05-Nov-2019 +* @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 "AlarmLamp.h" #include "BloodFlow.h" +#include "BloodLeak.h" #include "Buttons.h" #include "Compatible.h" #include "CPLD.h" #include "DialInFlow.h" +#include "DialOutFlow.h" +#include "Fans.h" #include "FPGA.h" +#include "Integrity.h" #include "ModeInitPOST.h" #include "NVDataMgmt.h" #include "OperationModes.h" +#include "PresOccl.h" #include "RTC.h" +#include "SafetyShutdown.h" +#include "SyringePump.h" +#include "system.h" #include "SystemCommMessages.h" #include "TaskGeneral.h" +#include "Temperatures.h" #include "Valves.h" #include "WatchdogMgmt.h" @@ -39,26 +51,40 @@ // ********** 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 ) +/// Maximum wait time for UI to send its final POST result. +#define POST_UI_MAX_WAIT_TIME ( 2 * MS_PER_SECOND / TASK_GENERAL_INTERVAL ) // ********** private data ********** -static HD_POST_STATE_T postState; ///< Current state of initialize and POST mode. -static BOOL postCompleted; ///< Flag indicates whether POST is completed. -static BOOL postPassed; ///< Flag indicates all POST tests passed. -static BOOL tempPOSTPassed; ///< Flag indicates all POST tests have passed so far. +static HD_POST_STATE_T postState; ///< Current state of initialize and POST mode. +static BOOL postCompleted; ///< Flag indicates whether POST is completed. +static BOOL postPassed; ///< Flag indicates all POST tests passed. +static BOOL tempPOSTPassed; ///< Flag indicates all POST tests have passed so far. -static BOOL uiPOSTPassed; ///< Final result for UI POST tests (TRUE = passed, FALSE = failed). -static BOOL dgPOSTPassed; ///< Final result for DG POST tests (TRUE = passed, FALSE = failed). +static BOOL uiPOSTPassed; ///< Final result for UI POST tests (TRUE = passed, FALSE = failed). +static BOOL dgPOSTPassed; ///< Final result for DG POST tests (TRUE = passed, FALSE = failed). +static BOOL uiPOSTResultReceived; ///< Have we received a final POST result from the UI? +static BOOL dgPOSTResultReceived; ///< Have we received a final POST result from the DG? +static U32 waitForUIPostTimerCtr; ///< Timer counter to limit wait for UI final POST result. +static U32 postCompleteDelayTimerCtr; ///< Timer counter for 2 second delay after POST completes and before transitioning to Standbymode. -static U32 postCompleteDelayTimerCtr; ///< Timer counter for 2 second delay after POST completes and before transitioning to Standbymode. +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. +extern U32 savedResetReasonCode; ///< Saved reset reason code from sys_startup.c. + // ********** 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 ); /*********************************************************************//** * @brief @@ -69,13 +95,17 @@ *************************************************************************/ void initInitAndPOSTMode( void ) { - postState = POST_STATE_START; - postCompleted = FALSE; - postPassed = FALSE; - tempPOSTPassed = TRUE; - uiPOSTPassed = FALSE; - dgPOSTPassed = FALSE; + postState = POST_STATE_START; + postCompleted = FALSE; + postPassed = FALSE; + tempPOSTPassed = TRUE; + uiPOSTPassed = FALSE; + dgPOSTPassed = FALSE; + uiPOSTResultReceived = FALSE; + dgPOSTResultReceived = FALSE; + waitForUIPostTimerCtr = 0; postCompleteDelayTimerCtr = 0; + startPOSTDelayCounter = 0; } /*********************************************************************//** @@ -84,19 +114,22 @@ * 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; } /*********************************************************************//** * @brief - * The execInitAndPOSTMode function executes the Initialize & POST Mode state machine. + * The execInitAndPOSTMode function executes the Initialize & POST Mode + * state machine. * @details Inputs: postState * @details Outputs: postState, postPassed, postCompleted * @return current state (sub-mode) @@ -111,28 +144,23 @@ // Ignore stop button in this mode. } - // TODO - send POST status on CAN - // Execute current POST state *Note - these switch cases must be in same order as enum HD_POST_States switch ( postState ) { case POST_STATE_START: - postState = POST_STATE_FW_COMPATIBILITY; -#ifdef SKIP_POST - postState = POST_STATE_COMPLETED; -#endif -#ifdef DONT_SKIP_NV_POST - // Only run NVDataMgmt POST - postState = POST_STATE_NVDATAMGMT; -#endif + postState = handlePOSTStateStart(); break; - case POST_STATE_FW_COMPATIBILITY: - testStatus = execFWCompatibilityTest(); + case POST_STATE_FW_INTEGRITY: + testStatus = execIntegrityTest(); postState = handlePOSTStatus( testStatus ); break; - case POST_STATE_FW_INTEGRITY: + case POST_STATE_AC: + if ( getMonitoredLineLevel( MONITORED_LINE_24V ) < MIN_24V_MEASURED_FOR_AC ) + { + initiatePowerOff(); + } postState = POST_STATE_WATCHDOG; break; @@ -141,6 +169,12 @@ postState = handlePOSTStatus( testStatus ); break; + case POST_STATE_SAFETY_SHUTDOWN: + testStatus = execSafetyShutdownTest(); + postState = handlePOSTStatus( testStatus ); + break; + + // NOTE: RTC's POST must go before NVDataMgmt case POST_STATE_RTC: testStatus = execRTCSelfTest(); postState = handlePOSTStatus( testStatus ); @@ -151,55 +185,110 @@ postState = handlePOSTStatus( testStatus ); break; + // NOTE: all the actuators and sensors must execute their POST after NVDataMgmt + // NVDataMgmt must load all the calibration data into RAM so the actuators + // can query their corresponding calibration values successfully case POST_STATE_BLOOD_FLOW: testStatus = execBloodFlowTest(); postState = handlePOSTStatus( testStatus ); break; - case POST_STATE_DIALYSATE_FLOW: + case POST_STATE_DIALYSATE_INLET_FLOW: testStatus = execDialInFlowTest(); postState = handlePOSTStatus( testStatus ); break; + case POST_STATE_DIALYSATE_OUTLET_FLOW: + testStatus = execDialOutFlowTest(); + postState = handlePOSTStatus( testStatus ); + break; + + case POST_STATE_BLOOD_LEAK: + testStatus = execBloodLeakSelfTest(); + postState = handlePOSTStatus( testStatus ); + break; + case POST_STATE_VALVES: testStatus = execValvesSelfTest(); postState = handlePOSTStatus( testStatus ); break; + case POST_STATE_SYRINGE_PUMP: + testStatus = execSyringePumpSelfTest(); + postState = handlePOSTStatus( testStatus ); + break; + + case POST_STATE_PRES_OCCL: + testStatus = execPresOcclSelfTest(); + postState = handlePOSTStatus( testStatus ); + break; + case POST_STATE_ALARM_AUDIO: - testStatus = execAlarmAudioSelfTest(); + if ( getSoftwareConfigStatus( SW_CONFIG_DISABLE_ALARM_AUDIO ) != SW_CONFIG_ENABLE_VALUE ) + { + testStatus = execAlarmAudioSelfTest(); + } + else + { + testStatus = SELF_TEST_STATUS_PASSED; + } postState = handlePOSTStatus( testStatus ); break; case POST_STATE_ALARM_LAMP: -#ifdef DONT_SKIP_NV_POST - // Skip the rest of the POSTs - postState = POST_STATE_COMPLETED; -#else testStatus = execAlarmLampTest(); postState = handlePOSTStatus( testStatus ); -#endif break; case POST_STATE_ACCELEROMETER: -#ifndef DISABLE_ACCELS - testStatus = execAccelTest(); -#else - testStatus = SELF_TEST_STATUS_PASSED; + +#ifndef _RELEASE_ + if ( getSoftwareConfigStatus( SW_CONFIG_DISABLE_ACCELEROMETERS ) != SW_CONFIG_ENABLE_VALUE ) #endif + { + testStatus = execAccelTest(); + } +#ifndef _RELEASE_ + else + { + testStatus = SELF_TEST_STATUS_PASSED; + } +#endif postState = handlePOSTStatus( testStatus ); break; + case POST_STATE_TEMPERATURES: + testStatus = execTemperaturesSelfTest(); + postState = handlePOSTStatus( testStatus ); + break; + + // NOTE: fans self test must be called after temperatures since the + // temperatures must get their calibration first before the fans start monitoring + // for RPM out of range + case POST_STATE_FANS: + testStatus = execFansSelfTest(); + postState = handlePOSTStatus( testStatus ); + break; + case POST_STATE_STUCK_BUTTON: testStatus = execStuckButtonTest(); postState = handlePOSTStatus( testStatus ); break; - // Should be last POST (and last POST test must be a test that completes in a single call) + case POST_STATE_UI_POST: + testStatus = execUITest(); + postState = handlePOSTStatus( testStatus ); + break; + + case POST_STATE_FW_COMPATIBILITY: + testStatus = execFWCompatibilityTest(); + postState = handlePOSTStatus( testStatus ); + break; + + // Should be last POST (and last POST test must be a test that completes in a single call) case POST_STATE_FPGA: testStatus = execFPGATest(); handlePOSTStatus( testStatus ); // Ignoring return value because last test - if ( TRUE == tempPOSTPassed ) { postState = POST_STATE_COMPLETED; @@ -210,8 +299,6 @@ } break; - // TODO - add POST test requiring all DG and UI POST tests to pass - case POST_STATE_COMPLETED: // Set overall HD POST status to "passed" postPassed = TRUE; @@ -230,7 +317,6 @@ // Should not get here - any failed post test should have already triggered a fault and taken us to fault mode default: SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_MODE_INIT_POST_INVALID_POST_STATE, postState ) - postState = POST_STATE_FAILED; break; } @@ -263,24 +349,52 @@ void signalUIPOSTFinalResult( BOOL passed ) { uiPOSTPassed = passed; + uiPOSTResultReceived = TRUE; } /*********************************************************************//** * @brief * 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; } /*********************************************************************//** * @brief + * The signalUIVersion function records the reported UI version information. + * @details Inputs: none + * @details Outputs: uiVersion + * @param version Version information reported by UI + * @return none + *************************************************************************/ +void signalUIVersion( UI_VERSIONS_T version ) +{ + uiVersion = version; +} + +/*********************************************************************//** + * @brief + * The signalDGVersion function records the reported DG version information. + * @details Inputs: none + * @details Outputs: dgVersion + * @param version Version information reported by DG + * @return none + *************************************************************************/ +void signalDGVersion( DG_VERSIONS_T version ) +{ + dgVersion = version; +} + +/*********************************************************************//** + * @brief * The isPOSTCompleted function determines whether all HD POST have * been run and completed. If true, call the isPOSTPassed() to see final * result (pass/fail). @@ -310,15 +424,19 @@ * @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 *************************************************************************/ static HD_POST_STATE_T handlePOSTStatus( SELF_TEST_STATUS_T testStatus ) { HD_POST_STATE_T result = postState; +#ifdef BOARD_WITH_NO_HARDWARE + testStatus = SELF_TEST_STATUS_PASSED; +#endif + if ( testStatus == SELF_TEST_STATUS_PASSED ) { // Broadcast passed POST result @@ -346,6 +464,41 @@ /*********************************************************************//** * @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 ) + { + 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. + + sendUIVersionRequest(); + + // Send the startup event + SEND_EVENT_WITH_2_U32_DATA( HD_EVENT_STARTUP, resetReason, systemREG1->GBLSTAT ) // log startup event w/ reset reason(s) bits + SEND_EVENT_WITH_2_U32_DATA( HD_EVENT_STARTUP, systemREG1->DEV, 0x12345678 ) // log startup event w/ device ID 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( HD_EVENT_OP_MODE_CHANGE, MODE_INIT, MODE_INIT ) + state = POST_STATE_FW_INTEGRITY; + startPOSTDelayCounter = 0; + } + + return state; +} + +/*********************************************************************//** + * @brief * The execFWCompatibilityTest function executes the firmware compatibility test. * @details Inputs: none * @details Outputs: none @@ -355,9 +508,53 @@ { SELF_TEST_STATUS_T result = SELF_TEST_STATUS_PASSED; - // TODO - implement +#ifndef DISABLE_UI_POST_TEST + if ( uiVersion.compatibility != SW_COMPATIBILITY_REV ) + { + result = SELF_TEST_STATUS_FAILED; + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_UI_COMPATIBILITY_ERROR, uiVersion.compatibility, SW_COMPATIBILITY_REV ) + } +#endif return result; } +/*********************************************************************//** + * @brief + * The execUITest function executes the UI POST passed test. + * @details Inputs: uiPOSTResultReceived, uiPOSTPassed, waitForUIPostTimerCtr + * @details Outputs: waitForUIPostTimerCtr + * @return in progress, passed, or failed + *************************************************************************/ +static SELF_TEST_STATUS_T execUITest( void ) +{ +#ifndef DISABLE_UI_POST_TEST + SELF_TEST_STATUS_T result = SELF_TEST_STATUS_IN_PROGRESS; + + // UI should have sent POST results before we start this test + if ( TRUE == uiPOSTResultReceived ) + { + if ( TRUE == uiPOSTPassed ) + { + result = SELF_TEST_STATUS_PASSED; + } + else + { + SET_ALARM_WITH_1_U32_DATA( ALARM_ID_HD_UI_POST_FAILED, 0 ) + result = SELF_TEST_STATUS_FAILED; + } + } + // If UI had not already sent POST results before we started, allow finite period for UI to send. + else if ( ++waitForUIPostTimerCtr > POST_UI_MAX_WAIT_TIME ) + { + SET_ALARM_WITH_1_U32_DATA( ALARM_ID_HD_UI_POST_FAILED, 1 ) + result = SELF_TEST_STATUS_FAILED; + } +#else + SELF_TEST_STATUS_T result = SELF_TEST_STATUS_PASSED; +#endif + + return result; +} + /**@}*/