Index: firmware/App/Controllers/Switches.c =================================================================== diff -u -r04c5d5d9198c1fde05df66ec8f5e660f7f7174b1 -r6499ea25921fcf67826fa0c35bb03caf411ba542 --- firmware/App/Controllers/Switches.c (.../Switches.c) (revision 04c5d5d9198c1fde05df66ec8f5e660f7f7174b1) +++ firmware/App/Controllers/Switches.c (.../Switches.c) (revision 6499ea25921fcf67826fa0c35bb03caf411ba542) @@ -1,21 +1,20 @@ /************************************************************************** * -* Copyright (c) 2021-2022 Diality Inc. - All Rights Reserved. +* Copyright (c) 2021-2023 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 Switches.c * * @author (last) Dara Navaei -* @date (last) 22-Feb-2022 +* @date (last) 28-Sep-2022 * * @author (original) Dara Navaei * @date (original) 24-Jul-2021 * ***************************************************************************/ - #include "FPGA.h" #include "MessageSupport.h" #include "Switches.h" @@ -46,12 +45,11 @@ static U32 switchesDataPublicationCounter; ///< Switches data publication counter. 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_CAPS ]; ///< Switches status array. +static SWITCH_STATUS_T switchesStatus[ NUM_OF_CAPS ]; ///< Switches status array. // ********** private function prototypes ********** static void publishSwitchesData( void ); -static void publishSwitchChanged( SWITCH_T switchId, U32 current_state ); /*********************************************************************//** * @brief @@ -87,7 +85,6 @@ void execSwitches( void ) { U08 i; - U08 currentSwitchStatus = 0; for ( i = 0; i < NUM_OF_CAPS; i++ ) @@ -103,8 +100,11 @@ currentSwitchStatus = ( getFPGADialysateCapStatus() != 0 ? STATE_OPEN : STATE_CLOSED ); break; - // NOTE: the default case was removed since this switch case is executed using a for loop so the default - // case is never called. The default case is unreachable in development testing. +#ifndef _VECTORCAST_ + default: + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_INVALID_SWITCH_SELECTED, i ); + break; +#endif } // Check if the current switch status is not the same as the recorded data @@ -118,7 +118,23 @@ // 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 ) ) { - publishSwitchChanged( (SWITCH_T)i, (U32)currentSwitchStatus ); + switch ( i ) + { + case CONCENTRATE_CAP: + SEND_EVENT_WITH_2_U32_DATA( DG_EVENT_CONCENTRATE_CAP_SWITCH_CHANGE, (U32)switchesStatus[ i ].status.data, (U32)currentSwitchStatus ); + break; + + case DIALYSATE_CAP: + SEND_EVENT_WITH_2_U32_DATA( DG_EVENT_DIALYSATE_CAP_SWITCH_CHANGE, (U32)switchesStatus[ i ].status.data, (U32)currentSwitchStatus ); + break; + +#ifndef _VECTORCAST_ + default: + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_INVALID_SWITCH_SELECTED, i ); + break; +#endif + } + switchesStatus[ i ].debounceStartTime = 0; switchesStatus[ i ].status.data = currentSwitchStatus; } @@ -140,7 +156,7 @@ * @param switchId which is the switch that its status is requested * @return switch status *************************************************************************/ -OPN_CLS_STATE_T getSwitchStatus( SWITCH_T switchId ) +OPN_CLS_STATE_T getSwitchStatus( CAP_T switchId ) { U32 status = 0; @@ -187,15 +203,6 @@ } } -static void publishSwitchChanged( SWITCH_T switchId, U32 current_state ) -{ - SWITCH_CHANGED_DATA_T data; - - data.SwitchId = (U32)switchId; - data.newstate = current_state; - - broadcastData( MSG_ID_DG_SWITCH_CHANGE, COMM_BUFFER_OUT_CAN_DG_BROADCAST, (U08*)&data, sizeof( SWITCH_CHANGED_DATA_T ) ); -} /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/