Index: firmware/App/Controllers/BloodLeak.c =================================================================== diff -u -rebb4b203609fa7da7137c346c832bd3d0cd54a99 -r8cf95991417ca6c7d9ab9a4ba85e28acb1583899 --- firmware/App/Controllers/BloodLeak.c (.../BloodLeak.c) (revision ebb4b203609fa7da7137c346c832bd3d0cd54a99) +++ firmware/App/Controllers/BloodLeak.c (.../BloodLeak.c) (revision 8cf95991417ca6c7d9ab9a4ba85e28acb1583899) @@ -30,40 +30,57 @@ // ********** 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 500 ///< Blood leak detector timeout for zeroing and self-test (15 ms extended edge detection) -#define BLOOD_LEAK_PERSISTENCE ( 5 * MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) ///< Persistence for blood leak detected alarm. +#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 500 ///< Blood leak detector timeout for zeroing and self-test (15 ms extended edge detection) +#define BLOOD_LEAK_PERSISTENCE ( 5 * 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 in ascii. +#define BLOOD_LEAK_UART_COMM_ACTIVE_LOW 0 ///< Blood leak UART communication active low command. +#define BLOOD_LEAK_UART_COMM_ACTIVE_HIGH 1 ///< Blood leak UART communication active high command. +#define BLOOD_LEAK_STARTUP_SEQUENCE_LENGTH 5 ///< Blood leak start up sequence array length. /// Defined states for the blood leak detector state machine. typedef enum BloodLeakStates { - BLOOD_LEAK_CHECK_SET_POINT_STATE = 0, ///< Check set point state. - BLOOD_LEAK_SET_SET_POINT_STATE, ///< Set set point state. - BLOOD_LEAK_INIT_STATE, ///< Init state. - BLOOD_LEAK_ZERO_STATE, ///< Zero state. - BLOOD_LEAK_SELF_TEST_STATE, ///< Self-test state. - BLOOD_LEAK_NORMAL_STATE, ///< Normal state. - NUM_OF_BLOOD_LEAK_STATES ///< Number of blood leak detector states. + BLOOD_LEAK_START_UP_STATE = 0, ///< Start up state. + 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_ZERO_STATE, ///< Zero state. + BLOOD_LEAK_SELF_TEST_STATE, ///< Self-test state. + BLOOD_LEAK_NORMAL_STATE, ///< Normal state. + NUM_OF_BLOOD_LEAK_STATES ///< Number of blood leak detector states. } BLOOD_LEAK_STATES_T; // ********** private data ********** -static BLOOD_LEAK_STATES_T bloodLeakState; ///< Current 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 BLOOD_LEAK_STATES_T bloodLeakState; ///< Current 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 = FALSE; ///< Blood leak zero requested flag -static U32 bloodLeakZeroStartTime = 0; ///< Blood leak zeroing start time. -static U32 bloodLeakSelfTestStartTime = 0; ///< Blood leak self-test start time. +static BOOL bloodLeakZeroRequested = FALSE; ///< Blood leak zero requested flag +static U32 bloodLeakZeroStartTime = 0; ///< Blood leak zeroing start time. +static U32 bloodLeakSelfTestStartTime = 0; ///< Blood leak self-test start time. -static U32 bloodLeakPersistenceCtr = 0; ///< Blood leak alarm persistence timer counter. +static U32 bloodLeakPersistenceCtr = 0; ///< Blood leak alarm persistence timer counter. 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. + 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. + +/// Blood leak start up sequence array. +static const U08 BLOOD_LEAK_START_UP_SEQUENCE[ BLOOD_LEAK_STARTUP_SEQUENCE_LENGTH ] = { BLOOD_LEAK_RESET_TX_FIFO, + BLOOD_LEAK_UART_COMM_ACTIVE_LOW, + BLOOD_LEAK_START_COMM_CTRL_U_ASCII, + BLOOD_LEAK_UART_COMM_ACTIVE_HIGH, + BLOOD_LEAK_UART_COMM_ACTIVE_LOW }; +static const U32 REMOVE_LATER_SET_POINT = 20; // TODO remove this later + // ********** private function prototypes ********** +static BLOOD_LEAK_STATES_T handleBloodLeakStartupState( void ); static BLOOD_LEAK_STATES_T handleBloodLeakCheckSetPointState( void ); static BLOOD_LEAK_STATES_T handleBloodLeakSetSetPointState( void ); static BLOOD_LEAK_STATES_T handleBloodLeakInitState( void ); @@ -77,12 +94,14 @@ * @brief * The initBloodLeak function initializes the Blood Leak module. * @details Inputs: none - * @details Outputs: Blood Leak module initialized. + * @details Outputs: bloodLeakState, bloodLeakStatus, bloodLeakSelfTestStatus, + * bloodLeakZeroRequested, bloodLeakZeroRequested, bloodLeakSelfTestStartTime, + * bloodLeakUARTCmdIndex * @return none *************************************************************************/ void initBloodLeak( void ) { - bloodLeakState = BLOOD_LEAK_CHECK_SET_POINT_STATE; + bloodLeakState = BLOOD_LEAK_START_UP_STATE; bloodLeakStatus.data = BLOOD_LEAK_NOT_DETECTED; bloodLeakStatus.ovInitData = BLOOD_LEAK_NOT_DETECTED; bloodLeakStatus.ovData = BLOOD_LEAK_NOT_DETECTED; @@ -91,6 +110,7 @@ bloodLeakZeroRequested = FALSE; bloodLeakZeroStartTime = 0; bloodLeakSelfTestStartTime = 0; + bloodLeakUARTCmdIndex = 0; } /*********************************************************************//** @@ -107,6 +127,10 @@ // Execute blood leak state machine switch( bloodLeakState ) { + case BLOOD_LEAK_START_UP_STATE: + bloodLeakState = handleBloodLeakStartupState(); + break; + case BLOOD_LEAK_CHECK_SET_POINT_STATE: bloodLeakState = handleBloodLeakCheckSetPointState(); break; @@ -157,34 +181,78 @@ /*********************************************************************//** * @brief + * The handleBloodLeakStartupState function handles the startup state of the + * of blood leak state machine. + * @details Inputs: bloodLeakUARTCmdIndex + * @details Outputs: bloodLeakUARTCmdIndex + * @return next state + *************************************************************************/ +static BLOOD_LEAK_STATES_T handleBloodLeakStartupState( void ) +{ + BLOOD_LEAK_STATES_T state = BLOOD_LEAK_START_UP_STATE; + + U32 command = BLOOD_LEAK_START_UP_SEQUENCE[ bloodLeakUARTCmdIndex ]; + + if ( BLOOD_LEAK_START_COMM_CTRL_U_ASCII == command ) + { + setFPGABloodLeakUARTTransmit( (U08)command ); + } + else + { + setFPGABloodLeakUARTControl( command ); + } + + if ( bloodLeakUARTCmdIndex > BLOOD_LEAK_STARTUP_SEQUENCE_LENGTH - 1 ) + { + bloodLeakUARTCmdIndex = 0; + state = BLOOD_LEAK_CHECK_SET_POINT_STATE; + } + else + { + bloodLeakUARTCmdIndex++; + } + + return state; +} + +/*********************************************************************//** + * @brief * The handleBloodLeakCheckSetPointState function handles the check set point * state to ensure the set point is set correctly. * @details Inputs: none - * @details Outputs: Blood Leak module init. + * @details Outputs: none * @return next state *************************************************************************/ static BLOOD_LEAK_STATES_T handleBloodLeakCheckSetPointState( void ) { BLOOD_LEAK_STATES_T state = BLOOD_LEAK_CHECK_SET_POINT_STATE; - // TODO remove - state = BLOOD_LEAK_SET_SET_POINT_STATE; - // TODO remove for testing only + U32 bloodLeakSetPoint = (U32)getFPGABloodLeakDetectSetPoint(); + if ( REMOVE_LATER_SET_POINT == bloodLeakSetPoint ) + { + state = BLOOD_LEAK_SET_SET_POINT_STATE; + } + else + { + state = BLOOD_LEAK_INIT_STATE; + } + return state; } /*********************************************************************//** * @brief * The handleBloodLeakSetSetPointState function handles the set set point state. * @details Inputs: none - * @details Outputs: Blood Leak module init. + * @details Outputs: TODO fill up * @return next state *************************************************************************/ static BLOOD_LEAK_STATES_T handleBloodLeakSetSetPointState( void ) { BLOOD_LEAK_STATES_T state = BLOOD_LEAK_SET_SET_POINT_STATE; + // TODO implement the set set point state state = BLOOD_LEAK_INIT_STATE; return state; @@ -195,7 +263,7 @@ * The handleBloodLeakInitState function handles the Blood Leak module in init * state. * @details Inputs: none - * @details Outputs: Blood Leak module init. + * @details Outputs: none * @return next state *************************************************************************/ static BLOOD_LEAK_STATES_T handleBloodLeakInitState( void ) @@ -259,6 +327,7 @@ { BLOOD_LEAK_STATES_T state = BLOOD_LEAK_SELF_TEST_STATE; +#ifndef IGNORE_BLOOD_LEAK_ALARM if ( SELF_TEST_STATUS_IN_PROGRESS == bloodLeakSelfTestStatus ) { if ( FALSE == noFPGABloodLeakDetected() ) // Faked blood leak caused by independent MCU board @@ -269,10 +338,9 @@ else if ( TRUE == didTimeout( bloodLeakSelfTestStartTime, BLOOD_LEAK_TIMEOUT_MS ) ) { bloodLeakSelfTestStatus = SELF_TEST_STATUS_FAILED; -#ifndef IGNORE_BLOOD_LEAK_ALARM + activateAlarmNoData( ALARM_ID_HD_BLOOD_LEAK_SELF_TEST_FAILURE ); -#endif - } + } } else { @@ -282,6 +350,9 @@ state = BLOOD_LEAK_NORMAL_STATE; } } +#else + state = BLOOD_LEAK_NORMAL_STATE; +#endif return state; } @@ -313,9 +384,7 @@ if ( ++bloodLeakPersistenceCtr > BLOOD_LEAK_PERSISTENCE ) { bloodLeakPersistenceCtr = BLOOD_LEAK_PERSISTENCE; -#ifndef IGNORE_BLOOD_LEAK_ALARM activateAlarmNoData( ALARM_ID_HD_BLOOD_LEAK_DETECTED ); -#endif } } else // Blood leak not detected @@ -326,9 +395,7 @@ } else { -#ifndef IGNORE_BLOOD_LEAK_ALARM clearAlarmCondition( ALARM_ID_HD_BLOOD_LEAK_DETECTED ); -#endif } } Index: firmware/App/Services/FPGA.c =================================================================== diff -u -rebb4b203609fa7da7137c346c832bd3d0cd54a99 -r8cf95991417ca6c7d9ab9a4ba85e28acb1583899 --- firmware/App/Services/FPGA.c (.../FPGA.c) (revision ebb4b203609fa7da7137c346c832bd3d0cd54a99) +++ firmware/App/Services/FPGA.c (.../FPGA.c) (revision 8cf95991417ca6c7d9ab9a4ba85e28acb1583899) @@ -2005,9 +2005,9 @@ fpgaActuatorSetPoints.fpgaSensorTest &= ~FPGA_BLOOD_LEAK_SELF_TEST_CMD; } -void setFPGABloodLeakUARTControl( void ) +void setFPGABloodLeakUARTControl( U32 value ) { - fpgaActuatorSetPoints.bloodLeakUARTControl = 21; + fpgaActuatorSetPoints.bloodLeakUARTControl = (U08)value; } void setFPGABloodLeakUARTTransmit( U08 value ) Index: firmware/App/Services/FPGA.h =================================================================== diff -u -rebb4b203609fa7da7137c346c832bd3d0cd54a99 -r8cf95991417ca6c7d9ab9a4ba85e28acb1583899 --- firmware/App/Services/FPGA.h (.../FPGA.h) (revision ebb4b203609fa7da7137c346c832bd3d0cd54a99) +++ firmware/App/Services/FPGA.h (.../FPGA.h) (revision 8cf95991417ca6c7d9ab9a4ba85e28acb1583899) @@ -126,7 +126,7 @@ void setFPGABloodLeakSelfTest( void ); void clearFPGABloodLeakSelfTest( void ); -void setFPGABloodLeakUARTControl( void ); +void setFPGABloodLeakUARTControl( U32 value ); void setFPGABloodLeakUARTTransmit( U08 value ); U08 getFPGABloodLeakZeroStatusCounter( void ); U08 getFPGABloodLeakCounter( void );