Index: firmware/App/Controllers/BloodLeak.c =================================================================== diff -u -rf1157c760b320bf088921a25eb78e973d6341578 -r1ab9ca9bc191f87901a3b827ecd85fe3b96dc6ed --- firmware/App/Controllers/BloodLeak.c (.../BloodLeak.c) (revision f1157c760b320bf088921a25eb78e973d6341578) +++ firmware/App/Controllers/BloodLeak.c (.../BloodLeak.c) (revision 1ab9ca9bc191f87901a3b827ecd85fe3b96dc6ed) @@ -140,7 +140,7 @@ U32 length; ///< Blood leak sensor expected response length in bytes. U32 timeoutMS; ///< Blood leak sensor receive timeout in milliseconds. U32 commandResp; ///< Blood leak sensor command response back. - U08 commandRetryCount; ///< Blood leak sensor command retry count. + U08 commandRqstCount; ///< Blood leak sensor command request count. BOOL isCmdRespRdy; ///< Blood leak sensor is command response ready flag. } EMB_MODE_CMD_T; @@ -204,6 +204,7 @@ static U32 getAvailableEmbModeQueueCount( void ); static void enqueueInfoEmbModeCmds( void ); static U16 getBloodLeakRxBytesAvailable( void ); +static void resetEmbModeCmdRqstCount( U08 cmd ); /*********************************************************************//** * @brief @@ -269,8 +270,7 @@ enqueueEmbModeCmd( D_EMB_MODE_CMD ); // initialize FPGA comm failures windowed timer count - initTimeWindowedCount( TIME_WINDOWED_COUNT_BLOOD_LEAK_COMM_ERROR, MAX_BLOOD_LEAK_COMM_FAILURES, MAX_BLOOD_LEAK_COMM_FAILURES_WINDOW_MS); - + initTimeWindowedCount( TIME_WINDOWED_COUNT_BLOOD_LEAK_COMM_ERROR, MAX_BLOOD_LEAK_COMM_FAILURES, MAX_BLOOD_LEAK_COMM_FAILURES_WINDOW_MS ); } /*********************************************************************//** @@ -360,7 +360,7 @@ * zeroed. * @details Inputs: bloodLeakEmbModeCmdEnqueueCount * @details Outputs: bloodLeakEmbModeHasZeroBeenRqustd, - * bloodLeakEmbModeCmdEnqueueCount + * bloodLeakEmbModeCmdEnqueueCount, bloodLeakSelfTestStatus * @return TRUE if the zero commands were successfully queued otherwise, FALSE *************************************************************************/ BOOL zeroBloodLeak( void ) @@ -371,16 +371,16 @@ { status = TRUE; bloodLeakEmbModeHasZeroBeenRqustd = TRUE; + // Since the zero commands have been queued, reset the counter + bloodLeakEmbModeCmdEnqueueCount = 0; + bloodLeakSelfTestStatus = SELF_TEST_STATUS_IN_PROGRESS; // Enqueue the zero and self test sequence (Z->G->Z->Q->T) enqueueEmbModeCmd( Z_EMB_MODE_CMD ); enqueueEmbModeCmd( G_EMB_MODE_CMD ); enqueueEmbModeCmd( Z_EMB_MODE_CMD ); enqueueEmbModeCmd( Q_EMB_MODE_CMD ); enqueueEmbModeCmd( T_EMB_MODE_CMD ); - - // Since the zero commands have been queued, reset the counter - bloodLeakEmbModeCmdEnqueueCount = 0; } else if ( ++bloodLeakEmbModeCmdEnqueueCount > BLOOD_LEAK_EMB_MODE_MAX_NUM_CMD_TRIES ) { @@ -392,6 +392,24 @@ /*********************************************************************//** * @brief + * The hasBloodLeakZeroSequenceFailed function returns TURE if the number + * of times the zero sequence has failed. + * @details Inputs: bloodLeakEmbModeCmd + * @details Outputs: none + * @return TRUE if zero sequence failed otherwise, FALSE + *************************************************************************/ +BOOL hasBloodLeakZeroSequenceFailed( void ) +{ + // The zero sequence contains Z->G->Z->Q->T and each of the commands has a request counter but for checking whether the + // zero sequence has failed only the Z command is checked. When the zero sequence is enqueued, all of the them enqueued so they are + // at the same request count number. + BOOL status = ( bloodLeakEmbModeCmd[ G_EMB_MODE_CMD ].commandRqstCount > BLOOD_LEAK_EMB_MODE_MAX_NUM_CMD_TRIES ? TRUE : FALSE ); + + return status; +} + +/*********************************************************************//** + * @brief * The exitBloodLeakNormalState requests that the blood leak sensor to exit * its normal state. * @details Inputs: bloodLeakState @@ -453,7 +471,7 @@ } else if ( ( TRUE == bloodLeakEmbModeCmd[ CS_EMB_MODE_CMD ].isCmdRespRdy ) && ( BLOOD_LEAK_EMB_MODE_FAIL_ASCII == cmdResp ) ) { - if ( ++bloodLeakEmbModeCmd[ CS_EMB_MODE_CMD ].commandRetryCount < BLOOD_LEAK_EMB_MODE_MAX_NUM_CMD_TRIES ) + if ( bloodLeakEmbModeCmd[ CS_EMB_MODE_CMD ].commandRqstCount < BLOOD_LEAK_EMB_MODE_MAX_NUM_CMD_TRIES ) { // Enqueue the commands to set the embedded mode and request the set point of the blood leak sensor // Since set point was requested in the init function as well, both are requested here because we have to be @@ -474,8 +492,8 @@ if ( ( getCurrentOperationMode() != MODE_INIT ) && ( TRUE == isEmbModeReady ) ) { - bloodLeakEmbModeCmd[ CS_EMB_MODE_CMD ].commandRetryCount = 0; - state = BLOOD_LEAK_CHECK_SET_POINT_STATE; + resetEmbModeCmdRqstCount( CS_EMB_MODE_CMD ); + state = BLOOD_LEAK_CHECK_SET_POINT_STATE; } return state; @@ -497,7 +515,7 @@ if ( ( bloodLeakSetPoint != bloodLeakCalRecord.setPoint ) && ( TRUE == isCommandRespReady ) ) { - if ( ++bloodLeakEmbModeCmd[ D_EMB_MODE_CMD ].commandRetryCount < BLOOD_LEAK_EMB_MODE_MAX_NUM_CMD_TRIES ) + if ( bloodLeakEmbModeCmd[ D_EMB_MODE_CMD ].commandRqstCount < BLOOD_LEAK_EMB_MODE_MAX_NUM_CMD_TRIES ) { enqueueEmbModeCmd( D_EMB_MODE_CMD ); } @@ -513,8 +531,8 @@ } else if ( TRUE == isCommandRespReady ) { - bloodLeakEmbModeCmd[ D_EMB_MODE_CMD ].commandRetryCount = 0; - state = BLOOD_LEAK_INIT_STATE; + resetEmbModeCmdRqstCount( D_EMB_MODE_CMD ); + state = BLOOD_LEAK_INIT_STATE; } return state; @@ -535,7 +553,8 @@ // Check if the zero command has been requested if ( TRUE == bloodLeakEmbModeHasZeroBeenRqustd ) { - state = BLOOD_LEAK_CHECK_ZERO_AND_SELF_TEST_STATE; + bloodLeakEmbModeHasZeroBeenRqustd = FALSE; + state = BLOOD_LEAK_CHECK_ZERO_AND_SELF_TEST_STATE; } return state; @@ -613,34 +632,18 @@ if ( FALSE == hasCmdSqncFailed ) { // Done with zero sequence, transition to other states - bloodLeakEmbModeCmd[ Z_EMB_MODE_CMD ].commandRetryCount = 0; - bloodLeakEmbModeHasZeroBeenRqustd = FALSE; - bloodLeakSelfTestStatus = SELF_TEST_STATUS_PASSED; - state = BLOOD_LEAK_NORMAL_STATE; + resetEmbModeCmdRqstCount( Z_EMB_MODE_CMD ); + resetEmbModeCmdRqstCount( G_EMB_MODE_CMD ); + resetEmbModeCmdRqstCount( Q_EMB_MODE_CMD ); + resetEmbModeCmdRqstCount( T_EMB_MODE_CMD ); + bloodLeakSelfTestStatus = SELF_TEST_STATUS_PASSED; + state = BLOOD_LEAK_NORMAL_STATE; } // If not successful, retry if we've not run out - else if ( bloodLeakEmbModeCmd[ Z_EMB_MODE_CMD ].commandRetryCount < BLOOD_LEAK_EMB_MODE_MAX_NUM_CMD_TRIES ) - { - if ( TRUE == zeroBloodLeak() ) - { - // Check if the zero sequence has been successfully enqueued - // If the command retry of one of the commands in the zero sequence failed, it means all of them have failed - // So in this condition only the Z command is checked - bloodLeakEmbModeCmd[ Z_EMB_MODE_CMD ].commandRetryCount++; - } - } - // If out of retries, fault else { -#ifndef _RELEASE_ - if ( getSoftwareConfigStatus( SW_CONFIG_DISABLE_BLOOD_LEAK_ALARM ) != SW_CONFIG_ENABLE_VALUE ) -#endif - { - bloodLeakSelfTestStatus = SELF_TEST_STATUS_FAILED; - state = BLOOD_LEAK_INIT_STATE; - - SET_ALARM_WITH_1_U32_DATA( ALARM_ID_HD_BLOOD_LEAK_SENSOR_ZERO_SEQUENCE_FAILED, failedCmd ); - } + bloodLeakSelfTestStatus = SELF_TEST_STATUS_FAILED; + state = BLOOD_LEAK_INIT_STATE; } } @@ -681,7 +684,8 @@ } // Check status reading and act upon - if ( ( BLOOD_LEAK_DETECTED == getBloodLeakStatus() ) && ( MODE_TREA == getCurrentOperationMode() ) ) + // Only check the blood detection in treatment mode and service mode for testing in manufacturing + if ( ( BLOOD_LEAK_DETECTED == getBloodLeakStatus() ) && ( ( MODE_TREA == getCurrentOperationMode() ) || ( MODE_SERV == getCurrentOperationMode() ) ) ) { if ( ++bloodLeakPersistenceCtr > BLOOD_LEAK_PERSISTENCE ) { @@ -1399,6 +1403,7 @@ * @details Inputs: none * @details Outputs: bloodLeakEmbModeCmdQRearIndex, bloodLeakEmbModeCmdQCount * bloodLeakEmbModeCmdQ, bloodLeakEmbModeCmd + * @param cmd the command to enqueue * @return none *************************************************************************/ static void enqueueEmbModeCmd( U08 cmd ) @@ -1408,11 +1413,26 @@ bloodLeakEmbModeCmdQ[ bloodLeakEmbModeCmdQRearIndex ] = cmd; bloodLeakEmbModeCmdQRearIndex = INC_WRAP( bloodLeakEmbModeCmdQRearIndex, 0, BLOOD_LEAK_EMB_MODE_CMD_Q_MAX_SIZE - 1 ); bloodLeakEmbModeCmd[ cmd ].isCmdRespRdy = FALSE; + bloodLeakEmbModeCmd[ cmd ].commandRqstCount++; bloodLeakEmbModeCmdQCount++; } /*********************************************************************//** * @brief + * The resetEmbModeCmdRqstCount function resets embedded mode command request + * count. + * @details Inputs: none + * @details Outputs: bloodLeakEmbModeCmd + * @param cmd the command to reset its request count + * @return none + *************************************************************************/ +static void resetEmbModeCmdRqstCount( U08 cmd ) +{ + bloodLeakEmbModeCmd[ cmd ].commandRqstCount = 0; +} + +/*********************************************************************//** + * @brief * The dequeueEmbModeCmd function dequeues the embedded mode command. * @details Inputs: none * @details Outputs: bloodLeakEmbModeCmdQFrontIndex, bloodLeakEmbModeCmdQCount