Index: firmware/App/Controllers/Fans.c =================================================================== diff -u --- firmware/App/Controllers/Fans.c (revision 0) +++ firmware/App/Controllers/Fans.c (revision 4164cba570c42566aee10d7cce23c3cea0d903ee) @@ -0,0 +1,479 @@ + + +#include "etpwm.h" + +#include "Fans.h" +#include "FPGA.h" +#include "PersistentAlarm.h" +#include "SystemCommMessages.h" +#include "TaskGeneral.h" +#include "Temperatures.h" + +/** + * @addtogroup Fans + * @{ + */ + +// ********** 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 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. + +/// 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_STATES_T; + +/// Fans status struct +typedef struct +{ + 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. + +/// 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 FANS_EXEC_STATES_T handleExecStateWaitForPOST( void ); +static FANS_EXEC_STATES_T handleExecStateRun( void ); + +static void setInletFansDutyCycle( F32 pwm ); +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: none + * @details Outputs: fansExecState, fansMonitorCounter, fansControlCounter, + * fansPublishCounter, isPOSTComplete + * @return none + *************************************************************************/ +void initFans( void ) +{ + // Initialize the variables + 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_HD_FAN_RPM_OUT_OF_RANGE, FANS_MAX_ALLOWED_RPM_OUT_OF_RANGE_INTERVAL, FANS_MAX_ALLOWED_RPM_OUT_OF_RANGE_INTERVAL ); +} + +/*********************************************************************//** + * @brief + * The execFansSelfTest function executes the fans self test. + * @details Inputs: none + * @details Outputs: isPOSTComplete + * @return Status of self test + *************************************************************************/ +SELF_TEST_STATUS_T execFansSelfTest( void ) +{ + SELF_TEST_STATUS_T status = SELF_TEST_STATUS_IN_PROGRESS; + + // TODO implement the calibration processing function. + // It returns a pass for now + + isPOSTComplete = TRUE; + status = SELF_TEST_STATUS_PASSED; + + return status; +} + +/*********************************************************************//** + * @brief + * The execFans function executes the execFans exec states. + * @details Inputs: fansExecState + * @details Outputs: fansExecState + * @return none + *************************************************************************/ +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: + fansExecState = handleExecStateWaitForPOST(); + break; + + case FANS_EXEC_STATE_RUN_STATE: + fansExecState = handleExecStateRun(); + break; + + default: + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_HD_FANS_INVALID_STATE, fansExecState ); + fansExecState = FANS_EXEC_STATE_RUN_STATE; + break; + } + + publishFansData(); +} + +/*********************************************************************//** + * @brief + * The getFanRPM function returns the RPM a the selected fan. + * @details Inputs: fansStatus + * @details Outputs: none + * @param selected fan to read its RPM + * @return RPM of the selected fan + *************************************************************************/ +F32 getMeasuredFanRPM( FAN_NAMES_T fan ) +{ + F32 rpm = 0.0; + + // Check if the called fan is in range + if ( fan < NUM_OF_FANS_NAMES ) + { + rpm = fansStatus.rpm[ fan ]; + } + else + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_HD_INVALID_FAN_SELECTED, fan ); + } + + return rpm; +} + +/*********************************************************************//** + * @brief + * The handleFansExecStateStart function handles the start state of the + * fans exec state machine. + * @details Inputs: none + * @details Outputs: none + * @return the next state of the exec state machine + *************************************************************************/ +static FANS_EXEC_STATES_T handleExecStateWaitForPOST( void ) +{ + FANS_EXEC_STATES_T state = FANS_EXEC_STATE_WAIT_FOR_POST_STATE; + + // Wait for the self test to finish before starting the fans + if ( TRUE == isPOSTComplete ) + { + // Start the fans with minimum PWM. The control will decide the next PWM automatically. + setInletFansDutyCycle( FANS_MIN_DUTY_CYCLE ); + 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; + // TODO REMOVE +#endif + return state; +} + +/*********************************************************************//** + * @brief + * The handleFansExecStateRun function handles the run state of the + * fans exec state machine. + * @details Inputs: fansStatus, fansControlCounter + * @details Outputs: fansStatus, fansControlCounter + * @return the next state of the exec state machine + *************************************************************************/ +static FANS_EXEC_STATES_T handleExecStateRun( void ) +{ + 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 ) + { + // Get the maximum temperature among all the thermistors and temperature sensors to run fan from the hottest temperature + F32 temperature = getMaximumTemperature(); + + // Solve the linear equation to calculate the duty cycle from temperature + 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 + if ( dutyCycle < FANS_MIN_DUTY_CYCLE ) + { + dutyCycle = FANS_MIN_DUTY_CYCLE; + } + if ( dutyCycle > FANS_MAX_DUTY_CYCLE ) + { + dutyCycle = FANS_MAX_DUTY_CYCLE; + } + + // If the fans calculated duty cycle is greater than the previous calculated duty cycle, we are ramping up + // otherwise, we are ramping down + if ( dutyCycle >= fansStatus.targetDutyCycle ) + { + // If the delta duty cycle from the previous duty cycle is greater than the max allowed ramp up duty cycle, + // otherwise, only add the delta duty cycle + if ( ( dutyCycle - fansStatus.targetDutyCycle ) >= FANS_MAX_ALLOWED_RAMP_UP_DELTA_DUTY_CYCLE ) + { + fansStatus.targetDutyCycle += FANS_MAX_ALLOWED_RAMP_UP_DELTA_DUTY_CYCLE; + } + else + { + fansStatus.targetDutyCycle = dutyCycle; + } + } + else + { + // If the delta duty cycle from the previous duty cycle is greater than the max allowed ramp down duty cycle, + // otherwise, only add the delta duty cycle + if ( ( fansStatus.targetDutyCycle - dutyCycle ) >= FANS_MAX_ALLOWED_RAMP_DOWN_DELTA_DUTY_CYCLE ) + { + // If we are ramping down, set the target duty cycle to max allowed ramp down duty cycle + fansStatus.targetDutyCycle -= FANS_MAX_ALLOWED_RAMP_DOWN_DELTA_DUTY_CYCLE; + } + else + { + fansStatus.targetDutyCycle = dutyCycle; + } + } + + // Set the PWM to inlet and outlet fans + setInletFansDutyCycle( fansStatus.targetDutyCycle ); + + // Reset the counter + fansControlCounter = 0; + } + + return state; +} + +/*********************************************************************//** + * @brief + * The setInletFansPWM function sets the inlet fans PWM. + * @details Inputs: none + * @details Outputs: none + * @param PWM that will be set + * @return none + *************************************************************************/ +static void setInletFansDutyCycle( F32 pwm ) +{ + etpwmSetCmpA( etpwmREG7, (U32)( (S32)( ( pwm * (F32)(etpwmREG6->TBPRD) ) + FLOAT_TO_INT_ROUNDUP_OFFSET ) ) ); +} + +/*********************************************************************//** + * @brief + * The getMaximumTemperature function gets the maximum temperature on the boards. + * @details Inputs: none + * @details Outputs: none + * @return maximum temperature of the thermistors and temperature sensors + ************************************************************************/ +static F32 getMaximumTemperature( void ) +{ + F32 temperature = 0.0; + F32 maxTemperature = 0.0; + + // NOTE: a for loop was not used because the venous pressure sensor's temperature + // is not used as one of temperature values to decide the hottest temperature + temperature = getTemperatureValue( THERMISTOR_ONBOARD_NTC ); + maxTemperature = ( temperature > maxTemperature ? temperature : maxTemperature ); + + temperature = getTemperatureValue( THERMISTOR_POWER_SUPPLY_1 ); + maxTemperature = ( temperature > maxTemperature ? temperature : maxTemperature ); + + temperature = getTemperatureValue( TEMPSENSOR_FPGA_BOARD_SENSOR ); + maxTemperature = ( temperature > maxTemperature ? temperature : maxTemperature ); + + temperature = getTemperatureValue( TEMPSENSOR_PBA_ADC_SENSOR ); + 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: fansStatus, toggle2RPMCoefficient + * @details Outputs: fansStatus + * @return none + ************************************************************************/ +static void convertTogglePeriod2RPM( void ) +{ + FAN_NAMES_T fan; + U32 togglePeriods[ NUM_OF_FANS_NAMES ]; + + togglePeriods[ FAN_INLET_1 ] = getFPGAInletFan1TogglePeriod(); + + for ( fan = FAN_INLET_1; fan < NUM_OF_FANS_NAMES; fan++ ) + { + // If the pulse is close to 0 or 0, FPGA will report 0xFFFF + // Otherwise, convert the pulse to RPM + if ( FANS_ZERO_RPM_TOGGLE_PERIOD_VALUE == togglePeriods[ fan ] ) + { + fansStatus.rpm[ fan ] = 0; + } + else + { + // Convert toggle period to RPM + fansStatus.rpm[ fan ] = TOGGLE_PERIOD_2_RPM_COEFFICIENT / togglePeriods[ fan ]; + } + } +} + +/*********************************************************************//** + * @brief + * The monitorFans function monitors the fans for RPM. + * @details Inputs: fansStatus + * @details Outputs: none + * @return none + *************************************************************************/ +static void monitorFans( void ) +{ + FAN_NAMES_T fan; + + 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 fanRpmOutOfRange = ( fansStatus.rpm[ fan ] < fansMinAllowedRPM ) || ( fansStatus.rpm[ fan ] > fansMaxAllowedRPM ); + isPersistentAlarmTriggered( ALARM_ID_DG_FAN_RPM_OUT_OF_RANGE, fanRpmOutOfRange ); + } + + fansMonitorCounter = 0; + } +} + +/*********************************************************************//** + * @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 + * @details Outputs: dataPublishCounter + * @return none + *************************************************************************/ +static void publishFansData( void ) +{ + if ( ++fansPublishCounter > getPublishFansDataInterval() ) + { + FANS_DATA_T fansData; + + fansData.fansTargetDutyCycle = fansStatus.targetDutyCycle * FRACTION_TO_PERCENT_FACTOR; + fansData.fanInlet1RPM = fansStatus.rpm[ FAN_INLET_1 ]; + + broadcastFansData( &fansData ); + + fansPublishCounter = 0; + } +} + + +/************************************************************************* +* TEST SUPPORT FUNCTIONS +*************************************************************************/ + + +/*********************************************************************//** + * @brief + * The testSetFanPublishIntervalOverride function overrides the fans data + * publish interval. + * @details Inputs: fansPublishInterval + * @details Outputs: fansPublishInterval + * @param value : override fans data publish interval with (in ms) + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testSetFanPublishIntervalOverride( U32 value ) +{ + BOOL result = FALSE; + + if ( TRUE == isTestingActivated() ) + { + U32 intvl = value / TASK_GENERAL_INTERVAL; + + result = TRUE; + fansPublishInterval.ovData = intvl; + fansPublishInterval.override = OVERRIDE_KEY; + } + + return result; +} + +/*********************************************************************//** + * @brief + * The testResetFanPublishIntervalOverride function resets the override + * of the fans data publish interval. + * @details Inputs: fansPublishInterval + * @details Outputs: fansPublishInterval + * @return TRUE if override reset successful, FALSE if not + ************************************************************************/ +BOOL testResetFanPublishIntervalOverride( void ) +{ + BOOL result = FALSE; + + if ( TRUE == isTestingActivated() ) + { + result = TRUE; + fansPublishInterval.override = OVERRIDE_RESET; + fansPublishInterval.ovData = fansPublishInterval.ovInitData; + } + + return result; +} + +/**@}*/ + Index: firmware/App/Controllers/Fans.h =================================================================== diff -u --- firmware/App/Controllers/Fans.h (revision 0) +++ firmware/App/Controllers/Fans.h (revision 4164cba570c42566aee10d7cce23c3cea0d903ee) @@ -0,0 +1,43 @@ + +#ifndef APP_CONTROLLERS_FANS_H_ +#define APP_CONTROLLERS_FANS_H_ + +#include "HDCommon.h" + +/** + * @defgroup Fans Fans + * @brief Fans monitor/controller module. Controls and monitors the DG fans. + * + * @addtogroup Fans + * @{ + */ + +/// Fans names +typedef enum DG_fans +{ + FAN_INLET_1 = 0, ///< Fan inlet 1 + NUM_OF_FANS_NAMES ///< Number of fans names +} FAN_NAMES_T; + +/// Fans data publish +typedef struct +{ + F32 fansTargetDutyCycle; ///< Fans target duty cycle + F32 fanInlet1RPM; ///< Fan inlet 1 RPM +} FANS_DATA_T; + +void initFans( void ); + +SELF_TEST_STATUS_T execFansSelfTest( void ); + +void execFans( void ); + +F32 getMeasuredFanRPM( FAN_NAMES_T fan ); + +BOOL testSetFanPublishIntervalOverride( U32 value ); +BOOL testResetFanPublishIntervalOverride( void ); + +/**@}*/ + + +#endif Index: firmware/App/Controllers/Temperatures.c =================================================================== diff -u -rbef8f02d9c868976c1e9d4f30432a3288db52324 -r4164cba570c42566aee10d7cce23c3cea0d903ee --- firmware/App/Controllers/Temperatures.c (.../Temperatures.c) (revision bef8f02d9c868976c1e9d4f30432a3288db52324) +++ firmware/App/Controllers/Temperatures.c (.../Temperatures.c) (revision 4164cba570c42566aee10d7cce23c3cea0d903ee) @@ -16,58 +16,61 @@ // ********** private definitions ********** -#define TEMPERATURES_DATA_PUBLISH_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Temperatures publish data time interval. -#define TEMPERATURES_ADC_READ_INTERVAL ( MS_PER_SECOND / ( 2 * TASK_GENERAL_INTERVAL ) ) ///< Temperatures ADC read time interval. -#define ADC_FPGA_READ_DELAY_COUNT 1.0 ///< FGPA read delay upon startup. -#define TWELVE_BIT_RESOLUTION 4096U ///< 12 bit resolution conversion. -#define THERMISTOR_REFERENCE_VOLTAGE 3.0 ///< Thermistors source voltage. -#define THERMISTOR_REFERENCE_RESISTOR_AT_25 10000.0 ///< Thermistors reference resistor in ohms. -#define THERMISTOR_REFERENCE_TEMPERATURE 298.0 ///< Thermistors reference temperature in kelvin. -#define ONBOARD_THERMISTOR_BETA_VALUE 3380.0 ///< Onboard thermistor beta value. -#define POWER_SUPPLY_THERMISTOR_BETA_VALUE 3345.0 ///< Power supply beta value. -#define CELSIUS_TO_KELVIN_CONVERSION 273.15 ///< Celsius to Kelvin temperature conversion. -#define MIN_ALLOWED_TEMPERATURE 0.0 ///< Thermistors/sensors minimum allowed temperature reading. -#define MAX_ALLOWED_TEMPERATURE 120.0 ///< Thermistors/sensors maximum allowed temperature reading. -#define MAX_ALLOWED_TEMP_OUT_OF_RANGE_PERIOD ( 5 * MS_PER_SECOND ) ///< Thermistors/sensors maximum allowed temperature out of range period. +#define TEMPERATURES_DATA_PUBLISH_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Temperatures publish data time interval. +#define TEMPERATURES_ADC_READ_INTERVAL ( MS_PER_SECOND / ( 2 * TASK_GENERAL_INTERVAL ) ) ///< Temperatures ADC read time interval. +#define ADC_FPGA_READ_DELAY_COUNT 1.0 ///< FGPA read delay upon startup. +#define TWELVE_BIT_RESOLUTION 4096U ///< 12 bit resolution conversion. +#define THERMISTOR_REFERENCE_VOLTAGE 3.0 ///< Thermistors source voltage. +#define THERMISTOR_REFERENCE_RESISTOR_AT_25 10000.0 ///< Thermistors reference resistor in ohms. +#define THERMISTOR_REFERENCE_TEMPERATURE 298.0 ///< Thermistors reference temperature in kelvin. +#define THERMISTOR_BETA_VALUE 3380.0 ///< Thermistor beta value. +#define CELSIUS_TO_KELVIN_CONVERSION 273.15 ///< Celsius to Kelvin temperature conversion. +#define ADC_BOARD_TEMP_SENSOR_CONVERSION_CONST_1 272.5 ///< ADC board temperature sensor conversion constant 1. +#define ADC_BOARD_TEMP_SENSOR_CONVERSION_CONST_2 0x800000 ///< ADC board temperature sensor conversion constant 2. +#define MIN_ALLOWED_TEMPERATURE 0.0 ///< Thermistors/sensors minimum allowed temperature reading. +#define MAX_ALLOWED_TEMPERATURE 120.0 ///< Thermistors/sensors maximum allowed temperature reading. +#define MAX_ALLOWED_TEMP_OUT_OF_RANGE_PERIOD ( 5 * MS_PER_SECOND ) ///< Thermistors/sensors maximum allowed temperature out of range period. /// Temperatures exec states typedef enum thermistors_Exec_States { - TEMPERATURES_EXEC_STATE_START_STATE = 0, ///< Temperatures exec state start state. - TEMPERATURES_EXEC_STATE_GET_ADC_VALUES_STATE, ///< Temperatures exec state get ADC values state. - NUM_OF_TEMPERATURES_EXEC_STATES, ///< Number of temperatures exec state. + TEMPERATURES_EXEC_STATE_START_STATE = 0, ///< Temperatures exec state start state. + TEMPERATURES_EXEC_STATE_GET_ADC_VALUES_STATE, ///< Temperatures exec state get ADC values state. + NUM_OF_TEMPERATURES_EXEC_STATES, ///< Number of temperatures exec state. } TEMPERATURES_EXEC_STATES_T; /// Temperatures structure typedef struct { - U32 rawADCRead; ///< Temperatures raw ADC read. - OVERRIDE_F32_T temperatureValue; ///< Temperatures value. + U32 rawADCRead; ///< Temperatures raw ADC read. + OVERRIDE_F32_T temperatureValue; ///< Temperatures value. } TEMPERATURE_SENSORS_T; // ********** private data ********** static TEMPERATURES_EXEC_STATES_T temperaturesExecState; ///< Temperatures exec state. static TEMPERATURE_SENSORS_T temperaturesStatus[ NUM_OF_TEMPERATURES ]; ///< Temperature sensors status. static OVERRIDE_U32_T temperaturesPublishInterval = { TEMPERATURES_DATA_PUBLISH_INTERVAL, - TEMPERATURES_DATA_PUBLISH_INTERVAL, 0, 0 }; ///< Temperatures publish time interval override. + TEMPERATURES_DATA_PUBLISH_INTERVAL, 0, 0 }; ///< Temperatures publish time interval override. static U32 dataPublishCounter; ///< Temperatures data publish timer counter. static U32 adcReadCounter; ///< Temperatures ADC read counter. -static const F32 THERMISTOR_VOLTAGE_CONV_COEFF = THERMISTOR_REFERENCE_VOLTAGE / - (F32)TWELVE_BIT_RESOLUTION; ///< On board thermistor ADC to voltage conversion coefficient. -static const F32 ON_BOARD_THERMISTOR_REF_TEMP_INV = 1 / THERMISTOR_REFERENCE_TEMPERATURE; ///< On board thermistor reference inverse. +static const F32 THERMISTOR_VOLTAGE_CONV_COEFF = THERMISTOR_REFERENCE_VOLTAGE / + (F32)TWELVE_BIT_RESOLUTION; ///< On board thermistor ADC to voltage conversion coefficient. +static const F32 ON_BOARD_THERMISTOR_REF_TEMP_INV = 1.0 / THERMISTOR_REFERENCE_TEMPERATURE; ///< On board thermistor reference inverse. +static const F32 FGPA_BOARD_TEMP_CONVERSION_COEFF = 1.0 / 13584.0; ///< FPGA board temperature conversion coefficient. +static const F32 VENOUS_PRESS_SENSOR_TEMP_CONVERSION_COEFF = 200.0 / 2047.0; ///< Venous pressure sensor temperature conversion coefficient. +static const F32 VENOUS_PRESS_SENSOR_TEMP_CONVERSION_CONSTANT = 50.0; ///< Venous pressure sensor temperature conversion constant. +static const F32 ADC_BOARD_TEMP_SENSOR_CONVERSION_COEFF = 1.0 / 13584.0; ///< ADC board temperatures sensor conversion coefficient. -static const F32 CONVERSION_COEFF = 1.0 / 13584.0; ///< Conversion coefficient for FPGA board temperature. - // ********** private function prototypes ********** static TEMPERATURES_EXEC_STATES_T handleExecStart( void ); static TEMPERATURES_EXEC_STATES_T handleExecGetADCValues( void ); static void monitorTemperatures( void ); static void convertADC2Temperature( void ); -static F32 calculateOnBoardThemristorTemperature( S32 adcValue ); +static F32 calculateThemristorTemperature( S32 adcValue ); static void publishTemperaturesData( void ); static U32 getPublishTemperaturesDataInterval( void ); @@ -108,7 +111,6 @@ // TODO implement the calibration processing function. // It returns a pass for now - status = SELF_TEST_STATUS_PASSED; return status; @@ -220,6 +222,7 @@ temperaturesStatus[ TEMPSENSOR_FPGA_BOARD_SENSOR ].rawADCRead = getFPGABoardTemperature(); temperaturesStatus[ TEMPSENSOR_PBA_ADC_SENSOR ].rawADCRead = getFPGAPBAADCTemperature(); + // Convert the ADC values to temperature convertADC2Temperature(); // Monitor the values for a gross range check @@ -246,14 +249,14 @@ static void monitorTemperatures( void ) { TEMPERATURES_T sensor; - F32 temperature; + F32 temperature = 0.0; - for ( sensor = THERMISTOR_ONBOARD_NTC; sensor < NUM_OF_THERMISTORS; sensor++ ) + for ( sensor = THERMISTOR_ONBOARD_NTC; sensor < NUM_OF_TEMPERATURES; sensor++ ) { - temperature = getThermistorTemperatureValue( thermistor ); + temperature = getTemperatureValue( sensor ); BOOL isTempOutOfRange = ( temperature > MAX_ALLOWED_TEMPERATURE ) || ( temperature < MIN_ALLOWED_TEMPERATURE ); - checkPersistentAlarm( ALARM_ID_HD_TEMPERATURES_OUT_OF_RANGE, isTempOutOfRange, temperature, MAX_ALLOWED_TEMPERATURE ); + isPersistentAlarmTriggered( ALARM_ID_HD_TEMPERATURES_OUT_OF_RANGE, isTempOutOfRange ); } } @@ -274,26 +277,30 @@ // Loop through the list and update the temperatures values for ( sensor = THERMISTOR_ONBOARD_NTC; sensor < NUM_OF_TEMPERATURES; sensor++ ) { - rawADC = (S32)temperaturesStatus[ sensor ].rawADCRead; + rawADC = (S32)( temperaturesStatus[ sensor ].rawADCRead & MASK_OFF_U32_MSB ); switch ( sensor ) { case THERMISTOR_ONBOARD_NTC: - temperature = calculateOnBoardThemristorTemperature( rawADC ); - break; - case THERMISTOR_POWER_SUPPLY_1: - // TODO figure out the temperature conversion + temperature = calculateThemristorTemperature( rawADC ); break; case TEMPSENSOR_FPGA_BOARD_SENSOR: // Temperature(C) = ((ADC x 503.975) / 4096) - 273.15 // The value of 503.975/4096 has been calculated and stored in the conversion coefficient variable of the structure - temperature = ( rawADC * CONVERSION_COEFF ) - CELSIUS_TO_KELVIN_CONVERSION; + temperature = ( rawADC * FGPA_BOARD_TEMP_CONVERSION_COEFF ) - CELSIUS_TO_KELVIN_CONVERSION; break; + case TEMPSENSOR_VENOUS_PRESSURE_SENSOR: + // Temperature (C) = ((ADC / 2047) * 200) - 50 + temperature = ( rawADC * VENOUS_PRESS_SENSOR_TEMP_CONVERSION_COEFF ) - VENOUS_PRESS_SENSOR_TEMP_CONVERSION_CONSTANT; + break; + case TEMPSENSOR_PBA_ADC_SENSOR: - // TODO figure out the temperature conversion + // Temperature (C) = ((ADC - 0x800000) / 13584) - 272.5 + temperature = ( ( rawADC - ADC_BOARD_TEMP_SENSOR_CONVERSION_CONST_2 ) * ADC_BOARD_TEMP_SENSOR_CONVERSION_COEFF ) - + ADC_BOARD_TEMP_SENSOR_CONVERSION_CONST_1; break; default: @@ -314,16 +321,15 @@ * of the onboard thermistor into temperature in C. Below are the calculation * steps: * voltage = ADC x 3 / 2^12 - * voltage = 3 x 10 / ( 10 + R(T) ) + * voltage = 3 x 10000 / ( 10000 + R(T) ) * R(T) = 10000 x e^(beta x (1/T - 1/298)) * Solve for T which is temperature in Kelvin - * @details Inputs: onBoardThermistorVoltageConvCoeff, - * onBoardThermistorBetaValueInv + * @details Inputs: none * @details Outputs: none - * @param ADC value to be converted into temperature in C + * @param adcValue which is the ADC value to be converted into temperature in C * @return calculated temperature in C *************************************************************************/ -static F32 calculateOnBoardThemristorTemperature( S32 adcValue ) +static F32 calculateThemristorTemperature( S32 adcValue ) { // Voltage = ADC x 3 / 2^12 for 12 bits resolution and a 3V ADC // The value of 3 / 2^12 has been calculated in a const to prevent the division again @@ -334,8 +340,8 @@ ( THERMISTOR_REFERENCE_RESISTOR_AT_25 * thermistorVoltage ) ) / thermistorVoltage; // 1/T = Ln(thermistorResistor/10000)/3380 + 1/298 - F32 invTemperature = ( logf( thermistorResistor / THERMISTOR_REFERENCE_RESISTOR_AT_25 ) / ONBOARD_THERMISTOR_BETA_VALUE ) + - ON_BOARD_THERMISTOR_REF_TEMP_INV; + F32 invTemperature = ( logf( thermistorResistor / THERMISTOR_REFERENCE_RESISTOR_AT_25 ) / THERMISTOR_BETA_VALUE ) + + ON_BOARD_THERMISTOR_REF_TEMP_INV; // Inverse the value to get the temperature in Kelvin and then convert it to Celsius F32 temperature = ( 1 / invTemperature ) - CELSIUS_TO_KELVIN_CONVERSION; @@ -345,6 +351,26 @@ /*********************************************************************//** * @brief + * The getPublishTemperaturesDataInterval function gets the temperatures + * data publish interval. + * @details Inputs: temperaturesPublishInterval + * @details Outputs: none + * @return data publish time interval in counts + *************************************************************************/ +static U32 getPublishTemperaturesDataInterval( void ) +{ + U32 result = temperaturesPublishInterval.data; + + if ( OVERRIDE_KEY == temperaturesPublishInterval.override ) + { + result = temperaturesPublishInterval.ovData; + } + + return result; +} + +/*********************************************************************//** + * @brief * The publishTemperaturesData function publishes the temperatures sensors * data at the specified time interval. * @details Inputs: dataPublishCounter @@ -353,7 +379,131 @@ *************************************************************************/ static void publishTemperaturesData( void ) { + if ( ++dataPublishCounter > getPublishTemperaturesDataInterval() ) + { + TEMPERATURES_DATA_T sensorsData; + // Get all the sensors/thermistors temperature values for publication + sensorsData.onboardThermistor = getTemperatureValue( THERMISTOR_ONBOARD_NTC ); + sensorsData.powerSupply1Thermistor = getTemperatureValue( THERMISTOR_POWER_SUPPLY_1 ); + sensorsData.venousPressSensorTemp = getTemperatureValue( TEMPSENSOR_VENOUS_PRESSURE_SENSOR ); + sensorsData.fpgaBoardTempSensor = getTemperatureValue( TEMPSENSOR_FPGA_BOARD_SENSOR ); + sensorsData.pbaADCTempSensor = getTemperatureValue( TEMPSENSOR_PBA_ADC_SENSOR ); + + // Broadcast the temperatures data + broadcastTemperaturesData( &sensorsData ); + + // Reset the counter + dataPublishCounter = 0; + } } +/************************************************************************* +* TEST SUPPORT FUNCTIONS +*************************************************************************/ + + +/*********************************************************************//** + * @brief + * The testSetMeasuredTemperatureOverride function overrides the value of + * a temperature sensor/thermistor. + * @details Inputs: none + * @details Outputs: temperaturesStatus + * @param sensorID the sensor its value is overridden + * @param temperature value to override + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testSetMeasuredTemperatureOverride( U32 sensorID, F32 temperature ) +{ + BOOL result = FALSE; + + if ( ( sensorID < NUM_OF_TEMPERATURES ) && ( TRUE == isTestingActivated() ) ) + { + // There is a temperature range that the thermistors can be set to, otherwise, the driver + // will throw an alarm. Also, the fans driver depends on these values to continuously control the fans + if ( ( temperature >= MIN_ALLOWED_TEMPERATURE ) && ( temperature < MAX_ALLOWED_TEMPERATURE ) ) + { + result = TRUE; + temperaturesStatus[ sensorID ].temperatureValue.ovData = temperature; + temperaturesStatus[ sensorID ].temperatureValue.override = OVERRIDE_KEY; + } + } + + return result; +} + +/*********************************************************************//** + * @brief + * The testResetMeasuredTemperatureOverride function resets the override + * value of a temperature sensors/thermistor. + * @details Inputs: none + * @details Outputs: temperaturesStatus + * @param sensorID which its value is reset + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testResetMeasuredTemperatureOverride( U32 sensorID ) +{ + BOOL result = FALSE; + + if ( TRUE == isTestingActivated() ) + { + if ( sensorID < NUM_OF_TEMPERATURES ) + { + result = TRUE; + temperaturesStatus[ sensorID ].temperatureValue.override = OVERRIDE_RESET; + temperaturesStatus[ sensorID ].temperatureValue.ovData = temperaturesStatus[ sensorID ].temperatureValue.ovInitData; + } + } + + return result; +} + +/*********************************************************************//** + * @brief + * The testSetTemperturesPublishIntervalOverride function overrides the + * temperatures data publish interval. + * @details Inputs: none + * @details Outputs: temperaturesPublishInterval + * @param value which is override value for the temperatures data publish + * interval + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testSetTemperaturesPublishIntervalOverride( U32 value ) +{ + BOOL result = FALSE; + + if ( TRUE == isTestingActivated() ) + { + U32 intvl = value / TASK_GENERAL_INTERVAL; + + result = TRUE; + temperaturesPublishInterval.ovData = intvl; + temperaturesPublishInterval.override = OVERRIDE_KEY; + } + + return result; +} + +/*********************************************************************//** + * @brief + * The testResetTemperaturesPublishIntervalOverride function resets the override + * of the temperatures publish interval. + * @details Inputs: none + * @details Outputs: temperaturesPublishInterval + * @return TRUE if override reset successful, FALSE if not + *************************************************************************/ +BOOL testResetTemperaturesPublishIntervalOverride( void ) +{ + BOOL result = FALSE; + + if ( TRUE == isTestingActivated() ) + { + result = TRUE; + temperaturesPublishInterval.override = OVERRIDE_RESET; + temperaturesPublishInterval.ovData = temperaturesPublishInterval.ovInitData; + } + + return result; +} + /**@}*/ Index: firmware/App/Controllers/Temperatures.h =================================================================== diff -u -r0c3533ac1aa509678a73a8177d648080fa567203 -r4164cba570c42566aee10d7cce23c3cea0d903ee --- firmware/App/Controllers/Temperatures.h (.../Temperatures.h) (revision 0c3533ac1aa509678a73a8177d648080fa567203) +++ firmware/App/Controllers/Temperatures.h (.../Temperatures.h) (revision 4164cba570c42566aee10d7cce23c3cea0d903ee) @@ -7,9 +7,9 @@ /** * @defgroup Temperatures Temperatures * @brief Thermistors driver module. Reads and processes the thermistors. - * Onboard thermistor manufacturer: Murata Manufacturing, PN: NCP14XH103J03RC - * Power supply thermistors manufacturer: Murata Manufacturing, PN: NCP18XH103F03RB or - * Epcos Manufacturing, PN: B57330V2103F260 + * Onboard thermistor manufacturer: Murata Manufacturing, PN: NCP14XH103J03RC + * Power supply thermistors manufacturer: Murata Manufacturing, PN: NCP18XH103F03RB or + * Epcos Manufacturing, PN: B57330V2103F260 * * @addtogroup Temperatures * @{ @@ -23,6 +23,7 @@ THERMISTOR_ONBOARD_NTC = 0, ///< Onboard thermistor THERMISTOR_POWER_SUPPLY_1, ///< HD power supply 1 thermistor TEMPSENSOR_FPGA_BOARD_SENSOR, ///< FPGA board temperature sensor + TEMPSENSOR_VENOUS_PRESSURE_SENSOR, ///< Venous pressure sensor temperature TEMPSENSOR_PBA_ADC_SENSOR, ///< PBA ADC temperature sensor NUM_OF_TEMPERATURES, ///< Number of temperatures } TEMPERATURES_T; @@ -33,6 +34,7 @@ F32 onboardThermistor; ///< Onboard thermistor data F32 powerSupply1Thermistor; ///< Power supply 1 thermistor F32 fpgaBoardTempSensor; ///< FPGA board temperature sensor + F32 venousPressSensorTemp; ///< Venous pressure sensor temperature F32 pbaADCTempSensor; ///< PBA ADC temperature sensor } TEMPERATURES_DATA_T; @@ -49,7 +51,7 @@ BOOL testSetMeasuredTemperatureOverride( U32 sensorID, F32 temperature ); BOOL testResetMeasuredTemperatureOverride( U32 sensorID ); -BOOL testSetTemperturesPublishIntervalOverride( U32 value ); +BOOL testSetTemperaturesPublishIntervalOverride( U32 value ); BOOL testResetTemperaturesPublishIntervalOverride( void ); /**@}*/ Index: firmware/App/Services/AlarmMgmtSWFaults.h =================================================================== diff -u -rbef8f02d9c868976c1e9d4f30432a3288db52324 -r4164cba570c42566aee10d7cce23c3cea0d903ee --- firmware/App/Services/AlarmMgmtSWFaults.h (.../AlarmMgmtSWFaults.h) (revision bef8f02d9c868976c1e9d4f30432a3288db52324) +++ firmware/App/Services/AlarmMgmtSWFaults.h (.../AlarmMgmtSWFaults.h) (revision 4164cba570c42566aee10d7cce23c3cea0d903ee) @@ -157,6 +157,8 @@ SW_FAULT_ID_HD_INVALID_BUBBLE_ID, SW_FAULT_ID_HD_TEMPERATURES_INALID_EXEC_STATE, SW_FAULT_ID_HD_INVALID_TEMPERATURE_SENSOR_SELECTED, + SW_FAULT_ID_HD_FANS_INVALID_STATE, + SW_FAULT_ID_HD_INVALID_FAN_SELECTED, // 130 NUM_OF_SW_FAULT_IDS } SW_FAULT_ID_T; Index: firmware/App/Services/FPGA.c =================================================================== diff -u -r3f26385e0e67b8596b06c26533353c759f3ee996 -r4164cba570c42566aee10d7cce23c3cea0d903ee --- firmware/App/Services/FPGA.c (.../FPGA.c) (revision 3f26385e0e67b8596b06c26533353c759f3ee996) +++ firmware/App/Services/FPGA.c (.../FPGA.c) (revision 4164cba570c42566aee10d7cce23c3cea0d903ee) @@ -2316,6 +2316,18 @@ return fpgaSensorReadings.adc1Channel1; } +/*********************************************************************//** + * @brief + * The getFPGAInletFan1TogglePeriod function reads the inlet fan 1 pulse time. + * @details Inputs: none + * @details Outputs: fpgaSensorReadings + * @return Inlet fan 1 pulse time + *************************************************************************/ +U16 getFPGAInletFan1TogglePeriod( void ) +{ + return fpgaSensorReadings.fan1PulseTime; +} + #ifdef DEBUG_ENABLED /*********************************************************************//** * @brief Index: firmware/App/Services/FPGA.h =================================================================== diff -u -r3f26385e0e67b8596b06c26533353c759f3ee996 -r4164cba570c42566aee10d7cce23c3cea0d903ee --- firmware/App/Services/FPGA.h (.../FPGA.h) (revision 3f26385e0e67b8596b06c26533353c759f3ee996) +++ firmware/App/Services/FPGA.h (.../FPGA.h) (revision 4164cba570c42566aee10d7cce23c3cea0d903ee) @@ -151,6 +151,7 @@ U16 getFPGAValveBloodArterialCurrentCounts( void ); U16 getFPGABoardTemperature( void ); U32 getFPGAPBAADCTemperature( void ); +U16 getFPGAInletFan1TogglePeriod( void ); // The PWM functions are only used during debugging #ifdef DEBUG_ENABLED Index: firmware/App/Services/SystemComm.c =================================================================== diff -u -r78cee9347b3766ac7c14d413ed848be758c7e9cd -r4164cba570c42566aee10d7cce23c3cea0d903ee --- firmware/App/Services/SystemComm.c (.../SystemComm.c) (revision 78cee9347b3766ac7c14d413ed848be758c7e9cd) +++ firmware/App/Services/SystemComm.c (.../SystemComm.c) (revision 4164cba570c42566aee10d7cce23c3cea0d903ee) @@ -1624,7 +1624,7 @@ handleTestValvesCurrentOverrideRequest( message ); break; - case MSD_ID_HD_VALVES_POSITION_COUNT_OVERRIDE: + case MSG_ID_HD_VALVES_POSITION_COUNT_OVERRIDE: handleTestValvesPositionCountOverrideRequest( message ); break; @@ -1672,6 +1672,18 @@ handleTestSyringePumpADCReadCtrOverrideRequest( message ); break; + case MSG_ID_HD_TEMPERATURES_VALUE_OVERRIDE: + handleTestTemperaturesValueOverrideRequest( message ); + break; + + case MSG_ID_HD_TEMPERATURES_PUBLISH_INTERVAL_OVERRIDE: + handleTestTemperaturesBroadcastIntervalOverrideRequest( message ); + break; + + case MSG_ID_HD_FANS_PUBLISH_INTERVAL_OVERRIDE: + handleTestFansBroadcastIntervalOverrideRequest( message ) + break; + case MSG_ID_HD_SET_CALIBRATION_RECORD: handleSetHDCalibrationRecord( message ); break; Index: firmware/App/Services/SystemCommMessages.c =================================================================== diff -u -r1eac55db00559965a7dc6752fc42a2c54d56f4b9 -r4164cba570c42566aee10d7cce23c3cea0d903ee --- firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision 1eac55db00559965a7dc6752fc42a2c54d56f4b9) +++ firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision 4164cba570c42566aee10d7cce23c3cea0d903ee) @@ -32,6 +32,7 @@ #include "SafetyShutdown.h" #include "SystemComm.h" #include "SystemCommMessages.h" +#include "Temperatures.h" #include "TreatmentEnd.h" #include "TreatmentRecirc.h" #include "Utilities.h" @@ -2733,6 +2734,60 @@ return result; } +/*********************************************************************//** + * @brief + * The broadcastTemperaturesData function sends out the temperatures data. + * @details Inputs: none + * @details Outputs: temperatures data msg constructed and queued + * @param temperaturesData which is the temperatures msg constructed and queued + * @return TRUE if msg successfully queued for transmit, FALSE if not + *************************************************************************/ +BOOL broadcastTemperaturesData( TEMPERATURES_DATA_T *temperaturesData ) +{ + BOOL result; + MESSAGE_T msg; + U08 *payloadPtr = msg.payload; + + // Create a message record + blankMessage( &msg ); + msg.hdr.msgID = MSG_ID_HD_TEMPERATURES_DATA; + msg.hdr.payloadLen = sizeof( TEMPERATURES_DATA_T ); + + memcpy( payloadPtr, temperaturesData, sizeof( TEMPERATURES_DATA_T ) ); + + // serialize the message (w/ sync, CRC, and appropriate CAN padding) and add serialized message data to appropriate comm buffer + result = serializeMessage( msg, COMM_BUFFER_OUT_CAN_HD_BROADCAST, ACK_NOT_REQUIRED ); + + return result; +} + +/*********************************************************************//** + * @brief + * The broadcastFansData function sends out the fans data. + * @details Inputs: none + * @details Outputs: fans data msg constructed and queued + * @param fansData which is the fans msg constructed and queued + * @return TRUE if msg successfully queued for transmit, FALSE if not + *************************************************************************/ +BOOL broadcastFansData( FANS_DATA_T *fansData ) +{ + BOOL result; + MESSAGE_T msg; + U08 *payloadPtr = msg.payload; + + // Create a message record + blankMessage( &msg ); + msg.hdr.msgID = MSG_ID_HD_FANS_DATA; + msg.hdr.payloadLen = sizeof( FANS_DATA_T ); + + memcpy( payloadPtr, fansData, sizeof( FANS_DATA_T ) ); + + // serialize the message (w/ sync, CRC, and appropriate CAN padding) and add serialized message data to appropriate comm buffer + result = serializeMessage( msg, COMM_BUFFER_OUT_CAN_HD_BROADCAST, ACK_NOT_REQUIRED ); + + return result; +} + #ifdef EMC_TEST_BUILD BOOL broadcastCANErrorCount( U32 count ) { @@ -6814,4 +6869,91 @@ sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); } +/*********************************************************************//** + * @brief + * The handleTestTemperaturesValueOverrideRequest function handles a + * request to override a temperatures sensor's value. + * @details Inputs: none + * @details Outputs: message handled + * @param message : a pointer to the message to handle + * @return none + *************************************************************************/ +void handleTestTemperaturesValueOverrideRequest( MESSAGE_T * message ) +{ + TEST_OVERRIDE_ARRAY_PAYLOAD_T payload; + BOOL result = FALSE; + + // Verify payload length + if ( sizeof(TEST_OVERRIDE_ARRAY_PAYLOAD_T) == message->hdr.payloadLen ) + { + memcpy( &payload, message->payload, sizeof(TEST_OVERRIDE_ARRAY_PAYLOAD_T) ); + if ( FALSE == payload.reset ) + { + result = testSetMeasuredTemperatureOverride( payload.index, payload.state.f32 ); + } + else + { + result = testResetMeasuredTemperatureOverride( payload.index ); + } + } + + // Respond to request + sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); +} + +/*********************************************************************//** + * @brief + * The handleTestTemperaturesBroadcastIntervalOverrideRequest function handles a + * request to override the temperatures data broadcast interval. + * @details Inputs: none + * @details Outputs: message handled + * @param message : a pointer to the message to handle + * @return none + *************************************************************************/ +void handleTestTemperaturesBroadcastIntervalOverrideRequest( MESSAGE_T *message ) +{ + TEST_OVERRIDE_PAYLOAD_T payload; + BOOL result = FALSE; + + // Verify payload length + if ( sizeof( TEST_OVERRIDE_PAYLOAD_T ) == message->hdr.payloadLen ) + { + memcpy( &payload, message->payload, sizeof( TEST_OVERRIDE_PAYLOAD_T ) ); + if ( FALSE == payload.reset ) + { + result = testSetTemperaturesPublishIntervalOverride( (U32)( payload.state.u32 ) ); + } + else + { + result = testResetTemperaturesPublishIntervalOverride(); + } + } + + // Respond to request + sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); +} + +void handleTestFansBroadcastIntervalOverrideRequest( MESSAGE_T *message ) +{ + TEST_OVERRIDE_PAYLOAD_T payload; + BOOL result = FALSE; + + // Verify payload length + if ( sizeof( TEST_OVERRIDE_PAYLOAD_T ) == message->hdr.payloadLen ) + { + memcpy( &payload, message->payload, sizeof( TEST_OVERRIDE_PAYLOAD_T ) ); + if ( FALSE == payload.reset ) + { + result = testSetFanPublishIntervalOverride( (U32)( payload.state.u32 ) ); + } + else + { + result = testResetFanPublishIntervalOverride(); + } + } + + // Respond to request + sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); +} + /**@}*/ Index: firmware/App/Services/SystemCommMessages.h =================================================================== diff -u -r3d8fdd44ca1d0ba87e0564d124b4a15ca18bc612 -r4164cba570c42566aee10d7cce23c3cea0d903ee --- firmware/App/Services/SystemCommMessages.h (.../SystemCommMessages.h) (revision 3d8fdd44ca1d0ba87e0564d124b4a15ca18bc612) +++ firmware/App/Services/SystemCommMessages.h (.../SystemCommMessages.h) (revision 4164cba570c42566aee10d7cce23c3cea0d903ee) @@ -26,7 +26,8 @@ #include "DGInterface.h" #include "DialInFlow.h" #include "DialOutFlow.h" -#include "Dialysis.h" +#include "Dialysis.h" +#include "Fans.h" #include "FluidLeak.h" #include "HDCommon.h" #include "Prime.h" @@ -37,6 +38,7 @@ #include "NVDataMgmt.h" #include "PresOccl.h" #include "Rinseback.h" +#include "Temperatures.h" #include "ModeStandby.h" #include "SyringePump.h" #include "Valves.h" @@ -453,6 +455,12 @@ // MSG_ID_HD_DISINFECT_STANDBY_DATA BOOL broadcastDisinfectsData( DISINFECTS_DATA_T *disinfectsData ); +// MSG_ID_HD_TEMPERATURES_DATA +BOOL broadcastTemperaturesData( TEMPERATURES_DATA_T *temperaturesData ); + +// MSG_ID_HD_FANS_DATA +BOOL broadcastFansData( FANS_DATA_T *fansData ); + #ifdef EMC_TEST_BUILD // MSG_ID_CAN_ERROR_COUNT BOOL broadcastCANErrorCount( U32 count ); @@ -750,6 +758,15 @@ // MSG_ID_HD_SYRINGE_PUMP_ADC_READ_COUNTER_OVERRIDE void handleTestSyringePumpADCReadCtrOverrideRequest( MESSAGE_T *message ); +// MSG_ID_HD_TEMPERATURES_VALUE_OVERRIDE +void handleTestTemperaturesValueOverrideRequest( MESSAGE_T * message ); + +// MSG_ID_HD_TEMPERATURES_PUBLISH_INTERVAL_OVERRRIDE +void handleTestTemperaturesBroadcastIntervalOverrideRequest( MESSAGE_T *message ); + +// MSG_ID_HD_FANS_PUBLISH_INTERVAL_OVERRIDE +void handleTestFansBroadcastIntervalOverrideRequest( MESSAGE_T *message ); + /**@}*/ #endif