Index: firmware/App/Controllers/Fans.c =================================================================== diff -u -rfba89d67dd2bef913e85a13563e2aa49f0e2e2f5 -rd3819286869611f9c02add72a0f8e321598fdf42 --- firmware/App/Controllers/Fans.c (.../Fans.c) (revision fba89d67dd2bef913e85a13563e2aa49f0e2e2f5) +++ firmware/App/Controllers/Fans.c (.../Fans.c) (revision d3819286869611f9c02add72a0f8e321598fdf42) @@ -32,9 +32,11 @@ #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 5000 ///< Fans max allowed RPM value. +#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 @@ -61,12 +63,11 @@ } FAN_STATUS_T; static FAN_STATUS_T fansStatus; ///< Fans status. -static SELF_TEST_STATUS_T fansSelfTestResult = SELF_TEST_STATUS_IN_PROGRESS; ///< Fans self test result. -static FANS_SELF_TEST_STATES_T fansSelfTestState = FANS_SELF_TEST_START_STATE; ///< Fans self test state. 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 ); @@ -76,9 +77,6 @@ static OVERRIDE_U32_T fansPublishInterval = { FANS_DATA_PUBLISH_INTERVAL, FANS_DATA_PUBLISH_INTERVAL, 0, 0 }; ///< Fans publish time interval override -static FANS_SELF_TEST_STATES_T handleSelfTestStart( void ); -static FANS_SELF_TEST_STATES_T handleSelfTestCheckRPM( void ); - static FANS_EXEC_STATES_T handleExecStateWaitForPOST( void ); static FANS_EXEC_STATES_T handleExecStateRun( void ); @@ -87,28 +85,25 @@ static F32 getMaximumTemperature( void ); static void convertTogglePeriod2RPM( void ); static void monitorFans( void ); -static U32 getPublishFansDataInterval( void ); static void publishFansData( void ); /*********************************************************************//** * @brief * The initFans function initializes the fans module. - * @details Inputs: fansExecState, fansSelfTestReslt, fansSelfTestState, - * fansStatus, fansControlCounter, fansPublishCounter - * @details Outputs: fansExecState, fansSelfTestReslt, fansSelfTestState, - * fansStatus, fansControlCounter, fansPublishCounter + * @details Inputs: fansExecState, fansStatus, fansControlCounter, + * fansPublishCounter + * @details Outputs: fansExecState, fansStatus, fansControlCounter, + * fansPublishCounter * @return none *************************************************************************/ void initFans( void ) { // Initialize the variables fansExecState = FANS_EXEC_STATE_WAIT_FOR_POST_STATE; - fansSelfTestResult = SELF_TEST_STATUS_IN_PROGRESS; - fansSelfTestState = FANS_SELF_TEST_START_STATE; - fansExecState = FANS_EXEC_STATE_WAIT_FOR_POST_STATE; fansControlCounter = 0; fansPublishCounter = 0; fansMonitorCounter = 0; + isPOSTComplete = FALSE; // 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 ); @@ -117,34 +112,21 @@ /*********************************************************************//** * @brief * The execFansSelfTest function executes the fans self test. - * @details Inputs: fansSelfTestState, fansSelfTestReslt - * @details Outputs: fansSelfTestState, fansSelfTestReslt + * @details Inputs: none + * @details Outputs: isPOSTComplete * @return Status of self test *************************************************************************/ SELF_TEST_STATUS_T execFansSelfTest( void ) { - switch ( fansSelfTestState ) - { - case FANS_SELF_TEST_START_STATE: - fansSelfTestState = handleSelfTestStart(); - break; + SELF_TEST_STATUS_T status = SELF_TEST_STATUS_IN_PROGRESS; - case FANS_SELF_TEST_CHECK_RPM_STATE: - fansSelfTestState = handleSelfTestCheckRPM(); - break; + // TODO implement the calibration processing function. + // It returns a pass for now - case FAN_SELF_TEST_COMPLETE_STATE: - // Done with POST. Do nothing - break; + isPOSTComplete = TRUE; + status = SELF_TEST_STATUS_PASSED; - default: - // Wrong state called - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_FAN_INVALID_SELF_TEST_STATE, fansSelfTestState ); - fansSelfTestState = FAN_SELF_TEST_COMPLETE_STATE; - break; - } - - return fansSelfTestResult; + return status; } /*********************************************************************//** @@ -157,7 +139,7 @@ void execFans( void ) { // Monitor the fans - monitorFans(); + //monitorFans(); TODO uncomment. this is to investigate why the fans RPM are out of range switch ( fansExecState ) { @@ -205,69 +187,6 @@ /*********************************************************************//** * @brief - * The handleSelfTestStart function handles the start state of the fans' - * self test. - * @details Inputs: none - * @details Outputs: none - * @return next state of self test - *************************************************************************/ -static FANS_SELF_TEST_STATES_T handleSelfTestStart( void ) -{ - FANS_SELF_TEST_STATES_T state = FANS_SELF_TEST_CHECK_RPM_STATE; - - // Set the fans to the target PWM for the next stage - setInletFansDutyCycle( FANS_SELF_TEST_TARGET_PWM ); - setOutletFansDutyCycle( FANS_SELF_TEST_TARGET_PWM ); - state = FANS_SELF_TEST_CHECK_RPM_STATE; - - return state; -} - -/*********************************************************************//** - * @brief - * The handleSelfTestCheckRPM function handles the check RPM state of the - * fans' self test. - * @details Inputs: fansStatus - * @details Outputs: none - * @return next state of self test - *************************************************************************/ -static FANS_SELF_TEST_STATES_T handleSelfTestCheckRPM( void ) -{ - FANS_SELF_TEST_STATES_T state = FANS_SELF_TEST_CHECK_RPM_STATE; - - FAN_NAMES_T fan; - - // Wait for the fans to run for a certain period of time before checking their RPM - if ( ++fansControlCounter > FANS_SELF_TEST_WAIT_INTERVAL ) - { - // Assuming the test will pass - fansSelfTestResult = SELF_TEST_STATUS_PASSED; - - convertTogglePeriod2RPM(); - - // Loop through all the fans to check their RPM. They should be above the specified RPM - for( fan = FAN_INLET_1; fan < NUM_OF_FANS_NAMES; fan++ ) - { - if ( fansStatus.rpm[ fan ] < MIN_TARGET_RPM_IN_SELF_TEST ) - { - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_FAN_RPM_OUT_OF_RANGE, fan, fansStatus.rpm[ fan ] ); - - fansSelfTestResult = SELF_TEST_STATUS_FAILED; - } - } - - // Turn off the fans, done with self test - setInletFansDutyCycle( 0.0 ); - setOutletFansDutyCycle( 0.0 ); - - state = FAN_SELF_TEST_COMPLETE_STATE; - } - - return state; -} - -/*********************************************************************//** - * @brief * The handleFansExecStateStart function handles the start state of the * fans exec state machine. * @details Inputs: none @@ -279,7 +198,7 @@ FANS_EXEC_STATES_T state = FANS_EXEC_STATE_WAIT_FOR_POST_STATE; // Wait for the self test to finish before starting the fans - if ( fansSelfTestState == FAN_SELF_TEST_COMPLETE_STATE ) + if ( TRUE == isPOSTComplete ) { // Start the fans with minimum PWM. The control will decide the next PWM automatically. setInletFansDutyCycle( FANS_MIN_DUTY_CYCLE ); @@ -308,15 +227,11 @@ FANS_EXEC_STATES_T state = FANS_EXEC_STATE_RUN_STATE; // Check if it is time to check for the control - if( ++fansControlCounter > FANS_CONTROL_INTERVAL ) + if ( ++fansControlCounter > FANS_CONTROL_INTERVAL ) { // Get the maximum temperature among all the thermistors and temperature sensors to run fan from the hottest temperature F32 temperature = getMaximumTemperature(); - //TODO REMOVE FOR TESTING - temperature = getThermistorTemperatureValue( THERMISTOR_ONBOARD_NTC ); - //TODO REMOVE FOR TESTING only - // Solve the linear equation to calculate the duty cycle from temperature F32 dutyCycle = ( SLOPE * ( temperature - MIN_ALLOWED_AMBIENT_TEMPERATURE ) ) + FANS_MIN_DUTY_CYCLE; @@ -477,11 +392,18 @@ if ( ++fansMonitorCounter >= FANS_MONITOR_INTERVAL_COUNT ) { + // 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++ ) { - BOOL const fanRpmOutOfRange = ( fansStatus.rpm[ fan ] >= FANS_MAX_ALLOWED_RPM ) || ( fansStatus.rpm[ fan ] <= FANS_MIN_ALLOWED_RPM ); + 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 ); } @@ -491,25 +413,6 @@ /*********************************************************************//** * @brief - * The getPublishFansDataInterval function gets the fans data publish interval. - * @details Inputs: fansPublishInterval - * @details Outputs: none - * @return data publish time interval in counts - *************************************************************************/ -static U32 getPublishFansDataInterval( void ) -{ - U32 result = fansPublishInterval.data; - - if ( OVERRIDE_KEY == fansPublishInterval.override ) - { - result = fansPublishInterval.ovData; - } - - return result; -} - -/*********************************************************************//** - * @brief * The publishFansData function publishes the fans data at the specified * time interval. * @details Inputs: dataPublishCounter @@ -518,7 +421,7 @@ *************************************************************************/ static void publishFansData( void ) { - if ( ++fansPublishCounter > getPublishFansDataInterval() ) + if ( ++fansPublishCounter > getU32OverrideValue( &fansPublishInterval ) ) { FANS_DATA_T fansData;