Index: firmware/App/Controllers/Pressures.c =================================================================== diff -u -r0dec8744af40d0c87a6d7cd1923920c1c2bd1d2f -rbeb6f17e872c1f31df1095e693b28c2661628cbe --- firmware/App/Controllers/Pressures.c (.../Pressures.c) (revision 0dec8744af40d0c87a6d7cd1923920c1c2bd1d2f) +++ firmware/App/Controllers/Pressures.c (.../Pressures.c) (revision beb6f17e872c1f31df1095e693b28c2661628cbe) @@ -14,12 +14,12 @@ * @date (original) 04-Apr-2020 * ***************************************************************************/ - +#include + #include "Pressures.h" #include "AlarmMgmt.h" #include "FPGA.h" #include "InternalADC.h" -#include "LoadCell.h" // TODO - test - remove later #include "OperationModes.h" #include "SystemCommMessages.h" #include "TaskPriority.h" @@ -32,15 +32,18 @@ // ********** private definitions ********** -/// Default publication interval for pressure and occlusion data. #define PRESSURES_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) ///< interval (ms/task time) at which the pressures data is published on the CAN bus. -#define PUMP_PRESSURE_ZERO 777 ///< ADC counts equivalent to 0 PSI for pump in/out pressure sensors. -#define PUMP_PRESSURE_PSIA_PER_COUNT 0.06434 ///< PSIA per ADC count conversion factor for pump in/out pressure sensors. -#define PUMP_PRESSURE_PSIA_TO_PSI_OFFSET 14.7 ///< Subtract this offset to convert PSIA to PSI. +#define PUMP_PRESSURE_ZERO 777 ///< ADC counts equivalent to 0 PSI for pump in/out pressure sensors. +#define PUMP_PRESSURE_PSIA_PER_COUNT 0.06434 ///< PSIA per ADC count conversion factor for pump in/out pressure sensors. +#define PUMP_PRESSURE_PSIA_TO_PSI_OFFSET 14.7 ///< Subtract this offset to convert PSIA to PSI. #define PRESSURE_SAMPLES_TO_AVERAGE (200 / TASK_PRIORITY_INTERVAL) ///< Averaging pressure data over the reporting interval. #define PRESSURE_AVERAGE_MULTIPLIER (1.0 / (F32)PRESSURE_SAMPLES_TO_AVERAGE) ///< Optimization - multiplying is faster than dividing. + +#define PRESSURE_SENSORS_ADC_BITS 12U ///< Pressure sensors ADC bits +#define PRESSURE_SENSORS_ADC_MAX_COUNT ( pow(2, PRESSURE_SENSORS_ADC_BITS) ) ///< Pressure sensors max ADC count + /// Defined states for the pressures monitor state machine. typedef enum PresOccl_States @@ -61,17 +64,17 @@ // ********** private data ********** -static PRESSURE_STATE_T pressuresState = PRESSURE_INIT_STATE; ///< current state of pressure monitor state machine. +static PRESSURE_STATE_T pressuresState; ///< current state of pressure monitor state machine. static U32 pressuresDataPublicationTimerCounter = 0; ///< used to schedule pressure data publication to CAN bus. - -static OVERRIDE_U32_T pressuresDataPublishInterval = { PRESSURES_DATA_PUB_INTERVAL, PRESSURES_DATA_PUB_INTERVAL, 0, 0 }; ///< interval (in ms/task interval) at which to publish pressures data to CAN bus. + +/// interval (in ms/task interval) at which to publish pressures data to CAN bus. +static OVERRIDE_U32_T pressuresDataPublishInterval = { PRESSURES_DATA_PUB_INTERVAL, PRESSURES_DATA_PUB_INTERVAL, 0, 0 }; static OVERRIDE_F32_T pressures[ NUM_OF_PRESSURE_SENSORS ]; ///< Measured pressure from sensors. static S32 measuredPressureReadingsSum[ NUM_OF_PRESSURE_SENSORS ]; ///< Raw pressure sensor sums for averaging. static U32 pressureFilterCounter = 0; ///< used to schedule pressure sensor filtering. -static PRESSURE_SELF_TEST_STATE_T pressuresSelfTestState = PRESSURE_SELF_TEST_STATE_START; ///< current pressure self test state. -static U32 pressuresSelfTestTimerCount = 0; ///< timer counter for pressure self test. +static PRESSURE_SELF_TEST_STATE_T pressuresSelfTestState; ///< current pressure self test state. // ********** private function prototypes ********** @@ -80,6 +83,8 @@ static void checkPressures( void ); static void publishPressuresData( void ); static DATA_GET_PROTOTYPE( U32, getPublishPressuresDataInterval ); + +static SELF_TEST_STATUS_T handleSelfTestADCCheck( void ); /*********************************************************************//** * @brief @@ -106,8 +111,7 @@ pressuresState = PRESSURE_INIT_STATE; pressuresSelfTestState = PRESSURE_SELF_TEST_STATE_START; pressuresDataPublicationTimerCounter = 0; - pressuresSelfTestTimerCount = 0; -} +} /*********************************************************************//** * @brief @@ -317,22 +321,65 @@ /*********************************************************************//** * @brief - * The execPressuresTest function executes the state machine for the \n + * The execPressureSelfTest function executes the state machine for the \n * Pressures self test. * @details - * Inputs : none - * Outputs : none - * @return the current state of the Pressures self test. + * Inputs : pressuresSelfTestState + * Outputs : pressuresSelfTestState + * @return PressuresSelfTestResult (SELF_TEST_STATUS_T) *************************************************************************/ -SELF_TEST_STATUS_T execPressuresTest( void ) -{ - SELF_TEST_STATUS_T result = SELF_TEST_STATUS_FAILED; +SELF_TEST_STATUS_T execPressureSelfTest( void ) +{ + switch ( pressuresSelfTestState ) + { + case PRESSURE_SELF_TEST_STATE_START: + pressuresSelfTestState = PRESSURE_TEST_STATE_IN_PROGRESS; + pressuresSelfTestResult = SELF_TEST_STATUS_IN_PROGRESS; + break; + + case PRESSURE_TEST_STATE_IN_PROGRESS: + pressuresSelfTestResult = handleSelfTestADCCheck(); + pressuresSelfTestState = PRESSURE_TEST_STATE_COMPLETE; + break; + + case PRESSURE_TEST_STATE_COMPLETE: + // Done with self test + break; + + default: + SET_ALARM_WITH_2_U32_DATA ( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_TEMPERATURE_SENSORS_INVALID_SELF_TEST_STATE, + pressuresSelfTestState ); + break; + } + + return pressuresSelfTestResult; +} + +/************************************************************************* + * @brief + * The handleSelfTestADCCheck function checks whether the ADC reads and + * report status back. If the reads are above the maximum 12bit ADC count + * or below 0, it will throw an alarm. + * @details + * Inputs : none + * Outputs : none + * @param none + * @return result (SELF_TEST_STATUS_T) + *************************************************************************/ +static SELF_TEST_STATUS_T handleSelfTestADCCheck( void ) +{ + SELF_TEST_STATUS_T result = SELF_TEST_STATUS_PASSED; + U16 const inletPressureADCReading = getIntADCReading( INT_ADC_RO_PUMP_INLET_PRESSURE ); + + if ( ( inletPressureADCReading <= 0 ) || ( inletPressureADCReading >= PRESSURE_SENSORS_ADC_MAX_COUNT ) ) + { + result = SELF_TEST_STATUS_FAILED; + SET_ALARM_WITH_1_U32_DATA ( ALARM_ID_PRESSURE_SENSOR_FAULT, inletPressureADCReading ); + } + + return result; +} - // TODO - implement self test(s) - - return result; -} - /**@}*/