Index: firmware/App/Drivers/GPIO.c =================================================================== diff -u -r380b0afc95467d0861ff3aa2cdcde5d5d7ac85e7 -r8cbddbe34a4ffed5a4d9fac07a065799c5862611 --- firmware/App/Drivers/GPIO.c (.../GPIO.c) (revision 380b0afc95467d0861ff3aa2cdcde5d5d7ac85e7) +++ firmware/App/Drivers/GPIO.c (.../GPIO.c) (revision 8cbddbe34a4ffed5a4d9fac07a065799c5862611) @@ -40,21 +40,24 @@ #define SAFETY_POST_NO_24V_RESTORE 2 ///< Safety shutdown POST failed because 24V was not restored when safety line reset. // GIO port A pin assignments for pins connected to CPLD -#define OFF_BUTTON_GIO_PORT_PIN 0U ///< GPIO pin ID on port A for off button input signal. -#define STOP_BUTTON_GIO_PORT_PIN 1U ///< GPIO pin ID on port A for stop button input signal. -#define SAFETY_GIO_PORT_PIN 3U ///< GPIO pin ID on port A for safety shutdown output signal +#define OFF_BUTTON_GIO_PORT_PIN 0U ///< GPIO pin ID on port A for off button input signal. +#define STOP_BUTTON_GIO_PORT_PIN 1U ///< GPIO pin ID on port A for stop button input signal. // GIO port B pin assignments for pins connected to CPLD -#define OFF_REQUEST_GIO_PORT_PIN 0U ///< GPIO pin ID on port B for power off request output signal. -#define WD_PET_GIO_PORT_PIN 1U ///< GPIO pin ID on port B for watchdog pet output signal. -#define SAFE_GIO_PORT_PIN 2U ///< GPIO pin ID on port B for safety shutdown input signal. +#define OFF_REQUEST_GIO_PORT_PIN 0U ///< GPIO pin ID on port B for power off request output signal. +#define WD_PET_GIO_PORT_PIN 1U ///< GPIO pin ID on port B for watchdog pet output signal. +#define SAFE_GIO_PORT_PIN 2U ///< GPIO pin ID on port B for safety shutdown input signal. +#define SAFETY_GIO_PORT_PIN 3U ///< GPIO pin ID on port B for safety shutdown output signal // MIBSPI5 port pin assignments for pins connected to CPLD -#define GREEN_SPI5_PORT_MASK 0x00000200 ///< (CLK - re-purposed as output GPIO) for green alarm lamp signal. -#define BLUE_SPI5_PORT_MASK 0x00000400 ///< (SIMO[0] - re-purposed as output GPIO) for blue alarm lamp signal. -#define RED_SPI5_PORT_MASK 0x00000800 ///< (SOMI[0] - re-purposed as output GPIO) for red alarm lamp signal. -#define AC_PRESENT_SPI5_PORT_MASK 0x00000001 ///< (SOMI[0] - re-purposed as output GPIO) for red alarm lamp signal. +#define GREEN_SPI5_PORT_MASK 0x00000200 ///< (CLK - re-purposed as output GPIO) for green alarm lamp signal. +#define BLUE_SPI5_PORT_MASK 0x00000400 ///< (SIMO[0] - re-purposed as output GPIO) for blue alarm lamp signal. +#define RED_SPI5_PORT_MASK 0x00000800 ///< (SOMI[0] - re-purposed as output GPIO) for red alarm lamp signal. +#define AC_PRESENT_SPI5_PORT_MASK 0x00000001 ///< (NCS[0] - re-purposed as output GPIO) for AC present signal. +// MIBSPI3 port pin assignments for pins connected to CPLD +#define BACKUP_AUDIO_ENABLE_SPI3_PORT_MASK 0x00000001 ///< (NCS[0] - re-purposed as output GPIO for backup alarm audio enable. + // CPLD pin I/O macros #define GET_OFF() (PIN_SIGNAL_STATE_T)(gioGetBit(gioPORTA, OFF_BUTTON_GIO_PORT_PIN)) ///< Macro to get off button signal state. #define GET_STOP() (PIN_SIGNAL_STATE_T)(gioGetBit(gioPORTA, STOP_BUTTON_GIO_PORT_PIN)) ///< Macro to get stop button signal state. @@ -80,7 +83,6 @@ #define CLR_SAFETY_SHUTDOWN() gioSetBit( gioPORTB, SAFETY_GIO_PORT_PIN, PIN_SIGNAL_LOW ) ///< Macro to set safety shutdown signal state low. // Backup alarm audio enable/disable macros -#define BACKUP_AUDIO_ENABLE_SPI3_PORT_MASK 0x00000001 ///< Pin SPI3-CS0 - re-purposed as output GPIO for backup alarm audio enable. #define SET_BACKUP_AUDIO_ENABLE() {mibspiREG3->PC3 |= BACKUP_AUDIO_ENABLE_SPI3_PORT_MASK;} ///< Macro to enable backup alarm audio. #define CLR_BACKUP_AUDIO_ENABLE() {mibspiREG3->PC3 &= ~BACKUP_AUDIO_ENABLE_SPI3_PORT_MASK;} ///< Macro to disable backup alarm audio. Index: firmware/App/Drivers/InternalADC.c =================================================================== diff -u -r380b0afc95467d0861ff3aa2cdcde5d5d7ac85e7 -r8cbddbe34a4ffed5a4d9fac07a065799c5862611 --- firmware/App/Drivers/InternalADC.c (.../InternalADC.c) (revision 380b0afc95467d0861ff3aa2cdcde5d5d7ac85e7) +++ firmware/App/Drivers/InternalADC.c (.../InternalADC.c) (revision 8cbddbe34a4ffed5a4d9fac07a065799c5862611) @@ -33,14 +33,14 @@ /// Mapping from enumerated used ADC channel to processor channel ID. const INT_ADC_CHANNEL_T ADC_CHANNEL_NUM_TO_CHANNEL_ID[ MAX_ADC_CHANNELS ] = { - INT_ADC_AVAILABLE_1, // 0 + INT_ADC_NOT_USED, // 0 INT_ADC_PS_THERMISTOR, // 1 INT_ADC_PBA_ADC_REF, // 2 INT_ADC_24V_ACTUATORS_REG, // 3 INT_ADC_1_2V_PROCESSOR, // 4 INT_ADC_5V_SENSORS, // 5 - INT_ADC_DUMMY, // 6 - INT_ADC_AVAILABLE_2, // 7 + INT_ADC_NOT_USED, // 6 + INT_ADC_NOT_USED, // 7 INT_ADC_PRIMARY_ALARM_CURRENT_HG, // 8 INT_ADC_NOT_USED, // 9 INT_ADC_BOARD_THERMISTOR, // 10 @@ -51,23 +51,19 @@ INT_ADC_NOT_USED, // 15 INT_ADC_BLOOD_PUMP_SPEED, // 16 INT_ADC_BLOOD_PUMP_MOTOR_CURRENT, // 17 - INT_ADC_AVAILABLE_3, // 18 - INT_ADC_AVAILABLE_4, // 19 + INT_ADC_BACKUP_V, // 18 + INT_ADC_NOT_USED, // 19 INT_ADC_NOT_USED, // 20 INT_ADC_NOT_USED, // 21 INT_ADC_24V_ACTUATORS, // 22 - INT_ADC_NOT_USED_2 // 23 + INT_ADC_NOT_USED // 23 }; const F32 ADC_CHANNEL_READ_TO_UNITS[ NUM_OF_INT_ADC_CHANNELS ] = { 0.0, // - INT_ADC_NOT_USED 1.601601, // RPM - INT_ADC_BLOOD_PUMP_SPEED 0.003002, // A - INT_ADC_BLOOD_PUMP_MOTOR_CURRENT - 1.601601, // V - INT_ADC_AVAILABLE_1 - 0.003002, // V - INT_ADC_AVAILABLE_2 - 1.601601, // V - INT_ADC_AVAILABLE_3 - 0.003002, // V - INT_ADC_AVAILABLE_4 0.001221, // V - INT_ADC_PS_THERMISTOR 0.001465, // V - INT_ADC_REFIN_1 0.009420, // V - INT_ADC_24V_ACTUATORS_REG @@ -80,7 +76,7 @@ 0.001465, // V - INT_ADC_5V_LOGIC 0.073240, // mA - INT_ADC_PRIMARY_ALARM_CURRENT_LG 0.007106, // V - INT_ADC_24V_ACTUATORS - 0.0, // - INT_ADC_NOT_USED_2 + 0.007106, // V - INT_ADC_BACKUP_V 0.000000, // V - INT_ADC_DUMMY }; Index: firmware/App/Drivers/InternalADC.h =================================================================== diff -u -r380b0afc95467d0861ff3aa2cdcde5d5d7ac85e7 -r8cbddbe34a4ffed5a4d9fac07a065799c5862611 --- firmware/App/Drivers/InternalADC.h (.../InternalADC.h) (revision 380b0afc95467d0861ff3aa2cdcde5d5d7ac85e7) +++ firmware/App/Drivers/InternalADC.h (.../InternalADC.h) (revision 8cbddbe34a4ffed5a4d9fac07a065799c5862611) @@ -42,10 +42,6 @@ INT_ADC_NOT_USED = 0, ///< Not used INT_ADC_BLOOD_PUMP_SPEED, ///< Internal ADC channel for blood pump speed INT_ADC_BLOOD_PUMP_MOTOR_CURRENT, ///< Internal ADC channel for blood pump current - INT_ADC_AVAILABLE_1, ///< Internal ADC channel for - INT_ADC_AVAILABLE_2, ///< Internal ADC channel for - INT_ADC_AVAILABLE_3, ///< Internal ADC channel for - INT_ADC_AVAILABLE_4, ///< Internal ADC channel for INT_ADC_PS_THERMISTOR, ///< Internal ADC channel for power supply temperature INT_ADC_PBA_ADC_REF, ///< Internal ADC channel for reference voltage to PBA ADC channel) INT_ADC_24V_ACTUATORS_REG, ///< Internal ADC channel for 24V regen (diode drop) to actuators @@ -58,7 +54,7 @@ INT_ADC_5V_LOGIC, ///< Internal ADC channel for 5V to logic INT_ADC_PRIMARY_ALARM_CURRENT_LG, ///< Internal ADC channel for primary alarm audio current low gain INT_ADC_24V_ACTUATORS, ///< Internal ADC channel for 24V to actuators - INT_ADC_NOT_USED_2, ///< Not used + INT_ADC_BACKUP_V, ///< Internal ADC channel for VBackup INT_ADC_DUMMY, ///< Internal ADC channel - not used, needed to get even number of channels NUM_OF_INT_ADC_CHANNELS ///< Number of used internal ADC channels. } INT_ADC_CHANNEL_T; Index: firmware/App/Monitors/Voltages.c =================================================================== diff -u --- firmware/App/Monitors/Voltages.c (revision 0) +++ firmware/App/Monitors/Voltages.c (revision 8cbddbe34a4ffed5a4d9fac07a065799c5862611) @@ -0,0 +1,449 @@ +/************************************************************************** +* +* Copyright (c) 2024-2024 Diality Inc. - All Rights Reserved. +* +* THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN +* WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. +* +* @file Voltages.c +* +* @author (last) Sean +* @date (last) 07-Aug-2024 +* +* @author (original) Sean +* @date (original) 07-Aug-2024 +* +***************************************************************************/ + +#include "AlarmMgmtTD.h" +#include "CpldInterface.h" +#include "DDInterface.h" +#include "FpgaTD.h" +#include "InternalADC.h" +#include "Messaging.h" +#include "OperationModes.h" +#include "PersistentAlarm.h" +#include "SystemCommTD.h" +#include "TaskGeneral.h" +#include "Timers.h" +#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 500 ///< 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; + +/// Maximum voltage/current level for each monitored signal. +static const F32 MAX_VOLTAGES[ NUM_OF_MONITORED_LINES ] = +{ + 1.32, // MONITORED_LINE_1_2V + 3.63, // MONITORED_LINE_3_3V + 5.5, // MONITORED_LINE_5V_LOGIC + 5.5, // MONITORED_LINE_5V_SENSORS + 26.4, // MONITORED_LINE_24V + 28.25, // MONITORED_LINE_24V_REGEN + 1.3125, // MONITORED_LINE_FPGA_REF_V + 3.3, // MONITORED_LINE_PBA_REF_V + 1.1, // MONITORED_LINE_FPGA_VCC_V + 1.98, // MONITORED_LINE_FPGA_AUX_V + 0.1 // MONITORED_LINE_FPGA_PVN_V +}; +/// Minimum voltage/current level for each monitored signal. +static const F32 MIN_VOLTAGES[ NUM_OF_MONITORED_LINES ] = +{ + 1.08, // MONITORED_LINE_1_2V + 2.97, // MONITORED_LINE_3_3V + 4.5, // MONITORED_LINE_5V_LOGIC + 4.5, // MONITORED_LINE_5V_SENSORS + 21.6, // MONITORED_LINE_24V + 22.0, // MONITORED_LINE_24V_REGEN + 1.1875, // MONITORED_LINE_FPGA_REF_V + 2.7, // MONITORED_LINE_PBA_REF_V + 0.9, // MONITORED_LINE_FPGA_VCC_V + 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. + +/// 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_F32_T voltages[ NUM_OF_MONITORED_LINES ]; ///< Monitored voltages and currents. + +// ********** 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 unit. + * @details \b Inputs: none + * @details \b Outputs: Voltages unit initialized. + * @return none + *************************************************************************/ +void initVoltagesMonitor( void ) +{ + U32 i; + + voltagesState = VOLTAGES_INIT_STATE; + voltagesDataPublicationTimerCounter = DATA_PUBLISH_COUNTER_START_COUNT; + + for ( i = 0; i < (U32)NUM_OF_MONITORED_LINES; i++ ) + { + voltages[i].data = 0.0; + voltages[i].ovData = 0.0; + voltages[i].ovInitData = 0.0; + voltages[i].override = OVERRIDE_RESET; + } + + initPersistentAlarm( ALARM_ID_TD_VOLTAGE_OUT_OF_RANGE, VOLTAGES_ALARM_PERSISTENCE_MS, VOLTAGES_ALARM_PERSISTENCE_MS ); + initPersistentAlarm( ALARM_ID_TD_AC_POWER_LOST, POWER_LOSS_VOLTAGE_PERSISTENCE_MS, 0 ); +} + +/*********************************************************************//** + * @brief + * The execVoltagesMonitor function executes the voltages monitor state + * machine. + * @details \b Alarms: ALARM_ID_TD_SOFTWARE_FAULT if voltages state is invalid + * @details \b Inputs: voltagesState + * @details \b 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_TD_SOFTWARE_FAULT, SW_FAULT_ID_VOLTAGES_INVALID_STATE, voltagesState ) + break; + } + + // Publish voltages data on interval + publishVoltagesData(); +} + +/*********************************************************************//** + * @brief + * The handleVoltagesInitState function handles the initialize state + * of the voltages monitor state machine. + * @details \b Inputs: none + * @details \b 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 \b Inputs: converted internal ADC readings + * @details \b 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 ); + voltages[ MONITORED_LINE_5V_LOGIC ].data = getIntADCVoltageConverted( INT_ADC_5V_LOGIC ); + voltages[ MONITORED_LINE_5V_SENSORS ].data = getIntADCVoltageConverted( INT_ADC_5V_SENSORS ); + voltages[ MONITORED_LINE_24V ].data = getIntADCVoltageConverted( INT_ADC_24V_ACTUATORS ); + voltages[ MONITORED_LINE_24V_REGEN ].data = getIntADCVoltageConverted( INT_ADC_24V_ACTUATORS_REG ); + voltages[ MONITORED_LINE_FPGA_REF_V ].data = getIntADCVoltageConverted( INT_ADC_1_25_FPGA_ADC_REF ); + voltages[ MONITORED_LINE_PBA_REF_V ].data = getIntADCVoltageConverted( INT_ADC_PBA_ADC_REF ); + voltages[ MONITORED_LINE_FPGA_VCC_V ].data = getFPGAVcc(); + voltages[ MONITORED_LINE_FPGA_AUX_V ].data = getFPGAVccAux(); + voltages[ MONITORED_LINE_FPGA_PVN_V ].data = getFPGAVpvn(); + + // Check voltage ranges + checkVoltageRanges(); + + return result; +} + +/*********************************************************************//** + * @brief + * The checkVoltageRanges function checks each monitored voltage or current + * against its minimum and maximum range. + * @details \b Alarm: ALARM_ID_TD_VOLTAGE_OUT_OF_RANGE if voltage is out + * of range. + * @details \b Alarm: ALARM_ID_TD_AC_POWER_LOST if AC power has been lost. + * @details \b Inputs: MAX_VOLTAGES[], MIN_VOLTAGES[] + * @details \b Outputs: alarm if out of range + * @return none + *************************************************************************/ +static void checkVoltageRanges( void ) +{ + MONITORED_VOLTAGES_T channel; + MONITORED_VOLTAGES_T channelInAlarm; + BOOL hasPowerBeenLost = getCPLDACPowerLossDetected(); + BOOL isVoltageOutOfRange = FALSE; + F32 volts = 0.0F; + F32 alarmVoltage = 0.0F; + + // Check range + for ( channel = MONITORED_LINE_FIRST_VOLTAGE; channel < NUM_OF_MONITORED_LINES; channel++ ) + { + if ( ( ( isSafetyShutdownActivated() != TRUE ) && ( hasPowerBeenLost != TRUE ) ) || + ( ( channel != MONITORED_LINE_24V ) && ( channel != MONITORED_LINE_24V_REGEN ) ) ) + { +#ifndef _RELEASE_ +// if ( getSoftwareConfigStatus( SW_CONFIG_DISABLE_VOLTAGES_ALARMS ) != SW_CONFIG_ENABLE_VALUE ) +#endif + { + volts = getMonitoredLineLevel( channel ); + if ( ( volts > MAX_VOLTAGES[ channel ] ) || ( volts < MIN_VOLTAGES[ channel] ) ) + { + isVoltageOutOfRange = TRUE; + channelInAlarm = channel; + alarmVoltage = volts; + break; // once a channel is out of range there is no need to continue + } + } + } + } + + // Check the persistence alarm + checkPersistentAlarm ( ALARM_ID_TD_VOLTAGE_OUT_OF_RANGE, isVoltageOutOfRange, channelInAlarm, alarmVoltage ); + + if ( TRUE == hasPowerBeenLost ) + { + TD_OP_MODE_T opMode = getCurrentOperationMode(); + + // Pre-Treatment, Treatment, or Post-Treatment mode + if ( ( MODE_PRET == opMode ) || ( MODE_TREA == opMode ) || ( MODE_POST == opMode ) ) + { + SET_ALARM_WITH_2_F32_DATA( ALARM_ID_TD_AC_POWER_LOST_IN_TREATMENT, getMonitoredLineLevel( MONITORED_LINE_24V ), getMonitoredLineLevel( MONITORED_LINE_24V_REGEN ) ); + } + else + { + SET_ALARM_WITH_2_F32_DATA( ALARM_ID_TD_AC_POWER_LOST, getMonitoredLineLevel( MONITORED_LINE_24V ), getMonitoredLineLevel( MONITORED_LINE_24V_REGEN ) ); + } + + // Reset the alarm clearance counter + resetPersistentAlarmTimer( ALARM_ID_TD_AC_POWER_LOST ); + } + else + { + if ( TRUE == isPersistentAlarmConditionCleared( ALARM_ID_TD_AC_POWER_LOST, hasPowerBeenLost ) ) + { + clearAlarmCondition( ALARM_ID_TD_AC_POWER_LOST ); + + // Just to make sure we are not clearing the AC power lost in treatment alarm until DG powers up and not in + // POST mode, to avoid HD sending commands when DG is not yet ready. + if ( DD_MODE_INIT != getDDOpMode() ) + { + clearAlarmCondition( ALARM_ID_TD_AC_POWER_LOST_IN_TREATMENT ); + } + } + } +} + +/*********************************************************************//** + * @brief + * The getMonitoredLineLevel function gets the current voltage or current + * level for a given signal. + * @details \b Alarm: ALARM_ID_TD_SOFTWARE_FAULT if given signal is invalid. + * @details \b Inputs: voltages[] + * @details \b Outputs: none + * @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; + + if ( signal < NUM_OF_MONITORED_LINES ) + { + result = voltages[ signal ].data; + + if ( OVERRIDE_KEY == voltages[ signal ].override ) + { + result = voltages[ signal ].ovData; + } + } + else + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_SOFTWARE_FAULT, SW_FAULT_ID_VOLTAGES_INVALID_SIGNAL, (U32)signal ) + } + + return result; +} + +/*********************************************************************//** + * @brief + * The publishVoltagesData function publishes voltages monitor data at the + * set interval. + * @details \b Inputs: latest voltages and currents + * @details \b 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.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_TD_VOLTAGES_DATA, COMM_BUFFER_OUT_CAN_TD_BROADCAST, (U08*)&data, sizeof( VOLTAGES_DATA_PAYLOAD_T ) ); + 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 + * @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; + + if ( signal < NUM_OF_MONITORED_LINES ) + { + 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 + * @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; + + if ( signal < NUM_OF_MONITORED_LINES ) + { + if ( TRUE == isTestingActivated() ) + { + result = TRUE; + voltages[ signal ].override = OVERRIDE_RESET; + voltages[ signal ].ovData = voltages[ signal ].ovInitData; + } + } + + return result; +} + +/**@}*/ Index: firmware/App/Monitors/Voltages.h =================================================================== diff -u --- firmware/App/Monitors/Voltages.h (revision 0) +++ firmware/App/Monitors/Voltages.h (revision 8cbddbe34a4ffed5a4d9fac07a065799c5862611) @@ -0,0 +1,84 @@ +/************************************************************************** +* +* Copyright (c) 2024-2024 Diality Inc. - All Rights Reserved. +* +* THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN +* WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. +* +* @file Voltages.h +* +* @author (last) Sean +* @date (last) 07-Aug-2024 +* +* @author (original) Sean +* @date (original) 07-Aug-2024 +* +***************************************************************************/ + +#ifndef __VOLTAGES_H__ +#define __VOLTAGES_H__ + +#include "TDCommon.h" + +/** + * @defgroup Voltages Voltages + * @brief Voltages monitor module. Monitors the various system voltages + * to ensure they are in expected range. + * + * @addtogroup Voltages + * @{ + */ + +// ********** public definitions ********** + +#define MIN_24V_MEASURED_FOR_AC 5.0F ///< Minimum voltage from 24V in order to say we have AC power. + +/// Enumeration of voltages monitored by this module. +typedef enum Voltages +{ + MONITORED_LINE_1_2V = 0, ///< Processor 1.2V + MONITORED_LINE_FIRST_VOLTAGE = MONITORED_LINE_1_2V, ///< First voltage in list + MONITORED_LINE_3_3V, ///< Logic voltage (3.3V) + MONITORED_LINE_5V_LOGIC, ///< Logic voltage (5V) + MONITORED_LINE_5V_SENSORS, ///< Sensors voltage (5V) + MONITORED_LINE_24V, ///< Actuators voltage (24V) + MONITORED_LINE_24V_REGEN, ///< Actuators regen voltage (24V) + MONITORED_LINE_FPGA_REF_V, ///< FPGA ADC reference voltage (1V) + MONITORED_LINE_PBA_REF_V, ///< PBA ADC reference voltage (3V) + MONITORED_LINE_FPGA_VCC_V, ///< FPGA input voltage (3V) + MONITORED_LINE_FPGA_AUX_V, ///< FPGA aux. voltage (3V) + MONITORED_LINE_FPGA_PVN_V, ///< FPGA pvn voltage (1V) + NUM_OF_MONITORED_LINES ///< Number of monitored voltages +} MONITORED_VOLTAGES_T; + +/// Payload record structure for the voltages data message. +typedef struct +{ + F32 adc1_2VProc; ///< Internal ADC channel for 1.2V to processor + F32 adc3_3V; ///< Internal ADC channel for 3.3V + F32 adc5VLogic; ///< Internal ADC channel for 5V to logic + F32 adc5VSensors; ///< Internal ADC channel for 5V to sensors + F32 adc24V; ///< Internal ADC channel for 24V to actuators + F32 adc24VRegen; ///< Internal ADC channel for 24V regen (diode drop) to actuators + F32 adcFpgaAdcRef; ///< Internal ADC channel for FPGA ADC reference voltage + F32 adcPbaRef; ///< Internal ADC channel for reference voltage to PBA ADC channel) + F32 fpgaVcc; ///< FPGA source voltage + F32 fpgaVaux; ///< FPGA aux. voltage + F32 fpgaVpvn; ///< FPGA pvn voltage +} VOLTAGES_DATA_PAYLOAD_T; + +// ********** public function prototypes ********** + +void initVoltagesMonitor( void ); +void execVoltagesMonitor( void ); + +F32 getMonitoredLineLevel( MONITORED_VOLTAGES_T signal ); + +BOOL testSetVoltagesDataPublishIntervalOverride( U32 value ); +BOOL testResetVoltagesDataPublishIntervalOverride( void ); +BOOL testSetLineLevelOverride( U32 signal, F32 value ); +BOOL testResetLineLevelOverride( U32 signal ); + +/**@}*/ + +#endif Index: firmware/App/Services/AlarmMgmtSWFaults.h =================================================================== diff -u -r380b0afc95467d0861ff3aa2cdcde5d5d7ac85e7 -r8cbddbe34a4ffed5a4d9fac07a065799c5862611 --- firmware/App/Services/AlarmMgmtSWFaults.h (.../AlarmMgmtSWFaults.h) (revision 380b0afc95467d0861ff3aa2cdcde5d5d7ac85e7) +++ firmware/App/Services/AlarmMgmtSWFaults.h (.../AlarmMgmtSWFaults.h) (revision 8cbddbe34a4ffed5a4d9fac07a065799c5862611) @@ -109,6 +109,8 @@ SW_FAULT_ID_PRESSURE_SENSOR_INVALID_SENSOR2 = 78, SW_FAULT_ID_PRESSURE_SENSOR_INVALID_SENSOR3 = 79, SW_FAULT_ID_PRESSURE_SENSOR_INVALID_SENSOR4 = 80, + SW_FAULT_ID_VOLTAGES_INVALID_STATE = 81, + SW_FAULT_ID_VOLTAGES_INVALID_SIGNAL = 82, NUM_OF_SW_FAULT_IDS } SW_FAULT_ID_T; Index: firmware/App/Services/DDInterface.c =================================================================== diff -u -r512065f0a0c9ba2c335e8856b790e8448852fc52 -r8cbddbe34a4ffed5a4d9fac07a065799c5862611 --- firmware/App/Services/DDInterface.c (.../DDInterface.c) (revision 512065f0a0c9ba2c335e8856b790e8448852fc52) +++ firmware/App/Services/DDInterface.c (.../DDInterface.c) (revision 8cbddbe34a4ffed5a4d9fac07a065799c5862611) @@ -15,7 +15,6 @@ * ***************************************************************************/ -#include "DDDefs.h" #include "DDInterface.h" #include "Messaging.h" #include "ModeInitPOST.h" Index: firmware/App/Tasks/TaskGeneral.c =================================================================== diff -u -r380b0afc95467d0861ff3aa2cdcde5d5d7ac85e7 -r8cbddbe34a4ffed5a4d9fac07a065799c5862611 --- firmware/App/Tasks/TaskGeneral.c (.../TaskGeneral.c) (revision 380b0afc95467d0861ff3aa2cdcde5d5d7ac85e7) +++ firmware/App/Tasks/TaskGeneral.c (.../TaskGeneral.c) (revision 8cbddbe34a4ffed5a4d9fac07a065799c5862611) @@ -20,6 +20,7 @@ #include "SystemComm.h" #include "SystemCommTD.h" #include "TaskGeneral.h" +#include "Voltages.h" #include "WatchdogMgmt.h" /** @@ -57,9 +58,9 @@ if ( ( TRUE == uiCommunicated() ) || ( ( FALSE == isOnlyCANNode() ) && ( TRUE == isAlarmActive( ALARM_ID_TD_UI_COMM_POST_FAILED ) ) ) ) { -// // Monitor voltages -// execVoltagesMonitor(); -// + // Monitor voltages + execVoltagesMonitor(); + // // Monitor DD // execDDInterfaceMonitor(); // Index: firmware/source/sys_main.c =================================================================== diff -u -raf8485c010085b535a81e9c44426c60eea2535e6 -r8cbddbe34a4ffed5a4d9fac07a065799c5862611 --- firmware/source/sys_main.c (.../sys_main.c) (revision af8485c010085b535a81e9c44426c60eea2535e6) +++ firmware/source/sys_main.c (.../sys_main.c) (revision 8cbddbe34a4ffed5a4d9fac07a065799c5862611) @@ -78,6 +78,7 @@ #include "TaskBG.h" #include "Timers.h" #include "Utilities.h" +#include "Voltages.h" #include "WatchdogMgmt.h" static void initProcessor( void ); @@ -188,6 +189,7 @@ initSystemCommTD(); initWatchdogMgmt(); // Initialize monitors + initVoltagesMonitor(); // Initialize controllers initAlarmLamp(); // Initialize modes