Index: firmware/App/Controllers/BloodLeak.c =================================================================== diff -u -rd558c3058a027d8f4407c7bb882505e30225a7f9 -r91913f55375f8e6b3e443c154a3132e9f4ef54af --- firmware/App/Controllers/BloodLeak.c (.../BloodLeak.c) (revision d558c3058a027d8f4407c7bb882505e30225a7f9) +++ firmware/App/Controllers/BloodLeak.c (.../BloodLeak.c) (revision 91913f55375f8e6b3e443c154a3132e9f4ef54af) @@ -62,18 +62,21 @@ #define DATA_PUBLISH_COUNTER_START_COUNT 60 ///< Data publish counter start count. // Embedded mode defines -#define BLOOD_LEAK_EMB_MODE_CMD_SEQ_LENGTH 4 ///< Blood leak embedded mode command sequence length. -#define BLOOD_LEAK_EMB_MODE_STOP_INDEX 1 ///< Blood leak embedded mode stop writing to FIFO index. +#define BLOOD_LEAK_EMB_MODE_CMD_SEQ_LENGTH 6 ///< Blood leak embedded mode command sequence length. +#define BLOOD_LEAK_EMB_MODE_STOP_INDEX 1 // TODO remove ///< Blood leak embedded mode stop writing to FIFO index. #define BLOOD_LEAK_EMB_MODE_COMM_ACTIVE_HIGH 5 ///< Blood leak embedded mode communication active high command. #define BLOOD_LEAK_EMB_MODE_COMM_ACTIVE_LOW 4 ///< Blood leak embedded mode communication active low command. -#define BLOOD_LEAK_EMB_MODE_COMM_READ_REQST 8 ///< Blood leak embedded mode communication read Rx byte request. -#define BLOOD_LEAK_EMB_MODE_RX_TIMEOUT_MS ( 5 * MS_PER_SECOND ) ///< Blood leak embedded mode calibration receive timeout in milliseconds. +#define BLOOD_LEAK_EMB_MODE_COMM_RESET 6 ///< Blood leak embedded mode communication reset. +#define BLOOD_LEAK_EMB_MODE_COMM_READ_REQST 12 ///< Blood leak embedded mode communication read Rx byte request. +#define BLOOD_LEAK_EMB_MODE_RX_TIMEOUT_MS ( 5 * MS_PER_SECOND ) // TODO remove ///< Blood leak embedded mode calibration receive timeout in milliseconds. #define BLOOD_LEAK_EMB_MODE_RX_BUFFER_EMPTY 0x80 ///< Blood leak embedded mode buffer empty value. #define BLOOD_LEAK_EMB_MODE_RESP_BUFFER_LEN 5 ///< Blood leak embedded mode number of commands. #define BLOOD_LEAK_EMB_MODE_MAX_NUM_CMD_TRIES 4 ///< Blood leak embedded mode max number of command tries. #define BLOOD_LEAK_EMB_MODE_0_NUM_ASCII 48 ///< Blood leak embedded mode character 0 in ASCII. #define BLOOD_LEAK_EMB_MODE_9_NUM_ASCII 57 ///< Blood leak embedded mode character 9 in ASCII. #define BLOOD_LEAK_EMB_MODE_SET_PNT_RESP_LEN 4 ///< Blood leak embedded mode set point response length. +#define BLOOD_LEAK_EMB_MODE_CMD_COL_INDEX 0 ///< Blood leak embedded mode command (UART/Transmit) column index number. +#define BLOOD_LEAK_EMB_MODE_IS_UART_COL_INDEX 1 ///< Blood leak embedded mode is command type UART or transmit flag. /// Defined states for the blood leak detector state machine. typedef enum BloodLeakStates @@ -123,6 +126,7 @@ U08 expChar1; ///< Blood leak sensor expected response in character. U08 expChar2; ///< Blood leak sensor expected response in character. U08 length; ///< Blood leak sensor expected response length in bytes. + U32 timeout; ///< Blood leak sensor receive timeout. } EMB_MODE_CMD_T; // ********** private data ********** @@ -161,15 +165,18 @@ // Embedded mode variables static BOOL bloodLeakSignalEmbModeReq; ///< Blood leak signal embedded mode has been requested. static U08 bloodLeakEmbModeRqstedCmd; ///< Blood leak signal embedded mode requested command. -static U08 bloodLeakEmbModeCmdSquence[ BLOOD_LEAK_EMB_MODE_CMD_SEQ_LENGTH ]; ///< Blood leak embedded mode command sequence. +// TOOD this has changed for the systems team testing +static U08 bloodLeakEmbModeCmdSquence[ BLOOD_LEAK_EMB_MODE_CMD_SEQ_LENGTH ][ 2 ]; ///< Blood leak embedded mode command sequence. static BLOOD_LEAK_EMB_MODE_STATE_T bloodLeakEmbModeSubstate; ///< Blood leak embedded mode state. static U32 bloodLeakEmbModeOpsStartTime; ///< Blood leak embedded mode operations start time. static U16 bloodLeakEmbModeSetPoint; ///< Blood leak embedded mode set point command. static EMB_MODE_CMD_T bloodLeakEmbModeCmd [ NUM_OF_EMB_CMDS ]; ///< Blood leak embedded mode commands. static U08 bloodLeakEmbModeRespBuffer[ BLOOD_LEAK_EMB_MODE_RESP_BUFFER_LEN ]; ///< Blood leak embedded mode response buffer. static U32 bloodLeakEmbModeRespIndex; ///< Blood leak embedded mode response buffer index. -static U32 bloodLeakEmbModeNumOfCmdTries; ///< Blood leak embedded mode number of command trials. +static U32 bloodLeakEmbModeNumOfCmdTries; // TODO remove? ///< Blood leak embedded mode number of command trials. +static BOOL areTempDone; + // ********** private function prototypes ********** static BLOOD_LEAK_STATE_T handleBloodLeakWaitForPostState( void ); @@ -240,15 +247,31 @@ memset( bloodLeakEmbModeRespBuffer, 0x0, BLOOD_LEAK_EMB_MODE_RESP_BUFFER_LEN ); // Initialize the blood leak calibration command sequence array. - // The first index is the command character so it can be changed upon request. - // The rest of the commands are never changing. - bloodLeakEmbModeCmdSquence[ 0 ] = 0; - bloodLeakEmbModeCmdSquence[ 1 ] = BLOOD_LEAK_STOP_WRITE_FIFO_COMMAND; - bloodLeakEmbModeCmdSquence[ 2 ] = BLOOD_LEAK_EMB_MODE_COMM_ACTIVE_HIGH; - bloodLeakEmbModeCmdSquence[ 3 ] = BLOOD_LEAK_EMB_MODE_COMM_ACTIVE_LOW; + bloodLeakEmbModeCmdSquence[ 0 ][ BLOOD_LEAK_EMB_MODE_CMD_COL_INDEX ] = BLOOD_LEAK_EMB_MODE_COMM_RESET; + bloodLeakEmbModeCmdSquence[ 0 ][ BLOOD_LEAK_EMB_MODE_IS_UART_COL_INDEX ] = TRUE; + bloodLeakEmbModeCmdSquence[ 1 ][ BLOOD_LEAK_EMB_MODE_CMD_COL_INDEX ] = BLOOD_LEAK_EMB_MODE_COMM_ACTIVE_LOW; + bloodLeakEmbModeCmdSquence[ 1 ][ BLOOD_LEAK_EMB_MODE_IS_UART_COL_INDEX ] = TRUE; + + bloodLeakEmbModeCmdSquence[ 2 ][ BLOOD_LEAK_EMB_MODE_CMD_COL_INDEX ] = NU_EMB_MODE_CMD; + bloodLeakEmbModeCmdSquence[ 2 ][ BLOOD_LEAK_EMB_MODE_IS_UART_COL_INDEX ] = FALSE; + + bloodLeakEmbModeCmdSquence[ 3 ][ BLOOD_LEAK_EMB_MODE_CMD_COL_INDEX ] = BLOOD_LEAK_STOP_WRITE_FIFO_COMMAND; + bloodLeakEmbModeCmdSquence[ 3 ][ BLOOD_LEAK_EMB_MODE_IS_UART_COL_INDEX ] = FALSE; + + bloodLeakEmbModeCmdSquence[ 4 ][ BLOOD_LEAK_EMB_MODE_CMD_COL_INDEX ] = BLOOD_LEAK_EMB_MODE_COMM_ACTIVE_HIGH; + bloodLeakEmbModeCmdSquence[ 4 ][ BLOOD_LEAK_EMB_MODE_IS_UART_COL_INDEX ] = TRUE; + + bloodLeakEmbModeCmdSquence[ 5 ][ BLOOD_LEAK_EMB_MODE_CMD_COL_INDEX ] = BLOOD_LEAK_EMB_MODE_COMM_ACTIVE_LOW; + bloodLeakEmbModeCmdSquence[ 5 ][ BLOOD_LEAK_EMB_MODE_IS_UART_COL_INDEX ] = TRUE; + + //bloodLeakEmbModeCmdSquence[ 5 ][ BLOOD_LEAK_EMB_MODE_CMD_COL_INDEX ] = BLOOD_LEAK_EMB_MODE_COMM_READ_REQST; + //bloodLeakEmbModeCmdSquence[ 5 ][ BLOOD_LEAK_EMB_MODE_IS_UART_COL_INDEX ] = TRUE; + // Initialize the embedded mode specifications initEmbModeSpecs(); + + areTempDone = TRUE; } /*********************************************************************//** @@ -419,7 +442,10 @@ // Read the value that is in the FPGA counter so it can be used to make sure the blood leak is communicating after // sending Ctrl U bloodLeakPrevFPGARegisterCount = getFPGABloodLeakRegisterCounter(); - state = BLOOD_LEAK_START_UP_STATE; + // 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 } return state; @@ -851,9 +877,8 @@ static BLOOD_LEAK_EMB_MODE_STATE_T handleCalBloodLeakWaitForCommandState( void ) { BLOOD_LEAK_EMB_MODE_STATE_T state = BLOOD_LEAK_CAL_WAIT_FOR_COMAND_STATE; + U08 test = getFPGABloodLeakTxFIFOCount(); - U08 test = getFPGABloodLeakTxFIFOCount(); - switch( bloodLeakEmbModeRqstedCmd ) { case NU_EMB_MODE_CMD: @@ -871,10 +896,12 @@ case C_EMB_MODE_CMD: // The requested command is not set point and so update the command sequence buffer. // The first index of calibration command sequence is the requested command in ASCII. - bloodLeakEmbModeCmdSquence[ 0 ] = bloodLeakEmbModeCmd[ bloodLeakEmbModeRqstedCmd ].commandASCII; - bloodLeakUARTCmdIndex = 0; - bloodLeakEmbModeNumOfCmdTries = 0; - state = BLOOD_LEAK_CAL_SEND_COMMAND_STATE; + bloodLeakEmbModeCmdSquence[ 2 ][ BLOOD_LEAK_EMB_MODE_CMD_COL_INDEX ] = bloodLeakEmbModeCmd[ bloodLeakEmbModeRqstedCmd ].commandASCII; + bloodLeakUARTCmdIndex = 0; + bloodLeakEmbModeNumOfCmdTries = 0; + state = BLOOD_LEAK_CAL_SEND_COMMAND_STATE; + + areTempDone = FALSE; break; case SP_EMB_MODE_CMD: @@ -898,10 +925,9 @@ *************************************************************************/ static BLOOD_LEAK_EMB_MODE_STATE_T handleCalBloodLeakSendCommandState( void ) { - U32 command; - + U08 command; BLOOD_LEAK_EMB_MODE_STATE_T state = BLOOD_LEAK_CAL_SEND_COMMAND_STATE; - BOOL isUARTTxDone = FALSE; + BOOL isUARTCtrlCmd = FALSE; BOOL isUARTCtrlDone = TRUE; switch ( bloodLeakEmbModeRqstedCmd ) @@ -915,8 +941,8 @@ case Q_EMB_MODE_CMD: case D_EMB_MODE_CMD: case C_EMB_MODE_CMD: - command = bloodLeakEmbModeCmdSquence[ bloodLeakUARTCmdIndex ]; - isUARTTxDone = ( bloodLeakUARTCmdIndex <= BLOOD_LEAK_EMB_MODE_STOP_INDEX ? FALSE : TRUE ); + command = bloodLeakEmbModeCmdSquence[ bloodLeakUARTCmdIndex ][ BLOOD_LEAK_EMB_MODE_CMD_COL_INDEX ]; + isUARTCtrlCmd = bloodLeakEmbModeCmdSquence[ bloodLeakUARTCmdIndex ][ BLOOD_LEAK_EMB_MODE_IS_UART_COL_INDEX ]; isUARTCtrlDone = ( bloodLeakUARTCmdIndex > ( BLOOD_LEAK_EMB_MODE_CMD_SEQ_LENGTH - 1 ) ? TRUE : FALSE ); bloodLeakUARTCmdIndex++; break; @@ -928,27 +954,28 @@ // The active high index is the length - 2 they are the last two elements U32 activeHighIndex = bloodLeakSetPointSeqLength - 2; command = bloodLeakSetPointSequence[ bloodLeakUARTCmdIndex ]; - isUARTTxDone = ( bloodLeakUARTCmdIndex >= activeHighIndex ? TRUE : FALSE ); + isUARTCtrlCmd = ( bloodLeakUARTCmdIndex >= activeHighIndex ? TRUE : FALSE ); isUARTCtrlDone = ( bloodLeakUARTCmdIndex > bloodLeakSetPointSeqLength ? TRUE : FALSE ); bloodLeakUARTCmdIndex++; } break; - } // Check if the current index towards the end of the buffer which are FIFO set and FIFO reset if ( FALSE == isUARTCtrlDone ) { // TODO test this - //FALSE == isUARTTxDone ? setFPGABloodLeakUARTTransmit( (U08)command ) : setFPGABloodLeakUARTControl( (U08)command ); + //FALSE == isUARTCtrlCmd ? setFPGABloodLeakUARTTransmit( command ) : setFPGABloodLeakUARTControl( command ); - if( FALSE == isUARTTxDone ) + U08 test = getFPGABloodLeakTxFIFOCount(); + + if( FALSE == isUARTCtrlCmd ) { - setFPGABloodLeakUARTTransmit( (U08)command ); + setFPGABloodLeakUARTTransmit( command ); } else { - setFPGABloodLeakUARTControl( (U08)command ); + setFPGABloodLeakUARTControl( command ); } } else @@ -959,9 +986,9 @@ bloodLeakEmbModeRespIndex = 0; state = BLOOD_LEAK_CAL_WAIT_FOR_COMMAND_RESPONSE_STATE; + areTempDone = TRUE; + memset( bloodLeakEmbModeRespBuffer, 0x0, BLOOD_LEAK_EMB_MODE_RESP_BUFFER_LEN ); - // TODO is this the right place for the first request? - setFPGABloodLeakUARTControl( BLOOD_LEAK_EMB_MODE_COMM_READ_REQST ); } return state; @@ -981,7 +1008,9 @@ U08 rxFIFOCount = getFPGABloodLeakRxFIFOCount(); U08 length = 0; - if ( rxFIFOCount > 0 ) + U08 data = getFPGABloodLeakRxFIFODataOut(); // TODO remove + + if ( ( rxFIFOCount > 0 ) && ( TRUE == areTempDone ) ) { /* * There are 3 types of data that can be received from the the sensor: @@ -1067,20 +1096,28 @@ } } } + // Send another request to the FPGA to read the next data in the buffer setFPGABloodLeakUARTControl( BLOOD_LEAK_EMB_MODE_COMM_READ_REQST ); + areTempDone = FALSE; } + else if ( FALSE == areTempDone ) + { + setFPGABloodLeakUARTControl( BLOOD_LEAK_EMB_MODE_COMM_ACTIVE_LOW ); + areTempDone = TRUE; + } + // If wait for the receive FIFO has timed out or all there is no buffer left in the Rx FIFO transition back to wait for command state for the next command - if ( ( TRUE == didTimeout( bloodLeakEmbModeOpsStartTime, BLOOD_LEAK_EMB_MODE_RX_TIMEOUT_MS ) ) || ( BLOOD_LEAK_EMB_MODE_RX_BUFFER_EMPTY == rxFIFOCount ) ) + if ( ( TRUE == didTimeout( bloodLeakEmbModeOpsStartTime, BLOOD_LEAK_EMB_MODE_RX_TIMEOUT_MS ) ) )//|| ( BLOOD_LEAK_EMB_MODE_RX_BUFFER_EMPTY == rxFIFOCount ) ) { // Check if the first element of the response buffer is null and the number of tries has not exceeded. When the response buffer is // null but it is the end of the receive buffer it means no response has been received back - if ( ( NU_EMB_MODE_CMD == bloodLeakEmbModeRespBuffer[ 0 ] ) && ( ++bloodLeakEmbModeNumOfCmdTries < BLOOD_LEAK_EMB_MODE_MAX_NUM_CMD_TRIES ) ) + /*if ( ( NU_EMB_MODE_CMD == bloodLeakEmbModeRespBuffer[ 0 ] ) && ( ++bloodLeakEmbModeNumOfCmdTries < BLOOD_LEAK_EMB_MODE_MAX_NUM_CMD_TRIES ) ) { state = BLOOD_LEAK_CAL_SEND_COMMAND_STATE; } - else + else*/ { U08 i; BOOL isNull = FALSE; @@ -1096,11 +1133,12 @@ // it failed set the embedded mode request to false so the other commands cannot be sent again bloodLeakSignalEmbModeReq = ( ( CS_EMB_MODE_CMD == bloodLeakEmbModeRqstedCmd ) && ( NU_EMB_MODE_CMD == bloodLeakEmbModeRespBuffer[ 0 ] ) ? FALSE : TRUE ); + /* TODO the retries has been disabled for the systems team for their testing. if ( ( TRUE == isNull ) && ( ++bloodLeakEmbModeNumOfCmdTries < BLOOD_LEAK_EMB_MODE_MAX_NUM_CMD_TRIES ) ) { state = BLOOD_LEAK_CAL_SEND_COMMAND_STATE; } - else + else */ { bloodLeakEmbModeRqstedCmd = NU_EMB_MODE_CMD; state = BLOOD_LEAK_CAL_WAIT_FOR_COMAND_STATE;