Index: firmware/App/Modes/OperationModes.c =================================================================== diff -u -r643e536ab4d3a615ce54df693c10257a77f20162 -rcd5be724d5a3ba7457e761191d82f278654d7f5c --- firmware/App/Modes/OperationModes.c (.../OperationModes.c) (revision 643e536ab4d3a615ce54df693c10257a77f20162) +++ 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) Sean Nash -* @date (last) 31-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 @@ -63,6 +62,7 @@ static U32 broadcastModeIntervalCtr; ///< Interval counter used to determine when to broadcast operation mode. Initialize to 11 to stagger broadcast. 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 @@ -89,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 @@ -142,13 +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 ) { @@ -164,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 @@ -173,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 @@ -217,16 +219,15 @@ break; } // End switch +#ifndef _VECTORCAST_ // Send operation status event when appropriate - if ( priorOpMode != currentMode || priorSubMode != currentSubMode || - priorSubState != currentSubState || prior4thLevelState != current4thLevelState ) + 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(); } @@ -438,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. @@ -561,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; } @@ -617,7 +610,7 @@ * @param none * @return none *************************************************************************/ -static void sendOperationStatusEvent( void ) +void sendOperationStatusEvent( void ) { EVENT_DATA_T dat1; EVENT_DATA_T dat2;