Index: firmware/App/Controllers/Switches.c =================================================================== diff -u -r622eebf6fb7f1c6c232ffd82bc072dd30a7b3f94 -r22176ce95e49213c48454f34ddf5d29b8109f2cb --- firmware/App/Controllers/Switches.c (.../Switches.c) (revision 622eebf6fb7f1c6c232ffd82bc072dd30a7b3f94) +++ firmware/App/Controllers/Switches.c (.../Switches.c) (revision 22176ce95e49213c48454f34ddf5d29b8109f2cb) @@ -1,5 +1,20 @@ +/************************************************************************** +* +* Copyright (c) 2021-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 Switches.c +* +* @author (last) Dara Navaei +* @date (last) 25-May-2022 +* +* @author (original) Dara Navaei +* @date (original) 24-Jul-2021 +* +***************************************************************************/ - #include "FPGA.h" #include "MessageSupport.h" #include "Switches.h" @@ -14,8 +29,9 @@ // ********** private definitions ********** -#define SWITCHES_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the switches data is published on the CAN bus. -#define SWITCHES_DEBOUNCE_TIME_MS ( MS_PER_SECOND / 4 ) ///< Switches debounce time in milliseconds. +#define SWITCHES_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the switches data is published on the CAN bus. +#define SWITCHES_DEBOUNCE_TIME_MS ( MS_PER_SECOND / 4 ) ///< Switches debounce time in milliseconds. +#define DATA_PUBLISH_COUNTER_START_COUNT 7 ///< Data publish counter start count. /// Switch status structure typedef struct @@ -29,7 +45,7 @@ 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_DOORS_AND_CAPS ]; ///< Switches status array. +static SWITCH_STATUS_T switchesStatus[ NUM_OF_CAPS ]; ///< Switches status array. // ********** private function prototypes ********** @@ -46,10 +62,10 @@ { U08 i; - switchesDataPublicationCounter = 0; + switchesDataPublicationCounter = DATA_PUBLISH_COUNTER_START_COUNT; // Initialize all the switches - for ( i = 0; i < NUM_OF_DOORS_AND_CAPS; i++ ) + for ( i = 0; i < NUM_OF_CAPS; i++ ) { switchesStatus[ i ].status.data = (U32)STATE_CLOSED; switchesStatus[ i ].status.ovData = (U32)STATE_CLOSED; @@ -69,10 +85,9 @@ void execSwitches( void ) { U08 i; - U08 currentSwitchStatus = 0; - for ( i = 0; i < NUM_OF_DOORS_AND_CAPS; i++ ) + for ( i = 0; i < NUM_OF_CAPS; i++ ) { // Get the current switch status switch ( i ) @@ -85,13 +100,8 @@ currentSwitchStatus = ( getFPGADialysateCapStatus() != 0 ? STATE_OPEN : STATE_CLOSED ); break; - case FLUID_DOOR: - currentSwitchStatus = ( getFPGAGFluidDoorStatus() != 0 ? STATE_OPEN : STATE_CLOSED ); - break; - - default: - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_DG_INVALID_SWITCH_ID, i ) - 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. } // Check if the current switch status is not the same as the recorded data @@ -126,11 +136,11 @@ * @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; - if ( switchId < NUM_OF_DOORS_AND_CAPS ) + if ( switchId < NUM_OF_CAPS ) { // Assume there is no override status = switchesStatus[ switchId ].status.data; @@ -166,7 +176,6 @@ data.concentrateCap = (U32)getSwitchStatus( CONCENTRATE_CAP ); data.dialysateCap = (U32)getSwitchStatus( DIALYSATE_CAP ); - data.fluidDoor = (U32)getSwitchStatus( FLUID_DOOR ); switchesDataPublicationCounter = 0; @@ -241,7 +250,7 @@ { BOOL result = FALSE; - if ( switchId < NUM_OF_DOORS_AND_CAPS ) + if ( switchId < NUM_OF_CAPS ) { if ( TRUE == isTestingActivated() ) { @@ -267,7 +276,7 @@ { BOOL result = FALSE; - if ( switchId < NUM_OF_DOORS_AND_CAPS ) + if ( switchId < NUM_OF_CAPS ) { if ( TRUE == isTestingActivated() ) {