Index: firmware/App/Controllers/BloodLeak.c =================================================================== diff -u -r6b26db807411a42b2365d47caeb94a1b852e85bb -r4311dd4997aaaa97fe2a1878151145a92e5491e2 --- firmware/App/Controllers/BloodLeak.c (.../BloodLeak.c) (revision 6b26db807411a42b2365d47caeb94a1b852e85bb) +++ firmware/App/Controllers/BloodLeak.c (.../BloodLeak.c) (revision 4311dd4997aaaa97fe2a1878151145a92e5491e2) @@ -90,8 +90,11 @@ #define BLOOD_LEAK_EMB_MODE_NUM_OF_INFO_CMDS 3 ///< Blood leak embedded mode number of informative commands. #define BLOOD_LEAK_FPGA_ERROR_TIMEOUT_MS ( 2 * MS_PER_SECOND ) ///< Blood leak embedded mode FPGA error timeout in milliseconds. -#define BLOOD_LEAK_RXFIFO_COUNT_MASK 0x03ff ///< Mask high order bits of blood leak sensor rx count +#define BLOOD_LEAK_RXFIFO_COUNT_MASK 0x03FF ///< Mask high order bits of blood leak sensor rx count +#define MAX_BLOOD_LEAK_COMM_FAILURES_WINDOW_MS ( 1 * SEC_PER_MIN * MS_PER_SECOND ) ///< Blood Leak comm failures window +#define MAX_BLOOD_LEAK_COMM_FAILURES 3 ///< Blood Leak maximum comm failures per MAX_BLOOD_LEAK_COMM_FAILURES_WINDOW_MS + /// Defined states for the blood leak detector state machine. typedef enum BloodLeakStates { @@ -261,12 +264,13 @@ // Initialize the blood leak embedded mode command sequence memset( bloodLeakEmbModeCmdSeq, 0x0, BLOOD_LEAK_EMB_MODE_CMD_SEQ_LENGTH ); - initFPGAPersistentAlarm( FPGA_PERS_ERROR_BLOOD_LEAK_SENSOR, ALARM_ID_HD_BLOOD_LEAK_FPGA_FAULT, - BLOOD_LEAK_FPGA_ERROR_TIMEOUT_MS, BLOOD_LEAK_FPGA_ERROR_TIMEOUT_MS ); - // Enqueue the commands to set the embedded mode and request the set point of the blood leak sensor enqueueEmbModeCmd( CS_EMB_MODE_CMD ); 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); + } /*********************************************************************//** @@ -315,8 +319,6 @@ enqueueInfoEmbModeCmds(); - checkFPGAPersistentErrorCountAlarm( FPGA_PERS_ERROR_BLOOD_LEAK_SENSOR, getFPGABloodLeakRxErrorCount() ); - // Publish blood leak data if due publishBloodLeakData(); } @@ -344,6 +346,11 @@ case BLOOD_LEAK_EMB_MODE_WAIT_FOR_COMMAND_RESPONSE_STATE: bloodLeakEmbModeSubstate = handleBloodLeakEmbModeWaitForCommandResponseState(); break; + + default: + SET_ALARM_WITH_1_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_BLOOD_LEAK_EMBEDDED_MODE_INVALID_STATE ) + bloodLeakEmbModeSubstate = BLOOD_LEAK_EMB_MODE_WAIT_FOR_COMAND_STATE; + break; } } @@ -561,6 +568,10 @@ // All the commands shall be processed and have data prior to checking the results areCommandsReady &= bloodLeakEmbModeCmd[ i ].isCmdRespRdy; break; + + default: + // Do nothing with the rest of the commands + break; } } @@ -591,6 +602,10 @@ hasCmdSqncFailed |= hasCurrCmdFailed; failedCmd = ( TRUE == hasCurrCmdFailed ? i : NU_EMB_MODE_CMD ); break; + + default: + // Do nothing with the rest of the commands + break; } } @@ -924,7 +939,8 @@ { // If the element in the first index of the command sequence buffer is the read a byte request, set the variable to TRUE so the // wait for data to receive state knows that the request has been sent and it can read the byte. - U08 commandInIndex0 = bloodLeakEmbModeCmdSeq[ BLOOD_LEAK_EMB_MODE_REQUEST_RX_INDEX ][ BLOOD_LEAK_EMB_MODE_CMD_COL_INDEX ]; + U08 commandInIndex0 = bloodLeakEmbModeCmdSeq[ BLOOD_LEAK_EMB_MODE_REQUEST_RX_INDEX ][ BLOOD_LEAK_EMB_MODE_CMD_COL_INDEX ]; + bloodLeakEmbModeHasRxRqstBeenSent = ( BLOOD_LEAK_EMB_MODE_COMM_READ_REQST == commandInIndex0 ? TRUE : FALSE ); bloodLeakUARTCmdIndex = 0; bloodLeakEmbModeCmdSeqLength = 0; @@ -1041,6 +1057,11 @@ bloodLeakEmbModeRqstedCmd = NU_EMB_MODE_CMD; state = BLOOD_LEAK_EMB_MODE_WAIT_FOR_COMAND_STATE; + + if ( TRUE == incTimeWindowedCount( TIME_WINDOWED_COUNT_BLOOD_LEAK_COMM_ERROR ) ) + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_BLOOD_LEAK_FPGA_FAULT, MAX_BLOOD_LEAK_COMM_FAILURES, (U32)MAX_BLOOD_LEAK_COMM_FAILURES_WINDOW_MS ) + } } return state; @@ -1254,6 +1275,7 @@ data.bloodLeakStatus = (U32)getBloodLeakStatus(); data.bloodLeakState = (U32)bloodLeakState; + data.bloodLeakPersitentCounter = bloodLeakPersistenceCtr; bloodLeakDataPublicationCounter = 0; broadcastData( MSG_ID_HD_BLOOD_LEAK_DATA, COMM_BUFFER_OUT_CAN_HD_BROADCAST, (U08*)&data, sizeof( BLOOD_LEAK_DATA_T ) ); @@ -1484,7 +1506,20 @@ } } +/*********************************************************************//** + * @brief + * The getBloodLeakRxBytesAvailable function returns the number of received + * bytes available from FPGA. + * @details Inputs: none + * @details Outputs: none + * @return Number of received bytes available + *************************************************************************/ +static U16 getBloodLeakRxBytesAvailable( void ) +{ + return getFPGABloodLeakRxFIFOCount() & BLOOD_LEAK_RXFIFO_COUNT_MASK; +} + /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/ @@ -1641,9 +1676,4 @@ return result; } -static U16 getBloodLeakRxBytesAvailable( void ) -{ - return getFPGABloodLeakRxFIFOCount() & BLOOD_LEAK_RXFIFO_COUNT_MASK; -} - /**@}*/