Index: firmware/App/Modes/OperationModes.c =================================================================== diff -u -rf308cc4c35eab630ebbbde405cfe47d049afeafb -re52973e08c03d6c9b10604e6e97259bcde076ebb --- firmware/App/Modes/OperationModes.c (.../OperationModes.c) (revision f308cc4c35eab630ebbbde405cfe47d049afeafb) +++ firmware/App/Modes/OperationModes.c (.../OperationModes.c) (revision e52973e08c03d6c9b10604e6e97259bcde076ebb) @@ -8,7 +8,7 @@ * @file OperationModes.c * * @author (last) Quang Nguyen -* @date (last) 21-Jul-2020 +* @date (last) 24-Aug-2020 * * @author (original) Dara Navaei * @date (original) 05-Nov-2019 @@ -17,9 +17,6 @@ #include "gio.h" -#include "SystemCommMessages.h" -#include "TaskGeneral.h" -#include "OperationModes.h" #include "ModeChemicalDisinfect.h" #include "ModeDrain.h" #include "ModeFault.h" @@ -31,6 +28,9 @@ #include "ModeService.h" #include "ModeSolo.h" #include "ModeStandby.h" +#include "OperationModes.h" +#include "SystemCommMessages.h" +#include "TaskGeneral.h" /** * @addtogroup DGOperationModes @@ -39,17 +39,17 @@ // ********** private definitions ********** -#define BROADCAST_DG_OP_MODE_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< interval (ms/task time) at which the op mode is published on the CAN bus. +#define BROADCAST_DG_OP_MODE_INTERVAL ( 250 / TASK_GENERAL_INTERVAL ) ///< interval (ms/task time) at which the operation mode is published on the CAN bus. // ********** private data ********** -static volatile BOOL modeRequest[NUM_OF_DG_MODES - 1]; ///< Array of mode request flags. -static DG_OP_MODE_T currentMode = DG_MODE_INIT; ///< The currently active mode. -static U32 currentSubMode = 0; ///< The currently active state of the active mode. -static U32 broadcastModeIntervalCtr = 11; ///< Interval counter used to determine when to broadcase operation mode. Initialize to 11 to stagger broadcast. +static volatile BOOL modeRequest[ NUM_OF_DG_MODES - 1 ]; ///< Array of mode request flags. +static DG_OP_MODE_T currentMode = DG_MODE_INIT; ///< The currently active mode. +static U32 currentSubMode = 0; ///< The currently active state of the active mode. +static U32 broadcastModeIntervalCtr = 11; ///< Interval counter used to determine when to broadcast operation mode. Initialize to 11 to stagger broadcast. /// This matrix determines legal transitions from one mode to another. -static const DG_OP_MODE_T MODE_TRANSITION_TABLE[NUM_OF_DG_MODES - 1][NUM_OF_DG_MODES - 1] = +static const DG_OP_MODE_T MODE_TRANSITION_TABLE[ NUM_OF_DG_MODES - 1 ][ NUM_OF_DG_MODES - 1 ] = { // from to-> FAULT SERVICE INIT STANBY STBY-SOLO RE-CIRC FILL DRAIN FLUSH HEAT DIS CHEM DIS /* FAUL */{ DG_MODE_FAUL, DG_MODE_SERV, DG_MODE_NLEG, DG_MODE_NLEG, DG_MODE_NLEG, DG_MODE_NLEG, DG_MODE_NLEG, DG_MODE_NLEG, DG_MODE_NLEG, DG_MODE_NLEG, DG_MODE_NLEG }, @@ -65,7 +65,6 @@ /* CHEM */{ DG_MODE_FAUL, DG_MODE_NLEG, DG_MODE_NLEG, DG_MODE_STAN, DG_MODE_NLEG, DG_MODE_NLEG, DG_MODE_NLEG, DG_MODE_NLEG, DG_MODE_NLEG, DG_MODE_NLEG, DG_MODE_CHEM } }; -static U32 dgOpModePublicationTimerCounter = 0; // ********** private function prototypes ********** @@ -74,11 +73,10 @@ static void broadcastOperationMode( void ); /*********************************************************************//** - * @brief execOperationModes - * The execOperationModes function initializes the Operation Modes module. - * @details - * Inputs : none - * Outputs : Operation Modes module initialized. + * @brief + * The initOperationModes function initializes the operation modes module. + * @details Inputs: none + * @details Outputs: Operation modes module initialized * @return none *************************************************************************/ void initOperationModes( void ) @@ -108,17 +106,13 @@ initFlushMode(); initHeatDisinfectMode(); initChemicalDisinfectMode(); - - // initialize broadcast timer counter - dgOpModePublicationTimerCounter = 0; } /*********************************************************************//** - * @brief execOperationModes - * The execOperationModes function executes the Operation Modes state machine. - * @details - * Inputs : none - * Outputs : currentMode is set by state machine. + * @brief + * The execOperationModes function executes the operation modes state machine. + * @details Inputs: currentMode + * @details Outputs: Operation modes' state machine executed * @return none *************************************************************************/ void execOperationModes( void ) @@ -127,12 +121,12 @@ // any new mode requests? newMode = arbitrateModeRequest(); // will return current mode if no pending requests - newMode = MODE_TRANSITION_TABLE[currentMode][newMode]; + newMode = MODE_TRANSITION_TABLE[ currentMode ][ newMode ]; // is requested new mode valid and legal at this time? if ( newMode >= DG_MODE_NLEG ) { - // TODO - s/w fault + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_OP_MODES_ILLEGAL_MODE_TRANSITION_REQUESTED, (U32)newMode ) newMode = currentMode; } @@ -192,22 +186,21 @@ break; default: - // TODO - trigger s/w fault + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_OP_MODES_INVALID_MODE_STATE, (U32)currentMode ) currentMode = DG_MODE_FAUL; currentSubMode = 0; break; - } // end switch + } // publish op mode on interval broadcastOperationMode(); } /*********************************************************************//** - * @brief requestNewOperationMode + * @brief * The requestNewOperationMode function requests a new operation mode. - * @details - * Inputs : none - * Outputs : makes the requested mode "pending". + * @details Inputs: none + * @details Outputs: makes the requested mode "pending" * @param newMode requested mode * @return none *************************************************************************/ @@ -221,30 +214,29 @@ } else { // invalid mode requested - // TODO - trigger s/w fault + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_OP_MODES_INVALID_MODE_REQUESTED, (U32)newMode ) } } /*********************************************************************//** - * @brief getCurrentOperationMode - * The getCurrentOperationMode function initializes the Operation Modes module. - * @details - * Inputs : none - * Outputs : Initializes the Operation Modes module. - * @return none + * @brief + * The getCurrentOperationMode function returns the current operation mode. + * @details Inputs: none + * @details Outputs: none + * @return current mode *************************************************************************/ DG_OP_MODE_T getCurrentOperationMode( void ) { return currentMode; } /*********************************************************************//** - * @brief arbitrateModeRequest - * The arbitrateModeRequest function initializes the Operation Modes module. - * @details - * Inputs : none - * Outputs : Initializes the Operation Modes module. - * @return none + * @brief + * The arbitrateModeRequest function selects highest priority mode request + * and clear all requests. + * @details Inputs: none + * @details Outputs: Arbitrated mode requests + * @return highest priority requested mode *************************************************************************/ static DG_OP_MODE_T arbitrateModeRequest( void ) { @@ -277,11 +269,11 @@ } /*********************************************************************//** - * @brief transitionToNewOperationMode - * The transitionToNewOperationMode function initializes the Operation Modes module. - * @details - * Inputs : none - * Outputs : Initializes the Operation Modes module. + * @brief + * The transitionToNewOperationMode function undergo the process of transition + * to new operation mode. + * @details Inputs: none + * @details Outputs: Transition to new mode * @param newMode new op mode to transition to * @return none *************************************************************************/ @@ -324,18 +316,17 @@ transitionToChemicalDisinfectMode(); break; default: - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, 0, (U32)newMode ) // TODO - add s/w fault enum to 1st data param + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_OP_MODES_INVALID_MODE_TO_TRANSITION_TO, (U32)newMode ) break; } } /*********************************************************************//** * @brief - * The broadcastOperationMode function sends the current operation mode at \n + * The broadcastOperationMode function broadcasts the current operation mode at * the prescribed interval. - * @details - * Inputs : broadcastModeIntervalCtr - * Outputs : DG operation mode broadcast message sent. + * @details Inputs: broadcastModeIntervalCtr + * @details Outputs: DG operation mode broadcast message sent * @return none *************************************************************************/ static void broadcastOperationMode( void )