Index: firmware/App/Modes/ModeInitPOST.c =================================================================== diff -u -r4d7d40a27130dc813d653f044cbb856b1b7d8481 -ra89d6b091874136d75a9bfbdbbc1ff00f42467b3 --- firmware/App/Modes/ModeInitPOST.c (.../ModeInitPOST.c) (revision 4d7d40a27130dc813d653f044cbb856b1b7d8481) +++ firmware/App/Modes/ModeInitPOST.c (.../ModeInitPOST.c) (revision a89d6b091874136d75a9bfbdbbc1ff00f42467b3) @@ -1,60 +1,84 @@ /************************************************************************** * -* 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) Quang Nguyen -* @date (last) 27-Aug-2020 +* @author (last) Dara Navaei +* @date (last) 06-Jul-2022 * -* @author (original) Dara Navaei -* @date (original) 05-Nov-2019 +* @author (original) Dara Navaei +* @date (original) 05-Nov-2019 * ***************************************************************************/ #include "Accel.h" +#include "ConcentratePumps.h" +#include "ConductivitySensors.h" #include "CPLD.h" +#include "DialysateFlow.h" +#include "DrainPump.h" +#include "Fans.h" #include "FPGA.h" -#include "Heaters.h" +#include "Integrity.h" +#include "LoadCell.h" #include "ModeInitPOST.h" +#include "NVDataMgmt.h" #include "OperationModes.h" #include "Pressures.h" +#include "Reservoirs.h" +#include "ROPump.h" #include "RTC.h" +#include "SafetyShutdown.h" +#include "SystemCommMessages.h" +#include "TaskGeneral.h" #include "TemperatureSensors.h" +#include "Thermistors.h" +#include "UVReactors.h" #include "WatchdogMgmt.h" /** * @addtogroup DGInitAndPOSTMode * @{ */ +// ********** 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; } /*********************************************************************//** @@ -63,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; } /*********************************************************************//** @@ -86,12 +112,22 @@ switch ( postState ) { case DG_POST_STATE_START: - postState = DG_POST_STATE_FPGA; -#ifdef SKIP_POST - postState = DG_POST_STATE_COMPLETED; + postState = handlePOSTStateStart(); +#ifdef BOARD_WITH_NO_HARDWARE + postState = DG_POST_STATE_RTC; #endif break; + case DG_POST_STATE_FW_COMPATIBILITY: + testStatus = execFWCompatibilityTest(); + postState = handlePOSTStatus( testStatus ); + break; + + case DG_POST_STATE_FW_INTEGRITY: + testStatus = execIntegrityTest(); + postState = handlePOSTStatus( testStatus ); + break; + case DG_POST_STATE_FPGA: testStatus = execFPGATest(); postState = handlePOSTStatus( testStatus ); @@ -102,22 +138,36 @@ postState = handlePOSTStatus( testStatus ); break; - case DG_POST_STATE_TEMPERATURE_SENSORS: - testStatus = execTemperatureSensorsSelfTest(); + case DG_POST_STATE_NVDATAMGMT: + testStatus = execNVDataMgmtSelfTest(); postState = handlePOSTStatus( testStatus ); break; - case DG_POST_STATE_HEATERS: - testStatus = execHeatersSelfTest(); + // 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 DG_POST_STATE_TEMPERATURE_SENSORS: +#ifndef BOARD_WITH_NO_HARDWARE + testStatus = execTemperatureSensorsSelfTest(); postState = handlePOSTStatus( testStatus ); +#else + postState = DG_POST_STATE_COMPLETED; +#endif break; case DG_POST_STATE_ACCELEROMETER: -#ifndef DISABLE_ACCELS - testStatus = execAccelTest(); -#else - testStatus = SELF_TEST_STATUS_PASSED; +#ifndef _RELEASE_ + if ( getSoftwareConfigStatus( SW_CONFIG_DISABLE_ACCELS ) != SW_CONFIG_ENABLE_VALUE ) #endif + { + testStatus = execAccelTest(); + } +#ifndef _RELEASE_ + else + { + testStatus = SELF_TEST_STATUS_PASSED; + } +#endif postState = handlePOSTStatus( testStatus ); break; @@ -126,9 +176,77 @@ postState = handlePOSTStatus( testStatus ); break; + case DG_POST_STATE_RO_PUMP: + testStatus = execROPumpSelfTest(); + postState = handlePOSTStatus( testStatus ); + break; + + case DG_POST_STATE_DRAIN_PUMP: + testStatus = execDrainPumpSelfTest(); + postState = handlePOSTStatus( testStatus ); + break; + + case DG_POST_STATE_CONCENTRATE_PUMPS: + testStatus = execConcenratePumpsSelfTest(); + postState = handlePOSTStatus( testStatus ); + break; + + case DG_POST_STATE_CONDUCTIVITY_SENSORS: + testStatus = execConductivitySensorsSelfTest(); + postState = handlePOSTStatus( testStatus ); + break; + + case DG_POST_STATE_RESERVOIRS: + testStatus = execReservoirsSelfTest(); + postState = handlePOSTStatus( testStatus ); + break; + + case DG_POST_STATE_UV_REACTORS: +#ifndef _RELEASE_ + if ( getSoftwareConfigStatus( SW_CONFIG_DISABLE_UV_REACTORS ) != SW_CONFIG_ENABLE_VALUE ) +#endif + { + testStatus = execUVReactorsSelfTest(); + } +#ifndef _RELEASE_ + else + { + testStatus = SELF_TEST_STATUS_PASSED; + } +#endif + postState = handlePOSTStatus( testStatus ); + break; + + case DG_POST_STATE_THERMISTORS: + testStatus = execThermistorsSelfTest(); + postState = handlePOSTStatus( testStatus ); + break; + + case DG_POST_STATE_FANS: + testStatus = execFansSelfTest(); + postState = handlePOSTStatus( testStatus ); + break; + + case DG_POST_STATE_DIALYSATE_FLOW_SENSOR: + testStatus = execDialysateFlowMeterSelfTest(); + postState = handlePOSTStatus( testStatus ); + break; + case DG_POST_STATE_WATCHDOG: testStatus = execWatchdogTest(); - handlePOSTStatus( testStatus ); // ignoring return value because last test + postState = handlePOSTStatus( testStatus ); + break; + + case DG_POST_STATE_SAFETY_SHUTDOWN: + testStatus = execSafetyShutdownTest(); + postState = handlePOSTStatus( testStatus ); + break; + + // Should be last POST (and last POST test must be a test that completes in a single call) + case DG_POST_STATE_LOAD_CELL: + testStatus = execLoadCellsSelfTest(); + handlePOSTStatus( testStatus ); + // Ignoring return value because last test if ( TRUE == tempPOSTPassed ) { postState = DG_POST_STATE_COMPLETED; @@ -140,23 +258,25 @@ break; case DG_POST_STATE_COMPLETED: - // set overall HD POST status to "passed" + // Set overall HD POST status to "passed" postPassed = TRUE; - // set overall HD POST completed status to TRUE + // Set overall HD POST completed status to TRUE postCompleted = TRUE; - // TODO - send POST status on CAN - // go to standby mode + // Broadcast final POST passed + sendPOSTFinalResult( TRUE ); + // Go to standby mode requestNewOperationMode( DG_MODE_STAN ); break; case DG_POST_STATE_FAILED: - // TODO - send POST status on CAN - // will want POST faults to wait for us to get here before sending us to fault mode + // Broadcast final POST failed + sendPOSTFinalResult( FALSE ); + // Will want POST faults to wait for us to get here before sending us to fault mode requestNewOperationMode( DG_MODE_FAUL ); break; default: - // TODO - s/w fault + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_MODE_INIT_POST_INVALID_POST_STATE, postState ) postState = DG_POST_STATE_FAILED; break; } @@ -202,10 +322,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 ) ) { - result = (DG_POST_STATE_T)((int)postState + 1); // move on to next POST test - if ( testStatus == SELF_TEST_STATUS_FAILED ) + 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 ( SELF_TEST_STATUS_FAILED == testStatus ) { tempPOSTPassed = FALSE; } @@ -216,6 +341,33 @@ /*********************************************************************//** * @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; + startPOSTDelayCounter = 0; + } + + return state; +} + +/*********************************************************************//** + * @brief * The getCurrentInitAndPOSTState function returns the current state of the * initialization and POST mode. * @details Inputs: postState @@ -227,4 +379,20 @@ return postState; } +/*********************************************************************//** + * @brief + * The execFWCompatibilityTest function executes the firmware compatibility test. + * @details Inputs: none + * @details Outputs: none + * @return in progress, passed, or failed + *************************************************************************/ +static SELF_TEST_STATUS_T execFWCompatibilityTest( void ) +{ + SELF_TEST_STATUS_T result = SELF_TEST_STATUS_PASSED; + + // TODO - implement + + return result; +} + /**@}*/