Index: firmware/App/Controllers/SyringePump.c =================================================================== diff -u -r44bd54e0202a15a0e38d7ccacd97669d0a14ab3c -r29465f0a7433debfde4f11acee16d2cd0d40bc42 --- firmware/App/Controllers/SyringePump.c (.../SyringePump.c) (revision 44bd54e0202a15a0e38d7ccacd97669d0a14ab3c) +++ firmware/App/Controllers/SyringePump.c (.../SyringePump.c) (revision 29465f0a7433debfde4f11acee16d2cd0d40bc42) @@ -166,10 +166,12 @@ #define SYRINGE_PUMP_STALL_SPEED_THRESHOLD 0.05F ///< Minimum syringe pump speed to be considered not stalled. #define SYRINGE_PUMP_ADC_FPGA_ERROR_TIMEOUT_MS ( 2 * MS_PER_SECOND ) ///< Syringe pump ADC FPGA error timeout in milliseconds. + #define SYRINGE_PUMP_DAC_MAX_RETRIES 5 ///< Syringe pump DAC retries to write. #define SYRINGE_PUMP_DAC_TIMER ( 200 / TASK_PRIORITY_INTERVAL ) ///< Syringe pump DAC timer between retries. #define SYRINGE_PUMP_OCCLUSION_PERSISTENCE 50 ///< Syringe pump occlusion persistence timer in milliseconds. #define SYRINGE_PUMP_EMPTY_FORCE_COUNT 5 ///< Syringe pump empty force voltage count persistence. + /// Defined states for the syringe pump control state machine. typedef enum SyringePump_States { @@ -349,6 +351,7 @@ initPersistentAlarm( ALARM_ID_HD_SYRINGE_PUMP_CONTROLLER_DIRECTION_ERROR, 0, SYRINGE_PUMP_DIR_ALARM_PERSISTENCE ); initPersistentAlarm( ALARM_ID_HD_SYRINGE_PUMP_RUNNING_WHILE_BP_OFF_ERROR, 0, SYRINGE_PUMP_OFF_ALARM_PERSISTENCE ); initPersistentAlarm( ALARM_ID_HD_SYRINGE_PUMP_SPEED_ERROR, 0, SYRINGE_PUMP_RATE_ALARM_PERSISTENCE ); + initPersistentAlarm( ALARM_ID_HD_SYRINGE_PUMP_OCCLUSION, 0, SYRINGE_PUMP_OCCLUSION_PERSISTENCE); initTimeWindowedCount( TIME_WINDOWED_COUNT_SYRINGE_PUMP_OFF_ERROR, SYRINGE_PUMP_OFF_ERROR_MAX_CNT, SYRINGE_PUMP_OFF_ERROR_TIME_WIN_MS ); initFPGAPersistentAlarm( FPGA_PERS_ERROR_SYRINGE_PUMP_ADC, ALARM_ID_HD_SYRINGE_PUMP_FPGA_ADC_FAULT, Index: firmware/App/Controllers/Valves.c =================================================================== diff -u -r3fa496b611a3a84c8aaa882a1b27762c6bc0024c -r29465f0a7433debfde4f11acee16d2cd0d40bc42 --- firmware/App/Controllers/Valves.c (.../Valves.c) (revision 3fa496b611a3a84c8aaa882a1b27762c6bc0024c) +++ firmware/App/Controllers/Valves.c (.../Valves.c) (revision 29465f0a7433debfde4f11acee16d2cd0d40bc42) @@ -1203,31 +1203,34 @@ maxDeviation = MAX_DEVIATION_FROM_TRAGET_IN_POS_B; } - // Check if the current position has deviated from the position it is supposed to be in - // For more than a certain amount of time. If it has, raise an alarm - // Absolute value is used for comparison to cover +/- from the commanded position - if ( abs( currentPosition - commandedPosition ) > maxDeviation ) + if ( FALSE == isACPowerLost() ) { - valvesStatus[ valve ].positionOutOfRangeCounter++; - } + // Check if the current position has deviated from the position it is supposed to be in + // For more than a certain amount of time. If it has, raise an alarm + // Absolute value is used for comparison to cover +/- from the commanded position + if ( abs( currentPosition - commandedPosition ) > maxDeviation ) + { + valvesStatus[ valve ].positionOutOfRangeCounter++; + } - if ( valvesStatus[ valve ].positionOutOfRangeCounter > MAX_POS_DEVIATION_TIME_INTERVAL_COUNTER ) - { - // If the valve's deviation from target was more than the counts for the define period of time trigger the alarm. - // Also, set the state to Idle so in the fault mode, the valve can transition to Pos C. The exec state is directly set here - // because this is a monitor function that is called in the controller function. - valvesStatus[ valve ].execState = VALVE_STATE_IDLE; - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_VALVE_POSITION_OUT_OF_RANGE, (U32)valve, currentPosition ); + if ( valvesStatus[ valve ].positionOutOfRangeCounter > MAX_POS_DEVIATION_TIME_INTERVAL_COUNTER ) + { + // If the valve's deviation from target was more than the counts for the define period of time trigger the alarm. + // Also, set the state to Idle so in the fault mode, the valve can transition to Pos C. The exec state is directly set here + // because this is a monitor function that is called in the controller function. + valvesStatus[ valve ].execState = VALVE_STATE_IDLE; + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_VALVE_POSITION_OUT_OF_RANGE, (U32)valve, currentPosition ); - if ( VALVE_POSITION_C_CLOSE == valvesStatus[ valve ].commandedPosition ) + if ( VALVE_POSITION_C_CLOSE == valvesStatus[ valve ].commandedPosition ) + { + activateSafetyShutdown(); + } + } + else if ( ( TRUE == isValveCloseToCommandedPosition( valve, commandedPositionEnum ) ) && ( valvesStatus[ valve ].positionOutOfRangeCounter > 0 ) ) { - activateSafetyShutdown(); + valvesStatus[ valve ].positionOutOfRangeCounter = 0; } } - else if ( ( TRUE == isValveCloseToCommandedPosition( valve, commandedPositionEnum ) ) && ( valvesStatus[ valve ].positionOutOfRangeCounter > 0 ) ) - { - valvesStatus[ valve ].positionOutOfRangeCounter = 0; - } } else { Index: firmware/App/Services/AlarmMgmt.c =================================================================== diff -u -r3fa496b611a3a84c8aaa882a1b27762c6bc0024c -r29465f0a7433debfde4f11acee16d2cd0d40bc42 --- firmware/App/Services/AlarmMgmt.c (.../AlarmMgmt.c) (revision 3fa496b611a3a84c8aaa882a1b27762c6bc0024c) +++ firmware/App/Services/AlarmMgmt.c (.../AlarmMgmt.c) (revision 29465f0a7433debfde4f11acee16d2cd0d40bc42) @@ -256,6 +256,33 @@ /*********************************************************************//** * @brief + * The isACPowerLost function determines whether A/C power loss has + * been detected. This function sets the alarms blocked condition to + * allow smooth alarm recovery. + * + * @details Inputs: alarmStatus + * @details Outputs: alarmsBlockedTimer + * @return TRUE if A/C power loss alarm is in effect, FALSE if not + *************************************************************************/ +BOOL isACPowerLost( void ) +{ + BOOL result = TRUE; + + // Continue to block new alarms until the alarms are cleared. + if ( ( FALSE == isAlarmConditionDetected( ALARM_ID_HD_AC_POWER_LOST ) ) && + ( FALSE == isAlarmConditionDetected( ALARM_ID_HD_AC_POWER_LOST_IN_TREATMENT ) ) ) + { + result = FALSE; + } + else + { + alarmsBlockedTimer = ALARM_BLOCKED_COUNT_AFTER_AC_RETURN; + } + return result; +} + +/*********************************************************************//** + * @brief * The activateAlarm function activates a given alarm. * @details Inputs: none * @details Outputs: alarmIsActive[], alarmStartedAt[], alarmStatus is updated @@ -264,6 +291,11 @@ *************************************************************************/ static void activateAlarm( ALARM_ID_T alarm ) { + // Block new alarms, occuring during loss of AC power + if ( ( TRUE == getCPLDACPowerLossDetected() ) ) + { + alarmsBlockedTimer = ALARM_BLOCKED_COUNT_AFTER_AC_RETURN; + } // Verify valid alarm index if ( ( alarm > ALARM_ID_NO_ALARM ) && ( alarm < NUM_OF_ALARM_IDS ) ) { Index: firmware/App/Services/AlarmMgmt.h =================================================================== diff -u -r3fa496b611a3a84c8aaa882a1b27762c6bc0024c -r29465f0a7433debfde4f11acee16d2cd0d40bc42 --- firmware/App/Services/AlarmMgmt.h (.../AlarmMgmt.h) (revision 3fa496b611a3a84c8aaa882a1b27762c6bc0024c) +++ firmware/App/Services/AlarmMgmt.h (.../AlarmMgmt.h) (revision 29465f0a7433debfde4f11acee16d2cd0d40bc42) @@ -205,6 +205,7 @@ void setAlarmUserActionEnabled( ALARM_USER_ACTION_T action, BOOL enabled ); void signalAlarmSilence( ALARM_SILENCE_CMD_T cmd ); void signalAlarmUserActionInitiated( ALARM_USER_ACTION_T action ); +BOOL isACPowerLost( void ); BOOL isAlarmActive( ALARM_ID_T alarm ); BOOL isAlarmConditionDetected( ALARM_ID_T alarm ); BOOL isAnyAlarmActive( void ); Index: firmware/App/Services/Reservoirs.c =================================================================== diff -u -r3fa496b611a3a84c8aaa882a1b27762c6bc0024c -r29465f0a7433debfde4f11acee16d2cd0d40bc42 --- firmware/App/Services/Reservoirs.c (.../Reservoirs.c) (revision 3fa496b611a3a84c8aaa882a1b27762c6bc0024c) +++ firmware/App/Services/Reservoirs.c (.../Reservoirs.c) (revision 29465f0a7433debfde4f11acee16d2cd0d40bc42) @@ -26,6 +26,7 @@ #include "NVDataMgmt.h" #include "OperationModes.h" #include "Reservoirs.h" +#include "SystemCommMessages.h" #include "TaskGeneral.h" #include "Timers.h" @@ -92,7 +93,7 @@ static U32 lastTimeReservoirInUF; ///< Reservoir time in ultrafiltration from prior reservoir (in ms). static F32 volSpentUFML; ///< Ultrafiltration volume in milliliters. static DG_RESERVOIR_ID_T activeReservoir; ///< Active reservoir. -static F32 recirculationLevelPct; ///< Recirculation level in percent. +static OVERRIDE_F32_T recirculationLevelPct = { 0.0, 0.0, 0.0, 0 }; ///< Recirculation level in percent. static U32 reservoirSwitchStartTimeMS; ///< Reservoir switch start time in milliseconds. static S32 timeWaitToFillMS; ///< Time to wait to fill in milliseconds. static F32 targetFillFlowLPM; ///< Target fill flow in liters/minutes. @@ -150,7 +151,7 @@ lastTimeReservoirInUF = 0; volSpentUFML = 0.0F; activeReservoir = getDGActiveReservoir(); - recirculationLevelPct = 0.0F; + recirculationLevelPct.data = 0.0F; reservoirSwitchStartTimeMS = 0; timeWaitToFillMS = 0; targetFillFlowLPM = 0.0F; @@ -207,7 +208,7 @@ volSpentML += ( flowRateMLPerMS * msSinceLastVolumeCalc ); timeReservoirInUse++; // Check the recirculation level - recirculationLevelPct = volSpentML / (F32)prevTargetFillVolumeML[ getDGActiveReservoir() ]; + recirculationLevelPct.data = volSpentML / (F32)prevTargetFillVolumeML[ getDGActiveReservoir() ]; } // Update the reservoir start time @@ -457,7 +458,7 @@ data.activeReservoirUFVolML = volSpentUFML; data.activeReservoirVolSpentML = volSpentML; data.dilLevelPct = dilutionLevelPct * 100; - data.recircLevelPct = recirculationLevelPct * 100; + data.recircLevelPct = getF32OverrideValue( &recirculationLevelPct ) * 100; data.timeDepletionMS = timeDepleteMS; data.timeWaitFillMS = timeWaitToFillMS; data.tempRemoveTargetFillFlow = targetFillFlowLPM; @@ -598,13 +599,13 @@ // If the recirculation level has exceeded the max allowed, raise the alarm to stop using the active reservoir as it has been // diluted to much - if ( recirculationLevelPct >= getReservoirRecirculationMaxPercent() ) + if ( getF32OverrideValue( &recirculationLevelPct ) >= getReservoirRecirculationMaxPercent() ) { #ifndef _RELEASE_ if ( getSoftwareConfigStatus( SW_CONFIG_DISABLE_RESERVOIRS_ALARMS ) != SW_CONFIG_ENABLE_VALUE ) #endif { - SET_ALARM_WITH_1_F32_DATA( ALARM_ID_HD_ACTIVE_RESERVOIR_RECIRCULATION_OUT_OF_RANGE, recirculationLevelPct ) + SET_ALARM_WITH_1_F32_DATA( ALARM_ID_HD_ACTIVE_RESERVOIR_RECIRCULATION_OUT_OF_RANGE, getF32OverrideValue( &recirculationLevelPct ) ) } } @@ -743,4 +744,55 @@ return targetFillVolumeML; } + +/************************************************************************* + * TEST SUPPORT FUNCTIONS + *************************************************************************/ + + +/*********************************************************************//** + * @brief + * The testSetRecirculationLevelPctOverride function overrides the recirculation + * percentage. + * @details Inputs: none + * @details Outputs: recirculationLevelPct + * @param value override percentage value with this + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testSetRecirculationLevelPctOverride( F32 value ) +{ + BOOL result = FALSE; + + if ( TRUE == isTestingActivated() ) + { + result = TRUE; + recirculationLevelPct.ovData = value; + recirculationLevelPct.override = OVERRIDE_KEY; + } + + return result; +} + +/*********************************************************************//** + * @brief + * The testResetRecirculationLevelPctOverride function resets the override of the + * recirculation percentage. + * @details Inputs: none + * @details Outputs: recirculationLevelPct + * @return TRUE if reset successful, FALSE if not + *************************************************************************/ +BOOL testResetRecirculationLevelPctOverride( void ) +{ + BOOL result = FALSE; + + if ( TRUE == isTestingActivated() ) + { + result = TRUE; + recirculationLevelPct.override = OVERRIDE_RESET; + recirculationLevelPct.ovData = recirculationLevelPct.ovInitData; + } + + return result; +} + /**@}*/ Index: firmware/App/Services/SystemCommMessages.c =================================================================== diff -u -r3fa496b611a3a84c8aaa882a1b27762c6bc0024c -r29465f0a7433debfde4f11acee16d2cd0d40bc42 --- firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision 3fa496b611a3a84c8aaa882a1b27762c6bc0024c) +++ firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision 29465f0a7433debfde4f11acee16d2cd0d40bc42) @@ -31,6 +31,7 @@ #include "ModeStandby.h" #include "ModeInitPOST.h" #include "OperationModes.h" +#include "Reservoirs.h" #include "RTC.h" #include "SampleWater.h" #include "SafetyShutdown.h" @@ -5526,6 +5527,7 @@ if ( sizeof( TEST_OVERRIDE_PAYLOAD_T ) == message->hdr.payloadLen ) { memcpy( &payload, message->payload, sizeof( TEST_OVERRIDE_PAYLOAD_T ) ); + if ( FALSE == payload.reset ) { result = testSetBatteryRemainingCapacityOverride( payload.state.f32 ); @@ -8479,4 +8481,36 @@ sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); } +/*********************************************************************//** + * @brief + * The handleTestHDRecirulationPctOverrideRequest function handles a + * request to override pending ACKs. + * @details Inputs: none + * @details Outputs: message handled + * @param message : a pointer to the message to handle + * @return none + *************************************************************************/ +void handleTestHDRecirulationPctOverrideRequest( MESSAGE_T *message ) +{ + TEST_OVERRIDE_PAYLOAD_T payload; + BOOL result = FALSE; + + // Verify payload length + if ( sizeof( TEST_OVERRIDE_PAYLOAD_T ) == message->hdr.payloadLen ) + { + memcpy( &payload, message->payload, sizeof( TEST_OVERRIDE_PAYLOAD_T ) ); + if ( FALSE == payload.reset ) + { + result = testSetRecirculationLevelPctOverride( payload.state.f32 ); + } + else + { + result = testResetRecirculationLevelPctOverride(); + } + } + + // Respond to request + sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); +} + /**@}*/ Index: firmware/App/Services/SystemCommMessages.h =================================================================== diff -u -r3fa496b611a3a84c8aaa882a1b27762c6bc0024c -r29465f0a7433debfde4f11acee16d2cd0d40bc42 --- firmware/App/Services/SystemCommMessages.h (.../SystemCommMessages.h) (revision 3fa496b611a3a84c8aaa882a1b27762c6bc0024c) +++ firmware/App/Services/SystemCommMessages.h (.../SystemCommMessages.h) (revision 29465f0a7433debfde4f11acee16d2cd0d40bc42) @@ -944,9 +944,6 @@ // MSG_ID_HD_SEND_BLOOD_LEAK_EMB_MODE_RESPONSE BOOL sendBloodLeakEmbeddedModeCommandResponse( U08 cmd, U32 responseLen, U08* response ); -// MSG_ID_HD_SEND_ALARMS_COMMAND -void handleResendAllAlarmsCommand( MESSAGE_T* message ); - // MSG_ID_HD_BLOOD_PUMP_SET_PWM void handleTestBloodPumpSetPWM( MESSAGE_T* message ); @@ -1013,6 +1010,9 @@ // MSG_ID_HD_CAN_RECEIVE_ACK_MESSAGE_OVERRIDE void handleTestHDPendingACKOverrideRequest( MESSAGE_T* message ); +// MSG_ID_HD_RECIRULATION_PCT_OVERRIDE +void handleTestHDRecirulationPctOverrideRequest( MESSAGE_T* message ); + /**@}*/ #endif