Index: firmware/App/Controllers/DrainPump.c =================================================================== diff -u -r696e732c9742535a58b9c65f243df7cd797d1423 -r6499ea25921fcf67826fa0c35bb03caf411ba542 --- firmware/App/Controllers/DrainPump.c (.../DrainPump.c) (revision 696e732c9742535a58b9c65f243df7cd797d1423) +++ firmware/App/Controllers/DrainPump.c (.../DrainPump.c) (revision 6499ea25921fcf67826fa0c35bb03caf411ba542) @@ -1,14 +1,14 @@ /************************************************************************** * -* Copyright (c) 2020-2022 Diality Inc. - All Rights Reserved. +* Copyright (c) 2020-2023 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 DrainPump.c * * @author (last) Dara Navaei -* @date (last) 28-Aug-2022 +* @date (last) 03-Nov-2022 * * @author (original) Sean * @date (original) 08-Apr-2020 @@ -33,6 +33,7 @@ #include "TaskGeneral.h" #include "TaskPriority.h" #include "Timers.h" +#include "Utilities.h" #include "Valves.h" /** @@ -78,7 +79,10 @@ #define DRAIN_PUMP_MAX_CURRENT_A 2.2F ///< Drain pump maximum current in amps. #define DRAIN_PUMP_CURRENT_OUT_OF_RANGE_TIMEOUT_MS ( 2 * MS_PER_SECOND ) ///< Drain pump current out of range timeout in milliseconds. #define DRAIN_PUMP_DIR_OF_RANGE_TIMEOUT_MS ( 2 * MS_PER_SECOND ) ///< Drain pump direction out of range timeout in milliseconds. -#define DRAIN_PUMP_FORWARD_DIR 0 ///< Drain pump forward direction. +#define DRAIN_PUMP_FORWARD_DIR 1 ///< Drain pump forward direction. +#define DRAIN_PUMP_DIR_BIT_MASK 0x80 ///< Drain pump direction bit clear mask. +#define DRAIN_PUMP_DIR_ERROR_CNT_BIT_MASK 0x3F ///< Drain pump direction error count bit mask. +#define DRAIN_PUMP_DIR_FPGA_ERROR_TIMEOUT_MS ( 2 * MS_PER_SECOND ) ///< Drain pump direction hall sensor FPGA error time out in milliseconds. /// Enumeration of drain pump states. typedef enum DrainPump_States @@ -177,6 +181,9 @@ initPersistentAlarm( ALARM_ID_DRAIN_PUMP_OFF_FAULT, SAFETY_SHUTDOWN_TIMEOUT, SAFETY_SHUTDOWN_TIMEOUT ); initPersistentAlarm( ALARM_ID_DG_DRAIN_PUMP_CURRENT_OUT_OF_RANGE, DRAIN_PUMP_CURRENT_OUT_OF_RANGE_TIMEOUT_MS, DRAIN_PUMP_CURRENT_OUT_OF_RANGE_TIMEOUT_MS ); initPersistentAlarm( ALARM_ID_DG_DRAIN_PUMP_DIRECTION_INVALID, DRAIN_PUMP_DIR_OF_RANGE_TIMEOUT_MS, DRAIN_PUMP_DIR_OF_RANGE_TIMEOUT_MS ); + + initFPGAPersistentAlarm( FPGA_PERS_ERROR_DRAIN_PUMP_DIR_HALL_SENSOR, ALARM_ID_DG_DRAIN_PUMP_DIRECTION_FPGA_FAULT, + DRAIN_PUMP_DIR_FPGA_ERROR_TIMEOUT_MS, DRAIN_PUMP_DIR_FPGA_ERROR_TIMEOUT_MS ); } /*********************************************************************//** @@ -349,14 +356,22 @@ U16 fpgaADCSpeedCount = getFPGADrainPumpSpeed(); U16 fpgaADCCurrentCount = getFPGADrainPumpCurrentFeedback(); F32 currentA = getDrainPumpMeasuredCurrentA(); + U32 dirHallSensorErrorCount = (U32)( getFPGADrainPumpDirection() & DRAIN_PUMP_DIR_ERROR_CNT_BIT_MASK ); drainPumpMeasuredRPM.data = ( DRAIN_PUMP_OFF_RPM_ADC_COUNT == fpgaADCSpeedCount ? 0 : (U32)( RPM_CONVERSION_COEFF / (F32)fpgaADCSpeedCount ) ); drainPumpMeasuredCurrentA.data = (F32)fpgaADCCurrentCount * CURRENT_CONVERSION_COEFF; - drainPumpMeasuredDir.data = ( (U32)getFPGADrainPumpDirection() & 0x40 ) >> 7; + drainPumpMeasuredDir.data = (U32)( ( getFPGADrainPumpDirection() & DRAIN_PUMP_DIR_BIT_MASK ) >> SHIFT_BITS_BY_7 ); #ifndef _RELEASE_ if ( getSoftwareConfigStatus( SW_CONFIG_DISABLE_DRAIN_PUMP_MONITOR ) != SW_CONFIG_ENABLE_VALUE ) #endif { +#ifndef _RELEASE_ + if ( ( getHardwareConfigStatus() != HW_CONFIG_BETA ) && ( getCurrentOperationMode() != DG_MODE_INIT ) ) +#endif + { + checkFPGAPersistentErrorCountAlarm( FPGA_PERS_ERROR_DRAIN_PUMP_DIR_HALL_SENSOR, dirHallSensorErrorCount ); + } + switch( drainPumpState ) { case DRAIN_PUMP_OFF_STATE: @@ -374,7 +389,7 @@ } #ifndef _RELEASE_ - if ( ( getSoftwareConfigStatus( SW_CONFIG_ENABLE_V3_SYSTEM ) != SW_CONFIG_ENABLE_VALUE ) && ( getCurrentOperationMode() != DG_MODE_INIT ) ) + if ( ( getHardwareConfigStatus() != HW_CONFIG_BETA ) && ( getCurrentOperationMode() != DG_MODE_INIT ) ) #endif { checkPersistentAlarm( ALARM_ID_DG_DRAIN_PUMP_CURRENT_OUT_OF_RANGE, isOffCurrentOut, currentA, DRAIN_PUMP_MAX_CURRENT_WHEN_OFF_A ); @@ -395,7 +410,7 @@ checkPersistentAlarm( ALARM_ID_DRAIN_PUMP_OFF_FAULT, FALSE, getDrainPumpMeasuredRPM(), MIN_DRAIN_PUMP_RPM ); #ifndef _RELEASE_ - if ( ( getSoftwareConfigStatus( SW_CONFIG_ENABLE_V3_SYSTEM ) != SW_CONFIG_ENABLE_VALUE ) && ( getCurrentOperationMode() != DG_MODE_INIT ) ) + if ( ( getHardwareConfigStatus() != HW_CONFIG_BETA ) && ( getCurrentOperationMode() != DG_MODE_INIT ) ) #endif { checkPersistentAlarm( ALARM_ID_DG_DRAIN_PUMP_DIRECTION_INVALID, isDirInvalid, (F32)direction, DRAIN_PUMP_FORWARD_DIR ); @@ -409,7 +424,7 @@ BOOL isDirInvalid = ( direction != DRAIN_PUMP_FORWARD_DIR ? TRUE : FALSE ); #ifndef _RELEASE_ - if ( ( getSoftwareConfigStatus( SW_CONFIG_ENABLE_V3_SYSTEM ) != SW_CONFIG_ENABLE_VALUE ) && ( getCurrentOperationMode() != DG_MODE_INIT ) ) + if ( ( getHardwareConfigStatus() != HW_CONFIG_BETA ) && ( getCurrentOperationMode() != DG_MODE_INIT ) ) #endif { checkPersistentAlarm( ALARM_ID_DG_DRAIN_PUMP_DIRECTION_INVALID, isDirInvalid, (F32)direction, DRAIN_PUMP_FORWARD_DIR ); @@ -426,7 +441,7 @@ } #ifndef _RELEASE_ - if ( ( getSoftwareConfigStatus( SW_CONFIG_ENABLE_V3_SYSTEM ) != SW_CONFIG_ENABLE_VALUE ) && ( getCurrentOperationMode() != DG_MODE_INIT ) ) + if ( ( getHardwareConfigStatus() != HW_CONFIG_BETA ) && ( getCurrentOperationMode() != DG_MODE_INIT ) ) #endif { // Check the persistent alarm for the maximum drain pump current @@ -479,7 +494,7 @@ drainPumpControlModeSet = drainPumpControlMode; signalNewRPMRequest = TRUE; } - pendingDrainPumpCmdTarget = 0.0; + pendingDrainPumpCmdTarget = 0.0F; pendingDrainPumpCmd = DRAIN_PUMP_OFF_STATE; } } @@ -904,7 +919,7 @@ drainPumpMeasuredRPM.ovData = value; drainPumpMeasuredRPM.override = OVERRIDE_KEY; drainPumpMeasuredRPM.ovInitData = drainPumpMeasuredRPM.data; - status = TRUE; + status = TRUE; } } @@ -928,10 +943,106 @@ { drainPumpMeasuredRPM.ovData = drainPumpMeasuredRPM.ovInitData; drainPumpMeasuredRPM.override = OVERRIDE_RESET; - status = TRUE; + status = TRUE; } return status; } +/*********************************************************************//** + * @brief + * The testSetDrainPumpMeasuredCurrentOverride function overrides the drain pump + * measured current data. + * @details Inputs: none + * @details Outputs: drainPumpMeasuredCurrentA + * @param value override drain pump measured current data + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testSetDrainPumpMeasuredCurrentOverride( F32 value ) +{ + BOOL status = FALSE; + + // Check if the user is logged in + if ( TRUE == isTestingActivated() ) + { + drainPumpMeasuredCurrentA.ovData = value; + drainPumpMeasuredCurrentA.override = OVERRIDE_KEY; + drainPumpMeasuredCurrentA.ovInitData = drainPumpMeasuredCurrentA.data; + status = TRUE; + } + + return status; +} + +/*********************************************************************//** + * @brief + * The testResetDrainPumpMeasuredCurrentOverride function resets the drain pump + * measured current data. + * @details Inputs: none + * @details Outputs: drainPumpMeasuredCurrentA + * @return TRUE if override reset successful, FALSE if not + *************************************************************************/ +BOOL testResetDrainPumpMeasuredCurrentOverride( void ) +{ + BOOL status = FALSE; + + // Check if the user is logged in + if ( TRUE == isTestingActivated() ) + { + drainPumpMeasuredCurrentA.ovData = drainPumpMeasuredCurrentA.ovInitData; + drainPumpMeasuredCurrentA.override = OVERRIDE_RESET; + status = TRUE; + } + + return status; +} + +/*********************************************************************//** + * @brief + * The testSetDrainPumpMeasuredDirectionOverride function overrides the drain pump + * measured direction data. + * @details Inputs: none + * @details Outputs: drainPumpMeasuredDir + * @param value override drain pump measured direction data + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testSetDrainPumpMeasuredDirectionOverride( U32 value ) +{ + BOOL status = FALSE; + + // Check if the user is logged in + if ( TRUE == isTestingActivated() ) + { + drainPumpMeasuredDir.ovData = value; + drainPumpMeasuredDir.override = OVERRIDE_KEY; + drainPumpMeasuredDir.ovInitData = drainPumpMeasuredDir.data; + status = TRUE; + } + + return status; +} + +/*********************************************************************//** + * @brief + * The testResetDrainPumpMeasuredDirectionOverride function resets the drain pump + * measured direction data. + * @details Inputs: none + * @details Outputs: drainPumpMeasuredDir + * @return TRUE if override reset successful, FALSE if not + *************************************************************************/ +BOOL testResetDrainPumpMeasuredDirectionOverride( void ) +{ + BOOL status = FALSE; + + // Check if the user is logged in + if ( TRUE == isTestingActivated() ) + { + drainPumpMeasuredDir.ovData = drainPumpMeasuredDir.ovInitData; + drainPumpMeasuredDir.override = OVERRIDE_RESET; + status = TRUE; + } + + return status; +} + /**@}*/