Index: firmware/App/Controllers/Voltages.c =================================================================== diff -u -rdf10b0aabdb10971df71abea8bea2f5ebae94f40 -reeb1f014f2cc7e23fc6faf817b3df93a662fe701 --- firmware/App/Controllers/Voltages.c (.../Voltages.c) (revision df10b0aabdb10971df71abea8bea2f5ebae94f40) +++ firmware/App/Controllers/Voltages.c (.../Voltages.c) (revision eeb1f014f2cc7e23fc6faf817b3df93a662fe701) @@ -14,38 +14,39 @@ * @date (original) 15-Apr-2021 * ***************************************************************************/ - + #include "AlarmMgmt.h" #include "CPLD.h" #include "FPGA.h" #include "InternalADC.h" #include "PersistentAlarm.h" -#include "SafetyShutdown.h" -#include "SystemCommMessages.h" -#include "TaskGeneral.h" +#include "SafetyShutdown.h" +#include "SystemCommMessages.h" +#include "TaskGeneral.h" #include "Timers.h" -#include "Voltages.h" - -/** - * @addtogroup Voltages - * @{ - */ - -// ********** private definitions ********** - +#include "Voltages.h" + +/** + * @addtogroup Voltages + * @{ + */ + +// ********** private definitions ********** + #define VOLTAGES_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the voltages data is published on the CAN bus. #define VOLTAGES_ALARM_PERSISTENCE_MS ( 1 * MS_PER_SECOND ) ///< Alarm persistence period for voltage monitor alarms in milliseconds. #define POWER_LOSS_VOLTAGE_PERSISTENCE_MS 150 ///< Power supply voltage out of range persistence in milliseconds. -#define DATA_PUBLISH_COUNTER_START_COUNT 14 ///< Data publish counter start count. - -/// Defined states for the voltage monitor state machine. -typedef enum Voltages_States -{ - VOLTAGES_INIT_STATE = 0, ///< Initialization state. - VOLTAGES_MONITOR_STATE, ///< Continuous read sensors state. - NUM_OF_VOLTAGES_STATES ///< Number of voltage monitor states. -} VOLTAGES_STATE_T; - +#define POWER_LOSS_VOLTAGE_THRESHOLD_V 5.0F ///< Power loss voltage threshold +#define DATA_PUBLISH_COUNTER_START_COUNT 14 ///< Data publish counter start count. + +/// Defined states for the voltage monitor state machine. +typedef enum Voltages_States +{ + VOLTAGES_INIT_STATE = 0, ///< Initialization state. + VOLTAGES_MONITOR_STATE, ///< Continuous read sensors state. + NUM_OF_VOLTAGES_STATES ///< Number of voltage monitor states. +} VOLTAGES_STATE_T; + /// Maximum voltage/current level for each monitored signal. static const F32 MAX_VOLTAGES[ NUM_OF_MONITORED_LINES ] = { @@ -61,7 +62,7 @@ 1.98, // MONITORED_LINE_FPGA_AUX_V 0.1 // MONITORED_LINE_FPGA_PVN_V }; -/// Minimum voltage/current level for each monitored signal. +/// Minimum voltage/current level for each monitored signal. static const F32 MIN_VOLTAGES[ NUM_OF_MONITORED_LINES ] = { 1.08, // MONITORED_LINE_1_2V @@ -76,31 +77,31 @@ 1.62, // MONITORED_LINE_FPGA_AUX_V -0.1 // MONITORED_LINE_FPGA_PVN_V }; - -// ********** private data ********** - -static VOLTAGES_STATE_T voltagesState; ///< Current state of voltages monitor state machine. -static U32 voltagesDataPublicationTimerCounter; ///< Used to schedule voltages monitor data publication to CAN bus. - + +// ********** private data ********** + +static VOLTAGES_STATE_T voltagesState; ///< Current state of voltages monitor state machine. +static U32 voltagesDataPublicationTimerCounter; ///< Used to schedule voltages monitor data publication to CAN bus. + /// Interval (in ms) at which to publish voltages monitor data to CAN bus. -static OVERRIDE_U32_T voltagesDataPublishInterval = { VOLTAGES_DATA_PUB_INTERVAL, VOLTAGES_DATA_PUB_INTERVAL, 0, 0 }; +static OVERRIDE_U32_T voltagesDataPublishInterval = { VOLTAGES_DATA_PUB_INTERVAL, VOLTAGES_DATA_PUB_INTERVAL, 0, 0 }; static OVERRIDE_F32_T voltages[ NUM_OF_MONITORED_LINES ]; ///< Monitored voltages and currents. -// ********** private function prototypes ********** - -static VOLTAGES_STATE_T handleVoltagesInitState( void ); +// ********** private function prototypes ********** + +static VOLTAGES_STATE_T handleVoltagesInitState( void ); static VOLTAGES_STATE_T handleVoltagesMonitorState( void ); static void checkVoltageRanges( void ); -static void publishVoltagesData( void ); - -/*********************************************************************//** - * @brief - * The initVoltagesMonitor function initializes the Voltages module. - * @details Inputs: none - * @details Outputs: Voltages module initialized. - * @return none - *************************************************************************/ -void initVoltagesMonitor( void ) +static void publishVoltagesData( void ); + +/*********************************************************************//** + * @brief + * The initVoltagesMonitor function initializes the Voltages module. + * @details Inputs: none + * @details Outputs: Voltages module initialized. + * @return none + *************************************************************************/ +void initVoltagesMonitor( void ) { U32 i; @@ -116,65 +117,65 @@ } initPersistentAlarm( ALARM_ID_HD_VOLTAGE_OUT_OF_RANGE, VOLTAGES_ALARM_PERSISTENCE_MS, VOLTAGES_ALARM_PERSISTENCE_MS ); - initPersistentAlarm( ALARM_ID_HD_AC_POWER_LOST, POWER_LOSS_VOLTAGE_PERSISTENCE_MS, 0 ); -} - -/*********************************************************************//** - * @brief - * The execVoltagesMonitor function executes the voltages monitor. - * @details Inputs: voltagesState - * @details Outputs: voltagesState - * @return none - *************************************************************************/ -void execVoltagesMonitor( void ) + initPersistentAlarm( ALARM_ID_HD_AC_POWER_LOST, POWER_LOSS_VOLTAGE_PERSISTENCE_MS, 0 ); +} + +/*********************************************************************//** + * @brief + * The execVoltagesMonitor function executes the voltages monitor. + * @details Inputs: voltagesState + * @details Outputs: voltagesState + * @return none + *************************************************************************/ +void execVoltagesMonitor( void ) { - // State machine - switch ( voltagesState ) - { - case VOLTAGES_INIT_STATE: - voltagesState = handleVoltagesInitState(); - break; - - case VOLTAGES_MONITOR_STATE: - voltagesState = handleVoltagesMonitorState(); - break; - - default: - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, 0, voltagesState ) // TODO - add enum for this s/w fault - break; - } - - // Publish voltages data on interval - publishVoltagesData(); -} - -/*********************************************************************//** - * @brief - * The handleVoltagesInitState function handles the initialize state - * of the voltages monitor state machine. - * @details Inputs: none - * @details Outputs: none - * @return next state - *************************************************************************/ -static VOLTAGES_STATE_T handleVoltagesInitState( void ) -{ - VOLTAGES_STATE_T result = VOLTAGES_MONITOR_STATE; - - return result; -} - -/*********************************************************************//** - * @brief - * The handleVoltagesMonitorState function handles the monitor state - * of the voltages monitor state machine. - * @details Inputs: converted internal ADC readings - * @details Outputs: alarm on failed check - * @return next state - *************************************************************************/ -static VOLTAGES_STATE_T handleVoltagesMonitorState( void ) -{ + // State machine + switch ( voltagesState ) + { + case VOLTAGES_INIT_STATE: + voltagesState = handleVoltagesInitState(); + break; + + case VOLTAGES_MONITOR_STATE: + voltagesState = handleVoltagesMonitorState(); + break; + + default: + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, 0, voltagesState ) // TODO - add enum for this s/w fault + break; + } + + // Publish voltages data on interval + publishVoltagesData(); +} + +/*********************************************************************//** + * @brief + * The handleVoltagesInitState function handles the initialize state + * of the voltages monitor state machine. + * @details Inputs: none + * @details Outputs: none + * @return next state + *************************************************************************/ +static VOLTAGES_STATE_T handleVoltagesInitState( void ) +{ VOLTAGES_STATE_T result = VOLTAGES_MONITOR_STATE; + return result; +} + +/*********************************************************************//** + * @brief + * The handleVoltagesMonitorState function handles the monitor state + * of the voltages monitor state machine. + * @details Inputs: converted internal ADC readings + * @details Outputs: alarm on failed check + * @return next state + *************************************************************************/ +static VOLTAGES_STATE_T handleVoltagesMonitorState( void ) +{ + VOLTAGES_STATE_T result = VOLTAGES_MONITOR_STATE; + // Get latest signal levels voltages[ MONITORED_LINE_1_2V ].data = getIntADCVoltageConverted( INT_ADC_1_2V_PROCESSOR ); voltages[ MONITORED_LINE_3_3V ].data = getIntADCVoltageConverted( INT_ADC_3_3V ); @@ -191,7 +192,7 @@ // Check voltage ranges checkVoltageRanges(); - return result; + return result; } /*********************************************************************//** @@ -204,42 +205,49 @@ *************************************************************************/ static void checkVoltageRanges( void ) { - U32 i; - BOOL hasPowerBeenLost = getCPLDACPowerLossDetected(); + MONITORED_VOLTAGES_T channel; + MONITORED_VOLTAGES_T channelInAlarm; + BOOL hasPowerBeenLost = FALSE; + BOOL isVoltageOutOfRange = FALSE; + F32 volts = 0.0F; + F32 alarmVoltage = 0.0F; - // Check range - for ( i = 0; i < NUM_OF_MONITORED_LINES; i++ ) + // Have we lost AC power? TODO - replace with CPLD status check + if ( getMonitoredLineLevel( MONITORED_LINE_24V ) < POWER_LOSS_VOLTAGE_THRESHOLD_V ) { - F32 volts = getMonitoredLineLevel( (MONITORED_VOLTAGES_T)i ); - BOOL isVoltageOutOfRange = ( ( volts > MAX_VOLTAGES[ i ] ) || ( volts < MIN_VOLTAGES[ i ] ) ? TRUE : FALSE ); + if ( ( getCurrentOperationMode() != MODE_INIT ) && ( FALSE == isSafetyShutdownActivated() ) ) + { + hasPowerBeenLost = TRUE; + } + } + // Check range + for ( channel = MONITORED_LINE_FIRST_VOLTAGE; channel < NUM_OF_MONITORED_LINES; channel++ ) + { if ( ( ( isSafetyShutdownActivated() != TRUE ) && ( hasPowerBeenLost != TRUE ) ) || - ( ( i != MONITORED_LINE_24V ) && ( i != MONITORED_LINE_24V_REGEN ) ) ) + ( ( channel != MONITORED_LINE_24V ) && ( channel != MONITORED_LINE_24V_REGEN ) ) ) { #ifndef _RELEASE_ if ( getSoftwareConfigStatus( SW_CONFIG_DISABLE_VOLTAGES_ALARMS ) != SW_CONFIG_ENABLE_VALUE ) #endif { - if ( TRUE == isPersistentAlarmTriggered( ALARM_ID_HD_VOLTAGE_OUT_OF_RANGE, isVoltageOutOfRange ) ) + volts = getMonitoredLineLevel( channel ); + if ( ( volts > MAX_VOLTAGES[ channel ] ) || ( volts < MIN_VOLTAGES[ channel] ) ) { - SET_ALARM_WITH_2_F32_DATA( ALARM_ID_HD_VOLTAGE_OUT_OF_RANGE, i, isVoltageOutOfRange ); + isVoltageOutOfRange = TRUE; + channelInAlarm = channel; + alarmVoltage = volts; + break; // once a channel is out of range there is + // no need to continue } } -#ifndef _RELEASE_ - else - { - isPersistentAlarmTriggered( ALARM_ID_HD_VOLTAGE_OUT_OF_RANGE, FALSE ); - } -#endif } - else - { - isPersistentAlarmTriggered( ALARM_ID_HD_VOLTAGE_OUT_OF_RANGE, FALSE ); - } } - // manage AC power loss alarm detection/clearing - if ( TRUE == hasPowerBeenLost ) + // Check the persistence alarm + checkPersistentAlarm ( ALARM_ID_HD_VOLTAGE_OUT_OF_RANGE, isVoltageOutOfRange, channelInAlarm, alarmVoltage ); + + if ( TRUE == isPersistentAlarmTriggered( ALARM_ID_HD_AC_POWER_LOST, hasPowerBeenLost ) ) { HD_OP_MODE_T opMode = getCurrentOperationMode(); @@ -263,15 +271,15 @@ } } -/*********************************************************************//** - * @brief +/*********************************************************************//** + * @brief * The getMonitoredLineLevel function gets the current voltage or current - * level for a given signal. - * @details Inputs: voltages[] + * level for a given signal. + * @details Inputs: voltages[] * @details Outputs: none - * @param signal the signal that is being asked for - * @return the voltage/current for the given signal - *************************************************************************/ + * @param signal the signal that is being asked for + * @return the voltage/current for the given signal + *************************************************************************/ F32 getMonitoredLineLevel( MONITORED_VOLTAGES_T signal ) { F32 result = 0.0; @@ -292,143 +300,143 @@ return result; } - -/*********************************************************************//** - * @brief - * The publishVoltagesData function publishes voltages monitor data at the - * set interval. - * @details Inputs: latest voltages and currents - * @details Outputs: voltages monitor data are published to CAN bus. - * @return none - *************************************************************************/ -static void publishVoltagesData( void ) -{ - // Publish voltages monitor data on interval - if ( ++voltagesDataPublicationTimerCounter >= getU32OverrideValue( &voltagesDataPublishInterval ) ) + +/*********************************************************************//** + * @brief + * The publishVoltagesData function publishes voltages monitor data at the + * set interval. + * @details Inputs: latest voltages and currents + * @details Outputs: voltages monitor data are published to CAN bus. + * @return none + *************************************************************************/ +static void publishVoltagesData( void ) +{ + // Publish voltages monitor data on interval + if ( ++voltagesDataPublicationTimerCounter >= getU32OverrideValue( &voltagesDataPublishInterval ) ) { VOLTAGES_DATA_PAYLOAD_T data; - - data.adc1_2VProc = getMonitoredLineLevel( MONITORED_LINE_1_2V ); - data.adc3_3V = getMonitoredLineLevel( MONITORED_LINE_3_3V ); - data.adc5VLogic = getMonitoredLineLevel( MONITORED_LINE_5V_LOGIC ); - data.adc5VSensors = getMonitoredLineLevel( MONITORED_LINE_5V_SENSORS ); - data.adc24V = getMonitoredLineLevel( MONITORED_LINE_24V ); + + data.adc1_2VProc = getMonitoredLineLevel( MONITORED_LINE_1_2V ); + data.adc3_3V = getMonitoredLineLevel( MONITORED_LINE_3_3V ); + data.adc5VLogic = getMonitoredLineLevel( MONITORED_LINE_5V_LOGIC ); + data.adc5VSensors = getMonitoredLineLevel( MONITORED_LINE_5V_SENSORS ); + data.adc24V = getMonitoredLineLevel( MONITORED_LINE_24V ); data.adc24VRegen = getMonitoredLineLevel( MONITORED_LINE_24V_REGEN ); data.adcFpgaAdcRef = getMonitoredLineLevel( MONITORED_LINE_FPGA_REF_V ); data.adcPbaRef = getMonitoredLineLevel( MONITORED_LINE_PBA_REF_V ); data.fpgaVcc = getMonitoredLineLevel( MONITORED_LINE_FPGA_VCC_V ); data.fpgaVaux = getMonitoredLineLevel( MONITORED_LINE_FPGA_AUX_V ); data.fpgaVpvn = getMonitoredLineLevel( MONITORED_LINE_FPGA_PVN_V ); - + broadcastData( MSG_ID_HD_VOLTAGES_DATA, COMM_BUFFER_OUT_CAN_HD_BROADCAST, (U08*)&data, sizeof( VOLTAGES_DATA_PAYLOAD_T ) ); - voltagesDataPublicationTimerCounter = 0; - } -} + voltagesDataPublicationTimerCounter = 0; + } +} - -/************************************************************************* - * TEST SUPPORT FUNCTIONS - *************************************************************************/ - - -/*********************************************************************//** - * @brief - * The testSetVoltagesDataPublishIntervalOverride function overrides the - * monitored voltages data publish interval. - * @details Inputs: none - * @details Outputs: voltagesDataPublishInterval - * @param value override monitored voltages data publish interval with (in ms) - * @return TRUE if override successful, FALSE if not - *************************************************************************/ -BOOL testSetVoltagesDataPublishIntervalOverride( U32 value ) -{ - BOOL result = FALSE; - - if ( TRUE == isTestingActivated() ) - { - U32 intvl = value / TASK_GENERAL_INTERVAL; - - result = TRUE; - voltagesDataPublishInterval.ovData = intvl; - voltagesDataPublishInterval.override = OVERRIDE_KEY; - } - - return result; -} - -/*********************************************************************//** - * @brief - * The testResetVoltagesDataPublishIntervalOverride function resets the override - * of the monitored voltages data publish interval. - * @details Inputs: none - * @details Outputs: voltagesDataPublishInterval - * @return TRUE if override reset successful, FALSE if not - *************************************************************************/ -BOOL testResetVoltagesDataPublishIntervalOverride( void ) -{ - BOOL result = FALSE; - - if ( TRUE == isTestingActivated() ) - { - result = TRUE; - voltagesDataPublishInterval.override = OVERRIDE_RESET; - voltagesDataPublishInterval.ovData = voltagesDataPublishInterval.ovInitData; - } - - return result; -} - -/*********************************************************************//** - * @brief - * The testSetLineLevelOverride function overrides the given monitored voltage - * or current. - * @details Inputs: none + +/************************************************************************* + * TEST SUPPORT FUNCTIONS + *************************************************************************/ + + +/*********************************************************************//** + * @brief + * The testSetVoltagesDataPublishIntervalOverride function overrides the + * monitored voltages data publish interval. + * @details Inputs: none + * @details Outputs: voltagesDataPublishInterval + * @param value override monitored voltages data publish interval with (in ms) + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testSetVoltagesDataPublishIntervalOverride( U32 value ) +{ + BOOL result = FALSE; + + if ( TRUE == isTestingActivated() ) + { + U32 intvl = value / TASK_GENERAL_INTERVAL; + + result = TRUE; + voltagesDataPublishInterval.ovData = intvl; + voltagesDataPublishInterval.override = OVERRIDE_KEY; + } + + return result; +} + +/*********************************************************************//** + * @brief + * The testResetVoltagesDataPublishIntervalOverride function resets the override + * of the monitored voltages data publish interval. + * @details Inputs: none + * @details Outputs: voltagesDataPublishInterval + * @return TRUE if override reset successful, FALSE if not + *************************************************************************/ +BOOL testResetVoltagesDataPublishIntervalOverride( void ) +{ + BOOL result = FALSE; + + if ( TRUE == isTestingActivated() ) + { + result = TRUE; + voltagesDataPublishInterval.override = OVERRIDE_RESET; + voltagesDataPublishInterval.ovData = voltagesDataPublishInterval.ovInitData; + } + + return result; +} + +/*********************************************************************//** + * @brief + * The testSetLineLevelOverride function overrides the given monitored voltage + * or current. + * @details Inputs: none * @details Outputs: voltages[] - * @param signal the signal to override - * @param value override signal level with this value - * @return TRUE if override successful, FALSE if not - *************************************************************************/ -BOOL testSetLineLevelOverride( U32 signal, F32 value ) -{ - BOOL result = FALSE; - + * @param signal the signal to override + * @param value override signal level with this value + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testSetLineLevelOverride( U32 signal, F32 value ) +{ + BOOL result = FALSE; + if ( signal < NUM_OF_MONITORED_LINES ) { - if ( TRUE == isTestingActivated() ) - { - result = TRUE; - voltages[ signal ].ovData = value; - voltages[ signal ].override = OVERRIDE_KEY; + if ( TRUE == isTestingActivated() ) + { + result = TRUE; + voltages[ signal ].ovData = value; + voltages[ signal ].override = OVERRIDE_KEY; } } - - return result; -} - -/*********************************************************************//** - * @brief - * The testResetLineLevelOverride function resets the override of the - * given monitored voltage or current. - * @details Inputs: none + + return result; +} + +/*********************************************************************//** + * @brief + * The testResetLineLevelOverride function resets the override of the + * given monitored voltage or current. + * @details Inputs: none * @details Outputs: voltages[] - * @param signal the signal to reset override - * @return TRUE if reset successful, FALSE if not - *************************************************************************/ -BOOL testResetLineLevelOverride( U32 signal ) -{ - BOOL result = FALSE; - + * @param signal the signal to reset override + * @return TRUE if reset successful, FALSE if not + *************************************************************************/ +BOOL testResetLineLevelOverride( U32 signal ) +{ + BOOL result = FALSE; + if ( signal < NUM_OF_MONITORED_LINES ) { - if ( TRUE == isTestingActivated() ) - { - result = TRUE; - voltages[ signal ].override = OVERRIDE_RESET; - voltages[ signal ].ovData = voltages[ signal ].ovInitData; + if ( TRUE == isTestingActivated() ) + { + result = TRUE; + voltages[ signal ].override = OVERRIDE_RESET; + voltages[ signal ].ovData = voltages[ signal ].ovInitData; } - } - - return result; -} - -/**@}*/ + } + + return result; +} + +/**@}*/