Index: firmware/App/Controllers/Fans.c =================================================================== diff -u -rcc8b9ddb9905161ddb0dc2af6bfbf863408669c8 -r72376b7008cfe0e1a8213b547116561d28acd55a --- firmware/App/Controllers/Fans.c (.../Fans.c) (revision cc8b9ddb9905161ddb0dc2af6bfbf863408669c8) +++ firmware/App/Controllers/Fans.c (.../Fans.c) (revision 72376b7008cfe0e1a8213b547116561d28acd55a) @@ -16,10 +16,12 @@ ***************************************************************************/ #include "etpwm.h" +#include "math.h" #include "Fans.h" #include "FPGA.h" #include "MessageSupport.h" +#include "NVDataMgmt.h" #include "PersistentAlarm.h" #include "SystemCommMessages.h" #include "TaskGeneral.h" @@ -55,6 +57,7 @@ #define FANS_MIN_ALLOWED_RPM 150 ///< Fans max allowed RPM value. #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 DATA_PUBLISH_COUNTER_START_COUNT 4 ///< Data publish counter start count. /// Fans exec states typedef enum fans_Exec_States @@ -75,11 +78,12 @@ 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 fansPublishCounter; ///< Fans data publish 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 OVERRIDE_U32_T rpmAlarmStartTimeOffset = { 0, 0, 0, 0 }; ///< RPM out of range alarm start time offset. static U32 rpmAlarmStartTime = 0; ///< RPM alarm start time. +static DG_FANS_CAL_RECORD_T fansCalReocrd; ///< Fans calibration record. /// 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 ); @@ -116,7 +120,7 @@ // Initialize the variables fansExecState = FANS_EXEC_STATE_WAIT_FOR_POST_STATE; fansControlCounter = 0; - fansPublishCounter = 0; + fansPublishCounter = DATA_PUBLISH_COUNTER_START_COUNT; isPOSTComplete = FALSE; hasAlarmBeenRaised = FALSE; rpmAlarmStartTime = 0; @@ -147,20 +151,28 @@ * @brief * The execFansSelfTest function executes the fans self test. * @details Inputs: none - * @details Outputs: isPOSTComplete + * @details Outputs: isPOSTComplete, fansCalReocrd * @return Status of self test *************************************************************************/ SELF_TEST_STATUS_T execFansSelfTest( void ) { - SELF_TEST_STATUS_T status = SELF_TEST_STATUS_IN_PROGRESS; + SELF_TEST_STATUS_T result = SELF_TEST_STATUS_IN_PROGRESS; - // TODO implement the calibration processing function. - // It returns a pass for now - + BOOL calStatus = getNVRecord2Driver( GET_CAL_FANS_RECORD, (U08*)&fansCalReocrd, sizeof( DG_FANS_CAL_RECORD_T ), + NUM_OF_CAL_DATA_FANS, ALARM_ID_NO_ALARM ); + // Signal POST is completed isPOSTComplete = TRUE; - status = SELF_TEST_STATUS_PASSED; - return status; + if ( TRUE == calStatus ) + { + result = SELF_TEST_STATUS_PASSED; + } + else + { + result = SELF_TEST_STATUS_FAILED; + } + + return result; } /*********************************************************************//** @@ -467,7 +479,7 @@ for ( fan = FAN_INLET_1; fan < NUM_OF_FANS_NAMES; fan++ ) { rpm = getMeasuredFanRPM( fan ); - isFanRPMOutOfRange |= ( ( rpm < fansMinAllowedRPM ) || ( rpm > fansMaxAllowedRPM ) ? TRUE : FALSE ); + isFanRPMOutOfRange |= ( ( fabs( rpm - fansMinAllowedRPM ) < NEARLY_ZERO ) || ( fabs( rpm - fansMaxAllowedRPM ) > NEARLY_ZERO ) ? TRUE : FALSE ); } // If the fans alarm has been raised already, do not raise again @@ -541,7 +553,7 @@ broadcastData( MSG_ID_DG_FANS_DATA, COMM_BUFFER_OUT_CAN_DG_BROADCAST, (U08*)&fansData, sizeof( FANS_DATA_T ) ); - fansPublishCounter = 0; + fansPublishCounter = DATA_PUBLISH_COUNTER_START_COUNT; } }