Index: firmware/App/Controllers/AirPump.c =================================================================== diff -u --- firmware/App/Controllers/AirPump.c (revision 0) +++ firmware/App/Controllers/AirPump.c (revision 3a8cf075eb6f0d255f516ac26bac7fbaacfde14a) @@ -0,0 +1,227 @@ +/************************************************************************** +* +* 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 AirPump.c +* +* @author (last) Sean +* @date (last) 17-Sep-2024 +* +* @author (original) Sean +* @date (original) 17-Sep-2024 +* +***************************************************************************/ + +#include "AirPump.h" +#include "AlarmMgmtTD.h" +#include "Messaging.h" +#include "OperationModes.h" +#include "PersistentAlarm.h" +#include "TaskGeneral.h" +#include "Timers.h" + +/** + * @addtogroup AirPump + * @{ + */ + +// ********** private definitions ********** + +#define AIR_PUMP_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Air pump data publish interval. +#define DATA_PUBLISH_COUNTER_START_COUNT 13 ///< Air pump data publish start counter. + +// ********** private data ********** + +static AIR_PUMP_STATE_T currentAirPumpState; ///< Current air pump control state. +static U32 airPumpDataPublicationTimerCounter; ///< Air pump data broadcast timer counter. +static OVERRIDE_U32_T airPumpDataPublishInterval; ///< Air pump data broadcast interval (in ms). + +// ********** private function prototypes ********** + +static AIR_PUMP_STATE_T handleAirPumpStartState( void ); +static AIR_PUMP_STATE_T handleAirPumpOffState( void ); +static AIR_PUMP_STATE_T handleAirPumpOnState ( void ); +static void publishAirPumpData( void ); + +/*********************************************************************//** + * @brief + * The initAirPump function initializes the valve driver. + * @details \b Inputs: none + * @details \b Outputs: currentAirPumpState, currentAirPumpMotorState + * @return none + *************************************************************************/ +void initAirPump(void) +{ + // Initialize driver + initGasLiqXferPumpDriver(); + + // Initialize controller variables + airPumpDataPublicationTimerCounter = DATA_PUBLISH_COUNTER_START_COUNT; + currentAirPumpState = AIR_PUMP_STATE_INIT; + airPumpDataPublishInterval.data = AIR_PUMP_DATA_PUB_INTERVAL; + airPumpDataPublishInterval.ovData = AIR_PUMP_DATA_PUB_INTERVAL; + airPumpDataPublishInterval.ovInitData = 0; + airPumpDataPublishInterval.override = OVERRIDE_RESET; +} + +/*********************************************************************//** + * @brief + * The setAirPumpState function sets the current air pump state machine state. + * @details \b Alarm: ALARM_ID_TD_SOFTWARE_FAULT if invalid state given. + * @details \b Inputs: currentAirPumpState + * @details \b Outputs: currentAirPumpState + * @param state Air pump state to set + * @return none + *************************************************************************/ +void setAirPumpState( AIR_PUMP_STATE_T state ) +{ + if ( state < NUM_OF_AIR_PUMP_STATES ) + { + currentAirPumpState = state; + } + else + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_SOFTWARE_FAULT, SW_FAULT_ID_TD_AIR_PUMP_INVALID_STATE1, (U32)state ) + } +} + +/*********************************************************************//** + * @brief + * The getAirPumpState function returns the current air pump state machine. + * @details \b Inputs: currentAirPumpState + * @details \b Outputs: currentAirPumpState + * @return current state of the air pump state machine. + *************************************************************************/ +AIR_PUMP_STATE_T getAirPumpState( void ) +{ + return currentAirPumpState; +} + +/*********************************************************************//** + * @brief + * The execAirPumpController function executes the air pump state machine. + * @details \b Alarm: ALARM_ID_TD_SOFTWARE_FAULT if the current state is invalid. + * @details \b Inputs: currentAirPumpState + * @details \b Outputs: currentAirPumpState + * @return none + *************************************************************************/ +void execAirPumpController( void ) +{ + switch( currentAirPumpState ) + { + case AIR_PUMP_STATE_INIT: + currentAirPumpState = handleAirPumpStartState(); + break; + + case AIR_PUMP_STATE_OFF: + currentAirPumpState = handleAirPumpOffState(); + break; + + case AIR_PUMP_STATE_ON: + currentAirPumpState = handleAirPumpOnState(); + break; + + default: + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_SOFTWARE_FAULT, SW_FAULT_ID_TD_AIR_PUMP_INVALID_STATE2, (U32)currentAirPumpState ) + break; + } + + publishAirPumpData(); +} + +/*********************************************************************//** + * @brief + * The handleAirPumpStartState function starts the air pump state machine. + * @details \b Inputs: none + * @details \b Outputs: none + * @return next state of the air pump state machine + *************************************************************************/ +static AIR_PUMP_STATE_T handleAirPumpStartState( void ) +{ + AIR_PUMP_STATE_T state = AIR_PUMP_STATE_OFF; + + return state; +} + +/*********************************************************************//** + * @brief + * The handleAirPumpOffState function stops the air pump + * @details \b Inputs: none + * @details \b Outputs: Air pump motor turned off + * @return next state of the air pump state machine + *************************************************************************/ +static AIR_PUMP_STATE_T handleAirPumpOffState( void ) +{ + AIR_PUMP_STATE_T state = AIR_PUMP_STATE_OFF; + + setAirPumpMotorState( AIR_PUMP_MOTOR_OFF ); + + return state; +} + +/*********************************************************************//** + * @brief + * The handleAirPumpOnState function starts the air pump + * @details \b Inputs: none + * @details \b Outputs: Air pump motor turned on. + * @return next state of the air pump state machine + *************************************************************************/ +static AIR_PUMP_STATE_T handleAirPumpOnState( void ) +{ + AIR_PUMP_STATE_T state = AIR_PUMP_STATE_ON; + + setAirPumpMotorState( AIR_PUMP_MOTOR_ON ); + + return state; +} + +/*********************************************************************//** + * @brief + * The publishAirPumpData function constructs and sends the air pump data + * broadcast message. + * @details \b Message \b Sent: MSG_ID_TD_AIR_PUMP_DATA + * @details \b Inputs: airPumpDataPublicationTimerCounter, currentAirPumpState + * @details \b Outputs: airPumpDataPublicationTimerCounter + * @return none + *************************************************************************/ +static void publishAirPumpData( void ) +{ + if (++airPumpDataPublicationTimerCounter >= getU32OverrideValue( &airPumpDataPublishInterval ) ) + { + AIR_PUMP_PAYLOAD_T data; + + data.airPumpStateStatus = getAirPumpState(); + + broadcastData( MSG_ID_TD_AIR_PUMP_DATA, COMM_BUFFER_OUT_CAN_TD_BROADCAST, (U08*)&data, sizeof( AIR_PUMP_PAYLOAD_T ) ); + airPumpDataPublicationTimerCounter = 0; + } +} + + +/************************************************************************* + * TEST SUPPORT FUNCTIONS + *************************************************************************/ + + +/*********************************************************************//** + * @brief + * The testAirPumpDataPublishIntervalOverride function overrides the interval + * at which the TD air pump data is published. + * @details \b Inputs: none + * @details \b Outputs: airPumpDataPublishInterval + * @param message Override message from Dialin which includes the interval + * (in ms) to override the air pump broadcast interval to. + * @return TRUE if override request is successful, FALSE if not + *************************************************************************/ +BOOL testAirPumpDataPublishIntervalOverride( MESSAGE_T *message ) +{ + BOOL result = u32BroadcastIntervalOverride( message, &airPumpDataPublishInterval, TASK_GENERAL_INTERVAL ); + + return result; +} + +/**@}*/ + Index: firmware/App/Controllers/AirPump.h =================================================================== diff -u --- firmware/App/Controllers/AirPump.h (revision 0) +++ firmware/App/Controllers/AirPump.h (revision 3a8cf075eb6f0d255f516ac26bac7fbaacfde14a) @@ -0,0 +1,62 @@ +/************************************************************************** +* +* 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 AirPump.h +* +* @author (last) Sean +* @date (last) 17-Sep-2024 +* +* @author (original) Sean +* @date (original) 17-Sep-2024 +* +***************************************************************************/ + +#ifndef __AIR_PUMP_H__ +#define __AIR_PUMP_H__ + +// ********** public definitions ********** + +#include "TDCommon.h" +#include "GLXferPump.h" + +/** + * @defgroup AirPump AirPump + * @brief Air Pump controller unit. Provides higher level control of the air pump. + * + * @addtogroup AirPump + * @{ + */ + +// ********** public definitions ********** + +/// Payload record structure for air pump data broadcast message +typedef struct +{ + U32 airPumpStateStatus; ///< Air Pump state status +} AIR_PUMP_PAYLOAD_T; + +/// Enumeration of air pump states. +typedef enum AirPumpControllerStates +{ + AIR_PUMP_STATE_INIT = 0, ///< Air Pump Initialize state + AIR_PUMP_STATE_OFF, ///< Air Pump Off state + AIR_PUMP_STATE_ON, ///< Air Pump On state + NUM_OF_AIR_PUMP_STATES, ///< Number of air pump states +} AIR_PUMP_STATE_T; + +// ********** public function prototypes ********** + +void initAirPump(void); +void execAirPumpController(void); +void setAirPumpState( AIR_PUMP_STATE_T state ); +AIR_PUMP_STATE_T getAirPumpState( void ); + +BOOL testAirPumpDataPublishIntervalOverride( MESSAGE_T *message ); + +/**@}*/ + +#endif Index: firmware/App/Controllers/AlarmAudio.c =================================================================== diff -u -rabba5986eed8c2f702ca1ed70afd735a7f31db2a -r3a8cf075eb6f0d255f516ac26bac7fbaacfde14a --- firmware/App/Controllers/AlarmAudio.c (.../AlarmAudio.c) (revision abba5986eed8c2f702ca1ed70afd735a7f31db2a) +++ firmware/App/Controllers/AlarmAudio.c (.../AlarmAudio.c) (revision 3a8cf075eb6f0d255f516ac26bac7fbaacfde14a) @@ -384,184 +384,78 @@ alarmAudioSelfTestState = ALARM_AUDIO_SELF_TEST_STATE_START; } -/*********************************************************************//** - * @brief - * The testSetAlarmAudioVolumeLevelOverride function sets the override for the - * alarm audio volume. - * @details \b Inputs: none - * @details \b Outputs: alarmAudioVolumeLevel - * @param volume Volume level (1..5) to set override to for alarm audio - * @return TRUE if override is successful, FALSE if not + +/************************************************************************* + * TEST SUPPORT FUNCTIONS *************************************************************************/ -BOOL testSetAlarmAudioVolumeLevelOverride( U32 volume ) -{ - BOOL result = FALSE; - if ( TRUE == isTestingActivated() ) - { - result = TRUE; - alarmAudioVolumeLevel.ovData = MAX_ALARM_VOLUME_LEVEL - volume; - alarmAudioVolumeLevel.override = OVERRIDE_KEY; - } - return result; -} - /*********************************************************************//** * @brief - * The testResetAlarmAudioVolumeLevelOverride function resets the override for - * the alarm audio volume. + * The testAlarmAudioVolumeLevelOverride function sets the override for the + * alarm audio volume. * @details \b Inputs: none * @details \b Outputs: alarmAudioVolumeLevel - * @return TRUE if override reset is successful, FALSE if not + * @param message Override message from Dialin which includes the alarm + * audio volume level to override to. + * @return TRUE if override is successful, FALSE if not *************************************************************************/ -BOOL testResetAlarmAudioVolumeLevelOverride( void ) +BOOL testAlarmAudioVolumeLevelOverride( MESSAGE_T *message ) { - BOOL result = FALSE; + BOOL result = u32Override( message, &alarmAudioVolumeLevel, 0, MAX_ALARM_VOLUME_LEVEL - 1 ); - if ( TRUE == isTestingActivated() ) - { - result = TRUE; - alarmAudioVolumeLevel.override = OVERRIDE_RESET; - alarmAudioVolumeLevel.ovData = alarmAudioVolumeLevel.ovInitData; - } - return result; } /*********************************************************************//** * @brief - * The testSetPrimaryAlarmAudioCurrentHGOverride function sets the override + * The testPrimaryAlarmAudioCurrentHGOverride function sets the override * for the alarm audio current (high gain) in mA. * @details \b Inputs: none * @details \b Outputs: alarmPrimaryAudioCurrentHG - * @param mA The milliamps measured from high gain channel of primary alarm audio + * @param message Override message from Dialin which includes the primary + * alarm audio current hgih gain (in mA) to override to. * @return TRUE if override is successful, FALSE if not *************************************************************************/ -BOOL testSetPrimaryAlarmAudioCurrentHGOverride( F32 mA ) +BOOL testPrimaryAlarmAudioCurrentHGOverride( MESSAGE_T *message ) { - BOOL result = FALSE; + BOOL result = f32Override( message, &alarmPrimaryAudioCurrentHG ); - if ( TRUE == isTestingActivated() ) - { - result = TRUE; - alarmPrimaryAudioCurrentHG.ovData = mA; - alarmPrimaryAudioCurrentHG.override = OVERRIDE_KEY; - } - return result; } /*********************************************************************//** * @brief - * The testResetPrimaryAlarmAudioCurrentHGOverride function resets the override - * for the alarm audio current (high gain). - * @details \b Inputs: none - * @details \b Outputs: alarmPrimaryAudioCurrentHG - * @return TRUE if override reset is successful, FALSE if not - *************************************************************************/ -BOOL testResetPrimaryAlarmAudioCurrentHGOverride( void ) -{ - BOOL result = FALSE; - - if ( TRUE == isTestingActivated() ) - { - result = TRUE; - alarmPrimaryAudioCurrentHG.override = OVERRIDE_RESET; - alarmPrimaryAudioCurrentHG.ovData = alarmPrimaryAudioCurrentHG.ovInitData; - } - - return result; -} - -/*********************************************************************//** - * @brief - * The testSetPrimaryAlarmAudioCurrentLGOverride function sets the override + * The testPrimaryAlarmAudioCurrentLGOverride function sets the override * for the alarm audio current (low gain) in mA. * @details \b Inputs: none * @details \b Outputs: alarmPrimaryAudioCurrentLG - * @param mA The milliamps measured from low gain channel of primary alarm audio + * @param message Override message from Dialin which includes the primary + * alarm audio current low gain (in mA) to override to. * @return TRUE if override is successful, FALSE if not *************************************************************************/ -BOOL testSetPrimaryAlarmAudioCurrentLGOverride( F32 mA ) +BOOL testPrimaryAlarmAudioCurrentLGOverride( MESSAGE_T *message ) { - BOOL result = FALSE; + BOOL result = f32Override( message, &alarmPrimaryAudioCurrentLG ); - if ( TRUE == isTestingActivated() ) - { - result = TRUE; - alarmPrimaryAudioCurrentLG.ovData = mA; - alarmPrimaryAudioCurrentLG.override = OVERRIDE_KEY; - } - return result; } /*********************************************************************//** * @brief - * The testResetPrimaryAlarmAudioCurrentLGOverride function resets the override - * for the alarm audio current (low gain). - * @details \b Inputs: none - * @details \b Outputs: alarmPrimaryAudioCurrentLG - * @return TRUE if override reset is successful, FALSE if not - *************************************************************************/ -BOOL testResetPrimaryAlarmAudioCurrentLGOverride( void ) -{ - BOOL result = FALSE; - - if ( TRUE == isTestingActivated() ) - { - result = TRUE; - alarmPrimaryAudioCurrentLG.override = OVERRIDE_RESET; - alarmPrimaryAudioCurrentLG.ovData = alarmPrimaryAudioCurrentLG.ovInitData; - } - - return result; -} - -/*********************************************************************//** - * @brief - * The testSetBackupAlarmAudioCurrentOverride function sets the override for + * The testBackupAlarmAudioCurrentOverride function sets the override for * the alarm audio current (backup) in mA. * @details \b Inputs: none * @details \b Outputs: alarmBackupAudioCurrent - * @param mA The milliamps measured from backup channel of primary alarm audio + * @param message Override message from Dialin which includes the backup + * alarm audio current (in mA) to override to. * @return TRUE if override is successful, FALSE if not *************************************************************************/ -BOOL testSetBackupAlarmAudioCurrentOverride( F32 mA ) +BOOL testBackupAlarmAudioCurrentOverride( MESSAGE_T *message ) { - BOOL result = FALSE; + BOOL result = f32Override( message, &alarmBackupAudioCurrent ); - if ( TRUE == isTestingActivated() ) - { - result = TRUE; - alarmBackupAudioCurrent.ovData = mA; - alarmBackupAudioCurrent.override = OVERRIDE_KEY; - } - return result; } -/*********************************************************************//** - * @brief - * The testResetBackupAlarmAudioCurrentOverride function resets the override - * for the alarm audio current (backup). - * @details \b Inputs: none - * @details \b Outputs: alarmBackupAudioCurrent - * @return TRUE if override reset is successful, FALSE if not - *************************************************************************/ -BOOL testResetBackupAlarmAudioCurrentOverride( void ) -{ - BOOL result = FALSE; - - if ( TRUE == isTestingActivated() ) - { - result = TRUE; - alarmBackupAudioCurrent.override = OVERRIDE_RESET; - alarmBackupAudioCurrent.ovData = alarmBackupAudioCurrent.ovInitData; - } - - return result; -} - /**@}*/ Index: firmware/App/Controllers/AlarmAudio.h =================================================================== diff -u -rabba5986eed8c2f702ca1ed70afd735a7f31db2a -r3a8cf075eb6f0d255f516ac26bac7fbaacfde14a --- firmware/App/Controllers/AlarmAudio.h (.../AlarmAudio.h) (revision abba5986eed8c2f702ca1ed70afd735a7f31db2a) +++ firmware/App/Controllers/AlarmAudio.h (.../AlarmAudio.h) (revision 3a8cf075eb6f0d255f516ac26bac7fbaacfde14a) @@ -19,6 +19,7 @@ #define __ALARM_AUDIO_H__ #include "TDCommon.h" +#include "MessageSupport.h" /** * @defgroup AlarmAudio AlarmAudio @@ -53,15 +54,11 @@ SELF_TEST_STATUS_T execAlarmAudioSelfTest( void ); void resetAlarmAudioPOSTState( void ); -BOOL testSetAlarmAudioVolumeLevelOverride( U32 volume ); -BOOL testResetAlarmAudioVolumeLevelOverride( void ); -BOOL testSetPrimaryAlarmAudioCurrentHGOverride( F32 mA ); -BOOL testResetPrimaryAlarmAudioCurrentHGOverride( void ); -BOOL testSetPrimaryAlarmAudioCurrentLGOverride( F32 mA ); -BOOL testResetPrimaryAlarmAudioCurrentLGOverride( void ); -BOOL testSetBackupAlarmAudioCurrentOverride( F32 mA ); -BOOL testResetBackupAlarmAudioCurrentOverride( void ); - +BOOL testAlarmAudioVolumeLevelOverride( MESSAGE_T *message ); +BOOL testPrimaryAlarmAudioCurrentHGOverride( MESSAGE_T *message ); +BOOL testPrimaryAlarmAudioCurrentLGOverride( MESSAGE_T *message ); +BOOL testBackupAlarmAudioCurrentOverride( MESSAGE_T *message ); + /**@}*/ #endif Index: firmware/App/Controllers/AlarmLamp.c =================================================================== diff -u -r380b0afc95467d0861ff3aa2cdcde5d5d7ac85e7 -r3a8cf075eb6f0d255f516ac26bac7fbaacfde14a --- firmware/App/Controllers/AlarmLamp.c (.../AlarmLamp.c) (revision 380b0afc95467d0861ff3aa2cdcde5d5d7ac85e7) +++ firmware/App/Controllers/AlarmLamp.c (.../AlarmLamp.c) (revision 3a8cf075eb6f0d255f516ac26bac7fbaacfde14a) @@ -325,47 +325,19 @@ /*********************************************************************//** * @brief - * The testSetCurrentLampPatternOverride function overrides the current + * The testAlarmLampPatternOverride function overrides the current * alarm lamp pattern with a given pattern. * @details \b Inputs: none * @details \b Outputs: currentLampPattern - * @param value Value to override the alarm lamp pattern to + * @param message Override message from Dialin which includes the alarm + * lamp pattern to override to. * @return TRUE if override successful, FALSE if not *************************************************************************/ -BOOL testSetCurrentLampPatternOverride( U32 value ) +BOOL testAlarmLampPatternOverride( MESSAGE_T *message ) { - BOOL result = FALSE; + BOOL result = u32Override( message, ¤tLampPattern, 0, NUM_OF_LAMP_PATTERNS - 1 ); - if ( TRUE == isTestingActivated() ) - { - result = TRUE; - currentLampPattern.ovData = value; - currentLampPattern.override = OVERRIDE_KEY; - } - return result; } -/*********************************************************************//** - * @brief - * The testResetCurrentLampPatternOverride function resets the override of the - * alarm lamp pattern. - * @details \b Inputs: none - * @details \b Outputs: currentLampPattern - * @return TRUE if override reset successful, FALSE if not - *************************************************************************/ -BOOL testResetCurrentLampPatternOverride( void ) -{ - BOOL result = FALSE; - - if ( TRUE == isTestingActivated() ) - { - result = TRUE; - currentLampPattern.override = OVERRIDE_RESET; - currentLampPattern.ovData = currentLampPattern.ovInitData; - } - - return result; -} - /**@}*/ Index: firmware/App/Controllers/AlarmLamp.h =================================================================== diff -u -r380b0afc95467d0861ff3aa2cdcde5d5d7ac85e7 -r3a8cf075eb6f0d255f516ac26bac7fbaacfde14a --- firmware/App/Controllers/AlarmLamp.h (.../AlarmLamp.h) (revision 380b0afc95467d0861ff3aa2cdcde5d5d7ac85e7) +++ firmware/App/Controllers/AlarmLamp.h (.../AlarmLamp.h) (revision 3a8cf075eb6f0d255f516ac26bac7fbaacfde14a) @@ -19,6 +19,7 @@ #define __ALARM_LAMP_H__ #include "TDCommon.h" +#include "MessageSupport.h" /** * @defgroup AlarmLamp AlarmLamp @@ -57,10 +58,9 @@ SELF_TEST_STATUS_T execAlarmLampTest( void ); void resetAlarmLampPOSTState( void ); + +BOOL testAlarmLampPatternOverride( MESSAGE_T *message ); -BOOL testSetCurrentLampPatternOverride( U32 value ); -BOOL testResetCurrentLampPatternOverride( void ); - /**@}*/ #endif Index: firmware/App/Drivers/BubbleDetector.c =================================================================== diff -u -r0c8ae7b952186d912c77d8c2cfb7dad809fa5225 -r3a8cf075eb6f0d255f516ac26bac7fbaacfde14a --- firmware/App/Drivers/BubbleDetector.c (.../BubbleDetector.c) (revision 0c8ae7b952186d912c77d8c2cfb7dad809fa5225) +++ firmware/App/Drivers/BubbleDetector.c (.../BubbleDetector.c) (revision 3a8cf075eb6f0d255f516ac26bac7fbaacfde14a) @@ -115,38 +115,8 @@ *************************************************************************/ BOOL testBubbleDetectOverride( MESSAGE_T *message ) { - BOOL result = FALSE; - TEST_OVERRIDE_ARRAY_PAYLOAD_T override; - OVERRIDE_TYPE_T ovType = getOverrideArrayPayloadFromMessage( message, &override ); + BOOL result = u32ArrayOverride( message, ¤tBubbleState[0], NUM_OF_BUBBLE_DETECTORS - 1, 0, NUM_OF_BUBBLE_DETECTION_STATES - 1 ); - // Verify tester has logged in with TD and override type is valid - if ( ( TRUE == isTestingActivated() ) && ( ovType != OVERRIDE_INVALID ) && ( ovType < NUM_OF_OVERRIDE_TYPES ) ) - { - U32 sensor = override.index; - - // Verify bubble detector index of override - if ( sensor < NUM_OF_BUBBLE_DETECTORS ) - { - if ( OVERRIDE_OVERRIDE == ovType ) - { - U32 value = override.state.u32; - - if ( value < NUM_OF_BUBBLE_DETECTION_STATES ) - { - result = TRUE; - currentBubbleState[ sensor ].ovData = value; - currentBubbleState[ sensor ].override = OVERRIDE_KEY; - } - } - else - { - result = TRUE; - currentBubbleState[ sensor ].override = OVERRIDE_RESET; - currentBubbleState[ sensor ].ovData = currentBubbleState[ sensor ].ovInitData; - } - } - } - return result; } Index: firmware/App/Drivers/GLXferPump.c =================================================================== diff -u --- firmware/App/Drivers/GLXferPump.c (revision 0) +++ firmware/App/Drivers/GLXferPump.c (revision 3a8cf075eb6f0d255f516ac26bac7fbaacfde14a) @@ -0,0 +1,127 @@ +/************************************************************************** +* +* 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 GLXferPump.c +* +* @author (last) Sean +* @date (last) 17-Sep-2024 +* +* @author (original) Sean +* @date (original) 17-Sep-2024 +* +***************************************************************************/ + +#include "AlarmMgmtTD.h" +#include "GLXferPump.h" +#include "GPIO.h" +#include "Messaging.h" + +/** + * @addtogroup GLXferPump + * @{ + */ + +// ********** private definitions ********** + +// ********** private data ********** + +static AIR_PUMP_MOTOR_STATE_T currentAirPumpMotorState; ///< Current air pump motor state (on/off). + +// ********** private function prototypes ********** + +/*********************************************************************//** + * @brief + * The initGasLiqXferPumpDriver function initializes the gas/liquid transfer + * pump driver unit. + * @details \b Inputs: none + * @details \b Outputs: currentAirPumpMotorState + * @return none + *************************************************************************/ +void initGasLiqXferPumpDriver(void) +{ + currentAirPumpMotorState = AIR_PUMP_MOTOR_OFF; + setAirPumpMotorSignal( (PIN_SIGNAL_STATE_T)currentAirPumpMotorState ); +} + +/*********************************************************************//** + * @brief + * The setAirPumpMotorState function sets the air pump motor state to on or off. + * @details \b Alarm: ALARM_ID_TD_SOFTWARE_FAULT if invalid state given. + * @details \b Inputs: none + * @details \b Outputs: currentAirPumpMotorState + * @param state State to set the air pump motor (on/off). + * @return none. + *************************************************************************/ +void setAirPumpMotorState( AIR_PUMP_MOTOR_STATE_T state ) +{ + if ( state < NUM_OF_AIR_PUMP_MOTOR_STATES ) + { + // if state is changing, set the air pump to the given on/off state and send event + if ( state != currentAirPumpMotorState ) + { + SEND_EVENT_WITH_2_U32_DATA( TD_EVENT_AIR_PUMP_ON_OFF, (U32)currentAirPumpMotorState, (U32)state ); + setAirPumpMotorSignal( (PIN_SIGNAL_STATE_T)state ); + currentAirPumpMotorState = state; + } + } + else + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_SOFTWARE_FAULT, SW_FAULT_ID_AIR_PUMP_INVALID_MOTOR_STATE_SELECTED, (U32)state ) + } +} + +/*********************************************************************//** + * @brief + * The getAirPumpMotorState function gets the current state of the air pump + * motor. + * @details \b Inputs: currentAirPumpMotorState + * @details \b Outputs: none + * @return Current on/off state of the air pump motor. + *************************************************************************/ +AIR_PUMP_MOTOR_STATE_T getAirPumpMotorState( void ) +{ + return currentAirPumpMotorState; +} + + +/************************************************************************* + * TEST SUPPORT FUNCTIONS + *************************************************************************/ + + +/*********************************************************************//** + * @brief + * The testSetAirPump function sets the air pump to a given state (on/off). + * @details \b Inputs: none + * @details \b Outputs: currentAirPumpState + * @param message set message from Dialin which includes the state to set + * the air pump to. + * @return TRUE if set request is successful, FALSE if not + *************************************************************************/ +BOOL testSetAirPump( MESSAGE_T *message ) +{ + BOOL result = FALSE; + + // Verify tester has logged in with TD and override type is valid + if ( TRUE == isTestingActivated() ) + { + U32 state; + + memcpy( &state, message->payload, sizeof(U32) ); + result = TRUE; + if ( state < NUM_OF_AIR_PUMP_MOTOR_STATES ) + { + setAirPumpMotorState( (AIR_PUMP_MOTOR_STATE_T)state ); + result = TRUE; + } + } + + return result; +} + +/**@}*/ + Index: firmware/App/Drivers/GLXferPump.h =================================================================== diff -u --- firmware/App/Drivers/GLXferPump.h (revision 0) +++ firmware/App/Drivers/GLXferPump.h (revision 3a8cf075eb6f0d255f516ac26bac7fbaacfde14a) @@ -0,0 +1,54 @@ +/************************************************************************** +* +* 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 GLXferPump.h +* +* @author (last) Sean +* @date (last) 17-Sep-2024 +* +* @author (original) Sean +* @date (original) 17-Sep-2024 +* +***************************************************************************/ + +#ifndef __GAS_LIQ_XFER_PUMP_H__ +#define __GAS_LIQ_XFER_PUMP_H__ + +// ********** public definitions ********** + +#include "TDCommon.h" + +/** + * @defgroup GLXferPump GLXferPump + * @brief Gas/Liquid Transfer Pump driver unit. Provides low level functions + * to control a gas/liquid transfer pump. + * + * @addtogroup GLXferPump + * @{ + */ + +// ********** public definitions ********** + +/// Enumeration of air pump motor states. +typedef enum AirPumpMotorStates +{ + AIR_PUMP_MOTOR_OFF = 0, ///< Air Pump Off. + AIR_PUMP_MOTOR_ON, ///< Air Pump On. + NUM_OF_AIR_PUMP_MOTOR_STATES, ///< Number of air pump motor states. +} AIR_PUMP_MOTOR_STATE_T; + +// ********** public function prototypes ********** + +void initGasLiqXferPumpDriver(void); +void setAirPumpMotorState( AIR_PUMP_MOTOR_STATE_T state ); +AIR_PUMP_MOTOR_STATE_T getAirPumpMotorState( void ); + +BOOL testSetAirPump( MESSAGE_T *message ); + +/**@}*/ + +#endif Index: firmware/App/Drivers/GPIO.c =================================================================== diff -u -r8cbddbe34a4ffed5a4d9fac07a065799c5862611 -r3a8cf075eb6f0d255f516ac26bac7fbaacfde14a --- firmware/App/Drivers/GPIO.c (.../GPIO.c) (revision 8cbddbe34a4ffed5a4d9fac07a065799c5862611) +++ firmware/App/Drivers/GPIO.c (.../GPIO.c) (revision 3a8cf075eb6f0d255f516ac26bac7fbaacfde14a) @@ -17,6 +17,7 @@ #include "gio.h" #include "mibspi.h" +#include "reg_het.h" #include "GPIO.h" @@ -49,6 +50,9 @@ #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 +// hetPORT1 pin assignments +#define AIR_PUMP_GPIO_PIN 4U ///< GPIO pin ID on hetPORT1 for air pump motor state. + // 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. @@ -354,4 +358,18 @@ CLR_BACKUP_AUDIO_ENABLE() } +/*********************************************************************//** + * @brief + * The setAirPumpMotorSignal function sets the air pump output signal to + * the given pin level. + * @details \b Inputs: none + * @details \b Outputs: Air pump output signal set to given level. + * @param signal Signal level to set the air pump output to + * @return none + *************************************************************************/ +void setAirPumpMotorSignal( PIN_SIGNAL_STATE_T signal ) +{ + gioSetBit( hetPORT1, AIR_PUMP_GPIO_PIN, (U32)signal ); +} + /**@}*/ Index: firmware/App/Drivers/GPIO.h =================================================================== diff -u -r380b0afc95467d0861ff3aa2cdcde5d5d7ac85e7 -r3a8cf075eb6f0d255f516ac26bac7fbaacfde14a --- firmware/App/Drivers/GPIO.h (.../GPIO.h) (revision 380b0afc95467d0861ff3aa2cdcde5d5d7ac85e7) +++ firmware/App/Drivers/GPIO.h (.../GPIO.h) (revision 3a8cf075eb6f0d255f516ac26bac7fbaacfde14a) @@ -58,6 +58,8 @@ void setAlarmBuzzerSignal( void ); void clrAlarmBuzzerSignal( void ); +void setAirPumpMotorSignal( PIN_SIGNAL_STATE_T signal ); + /**@}*/ #endif Index: firmware/App/Drivers/PressureSensor.c =================================================================== diff -u -r0ac32b16df2334a48c964d976ba0c846830a5f4c -r3a8cf075eb6f0d255f516ac26bac7fbaacfde14a --- firmware/App/Drivers/PressureSensor.c (.../PressureSensor.c) (revision 0ac32b16df2334a48c964d976ba0c846830a5f4c) +++ firmware/App/Drivers/PressureSensor.c (.../PressureSensor.c) (revision 3a8cf075eb6f0d255f516ac26bac7fbaacfde14a) @@ -273,35 +273,8 @@ *************************************************************************/ BOOL testPressureSensorOverride( MESSAGE_T *message ) { - BOOL result = FALSE; - TEST_OVERRIDE_ARRAY_PAYLOAD_T override; - OVERRIDE_TYPE_T ovType = getOverrideArrayPayloadFromMessage( message, &override ); + BOOL result = f32ArrayOverride( message, ¤tPressureReadings[0], NUM_OF_PRESSURE_SENSORS - 1 ); - // Verify tester has logged in with TD and override type is valid - if ( ( TRUE == isTestingActivated() ) && ( ovType != OVERRIDE_INVALID ) && ( ovType < NUM_OF_OVERRIDE_TYPES ) ) - { - U32 sensor = override.index; - - // Verify pressure sensor index of override - if ( sensor < NUM_OF_PRESSURE_SENSORS ) - { - result = TRUE; - - if ( OVERRIDE_OVERRIDE == ovType ) - { - F32 value = override.state.f32; - - currentPressureReadings[ sensor ].ovData = value; - currentPressureReadings[ sensor ].override = OVERRIDE_KEY; - } - else - { - currentPressureReadings[ sensor ].override = OVERRIDE_RESET; - currentPressureReadings[ sensor ].ovData = currentPressureReadings[ sensor ].ovInitData; - } - } - } - return result; } Index: firmware/App/Modes/ModeStandby.c =================================================================== diff -u -r380b0afc95467d0861ff3aa2cdcde5d5d7ac85e7 -r3a8cf075eb6f0d255f516ac26bac7fbaacfde14a --- firmware/App/Modes/ModeStandby.c (.../ModeStandby.c) (revision 380b0afc95467d0861ff3aa2cdcde5d5d7ac85e7) +++ firmware/App/Modes/ModeStandby.c (.../ModeStandby.c) (revision 3a8cf075eb6f0d255f516ac26bac7fbaacfde14a) @@ -137,7 +137,7 @@ HD_STANDBY_STATE_T state = STANDBY_WAIT_FOR_TREATMENT_STATE; // Wait for door to be closed so we can home actuators -// if ( STATE_CLOSED == getSwitchStatus( FRONT_DOOR ) ) +// if ( STATE_CLOSED == getSwitchState( FRONT_DOOR ) ) // { // // If we haven't already initiated homing of actuators, initiate now // if ( homingInitiated != TRUE ) Index: firmware/App/Monitors/Bubbles.c =================================================================== diff -u -r0c8ae7b952186d912c77d8c2cfb7dad809fa5225 -r3a8cf075eb6f0d255f516ac26bac7fbaacfde14a --- firmware/App/Monitors/Bubbles.c (.../Bubbles.c) (revision 0c8ae7b952186d912c77d8c2cfb7dad809fa5225) +++ firmware/App/Monitors/Bubbles.c (.../Bubbles.c) (revision 3a8cf075eb6f0d255f516ac26bac7fbaacfde14a) @@ -330,33 +330,8 @@ *************************************************************************/ BOOL testBubblesDataPublishIntervalOverride( MESSAGE_T *message ) { - BOOL result = FALSE; - TEST_OVERRIDE_PAYLOAD_T override; - OVERRIDE_TYPE_T ovType = getOverridePayloadFromMessage( message, &override ); + BOOL result = u32BroadcastIntervalOverride( message, &bubblesDataPublishInterval, TASK_PRIORITY_INTERVAL ); - // Verify tester has logged in with TD and override type is valid - if ( ( TRUE == isTestingActivated() ) && ( ovType != OVERRIDE_INVALID ) && ( ovType < NUM_OF_OVERRIDE_TYPES ) ) - { - if ( OVERRIDE_OVERRIDE == ovType ) - { - U32 value = override.state.u32; - U32 intvl = value / TASK_PRIORITY_INTERVAL; - - if ( intvl > 0 ) - { - result = TRUE; - bubblesDataPublishInterval.ovData = intvl; - bubblesDataPublishInterval.override = OVERRIDE_KEY; - } - } - else - { - result = TRUE; - bubblesDataPublishInterval.override = OVERRIDE_RESET; - bubblesDataPublishInterval.ovData = bubblesDataPublishInterval.ovInitData; - } - } - return result; } Index: firmware/App/Monitors/Buttons.c =================================================================== diff -u --- firmware/App/Monitors/Buttons.c (revision 0) +++ firmware/App/Monitors/Buttons.c (revision 3a8cf075eb6f0d255f516ac26bac7fbaacfde14a) @@ -0,0 +1,544 @@ +/************************************************************************** +* +* 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 Buttons.c +* +* @author (last) Sean +* @date (last) 18-Sep-2024 +* +* @author (original) Sean +* @date (original) 18-Sep-2024 +* +***************************************************************************/ + +#include "Buttons.h" +#include "CpldInterface.h" +#include "Messaging.h" +//#include "NVDataMgmt.h" +#include "OperationModes.h" +#include "TaskPriority.h" +#include "Timers.h" + +/** + * @addtogroup Buttons + * @{ + */ + +// ********** private definitions ********** + +/// Enumeration of button self-test states. +typedef enum Button_Self_Test_States +{ + BUTTON_SELF_TEST_STATE_START = 0, ///< Button self-test start state + BUTTON_SELF_TEST_STATE_IN_PROGRESS, ///< Button self-test in progress state + BUTTON_SELF_TEST_STATE_COMPLETE, ///< Button self-test completed state + NUM_OF_BUTTON_SELF_TEST_STATES ///< Number of button self-test states +} BUTTON_SELF_TEST_STATE_T; + +/// Enumeration of hardware buttons. +typedef enum Buttons +{ + BUTTON_OFF = 0, ///< Off button + BUTTON_STOP, ///< Stop button + NUM_OF_BUTTONS ///< Number of hardware buttons +} BUTTON_T; + +/// Enumeration of off button commands to UI. +typedef enum OffButtonCmdsToUI +{ + OFF_BUTTON_CMD_PROMPT_USER_TO_CONFIRM = 0, ///< Prompt user to confirm power off command + OFF_BUTTON_CMD_CANCEL_USER_CONFIRM_PROMPT, ///< Cancel user confirm prompt command + OFF_BUTTON_CMD_REJECT_USER_OFF_REQUEST, ///< Reject user off request command + NUM_OF_OFF_BUTTON_CMDS ///< Number of off button commands to UI +} OFF_BUTTON_CMD_T; + +/// Enumeration of off button responses from UI. +typedef enum OffButtonRspsFromUI +{ + OFF_BUTTON_RSP_USER_REQUESTS_POWER_OFF = 0, ///< User requests power off response + OFF_BUTTON_RSP_USER_CONFIRMS_POWER_OFF, ///< User confirms power off response + OFF_BUTTON_RSP_USER_REJECTS_POWER_OFF, ///< User rejects power off response + NUM_OF_OFF_BUTTON_RSPS ///< Number of off button responses from UI +} OFF_BUTTON_RSP_T; + +#define OFF_REQUEST_PULSE_COUNT 4 ///< Number of edges for power off sequence on power off output signal. +#define OFF_REQUEST_PULSE_INTVL_MS 50 ///< Duration (in ms) of power off sequence steps. +#define OFF_REQUEST_DELAY_TIME_MS 2000 ///< Duration (in ms) of delay before power off sequence is initiated to provide sub-systems time to wrap things up. +#define STOP_BUTTON_PENDING_TIMEOUT_MS 500 ///< Timeout period (in ms) for stop button press to be consumed. +#define STUCK_BUTTON_TIMEOUT_MS 1000 ///< Duration (in ms) that a button must be in pressed state before considering it stuck at power up. +#define OFF_REQUEST_EXPIRATION_TIME_MS (1000 * 60) ///< Time (in ms) that the user is given to confirm a power off request before it expires. + +#define USER_CONFIRMED 1 ///< User response code to power off confirmation prompt that indicates confirmation. +#define USER_REJECTED 0 ///< User response code to power off confirmation prompt that indicates rejection. + +// ********** private data ********** + +static OVERRIDE_U32_T dataOffButtonState; ///< Current off button state (overrideable). +static BUTTON_STATE_T prevOffButtonState; ///< Previous state of off button. +static BOOL offRequestAwaitingUserConfirmation = FALSE; ///< Flag indicates whether a power off request is pending user confirmation. +static U32 offRequestPendingTimer; ///< Timer counter for pending power off request. +static BOOL offButtonPressPending; ///< Flag indicates whether a confirmed power off request is pending execution. +static U32 offRequestPulseCount; ///< Power off sequence step counter. +static U32 offRequestPulseTimer; ///< Power off sequence step timer counter. +static U32 offRequestDelayTimer; ///< Power off sequence delay timer counter. + +static OVERRIDE_U32_T dataStopButtonState; ///< Current stop button state (overrideable). +static BUTTON_STATE_T prevStopButtonState; ///< Previous state of stop button. +static BOOL stopButtonPressPending = FALSE; ///< Flag indicates a stop button press is pending consumption. +static U32 stopButtonPendingTimer; ///< Timer counter for pending stop button press. + +static BUTTON_SELF_TEST_STATE_T buttonSelfTestState; ///< Current state of button self-test. +static U32 buttonSelfTestTimerCount; ///< Timer counter for button self-test states. + +// ********** private function prototypes ********** + +static void handleOffButtonProcessing( void ); +static void handleStopButtonProcessing( void ); +static BOOL isCurrentOpModeOkToTurnOff( void ); + +/*********************************************************************//** + * @brief + * The initButtons function initializes the Buttons unit. + * @details \b Inputs: none + * @details \b Outputs: Buttons monitor unit initialized. + * @return none + *************************************************************************/ +void initButtons( void ) +{ + prevOffButtonState = BUTTON_STATE_RELEASED; + offRequestAwaitingUserConfirmation = FALSE; + offRequestPendingTimer = 0; + offButtonPressPending = FALSE; + offRequestPulseCount = 0; + offRequestPulseTimer = 0; + offRequestDelayTimer = 0; + + prevStopButtonState = BUTTON_STATE_RELEASED; + stopButtonPressPending = FALSE; + stopButtonPendingTimer = 0; + + buttonSelfTestState = BUTTON_SELF_TEST_STATE_START; + buttonSelfTestTimerCount = 0; + + dataOffButtonState.data = BUTTON_STATE_RELEASED; + dataOffButtonState.ovData = BUTTON_STATE_PRESSED; + dataOffButtonState.ovInitData = BUTTON_STATE_PRESSED; + dataOffButtonState.override = OVERRIDE_RESET; + dataStopButtonState.data = BUTTON_STATE_RELEASED; + dataStopButtonState.ovData = BUTTON_STATE_PRESSED; + dataStopButtonState.ovInitData = BUTTON_STATE_PRESSED; + dataStopButtonState.override = OVERRIDE_RESET; + + prevOffButtonState = BUTTON_STATE_RELEASED; + prevStopButtonState = BUTTON_STATE_RELEASED; +} + +/*********************************************************************//** + * @brief + * The execButtons function executes the Buttons monitor. + * @details \b Inputs: none + * @details \b Outputs: offButtonState, stopButtonState, prevOffButtonState, prevStopButtonState + * @return none + *************************************************************************/ +void execButtons( void ) +{ + PIN_SIGNAL_STATE_T off = getCPLDOffButton(); + PIN_SIGNAL_STATE_T stop = getCPLDStopButton(); + + // Set current button states read from CPLD + dataOffButtonState.data = ( off == PIN_SIGNAL_HIGH ? BUTTON_STATE_PRESSED : BUTTON_STATE_RELEASED ); + dataStopButtonState.data = ( stop == PIN_SIGNAL_HIGH ? BUTTON_STATE_PRESSED : BUTTON_STATE_RELEASED ); + + // Handle button state transitions for stop button + handleStopButtonProcessing(); + + // Handle button state transitions for off button + handleOffButtonProcessing(); +} + +/*********************************************************************//** + * @brief + * The isStopButtonPressed function determines whether the stop button has been + * pressed. Once the stop button has transitioned from released to pressed, a + * press for the stop button will be pending until this function is called. + * @details \b Inputs: stopButtonPressPending + * @details \b Outputs: stopButtonPressPending + * @return true if the stop button is pressed, false if not + *************************************************************************/ +BOOL isStopButtonPressed( void ) +{ + BOOL result = stopButtonPressPending; + + stopButtonPressPending = FALSE; + + return result; +} + +/*********************************************************************//** + * @brief + * The getOffButtonState function determines whether the off button is + * currently pressed. + * @details \b Inputs: dataOffButtonState, prevOffButtonState + * @details \b Outputs: none + * @return BUTTON_STATE_PRESSED if off button pressed, BUTTON_STATE_RELEASED if not + *************************************************************************/ +BUTTON_STATE_T getOffButtonState( void ) +{ + BUTTON_STATE_T result = (BUTTON_STATE_T)dataOffButtonState.data; + + if ( OVERRIDE_KEY == dataOffButtonState.override ) + { + result = (BUTTON_STATE_T)dataOffButtonState.ovData; + } + + return result; +} + +/*********************************************************************//** + * @brief + * The getStopButtonState function determines whether the stop button is + * currently pressed. + * @details \b Inputs: dataStopButtonState, prevStopButtonState + * @details \b Outputs: none + * @return BUTTON_STATE_PRESSED if stop button pressed, BUTTON_STATE_RELEASED if not + *************************************************************************/ +BUTTON_STATE_T getStopButtonState( void ) +{ + BUTTON_STATE_T result = (BUTTON_STATE_T)dataStopButtonState.data; + + if ( OVERRIDE_KEY == dataStopButtonState.override ) + { + result = (BUTTON_STATE_T)dataStopButtonState.ovData; + } + + return result; +} + +/*********************************************************************//** + * @brief + * The execStuckButtonTest function executes the stuck button test. + * @note This function should be called periodically until a pass or fail + * result is returned. + * @details \b Alarm: ALARM_ID_TD_STUCK_BUTTON_TEST_FAILED if test fails. + * @details \b Alarm: ALARM_ID_TD_SOFTWARE_FAULT if test state is invalid. + * @details \b Inputs: buttonSelfTestState, buttonSelfTestTimerCount + * @details \b Outputs: buttonSelfTestState, buttonSelfTestTimerCount + * @return Test status (in progress, passed, or failed) + *************************************************************************/ +SELF_TEST_STATUS_T execStuckButtonTest( void ) +{ + SELF_TEST_STATUS_T result = SELF_TEST_STATUS_IN_PROGRESS; + + switch ( buttonSelfTestState ) + { + case BUTTON_SELF_TEST_STATE_START: + buttonSelfTestState = BUTTON_SELF_TEST_STATE_IN_PROGRESS; + buttonSelfTestTimerCount = getMSTimerCount(); + // No break here so we pass through directly to in progress processing + + case BUTTON_SELF_TEST_STATE_IN_PROGRESS: + if ( ( dataOffButtonState.data == BUTTON_STATE_RELEASED ) && ( dataStopButtonState.data == BUTTON_STATE_RELEASED ) ) + { + buttonSelfTestState = BUTTON_SELF_TEST_STATE_COMPLETE; + result = SELF_TEST_STATUS_PASSED; + } + else if ( TRUE == didTimeout( buttonSelfTestTimerCount, STUCK_BUTTON_TIMEOUT_MS ) ) + { + U32 almData = ( dataStopButtonState.data == BUTTON_STATE_PRESSED ? BUTTON_STOP : BUTTON_OFF ); + + SET_ALARM_WITH_1_U32_DATA( ALARM_ID_TD_STUCK_BUTTON_TEST_FAILED, almData ) + buttonSelfTestState = BUTTON_SELF_TEST_STATE_COMPLETE; + result = SELF_TEST_STATUS_FAILED; + } + // Else just stay in progress and wait for next call + break; + + case BUTTON_SELF_TEST_STATE_COMPLETE: + // If we get called in this state, assume we are doing self-test again + buttonSelfTestState = BUTTON_SELF_TEST_STATE_START; + break; + + default: + result = SELF_TEST_STATUS_FAILED; + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_SOFTWARE_FAULT, SW_FAULT_ID_BUTTONS_INVALID_SELF_TEST_STATE, buttonSelfTestState ) + break; + } + + return result; +} + +/*********************************************************************//** + * @brief + * The resetStuckButtonPOSTState function resets the stuck button POST state. + * @details \b Inputs: none + * @details \b Outputs: buttonSelfTestState + * @return none + *************************************************************************/ +void resetStuckButtonPOSTState( void ) +{ + buttonSelfTestState = BUTTON_SELF_TEST_STATE_START; +} + +/*********************************************************************//** + * @brief + * The userConfirmOffButton function handles user confirmation of the off + * button. The off request will be initiated here if confirmed or cancelled + * if rejected by user. + * @details \b Inputs: current operation mode + * @details \b Outputs: stopButtonPressPending + * @param response 1 = confirmed, 0 = rejected + * @return none + *************************************************************************/ +void userConfirmOffButton( U08 response ) +{ + switch ( response ) + { + case OFF_BUTTON_RSP_USER_REQUESTS_POWER_OFF: + // If we are in a mode that allows power off, set off pending flag and request user confirmation + if ( TRUE == isCurrentOpModeOkToTurnOff() ) + { + offRequestAwaitingUserConfirmation = TRUE; + offRequestPendingTimer = 0; +#ifndef SIMULATE_UI + sendOffButtonMsgToUI( OFF_BUTTON_CMD_PROMPT_USER_TO_CONFIRM ); +#endif + } + else + { // Send rejection response to power off request + sendOffButtonMsgToUI( OFF_BUTTON_CMD_REJECT_USER_OFF_REQUEST ); + } + break; + + case OFF_BUTTON_RSP_USER_CONFIRMS_POWER_OFF: + // Is an off request pending user confirmation? + if ( TRUE == offRequestAwaitingUserConfirmation ) + { + // Reset off request pending flag + offRequestAwaitingUserConfirmation = FALSE; + // If we are in a mode that allows power off, initiate power off sequence + if ( TRUE == isCurrentOpModeOkToTurnOff() ) + { + POWER_OFF_WARNING_DATA_T data; + + data.powerOffWarning = 0; + + broadcastData( MSG_ID_POWER_OFF_WARNING, COMM_BUFFER_OUT_CAN_TD_BROADCAST, (U08*)&data, sizeof( POWER_OFF_WARNING_DATA_T ) ); + //signalPowerOffWarning(); // warn nvdata unit that power is going down + offButtonPressPending = TRUE; + offRequestPulseCount = OFF_REQUEST_PULSE_COUNT; + offRequestPulseTimer = 0; + } + else + { + sendOffButtonMsgToUI( OFF_BUTTON_CMD_REJECT_USER_OFF_REQUEST ); + } + } + else + { + sendOffButtonMsgToUI( OFF_BUTTON_CMD_REJECT_USER_OFF_REQUEST ); + } + break; + + case OFF_BUTTON_RSP_USER_REJECTS_POWER_OFF: + // Is an off request pending user confirmation? + if ( TRUE == offRequestAwaitingUserConfirmation ) + { + // Reset off request pending flag + offRequestAwaitingUserConfirmation = FALSE; + } + break; + + default: + // Ok - do nothing + break; + } // End switch +} + +/*********************************************************************//** + * @brief + * The isCurrentOpModeOkToTurnOff function determines whether the system can + * be turned off in current operation mode. + * @details \b Inputs: Current operation mode. + * @details \b Outputs: none + * @return TRUE if can turn system off in current mode, FALSE if not + *************************************************************************/ +static BOOL isCurrentOpModeOkToTurnOff( void ) +{ + TD_OP_MODE_T opMode = getCurrentOperationMode(); + BOOL result = FALSE; + + if ( ( opMode == MODE_STAN ) || ( opMode == MODE_SERV ) || ( opMode == MODE_FAUL ) ) + { + result = TRUE; + } + + return result; +} + +/*********************************************************************//** + * @brief + * The initiatePowerOff function initiates a power off sequence. + * @details \b Inputs: none + * @details \b Outputs: offRequestDelayTimer, offRequestPulseTimer, offRequestPulseCount, offButtonPressPending + * @return none + *************************************************************************/ +void initiatePowerOff( void ) +{ + // Warn NV Data Mgr that power will be lost shortly + // TODO signalPowerOffWarning(); + // Mimic confirmed power off button state to initiate power off cycle + offRequestDelayTimer = 0; + offRequestPulseTimer = 0; + offRequestPulseCount = OFF_REQUEST_PULSE_COUNT; + offButtonPressPending = TRUE; +} + +/*********************************************************************//** + * @brief + * The handleOffButtonProcessing function checks for and processes off button + * activity. + * @details \b Message \b Sent: TD_EVENT_BUTTON when off button state changes. + * @details \b Message \b Sent: OFF_BUTTON_CMD_CANCEL_USER_CONFIRM_PROMPT when + * pending off button expires. + * @details \b Inputs: offButtonState, prevOffButtonState + * @details \b Outputs: offButtonPressPending, offRequestPulseCount, offRequestPulseTimer + * @return none + *************************************************************************/ +static void handleOffButtonProcessing( void ) +{ + // Handle button state transitions for off button + if ( getOffButtonState() != prevOffButtonState ) + { + if ( getOffButtonState() == BUTTON_STATE_PRESSED ) + { + // If off request in a valid mode, send to UI for user confirmation + userConfirmOffButton( OFF_BUTTON_RSP_USER_REQUESTS_POWER_OFF ); + // Log off button press + SEND_EVENT_WITH_2_U32_DATA( TD_EVENT_BUTTON, BUTTON_OFF, BUTTON_STATE_PRESSED ) + } + else + { + SEND_EVENT_WITH_2_U32_DATA( TD_EVENT_BUTTON, BUTTON_OFF, BUTTON_STATE_RELEASED ) + } + prevOffButtonState = getOffButtonState(); + } + + // If off request has not been confirmed by user before it expires, cancel it + if ( TRUE == offRequestAwaitingUserConfirmation ) + { + offRequestPendingTimer += TASK_PRIORITY_INTERVAL; + if ( offRequestPendingTimer >= OFF_REQUEST_EXPIRATION_TIME_MS ) + { + offRequestAwaitingUserConfirmation = FALSE; + sendOffButtonMsgToUI( OFF_BUTTON_CMD_CANCEL_USER_CONFIRM_PROMPT ); + } + } + + // If user confirmed off button press, manage off request sequence + if ( TRUE == offButtonPressPending ) + { + // Delay power off to provide sub-systems time to prepare for shutdown + offRequestDelayTimer += TASK_PRIORITY_INTERVAL; + if ( offRequestDelayTimer >= OFF_REQUEST_DELAY_TIME_MS ) + { + // Power off sequence is 4 50 ms toggles of the off request output signal + offRequestPulseTimer += TASK_PRIORITY_INTERVAL; + if ( offRequestPulseTimer >= OFF_REQUEST_PULSE_INTVL_MS ) + { + offRequestPulseTimer = 0; + offRequestPulseCount--; + if ( offRequestPulseCount == 0 ) + { + offButtonPressPending = false; + } + toggleCPLDOffRequest(); + } + } + } +} + +/*********************************************************************//** + * @brief + * The handleStopButtonProcessing function checks for and processes stop button + * activity. + * @details \b Alarm: ALARM_ID_TD_SOFTWARE_FAULT if a pending stop button is + * expires. + * @details \b Message \b Sent: TD_EVENT_BUTTON when stop button state changes. + * @details \b Inputs: stopButtonState, prevStopButtonState + * @details \b Outputs: stopButtonPressPending + * @return none + *************************************************************************/ +static void handleStopButtonProcessing( void ) +{ + // Handle button state transitions for stop button + if ( getStopButtonState() != prevStopButtonState ) + { + if ( getStopButtonState() == BUTTON_STATE_PRESSED ) + { + stopButtonPressPending = TRUE; + stopButtonPendingTimer = getMSTimerCount(); + // Log stop button press + SEND_EVENT_WITH_2_U32_DATA( TD_EVENT_BUTTON, BUTTON_STOP, BUTTON_STATE_PRESSED ) + } + else + { + SEND_EVENT_WITH_2_U32_DATA( TD_EVENT_BUTTON, BUTTON_STOP, BUTTON_STATE_RELEASED ) + } + prevStopButtonState = getStopButtonState(); + } + + // Handle when a stop button press is pending + if ( TRUE == stopButtonPressPending ) + { + // If stop button not consumed within a reasonable time, s/w fault + if ( TRUE == didTimeout( stopButtonPendingTimer, STOP_BUTTON_PENDING_TIMEOUT_MS ) ) + { + stopButtonPressPending = FALSE; + SET_ALARM_WITH_1_U32_DATA( ALARM_ID_TD_SOFTWARE_FAULT, SW_FAULT_ID_BUTTONS_STOP_BUTTON_NOT_CONSUMED ) + } + } +} + + +/************************************************************************* + * TEST SUPPORT FUNCTIONS + *************************************************************************/ + + +/*********************************************************************//** + * @brief + * The testOffButtonOverride function overrides the off button state. + * @details \b Inputs: none + * @details \b Outputs: dataOffButtonState + * @param message Override message from Dialin which includes the state to + * override the off button to. + * @return TRUE if override request is successful, FALSE if not + *************************************************************************/ +BOOL testOffButtonOverride( MESSAGE_T *message ) +{ + BOOL result = u32Override( message, &dataOffButtonState, 0, NUM_OF_BUTTON_STATES - 1 ); + + return result; +} + +/*********************************************************************//** + * @brief + * The testStopButtonOverride function overrides the stop button state. + * @details \b Inputs: none + * @details \b Outputs: dataStopButtonState + * @param message Override message from Dialin which includes the state to + * override the stop button to. + * @return TRUE if override request is successful, FALSE if not + *************************************************************************/ +BOOL testStopButtonOverride( MESSAGE_T *message ) +{ + BOOL result = u32Override( message, &dataStopButtonState, 0, NUM_OF_BUTTON_STATES - 1 ); + + return result; +} + +/**@}*/ Index: firmware/App/Monitors/Buttons.h =================================================================== diff -u --- firmware/App/Monitors/Buttons.h (revision 0) +++ firmware/App/Monitors/Buttons.h (revision 3a8cf075eb6f0d255f516ac26bac7fbaacfde14a) @@ -0,0 +1,74 @@ +/************************************************************************** +* +* 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 Buttons.h +* +* @author (last) Sean +* @date (last) 18-Sep-2024 +* +* @author (original) Sean +* @date (original) 18-Sep-2024 +* +***************************************************************************/ + +#ifndef __BUTTONS_H__ +#define __BUTTONS_H__ + +#include "TDCommon.h" + +/** + * @defgroup Buttons Buttons + * @brief The Buttons monitor unit. Monitors button states. + * + * @addtogroup Buttons + * @{ + */ + +// ********** public definitions ********** + +/// Enumeration of hardware button states. +typedef enum Button_States +{ + BUTTON_STATE_RELEASED = 0, ///< Button is in the released state + BUTTON_STATE_PRESSED, ///< Button is in the pressed state + NUM_OF_BUTTON_STATES ///< Number of button states +} BUTTON_STATE_T; + +#pragma pack(push,1) +/// Payload record structure for an off button confirmation message from the UI. +typedef struct +{ + U08 confirmed; ///< 1 = confirmed, 0 = rejected/timed out +} OFF_BUTTON_MESSAGE_FROM_UI_PAYLOAD_T; +#pragma pack(pop) + +/// Power off warning message payload data. +typedef struct +{ + U32 powerOffWarning; ///< Power off warning message. +} POWER_OFF_WARNING_DATA_T; + +// ********** public function prototypes ********** + +void initButtons( void ); +void execButtons( void ); +BOOL isStopButtonPressed( void ); +void userConfirmOffButton( U08 response ); +SELF_TEST_STATUS_T execStuckButtonTest( void ); +void resetStuckButtonPOSTState( void ); + +BUTTON_STATE_T getOffButtonState( void ); +BUTTON_STATE_T getStopButtonState( void ); + +void initiatePowerOff( void ); + +BOOL testOffButtonOverride( MESSAGE_T *message ); +BOOL testStopButtonOverride( MESSAGE_T *message ); + +/**@}*/ + +#endif Index: firmware/App/Monitors/Switches.c =================================================================== diff -u --- firmware/App/Monitors/Switches.c (revision 0) +++ firmware/App/Monitors/Switches.c (revision 3a8cf075eb6f0d255f516ac26bac7fbaacfde14a) @@ -0,0 +1,280 @@ +/************************************************************************** +* +* 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 Switches.c +* +* @author (last) Sean +* @date (last) 17-Sep-2024 +* +* @author (original) Sean +* @date (original) 17-Sep-2024 +* +***************************************************************************/ + +#include "FpgaTD.h" +#include "Messaging.h" +//#include "NVDataMgmt.h" +#include "Switches.h" +#include "TaskGeneral.h" +#include "Timers.h" + +/** + * @addtogroup Switches + * @{ + */ + +// ********** private definitions ********** + +#define SWITCHES_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the switches data is published on the CAN bus. +#define SWITCHES_DEBOUNCE_TIME_MS ( MS_PER_SECOND / 4 ) ///< Switches FPGA status check interval. +#define DATA_PUBLISH_COUNTER_START_COUNT 90 ///< Data publish counter start count. + +/// Switch status structure +typedef struct +{ + OVERRIDE_U32_T status; ///< Switch status. + U32 debounceStartTime; ///< Debounce start time. +} SWITCH_STATUS_T; + +// ********** private data ********** + +static U32 switchesDataPublicationCounter; ///< Switches data publication counter. +static OVERRIDE_U32_T switchesDataPublishInterval; ///< Interval (in ms) at which to publish switches data to CAN bus. +static SWITCH_STATUS_T switchesStatus[ NUM_OF_SWITCHES ]; ///< Switches status array. +static BOOL requireDoorClosed; ///< Flag indicates whether door is required to be closed in current state. + +// ********** private function prototypes ********** + +static void publishSwitchesData( void ); +static void handleSwitchAlarms( void ); + +/*********************************************************************//** + * @brief + * The initSwitches function initializes the switches unit. + * @details \b Inputs: none + * @details \b Outputs: Switches monitor unit initialized + * @return none + *************************************************************************/ +void initSwitches( void ) +{ + U32 i; + + switchesDataPublicationCounter = DATA_PUBLISH_COUNTER_START_COUNT; + requireDoorClosed = FALSE; + + switchesDataPublishInterval.data = SWITCHES_DATA_PUB_INTERVAL; + switchesDataPublishInterval.ovData = SWITCHES_DATA_PUB_INTERVAL; + switchesDataPublishInterval.ovInitData = 0; + switchesDataPublishInterval.override = OVERRIDE_RESET; + + // Initialize all the switches + for ( i = 0; i < NUM_OF_SWITCHES; i++ ) + { + switchesStatus[ i ].status.data = (U32)STATE_CLOSED; + switchesStatus[ i ].status.ovData = (U32)STATE_CLOSED; + switchesStatus[ i ].status.ovInitData = (U32)STATE_CLOSED; + switchesStatus[ i ].status.override = OVERRIDE_RESET; + switchesStatus[ i ].debounceStartTime = 0; + } +} + +/*********************************************************************//** + * @brief + * The execSwitches function executes the switches monitor executive. + * @details \b Inputs: switchesStatus + * @details \b Outputs: switchesStatus + * @return none + *************************************************************************/ +void execSwitches( void ) +{ + U32 i; + OPN_CLS_STATE_T currentSwitchStates[ NUM_OF_SWITCHES ]; + + // Get current state of each switch + currentSwitchStates[ FRONT_DOOR ] = ( FALSE == getFPGAFrontDoorClosedStatus() ? STATE_OPEN : STATE_CLOSED ); + + // Debounce each switch + for ( i = 0; i < NUM_OF_SWITCHES; i++ ) + { +#ifndef _RELEASE_ +// if ( SW_CONFIG_ENABLE_VALUE == getSoftwareConfigStatus( SW_CONFIG_DISABLE_SWITCHES_MONITOR ) ) +// { +// switchesStatus[ i ].status.data = STATE_CLOSED; +// } +// else +#endif + { + // Check if the current switch status is not the same as the recorded data + if ( (U32)currentSwitchStates[ i ] != switchesStatus[ i ].status.data ) + { + // If the debounce time is 0, start the timer + if ( 0 == switchesStatus[ i ].debounceStartTime ) + { + switchesStatus[ i ].debounceStartTime = getMSTimerCount(); + } + // If the debounce time has been elapsed, update the switch status to the new status + else if ( TRUE == didTimeout( switchesStatus[ i ].debounceStartTime, SWITCHES_DEBOUNCE_TIME_MS ) ) + { + // If the bit is 0, the door switch is open, because it is normally open switch + switchesStatus[ i ].debounceStartTime = 0; + switchesStatus[ i ].status.data = currentSwitchStates[ i ]; + } + } + else + { + switchesStatus[ i ].debounceStartTime = 0; + } + } + } + + // Check for switch alarms + handleSwitchAlarms(); + + // Handle publishing switches data + publishSwitchesData(); +} + +/*********************************************************************//** + * @brief + * The handleSwitchAlarms function checks for switch related alarms. + * @details \b Alarm: ALARM_ID_TD_CARTRIDGE_DOOR_OPENED if door is open when + * it should be closed. + * @details \b Inputs: requireDoorClosed, switchesStatus + * @details \b Outputs: switchesStatus + * @return none + *************************************************************************/ +static void handleSwitchAlarms( void ) +{ +#ifndef _RELEASE_ +// if ( getSoftwareConfigStatus( SW_CONFIG_DISABLE_SWITCHES_MONITOR ) != SW_CONFIG_ENABLE_VALUE ) +#endif + { + // Check for door closed alarm + if ( TRUE == requireDoorClosed ) + { + if ( getSwitchState( FRONT_DOOR ) != STATE_CLOSED ) + { + activateAlarmNoData( ALARM_ID_TD_CARTRIDGE_DOOR_OPENED ); + } + } + + // Handle clearing alarm conditions + if ( STATE_CLOSED == getSwitchState( FRONT_DOOR ) ) + { + clearAlarmCondition( ALARM_ID_TD_CARTRIDGE_DOOR_OPENED ); + } + } +} + +/*********************************************************************//** + * @brief + * The getSwitchState function returns the state of a given switch. + * @details \b Alarm: ALARM_ID_TD_SOFTWARE_FAULT if given switch ID is invalid. + * @details \b Inputs: switchesStatus + * @details \b Outputs: switchesStatus + * @param switchId ID of switch to get state for + * @return switch state of given switch + *************************************************************************/ +OPN_CLS_STATE_T getSwitchState( SWITCH_T switchId ) +{ + U32 state = 0; + + if ( switchId < NUM_OF_SWITCHES ) + { + state = switchesStatus[ switchId ].status.data; + + if ( OVERRIDE_KEY == switchesStatus[ switchId ].status.override ) + { + state = switchesStatus[ switchId ].status.ovData; + } + } + else + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_SOFTWARE_FAULT, SW_FAULT_ID_TD_INVALID_SWITCH_ID, (U32)switchId ) + } + + return (OPN_CLS_STATE_T)state; +} + +/*********************************************************************//** + * @brief + * The doorClosedRequired function sets flags that determine whether door + * and pump tracks should be closed/locked in current state. Associated + * alarms will be triggered if switches not in required state. + * @details \b Inputs: none + * @details \b Outputs: requireDoorClosed + * @param door is door required to be closed in current state? + * @return none + *************************************************************************/ +void doorClosedRequired( BOOL door ) +{ + requireDoorClosed = door; +} + +/*********************************************************************//** + * @brief + * The publishSwitchesData function broadcasts the switches data at the + * publication interval. + * @details \b Message \b Sent: MSG_ID_TD_SWITCHES_DATA + * @details \b Inputs: switchesDataPublicationCounter + * @details \b Outputs: switchesDataPublicationCounter + * @return none + *************************************************************************/ +static void publishSwitchesData( void ) +{ + if ( ++switchesDataPublicationCounter >= getU32OverrideValue( &switchesDataPublishInterval ) ) + { + SWITCHES_DATA_T data; + + switchesDataPublicationCounter = 0; + data.frontDoor = (U32)getSwitchState( FRONT_DOOR ); + broadcastData( MSG_ID_TD_SWITCHES_DATA, COMM_BUFFER_OUT_CAN_TD_BROADCAST, (U08*)&data, sizeof( SWITCHES_DATA_T ) ); + } +} + + +/************************************************************************* + * TEST SUPPORT FUNCTIONS + *************************************************************************/ + + +/*********************************************************************//** + * @brief + * The testSwitchesDataPublishIntervalOverride function overrides the interval + * at which the TD switches data is published. + * @details \b Inputs: none + * @details \b Outputs: switchesDataPublishInterval + * @param message Override message from Dialin which includes the interval + * (in ms) to override the switches broadcast interval to. + * @return TRUE if override request is successful, FALSE if not + *************************************************************************/ +BOOL testSwitchesDataPublishIntervalOverride( MESSAGE_T *message ) +{ + BOOL result = u32BroadcastIntervalOverride( message, &switchesDataPublishInterval, TASK_GENERAL_INTERVAL ); + + return result; +} + +/*********************************************************************//** + * @brief + * The testSwitchOverride function overrides the state for a given switch. + * @details \b Inputs: none + * @details \b Outputs: switchesStatus[] + * @param message Override message from Dialin which includes an ID of + * the switch to override and the state to override the switch to. + * @return TRUE if override request is successful, FALSE if not + *************************************************************************/ +BOOL testSwitchOverride( MESSAGE_T *message ) +{ + BOOL result = u32ArrayOverride( message, &switchesStatus[0], NUM_OF_SWITCHES - 1, 0, NUM_OF_OPN_CLS_STATES - 1 ); + + return result; +} + +/**@}*/ + + Index: firmware/App/Monitors/Switches.h =================================================================== diff -u --- firmware/App/Monitors/Switches.h (revision 0) +++ firmware/App/Monitors/Switches.h (revision 3a8cf075eb6f0d255f516ac26bac7fbaacfde14a) @@ -0,0 +1,59 @@ +/************************************************************************** +* +* 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 Switches.h +* +* @author (last) Sean +* @date (last) 17-Sep-2024 +* +* @author (original) Sean +* @date (original) 17-Sep-2024 +* +***************************************************************************/ + +#ifndef APP_SWITCHES_H_ +#define APP_SWITCHES_H_ + +#include "TDCommon.h" + +/** + * @defgroup Switches Switches + * @brief Switches monitor unit. Provides functions for monitoring the status + * of the TD switch positions. + * + * @addtogroup Switches + * @{ + */ + +// ********** public definitions ********** + +/// TD switches enumeration +typedef enum switch_names +{ + FRONT_DOOR = 0, ///< Front door switch + NUM_OF_SWITCHES ///< Number of switches +} SWITCH_T; + +/// TD switches data publish structure +typedef struct +{ + U32 frontDoor; ///< Front door +} SWITCHES_DATA_T; + +// ********** public function prototypes ********** + +void initSwitches( void ); + +void execSwitches( void ); + +OPN_CLS_STATE_T getSwitchState( SWITCH_T switchId ); +void doorClosedRequired( BOOL door ); + +BOOL testSwitchesDataPublishIntervalOverride( MESSAGE_T *message ); +BOOL testSwitchOverride( MESSAGE_T *message ); + +#endif /* APP_CONTROLLERS_SWITCHES_H_ */ Index: firmware/App/Monitors/Voltages.c =================================================================== diff -u -r0c8ae7b952186d912c77d8c2cfb7dad809fa5225 -r3a8cf075eb6f0d255f516ac26bac7fbaacfde14a --- firmware/App/Monitors/Voltages.c (.../Voltages.c) (revision 0c8ae7b952186d912c77d8c2cfb7dad809fa5225) +++ firmware/App/Monitors/Voltages.c (.../Voltages.c) (revision 3a8cf075eb6f0d255f516ac26bac7fbaacfde14a) @@ -358,33 +358,8 @@ *************************************************************************/ BOOL testVoltageDataPublishIntervalOverride( MESSAGE_T *message ) { - BOOL result = FALSE; - TEST_OVERRIDE_PAYLOAD_T override; - OVERRIDE_TYPE_T ovType = getOverridePayloadFromMessage( message, &override ); + BOOL result = u32BroadcastIntervalOverride( message, &voltagesDataPublishInterval, TASK_GENERAL_INTERVAL ); - // Verify tester has logged in with TD and override type is valid - if ( ( TRUE == isTestingActivated() ) && ( ovType != OVERRIDE_INVALID ) && ( ovType < NUM_OF_OVERRIDE_TYPES ) ) - { - if ( OVERRIDE_OVERRIDE == ovType ) - { - U32 value = override.state.u32; - U32 intvl = value / TASK_GENERAL_INTERVAL; - - if ( intvl > 0 ) - { - result = TRUE; - voltagesDataPublishInterval.ovData = intvl; - voltagesDataPublishInterval.override = OVERRIDE_KEY; - } - } - else - { - result = TRUE; - voltagesDataPublishInterval.override = OVERRIDE_RESET; - voltagesDataPublishInterval.ovData = voltagesDataPublishInterval.ovInitData; - } - } - return result; } @@ -399,34 +374,8 @@ *************************************************************************/ BOOL testVoltageOverride( MESSAGE_T *message ) { - BOOL result = FALSE; - TEST_OVERRIDE_ARRAY_PAYLOAD_T override; - OVERRIDE_TYPE_T ovType = getOverrideArrayPayloadFromMessage( message, &override ); + BOOL result = f32ArrayOverride( message, &voltages[0], NUM_OF_MONITORED_VOLTAGES - 1 ); - // Verify tester has logged in with TD and override type is valid - if ( ( TRUE == isTestingActivated() ) && ( ovType != OVERRIDE_INVALID ) && ( ovType < NUM_OF_OVERRIDE_TYPES ) ) - { - U32 voltage = override.index; - - // Verify voltage index of override - if ( voltage < NUM_OF_MONITORED_VOLTAGES ) - { - result = TRUE; - if ( OVERRIDE_OVERRIDE == ovType ) - { - F32 value = override.state.f32; - - voltages[ voltage ].ovData = value; - voltages[ voltage ].override = OVERRIDE_KEY; - } - else - { - voltages[ voltage ].override = OVERRIDE_RESET; - voltages[ voltage ].ovData = voltages[ voltage ].ovInitData; - } - } - } - return result; } Index: firmware/App/Services/AlarmMgmtSWFaults.h =================================================================== diff -u -r0c8ae7b952186d912c77d8c2cfb7dad809fa5225 -r3a8cf075eb6f0d255f516ac26bac7fbaacfde14a --- firmware/App/Services/AlarmMgmtSWFaults.h (.../AlarmMgmtSWFaults.h) (revision 0c8ae7b952186d912c77d8c2cfb7dad809fa5225) +++ firmware/App/Services/AlarmMgmtSWFaults.h (.../AlarmMgmtSWFaults.h) (revision 3a8cf075eb6f0d255f516ac26bac7fbaacfde14a) @@ -114,6 +114,12 @@ SW_FAULT_ID_BUBBLES_INVALID_STATE = 83, SW_FAULT_ID_BUBBLES_INVALID_SENSOR_ID1 = 84, SW_FAULT_ID_BUBBLES_INVALID_SENSOR_ID2 = 85, + SW_FAULT_ID_AIR_PUMP_INVALID_MOTOR_STATE_SELECTED = 86, + SW_FAULT_ID_TD_AIR_PUMP_INVALID_STATE1 = 87, + SW_FAULT_ID_TD_AIR_PUMP_INVALID_STATE2 = 88, + SW_FAULT_ID_TD_INVALID_SWITCH_ID = 89, + SW_FAULT_ID_BUTTONS_INVALID_SELF_TEST_STATE = 90, + SW_FAULT_ID_BUTTONS_STOP_BUTTON_NOT_CONSUMED = 91, NUM_OF_SW_FAULT_IDS } SW_FAULT_ID_T; Index: firmware/App/Services/AlarmMgmtTD.c =================================================================== diff -u -r512065f0a0c9ba2c335e8856b790e8448852fc52 -r3a8cf075eb6f0d255f516ac26bac7fbaacfde14a --- firmware/App/Services/AlarmMgmtTD.c (.../AlarmMgmtTD.c) (revision 512065f0a0c9ba2c335e8856b790e8448852fc52) +++ firmware/App/Services/AlarmMgmtTD.c (.../AlarmMgmtTD.c) (revision 3a8cf075eb6f0d255f516ac26bac7fbaacfde14a) @@ -113,9 +113,6 @@ ALARM_ID_T a; ALARM_BUTTON_BLOCKER_T b; - // Initialize alarm audio - initAlarmAudio(); - // Initialize common alarm mgmt unit initAlarmMgmt(); @@ -162,6 +159,10 @@ alarmsBlockedTimer = 0; lastUserAlarmActionReceivedTime = 0; resumeBlockedByAlarmProperty = FALSE; + + // Initialize alarm audio and lamp + initAlarmLamp(); + initAlarmAudio(); } /*********************************************************************//** Index: firmware/App/Services/FpgaTD.c =================================================================== diff -u -rc596f2433ccbcfde4663960eaa931f74820f487d -r3a8cf075eb6f0d255f516ac26bac7fbaacfde14a --- firmware/App/Services/FpgaTD.c (.../FpgaTD.c) (revision c596f2433ccbcfde4663960eaa931f74820f487d) +++ firmware/App/Services/FpgaTD.c (.../FpgaTD.c) (revision 3a8cf075eb6f0d255f516ac26bac7fbaacfde14a) @@ -756,11 +756,18 @@ * bit (0x10). * @details \b Inputs: fpgaSensorReadings * @details \b Outputs: none - * @return front door FPGA status bit (0x10 = Open, 0x00 = Closed) + * @return TRUE if front door is closed, FALSE if not. *************************************************************************/ -U16 getFPGAFrontDoorStatus( void ) +BOOL getFPGAFrontDoorClosedStatus( void ) { - return ( fpgaSensorReadings.GPIOReg & FRONT_DOOR_SWITCH_MASK ); + BOOL result = TRUE; + + if ( ( fpgaSensorReadings.GPIOReg & FRONT_DOOR_SWITCH_MASK ) != 0 ) + { + result = FALSE; + } + + return result; } /*********************************************************************//** Index: firmware/App/Services/FpgaTD.h =================================================================== diff -u -rc596f2433ccbcfde4663960eaa931f74820f487d -r3a8cf075eb6f0d255f516ac26bac7fbaacfde14a --- firmware/App/Services/FpgaTD.h (.../FpgaTD.h) (revision c596f2433ccbcfde4663960eaa931f74820f487d) +++ firmware/App/Services/FpgaTD.h (.../FpgaTD.h) (revision 3a8cf075eb6f0d255f516ac26bac7fbaacfde14a) @@ -85,7 +85,7 @@ U32 getFPGAPBAADCTemperature( void ); U16 getFPGAInletFan1TogglePeriod( void ); -U16 getFPGAFrontDoorStatus( void ); +BOOL getFPGAFrontDoorClosedStatus( void ); /**@}*/ Index: firmware/App/Services/Messaging.c =================================================================== diff -u -r0c8ae7b952186d912c77d8c2cfb7dad809fa5225 -r3a8cf075eb6f0d255f516ac26bac7fbaacfde14a --- firmware/App/Services/Messaging.c (.../Messaging.c) (revision 0c8ae7b952186d912c77d8c2cfb7dad809fa5225) +++ firmware/App/Services/Messaging.c (.../Messaging.c) (revision 3a8cf075eb6f0d255f516ac26bac7fbaacfde14a) @@ -17,12 +17,15 @@ #include // For memcpy() +#include "AirPump.h" #include "Bubbles.h" +#include "Buttons.h" #include "Compatible.h" #include "Messaging.h" #include "OperationModes.h" #include "PAL.h" #include "PressureSensor.h" +#include "Switches.h" #include "SystemCommTD.h" #include "Utilities.h" #include "Voltages.h" @@ -76,7 +79,18 @@ MSG_ID_TD_VOLTAGE_PUBLISH_INTERVAL_OVERRIDE_REQUEST, MSG_ID_TD_VOLTAGE_OVERRIDE_REQUEST, MSG_ID_TD_BUBBLE_PUBLISH_INTERVAL_OVERRIDE_REQUEST, - MSG_ID_TD_PRESSURE_OVERRIDE_REQUEST + MSG_ID_TD_PRESSURE_OVERRIDE_REQUEST, + MSG_ID_TD_AIR_PUMP_SET_STATE_REQUEST, + MSG_ID_TD_AIR_PUMP_PUBLISH_INTERVAL_OVERRIDE_REQUEST, + MSG_ID_TD_SWITCHES_PUBLISH_INTERVAL_OVERRIDE_REQUEST, + MSG_ID_TD_SWITCH_STATE_OVERRIDE_REQUEST, + MSG_ID_TD_OFF_BUTTON_OVERRIDE_REQUEST, + MSG_ID_TD_STOP_BUTTON_OVERRIDE_REQUEST, + MSG_ID_TD_ALARM_LAMP_PATTERN_OVERRIDE_REQUEST, + MSG_ID_TD_ALARM_AUDIO_LEVEL_OVERRIDE_REQUEST, + MSG_ID_TD_ALARM_AUDIO_CURRENT_HG_OVERRIDE_REQUEST, + MSG_ID_TD_ALARM_AUDIO_CURRENT_LG_OVERRIDE_REQUEST, + MSG_ID_TD_BACKUP_ALARM_AUDIO_CURRENT_OVERRIDE_REQUEST }; /// Message handling function table @@ -87,7 +101,18 @@ &testVoltageDataPublishIntervalOverride, &testVoltageOverride, &testBubblesDataPublishIntervalOverride, - &testPressureSensorOverride + &testPressureSensorOverride, + &testSetAirPump, + &testAirPumpDataPublishIntervalOverride, + &testSwitchesDataPublishIntervalOverride, + &testSwitchOverride, + &testOffButtonOverride, + &testStopButtonOverride, + &testAlarmLampPatternOverride, + &testAlarmAudioVolumeLevelOverride, + &testPrimaryAlarmAudioCurrentHGOverride, + &testPrimaryAlarmAudioCurrentLGOverride, + &testBackupAlarmAudioCurrentOverride }; #define NUM_OF_FUNCTION_HANDLERS (sizeof(MSG_FUNCTION_HANDLERS) / sizeof(MsgFuncPtr)) @@ -392,7 +417,38 @@ return result; } +/*********************************************************************//** + * @brief + * The sendOffButtonMsgToUI function constructs an off button msg to the UI + * and queues the msg for transmit on the appropriate CAN channel. + * @details \b Message \b Sent: MSG_ID_OFF_BUTTON_PRESS_REQUEST + * @details \b Inputs: none + * @details \b Outputs: Off button msg constructed and queued. + * @param prompt 0=prompt user to confirm, 1=cancel prompt, 2=reject user off request + * @return TRUE if msg successfully queued for transmit, FALSE if not + *************************************************************************/ +BOOL sendOffButtonMsgToUI( U08 prompt ) +{ + BOOL result; + MESSAGE_T msg; + UI_OFF_BUTTON_RESPONSE_PAYLOAD_T cmd; + cmd.userRequest = prompt; + + // Create a message record + blankMessage( &msg ); + msg.hdr.msgID = MSG_ID_OFF_BUTTON_PRESS_REQUEST; + msg.hdr.payloadLen = sizeof( UI_OFF_BUTTON_RESPONSE_PAYLOAD_T ); + + memcpy( &msg.payload, &cmd, sizeof( UI_OFF_BUTTON_RESPONSE_PAYLOAD_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_TD_2_UI, ACK_REQUIRED ); + + return result; +} + + /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/ Index: firmware/App/Services/Messaging.h =================================================================== diff -u -r380b0afc95467d0861ff3aa2cdcde5d5d7ac85e7 -r3a8cf075eb6f0d255f516ac26bac7fbaacfde14a --- firmware/App/Services/Messaging.h (.../Messaging.h) (revision 380b0afc95467d0861ff3aa2cdcde5d5d7ac85e7) +++ firmware/App/Services/Messaging.h (.../Messaging.h) (revision 3a8cf075eb6f0d255f516ac26bac7fbaacfde14a) @@ -158,6 +158,7 @@ BOOL handleTesterLogInRequest( MESSAGE_T *message ); BOOL sendEvent( TD_EVENT_ID_T event, EVENT_DATA_T dat1, EVENT_DATA_T dat2 ); +BOOL sendOffButtonMsgToUI( U08 prompt ); // MSG_ID_TD_SOFTWARE_RESET_REQUEST BOOL handleTDSoftwareResetRequest( MESSAGE_T *message ); Index: firmware/App/Tasks/TaskGeneral.c =================================================================== diff -u -r8cbddbe34a4ffed5a4d9fac07a065799c5862611 -r3a8cf075eb6f0d255f516ac26bac7fbaacfde14a --- firmware/App/Tasks/TaskGeneral.c (.../TaskGeneral.c) (revision 8cbddbe34a4ffed5a4d9fac07a065799c5862611) +++ firmware/App/Tasks/TaskGeneral.c (.../TaskGeneral.c) (revision 3a8cf075eb6f0d255f516ac26bac7fbaacfde14a) @@ -15,9 +15,10 @@ * ***************************************************************************/ +#include "AirPump.h" #include "Messaging.h" #include "OperationModes.h" -#include "SystemComm.h" +#include "Switches.h" #include "SystemCommTD.h" #include "TaskGeneral.h" #include "Voltages.h" @@ -67,9 +68,9 @@ // // Monitor pressure sensors // execPressures(); // -// // Monitor switches -// execSwitches(); -// + // Monitor switches + execSwitches(); + // // Monitor temperatures // execTemperatures(); // @@ -85,9 +86,9 @@ // // Control blood pump // execBloodFlowController(); // -// // Control Air Pump -// execAirPumpController(); -// + // Control Air Pump + execAirPumpController(); + // // Monitor/Control fan // execFan(); // Index: firmware/App/Tasks/TaskPriority.c =================================================================== diff -u -r494b19c85bdea2b8fc273c648b4f1955f9d07dc3 -r3a8cf075eb6f0d255f516ac26bac7fbaacfde14a --- firmware/App/Tasks/TaskPriority.c (.../TaskPriority.c) (revision 494b19c85bdea2b8fc273c648b4f1955f9d07dc3) +++ firmware/App/Tasks/TaskPriority.c (.../TaskPriority.c) (revision 3a8cf075eb6f0d255f516ac26bac7fbaacfde14a) @@ -16,7 +16,9 @@ ***************************************************************************/ #include "Bubbles.h" +#include "Buttons.h" #include "FPGA.h" +#include "InternalADC.h" #include "SystemCommTD.h" #include "TaskPriority.h" #include "WatchdogMgmt.h" @@ -51,22 +53,14 @@ // execFPGAClockSpeedTest(); // Monitor and process buttons -// execButtons(); + execButtons(); // Monitor internal ADC channels -// execInternalADC(); + execInternalADC(); // Monitor air trap level sensors // execAirTrapMonitor(); -#ifndef _RELEASE_ -// if ( getSoftwareConfigStatus( SW_CONFIG_DISABLE_SYRINGE_PUMP ) != SW_CONFIG_ENABLE_VALUE ) -#endif - { - // Control/Monitor syringe pump -// execSyringePump(); - } - // Monitor blood pump and flow // execBloodFlowMonitor(); Index: firmware/source/sys_main.c =================================================================== diff -u -r494b19c85bdea2b8fc273c648b4f1955f9d07dc3 -r3a8cf075eb6f0d255f516ac26bac7fbaacfde14a --- firmware/source/sys_main.c (.../sys_main.c) (revision 494b19c85bdea2b8fc273c648b4f1955f9d07dc3) +++ firmware/source/sys_main.c (.../sys_main.c) (revision 3a8cf075eb6f0d255f516ac26bac7fbaacfde14a) @@ -63,8 +63,9 @@ #include "rti.h" #include "TDCommon.h" -#include "AlarmLamp.h" +#include "AirPump.h" #include "Bubbles.h" +#include "Buttons.h" #include "CpldInterface.h" #include "DDInterface.h" #include "FpgaTD.h" @@ -73,7 +74,7 @@ #include "MsgQueues.h" #include "OperationModes.h" #include "PressureSensor.h" -#include "SystemComm.h" +#include "Switches.h" #include "SystemCommTD.h" #include "TaskBG.h" #include "Timers.h" @@ -189,9 +190,11 @@ initWatchdogMgmt(); // Initialize monitors initBubbles(); + initButtons(); + initSwitches(); initVoltagesMonitor(); // Initialize controllers - initAlarmLamp(); + initAirPump(); // Initialize modes initOperationModes(); }