Index: firmware/App/Controllers/BloodLeak.c =================================================================== diff -u -raad5e13d6c6b65fe869668fd987af64b75d9e3b8 -rb442cce89b3fde168017fa38c6f5f799da8b4510 --- firmware/App/Controllers/BloodLeak.c (.../BloodLeak.c) (revision aad5e13d6c6b65fe869668fd987af64b75d9e3b8) +++ firmware/App/Controllers/BloodLeak.c (.../BloodLeak.c) (revision b442cce89b3fde168017fa38c6f5f799da8b4510) @@ -7,8 +7,8 @@ * * @file BloodLeak.c * -* @author (last) Sean Nash -* @date (last) 02-Feb-2023 +* @author (last) Bill Bracken +* @date (last) 13-Jun-2023 * * @author (original) Peman Montazemi * @date (original) 18-Mar-2021 @@ -17,13 +17,15 @@ #include // For sprintf and strlen #include +#include // For sprintf #include "AlarmMgmt.h" #include "BloodLeak.h" #include "FPGA.h" #include "NVDataMgmtHDRecords.h" #include "OperationModes.h" #include "PersistentAlarm.h" +#include "Switches.h" #include "SystemCommMessages.h" #include "TaskPriority.h" #include "Timers.h" @@ -88,7 +90,11 @@ #define BLOOD_LEAK_EMB_MODE_NUM_OF_INFO_CMDS 3 ///< Blood leak embedded mode number of informative commands. #define BLOOD_LEAK_FPGA_ERROR_TIMEOUT_MS ( 2 * MS_PER_SECOND ) ///< Blood leak embedded mode FPGA error timeout in milliseconds. +#define BLOOD_LEAK_RXFIFO_COUNT_MASK 0x03ff ///< Mask high order bits of blood leak sensor rx count +#define MAX_BLOOD_LEAK_COMM_FAILURES_WINDOW_MS ( 1 * SEC_PER_MIN * MS_PER_SECOND ) ///< Blood Leak comm failures window +#define MAX_BLOOD_LEAK_COMM_FAILURES 3 ///< Blood Leak maximum comm failures per MAX_BLOOD_LEAK_COMM_FAILURES_WINDOW_MS + /// Defined states for the blood leak detector state machine. typedef enum BloodLeakStates { @@ -197,6 +203,7 @@ static BOOL isEmbModeCmdQueueEmpty( void ); static U32 getAvailableEmbModeQueueCount( void ); static void enqueueInfoEmbModeCmds( void ); +static U16 getBloodLeakRxBytesAvailable( void ); /*********************************************************************//** * @brief @@ -257,12 +264,13 @@ // Initialize the blood leak embedded mode command sequence memset( bloodLeakEmbModeCmdSeq, 0x0, BLOOD_LEAK_EMB_MODE_CMD_SEQ_LENGTH ); - initFPGAPersistentAlarm( FPGA_PERS_ERROR_BLOOD_LEAK_SENSOR, ALARM_ID_HD_BLOOD_LEAK_FPGA_FAULT, - BLOOD_LEAK_FPGA_ERROR_TIMEOUT_MS, BLOOD_LEAK_FPGA_ERROR_TIMEOUT_MS ); - // Enqueue the commands to set the embedded mode and request the set point of the blood leak sensor enqueueEmbModeCmd( CS_EMB_MODE_CMD ); enqueueEmbModeCmd( D_EMB_MODE_CMD ); + + // initialize FPGA comm failures windowed timer count + initTimeWindowedCount( TIME_WINDOWED_COUNT_BLOOD_LEAK_COMM_ERROR, MAX_BLOOD_LEAK_COMM_FAILURES, MAX_BLOOD_LEAK_COMM_FAILURES_WINDOW_MS); + } /*********************************************************************//** @@ -311,8 +319,6 @@ enqueueInfoEmbModeCmds(); - checkFPGAPersistentErrorCountAlarm( FPGA_PERS_ERROR_BLOOD_LEAK_SENSOR, getFPGABloodLeakRxErrorCount() ); - // Publish blood leak data if due publishBloodLeakData(); } @@ -367,6 +373,9 @@ enqueueEmbModeCmd( Z_EMB_MODE_CMD ); enqueueEmbModeCmd( Q_EMB_MODE_CMD ); enqueueEmbModeCmd( T_EMB_MODE_CMD ); + + // Since the zero commands have been queued, reset the counter + bloodLeakEmbModeCmdEnqueueCount = 0; } else if ( ++bloodLeakEmbModeCmdEnqueueCount > BLOOD_LEAK_EMB_MODE_MAX_NUM_CMD_TRIES ) { @@ -652,8 +661,14 @@ { #endif + if ( STATE_OPEN == getSwitchStatus( PUMP_TRACK_SWITCH ) ) + { + // If the pump track on open, zero the persistent counter to not check the blood leak alarm + bloodLeakPersistenceCtr = 0; + } + // Check status reading and act upon - if ( BLOOD_LEAK_DETECTED == getBloodLeakStatus() ) + if ( ( BLOOD_LEAK_DETECTED == getBloodLeakStatus() ) && ( MODE_TREA == getCurrentOperationMode() ) ) { if ( ++bloodLeakPersistenceCtr > BLOOD_LEAK_PERSISTENCE ) { @@ -663,6 +678,7 @@ #endif { activateAlarmNoData( ALARM_ID_HD_BLOOD_LEAK_DETECTED ); + exitBloodLeakNormalState(); // so we don't keep triggering after user clears it (rinseback or end tx). } } } @@ -887,7 +903,7 @@ if ( ( bloodLeakEmbModeRqstedCmd != CS_EMB_MODE_CMD ) && ( bloodLeakUARTCmdIndex - 1 > BLOOD_LEAK_EMB_MODE_RESET_INDEX ) && ( bloodLeakUARTCmdIndex - 1 <= BLOOD_LEAK_EMB_MODE_RESET_INDEX + 1 ) ) { - if ( BLOOD_LEAK_EMB_MODE_RX_BUFFER_EMPTY == getFPGABloodLeakRxFIFOCount() ) + if ( 0 == getBloodLeakRxBytesAvailable() ) { // TODO do nothing right now. I case it was decided to use the terminal mode again, make sure the reset went through prior to sending the // reset of the command sequence @@ -933,7 +949,7 @@ static BLOOD_LEAK_EMB_MODE_STATE_T handleBloodLeakEmbModeWaitForCommandResponseState( void ) { BLOOD_LEAK_EMB_MODE_STATE_T state = BLOOD_LEAK_EMB_MODE_WAIT_FOR_COMMAND_RESPONSE_STATE; - U08 rxFIFOCount = getFPGABloodLeakRxFIFOCount(); + U16 rxFIFOCount = getBloodLeakRxBytesAvailable(); BOOL hasCharBeenReceived = FALSE; U32 commandTimeoutMS = bloodLeakEmbModeCmd[ bloodLeakEmbModeRqstedCmd ].timeoutMS; U32 length = bloodLeakEmbModeCmd[ bloodLeakEmbModeRqstedCmd ].length; @@ -1027,6 +1043,11 @@ bloodLeakEmbModeRqstedCmd = NU_EMB_MODE_CMD; state = BLOOD_LEAK_EMB_MODE_WAIT_FOR_COMAND_STATE; + + if ( TRUE == incTimeWindowedCount( TIME_WINDOWED_COUNT_BLOOD_LEAK_COMM_ERROR ) ) + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_BLOOD_LEAK_FPGA_FAULT, MAX_BLOOD_LEAK_COMM_FAILURES, (U32)MAX_BLOOD_LEAK_COMM_FAILURES_WINDOW_MS ) + } } return state; @@ -1344,7 +1365,7 @@ bloodLeakEmbModeCmd[ D_EMB_MODE_CMD ].length = 5; bloodLeakEmbModeCmd[ D_EMB_MODE_CMD ].timeoutMS = 5 * MS_PER_SECOND; bloodLeakEmbModeCmd[ D_EMB_MODE_CMD ].commandResp = 0; - bloodLeakEmbModeCmd[ CS_EMB_MODE_CMD ].isCmdRespRdy = FALSE; + bloodLeakEmbModeCmd[ D_EMB_MODE_CMD ].isCmdRespRdy = FALSE; // Calibrate command bloodLeakEmbModeCmd[ C_EMB_MODE_CMD ].commandASCII = 67; @@ -1353,7 +1374,7 @@ bloodLeakEmbModeCmd[ C_EMB_MODE_CMD ].length = 4; bloodLeakEmbModeCmd[ C_EMB_MODE_CMD ].timeoutMS = 5 * MS_PER_SECOND; bloodLeakEmbModeCmd[ C_EMB_MODE_CMD ].commandResp = 0; - bloodLeakEmbModeCmd[ CS_EMB_MODE_CMD ].isCmdRespRdy = FALSE; + bloodLeakEmbModeCmd[ C_EMB_MODE_CMD ].isCmdRespRdy = FALSE; } /*********************************************************************//** @@ -1627,4 +1648,9 @@ return result; } +static U16 getBloodLeakRxBytesAvailable( void ) +{ + return getFPGABloodLeakRxFIFOCount() & BLOOD_LEAK_RXFIFO_COUNT_MASK; +} + /**@}*/