Index: firmware/App/Controllers/BloodLeak.c =================================================================== diff -u -r0e01a5db1f8bb113b7a45faec25ea661b7418af6 -r8b73263b38f449dacc0795c67a7cf6240cb79026 --- firmware/App/Controllers/BloodLeak.c (.../BloodLeak.c) (revision 0e01a5db1f8bb113b7a45faec25ea661b7418af6) +++ firmware/App/Controllers/BloodLeak.c (.../BloodLeak.c) (revision 8b73263b38f449dacc0795c67a7cf6240cb79026) @@ -8,7 +8,7 @@ * @file BloodLeak.c * * @author (last) Dara Navaei -* @date (last) 23-May-2022 +* @date (last) 04-Aug-2022 * * @author (original) Peman Montazemi * @date (original) 18-Mar-2021 @@ -34,7 +34,6 @@ // ********** private definitions ********** #define BLOOD_LEAK_PUB_INTERVAL ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) ///< Interval (ms/task time) at which the blood leak data is published on the CAN bus. -#define BLOOD_LEAK_TIMEOUT_MS 2000 ///< Blood leak detector timeout for zeroing and self-test (15 ms extended edge detection) #define BLOOD_LEAK_PERSISTENCE ( 10 * MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) ///< Persistence for blood leak detected alarm. #define BLOOD_LEAK_RESET_TX_FIFO 2 ///< Blood leak reset transmit FIFO command. #define BLOOD_LEAK_START_COMM_CTRL_U_ASCII 21 ///< Blood leak start communication command, ^U (Ctrl-U) in ascii. @@ -56,7 +55,13 @@ #define BLOOD_LEAK_WAIT_2_READ_CTRL_U ( 1 * MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) ///< Blood leak wait to read control U in counts. #define BLOOD_LEAK_MAX_SET_POINT_WRITE_TRIALS 3 ///< Blood leak maximum number of trials to write the set point. #define BLOOD_LEAK_MAX_CTRL_U_WRITE_TRIALS 3 ///< Blood leak maximum number of trials to write the control U command. - +#define BLOOD_LEAK_ZERO_CMD_STATUS_READY 0x80 ///< Blood leak zero command status ready value. +#define BLOOD_LEAK_SELF_TEST_CMD_STATUS_READY 0x80 ///< Blood leak self test command status ready value. +#define BLOOD_LEAK_STATUS_BIT_HIGH 1 ///< Blood leak status bit high. +#define BLOOD_LEAK_STATUS_BIT_LOW 0 ///< Blood leak status bit low. +#define BLOOD_LEAK_ZERO_CMD_TIMEOUT_MS ( 2 * MS_PER_SECOND ) ///< Blood leak zero command timeout in milliseconds. +#define BLOOD_LEAK_SELF_TEST_CMD_TIMEOUT_MS ( 2 * MS_PER_SECOND ) ///< Blood leak self test command timeout in milliseconds. +#define BLOOD_LEAK_BETWEEN_ZERO_ST_WAIT_MS 250 ///< Blood leak wait time in between zero and self test commands in milliseconds. #define BLOOD_LEAK_MIN_WAIT_TIME_2_GET_CAL_MS ( 2 * MS_PER_SECOND ) ///< Blood leak minimum wait time to get calibration in milliseconds. #define DATA_PUBLISH_COUNTER_START_COUNT 60 ///< Data publish counter start count. @@ -94,7 +99,9 @@ BLOOD_LEAK_CHECK_SET_POINT_STATE, ///< Check set point state. BLOOD_LEAK_SET_SET_POINT_STATE, ///< Set set point state. BLOOD_LEAK_INIT_STATE, ///< Init state. + BLOOD_LEAK_PREP_FOR_ZERO_CMD_STATE, ///< Prepare for zero command state. BLOOD_LEAK_ZERO_STATE, ///< Zero state. + BLOOD_LEAK_PREP_FOR_SELF_TEST_CMD_STATE, ///< Prepare for self test command state. BLOOD_LEAK_SELF_TEST_STATE, ///< Self-test state. BLOOD_LEAK_NORMAL_STATE, ///< Normal state. BLOOD_LEAK_CALIBRATION_STATE, ///< Calibration state. @@ -136,15 +143,21 @@ U32 timeoutMS; ///< Blood leak sensor receive timeout in milliseconds. } EMB_MODE_CMD_T; +/// Zero command structure +typedef struct +{ + BOOL cmdZeroRequested; ///< Blood leak zero command requested. + U08 cmdPrevStatus; ///< Blood leak previous zero/self test status. + U32 cmdStartTimeMS; ///< Blood leak zero/self test command start time in milliseconds. + U32 cmdWaitBtwnZeroSTestMS; ///< Blood leak wait time in between zero and self test in milliseconds. +} BLOOD_LEAK_GPIO_CMD_T; + // ********** private data ********** static BLOOD_LEAK_STATE_T bloodLeakState; ///< Current state of blood leak state machine. +static BLOOD_LEAK_STATE_T bloodLeakPrevState; ///< Previous state of blood leak state machine. static OVERRIDE_U32_T bloodLeakStatus; ///< Detected blood leak status for blood leak detector. static SELF_TEST_STATUS_T bloodLeakSelfTestStatus; ///< Current status of blood leak self-test. - -static BOOL bloodLeakZeroRequested; ///< Blood leak zero requested flag -static U32 bloodLeakZeroStartTime; ///< Blood leak zeroing start time. -static U32 bloodLeakSelfTestStartTime; ///< Blood leak self-test start time. static BOOL bloodLeakIsPOSTComplete; ///< Blood leak is POST complete flag. static U32 bloodLeakPersistenceCtr; ///< Blood leak alarm persistence timer counter. @@ -160,6 +173,7 @@ static U32 bloodLeakGetCalStartTime; ///< Blood leak get calibration start time. static U32 bloodLeakPrevFPGARegisterCount; ///< Blood leak previous FPGA communications counter. static BOOL bloodLeakExitNormalRequested; ///< Blood leak exit normal state requested. +static BLOOD_LEAK_GPIO_CMD_T bloodLeakGPIOCmd; ///< Blood leak zero/self test GPIO command. /// Blood leak start up sequence array. static const U08 BLOOD_LEAK_START_UP_SEQUENCE[ BLOOD_LEAK_STARTUP_SEQ_LENGTH ] = { BLOOD_LEAK_RESET_TX_FIFO, @@ -189,7 +203,9 @@ static BLOOD_LEAK_STATE_T handleBloodLeakCheckSetPointState( void ); static BLOOD_LEAK_STATE_T handleBloodLeakSetSetPointState( void ); static BLOOD_LEAK_STATE_T handleBloodLeakInitState( void ); +static BLOOD_LEAK_STATE_T handleBloodLeakPrepForZeroCmdState( void ); static BLOOD_LEAK_STATE_T handleBloodLeakZeroState( void ); +static BLOOD_LEAK_STATE_T handleBloodLeakPrepForSelfTestCmdState( void ); static BLOOD_LEAK_STATE_T handleBloodLeakSelfTestState( void ); static BLOOD_LEAK_STATE_T handleBloodLeakNormalState( void ); static BLOOD_LEAK_STATE_T handleBloodLeakCalibrationState( void ); @@ -202,13 +218,13 @@ static void prepareSetPointSeq( U16 setPoint ); static void publishBloodLeakData( void ); static void initEmbModeSpecs( void ); +static BOOL hasZeroBloodLeakBeenRequested( void ); /*********************************************************************//** * @brief * The initBloodLeak function initializes the Blood Leak module. * @details Inputs: none * @details Outputs: bloodLeakState, bloodLeakStatus, bloodLeakSelfTestStatus, - * bloodLeakZeroRequested, bloodLeakZeroRequested, bloodLeakSelfTestStartTime, * bloodLeakUARTCmdIndex, bloodLeakSetPointSequence, bloodLeakPrevFPGARegisterCount * bloodLeakWait2ReadResponseCounter, bloodLeakDataPublicationTimerCounter, * bloodLeakCommandWriteTryCount, bloodLeakGetCalStartTime, bloodLeakEmbModeSubstate @@ -227,9 +243,6 @@ bloodLeakStatus.ovData = BLOOD_LEAK_NOT_DETECTED; bloodLeakStatus.override = OVERRIDE_RESET; bloodLeakSelfTestStatus = SELF_TEST_STATUS_IN_PROGRESS; - bloodLeakZeroRequested = FALSE; - bloodLeakZeroStartTime = 0; - bloodLeakSelfTestStartTime = 0; bloodLeakUARTCmdIndex = 0; bloodLeakSetPointSeqLength = 0; bloodLeakWait2ReadResponseCounter = 0; @@ -326,10 +339,18 @@ bloodLeakState = handleBloodLeakInitState(); break; + case BLOOD_LEAK_PREP_FOR_ZERO_CMD_STATE: + bloodLeakState = handleBloodLeakPrepForZeroCmdState(); + break; + case BLOOD_LEAK_ZERO_STATE: bloodLeakState = handleBloodLeakZeroState(); break; + case BLOOD_LEAK_PREP_FOR_SELF_TEST_CMD_STATE: + bloodLeakState = handleBloodLeakPrepForSelfTestCmdState(); + break; + case BLOOD_LEAK_SELF_TEST_STATE: bloodLeakState = handleBloodLeakSelfTestState(); break; @@ -358,13 +379,13 @@ * The zeroBloodLeak function requests that the Blood Leak Detector be * zeroed. * @details Inputs: none - * @details Outputs: Blood Leak module zeroing. + * @details Outputs: bloodLeakCmd.cmdZeroRequested, bloodLeakUARTCmdIndex * @return none *************************************************************************/ void zeroBloodLeak( void ) { - bloodLeakZeroRequested = TRUE; - bloodLeakUARTCmdIndex = 0; + bloodLeakGPIOCmd.cmdZeroRequested = TRUE; + bloodLeakUARTCmdIndex = 0; } /*********************************************************************//** @@ -430,8 +451,8 @@ bloodLeakPrevFPGARegisterCount = getFPGABloodLeakRegisterCounter(); // TODO this has been disabled for the systems team testing. In their test, ^U is not sent //state = BLOOD_LEAK_START_UP_STATE; - state = BLOOD_LEAK_INIT_STATE; - // TODO remove once testing is done + // TODO decide whether we need to go to ^U upon startup + state = BLOOD_LEAK_INIT_STATE; } return state; @@ -447,6 +468,7 @@ *************************************************************************/ static BLOOD_LEAK_STATE_T handleBloodLeakStartupState( void ) { + // TODO NOTE: This function is bypassed until the use of ^U is finalized by the system's team BLOOD_LEAK_STATE_T state = BLOOD_LEAK_START_UP_STATE; U32 command = BLOOD_LEAK_START_UP_SEQUENCE[ bloodLeakUARTCmdIndex ]; @@ -490,6 +512,7 @@ *************************************************************************/ static BLOOD_LEAK_STATE_T handleBloodLeakCheckCommState( void ) { + // TODO NOTE: This function is bypassed until the use of ^U is finalized by the system's team BLOOD_LEAK_STATE_T state = BLOOD_LEAK_CHECK_COMM_STATE; // Check if the blood leak sensor has started communicating @@ -532,7 +555,7 @@ { BLOOD_LEAK_STATE_T state = BLOOD_LEAK_CHECK_SET_POINT_STATE; - U16 bloodLeakSetPoint = getFPGABloodLeakDetectSetPoint(); + U16 bloodLeakSetPoint = getFPGABloodLeakDetectSetPoint(); // TODO is this working in embedded mode? #ifdef BOARD_WITH_NO_HARDWARE // In case it is just a bare board, use this value @@ -559,7 +582,7 @@ } else { - state = BLOOD_LEAK_INIT_STATE; + state = BLOOD_LEAK_INIT_STATE; bloodLeakCommandWriteTryCount = 0; } @@ -575,6 +598,7 @@ *************************************************************************/ static BLOOD_LEAK_STATE_T handleBloodLeakSetSetPointState( void ) { + // TODO remove this function BLOOD_LEAK_STATE_T state = BLOOD_LEAK_SET_SET_POINT_STATE; // Check if the current buffer index is less than the buffer length @@ -623,15 +647,47 @@ { BLOOD_LEAK_STATE_T state = BLOOD_LEAK_INIT_STATE; - if ( TRUE == bloodLeakZeroRequested ) - { - state = BLOOD_LEAK_ZERO_STATE; - bloodLeakZeroRequested = FALSE; - bloodLeakZeroStartTime = getMSTimerCount(); + // Check if the zero command has been requested + state = ( TRUE == hasZeroBloodLeakBeenRequested() ? BLOOD_LEAK_PREP_FOR_ZERO_CMD_STATE : state ); + return state; +} + +/*********************************************************************//** + * @brief + * The handleBloodLeakPrepForZeroCmdState function handles the blood leak + * prepare for zero command state. + * @details Inputs: bloodLeakCmd + * @details Outputs: bloodLeakCmd + * @return next state + *************************************************************************/ +static BLOOD_LEAK_STATE_T handleBloodLeakPrepForZeroCmdState( void ) +{ + BLOOD_LEAK_STATE_T state = BLOOD_LEAK_PREP_FOR_ZERO_CMD_STATE; + U08 zeroCmdStatus = getFPGABloodLeakZeroErrorCounter() & BLOOD_LEAK_ZERO_CMD_STATUS_READY; + + // Check if the zero command is ready to receive a command and the zero status is high + if ( ( BLOOD_LEAK_ZERO_CMD_STATUS_READY == zeroCmdStatus ) && ( BLOOD_LEAK_STATUS_BIT_HIGH == getFPGABloodLeakZeroStatus() ) ) + { + // The conditions are met start the command + // Start with the previous status bit is high + state = BLOOD_LEAK_ZERO_STATE; + bloodLeakGPIOCmd.cmdStartTimeMS = getMSTimerCount(); + bloodLeakGPIOCmd.cmdPrevStatus = BLOOD_LEAK_STATUS_BIT_HIGH; setFPGABloodLeakZero(); } + else if ( TRUE == didTimeout( bloodLeakGPIOCmd.cmdStartTimeMS, BLOOD_LEAK_ZERO_CMD_TIMEOUT_MS ) ) + { +#ifndef _RELEASE_ + if ( getSoftwareConfigStatus( SW_CONFIG_DISABLE_BLOOD_LEAK_ALARM ) != SW_CONFIG_ENABLE_VALUE ) +#endif + { + activateAlarmNoData( ALARM_ID_HD_BLOOD_LEAK_ZERO_CMD_SEND_TIMEOUT ); + } + state = BLOOD_LEAK_INIT_STATE; + } + return state; } @@ -646,27 +702,77 @@ static BLOOD_LEAK_STATE_T handleBloodLeakZeroState( void ) { BLOOD_LEAK_STATE_T state = BLOOD_LEAK_ZERO_STATE; + U08 bloodLeakZeroStatus = getFPGABloodLeakZeroStatus(); - if ( TRUE == FPGABloodLeakZeroDetected() ) + // Check if the previous zero status bit was a 0 (low) and the current zero status bit is a 1 (high) + // Clear the blood leak zero and self test commands and get ready to do the self test + if ( ( BLOOD_LEAK_STATUS_BIT_LOW == bloodLeakGPIOCmd.cmdPrevStatus ) && ( BLOOD_LEAK_STATUS_BIT_HIGH == bloodLeakZeroStatus ) ) { - state = BLOOD_LEAK_SELF_TEST_STATE; - bloodLeakSelfTestStatus = SELF_TEST_STATUS_IN_PROGRESS; - bloodLeakSelfTestStartTime = getMSTimerCount(); - + // Clear the zero command since it is done and clear the self test since we are getting ready to do a self test. clearFPGABloodLeakZero(); - setFPGABloodLeakSelfTest(); + clearFPGABloodLeakSelfTest(); + // Get ready for the next state. + state = BLOOD_LEAK_PREP_FOR_SELF_TEST_CMD_STATE; + bloodLeakGPIOCmd.cmdStartTimeMS = getMSTimerCount(); + bloodLeakGPIOCmd.cmdWaitBtwnZeroSTestMS = getMSTimerCount(); } + else if ( TRUE == didTimeout( bloodLeakGPIOCmd.cmdStartTimeMS, BLOOD_LEAK_ZERO_CMD_TIMEOUT_MS ) ) + { + // Zero command timed out +#ifndef _RELEASE_ + if ( getSoftwareConfigStatus( SW_CONFIG_DISABLE_BLOOD_LEAK_ALARM ) != SW_CONFIG_ENABLE_VALUE ) +#endif + { + activateAlarmNoData( ALARM_ID_HD_BLOOD_LEAK_ZERO_CMD_FAULT ); + } + // Get back to init state + state = BLOOD_LEAK_INIT_STATE; + } else { - if ( TRUE == didTimeout( bloodLeakZeroStartTime, BLOOD_LEAK_TIMEOUT_MS ) ) + // Update the previous status with the current zero status since the low to high edge has been observed yet + bloodLeakGPIOCmd.cmdPrevStatus = bloodLeakZeroStatus; + } + + return state; +} + +/*********************************************************************//** + * @brief + * The handleBloodLeakPrepForSelfTestCmdState function handles the blood leak + * prepare for self test command state. + * @details Inputs: bloodLeakGPIOCmd + * @details Outputs: bloodLeakGPIOCmd + * @return next state + *************************************************************************/ +static BLOOD_LEAK_STATE_T handleBloodLeakPrepForSelfTestCmdState( void ) +{ + BLOOD_LEAK_STATE_T state = BLOOD_LEAK_PREP_FOR_SELF_TEST_CMD_STATE; + U08 selfTestCmdStatus = getFPGABloodLeakSelfTestErrorCounter() & BLOOD_LEAK_SELF_TEST_CMD_STATUS_READY; + + // Check if the self test command status is ready and self test status bit is low (0) + if ( ( BLOOD_LEAK_SELF_TEST_CMD_STATUS_READY == selfTestCmdStatus ) && ( BLOOD_LEAK_STATUS_BIT_LOW == getFPGABloodLeakStatus() ) ) + { + // Check if the delay in between the zero command and the self test command has been elapsed + if ( TRUE == didTimeout( bloodLeakGPIOCmd.cmdWaitBtwnZeroSTestMS, BLOOD_LEAK_BETWEEN_ZERO_ST_WAIT_MS ) ) { + // Update the variables and set the self test + state = BLOOD_LEAK_SELF_TEST_STATE; + bloodLeakGPIOCmd.cmdStartTimeMS = getMSTimerCount(); + bloodLeakGPIOCmd.cmdPrevStatus = BLOOD_LEAK_STATUS_BIT_LOW; + setFPGABloodLeakSelfTest(); + } + } + else if ( TRUE == didTimeout( bloodLeakGPIOCmd.cmdStartTimeMS, BLOOD_LEAK_SELF_TEST_CMD_TIMEOUT_MS ) ) + { #ifndef _RELEASE_ - if ( getSoftwareConfigStatus( SW_CONFIG_DISABLE_BLOOD_LEAK_ALARM ) != SW_CONFIG_ENABLE_VALUE ) + if ( getSoftwareConfigStatus( SW_CONFIG_DISABLE_BLOOD_LEAK_ALARM ) != SW_CONFIG_ENABLE_VALUE ) #endif - { - activateAlarmNoData( ALARM_ID_HD_BLOOD_LEAK_FAULT ); - } + { + activateAlarmNoData( ALARM_ID_HD_BLOOD_LEAK_SELF_TEST_SEND_TIMEOUT ); } + // Self test command failed + state = BLOOD_LEAK_INIT_STATE; } return state; @@ -682,29 +788,33 @@ *************************************************************************/ static BLOOD_LEAK_STATE_T handleBloodLeakSelfTestState( void ) { - BLOOD_LEAK_STATE_T state = BLOOD_LEAK_SELF_TEST_STATE; + BLOOD_LEAK_STATE_T state = BLOOD_LEAK_SELF_TEST_STATE; + U08 bloodLeakSelfTestStatus = getFPGABloodLeakStatus(); - if ( SELF_TEST_STATUS_IN_PROGRESS == bloodLeakSelfTestStatus ) + // Check if the previous status bit was a high (1) and the current status bit is a low (0). This means that the self test was + // successfully finished + if ( ( BLOOD_LEAK_STATUS_BIT_HIGH == bloodLeakGPIOCmd.cmdPrevStatus ) && ( BLOOD_LEAK_STATUS_BIT_LOW == bloodLeakSelfTestStatus ) ) { - if ( FALSE == noFPGABloodLeakDetected() ) // Faked blood leak caused by independent MCU board + // Clear the self test command since it is done + clearFPGABloodLeakSelfTest(); + state = BLOOD_LEAK_NORMAL_STATE; + bloodLeakSelfTestStatus = SELF_TEST_STATUS_PASSED; + } + else if ( TRUE == didTimeout( bloodLeakGPIOCmd.cmdStartTimeMS, BLOOD_LEAK_SELF_TEST_CMD_TIMEOUT_MS ) ) + { +#ifndef _RELEASE_ + if ( getSoftwareConfigStatus( SW_CONFIG_DISABLE_BLOOD_LEAK_ALARM ) != SW_CONFIG_ENABLE_VALUE ) +#endif { - bloodLeakSelfTestStatus = SELF_TEST_STATUS_PASSED; - clearFPGABloodLeakSelfTest(); + activateAlarmNoData( ALARM_ID_HD_BLOOD_LEAK_SELF_TEST_FAULT ); } - else if ( TRUE == didTimeout( bloodLeakSelfTestStartTime, BLOOD_LEAK_TIMEOUT_MS ) ) - { - bloodLeakSelfTestStatus = SELF_TEST_STATUS_FAILED; - - activateAlarmNoData( ALARM_ID_HD_BLOOD_LEAK_SELF_TEST_FAILURE ); - } + // Self test failed due to timeout + state = BLOOD_LEAK_INIT_STATE; + bloodLeakSelfTestStatus = SELF_TEST_STATUS_FAILED; } else { - // Blood leak self-test finished, wait for self-test faked blood leak clear - if ( TRUE == noFPGABloodLeakDetected() ) - { - state = BLOOD_LEAK_NORMAL_STATE; - } + bloodLeakGPIOCmd.cmdPrevStatus = bloodLeakSelfTestStatus; } return state; @@ -722,15 +832,19 @@ { BLOOD_LEAK_STATE_T state = BLOOD_LEAK_NORMAL_STATE; - if ( TRUE == noFPGABloodLeakDetected() ) + // TODO remove + /*if ( TRUE == noFPGABloodLeakDetected() ) // TODO remove noFPGABloodLeakDetected() { bloodLeakStatus.data = BLOOD_LEAK_NOT_DETECTED; } else { bloodLeakStatus.data = BLOOD_LEAK_DETECTED; - } + }*/ + // If the blood leak status bit is low (0) it means blood has not been detected, otherwise, blood has been detected + bloodLeakStatus.data = ( BLOOD_LEAK_STATUS_BIT_LOW == getFPGABloodLeakStatus() ? BLOOD_LEAK_NOT_DETECTED : BLOOD_LEAK_DETECTED ); + // Check status reading and act upon if ( BLOOD_LEAK_DETECTED == getBloodLeakStatus() ) { @@ -762,21 +876,16 @@ } } - if ( TRUE == bloodLeakZeroRequested ) - { - state = BLOOD_LEAK_ZERO_STATE; - bloodLeakZeroRequested = FALSE; - - setFPGABloodLeakZero(); - bloodLeakZeroStartTime = getMSTimerCount(); - } - if ( TRUE == bloodLeakExitNormalRequested ) { state = BLOOD_LEAK_INIT_STATE; - bloodLeakZeroRequested = FALSE; bloodLeakExitNormalRequested = FALSE; } + else if ( TRUE == hasZeroBloodLeakBeenRequested() ) + { + // Check whether zeroing the sensor has been requested or not if yes, transition to zero command state otherwise, stay in this state + state = BLOOD_LEAK_PREP_FOR_ZERO_CMD_STATE; + } return state; } @@ -867,56 +976,56 @@ switch( bloodLeakEmbModeRqstedCmd ) { - case NU_EMB_MODE_CMD: - // Null command do nothing - break; + case NU_EMB_MODE_CMD: + // Null command do nothing + break; - case CS_EMB_MODE_CMD: - case T_EMB_MODE_CMD: - case G_EMB_MODE_CMD: - case I_EMB_MODE_CMD: - case V_EMB_MODE_CMD: - case Z_EMB_MODE_CMD: - case Q_EMB_MODE_CMD: - case D_EMB_MODE_CMD: - case C_EMB_MODE_CMD: - // First clear the buffer from the older data - memset( bloodLeakEmbModeCmdSquence, 0x0, BLOOD_LEAK_EMB_MODE_CMD_SEQ_LENGTH ); - // Set the command sequence - bloodLeakEmbModeCmdSquence[ BLOOD_LEAK_EMB_MODE_RESET_INDEX ][ BLOOD_LEAK_EMB_MODE_CMD_COL_INDEX ] = BLOOD_LEAK_EMB_MODE_COMM_RESET; - bloodLeakEmbModeCmdSquence[ BLOOD_LEAK_EMB_MODE_RESET_INDEX ][ BLOOD_LEAK_EMB_MODE_IS_UART_COL_INDEX ] = TRUE; - bloodLeakEmbModeCmdSquence[ BLOOD_LEAK_EMB_MODE_RESET_INDEX + 1 ][ BLOOD_LEAK_EMB_MODE_CMD_COL_INDEX ] = BLOOD_LEAK_EMB_MODE_COMM_ACTIVE_LOW; - bloodLeakEmbModeCmdSquence[ BLOOD_LEAK_EMB_MODE_RESET_INDEX + 1 ][ BLOOD_LEAK_EMB_MODE_IS_UART_COL_INDEX ] = TRUE; - bloodLeakEmbModeCmdSquence[ BLOOD_LEAK_EMB_MODE_CMD_INDEX ][ BLOOD_LEAK_EMB_MODE_CMD_COL_INDEX ] = command; - bloodLeakEmbModeCmdSquence[ BLOOD_LEAK_EMB_MODE_CMD_INDEX ][ BLOOD_LEAK_EMB_MODE_IS_UART_COL_INDEX ] = FALSE; - bloodLeakEmbModeCmdSquence[ BLOOD_LEAK_EMB_MODE_STOP_WRITE_INDEX ][ BLOOD_LEAK_EMB_MODE_CMD_COL_INDEX ] = BLOOD_LEAK_STOP_WRITE_FIFO_COMMAND; - bloodLeakEmbModeCmdSquence[ BLOOD_LEAK_EMB_MODE_STOP_WRITE_INDEX ][ BLOOD_LEAK_EMB_MODE_IS_UART_COL_INDEX ] = FALSE; - bloodLeakEmbModeCmdSquence[ BLOOD_LEAK_EMB_MODE_ACTIVE_HIGH_INDEX ][ BLOOD_LEAK_EMB_MODE_CMD_COL_INDEX ] = BLOOD_LEAK_EMB_MODE_COMM_ACTIVE_HIGH; - bloodLeakEmbModeCmdSquence[ BLOOD_LEAK_EMB_MODE_ACTIVE_HIGH_INDEX ][ BLOOD_LEAK_EMB_MODE_IS_UART_COL_INDEX ] = TRUE; - bloodLeakEmbModeCmdSquence[ BLOOD_LEAK_EMB_MODE_ACTIVE_HIGH_INDEX + 1 ][ BLOOD_LEAK_EMB_MODE_CMD_COL_INDEX ] = BLOOD_LEAK_EMB_MODE_COMM_ACTIVE_LOW; - bloodLeakEmbModeCmdSquence[ BLOOD_LEAK_EMB_MODE_ACTIVE_HIGH_INDEX + 1 ][ BLOOD_LEAK_EMB_MODE_IS_UART_COL_INDEX ] = TRUE; + case CS_EMB_MODE_CMD: + case T_EMB_MODE_CMD: + case G_EMB_MODE_CMD: + case I_EMB_MODE_CMD: + case V_EMB_MODE_CMD: + case Z_EMB_MODE_CMD: + case Q_EMB_MODE_CMD: + case D_EMB_MODE_CMD: + case C_EMB_MODE_CMD: + // First clear the buffer from the older data + memset( bloodLeakEmbModeCmdSquence, 0x0, 2 * BLOOD_LEAK_EMB_MODE_CMD_SEQ_LENGTH ); + // Set the command sequence + bloodLeakEmbModeCmdSquence[ BLOOD_LEAK_EMB_MODE_RESET_INDEX ][ BLOOD_LEAK_EMB_MODE_CMD_COL_INDEX ] = BLOOD_LEAK_EMB_MODE_COMM_RESET; + bloodLeakEmbModeCmdSquence[ BLOOD_LEAK_EMB_MODE_RESET_INDEX ][ BLOOD_LEAK_EMB_MODE_IS_UART_COL_INDEX ] = TRUE; + bloodLeakEmbModeCmdSquence[ BLOOD_LEAK_EMB_MODE_RESET_INDEX + 1 ][ BLOOD_LEAK_EMB_MODE_CMD_COL_INDEX ] = BLOOD_LEAK_EMB_MODE_COMM_ACTIVE_LOW; + bloodLeakEmbModeCmdSquence[ BLOOD_LEAK_EMB_MODE_RESET_INDEX + 1 ][ BLOOD_LEAK_EMB_MODE_IS_UART_COL_INDEX ] = TRUE; + bloodLeakEmbModeCmdSquence[ BLOOD_LEAK_EMB_MODE_CMD_INDEX ][ BLOOD_LEAK_EMB_MODE_CMD_COL_INDEX ] = command; + bloodLeakEmbModeCmdSquence[ BLOOD_LEAK_EMB_MODE_CMD_INDEX ][ BLOOD_LEAK_EMB_MODE_IS_UART_COL_INDEX ] = FALSE; + bloodLeakEmbModeCmdSquence[ BLOOD_LEAK_EMB_MODE_STOP_WRITE_INDEX ][ BLOOD_LEAK_EMB_MODE_CMD_COL_INDEX ] = BLOOD_LEAK_STOP_WRITE_FIFO_COMMAND; + bloodLeakEmbModeCmdSquence[ BLOOD_LEAK_EMB_MODE_STOP_WRITE_INDEX ][ BLOOD_LEAK_EMB_MODE_IS_UART_COL_INDEX ] = FALSE; + bloodLeakEmbModeCmdSquence[ BLOOD_LEAK_EMB_MODE_ACTIVE_HIGH_INDEX ][ BLOOD_LEAK_EMB_MODE_CMD_COL_INDEX ] = BLOOD_LEAK_EMB_MODE_COMM_ACTIVE_HIGH; + bloodLeakEmbModeCmdSquence[ BLOOD_LEAK_EMB_MODE_ACTIVE_HIGH_INDEX ][ BLOOD_LEAK_EMB_MODE_IS_UART_COL_INDEX ] = TRUE; + bloodLeakEmbModeCmdSquence[ BLOOD_LEAK_EMB_MODE_ACTIVE_HIGH_INDEX + 1 ][ BLOOD_LEAK_EMB_MODE_CMD_COL_INDEX ] = BLOOD_LEAK_EMB_MODE_COMM_ACTIVE_LOW; + bloodLeakEmbModeCmdSquence[ BLOOD_LEAK_EMB_MODE_ACTIVE_HIGH_INDEX + 1 ][ BLOOD_LEAK_EMB_MODE_IS_UART_COL_INDEX ] = TRUE; - // Set the variables for the next state - bloodLeakUARTCmdIndex = 0; - bloodLeakEmbModeRespIndex = 0; - bloodLeakEmbModeCmdSeqLength = BLOOD_LEAK_EMB_MODE_CMD_SEQ_LENGTH; - bloodLeakEmbModeOpsStartTime = getMSTimerCount(); - state = BLOOD_LEAK_CAL_SEND_COMMAND_STATE; - // Clear the response buffer to able to receive fresh data - memset( bloodLeakEmbModeRespBuffer, 0x0, BLOOD_LEAK_EMB_MODE_RESP_BUFFER_LEN ); - break; - - case SP_EMB_MODE_CMD: - prepareSetPointSeq( bloodLeakEmbModeSetPoint ); - bloodLeakEmbModeRespIndex = 0; - bloodLeakEmbModeOpsStartTime = getMSTimerCount(); - state = BLOOD_LEAK_CAL_SEND_COMMAND_STATE; - // Clear the command sequence buffer in case it is needed to send byte read request. The byte - // read requests are sent using this buffer while the set point is set using the set point buffer - memset( bloodLeakEmbModeCmdSquence, 0x0, 2 * BLOOD_LEAK_EMB_MODE_CMD_SEQ_LENGTH ); - // Clear the response buffer to able to receive fresh data - memset( bloodLeakEmbModeRespBuffer, 0x0, BLOOD_LEAK_EMB_MODE_RESP_BUFFER_LEN ); + // Set the variables for the next state + bloodLeakUARTCmdIndex = 0; + bloodLeakEmbModeRespIndex = 0; + bloodLeakEmbModeCmdSeqLength = BLOOD_LEAK_EMB_MODE_CMD_SEQ_LENGTH; + bloodLeakEmbModeOpsStartTime = getMSTimerCount(); + state = BLOOD_LEAK_CAL_SEND_COMMAND_STATE; + // Clear the response buffer to able to receive fresh data + memset( bloodLeakEmbModeRespBuffer, 0x0, BLOOD_LEAK_EMB_MODE_RESP_BUFFER_LEN ); break; + + case SP_EMB_MODE_CMD: + prepareSetPointSeq( bloodLeakEmbModeSetPoint ); + bloodLeakEmbModeRespIndex = 0; + bloodLeakEmbModeOpsStartTime = getMSTimerCount(); + state = BLOOD_LEAK_CAL_SEND_COMMAND_STATE; + // Clear the command sequence buffer in case it is needed to send byte read request. The byte + // read requests are sent using this buffer while the set point is set using the set point buffer + memset( bloodLeakEmbModeCmdSquence, 0x0, 2 * BLOOD_LEAK_EMB_MODE_CMD_SEQ_LENGTH ); + // Clear the response buffer to able to receive fresh data + memset( bloodLeakEmbModeRespBuffer, 0x0, BLOOD_LEAK_EMB_MODE_RESP_BUFFER_LEN ); + break; } return state; @@ -1258,7 +1367,7 @@ * @brief * The publishBloodLeakData function publishes blood leak data at the set interval. * @details Inputs: bloodLeakDataPublicationTimerCounter - * @details Outputs: bloodLeakDataPublicationTimerCounter + * @details Outputs: bloodLeakDataPublicatimerCouonTinter * @return none *************************************************************************/ static void publishBloodLeakData( void ) @@ -1267,7 +1376,6 @@ if ( ++bloodLeakDataPublicationTimerCounter >= getU32OverrideValue( &bloodLeakDataPublishInterval ) ) { BLOOD_LEAK_DATA_T data; - data.bloodLeakStatus = (U32)getBloodLeakStatus(); data.bloodLeakState = (U32)bloodLeakState; data.bloodLeakZeroStatusCounter = (U32)getFPGABloodLeakZeroStatusCounter(); @@ -1372,7 +1480,30 @@ bloodLeakEmbModeCmd[ C_EMB_MODE_CMD ].timeoutMS = 5 * MS_PER_SECOND; } +/*********************************************************************//** + * @brief + * The hasZeroBloodLeakBeenRequested function checks whether zeroing blood + * leak has been requested or not. + * @details Inputs: bloodLeakCmd + * @details Outputs: bloodLeakCmd + * @return TURE if request otherwise, FLASE + *************************************************************************/ +static BOOL hasZeroBloodLeakBeenRequested( void ) +{ + BOOL status = FALSE; + if ( TRUE == bloodLeakGPIOCmd.cmdZeroRequested ) + { + status = TRUE; + bloodLeakGPIOCmd.cmdZeroRequested = FALSE; + bloodLeakGPIOCmd.cmdStartTimeMS = getMSTimerCount(); + clearFPGABloodLeakZero(); + } + + return status; +} + + /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/ @@ -1393,8 +1524,7 @@ if ( TRUE == isTestingActivated() ) { - U32 intvl = value / TASK_PRIORITY_INTERVAL; - + U32 intvl = value / TASK_PRIORITY_INTERVAL; result = TRUE; bloodLeakDataPublishInterval.ovData = intvl; bloodLeakDataPublishInterval.override = OVERRIDE_KEY;