Index: firmware/App/Controllers/BloodLeak.c =================================================================== diff -u -r47b10f91b20adc108a417b4e7677c0ccad13a134 -r1e8be8e6cfe034e1f91b6a8842da2c243ec01171 --- firmware/App/Controllers/BloodLeak.c (.../BloodLeak.c) (revision 47b10f91b20adc108a417b4e7677c0ccad13a134) +++ firmware/App/Controllers/BloodLeak.c (.../BloodLeak.c) (revision 1e8be8e6cfe034e1f91b6a8842da2c243ec01171) @@ -61,6 +61,7 @@ #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. @@ -145,14 +146,16 @@ /// Zero command structure typedef struct { - BOOL zeroCmdRequested; ///< Blood leak zero command requested. + 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. -} BLOOD_LEAK_CMD_T; + 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 bloodLeakIsPOSTComplete; ///< Blood leak is POST complete flag. @@ -170,7 +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_CMD_T bloodLeakCmd; ///< Blood leak zero/self test command. +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, @@ -376,13 +379,13 @@ * The zeroBloodLeak function requests that the Blood Leak Detector be * zeroed. * @details Inputs: none - * @details Outputs: bloodLeakCmd.zeroCmdRequested, bloodLeakUARTCmdIndex + * @details Outputs: bloodLeakCmd.cmdZeroRequested, bloodLeakUARTCmdIndex * @return none *************************************************************************/ void zeroBloodLeak( void ) { - bloodLeakCmd.zeroCmdRequested = TRUE; - bloodLeakUARTCmdIndex = 0; + bloodLeakGPIOCmd.cmdZeroRequested = TRUE; + bloodLeakUARTCmdIndex = 0; } /*********************************************************************//** @@ -667,12 +670,12 @@ { // The conditions are met start the command // Start with the previous status bit is high - state = BLOOD_LEAK_ZERO_STATE; - bloodLeakCmd.cmdStartTimeMS = getMSTimerCount(); - bloodLeakCmd.cmdPrevStatus = BLOOD_LEAK_STATUS_BIT_HIGH; + state = BLOOD_LEAK_ZERO_STATE; + bloodLeakGPIOCmd.cmdStartTimeMS = getMSTimerCount(); + bloodLeakGPIOCmd.cmdPrevStatus = BLOOD_LEAK_STATUS_BIT_HIGH; setFPGABloodLeakZero(); } - else if ( TRUE == didTimeout( bloodLeakCmd.cmdStartTimeMS, BLOOD_LEAK_ZERO_CMD_TIMEOUT_MS ) ) + 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 ) @@ -702,14 +705,17 @@ // 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 == bloodLeakCmd.cmdPrevStatus ) && ( BLOOD_LEAK_STATUS_BIT_HIGH == bloodLeakZeroStatus ) ) + if ( ( BLOOD_LEAK_STATUS_BIT_LOW == bloodLeakGPIOCmd.cmdPrevStatus ) && ( BLOOD_LEAK_STATUS_BIT_HIGH == bloodLeakZeroStatus ) ) { // Clear the zero command since it is done and clear the self test since we are getting ready to do a self test. clearFPGABloodLeakZero(); clearFPGABloodLeakSelfTest(); - state = BLOOD_LEAK_PREP_FOR_SELF_TEST_CMD_STATE; + // 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( bloodLeakCmd.cmdStartTimeMS, BLOOD_LEAK_ZERO_CMD_TIMEOUT_MS ) ) + else if ( TRUE == didTimeout( bloodLeakGPIOCmd.cmdStartTimeMS, BLOOD_LEAK_ZERO_CMD_TIMEOUT_MS ) ) { // Zero command timed out #ifndef _RELEASE_ @@ -724,7 +730,7 @@ else { // Update the previous status with the current zero status since the low to high edge has been observed yet - bloodLeakCmd.cmdPrevStatus = bloodLeakZeroStatus; + bloodLeakGPIOCmd.cmdPrevStatus = bloodLeakZeroStatus; } return state; @@ -746,13 +752,17 @@ // 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() ) ) { - // Update the variables and set the self test - state = BLOOD_LEAK_SELF_TEST_STATE; - bloodLeakCmd.cmdStartTimeMS = getMSTimerCount(); - bloodLeakCmd.cmdPrevStatus = BLOOD_LEAK_STATUS_BIT_LOW; - setFPGABloodLeakSelfTest(); + // 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( bloodLeakCmd.cmdStartTimeMS, BLOOD_LEAK_SELF_TEST_CMD_TIMEOUT_MS ) ) + 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 ) @@ -782,14 +792,14 @@ // 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 == bloodLeakCmd.cmdPrevStatus ) && ( BLOOD_LEAK_STATUS_BIT_LOW == bloodLeakSelfTestStatus ) ) + if ( ( BLOOD_LEAK_STATUS_BIT_HIGH == bloodLeakGPIOCmd.cmdPrevStatus ) && ( BLOOD_LEAK_STATUS_BIT_LOW == bloodLeakSelfTestStatus ) ) { // Clear the self test command since it is done clearFPGABloodLeakSelfTest(); state = BLOOD_LEAK_NORMAL_STATE; bloodLeakSelfTestStatus = SELF_TEST_STATUS_PASSED; } - else if ( TRUE == didTimeout( bloodLeakCmd.cmdStartTimeMS, BLOOD_LEAK_SELF_TEST_CMD_TIMEOUT_MS ) ) + 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 ) @@ -803,7 +813,7 @@ } else { - bloodLeakCmd.cmdPrevStatus = bloodLeakSelfTestStatus; + bloodLeakGPIOCmd.cmdPrevStatus = bloodLeakSelfTestStatus; } return state; @@ -1354,7 +1364,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 ) @@ -1363,7 +1373,6 @@ if ( ++bloodLeakDataPublicationTimerCounter >= getU32OverrideValue( &bloodLeakDataPublishInterval ) ) { BLOOD_LEAK_DATA_T data; - data.bloodLeakStatus = (U32)getBloodLeakStatus(); data.bloodLeakState = (U32)bloodLeakState; data.bloodLeakZeroStatusCounter = (U32)getFPGABloodLeakZeroStatusCounter(); @@ -1480,11 +1489,11 @@ { BOOL status = FALSE; - if ( TRUE == bloodLeakCmd.zeroCmdRequested ) + if ( TRUE == bloodLeakGPIOCmd.cmdZeroRequested ) { - status = TRUE; - bloodLeakCmd.zeroCmdRequested = FALSE; - bloodLeakCmd.cmdStartTimeMS = getMSTimerCount(); + status = TRUE; + bloodLeakGPIOCmd.cmdZeroRequested = FALSE; + bloodLeakGPIOCmd.cmdStartTimeMS = getMSTimerCount(); clearFPGABloodLeakZero(); } @@ -1512,8 +1521,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;