Index: firmware/App/Controllers/Fans.c =================================================================== diff -u -rf6016459473bdb85aebe393c07cd580b973d7247 -r0b17c6271cdc3c55697a74ecaadb477d9c8f5687 --- firmware/App/Controllers/Fans.c (.../Fans.c) (revision f6016459473bdb85aebe393c07cd580b973d7247) +++ firmware/App/Controllers/Fans.c (.../Fans.c) (revision 0b17c6271cdc3c55697a74ecaadb477d9c8f5687) @@ -1,11 +1,12 @@ #include "etpwm.h" + #include "Fans.h" -#include "TaskGeneral.h" -#include "Thermistors.h" -#include "SystemCommMessages.h" #include "FPGA.h" #include "PersistentAlarm.h" +#include "SystemCommMessages.h" +#include "TaskGeneral.h" +#include "Thermistors.h" /** * @addtogroup Fans @@ -36,18 +37,18 @@ /// Fans self test states typedef enum fans_Self_Test { - FANS_SELF_TEST_START = 0, ///< Fans self test start state - FANS_SELF_TEST_CHECK_RPM, ///< Fans self test check RPM - FAN_SELF_TEST_COMPLETE, ///< Fans self test complete state - NUM_OF_SELF_TEST_STATES, ///< Number of 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 = 0, ///< Fans exec state start - FANS_EXEC_STATE_RUN, ///< Fans exec state run - 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 @@ -58,17 +59,17 @@ } FAN_STATUS_T; static FAN_STATUS_T fansStatus; ///< Fans status -static SELF_TEST_STATUS_T fansSelfTestReslt = SELF_TEST_STATUS_IN_PROGRESS; ///< Fans self test result -static FANS_SELF_TEST_STATES_T fansSelfTestState = FANS_SELF_TEST_START; ///< Fans self test state -static FANS_EXEC_STATES_T fansExecState = FANS_EXEC_STATE_WAIT_FOR_POST; ///< Fans exec state +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 /// 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 ); +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 toggle2RPMCoefficient = SEC_PER_MIN / ( TOGGLE_PERIOD_RESOLUTION_SECONDS * ROTATIONAL_TO_TOGGLE_PERIOD_CONVERSION ); +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 @@ -98,14 +99,13 @@ void initFans( void ) { // Initialize the variables - fansExecState = FANS_EXEC_STATE_WAIT_FOR_POST; - fansSelfTestReslt = SELF_TEST_STATUS_IN_PROGRESS; - fansSelfTestState = FANS_SELF_TEST_START; - fansExecState = FANS_EXEC_STATE_WAIT_FOR_POST; + 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; - // Initialize a persistent alarm for fans RPM out of range initPersistentAlarm( PERSISTENT_ALARM_FANS_RPM_OUT_RANGE, ALARM_ID_DG_FAN_RPM_OUT_OF_RANGE, TRUE, FANS_MAX_ALLOWED_RPM_OUT_OF_RANGE_COUNT, FANS_MAX_ALLOWED_RPM_OUT_OF_RANGE_COUNT ); @@ -122,26 +122,26 @@ { switch ( fansSelfTestState ) { - case FANS_SELF_TEST_START: + case FANS_SELF_TEST_START_STATE: fansSelfTestState = handleSelfTestStart(); break; - case FANS_SELF_TEST_CHECK_RPM: + case FANS_SELF_TEST_CHECK_RPM_STATE: fansSelfTestState = handleSelfTestCheckRPM(); break; - case FAN_SELF_TEST_COMPLETE: + case FAN_SELF_TEST_COMPLETE_STATE: // Done with POST. Do nothing break; 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; + fansSelfTestState = FAN_SELF_TEST_COMPLETE_STATE; break; } - return fansSelfTestReslt; + return fansSelfTestResult; } /*********************************************************************//** @@ -155,17 +155,17 @@ { switch ( fansExecState ) { - case FANS_EXEC_STATE_WAIT_FOR_POST: + case FANS_EXEC_STATE_WAIT_FOR_POST_STATE: fansExecState = handleExecStateWaitForPOST(); break; - case FANS_EXEC_STATE_RUN: + case FANS_EXEC_STATE_RUN_STATE: fansExecState = handleExecStateRun(); break; default: SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_FAN_INVALID_EXEC_STATE, fansExecState ); - fansExecState = FANS_EXEC_STATE_RUN; + fansExecState = FANS_EXEC_STATE_RUN_STATE; break; } @@ -180,7 +180,7 @@ * @param selected fan to read its RPM * @return RPM of the selected fan *************************************************************************/ -F32 getFanRPM( FANS_NAMES_T fan ) +F32 getMeasuredFanRPM( FAN_NAMES_T fan ) { F32 rpm = 0.0; @@ -207,9 +207,9 @@ *************************************************************************/ static FANS_SELF_TEST_STATES_T handleSelfTestStart( void ) { - FANS_SELF_TEST_STATES_T state = FANS_SELF_TEST_START; + FANS_SELF_TEST_STATES_T state; U32 failureCount = 0; - FANS_NAMES_T fan; + FAN_NAMES_T fan; // Get the raw toggle periods from FPGA and convert them to RPM. They all should be 0 upon staring // the device @@ -229,15 +229,15 @@ // If there was a failure, go to complete if ( failureCount > 0 ) { - fansSelfTestReslt = SELF_TEST_STATUS_FAILED; - state = FAN_SELF_TEST_COMPLETE; + fansSelfTestResult = SELF_TEST_STATUS_FAILED; + state = FAN_SELF_TEST_COMPLETE_STATE; } else { // 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 = FANS_SELF_TEST_CHECK_RPM_STATE; } return state; @@ -253,13 +253,16 @@ *************************************************************************/ static FANS_SELF_TEST_STATES_T handleSelfTestCheckRPM( void ) { - FANS_SELF_TEST_STATES_T state = FANS_SELF_TEST_CHECK_RPM; - U32 failureCount = 0; - FANS_NAMES_T fan; + 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 above the specified RPM @@ -268,25 +271,16 @@ 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 ] ); - failureCount++; + + fansSelfTestResult = SELF_TEST_STATUS_FAILED; } } // Turn off the fans, done with self test setInletFansDutyCycle( 0.0 ); setOutletFansDutyCycle( 0.0 ); - // If the failure count is greater than 0, fail POST - if ( failureCount > 0 ) - { - fansSelfTestReslt = SELF_TEST_STATUS_FAILED; - } - else - { - fansSelfTestReslt = SELF_TEST_STATUS_PASSED; - } - - state = FAN_SELF_TEST_COMPLETE; + state = FAN_SELF_TEST_COMPLETE_STATE; } return state; @@ -302,20 +296,20 @@ *************************************************************************/ static FANS_EXEC_STATES_T handleExecStateWaitForPOST( void ) { - FANS_EXEC_STATES_T state = FANS_EXEC_STATE_WAIT_FOR_POST; + 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 ) + if ( fansSelfTestState == FAN_SELF_TEST_COMPLETE_STATE ) { // Start the fans with minimum PWM. The control will decide the next PWM automatically. setInletFansDutyCycle( FANS_MIN_DUTY_CYCLE ); setOutletFansDutyCycle( FANS_MIN_DUTY_CYCLE ); - state = FANS_EXEC_STATE_RUN; + state = FANS_EXEC_STATE_RUN_STATE; } #ifndef _VECTORCAST_ // To skip the wait for POST and start running. // TODO REMOVE - state = FANS_EXEC_STATE_RUN; + state = FANS_EXEC_STATE_RUN_STATE; // TODO REMOVE #endif return state; @@ -331,11 +325,14 @@ *************************************************************************/ static FANS_EXEC_STATES_T handleExecStateRun( void ) { - FANS_EXEC_STATES_T state = FANS_EXEC_STATE_RUN; + 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 ) { + // Monitor is called here to use the counter of the control + monitorFans(); + // Get the maximum temperature among all the thermistors and temperature sensors to run fan from the hottest temperature F32 temperature = getMaximumTemperature(); @@ -344,10 +341,9 @@ //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; + F32 dutyCycle = SLOPE * ( temperature - MIN_ALLOWED_AMBIENT_TEMPERATURE ) + FANS_MIN_DUTY_CYCLE; - // Check whether the duty cycle is not outside of the range - // and cap it if needed + // Check whether the duty cycle is not outside of the range and cap it if needed if ( dutyCycle < FANS_MIN_DUTY_CYCLE ) { dutyCycle = FANS_MIN_DUTY_CYCLE; @@ -382,13 +378,6 @@ setInletFansDutyCycle( fansStatus.targetDutyCycle ); setOutletFansDutyCycle( fansStatus.targetDutyCycle ); - // Convert and monitor functions are called here to convert and monitor - // the data at the control interval. Otherwise, they should have been called - // in the exec function, but the plan was to use the control interval - // Convert all the latest ADCs to RPM. - convertTogglePeriod2RPM(); - monitorFans(); - // Reset the counter fansControlCounter = 0; } @@ -463,7 +452,7 @@ ************************************************************************/ static void convertTogglePeriod2RPM( void ) { - FANS_NAMES_T fan; + FAN_NAMES_T fan; U32 togglePeriods[ NUM_OF_FANS_NAMES ]; togglePeriods[ FAN_INLET_1 ] = getFPGAInletFan1TogglePeriod(); @@ -484,7 +473,7 @@ else { // Convert toggle period to RPM - fansStatus.rpm[ fan ] = toggle2RPMCoefficient / togglePeriods[ fan ]; + fansStatus.rpm[ fan ] = TOGGLE_PERIOD_2_RPM_COEFFICIENT / togglePeriods[ fan ]; } } } @@ -498,12 +487,14 @@ *************************************************************************/ static void monitorFans( void ) { - FANS_NAMES_T fan; + FAN_NAMES_T fan; + convertTogglePeriod2RPM(); + for ( fan = FAN_INLET_1; fan < NUM_OF_FANS_NAMES; fan++ ) { // Call persistent alarm if a fan's RPM is out of range - if ( fansStatus.rpm[ fan ] >= FANS_MAX_ALLOWED_RPM ) + if ( fansStatus.rpm[ fan ] >= FANS_MAX_ALLOWED_RPM || fansStatus.rpm[ fan ] <= NEARLY_ZERO ) { checkPersistentAlarm( PERSISTENT_ALARM_FANS_RPM_OUT_RANGE, TRUE, fansStatus.rpm[ fan ] ); } @@ -543,7 +534,7 @@ { FANS_DATA_T fansData; - fansData.fansTargetPWM = fansStatus.targetDutyCycle * 100; + fansData.fansTargetDutyCycle = fansStatus.targetDutyCycle * FRACTION_TO_PERCENT_FACTOR; fansData.fanInlet1RPM = fansStatus.rpm[ FAN_INLET_1 ]; fansData.fanInlet2RPM = fansStatus.rpm[ FAN_INLET_2 ]; fansData.fanInlet3RPM = fansStatus.rpm[ FAN_INLET_3 ];