Index: firmware/App/Modes/ModeInitPOST.c =================================================================== diff -u -r6287441e188e7a245f59d3d0d47cdc77808cdb91 -r37a9fd8f15e413db5337371a7d1a1cb65567af7c --- firmware/App/Modes/ModeInitPOST.c (.../ModeInitPOST.c) (revision 6287441e188e7a245f59d3d0d47cdc77808cdb91) +++ firmware/App/Modes/ModeInitPOST.c (.../ModeInitPOST.c) (revision 37a9fd8f15e413db5337371a7d1a1cb65567af7c) @@ -1,37 +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" @@ -42,6 +51,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 +75,14 @@ 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 ); @@ -80,16 +95,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 +114,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 +148,22 @@ 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(); + } + postState = POST_STATE_WATCHDOG; + break; + case POST_STATE_WATCHDOG: testStatus = execWatchdogTest(); postState = handlePOSTStatus( testStatus ); @@ -169,11 +193,21 @@ 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 ); @@ -184,12 +218,20 @@ postState = handlePOSTStatus( testStatus ); break; + case POST_STATE_PRES_OCCL: + testStatus = execPresOcclSelfTest(); + postState = handlePOSTStatus( testStatus ); + break; + case POST_STATE_ALARM_AUDIO: -#ifndef DISABLE_ALARM_AUDIO - testStatus = execAlarmAudioSelfTest(); -#else - testStatus = SELF_TEST_STATUS_PASSED; -#endif + if ( getSoftwareConfigStatus( SW_CONFIG_DISABLE_ALARM_AUDIO ) != SW_CONFIG_ENABLE_VALUE ) + { + testStatus = execAlarmAudioSelfTest(); + } + else + { + testStatus = SELF_TEST_STATUS_PASSED; + } postState = handlePOSTStatus( testStatus ); break; @@ -199,14 +241,35 @@ 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 ); @@ -294,13 +357,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,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 @@ -397,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