Index: firmware/App/Controllers/Voltages.c =================================================================== diff -u --- firmware/App/Controllers/Voltages.c (revision 0) +++ firmware/App/Controllers/Voltages.c (revision 9f2e4e5933d2e418b75f91e3db5df69c71878d43) @@ -0,0 +1,430 @@ +/************************************************************************** +* +* Copyright (c) 2019-2020 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 Nash +* @date (last) 15-Apr-2021 +* +* @author (original) Sean +* @date (original) 15-Apr-2021 +* +***************************************************************************/ + +#include "AlarmMgmt.h" +#include "InternalADC.h" +#include "SystemCommMessages.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_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Alarm persistence period for voltage monitor alarms. + +/// Defined states for the pressure and occlusion 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; + +/// Defined states for the voltage monitor self-test state machine. +typedef enum Voltages_Self_Test_States +{ + VOLTAGES_SELF_TEST_STATE_START = 0, ///< Self test start state. + VOLTAGES_TEST_STATE_IN_PROGRESS, ///< Self test in progress state. + VOLTAGES_TEST_STATE_COMPLETE, ///< Self test completed state. + NUM_OF_VOLTAGES_SELF_TEST_STATES ///< Number of voltage monitor self-test states. +} VOLTAGES_SELF_TEST_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 + 30.0, // MONITORED_LINE_24V_REGEN + 1.05, // MONITORED_LINE_FPGA_REF_V + 3.3, // MONITORED_LINE_PBA_REF_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 + 18.0, // MONITORED_LINE_24V_REGEN + 0.95, // MONITORED_LINE_FPGA_REF_V + 2.7, // MONITORED_LINE_PBA_REF_V +}; + +// ********** private data ********** + +static VOLTAGES_STATE_T voltagesState; ///< Current state of voltages monitor state machine. +static U32 voltagesDataPublicationTimerCounter = 0; ///< 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. + +static U32 voltageAlarmPerisistenceCtr[ NUM_OF_MONITORED_LINES ]; ///< Alarm persistence counters for voltage check failures. + +// ********** private function prototypes ********** + +static VOLTAGES_STATE_T handleVoltagesInitState( void ); +static VOLTAGES_STATE_T handleVoltagesMonitorState( void ); +static void checkVoltageRanges( void ); +static void publishVoltagesData( void ); +static U32 getPublishVoltagesDataInterval( void ); + +/*********************************************************************//** + * @brief + * The initVoltagesMonitor function initializes the Voltages module. + * @details Inputs: none + * @details Outputs: Voltages module initialized. + * @return none + *************************************************************************/ +void initVoltagesMonitor( void ) +{ + U32 i; + + voltagesState = VOLTAGES_INIT_STATE; + + 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; + + voltageAlarmPerisistenceCtr[i] = 0; + } +} + +/*********************************************************************//** + * @brief + * The execVoltagesMonitor function executes the voltages monitor. + * @details Inputs: voltagesState + * @details Outputs: voltagesState + * @return none + *************************************************************************/ +void execVoltagesMonitor( void ) +{ + // State machine + switch ( voltagesState ) + { + case VOLTAGES_INIT_STATE: + voltagesState = handleVoltagesInitState(); + break; + + case VOLTAGES_MONITOR_STATE: + voltagesState = handleVoltagesMonitorState(); + break; + + default: + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, 0, voltagesState ) // TODO - add enum for this s/w fault + break; + } + + // Publish voltages data on interval + publishVoltagesData(); +} + +/*********************************************************************//** + * @brief + * The handleVoltagesInitState function handles the initialize state + * of the voltages monitor state machine. + * @details Inputs: TBD + * @details Outputs: TBD + * @return next state + *************************************************************************/ +static VOLTAGES_STATE_T handleVoltagesInitState( void ) +{ + VOLTAGES_STATE_T result = VOLTAGES_MONITOR_STATE; + + return result; +} + +/*********************************************************************//** + * @brief + * The handleVoltagesMonitorState function handles the monitor state + * of the voltages monitor state machine. + * @details Inputs: converted internal ADC readings + * @details Outputs: alarm on failed check + * @return next state + *************************************************************************/ +static VOLTAGES_STATE_T handleVoltagesMonitorState( void ) +{ + VOLTAGES_STATE_T result = VOLTAGES_MONITOR_STATE; + + // Get latest signal levels + voltages[ MONITORED_LINE_1_2V ].data = getIntADCVoltageConverted( INT_ADC_1_2V_PROCESSOR ); + voltages[ MONITORED_LINE_3_3V ].data = getIntADCVoltageConverted( INT_ADC_3_3V ); + 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_FPGA_ADC_REF ); + voltages[ MONITORED_LINE_PBA_REF_V ].data = getIntADCVoltageConverted( INT_ADC_PBA_ADC_REF ); + + // Check voltage ranges + checkVoltageRanges(); + + return result; +} + +/*********************************************************************//** + * @brief + * The checkVoltageRanges function checks each monitored voltage or current + * against its minimum and maximum range. + * @details Inputs: voltageAlarmPerisistenceCtr, MAX_VOLTAGES[], MIN_VOLTAGES[], voltages[] + * @details Outputs: voltageAlarmPerisistenceCtr, alarm if out of range + * @return none + *************************************************************************/ +static void checkVoltageRanges( void ) +{ + U32 i; + + // Check range + for ( i = 0; i < NUM_OF_MONITORED_LINES; i++ ) + { + F32 volts = getMonitoredLineLevel( (MONITORED_VOLTAGES_T)i ); + + if ( volts > MAX_VOLTAGES[ i ] ) + { + if ( ++voltageAlarmPerisistenceCtr[ i ] > VOLTAGES_ALARM_PERSISTENCE ) + { + SET_ALARM_WITH_2_F32_DATA( ALARM_ID_HD_VOLTAGE_OUT_OF_RANGE, (F32)i, volts ) + } + } + else if ( volts < MIN_VOLTAGES[ i ] ) + { + if ( ++voltageAlarmPerisistenceCtr[ i ] > VOLTAGES_ALARM_PERSISTENCE ) + { + SET_ALARM_WITH_2_F32_DATA( ALARM_ID_HD_VOLTAGE_OUT_OF_RANGE, (F32)i, volts ) + } + } + else + { + voltageAlarmPerisistenceCtr[ i ] = 0; + } + } +} + +/*********************************************************************//** + * @brief + * The getPublishVoltagesDataInterval function gets the voltages monitor data + * publication interval. + * @details Inputs: voltagesDataPublishInterval + * @details Outputs: none + * @return the current voltage monitor data publication interval (in task intervals). + *************************************************************************/ +static U32 getPublishVoltagesDataInterval( void ) +{ + U32 result = voltagesDataPublishInterval.data; + + if ( OVERRIDE_KEY == voltagesDataPublishInterval.override ) + { + result = voltagesDataPublishInterval.ovData; + } + + return result; +} + +/*********************************************************************//** + * @brief + * The getMonitoredLineLevel function gets the current voltage or current + * level for a given signal. + * @details Inputs: voltages[] + * @details Outputs: none + * @param signal the signal that is being asked for + * @return the voltage/current for the given signal + *************************************************************************/ +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 + { + // TODO - s/w fault + } + + return result; +} + +/*********************************************************************//** + * @brief + * The publishVoltagesData function publishes voltages monitor data at the + * set interval. + * @details Inputs: latest voltages and currents + * @details Outputs: voltages monitor data are published to CAN bus. + * @return none + *************************************************************************/ +static void publishVoltagesData( void ) +{ + // Publish voltages monitor data on interval + if ( ++voltagesDataPublicationTimerCounter >= getPublishVoltagesDataInterval() ) + { + 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 ); + + broadcastVoltagesData( data ); + voltagesDataPublicationTimerCounter = 0; + } +} + +/*********************************************************************//** + * @brief + * The execVoltagesTest function executes the voltage monitor self-test. + * @details Inputs: none + * @details Outputs: none + * @return the result of the voltage monitor self-test. + *************************************************************************/ +SELF_TEST_STATUS_T execVoltagesTest( void ) +{ + SELF_TEST_STATUS_T result = SELF_TEST_STATUS_PASSED; + + // TODO - implement + + return result; +} + +/************************************************************************* + * 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/Controllers/Voltages.h =================================================================== diff -u --- firmware/App/Controllers/Voltages.h (revision 0) +++ firmware/App/Controllers/Voltages.h (revision 9f2e4e5933d2e418b75f91e3db5df69c71878d43) @@ -0,0 +1,77 @@ +/************************************************************************** +* +* Copyright (c) 2019-2020 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 PresOccl.h +* +* @author (last) Sean Nash +* @date (last) 15-Apr-2021 +* +* @author (original) Sean +* @date (original) 15-Apr-2021 +* +***************************************************************************/ + +#ifndef __VOLTAGES_H__ +#define __VOLTAGES_H__ + +#include "HDCommon.h" + +/** + * @defgroup Voltages Voltages + * @brief Pressure & Occlusion controller/monitor module. Monitors the + * blood line pressure sensors and pump occlusion sensors. + * + * @addtogroup Voltages + * @{ + */ + +// ********** public definitions ********** + +/// Enumeration of pressure sensors monitored by this module. +typedef enum Voltages +{ + MONITORED_LINE_1_2V = 0, ///< Processor voltage (1.2V) + 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) + 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) +} VOLTAGES_DATA_PAYLOAD_T; + +// ********** public function prototypes ********** + +void initVoltagesMonitor( void ); +void execVoltagesMonitor( void ); + +SELF_TEST_STATUS_T execVoltagesTest( 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/Drivers/InternalADC.c =================================================================== diff -u -rf3326a3d0fd2a465a518e31ee578e335db301c27 -r9f2e4e5933d2e418b75f91e3db5df69c71878d43 --- firmware/App/Drivers/InternalADC.c (.../InternalADC.c) (revision f3326a3d0fd2a465a518e31ee578e335db301c27) +++ firmware/App/Drivers/InternalADC.c (.../InternalADC.c) (revision 9f2e4e5933d2e418b75f91e3db5df69c71878d43) @@ -36,7 +36,7 @@ { INT_ADC_DIAL_IN_PUMP_SPEED, // 0 INT_ADC_PS_THERMISTOR, // 1 - INT_ADC_REFIN_1, // 2 + INT_ADC_PBA_ADC_REF, // 2 INT_ADC_24V_ACTUATORS_REG, // 3 INT_ADC_1_2V_PROCESSOR, // 4 INT_ADC_5V_SENSORS, // 5 Index: firmware/App/Drivers/InternalADC.h =================================================================== diff -u -rf3326a3d0fd2a465a518e31ee578e335db301c27 -r9f2e4e5933d2e418b75f91e3db5df69c71878d43 --- firmware/App/Drivers/InternalADC.h (.../InternalADC.h) (revision f3326a3d0fd2a465a518e31ee578e335db301c27) +++ firmware/App/Drivers/InternalADC.h (.../InternalADC.h) (revision 9f2e4e5933d2e418b75f91e3db5df69c71878d43) @@ -46,17 +46,17 @@ INT_ADC_DIAL_IN_PUMP_MOTOR_CURRENT, ///< Internal ADC channel for dialysate inlet pump current INT_ADC_DIAL_OUT_PUMP_SPEED, ///< Internal ADC channel for dialysate outlet pump speed INT_ADC_DIAL_OUT_PUMP_MOTOR_CURRENT, ///< Internal ADC channel for dialysate outlet pump current - INT_ADC_PS_THERMISTOR, ///< Internal ADC channel for trimmer heater temperature (primary) - INT_ADC_REFIN_1, ///< Internal ADC channel for reference voltage to LCA1 & LCB1 (primary load cell ADC channels) - INT_ADC_24V_ACTUATORS_REG, ///< Internal ADC channel for reference voltage to LCA2 & LCB2 (redundant load cell ADC channels) + 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 INT_ADC_1_2V_PROCESSOR, ///< Internal ADC channel for 1.2V to processor INT_ADC_5V_SENSORS, ///< Internal ADC channel for 5V to sensors - INT_ADC_PRIMARY_ALARM_CURRENT_HG, ///< Internal ADC channel for primary alarm audio current HG - INT_ADC_BOARD_THERMISTOR, ///< Internal ADC channel for trimmer heater temperature (redundant) + INT_ADC_PRIMARY_ALARM_CURRENT_HG, ///< Internal ADC channel for primary alarm audio current high gain + INT_ADC_BOARD_THERMISTOR, ///< Internal ADC channel for PCB temperature INT_ADC_FPGA_ADC_REF, ///< Internal ADC channel for FPGA ADC reference voltage INT_ADC_3_3V, ///< Internal ADC channel for 3.3V 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 LG + 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_BACKUP_ALARM_CURRENT, ///< Internal ADC channel for backup alarm audio current NUM_OF_INT_ADC_CHANNELS ///< Number of used internal ADC channels. Index: firmware/App/Modes/BloodPrime.c =================================================================== diff -u -rdb22e9d530c5c9d62b02e6dcc72ed96fb67c165a -r9f2e4e5933d2e418b75f91e3db5df69c71878d43 --- firmware/App/Modes/BloodPrime.c (.../BloodPrime.c) (revision db22e9d530c5c9d62b02e6dcc72ed96fb67c165a) +++ firmware/App/Modes/BloodPrime.c (.../BloodPrime.c) (revision 9f2e4e5933d2e418b75f91e3db5df69c71878d43) @@ -240,7 +240,7 @@ // ramp blood pump on ramp interval if ( ++bloodPrimeRampControlTimerCtr >= BLOOD_PRIME_RAMPING_INTERVAL ) { - bloodPrimeRampControlTimerCtr = 0; + bloodPrimeRampControlTimerCtr = 0; // TODO - stop ramping when reach set rate for BP bloodPrimeRampFlowRate_mL_min += bloodPrimeRampStep_mL; setBloodPumpTargetFlowRate( (U32)bloodPrimeRampFlowRate_mL_min, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_OPEN_LOOP ); } Index: firmware/App/Services/AlarmMgmt.c =================================================================== diff -u -r6dcc3d91f1f6095d6d3a722c2e3c2074d69be2a5 -r9f2e4e5933d2e418b75f91e3db5df69c71878d43 --- firmware/App/Services/AlarmMgmt.c (.../AlarmMgmt.c) (revision 6dcc3d91f1f6095d6d3a722c2e3c2074d69be2a5) +++ firmware/App/Services/AlarmMgmt.c (.../AlarmMgmt.c) (revision 9f2e4e5933d2e418b75f91e3db5df69c71878d43) @@ -564,10 +564,21 @@ *************************************************************************/ void setAlarmAudioVolume( U32 volumeLevel ) { + BOOL accepted = FALSE; + U32 rejReason = REQUEST_REJECT_REASON_NONE; + if ( ( volumeLevel > 0 ) && ( volumeLevel <= MAX_ALARM_VOLUME_LEVEL ) ) { // Convert volume level to attenuation level alarmAudioVolumeLevel = MAX_ALARM_VOLUME_LEVEL - volumeLevel; + accepted = TRUE; } + else + { + rejReason = REQUEST_REJECT_REASON_PARAM_OUT_OF_RANGE; + } + + // Send response to UI + sendAlarmAudioVolumeSetResponse( accepted, rejReason ); } /*********************************************************************//** Index: firmware/App/Services/SystemComm.c =================================================================== diff -u -raa0c1b0150e1eeb2ff5f7cac8715ecacb6aca119 -r9f2e4e5933d2e418b75f91e3db5df69c71878d43 --- firmware/App/Services/SystemComm.c (.../SystemComm.c) (revision aa0c1b0150e1eeb2ff5f7cac8715ecacb6aca119) +++ firmware/App/Services/SystemComm.c (.../SystemComm.c) (revision 9f2e4e5933d2e418b75f91e3db5df69c71878d43) @@ -1209,6 +1209,10 @@ handleHeparinCommandRequest( message ); break; + case MSG_ID_UI_SET_ALARM_AUDIO_VOLUME_LEVEL_CMD: + handleAlarmAudioVolumeSetCmd( message ); + break; + case MSG_ID_UI_SET_UF_VOLUME_PARAMETER: handleUFVolumeSetRequest( message ); break; Index: firmware/App/Services/SystemCommMessages.c =================================================================== diff -u -r6dcc3d91f1f6095d6d3a722c2e3c2074d69be2a5 -r9f2e4e5933d2e418b75f91e3db5df69c71878d43 --- firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision 6dcc3d91f1f6095d6d3a722c2e3c2074d69be2a5) +++ firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision 9f2e4e5933d2e418b75f91e3db5df69c71878d43) @@ -502,6 +502,38 @@ return result; } +/*********************************************************************//** + * @brief + * The sendAlarmAudioVolumeSetResponse function constructs an alarm audio + * volume set request response to the UI and queues the msg for transmit on the + * appropriate CAN channel. + * @details Inputs: none + * @details Outputs: Alarm audio volume set. + * @param accepted flag indicating whether request was accepted + * @param rejReason rejection reason code + * @return TRUE if msg successfully queued for transmit, FALSE if not + *************************************************************************/ +BOOL sendAlarmAudioVolumeSetResponse( U32 accepted, U32 rejReason ) +{ + BOOL result; + MESSAGE_T msg; + U08 *payloadPtr = msg.payload; + + // Create a message record + blankMessage( &msg ); + msg.hdr.msgID = MSG_ID_HD_ALARM_AUDIO_VOLUME_SET_RESPONSE; + msg.hdr.payloadLen = sizeof( U32 ) * 2; + + memcpy( payloadPtr, &accepted, sizeof( U32 ) ); + payloadPtr += sizeof( U32 ); + memcpy( payloadPtr, &rejReason, sizeof( U32 ) ); + + // Serialize the message (w/ sync, CRC, and appropriate CAN padding) and add serialized message data to appropriate comm buffer + result = serializeMessage( msg, COMM_BUFFER_OUT_CAN_HD_2_UI, ACK_REQUIRED ); + + return result; +} + /*********************************************************************//** * @brief * The sendTreatmentParamsRangesToUI function constructs a treatment parameter @@ -1412,6 +1444,34 @@ result = serializeMessage( msg, COMM_BUFFER_OUT_CAN_HD_BROADCAST, ACK_NOT_REQUIRED ); return result; +} + +/*********************************************************************//** + * @brief + * The broadcastVoltagesData function constructs a monitored voltages data msg to + * be broadcast and queues the msg for transmit on the appropriate CAN channel. + * @details Inputs: none + * @details Outputs: monitored voltages data msg constructed and queued. + * @param data Latest monitored voltage values. + * @return TRUE if msg successfully queued for transmit, FALSE if not + *************************************************************************/ +BOOL broadcastVoltagesData( VOLTAGES_DATA_PAYLOAD_T data ) +{ + BOOL result; + MESSAGE_T msg; + U08 *payloadPtr = msg.payload; + + // Create a message record + blankMessage( &msg ); + msg.hdr.msgID = MSG_ID_HD_VOLTAGES_DATA; + msg.hdr.payloadLen = sizeof( VOLTAGES_DATA_PAYLOAD_T ); + + memcpy( payloadPtr, &data, sizeof( VOLTAGES_DATA_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_HD_BROADCAST, ACK_NOT_REQUIRED ); + + return result; } /*********************************************************************//** @@ -2752,6 +2812,31 @@ /*********************************************************************//** * @brief + * The handleAlarmAudioVolumeSetCmd function handles a alarm audio volume + * set request message from the UI. + * @details Inputs: none + * @details Outputs: message handled + * @param message a pointer to the message to handle + * @return none + *************************************************************************/ +void handleAlarmAudioVolumeSetCmd( MESSAGE_T *message ) +{ + if ( sizeof( U32 ) == message->hdr.payloadLen ) + { + U32 payload; + + memcpy( &payload, &message->payload[0], sizeof( U32 ) ); + + setAlarmAudioVolume( payload ); + } + else + { + sendAckResponseMsg( (MSG_ID_T)message->hdr.msgID, COMM_BUFFER_OUT_CAN_HD_2_UI, FALSE ); + } +} + +/*********************************************************************//** + * @brief * The handleSalineBolusRequest function handles a saline bolus request * message from the UI. * @details Inputs: none Index: firmware/App/Services/SystemCommMessages.h =================================================================== diff -u -r6419179374edcd65da462de84e8aeaefb7e20320 -r9f2e4e5933d2e418b75f91e3db5df69c71878d43 --- firmware/App/Services/SystemCommMessages.h (.../SystemCommMessages.h) (revision 6419179374edcd65da462de84e8aeaefb7e20320) +++ firmware/App/Services/SystemCommMessages.h (.../SystemCommMessages.h) (revision 9f2e4e5933d2e418b75f91e3db5df69c71878d43) @@ -36,6 +36,7 @@ #include "Rinseback.h" #include "SyringePump.h" #include "Valves.h" +#include "Voltages.h" /** * @defgroup SystemCommMessages SystemCommMessages @@ -171,6 +172,12 @@ // MSG_ID_HD_HEPARIN_PAUSE_RESUME_RESPONSE BOOL sendHeparinCommandResponse( U32 accepted, U32 rejReason ); +// MSG_ID_UI_SET_ALARM_AUDIO_VOLUME_LEVEL_CMD +void handleAlarmAudioVolumeSetCmd( MESSAGE_T *message ); + +// MSG_ID_HD_ALARM_AUDIO_VOLUME_SET_RESPONSE +BOOL sendAlarmAudioVolumeSetResponse( U32 accepted, U32 rejReason ); + // MSG_ID_UI_SAMPLE_WATER_CMD void handleSampleWaterCmd( MESSAGE_T *message ); @@ -297,6 +304,9 @@ // MSG_ID_PRESSURE_OCCLUSION_DATA BOOL broadcastPresOcclData( PRESSURE_OCCLUSION_DATA_T data ); + +// MSG_ID_HD_VOLTAGES_DATA +BOOL broadcastVoltagesData( VOLTAGES_DATA_PAYLOAD_T data ); // MSG_ID_RTC_EPOCH BOOL broadcastRTCEpoch( U32 epoch ); Index: firmware/App/Tasks/TaskGeneral.c =================================================================== diff -u -r6419179374edcd65da462de84e8aeaefb7e20320 -r9f2e4e5933d2e418b75f91e3db5df69c71878d43 --- firmware/App/Tasks/TaskGeneral.c (.../TaskGeneral.c) (revision 6419179374edcd65da462de84e8aeaefb7e20320) +++ firmware/App/Tasks/TaskGeneral.c (.../TaskGeneral.c) (revision 9f2e4e5933d2e418b75f91e3db5df69c71878d43) @@ -25,11 +25,12 @@ #include "NVDataMgmt.h" #include "OperationModes.h" #include "PresOccl.h" +#include "RTC.h" #include "SystemComm.h" #include "SystemCommMessages.h" -#include "WatchdogMgmt.h" -#include "TaskGeneral.h" -#include "RTC.h" +#include "TaskGeneral.h" +#include "Voltages.h" +#include "WatchdogMgmt.h" /** * @addtogroup TaskGeneral @@ -71,7 +72,9 @@ // Monitor pressure/occlusion sensors execPresOccl(); -#endif +#endif + // Monitor voltages + execVoltagesMonitor(); // Run operation mode state machine execOperationModes(); Index: firmware/source/sys_main.c =================================================================== diff -u -r6419179374edcd65da462de84e8aeaefb7e20320 -r9f2e4e5933d2e418b75f91e3db5df69c71878d43 --- firmware/source/sys_main.c (.../sys_main.c) (revision 6419179374edcd65da462de84e8aeaefb7e20320) +++ firmware/source/sys_main.c (.../sys_main.c) (revision 9f2e4e5933d2e418b75f91e3db5df69c71878d43) @@ -88,6 +88,7 @@ #include "TaskBG.h" #include "Timers.h" #include "Valves.h" +#include "Voltages.h" #include "WatchdogMgmt.h" static void initProcessor( void ); @@ -188,6 +189,7 @@ initAccel(); initButtons(); initPresOccl(); + initVoltagesMonitor(); // Initialize controllers initAirTrap(); initAlarmLamp();