Index: firmware/App/Controllers/Switches.c =================================================================== diff -u -rc2fe204db1b8926994b5eee78afa1b516c97d02c -rb7c30522ec6cde3ca515f36a053a1fff4e14159c --- firmware/App/Controllers/Switches.c (.../Switches.c) (revision c2fe204db1b8926994b5eee78afa1b516c97d02c) +++ firmware/App/Controllers/Switches.c (.../Switches.c) (revision b7c30522ec6cde3ca515f36a053a1fff4e14159c) @@ -4,6 +4,7 @@ #include "Switches.h" #include "SystemCommMessages.h" #include "TaskGeneral.h" +#include "Timers.h" /** * @addtogroup Switches @@ -12,17 +13,21 @@ // ********** 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 debounce time in milliseconds. +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 ********** @@ -41,12 +46,15 @@ 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; + 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; } } @@ -59,13 +67,51 @@ *************************************************************************/ void execSwitches( void ) { - if ( ++switchesFPGAStatusCheckCounter > SWITCHES_FPGA_STATUS_CHECK_INTERVAL ) + U08 i; + + U08 currentSwitchStatus = 0; + + for ( i = 0; i < NUM_OF_DOORS_AND_CAPS; i++ ) { - switchStatus[ CONCENTRATE_CAP ].data = (U32)( getFPGAGFluidDoorStatus() != 0 ? STATE_CLOSED : STATE_OPEN ); - switchStatus[ DIALYSATE_CAP ].data = (U32)( getFPGADialysateCapStatus() != 0 ? STATE_CLOSED : STATE_OPEN ); - switchStatus[ FLUID_DOOR ].data = (U32)( getFPGAConcentrateCapStatus() != 0 ? STATE_CLOSED : STATE_OPEN ); + // Get the current switch status + switch ( i ) + { + case CONCENTRATE_CAP: + currentSwitchStatus = getFPGAConcentrateCapStatus(); + break; - switchesFPGAStatusCheckCounter = 0; + case DIALYSATE_CAP: + currentSwitchStatus = getFPGADialysateCapStatus(); + break; + + case FLUID_DOOR: + currentSwitchStatus = getFPGAGFluidDoorStatus(); + break; + + default: + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_DG_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 +131,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 @@ -220,15 +266,14 @@ if ( isTestingActivated() ) { result = TRUE; - switchStatus[ switchId ].ovData = status; - switchStatus[ switchId ].override = OVERRIDE_KEY; + switchesStatus[ switchId ].status.ovData = status; + switchesStatus[ switchId ].status.override = OVERRIDE_KEY; } } return result; } - /*********************************************************************//** * @brief * The testResetSwitchesStatusOverride function resets the override @@ -247,8 +292,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 -rc2fe204db1b8926994b5eee78afa1b516c97d02c -rb7c30522ec6cde3ca515f36a053a1fff4e14159c --- firmware/App/Controllers/Switches.h (.../Switches.h) (revision c2fe204db1b8926994b5eee78afa1b516c97d02c) +++ firmware/App/Controllers/Switches.h (.../Switches.h) (revision b7c30522ec6cde3ca515f36a053a1fff4e14159c) @@ -7,7 +7,8 @@ /** * @defgroup Switches Switches - * @brief Switches module. Controls the shunt, acid/bicarb cover and door switches. TODO fill up + * @brief Switches module monitors the fluid door, dialysate cap, and concentrate cap. + * Switches manufacturer: Littlefuse PN: 55100 Miniature Flange Mounting Proximity Sensor * * @addtogroup Switches * @{ Index: firmware/App/Services/FPGA.c =================================================================== diff -u -rb93d59e35abc7a815cb108831ffca93635321028 -rb7c30522ec6cde3ca515f36a053a1fff4e14159c --- firmware/App/Services/FPGA.c (.../FPGA.c) (revision b93d59e35abc7a815cb108831ffca93635321028) +++ firmware/App/Services/FPGA.c (.../FPGA.c) (revision b7c30522ec6cde3ca515f36a053a1fff4e14159c) @@ -18,12 +18,14 @@ #include // for memset(), memcpy() +#include "gio.h" #include "sci.h" #include "sys_dma.h" -#include "FPGA.h" #include "Comm.h" #include "Compatible.h" +#include "FPGA.h" +#include "PersistentAlarm.h" #include "SystemCommMessages.h" #include "Utilities.h" @@ -82,7 +84,8 @@ #define FLUID_DOOR_SWITCH_MASK 0x08 ///< Fluid door switch bit mask. #define DIALYSATE_CAP_SWITCH_MASK 0x10 ///< Dialysate cap switch bit mask. #define CONCENTRATE_CAP_SWITCH_MASK 0x1A ///< Concentrate cap switch bit mask. -#define FPGA_POWER_STATUS_MASK 0x40 ///< FPGA power status bit mask. +#define FPGA_POWER_OUT_TIMEOUT_MS ( 2 * MS_PER_SECOND ) ///< FPGA power out timeout in milliseconds. +#define FPGA_GPIO_POWER_STATUS_PIN 7 ///< FPGA GPIO power status pin // FPGA header struct. #pragma pack(push,1) @@ -364,6 +367,9 @@ // there shouldn't be any data pending yet consumeUnexpectedData(); + + // Initialize the persistent alarm for FPGA power out + initPersistentAlarm( ALARM_ID_DG_FPGA_POWER_OUT_TIMEOUT, FPGA_POWER_OUT_TIMEOUT_MS, FPGA_POWER_OUT_TIMEOUT_MS ); } /*********************************************************************//** @@ -486,6 +492,9 @@ // reset comm flags after processing incoming responses resetFPGACommFlags(); + + // Check the FPGA power status + monitorFPGAPowerStatus(); } /*********************************************************************//** @@ -928,9 +937,20 @@ } } +/*********************************************************************//** + * @brief + * The monitorFPGAPowerStatus function monitors the status of the FPGA power source. + * @details Inputs: none + * @details Outputs: none + * @return none + *************************************************************************/ static void monitorFPGAPowerStatus( void ) { - BOOL isFPGAPowered = (BOOL)( fpgaSensorReadings.fpgaGPIO & FPGA_POWER_STATUS_MASK ); + // If the GIO bit returned a 0 it mean the power is out, otherwise the power is not out + BOOL isPowerOut = ( TRUE == (BOOL)gioGetBit( gioPORTA, FPGA_GPIO_POWER_STATUS_PIN ) ? FALSE : TRUE ); + + // TODO check to make sure alarm is not raised when the power is good + checkPersistentAlarm( ALARM_ID_DG_FPGA_POWER_OUT_TIMEOUT, isPowerOut, 0, FPGA_POWER_OUT_TIMEOUT_MS ); } /*********************************************************************//** Index: firmware/DG.dil =================================================================== diff -u -r97e0100921ccad633b39b509a93a7237e4d80446 -rb7c30522ec6cde3ca515f36a053a1fff4e14159c --- firmware/DG.dil (.../DG.dil) (revision 97e0100921ccad633b39b509a93a7237e4d80446) +++ firmware/DG.dil (.../DG.dil) (revision b7c30522ec6cde3ca515f36a053a1fff4e14159c) @@ -1,4 +1,4 @@ -# RM46L852PGE 07/22/21 10:30:54 +# RM46L852PGE 07/31/21 13:58:42 # ARCH=RM46L852PGE # @@ -1533,7 +1533,7 @@ DRIVER.GIO.VAR.GIO_PORT0_BIT4_PDR.VALUE=0 DRIVER.GIO.VAR.GIO_PORT0_BIT3_POL.VALUE=0 DRIVER.GIO.VAR.GIO_PORT1_BIT5_PULDIS.VALUE=0 -DRIVER.GIO.VAR.GIO_PORT0_BIT7_ENA.VALUE=1 +DRIVER.GIO.VAR.GIO_PORT0_BIT7_ENA.VALUE=0 DRIVER.GIO.VAR.GIO_PORT0_BIT3_PSL.VALUE=0 DRIVER.GIO.VAR.GIO_PORT1_BIT5_PULL.VALUE=1 DRIVER.GIO.VAR.GIO_PORT0_BIT7_DIR.VALUE=0 Index: firmware/include/gio.h =================================================================== diff -u -r8638b207699a3a48e3657e838e24ae838369c867 -rb7c30522ec6cde3ca515f36a053a1fff4e14159c --- firmware/include/gio.h (.../gio.h) (revision 8638b207699a3a48e3657e838e24ae838369c867) +++ firmware/include/gio.h (.../gio.h) (revision b7c30522ec6cde3ca515f36a053a1fff4e14159c) @@ -96,7 +96,7 @@ | (uint32)((uint32)0U << 4U) \ | (uint32)((uint32)0U << 5U) \ | (uint32)((uint32)0U << 6U) \ - | (uint32)((uint32)1U << 7U) \ + | (uint32)((uint32)0U << 7U) \ | (uint32)((uint32)0U << 8U) \ | (uint32)((uint32)0U << 9U) \ | (uint32)((uint32)0U << 10U)\ Index: firmware/source/gio.c =================================================================== diff -u -r8638b207699a3a48e3657e838e24ae838369c867 -rb7c30522ec6cde3ca515f36a053a1fff4e14159c --- firmware/source/gio.c (.../gio.c) (revision 8638b207699a3a48e3657e838e24ae838369c867) +++ firmware/source/gio.c (.../gio.c) (revision b7c30522ec6cde3ca515f36a053a1fff4e14159c) @@ -228,7 +228,7 @@ | (uint32)((uint32)0U << 4U) /* Bit 4 */ | (uint32)((uint32)0U << 5U) /* Bit 5 */ | (uint32)((uint32)0U << 6U) /* Bit 6 */ - | (uint32)((uint32)1U << 7U) /* Bit 7 */ + | (uint32)((uint32)0U << 7U) /* Bit 7 */ | (uint32)((uint32)0U << 8U) /* Bit 8 */ | (uint32)((uint32)0U << 9U) /* Bit 9 */ | (uint32)((uint32)0U << 10U) /* Bit 10 */