Index: firmware/App/Controllers/BloodLeak.c =================================================================== diff -u -re55f9fe6ad322e30fbc53a6857b19a95a3107706 -rdd1a9a6f5e43a5da27f4d51f56388f7d019cc43d --- firmware/App/Controllers/BloodLeak.c (.../BloodLeak.c) (revision e55f9fe6ad322e30fbc53a6857b19a95a3107706) +++ firmware/App/Controllers/BloodLeak.c (.../BloodLeak.c) (revision dd1a9a6f5e43a5da27f4d51f56388f7d019cc43d) @@ -7,8 +7,8 @@ * * @file BloodLeak.c * -* @author (last) Sean Nash -* @date (last) 12-Nov-2021 +* @author (last) Dara Navaei +* @date (last) 04-Jan-2022 * * @author (original) Peman Montazemi * @date (original) 18-Mar-2021 @@ -56,6 +56,12 @@ #define BLOOD_LEAK_MIN_WAIT_TIME_2_GET_CAL_MS ( 2 * MS_PER_SECOND ) ///< Blood leak minimum wait time to get calibration in milliseconds. +// TODO remove after zeroing was fixed +#define BLOOD_LEAK_ZERO_SENSOR_SEQ_LENGTH 5 ///< Blood leak zero sensor sequence length. +#define BLOOD_LEAK_ZERO_Z_CHAR_ASCII 90 ///< Blood leak zero sensor 'Z' command in ascii. +#define BLOOD_LEAK_ZERO_FIFO_STOP_INDEX 2 ///< Blood leak zero sensor stop writing to FIFO command. +// TODO remove after zeroing was fixed + /// Defined states for the blood leak detector state machine. typedef enum BloodLeakStates { @@ -84,7 +90,7 @@ static OVERRIDE_U32_T bloodLeakDataPublishInterval = { BLOOD_LEAK_PUB_INTERVAL, BLOOD_LEAK_PUB_INTERVAL, 0, 0 }; ///< Interval (in ms) at which to publish blood leak data to CAN bus. static U32 bloodLeakDataPublicationTimerCounter = 0; ///< Timer counter used to schedule blood leak data publication to CAN bus. -static U32 bloodLeakUARTCmdIndex; ///< Blood leak UART command index. +static U32 bloodLeakUARTCmdIndex = 0; ///< Blood leak UART command index. static U32 bloodLeakSetPointSeqLength = 0; ///< Blood leak set point sequence actual length. static U08 bloodLeakSetPointSequence[ BLOOD_LEAK_SET_POINT_SEQ_MAX_LENGTH ]; ///< Blood leak set point sequence array. static U32 bloodLeakWait2ReadSetPointCounter = 0; ///< Blood leak wait to read delay counter. @@ -100,6 +106,15 @@ BLOOD_LEAK_UART_COMM_ACTIVE_HIGH, BLOOD_LEAK_UART_COMM_ACTIVE_LOW }; +// TODO remove after zeroing was fixed +/// Blood leak zero sensor sequence array. +static const U08 BLOOD_LEAK_ZERO_SNSR_SEQUENCE[ BLOOD_LEAK_ZERO_SENSOR_SEQ_LENGTH ] = { BLOOD_LEAK_ZERO_Z_CHAR_ASCII, + BLOOD_LEAK_CARRIAGE_RETURN_ASCII, + BLOOD_LEAK_STOP_WRITE_FIFO_COMMAND, + BLOOD_LEAK_UART_COMM_ACTIVE_HIGH, + BLOOD_LEAK_UART_COMM_ACTIVE_LOW }; +// TODO remove after zeroing was fixed + // ********** private function prototypes ********** static BLOOD_LEAK_STATES_T handleBloodLeakStartupState( void ); @@ -229,6 +244,7 @@ void zeroBloodLeak( void ) { bloodLeakZeroRequested = TRUE; + bloodLeakUARTCmdIndex = 0; } /*********************************************************************//** @@ -325,7 +341,6 @@ activateAlarmNoData( ALARM_ID_HD_BLOOD_LEAK_SENSOR_SET_POINT_SET_FAILURE ); #endif } - } else { @@ -398,7 +413,7 @@ state = BLOOD_LEAK_ZERO_STATE; bloodLeakZeroRequested = FALSE; - setFPGABloodLeakZero(); + //setFPGABloodLeakZero(); // DEBUG_DENALI bloodLeakZeroStartTime = getMSTimerCount(); } @@ -417,24 +432,40 @@ { BLOOD_LEAK_STATES_T state = BLOOD_LEAK_ZERO_STATE; - if ( TRUE == FPGABloodLeakZeroDetected() ) + if ( bloodLeakUARTCmdIndex < BLOOD_LEAK_ZERO_SENSOR_SEQ_LENGTH ) { - bloodLeakSelfTestStatus = SELF_TEST_STATUS_IN_PROGRESS; - clearFPGABloodLeakZero(); -#ifndef IGNORE_BLOOD_LEAK_SELF_TEST - setFPGABloodLeakSelfTest(); - state = BLOOD_LEAK_SELF_TEST_STATE; -#else - state = BLOOD_LEAK_NORMAL_STATE; -#endif - bloodLeakSelfTestStartTime = getMSTimerCount(); + U08 command = BLOOD_LEAK_ZERO_SNSR_SEQUENCE[ bloodLeakUARTCmdIndex ]; + + if ( bloodLeakUARTCmdIndex <= BLOOD_LEAK_ZERO_FIFO_STOP_INDEX ) + { + setFPGABloodLeakUARTTransmit( (U08)command ); + } + else + { + setFPGABloodLeakUARTControl( (U08)command ); + } + + bloodLeakUARTCmdIndex++; } else { - if ( TRUE == didTimeout( bloodLeakZeroStartTime, BLOOD_LEAK_TIMEOUT_MS ) ) + if ( TRUE == FPGABloodLeakZeroDetected() ) { - activateAlarmNoData( ALARM_ID_HD_BLOOD_LEAK_FAULT ); + state = BLOOD_LEAK_SELF_TEST_STATE; + bloodLeakSelfTestStatus = SELF_TEST_STATUS_IN_PROGRESS; + clearFPGABloodLeakZero(); + setFPGABloodLeakSelfTest(); + bloodLeakSelfTestStartTime = getMSTimerCount(); } + else + { + if ( TRUE == didTimeout( bloodLeakZeroStartTime, BLOOD_LEAK_TIMEOUT_MS ) ) + { + #ifndef IGNORE_BLOOD_LEAK_ALARM + activateAlarmNoData( ALARM_ID_HD_BLOOD_LEAK_FAULT ); + #endif + } + } } return state; @@ -534,7 +565,7 @@ state = BLOOD_LEAK_ZERO_STATE; bloodLeakZeroRequested = FALSE; - setFPGABloodLeakZero(); + //setFPGABloodLeakZero(); // DEBUG_DENALI bloodLeakZeroStartTime = getMSTimerCount(); }