Index: firmware/App/Controllers/Switches.c =================================================================== diff -u -r7da76d7131d824ab15f58857eeeedcf128e57391 -r2e56d2d983becc4b15bd296d583e046e061a5719 --- firmware/App/Controllers/Switches.c (.../Switches.c) (revision 7da76d7131d824ab15f58857eeeedcf128e57391) +++ firmware/App/Controllers/Switches.c (.../Switches.c) (revision 2e56d2d983becc4b15bd296d583e046e061a5719) @@ -3,6 +3,7 @@ #include "Switches.h" #include "SystemCommMessages.h" #include "TaskGeneral.h" +#include "Timers.h" /** * @addtogroup Switches @@ -11,17 +12,22 @@ // ********** 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_FPGA_STATUS_CHECK_INTERVAL ( MS_PER_SECOND / ( 5 * TASK_GENERAL_INTERVAL ) ) ///< Switches FPGA status check interval. +#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. +/// Switch status structure +typedef struct +{ + OVERRIDE_U32_T status; ///< Switch status. + U32 debounceStartTime; ///< Debounce start time. +} SWITCH_STATUS_T; + // ********** private data ********** -static U32 switchesDataPublicationCounter; ///< Switches data publication counter. +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 OVERRIDE_U32_T switchStatus[ NUM_OF_DOORS_AND_CAPS ]; ///< Switches status array. -static U32 switchesFPGAStatusCheckCounter; ///< Switches FPGA status check counter. + 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. // ********** private function prototypes ********** @@ -40,32 +46,68 @@ U08 i; switchesDataPublicationCounter = 0; - switchesFPGAStatusCheckCounter = 0; // Initialize all the switches for ( i = 0; i < NUM_OF_DOORS_AND_CAPS; i++ ) { - switchStatus[ i ].data = (U32)STATE_CLOSED; - switchStatus[ i ].ovData = (U32)STATE_CLOSED; - switchStatus[ i ].ovInitData = (U32)STATE_CLOSED; - switchStatus[ i ].override = OVERRIDE_RESET; + switchesStatus[ i ].status.data = (U32)STATE_CLOSED; + switchesStatus[ i ].status.ovData = (U32)STATE_CLOSED; + switchesStatus[ i ].status.ovInitData = (U32)STATE_CLOSED; + switchesStatus[ i ].status.override = OVERRIDE_RESET; + switchesStatus[ i ].debounceStartTime = 0; } } /*********************************************************************//** * @brief * The execSwitches function executes the switches executive. - * @details Inputs: switchesFPGAStatusCheckCounter - * @details Outputs: switchStatus, switchesFPGAStatusCheckCounter + * @details Inputs: switchesStatus + * @details Outputs: switchStatus * @return none *************************************************************************/ void execSwitches( void ) { - if ( ++switchesFPGAStatusCheckCounter > SWITCHES_FPGA_STATUS_CHECK_INTERVAL ) + U08 i; + + U16 currentSwitchStatus = 0; + + for ( i = 0; i < NUM_OF_DOORS_AND_CAPS; i++ ) { - switchStatus[ FRONT_DOOR ].data = (U32)( getFPGAFrontDoorStatus() != 0 ? STATE_CLOSED : STATE_OPEN ); + // Get the current switch status + switch ( i ) + { + case FRONT_DOOR: + currentSwitchStatus = getFPGAFrontDoorStatus(); + break; - switchesFPGAStatusCheckCounter = 0; + case CARTRDIGE_LATCH: + currentSwitchStatus = getFPGACartridgeLatchStatus(); + break; + + default: + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_HD_INVALID_SWITCH_ID, i ) + break; + } + + // Check if the current switch status is not the same as the recorded data + if ( currentSwitchStatus != switchesStatus[ i ].status.data ) + { + // If the debounce time is 0, start the timer + if ( 0 == switchesStatus[ i ].debounceStartTime ) + { + 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 ) ) + { + switchesStatus[ i ].debounceStartTime = 0; + switchesStatus[ i ].status.data = currentSwitchStatus; + } + } + else + { + switchesStatus[ i ].debounceStartTime = 0; + } } publishSwitchesData(); @@ -85,13 +127,13 @@ if ( switchId < NUM_OF_DOORS_AND_CAPS ) { - if ( OVERRIDE_KEY == switchStatus[ switchId ].override ) + if ( OVERRIDE_KEY == switchesStatus[ switchId ].status.override ) { - status = switchStatus[ switchId ].ovData; + status = switchesStatus[ switchId ].status.ovData; } else { - status = switchStatus[ switchId ].data; + status = switchesStatus[ switchId ].status.data; } } else @@ -118,7 +160,8 @@ { SWITCHES_DATA_T data; - data.frontDoor = (U32)getSwitchStatus( FRONT_DOOR ); + data.frontDoor = (U32)getSwitchStatus( FRONT_DOOR ); + data.cartrdigeLatch = (U32)getSwitchStatus( CARTRDIGE_LATCH ); switchesDataPublicationCounter = 0; @@ -218,8 +261,8 @@ if ( isTestingActivated() ) { result = TRUE; - switchStatus[ switchId ].ovData = status; - switchStatus[ switchId ].override = OVERRIDE_KEY; + switchesStatus[ switchId ].status.ovData = status; + switchesStatus[ switchId ].status.override = OVERRIDE_KEY; } } @@ -244,8 +287,8 @@ if ( isTestingActivated() ) { result = TRUE; - switchStatus[ switchId ].override = OVERRIDE_RESET; - switchStatus[ switchId ].ovData = switchStatus[ switchId ].ovInitData; + switchesStatus[ switchId ].status.override = OVERRIDE_RESET; + switchesStatus[ switchId ].status.ovData = switchesStatus[ switchId ].status.ovInitData; } } Index: firmware/App/Controllers/Switches.h =================================================================== diff -u -r9fdd42e75e67270808116d7d89f099939c13add7 -r2e56d2d983becc4b15bd296d583e046e061a5719 --- firmware/App/Controllers/Switches.h (.../Switches.h) (revision 9fdd42e75e67270808116d7d89f099939c13add7) +++ firmware/App/Controllers/Switches.h (.../Switches.h) (revision 2e56d2d983becc4b15bd296d583e046e061a5719) @@ -19,13 +19,15 @@ typedef enum switches_names { FRONT_DOOR = 0, ///< Front door + CARTRDIGE_LATCH, ///< Cartridge latch switch NUM_OF_DOORS_AND_CAPS ///< Number of doors and caps } SWITCH_T; /// DG doors and caps data publish structure typedef struct { U32 frontDoor; ///< Front door + U32 cartrdigeLatch; ///< Cartridge latch } SWITCHES_DATA_T; // ********** public function prototypes ********** Index: firmware/App/Services/FPGA.c =================================================================== diff -u -r7da76d7131d824ab15f58857eeeedcf128e57391 -r2e56d2d983becc4b15bd296d583e046e061a5719 --- firmware/App/Services/FPGA.c (.../FPGA.c) (revision 7da76d7131d824ab15f58857eeeedcf128e57391) +++ firmware/App/Services/FPGA.c (.../FPGA.c) (revision 2e56d2d983becc4b15bd296d583e046e061a5719) @@ -550,6 +550,9 @@ // Reset comm flags after processing incoming responses resetFPGACommFlags(); + + // Monitor the power status + monitorFPGAPowerStatus(); } /*********************************************************************//** @@ -940,7 +943,7 @@ *************************************************************************/ static void monitorFPGAPowerStatus( void ) { - + // TOD fill up. Figure out the status of the power source from FPGA from NOE and Kai. } /*********************************************************************//** @@ -2321,6 +2324,20 @@ return ( fpgaSensorReadings.fpgaGPIO & FRONT_DOOR_SWITCH_MASK ); } +/*********************************************************************//** + * @brief + * The getFPGACartridgeLatchStatus function returns the FPGA cartridge latch + * status bit. + * @details Inputs: none + * @details Outputs: fpgaSensorReadings + * @return cartridge latch FPGA status bit + *************************************************************************/ +U16 getFPGACartridgeLatchStatus( void ) +{ + // TODO fill up + return 0; +} + #ifdef DEBUG_ENABLED /*********************************************************************//** * @brief Index: firmware/App/Services/FPGA.h =================================================================== diff -u -r7da76d7131d824ab15f58857eeeedcf128e57391 -r2e56d2d983becc4b15bd296d583e046e061a5719 --- firmware/App/Services/FPGA.h (.../FPGA.h) (revision 7da76d7131d824ab15f58857eeeedcf128e57391) +++ firmware/App/Services/FPGA.h (.../FPGA.h) (revision 2e56d2d983becc4b15bd296d583e046e061a5719) @@ -151,6 +151,7 @@ U16 getFPGAValveBloodArterialCurrentCounts( void ); U16 getFPGAFrontDoorStatus( void ); +U16 getFPGACartridgeLatchStatus( void ); // The PWM functions are only used during debugging #ifdef DEBUG_ENABLED Index: firmware/source/sys_main.c =================================================================== diff -u -rd8fa48ead3336b1fe090b42030a8648264831076 -r2e56d2d983becc4b15bd296d583e046e061a5719 --- firmware/source/sys_main.c (.../sys_main.c) (revision d8fa48ead3336b1fe090b42030a8648264831076) +++ firmware/source/sys_main.c (.../sys_main.c) (revision 2e56d2d983becc4b15bd296d583e046e061a5719) @@ -77,6 +77,7 @@ #include "DialOutFlow.h" #include "FluidLeak.h" #include "FPGA.h" +#include "Integrity.h" #include "InternalADC.h" #include "Interrupts.h" #include "MsgQueues.h" @@ -182,7 +183,7 @@ initRTC(); // Initialize services initCommBuffers(); - //initIntegrity(); TODO what happened to this driver? + initIntegrity(); initFPGA(); initMsgQueues(); initNVDataMgmt();