Index: firmware/App/Controllers/Switches.c =================================================================== diff -u -rf6b78d1fe6741043de38707211710ab0e8a08483 -r7499a42cc0f906f9a4a947c82c5b4615217ce7e5 --- firmware/App/Controllers/Switches.c (.../Switches.c) (revision f6b78d1fe6741043de38707211710ab0e8a08483) +++ firmware/App/Controllers/Switches.c (.../Switches.c) (revision 7499a42cc0f906f9a4a947c82c5b4615217ce7e5) @@ -7,15 +7,16 @@ * * @file Switches.c * -* @author (last) Sean Nash -* @date (last) 12-Nov-2021 +* @author (last) Dara Navaei +* @date (last) 13-Jul-2022 * * @author (original) Dara Navaei * @date (original) 25-Jul-2021 * ***************************************************************************/ #include "FPGA.h" +#include "NVDataMgmt.h" #include "Switches.h" #include "SystemCommMessages.h" #include "TaskGeneral.h" @@ -30,8 +31,11 @@ #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 FPGA status check interval. -#define DATA_PUBLISH_COUNTER_START_COUNT 4 ///< Data publish counter start count. +#define DATA_PUBLISH_COUNTER_START_COUNT 90 ///< Data publish counter start count. +#define FRONT_DOOR_SWITCH_MASK 0x0010 ///< Front door switch bit mask. Bit 4 of the FPGA GPIO register. +#define PUMP_TRACK_SWITCH_MASK 0x0020 ///< Pump track switch bit mask. Bit 5 of the FPGA GPIO register. + /// Switch status structure typedef struct { @@ -93,16 +97,20 @@ switch ( i ) { case FRONT_DOOR: - currentSwitchStatus = ( 0 == getFPGAFrontDoorStatus() ? STATE_OPEN : STATE_CLOSED ); + currentSwitchStatus = ( FRONT_DOOR_SWITCH_MASK == getFPGAFrontDoorStatus() ? STATE_OPEN : STATE_CLOSED ); break; case PUMP_TRACK_SWITCH: - currentSwitchStatus = ( 0 == getFPGAPumpTrackSwitchStatus() ? STATE_OPEN : STATE_CLOSED ); + currentSwitchStatus = ( PUMP_TRACK_SWITCH_MASK == getFPGAPumpTrackSwitchStatus() ? STATE_OPEN : STATE_CLOSED ); break; +#ifndef _VECTORCAST_ + // 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 @@ -116,9 +124,18 @@ // 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 ) ) { - switchesStatus[ i ].debounceStartTime = 0; + 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 - // TODO investigate the polarity of the pump track switch once it tied to the cartridge latch + switchesStatus[ i ].debounceStartTime = 0; switchesStatus[ i ].status.data = currentSwitchStatus; } } @@ -128,6 +145,22 @@ } } +#ifndef _RELEASE_ + if ( getSoftwareConfigStatus( SW_CONFIG_DISABLE_SWITCHES_MONITOR ) != SW_CONFIG_ENABLE_VALUE ) +#endif + { + // Clear active Alarms + if ( STATE_CLOSED == getSwitchStatus( FRONT_DOOR ) ) + { + clearAlarmCondition( ALARM_ID_CARTRIDGE_DOOR_OPENED ); + } + + if ( STATE_CLOSED == getSwitchStatus( PUMP_TRACK_SWITCH ) ) + { + clearAlarmCondition( ALARM_ID_PUMP_TRACK_LATCH_OPENED ); + } + } + publishSwitchesData(); } @@ -176,7 +209,7 @@ { SWITCHES_DATA_T data; - data.frontDoor = (U32)getSwitchStatus( FRONT_DOOR ); + data.frontDoor = (U32)getSwitchStatus( FRONT_DOOR ); data.pumpTrackSwitch = (U32)getSwitchStatus( PUMP_TRACK_SWITCH ); switchesDataPublicationCounter = 0;