Index: firmware/App/Controllers/Valves.c =================================================================== diff -u -r8bd1ae47aa13a843aa8abd6321ddc050deacb4a6 -r37a9fd8f15e413db5337371a7d1a1cb65567af7c --- firmware/App/Controllers/Valves.c (.../Valves.c) (revision 8bd1ae47aa13a843aa8abd6321ddc050deacb4a6) +++ firmware/App/Controllers/Valves.c (.../Valves.c) (revision 37a9fd8f15e413db5337371a7d1a1cb65567af7c) @@ -1,14 +1,14 @@ /************************************************************************** * -* Copyright (c) 2019-2021 Diality Inc. - All Rights Reserved. +* Copyright (c) 2020-2022 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 Valves.c * -* @author (last) Dara Navaei -* @date (last) 10-Nov-2021 +* @author (last) Darren Cox +* @date (last) 10-Mar-2022 * * @author (original) Dara Navaei * @date (original) 07-Aug-2020 @@ -21,6 +21,7 @@ #include "FPGA.h" #include "MessageSupport.h" +#include "NVDataMgmt.h" #include "SafetyShutdown.h" #include "SystemCommMessages.h" #include "TaskPriority.h" @@ -106,6 +107,8 @@ #define VALVE_CCW_PWM_TO_CNT_CONVERSION( pwm ) ( ( -20 * pwm ) + 2500 ) ///< Valve counter clockwise PWM to count conversion #define VALVE_CCW_CNT_TO_PWM_CONVERSION( cnt ) ( ( -0.05 * cnt ) + 125 ) ///< Valve counter clockwise count to PWM conversion +#define DATA_PUBLISH_COUNTER_START_COUNT 80 ///< Data publish counter start count. + /// Exec valve self test states typedef enum valves_Self_Test_States { @@ -213,18 +216,15 @@ static const U16 VALVE_CONTROL_MODES_RESET_BITS[ NUM_OF_VALVES ] = { VDI_RESET_CONTROL_BIT_MASK, VDO_RESET_CONTROL_BIT_MASK, VBA_RESET_CONTROL_BIT_MASK, VBV_RESET_CONTROL_BIT_MASK }; ///< Valves control modes rest bits -#ifndef DISABLE_3WAY_VALVES -#ifndef DISABLE_VALVE_ALARMS static const U16 VALVE_CONTROL_STATUS_BITS[ NUM_OF_VALVES ][ NUM_OF_VALVE_CONTROL_STATUS ] = { { VDI_INIT_STATUS_BIT_MASK, VDI_ENABLE_PID_STATUS_BIT_MASK, VDI_ENABLE_BYPASS_STATUS_BIT_MASK, VDI_RESET_CONTROL_BIT_MASK }, { VDO_INIT_STATUS_BIT_MASK, VDO_ENABLE_PID_STATUS_BIT_MASK, VDO_ENABLE_BYPASS_STATUS_BIT_MASK, VDO_RESET_CONTROL_BIT_MASK }, { VBA_INIT_STATUS_BIT_MASK, VBA_ENABLE_PID_STATUS_BIT_MASK, VBA_ENABLE_BYPASS_STATUS_BIT_MASK, VBA_RESET_CONTROL_BIT_MASK }, { VBV_INIT_STATUS_BIT_MASK, VBV_ENABLE_PID_STATUS_BIT_MASK, VBV_ENABLE_BYPASS_STATUS_BIT_MASK, VBV_RESET_CONTROL_BIT_MASK } }; ///< Valves control status bits -#endif -#endif static U16 valvesControlSetBits = 0x0000; ///< Valves control set bit static OPN_CLS_STATE_T valveAirTrapStatus; ///< Air trap valve status (open/close) +static HD_VALVES_CAL_RECORD_T valvesCalibrationRecord; ///< Valves calibration record. // Self test function prototypes static VALVE_SELF_TEST_STATE_T handleValveSelfTestEnableValves( void ); @@ -280,11 +280,12 @@ // Initialize some of the variables for ( valve = VDI; valve < NUM_OF_VALVES; valve++ ) { - valvesStatus[ valve ].execState = VALVE_STATE_WAIT_FOR_POST; - valvesStatus[ valve ].current.data = 0.0; - valvesStatus[ valve ].current.ovData = 0.0; + valvesStatus[ valve ].execState = VALVE_STATE_WAIT_FOR_POST; + valvesStatus[ valve ].current.data = 0.0; + valvesStatus[ valve ].current.ovData = 0.0; valvesStatus[ valve ].current.ovInitData = 0.0; - valvesStatus[ valve ].current.override = 0; + valvesStatus[ valve ].current.override = 0; + valvesStatus[ valve ].dataPublishCounter = DATA_PUBLISH_COUNTER_START_COUNT; } // Close air trap valve @@ -567,7 +568,10 @@ { VALVE_SELF_TEST_STATE_T state = VALVE_SELF_TEST_COMPLETE; - if ( TRUE == areValvesFunctional() ) + BOOL calStatus = getNVRecord2Driver( GET_CAL_VALVES, (U08*)&valvesCalibrationRecord, sizeof( HD_VALVES_CAL_RECORD_T ), + NUM_OF_CAL_DATA_HD_VALVES, ALARM_ID_NO_ALARM ); + + if ( ( TRUE == areValvesFunctional() ) && ( TRUE == calStatus ) ) { valvesSelfTestResult = SELF_TEST_STATUS_PASSED; } @@ -734,9 +738,7 @@ valvesStatus[ valve ].hasValveBeenHomed = FALSE; valvesStatus[ valve ].hasHomingFailed = TRUE; state = VALVE_STATE_HOMING_NOT_STARTED; -#ifndef DISABLE_VALVE_ALARMS SET_ALARM_WITH_1_U32_DATA( ALARM_ID_HD_VALVE_HOMING_FAILED, (U32)valve ); -#endif } else { @@ -773,16 +775,6 @@ { VALVE_STATE_T state = VALVE_STATE_IDLE; -#ifdef TST_3WAY_VALVES_ALWAYS_OPEN - static BOOL valvesOpenedForSarina[NUM_OF_VALVES] = { FALSE, FALSE, FALSE, FALSE }; - - if ( FALSE == valvesOpenedForSarina[ valve ] ) - { - valvesOpenedForSarina[ valve ] = TRUE; - setValvePosition( valve, VALVE_POSITION_B_OPEN ); - } -#endif - if ( TRUE == valvesStatus[ valve ].hasHomingBeenRequested ) { state = VALVE_STATE_HOMING_NOT_STARTED; @@ -861,9 +853,8 @@ //valvesStatus[ valve ].hasTransitionBeenRequested = FALSE; TODO remove // Go back to Idle state state = VALVE_STATE_IDLE; -#ifndef DISABLE_VALVE_ALARMS SET_ALARM_WITH_1_U32_DATA( ALARM_ID_HD_VALVE_TRANSITION_TIMEOUT, (U32)valve ); -#endif + // If the valve transition timeout is active and the valve's commanded positions is position C, activate safety shutdown if ( ( TRUE == isAlarmActive( ALARM_ID_HD_VALVE_TRANSITION_TIMEOUT ) ) && ( VALVE_POSITION_C_CLOSE == valvesStatus[ valve ].commandedPosition ) ) { @@ -949,15 +940,12 @@ *************************************************************************/ static void execMonitorValves( void ) { -#ifndef DISABLE_3WAY_VALVES // Check if the valves are still enabled areValvesFunctional(); -#endif // Get the current position of the valves in counts and store them getAndMonitorValvesCurrentFPGAPosition(); -#ifndef DISABLE_3WAY_VALVES // Get the current in ADC and convert them to amps // Check whether any of the valves are over current convertAndMonitorValvesCurrent(); @@ -967,7 +955,6 @@ #ifdef DEBUG_ENABLED getValvesCurrentPWM(); #endif -#endif } /*********************************************************************//** @@ -982,8 +969,6 @@ static BOOL areValvesFunctional( void ) { BOOL result = TRUE; -#ifndef DISABLE_3WAY_VALVES -#ifndef DISABLE_VALVE_ALARMS VALVE_T valve; VALVE_MODE_T mode; @@ -1031,8 +1016,6 @@ result = FALSE; } } -#endif -#endif return result; } @@ -1122,9 +1105,7 @@ // Check if the current is over the threshold for the defined amount of time if ( valvesStatus[ valve ].overCurrentCounter > MAX_OVER_CURRENT_TIME_INTERVAL_COUNTER ) { -#ifndef DISABLE_VALVE_ALARMS SET_ALARM_WITH_2_F32_DATA( ALARM_ID_HD_VALVE_CURRENT_OUT_OF_RANGE, (F32)valve, current ); -#endif } // If the current is below the threshold again and the counter for the time is greater than else if ( ( current < VALVES_CURRENT_THRESHOLD_AMPS ) && ( valvesStatus[ valve ].overCurrentCounter > 0 ) ) @@ -1158,7 +1139,6 @@ valvesStatus[ VBA ].currentPositionInCounts.data = (S32)getFPGAValveBloodArterialPosition(); valvesStatus[ VBV ].currentPositionInCounts.data = (S32)getFPGAValveBloodVenousPosition(); -#ifndef DISABLE_3WAY_VALVES // Check the position of each valve for ( valve = VDI; valve < NUM_OF_VALVES; valve++ ) { @@ -1187,9 +1167,7 @@ if ( valvesStatus[ valve ].positionOutOfRangeCounter > MAX_POS_DEVIATION_TIME_INTERVAL_COUNTER ) { -#ifndef DISABLE_VALVE_ALARMS SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_VALVE_POSITION_OUT_OF_RANGE, (U32)valve, currentPosition ); -#endif } else if ( abs( currentPosition - commandedPosition ) < MAX_DEVIATION_FROM_TARGET_IN_COUNTS && valvesStatus[ valve ].positionOutOfRangeCounter > 0 ) @@ -1198,7 +1176,6 @@ } } } -#endif } /*********************************************************************//**