Index: firmware/App/Controllers/Switches.c =================================================================== diff -u -rbb5280946ac08388b456c7c1848d7797c4a28038 -r4760b847bd262dfc693b3d3458864c05b1c816d7 --- firmware/App/Controllers/Switches.c (.../Switches.c) (revision bb5280946ac08388b456c7c1848d7797c4a28038) +++ firmware/App/Controllers/Switches.c (.../Switches.c) (revision 4760b847bd262dfc693b3d3458864c05b1c816d7) @@ -8,7 +8,7 @@ * @file Switches.c * * @author (last) Dara Navaei -* @date (last) 13-Jun-2022 +* @date (last) 13-Jul-2022 * * @author (original) Dara Navaei * @date (original) 25-Jul-2021 @@ -49,10 +49,13 @@ static OVERRIDE_U32_T switchesDataPublishInterval = { SWITCHES_DATA_PUB_INTERVAL, SWITCHES_DATA_PUB_INTERVAL, 0, 0 }; ///< Interval (in ms) at which to publish switches data to CAN bus. static SWITCH_STATUS_T switchesStatus[ NUM_OF_DOORS_AND_SWITCHES ]; ///< Switches status array. +static BOOL requireDoorClosed; ///< Flag indicates whether door is required to be closed in current state. +static BOOL requirePumpTrackLocked; ///< Flag indicates whether pump track is required to be locked in current state. // ********** private function prototypes ********** static void publishSwitchesData( void ); +static void handleSwitchAlarms( void ); static U32 getPublishSwitchesDataInterval( void ); /*********************************************************************//** @@ -67,6 +70,8 @@ U08 i; switchesDataPublicationCounter = DATA_PUBLISH_COUNTER_START_COUNT; + requireDoorClosed = FALSE; + requirePumpTrackLocked = FALSE; // Initialize all the switches for ( i = 0; i < NUM_OF_DOORS_AND_SWITCHES; i++ ) @@ -105,62 +110,101 @@ break; #ifndef _VECTORCAST_ - // The default cannot be reached in VectorCAST since the cases are run in a for loop + // Since this is a for loop the default cannot be reached in VectorCAST for 100% coverage + default: SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_HD_INVALID_SWITCH_ID, i ) break; #endif } - // Check if the current switch status is not the same as the recorded data - if ( currentSwitchStatus != switchesStatus[ i ].status.data ) +#ifndef _RELEASE_ + if ( SW_CONFIG_ENABLE_VALUE == getSoftwareConfigStatus( SW_CONFIG_DISABLE_SWITCHES_MONITOR ) ) { - // If the debounce time is 0, start the timer - if ( 0 == switchesStatus[ i ].debounceStartTime ) + switchesStatus[ i ].status.data = STATE_CLOSED; + } + else +#endif + { + // Check if the current switch status is not the same as the recorded data + if ( currentSwitchStatus != switchesStatus[ i ].status.data ) { - switchesStatus[ i ].debounceStartTime = getMSTimerCount(); - } - // If the debounce time has been elapsed, update the switch status to the new status - else if ( TRUE == didTimeout( switchesStatus[ i ].debounceStartTime, SWITCHES_DEBOUNCE_TIME_MS ) ) - { - if ( FRONT_DOOR == i ) + // If the debounce time is 0, start the timer + if ( 0 == switchesStatus[ i ].debounceStartTime ) { - // Log front door switch change - sendTreatmentLogEventData( FRONT_DOOR_SWITCH_CHANGED_EVENT, (F32)switchesStatus[ i ].status.data, (F32)currentSwitchStatus ); + switchesStatus[ i ].debounceStartTime = getMSTimerCount(); } - else if ( PUMP_TRACK_SWITCH == i ) + // If the debounce time has been elapsed, update the switch status to the new status + else if ( TRUE == didTimeout( switchesStatus[ i ].debounceStartTime, SWITCHES_DEBOUNCE_TIME_MS ) ) { - // Log pump track switch change - sendTreatmentLogEventData( PUMP_TRACK_SWITCH_CHANGED_EVENT, (F32)switchesStatus[ i ].status.data, (F32)currentSwitchStatus ); + if ( FRONT_DOOR == i ) + { + // Log front door switch change + sendTreatmentLogEventData( FRONT_DOOR_SWITCH_CHANGED_EVENT, (F32)switchesStatus[ i ].status.data, (F32)currentSwitchStatus ); + } + else if ( PUMP_TRACK_SWITCH == i ) + { + // Log pump track switch change + sendTreatmentLogEventData( PUMP_TRACK_SWITCH_CHANGED_EVENT, (F32)switchesStatus[ i ].status.data, (F32)currentSwitchStatus ); + } + // If the bit is 0, the door switch is open, because it is normally open switch + switchesStatus[ i ].debounceStartTime = 0; + switchesStatus[ i ].status.data = currentSwitchStatus; } - // If the bit is 0, the door switch is open, because it is normally open switch + } + else + { switchesStatus[ i ].debounceStartTime = 0; - switchesStatus[ i ].status.data = currentSwitchStatus; } } - else - { - switchesStatus[ i ].debounceStartTime = 0; - } } + handleSwitchAlarms(); + publishSwitchesData(); +} + +/*********************************************************************//** + * @brief + * The getSwitchStatus function returns the status of the called switch. + * @details Inputs: switchStatus + * @details Outputs: switchStatus, requireDoorClosed, requirePumpTrackLocked + * @param switchId which is the switch that its status is requested + * @return switch status + *************************************************************************/ +static void handleSwitchAlarms( void ) +{ #ifndef _RELEASE_ if ( getSoftwareConfigStatus( SW_CONFIG_DISABLE_SWITCHES_MONITOR ) != SW_CONFIG_ENABLE_VALUE ) #endif { - // Clear active Alarms - if ( STATE_CLOSED == getSwitchStatus( FRONT_DOOR ) ) + // Check for door closed alarm + if ( TRUE == requireDoorClosed ) { + if ( getSwitchStatus( FRONT_DOOR ) != STATE_CLOSED ) + { + activateAlarmNoData( ALARM_ID_CARTRIDGE_DOOR_OPENED ); + } + } + // Check for pump track unlocked alarm + if ( TRUE == requirePumpTrackLocked ) + { + if ( getSwitchStatus( PUMP_TRACK_SWITCH ) != STATE_CLOSED ) + { + activateAlarmNoData( ALARM_ID_PUMP_TRACK_LATCH_OPENED ); + } + } + + // Handle clearing alarm conditions + if ( ( STATE_CLOSED == getSwitchStatus( FRONT_DOOR ) ) || ( requireDoorClosed != TRUE ) ) + { clearAlarmCondition( ALARM_ID_CARTRIDGE_DOOR_OPENED ); } - if ( STATE_CLOSED == getSwitchStatus( PUMP_TRACK_SWITCH ) ) + if ( ( STATE_CLOSED == getSwitchStatus( PUMP_TRACK_SWITCH ) ) || ( requirePumpTrackLocked != TRUE ) ) { clearAlarmCondition( ALARM_ID_PUMP_TRACK_LATCH_OPENED ); } } - - publishSwitchesData(); } /*********************************************************************//** @@ -192,6 +236,23 @@ return (OPN_CLS_STATE_T)status; } +/*********************************************************************//** + * @brief + * The doorClosedRequired function sets flags that determine whether door + * and pump tracks should be closed/locked in current state. Associated + * alarms will be triggered if switches not in required state. + * @details Inputs: none + * @details Outputs: requireDoorClosed, requirePumpTrackLocked + * @param door is door required to be closed in current state? + * @param pumpTrack is pump track required to be locked in current state? + * @return none + *************************************************************************/ +void doorClosedRequired( BOOL door, BOOL pumpTrack ) +{ + requireDoorClosed = door; + requirePumpTrackLocked = pumpTrack; +} + // ********** private functions ********** /*********************************************************************//**