Index: firmware/App/Controllers/Switches.c =================================================================== diff -u -r076d41f2a507a2f1e5ceb929100bd025cee3b840 -r37a9fd8f15e413db5337371a7d1a1cb65567af7c --- firmware/App/Controllers/Switches.c (.../Switches.c) (revision 076d41f2a507a2f1e5ceb929100bd025cee3b840) +++ firmware/App/Controllers/Switches.c (.../Switches.c) (revision 37a9fd8f15e413db5337371a7d1a1cb65567af7c) @@ -1,3 +1,19 @@ +/************************************************************************** +* +* 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) Darren Cox +* @date (last) 10-Mar-2022 +* +* @author (original) Dara Navaei +* @date (original) 25-Jul-2021 +* +***************************************************************************/ #include "FPGA.h" #include "Switches.h" @@ -14,6 +30,7 @@ #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. /// Switch status structure typedef struct @@ -45,7 +62,7 @@ { U08 i; - switchesDataPublicationCounter = 0; + switchesDataPublicationCounter = DATA_PUBLISH_COUNTER_START_COUNT; // Initialize all the switches for ( i = 0; i < NUM_OF_DOORS_AND_SWITCHES; i++ ) @@ -68,24 +85,23 @@ void execSwitches( void ) { U08 i; + U16 currentSwitchStatus; - U16 currentSwitchStatus = 0; - for ( i = 0; i < NUM_OF_DOORS_AND_SWITCHES; i++ ) { // Get the current switch status switch ( i ) { case FRONT_DOOR: - currentSwitchStatus = getFPGAFrontDoorStatus(); + currentSwitchStatus = ( 0 == getFPGAFrontDoorStatus() ? STATE_OPEN : STATE_CLOSED ); break; case PUMP_TRACK_SWITCH: - currentSwitchStatus = getFPGAPumpTrackSwitchStatus(); + currentSwitchStatus = ( 0 == getFPGAPumpTrackSwitchStatus() ? STATE_OPEN : STATE_CLOSED ); break; default: - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_HD_INVALID_SWITCH_ID, i ) + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_HD_INVALID_SWITCH_ID, i ) break; } @@ -103,7 +119,7 @@ switchesStatus[ i ].debounceStartTime = 0; // 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 ].status.data = ( 0 == currentSwitchStatus ? STATE_OPEN : STATE_CLOSED ); + switchesStatus[ i ].status.data = currentSwitchStatus; } } else @@ -112,6 +128,17 @@ } } + // 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(); } @@ -138,7 +165,7 @@ } else { - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_HD_INVALID_SWITCH_ID, (U32)switchId ) + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_HD_INVALID_SWITCH_ID, (U32)switchId ) } return (OPN_CLS_STATE_T)status; @@ -161,11 +188,11 @@ SWITCHES_DATA_T data; data.frontDoor = (U32)getSwitchStatus( FRONT_DOOR ); - data.cartrdigeLatch = (U32)getSwitchStatus( PUMP_TRACK_SWITCH ); + data.pumpTrackSwitch = (U32)getSwitchStatus( PUMP_TRACK_SWITCH ); switchesDataPublicationCounter = 0; - broadcastSwitchesData( &data ); + broadcastData( MSG_ID_HD_SWITCHES_DATA, COMM_BUFFER_OUT_CAN_HD_BROADCAST, (U08*)&data, sizeof( SWITCHES_DATA_T ) ); } }