Index: firmware/App/Controllers/Fans.c =================================================================== diff -u -r22f1a58ac8e419353ec004b04e7c765c1d59df2b -r2d8f95eaae3bcb7027f5e96809ddc6e9c0efbc4c --- firmware/App/Controllers/Fans.c (.../Fans.c) (revision 22f1a58ac8e419353ec004b04e7c765c1d59df2b) +++ firmware/App/Controllers/Fans.c (.../Fans.c) (revision 2d8f95eaae3bcb7027f5e96809ddc6e9c0efbc4c) @@ -6,9 +6,7 @@ #include "PersistentAlarm.h" #include "SystemCommMessages.h" #include "TaskGeneral.h" -#include "TemperatureSensors.h" #include "Thermistors.h" -#include "Timers.h" /** * @addtogroup Fans @@ -17,60 +15,67 @@ // ********** private definitions ********** -#define FANS_MIN_DUTY_CYCLE 0.1 ///< Fans min PWM. -#define FANS_MAX_DUTY_CYCLE 0.95 ///< Fans max PWM. -#define MIN_ALLOWED_AMBIENT_TEMPERATURE 20 ///< Min allowed ambient temperature. -#define MAX_ALLOWED_AMBINET_TEMPERATURE 70 ///< Max allowed ambient temperature. -#define FANS_MAX_ALLOWED_RAMP_UP_DELTA_DUTY_CYCLE 0.3 ///< Fans max allowed ramp up PWM change. -#define FANS_MAX_ALLOWED_RAMP_DOWN_DELTA_DUTY_CYCLE 0.005 ///< Fans min allowed ramp down PWM change. +#define FANS_MIN_DUTY_CYCLE 0.1 ///< Fans min PWM. +#define FANS_MAX_DUTY_CYCLE 0.95 ///< Fans max PWM. +#define MIN_ALLOWED_AMBIENT_TEMPERATURE 20 ///< Min allowed ambient temperature. +#define MAX_ALLOWED_AMBINET_TEMPERATURE 70 ///< Max allowed ambient temperature. +#define FANS_MAX_ALLOWED_RAMP_UP_DELTA_DUTY_CYCLE 0.3 ///< Fans max allowed ramp up PWM change. +#define FANS_MAX_ALLOWED_RAMP_DOWN_DELTA_DUTY_CYCLE 0.005 ///< Fans min allowed ramp down PWM change. -#define TOGGLE_PERIOD_RESOLUTION_SECONDS 0.0000025 ///< FPGA fans toggle period resolution in micro seconds. -#define ROTATIONAL_TO_TOGGLE_PERIOD_CONVERSION 4 ///< FPGA rotational to toggle period conversion coefficient. +#define TOGGLE_PERIOD_RESOLUTION_SECONDS 0.0000025 ///< FPGA fans toggle period resolution in micro seconds. +#define ROTATIONAL_TO_TOGGLE_PERIOD_CONVERSION 4 ///< FPGA rotational to toggle period conversion coefficient. -#define FANS_DATA_PUBLISH_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Fans publish data time interval in counts. -#define FANS_CONTROL_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Fans control time interval in counts. -#define FANS_ZERO_RPM_TOGGLE_PERIOD_VALUE 0xFFFF ///< Fans zero RPM toggle period value. -#define MIN_TARGET_RPM_IN_SELF_TEST 1000 ///< Fans min target RPM that they should be during POST. -#define FANS_SELF_TEST_WAIT_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Fans self test wait time for the fans to get to RPM. -#define FANS_SELF_TEST_TARGET_PWM 0.5 ///< Fans self test target PWM for testing the fans are running. -#define FANS_MAX_ALLOWED_RPM_OUT_OF_RANGE_INTERVAL ( 3 * MS_PER_SECOND ) ///< Fans max allowed RPM out of range time interval. -#define FANS_MAX_ALLOWED_RPM 5500 ///< Fans max allowed RPM value. -#define FANS_MIN_ALLOWED_RPM 150 ///< Fans max allowed RPM value. -#define FANS_MONITOR_INTERVAL_COUNT ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Fans monitor time interval in counts. -#define FANS_MIN_RPM_OUT_OF_RANGE_TOL 0.25 ///< Fans min RPM out of range tolerance. -#define FANS_MAX_RPM_OUT_OF_RANGE_TOL 0.5 ///< Fans max RPM out of range tolerance. +#define FANS_DATA_PUBLISH_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Fans publish data time interval in counts. +#define FANS_CONTROL_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Fans control time interval in counts. +#define FANS_ZERO_RPM_TOGGLE_PERIOD_VALUE 0xFFFF ///< Fans zero RPM toggle period value. +#define MIN_TARGET_RPM_IN_SELF_TEST 1000 ///< Fans min target RPM that they should be during POST. +#define FANS_SELF_TEST_WAIT_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Fans self test wait time for the fans to get to RPM. +#define FANS_SELF_TEST_TARGET_PWM 0.5 ///< Fans self test target PWM for testing the fans are running. +#define FANS_MAX_ALLOWED_RPM_OUT_OF_RANGE_INTERVAL ( 3 * MS_PER_SECOND ) ///< Fans max allowed RPM out of range time interval. +#define FANS_MAX_ALLOWED_RPM 5500 ///< Fans max allowed RPM value. +#define FANS_MIN_ALLOWED_RPM 150 ///< Fans max allowed RPM value. +#define FANS_MONITOR_INTERVAL_COUNT ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Fans monitor time interval in counts. +#define FANS_MIN_RPM_OUT_OF_RANGE_TOL 0.25 ///< Fans min RPM out of range tolerance. +#define FANS_MAX_RPM_OUT_OF_RANGE_TOL 0.5 ///< Fans max RPM out of range tolerance. +/// Fans self test states +typedef enum fans_Self_Test +{ + FANS_SELF_TEST_START_STATE = 0, ///< Fans self test start state + FANS_SELF_TEST_CHECK_RPM_STATE, ///< Fans self test check RPM state + FAN_SELF_TEST_COMPLETE_STATE, ///< Fans self test complete state + NUM_OF_SELF_TEST_STATES, ///< Number of fans self test +} FANS_SELF_TEST_STATES_T; + /// Fans exec states typedef enum fans_Exec_States { - FANS_EXEC_STATE_WAIT_FOR_POST_STATE = 0, ///< Fans exec state start state. - FANS_EXEC_STATE_RUN_STATE, ///< Fans exec state run state. - NUM_OF_FANS_EXEC_STATES, ///< Number of fans exec states. + FANS_EXEC_STATE_WAIT_FOR_POST_STATE = 0, ///< Fans exec state start state + FANS_EXEC_STATE_RUN_STATE, ///< Fans exec state run state + NUM_OF_FANS_EXEC_STATES, ///< Number of fans exec states } FANS_EXEC_STATES_T; /// Fans status struct typedef struct { - F32 targetDutyCycle; ///< Fan's target duty cycle that was fed to the fans. - OVERRIDE_F32_T rpm[ NUM_OF_FANS_NAMES ]; ///< Fan's current tachometers reading in RPM. + F32 targetDutyCycle; ///< Fan's target duty cycle that was fed to the fans + U32 rpm[ NUM_OF_FANS_NAMES ]; ///< Fan's current tachometers reading in RPM } FAN_STATUS_T; -static FAN_STATUS_T fansStatus; ///< Fans status. -static FANS_EXEC_STATES_T fansExecState = FANS_EXEC_STATE_WAIT_FOR_POST_STATE; ///< Fans exec state. -static U32 fansControlCounter = 0; ///< Fans control interval counter. -static U32 fansPublishCounter = 0; ///< Fans data publish interval counter. -static U32 fansMonitorCounter = 0; ///< Fans monitor interval counter. -static BOOL isPOSTComplete = FALSE; ///< Flag that indicates whether POST is complete or not. -static BOOL hasAlarmBeenRaised = FALSE; ///< Flag that indicates whether the RPM out of range alarm been raise. -static U32 rpmAlarmStartTimer = 0; ///< RPM out of range alarm start timer when the alarm is raised. +static FAN_STATUS_T fansStatus; ///< Fans status. +static FANS_EXEC_STATES_T fansExecState = FANS_EXEC_STATE_WAIT_FOR_POST_STATE; ///< Fans exec state. +static U32 fansControlCounter = 0; ///< Fans control interval counter. +static U32 fansPublishCounter = 0; ///< Fans data publish interval counter. +static U32 fansMonitorCounter = 0; ///< Fans monitor interval counter. +static BOOL isPOSTComplete = FALSE; ///< Flag that indicates whether POST is complete or not. /// Temperature to duty cycle conversion slope (duty cycle not in percent) static const F32 SLOPE = ( FANS_MAX_DUTY_CYCLE - FANS_MIN_DUTY_CYCLE ) / ( MAX_ALLOWED_AMBINET_TEMPERATURE - MIN_ALLOWED_AMBIENT_TEMPERATURE ); /// FGPA Toggle to RPM conversion coefficient static const F32 TOGGLE_PERIOD_2_RPM_COEFFICIENT = SEC_PER_MIN / ( TOGGLE_PERIOD_RESOLUTION_SECONDS * ROTATIONAL_TO_TOGGLE_PERIOD_CONVERSION ); -static OVERRIDE_U32_T fansPublishInterval = { FANS_DATA_PUBLISH_INTERVAL, FANS_DATA_PUBLISH_INTERVAL, 0, 0 }; ///< Fans publish time interval override. +static OVERRIDE_U32_T fansPublishInterval = { FANS_DATA_PUBLISH_INTERVAL, FANS_DATA_PUBLISH_INTERVAL, 0, 0 }; ///< Fans publish time interval override static FANS_EXEC_STATES_T handleExecStateWaitForPOST( void ); static FANS_EXEC_STATES_T handleExecStateRun( void ); @@ -86,34 +91,21 @@ /*********************************************************************//** * @brief * The initFans function initializes the fans module. - * @details Inputs: none + * @details Inputs: fansExecState, fansStatus, fansControlCounter, + * fansPublishCounter * @details Outputs: fansExecState, fansStatus, fansControlCounter, - * fansPublishCounter, fansMonitorCounter, isPOSTComplete, hasAlarmBeenRaised, - * rpmAlarmStartTimer + * fansPublishCounter * @return none *************************************************************************/ void initFans( void ) { - FAN_NAMES_T fan; - // Initialize the variables fansExecState = FANS_EXEC_STATE_WAIT_FOR_POST_STATE; fansControlCounter = 0; fansPublishCounter = 0; fansMonitorCounter = 0; isPOSTComplete = FALSE; - hasAlarmBeenRaised = FALSE; - rpmAlarmStartTimer = 0; - // Initialize the fans - for ( fan = FAN_INLET_1; fan < NUM_OF_FANS_NAMES; fan++ ) - { - fansStatus.rpm[ fan ].data = 0.0; - fansStatus.rpm[ fan ].ovData = 0.0; - fansStatus.rpm[ fan ].ovInitData = 0.0; - fansStatus.rpm[ fan ].override = OVERRIDE_RESET; - } - // Initialize a persistent alarm for fans RPM out of range initPersistentAlarm( ALARM_ID_DG_FAN_RPM_OUT_OF_RANGE, FANS_MAX_ALLOWED_RPM_OUT_OF_RANGE_INTERVAL, FANS_MAX_ALLOWED_RPM_OUT_OF_RANGE_INTERVAL ); } @@ -147,6 +139,9 @@ *************************************************************************/ void execFans( void ) { + // Monitor the fans + //monitorFans(); TODO uncomment. this is to investigate why the fans RPM are out of range + switch ( fansExecState ) { case FANS_EXEC_STATE_WAIT_FOR_POST_STATE: @@ -163,12 +158,6 @@ break; } - // Convert the counts to RPM - convertTogglePeriod2RPM(); - - // Monitor the RPM of the fans - monitorFans(); - publishFansData(); } @@ -182,18 +171,12 @@ *************************************************************************/ F32 getMeasuredFanRPM( FAN_NAMES_T fan ) { - F32 rpm; + F32 rpm = 0.0; // Check if the called fan is in range if ( fan < NUM_OF_FANS_NAMES ) { - // Assume there is no override - rpm = fansStatus.rpm[ fan ].data; - - if ( OVERRIDE_KEY == fansStatus.rpm[ fan ].override ) - { - rpm = fansStatus.rpm[ fan ].ovData; - } + rpm = fansStatus.rpm[ fan ]; } else { @@ -342,40 +325,30 @@ { F32 temperature; THERMISTORS_TEMP_SENSORS_T thermistor; - F32 maxTemperature; + F32 maxTemperature = 0.0; // Loop through the sensors and thermistors for ( thermistor = THERMISTOR_ONBOARD_NTC; thermistor < NUM_OF_THERMISTORS; thermistor++ ) { + // Get the value temperature = getThermistorTemperatureValue( thermistor ); - maxTemperature = ( temperature > maxTemperature ? temperature : maxTemperature ); + + // If the latest temperature read is greater than the max temperature, + // set the maximum temperature there + if ( temperature > maxTemperature ) + { + maxTemperature = temperature; + } } - // The temperature sensors that are on the hardware and are not on the fluid path are used to - // decide the maximum temperature - temperature = getTemperatureValue( TEMPSENSORS_FPGA_BOARD_SENSOR ); - maxTemperature = ( temperature > maxTemperature ? temperature : maxTemperature ); - - temperature = getTemperatureValue( TEMPSENSORS_LOAD_CELL_A1_B1 ); - maxTemperature = ( temperature > maxTemperature ? temperature : maxTemperature ); - - temperature = getTemperatureValue( TEMPSENSORS_LOAD_CELL_A2_B2 ); - maxTemperature = ( temperature > maxTemperature ? temperature : maxTemperature ); - - temperature = getTemperatureValue( TEMPSENSORS_INTERNAL_THDO_RTD ); - maxTemperature = ( temperature > maxTemperature ? temperature : maxTemperature ); - - temperature = getTemperatureValue( TEMPSENSORS_INTERNAL_TDI_RTD ); - maxTemperature = ( temperature > maxTemperature ? temperature : maxTemperature ); - return maxTemperature; } /*********************************************************************//** * @brief * The convertTogglePeriod2RPM function runs through the list of the fans * to get the FPGA pulse from them and converts them to RPM. - * @details Inputs: none + * @details Inputs: fansStatus, toggle2RPMCoefficient * @details Outputs: fansStatus * @return none ************************************************************************/ @@ -397,21 +370,21 @@ // Otherwise, convert the pulse to RPM if ( togglePeriods[ fan ] == FANS_ZERO_RPM_TOGGLE_PERIOD_VALUE ) { - fansStatus.rpm[ fan ].data = 0; + fansStatus.rpm[ fan ] = 0; } else { // Convert toggle period to RPM - fansStatus.rpm[ fan ].data = TOGGLE_PERIOD_2_RPM_COEFFICIENT / togglePeriods[ fan ]; + fansStatus.rpm[ fan ] = TOGGLE_PERIOD_2_RPM_COEFFICIENT / togglePeriods[ fan ]; } } } /*********************************************************************//** * @brief * The monitorFans function monitors the fans for RPM. - * @details Inputs: fansMonitorCounter, fansStatus - * @details Outputs: fansMonitorCounter + * @details Inputs: fansStatus + * @details Outputs: none * @return none *************************************************************************/ static void monitorFans( void ) @@ -420,36 +393,19 @@ if ( ++fansMonitorCounter >= FANS_MONITOR_INTERVAL_COUNT ) { - // If the fans alarm has been raise already, do not raise again - if ( FALSE == hasAlarmBeenRaised ) - { - BOOL isFanRPMOutOfRange; + // The RPM is expected to be 5500 @ 100% duty cycle + // The nominal RPM = duty cycle * 5500 / 1.0 + // The RPM tolerance is -25% to +50% of the nominal RPM + F32 fansNominalRPM = fansStatus.targetDutyCycle * FANS_MAX_ALLOWED_RPM; + F32 fansMinAllowedRPM = fansNominalRPM - ( fansNominalRPM * FANS_MIN_RPM_OUT_OF_RANGE_TOL ); + F32 fansMaxAllowedRPM = fansNominalRPM - ( fansNominalRPM * FANS_MAX_RPM_OUT_OF_RANGE_TOL ); - // The RPM is expected to be 5500 @ 100% duty cycle - // The nominal RPM = duty cycle * 5500 / 1.0 - // The RPM tolerance is -25% to +50% of the nominal RPM - F32 fansNominalRPM = fansStatus.targetDutyCycle * FANS_MAX_ALLOWED_RPM; - F32 fansMinAllowedRPM = fansNominalRPM - ( fansNominalRPM * FANS_MIN_RPM_OUT_OF_RANGE_TOL ); - F32 fansMaxAllowedRPM = fansNominalRPM + ( fansNominalRPM * FANS_MAX_RPM_OUT_OF_RANGE_TOL ); + convertTogglePeriod2RPM(); - for ( fan = FAN_INLET_1; fan < NUM_OF_FANS_NAMES; fan++ ) - { - isFanRPMOutOfRange = ( getMeasuredFanRPM( fan ) < fansMinAllowedRPM ) || ( getMeasuredFanRPM( fan ) > fansMaxAllowedRPM ); - checkPersistentAlarm( ALARM_ID_DG_FAN_RPM_OUT_OF_RANGE, isFanRPMOutOfRange, getMeasuredFanRPM( fan ), FANS_MAX_ALLOWED_RPM ); - - // If the RPM out of range alarm has been raised, do not raise it again, until its alarm silence time has been elapsed - hasAlarmBeenRaised = ( TRUE == isAlarmActive( ALARM_ID_DG_FAN_RPM_OUT_OF_RANGE ) ? TRUE : FALSE ); - - if ( ( TRUE == hasAlarmBeenRaised ) && ( 0 == rpmAlarmStartTimer ) ) - { - rpmAlarmStartTimer = getMSTimerCount(); - } - } - } - else if ( ( TRUE == hasAlarmBeenRaised ) && ( TRUE == didTimeout( rpmAlarmStartTimer, SECONDS_IN_A_DAY ) ) ) + for ( fan = FAN_INLET_1; fan < NUM_OF_FANS_NAMES; fan++ ) { - hasAlarmBeenRaised = FALSE; - rpmAlarmStartTimer = 0; + BOOL const fanRpmOutOfRange = ( fansStatus.rpm[ fan ] < fansMinAllowedRPM ) || ( fansStatus.rpm[ fan ] > fansMaxAllowedRPM ); + checkPersistentAlarm( ALARM_ID_DG_FAN_RPM_OUT_OF_RANGE, fanRpmOutOfRange, fansStatus.rpm[ fan ], FANS_MAX_ALLOWED_RPM ); } fansMonitorCounter = 0; @@ -490,12 +446,12 @@ FANS_DATA_T fansData; fansData.fansTargetDutyCycle = fansStatus.targetDutyCycle * FRACTION_TO_PERCENT_FACTOR; - fansData.fanInlet1RPM = getMeasuredFanRPM( FAN_INLET_1 ); - fansData.fanInlet2RPM = getMeasuredFanRPM( FAN_INLET_2 ); - fansData.fanInlet3RPM = getMeasuredFanRPM( FAN_INLET_3 ); - fansData.fanOutlet1RPM = getMeasuredFanRPM( FAN_OUTLET_1 ); - fansData.fanOutlet2RPM = getMeasuredFanRPM( FAN_OUTLET_2 ); - fansData.fanOutlet3RPM = getMeasuredFanRPM( FAN_OUTLET_3 ); + fansData.fanInlet1RPM = fansStatus.rpm[ FAN_INLET_1 ]; + fansData.fanInlet2RPM = fansStatus.rpm[ FAN_INLET_2 ]; + fansData.fanInlet3RPM = fansStatus.rpm[ FAN_INLET_3 ]; + fansData.fanOutlet1RPM = fansStatus.rpm[ FAN_OUTLET_1 ]; + fansData.fanOutlet2RPM = fansStatus.rpm[ FAN_OUTLET_2 ]; + fansData.fanOutlet3RPM = fansStatus.rpm[ FAN_OUTLET_3 ]; broadcastFansData( &fansData ); @@ -556,55 +512,4 @@ return result; } -/*********************************************************************//** - * @brief - * The testSetFanRPMOverride function overrides the RPM of a fan. - * @details Inputs: none - * @details Outputs: fansStatus - * @param fanId fan ID - * @param rpm the RPM override value - * @return TRUE if override successful, FALSE if not - *************************************************************************/ -BOOL testSetFanRPMOverride( U32 fanId, F32 rpm ) -{ - BOOL result = FALSE; - - if ( fanId < NUM_OF_FANS_NAMES ) - { - if ( TRUE == isTestingActivated() ) - { - result = TRUE; - fansStatus.rpm[ fanId ].ovData = rpm; - fansStatus.rpm[ fanId ].override = OVERRIDE_KEY; - } - } - - return result; -} - -/*********************************************************************//** - * @brief - * The testResetFanRPMOverride function resets the override value of a fan. - * @details Inputs: none - * @details Outputs: fansStatus - * @param fanId fan index - * @return TRUE if override successful, FALSE if not - *************************************************************************/ -BOOL testResetFanRPMOverride( U32 fanId ) -{ - BOOL result = FALSE; - - if ( fanId < NUM_OF_FANS_NAMES ) - { - if ( TRUE == isTestingActivated() ) - { - result = TRUE; - fansStatus.rpm[ fanId ].ovData = fansStatus.rpm[ fanId ].ovInitData; - fansStatus.rpm[ fanId ].override = OVERRIDE_RESET; - } - } - - return result; -} - /**@}*/