Index: firmware/App/Modes/OperationModes.c =================================================================== diff -u -rcc398b14ccf518f350b57fb5cb8728e5c908bd1e -re52973e08c03d6c9b10604e6e97259bcde076ebb --- firmware/App/Modes/OperationModes.c (.../OperationModes.c) (revision cc398b14ccf518f350b57fb5cb8728e5c908bd1e) +++ firmware/App/Modes/OperationModes.c (.../OperationModes.c) (revision e52973e08c03d6c9b10604e6e97259bcde076ebb) @@ -7,8 +7,8 @@ * * @file OperationModes.c * -* @author (last) Sean Nash -* @date (last) 19-Aug-2020 +* @author (last) Quang Nguyen +* @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,18 +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 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 U32 dgOpModePublicationTimerCounter = 0; ///< Timer counter for DG operation mode publication +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 }, @@ -76,9 +75,8 @@ /*********************************************************************//** * @brief * The initOperationModes function initializes the operation modes module. - * @details - * Inputs : none - * Outputs : Operation modes module initialized + * @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 * The execOperationModes function executes the operation modes state machine. - * @details - * Inputs : currentMode - * Outputs : Operation modes' state machine executed + * @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,11 +186,11 @@ 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(); @@ -205,9 +199,8 @@ /*********************************************************************//** * @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,16 +214,15 @@ } 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 * The getCurrentOperationMode function returns the current operation mode. - * @details - * Inputs : none - * Outputs : none + * @details Inputs: none + * @details Outputs: none * @return current mode *************************************************************************/ DG_OP_MODE_T getCurrentOperationMode( void ) @@ -242,9 +234,8 @@ * @brief * The arbitrateModeRequest function selects highest priority mode request * and clear all requests. - * @details - * Inputs : none - * Outputs : Arbitrated mode requests + * @details Inputs: none + * @details Outputs: Arbitrated mode requests * @return highest priority requested mode *************************************************************************/ static DG_OP_MODE_T arbitrateModeRequest( void ) @@ -281,9 +272,8 @@ * @brief * The transitionToNewOperationMode function undergo the process of transition * to new operation mode. - * @details - * Inputs : none - * Outputs : Transition to new mode + * @details Inputs: none + * @details Outputs: Transition to new mode * @param newMode new op mode to transition to * @return none *************************************************************************/ @@ -326,7 +316,7 @@ 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; } } @@ -335,9 +325,8 @@ * @brief * 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 )