Index: firmware/App/Modes/OperationModes.c =================================================================== diff -u -r60c102696e521ff82452aaad30e1db9f240eef58 -rcd5be724d5a3ba7457e761191d82f278654d7f5c --- firmware/App/Modes/OperationModes.c (.../OperationModes.c) (revision 60c102696e521ff82452aaad30e1db9f240eef58) +++ firmware/App/Modes/OperationModes.c (.../OperationModes.c) (revision cd5be724d5a3ba7457e761191d82f278654d7f5c) @@ -1,14 +1,14 @@ /************************************************************************** * -* Copyright (c) 2019-2023 Diality Inc. - All Rights Reserved. +* Copyright (c) 2019-2024 Diality Inc. - All Rights Reserved. * * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. * * @file OperationModes.c * -* @author (last) Michael Garthwaite -* @date (last) 16-May-2023 +* @author (last) Dara Navaei +* @date (last) 12-Oct-2023 * * @author (original) Dara Navaei * @date (original) 05-Nov-2019 @@ -43,7 +43,6 @@ #define BROADCAST_HD_OP_MODE_INTERVAL ( 250 / TASK_GENERAL_INTERVAL ) ///< HD operation mode broadcast interval (in task interval/sec). #define DATA_PUBLISH_COUNTER_START_COUNT 11 ///< Data publish counter start count. #define MAX_PENDING_CONFIRM_REQUESTS 4 ///< Maximum number of confirmation requests allowed at any given time. -#define CONFIRMATION_REQUEST_TIMEOUT_MS ( SEC_PER_MIN * MS_PER_SECOND ) ///< Confirmation response timeout in ms /// Structure for confirmation request. typedef struct @@ -61,7 +60,9 @@ static HD_OP_MODE_T currentMode; ///< Current operation mode. static U32 currentSubMode; ///< The currently active state of the active mode. static U32 broadcastModeIntervalCtr; ///< Interval counter used to determine when to broadcast operation mode. Initialize to 11 to stagger broadcast. -static U32 currentSubState; +static U32 currentSubState; ///< current sub state. +static U32 current4thLevelState; ///< current 4th level state. + /// Interval (in task intervals) at which to publish operation mode data to CAN bus. static OVERRIDE_U32_T opModePublishInterval = { BROADCAST_HD_OP_MODE_INTERVAL, BROADCAST_HD_OP_MODE_INTERVAL, BROADCAST_HD_OP_MODE_INTERVAL, 0 }; /// Local structure init for saving confirmation requests @@ -75,7 +76,7 @@ static const HD_OP_MODE_T MODE_TRANSITION_TABLE[ NUM_OF_MODES - 1 ][ NUM_OF_MODES - 1 ] = { // From to-> FAULT SERVICE INIT STANBY TRT.PARAMS PRE-TREAT TREATMENT POST_TREA /* FAUL */{ MODE_FAUL, MODE_SERV, MODE_NLEG, MODE_NLEG, MODE_NLEG, MODE_NLEG, MODE_NLEG, MODE_NLEG, }, -/* SERV */{ MODE_FAUL, MODE_SERV, MODE_NLEG, MODE_NLEG, MODE_NLEG, MODE_NLEG, MODE_NLEG, MODE_NLEG, }, +/* SERV */{ MODE_NLEG, MODE_SERV, MODE_NLEG, MODE_NLEG, MODE_NLEG, MODE_NLEG, MODE_NLEG, MODE_NLEG, }, /* INIT */{ MODE_FAUL, MODE_NLEG, MODE_INIT, MODE_STAN, MODE_NLEG, MODE_NLEG, MODE_NLEG, MODE_NLEG, }, /* STAN */{ MODE_FAUL, MODE_SERV, MODE_INIT, MODE_STAN, MODE_TPAR, MODE_NLEG, MODE_NLEG, MODE_NLEG, }, /* TPAR */{ MODE_FAUL, MODE_NLEG, MODE_NLEG, MODE_STAN, MODE_TPAR, MODE_PRET, MODE_NLEG, MODE_NLEG, }, @@ -88,8 +89,6 @@ static HD_OP_MODE_T arbitrateModeRequest( void ); static void transitionToNewOperationMode( HD_OP_MODE_T newMode ); static void broadcastOperationMode( void ); -static void updateConfirmationRequestTimeouts( void ); -static void sendOperationStatusEvent( void ); /*********************************************************************//** * @brief @@ -112,7 +111,8 @@ lastMode = MODE_INIT; currentMode = MODE_INIT; currentSubMode = 0; - currentSubState = 0xFF; + currentSubState = NO_SUB_STATE; + current4thLevelState = NO_SUB_STATE; broadcastModeIntervalCtr = DATA_PUBLISH_COUNTER_START_COUNT; transitionToNewOperationMode( MODE_INIT ); @@ -140,12 +140,16 @@ HD_OP_MODE_T newMode; U32 priorSubMode = currentSubMode; U32 priorSubState = currentSubState; - U32 priorOpMode = (U32)currentMode; + U32 prior4thLevelState = current4thLevelState; // Any new mode requests? newMode = arbitrateModeRequest(); // Will return current mode if no pending requests - newMode = MODE_TRANSITION_TABLE[ currentMode ][ newMode ]; + if ( getTestConfigStatus( TEST_CONFIG_RECOVER_TREATMENT ) != TRUE ) + { + newMode = MODE_TRANSITION_TABLE[ currentMode ][ newMode ]; + } + // Is requested new mode valid and legal at this time? if ( newMode >= MODE_NLEG ) { @@ -161,7 +165,7 @@ transitionToNewOperationMode( newMode ); currentMode = newMode; - if ( ( MODE_TREA == lastMode ) && ( currentMode != MODE_TREA ) ) + if ( MODE_TREA == lastMode ) { // If the last mode is treatment but the new mode is not treatment // it means the treatment is done. Get the elapsed time since the beginning of the treatment and convert it to hours to be written @@ -170,6 +174,7 @@ // Write the treatment hours and set the service to be false so the treatment hours is not reset setTxTimeHours( txElapsedTimeHrs ); } + sendOperationStatusEvent(); } // Mode specific processing to be done continuously @@ -214,15 +219,15 @@ break; } // End switch +#ifndef _VECTORCAST_ // Send operation status event when appropriate - if ( priorOpMode != currentMode || priorSubMode != currentSubMode || priorSubState != currentSubState ) + if ( ( priorSubMode != currentSubMode ) || ( priorSubState != currentSubState ) || ( prior4thLevelState != current4thLevelState ) ) +#endif { sendOperationStatusEvent(); SEND_EVENT_WITH_2_U32_DATA( HD_EVENT_SUB_MODE_CHANGE, priorSubMode, currentSubMode ) } - updateConfirmationRequestTimeouts( ); - // Broadcast current operation mode on interval broadcastOperationMode(); } @@ -434,30 +439,6 @@ /*********************************************************************//** * @brief - * The updateConfirmationRequestTimeouts function checks the status of - * all active confirmation requests and updates the timeout. - * @details Inputs: confirmRequests[] - * @details Outputs: confirmRequests[] status updated if timeout. - * @return none - *************************************************************************/ -static void updateConfirmationRequestTimeouts( void ) -{ - U32 i; - - for ( i = 0; i < MAX_PENDING_CONFIRM_REQUESTS; i++ ) - { - if ( CONFIRMATION_REQUEST_STATUS_PENDING == confirmRequests[ i ].status ) - { - if ( TRUE == didTimeout( confirmRequests[ i ].timeStamp, CONFIRMATION_REQUEST_TIMEOUT_MS ) ) - { - confirmRequests[ i ].status = CONFIRMATION_REQUEST_STATUS_TIMEOUT; - } - } - } -} - -/*********************************************************************//** - * @brief * The getConfirmationRequestStatus function returns the status of a confirmation request * @details Inputs: confirmRequests[] * @details Outputs: confirmRequests[] consumed/cleared if completed. @@ -557,24 +538,40 @@ *************************************************************************/ GENERIC_CONFIRM_ID_T addConfirmationRequest( GENERIC_CONFIRM_ID_T requestID, GENERIC_CONFIRM_COMMAND_T requestType, U32 rejectReason ) { - U32 i; + U32 i; + BOOL confirmAlreadyPending = FALSE; GENERIC_CONFIRM_ID_T newID = GENERIC_CONFIRM_ID_NONE; + // Check to make sure specified confirmation is not already pending for ( i = 0; i < MAX_PENDING_CONFIRM_REQUESTS; i++ ) { - if ( CONFIRMATION_REQUEST_STATUS_UNUSED == confirmRequests[ i ].status ) + if ( ( confirmRequests[ i ].requestID == requestID ) && + ( confirmRequests[ i ].status != CONFIRMATION_REQUEST_STATUS_UNUSED ) ) { - // Save the confirmation request info - confirmRequests[ i ].requestID = requestID; - confirmRequests[ i ].requestType = requestType; - confirmRequests[ i ].timeStamp = getMSTimerCount(); - confirmRequests[ i ].status = CONFIRMATION_REQUEST_STATUS_PENDING; - newID = requestID; - sendConfirmationRequest( requestID, requestType, rejectReason ); + confirmAlreadyPending = TRUE; break; } } + // If not already pending, add confirmation to list of pending confirmations and send to UI to be displayed + if ( confirmAlreadyPending != TRUE ) + { + for ( i = 0; i < MAX_PENDING_CONFIRM_REQUESTS; i++ ) + { + if ( CONFIRMATION_REQUEST_STATUS_UNUSED == confirmRequests[ i ].status ) + { + // Save the confirmation request info + confirmRequests[ i ].requestID = requestID; + confirmRequests[ i ].requestType = requestType; + confirmRequests[ i ].timeStamp = getMSTimerCount(); + confirmRequests[ i ].status = CONFIRMATION_REQUEST_STATUS_PENDING; + newID = requestID; + sendConfirmationRequest( requestID, requestType, rejectReason ); + break; + } + } + } + return newID; } @@ -593,20 +590,34 @@ /*********************************************************************//** * @brief + * The setCurrent4thLevelState function sets the current 4th level state. + * @details Inputs: state + * @details Outputs: current4thLevelState + * @param subState the enumerated sub state. + * @return none + *************************************************************************/ +void setCurrent4thLevelState( U32 state ) +{ + current4thLevelState = state; +} + +/*********************************************************************//** + * @brief * The sendOperationStatusEvent function constructs and sends an HD operation * status event. - * @details Inputs: currentMode, currentSubMode, currentSubState + * @details Inputs: currentMode, currentSubMode, currentSubState, current4thLevelState * @details Outputs: dat1, dat2. * @param none * @return none *************************************************************************/ -static void sendOperationStatusEvent( void ) +void sendOperationStatusEvent( void ) { EVENT_DATA_T dat1; EVENT_DATA_T dat2; U32 opData = ( (U08)currentMode + ( (U08)currentSubMode << SHIFT_8_BITS_FOR_BYTE_SHIFT ) + - ( (U08)currentSubState << SHIFT_16_BITS_FOR_WORD_SHIFT ) ); + ( (U08)currentSubState << SHIFT_16_BITS_FOR_WORD_SHIFT ) + + ( (U08)current4thLevelState << SHIFT_24_BITS ) ); dat2.dataType = EVENT_DATA_TYPE_U32; dat2.data.uInt.data = 0;