Index: firmware/App/Services/Messaging.c =================================================================== diff -u -r83310420ae862de4724f8cfbbaeda9936c47801b -r689ec9d4574754ba13d0b630eed4eef0eeb79760 --- firmware/App/Services/Messaging.c (.../Messaging.c) (revision 83310420ae862de4724f8cfbbaeda9936c47801b) +++ firmware/App/Services/Messaging.c (.../Messaging.c) (revision 689ec9d4574754ba13d0b630eed4eef0eeb79760) @@ -31,6 +31,7 @@ #include "FpgaTD.h" #include "LevelSensors.h" #include "Messaging.h" +#include "ModeInitPOST.h" #include "ModeStandby.h" #include "ModeTreatment.h" #include "OperationModes.h" @@ -111,6 +112,7 @@ { MSG_ID_FW_VERSIONS_REQUEST, &handleVersionRequestMessage }, { MSG_ID_UI_CHECK_IN, &handleUICheckIn }, { MSG_ID_DD_OP_MODE_DATA, &setDDOpMode }, + { MSG_ID_UI_VERSION_INFO_RESPONSE, &handleUIVersionResponse }, { MSG_ID_DD_GEN_DIALYSATE_MODE_DATA, &setDialysateData }, { MSG_ID_DD_PRESSURES_DATA, &setDialysatePressure }, { MSG_ID_UI_TREATMENT_PARAMS_TO_VALIDATE, &validateAndSetTreatmentParameters }, @@ -136,6 +138,7 @@ { MSG_ID_UI_ADJUST_DISPOSABLES_REMOVAL_CONFIRM_REQUEST, &handleAutoEjectRequest }, { MSG_ID_FFU_SIGNAL_TD_UPDATE_AVAILABLE, &handleUpdateAvailable }, { MSG_ID_UI_FLUID_BOLUS_REQUEST, &handleFluidBolusRequest }, + { MSG_ID_UI_GENERIC_CONFIRMATION_RESULT_RESPONSE, &handleUIConfirmationResponse }, { MSG_ID_TD_SOFTWARE_RESET_REQUEST, &testTDSoftwareResetRequest }, { MSG_ID_TD_BUBBLE_OVERRIDE_REQUEST, &testBubbleDetectOverride }, { MSG_ID_TD_BUBBLE_PUBLISH_INTERVAL_OVERRIDE_REQUEST, &testBubblesDataPublishIntervalOverride }, @@ -239,7 +242,6 @@ static MsgFuncPtr getMsgHandler( U16 msgID ); static BOOL sendTestAckResponseMsg( MSG_ID_T msgID, BOOL ack ); -static BOOL sendAckResponseMsg( MSG_ID_T msgID, COMM_BUFFER_T buffer, BOOL ack ); /*********************************************************************//** * @brief @@ -398,7 +400,7 @@ * @param ack TRUE to ACK, FALSE to NAK * @return TRUE if response message successfully queued for transmit, FALSE if not *************************************************************************/ -static BOOL sendAckResponseMsg( MSG_ID_T msgID, COMM_BUFFER_T buffer, BOOL ack ) +BOOL sendAckResponseMsg( MSG_ID_T msgID, COMM_BUFFER_T buffer, BOOL ack ) { BOOL result; MESSAGE_T msg; @@ -525,7 +527,31 @@ return result; } +/*********************************************************************//** + * @brief + * The handleUIVersionResponse function handles a response to request for + * UI version information. + * @details Inputs: none + * @details Outputs: message handled + * @param message a pointer to the message to handle. + * @return none + *************************************************************************/ +BOOL handleUIVersionResponse( MESSAGE_T *message ) +{ + BOOL result = TRUE; + // Get UI version data and have it recorded + if ( sizeof(UI_VERSIONS_T) == message->hdr.payloadLen ) + { + UI_VERSIONS_T uiVersion; + + memcpy( &uiVersion, &message->payload[ 0 ], sizeof(UI_VERSIONS_T) ); + signalUIVersion( uiVersion ); + } + + return result; +} + // *********************************************************************** // ***************** Message Sending Helper Functions ******************** // *********************************************************************** @@ -570,36 +596,54 @@ /*********************************************************************//** * @brief - * The sendOffButtonMsgToUI function constructs an off button msg to the UI - * and queues the msg for transmit on the appropriate CAN channel. - * @details \b Message \b Sent: MSG_ID_OFF_BUTTON_PRESS_REQUEST + * The sendUIVersionRequest function constructs a UI version request msg + * to the UI and queues the msg for transmit on the appropriate CAN channel. + * @details \b Message \b Sent: MSG_ID_TD_UI_VERSION_INFO_REQUEST * @details \b Inputs: none - * @details \b Outputs: Off button msg constructed and queued. - * @param prompt 0=prompt user to confirm, 1=cancel prompt, 2=reject user off request + * @details \b Outputs: none * @return TRUE if msg successfully queued for transmit, FALSE if not *************************************************************************/ -BOOL sendOffButtonMsgToUI( U08 prompt ) +BOOL sendUIVersionRequest( void ) { BOOL result; MESSAGE_T msg; - UI_OFF_BUTTON_RESPONSE_PAYLOAD_T cmd; - cmd.userRequest = prompt; - // Create a message record blankMessage( &msg ); - msg.hdr.msgID = MSG_ID_OFF_BUTTON_PRESS_REQUEST; - msg.hdr.payloadLen = sizeof( UI_OFF_BUTTON_RESPONSE_PAYLOAD_T ); + msg.hdr.msgID = MSG_ID_TD_UI_VERSION_INFO_REQUEST; + msg.hdr.payloadLen = 0; - memcpy( &msg.payload, &cmd, sizeof( UI_OFF_BUTTON_RESPONSE_PAYLOAD_T ) ); - // Serialize the message (w/ sync, CRC, and appropriate CAN padding) and add serialized message data to appropriate comm buffer result = serializeMessage( msg, COMM_BUFFER_OUT_CAN_TD_2_UI, ACK_REQUIRED ); return result; } +/*********************************************************************//** + * @brief + * The sendRequestForDDResendAlarms function sends out the TD request for + * DG re-send all active alarms. + * @details \b Inputs: none + * @details \b Outputs: DD alarms re-send request msg constructed and queued + * @return TRUE if msg successfully queued for transmit, FALSE if not + *************************************************************************/ +BOOL sendRequestForDDResendAlarms( void ) +{ + BOOL result; + MESSAGE_T msg; + // Create a message record + blankMessage( &msg ); + msg.hdr.msgID = MSG_ID_TD_DD_ALARMS_REQUEST; + msg.hdr.payloadLen = 0; + + // Serialize the message (w/ sync, CRC, and appropriate CAN padding) and add serialized message data to appropriate comm buffer + result = serializeMessage( msg, COMM_BUFFER_OUT_CAN_TD_2_DD, ACK_REQUIRED ); + + return result; +} + + /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/ @@ -739,6 +783,43 @@ /*********************************************************************//** * @brief + * The sendPOSTTestResult function sends the result of a single TD POST + * test to the UI. + * @details \b Inputs: none + * @details \b Outputs: TD POST test result msg queued for CAN transmit. + * @param test ID of the TD POST test. + * @param passed TRUE if POST test passed, FALSE if POST test failed. + * @return TRUE if message successfully queued for transmit, FALSE if not + *************************************************************************/ +BOOL sendPOSTTestResult( TD_POST_STATE_T test, BOOL passed ) +{ + U08 payload[ sizeof( BOOL ) + sizeof( U32 ) ]; + U32 testID = (U32)test; + + memcpy( payload, &passed, sizeof( BOOL ) ); + memcpy( &payload[ sizeof( BOOL ) ], &testID, sizeof( U32 ) ); + + // Use the generic send helper for transmission. + return sendMessage( MSG_ID_TD_POST_SINGLE_TEST_RESULT, COMM_BUFFER_OUT_CAN_TD_BROADCAST, payload, sizeof( payload ) ); +} + +/*********************************************************************//** + * @brief + * The sendPOSTFinalResult function sends the overall TD POST result + * and queues the message for transmit on the appropriate CAN channel. + * @details \b Inputs: none + * @details \b Outputs: TD POST final result msg queued for CAN transmit. + * @param passed TRUE if all TD POST tests passed, FALSE otherwise. + * @return TRUE if message successfully queued for transmit, FALSE if not + *************************************************************************/ +BOOL sendPOSTFinalResult( BOOL passed ) +{ + // Use the generic send helper for transmission. + return sendMessage( MSG_ID_TD_POST_FINAL_TEST_RESULT, COMM_BUFFER_OUT_CAN_TD_BROADCAST, (U08 *)&passed, sizeof( BOOL ) ); +} + +/*********************************************************************//** + * @brief * The testTDSoftwareResetRequest function handles a request to reset the * TD firmware processor. * @note If reset is successful, this function will not return. Index: firmware/App/Services/Messaging.h =================================================================== diff -u -r9c833ef5623ce842267e284d958820ac0dc3a7fc -r689ec9d4574754ba13d0b630eed4eef0eeb79760 --- firmware/App/Services/Messaging.h (.../Messaging.h) (revision 9c833ef5623ce842267e284d958820ac0dc3a7fc) +++ firmware/App/Services/Messaging.h (.../Messaging.h) (revision 689ec9d4574754ba13d0b630eed4eef0eeb79760) @@ -22,6 +22,7 @@ #include "TDDefs.h" #include "MessageSupport.h" #include "MsgQueues.h" +#include "OperationModes.h" /** * @defgroup Messaging Messaging @@ -49,6 +50,7 @@ { U08 userRequest; ///< request to confirm, cancel, or reject off button request } UI_OFF_BUTTON_RESPONSE_PAYLOAD_T; + #pragma pack(pop) /// Payload record structure for UI response. @@ -128,16 +130,21 @@ BOOL handleUICheckIn( MESSAGE_T *message ); BOOL handleTesterLogInRequest( MESSAGE_T *message ); BOOL handleUpdateAvailable( MESSAGE_T *message ); +BOOL handleUIVersionResponse( MESSAGE_T *message ); BOOL testTDSoftwareResetRequest( MESSAGE_T *message ); // Test send message helper functions BOOL sendEvent( TD_EVENT_ID_T event, EVENT_DATA_T dat1, EVENT_DATA_T dat2 ); -BOOL sendOffButtonMsgToUI( U08 prompt ); +BOOL sendPOSTTestResult( TD_POST_STATE_T test, BOOL passed ); +BOOL sendPOSTFinalResult( BOOL passed ); +BOOL sendUIVersionRequest( void ); +BOOL sendRequestForDDResendAlarms( void ); BOOL testSetTestConfiguration( MESSAGE_T *message ); BOOL testGetTestConfiguration( MESSAGE_T *message ); BOOL testResetAllTestConfigurations( MESSAGE_T *message ); +BOOL sendAckResponseMsg( MSG_ID_T msgID, COMM_BUFFER_T buffer, BOOL ack ); /**@}*/ Index: firmware/App/Services/SystemCommTD.c =================================================================== diff -u -r9fcd1ad071bcce7a592833367c103e235e49654f -r689ec9d4574754ba13d0b630eed4eef0eeb79760 --- firmware/App/Services/SystemCommTD.c (.../SystemCommTD.c) (revision 9fcd1ad071bcce7a592833367c103e235e49654f) +++ firmware/App/Services/SystemCommTD.c (.../SystemCommTD.c) (revision 689ec9d4574754ba13d0b630eed4eef0eeb79760) @@ -7,43 +7,44 @@ * * @file SystemCommTD.c * -* @author (last) Dara Navaei -* @date (last) 06-Mar-2026 +* @author (last) Praneeth Bunne +* @date (last) 12-Jun-2026 * * @author (original) Sean Nash * @date (original) 01-Aug-2024 * ***************************************************************************/ - -#include // For memcpy() -#include "Buttons.h" -#include "can.h" -#include "sci.h" -#include "sys_dma.h" - -#include "Comm.h" +#include // For memcpy() + +#include "Buttons.h" +#include "can.h" +#include "sci.h" +#include "sys_dma.h" + +#include "Comm.h" #include "Interrupts.h" #include "Messaging.h" #include "MessageSupport.h" +#include "OperationModes.h" #include "SystemCommTD.h" -#include "Timers.h" -#include "Utilities.h" - +#include "Timers.h" +#include "Utilities.h" + /** * @addtogroup SystemCommTD * @{ */ -// ********** private definitions ********** - +// ********** private definitions ********** + #define UI_COMM_TIMEOUT_IN_MS 7500 ///< Maximum time (in ms) that UI is allowed to wait before checking in with HD. -#define UI_COMM_SERVICE_MODE_TIMEOUT_IN_MS (2 * SEC_PER_MIN * MS_PER_SECOND) ///< Maximum time (in ms) that UI is allowed to wait before checking in with HD when in service mode. -#define DG_COMM_TIMEOUT_IN_MS 1000 ///< DG has not checked in for this much time - -#define MAX_COMM_CRC_FAILURES 5 ///< Maximum number of CRC errors within window period before alarm -#define MAX_COMM_CRC_FAILURE_WINDOW_MS (10 * SEC_PER_MIN * MS_PER_SECOND) ///< CRC error window - +#define UI_COMM_SERVICE_MODE_TIMEOUT_IN_MS (2 * SEC_PER_MIN * MS_PER_SECOND) ///< Maximum time (in ms) that UI is allowed to wait before checking in with HD when in service mode. +#define DG_COMM_TIMEOUT_IN_MS 1000 ///< DG has not checked in for this much time + +#define MAX_COMM_CRC_FAILURES 5 ///< Maximum number of CRC errors within window period before alarm +#define MAX_COMM_CRC_FAILURE_WINDOW_MS (10 * SEC_PER_MIN * MS_PER_SECOND) ///< CRC error window + #define MAX_FPGA_CLOCK_SPEED_ERRORS 3 ///< maximum number of FPGA clock speed errors within window period before alarm #define MAX_FPGA_CLOCK_SPEED_ERROR_WINDOW_MS (10 * SEC_PER_MIN * MS_PER_SECOND) ///< FPGA clock speed error window @@ -71,122 +72,122 @@ COMM_BUFFER_IN_CAN_PC, }; -// ********** private data ********** - +// ********** private data ********** + static volatile BOOL tdIsOnlyCANNode = TRUE; ///< Flag indicating whether HD is alone on CAN bus. -static volatile BOOL ddIsCommunicating = FALSE; ///< Has DD sent a message since last check -static U32 timeOfLastDDCheckIn = 0; ///< Last time DD checked in -static volatile BOOL uiIsCommunicating = FALSE; ///< Has UI sent a message since last check -static U32 timeOfLastUICheckIn = 0; ///< Last time UI checked in +static volatile BOOL ddIsCommunicating = FALSE; ///< Has DD sent a message since last check +static U32 timeOfLastDDCheckIn = 0; ///< Last time DD checked in +static volatile BOOL uiIsCommunicating = FALSE; ///< Has UI sent a message since last check +static U32 timeOfLastUICheckIn = 0; ///< Last time UI checked in static volatile BOOL uiDidCommunicate = FALSE; ///< Has UI every sent a message - -// ********** private function prototypes ********** - - -/*********************************************************************//** - * @brief + +// ********** private function prototypes ********** + + +/*********************************************************************//** + * @brief * The initSystemCommTD function initializes the system communication unit - * for the TD firmware. - * @details \b Inputs: none - * @details \b Outputs: SystemComm unit initialized. - * @return none - *************************************************************************/ -void initSystemCommTD( void ) + * for the TD firmware. + * @details \b Inputs: none + * @details \b Outputs: SystemComm unit initialized. + * @return none + *************************************************************************/ +void initSystemCommTD( void ) { // Initialize common system comm unit initSystemComm(); - + // Initialize bad message CRC time windowed count initTimeWindowedCount( TIME_WINDOWED_COUNT_BAD_MSG_CRC, MAX_COMM_CRC_FAILURES, MAX_COMM_CRC_FAILURE_WINDOW_MS ); // Initialize FPGA clock speed error time windowed count initTimeWindowedCount( TIME_WINDOWED_COUNT_FPGA_CLOCK_SPEED_ERROR, MAX_FPGA_CLOCK_SPEED_ERRORS, MAX_FPGA_CLOCK_SPEED_ERROR_WINDOW_MS); -} - -/*********************************************************************//** - * @brief - * The checkInFromDD function checks in the DD with the TD - indicating that - * the DD is communicating. - * @details \b Inputs: none - * @details \b Outputs: ddIsCommunicating, timeOfLastDDCheckIn - * @return none - *************************************************************************/ -void checkInFromDD( void ) -{ - ddIsCommunicating = TRUE; +} + +/*********************************************************************//** + * @brief + * The checkInFromDD function checks in the DD with the TD - indicating that + * the DD is communicating. + * @details \b Inputs: none + * @details \b Outputs: ddIsCommunicating, timeOfLastDDCheckIn + * @return none + *************************************************************************/ +void checkInFromDD( void ) +{ + ddIsCommunicating = TRUE; timeOfLastDDCheckIn = getMSTimerCount(); if ( TRUE == isAlarmActive( ALARM_ID_TD_DD_COMM_TIMEOUT ) ) { clearAlarmCondition( ALARM_ID_TD_DD_COMM_TIMEOUT ); - } -} - -/*********************************************************************//** - * @brief - * The checkInFromUI function checks in the UI with the TD - indicating that - * the UI is communicating. - * @details \b Inputs: none - * @details \b Outputs: uiIsCommunicating, timeOfLastUICheckIn, uiDidCommunicate - * @return none - *************************************************************************/ -void checkInFromUI( void ) -{ + } +} + +/*********************************************************************//** + * @brief + * The checkInFromUI function checks in the UI with the TD - indicating that + * the UI is communicating. + * @details \b Inputs: none + * @details \b Outputs: uiIsCommunicating, timeOfLastUICheckIn, uiDidCommunicate + * @return none + *************************************************************************/ +void checkInFromUI( void ) +{ if ( FALSE == uiDidCommunicate ) { // Start DD check-in timer when UI first communicates timeOfLastDDCheckIn = getMSTimerCount(); } - - uiIsCommunicating = TRUE; - timeOfLastUICheckIn = getMSTimerCount(); - uiDidCommunicate = TRUE; -} - -/*********************************************************************//** - * @brief - * The isDDCommunicating function determines whether the DD is communicating - * with the TD. - * @details \b Inputs: ddIsCommunicating - * @details \b Outputs: none - * @return TRUE if DD is communicating, FALSE if not - *************************************************************************/ -BOOL isDDCommunicating( void ) -{ - return ddIsCommunicating; -} - -/*********************************************************************//** - * @brief - * The isUICommunicating function determines whether the UI is communicating - * with the TD. - * @details \b Inputs: uiIsCommunicating - * @details \b Outputs: uiIsCommunicating - * @return TRUE if UI has checked in since last call, FALSE if not - *************************************************************************/ -BOOL isUICommunicating( void ) -{ - BOOL result = uiIsCommunicating; - - uiIsCommunicating = FALSE; - - return result; -} - -/*********************************************************************//** - * @brief + + uiIsCommunicating = TRUE; + timeOfLastUICheckIn = getMSTimerCount(); + uiDidCommunicate = TRUE; +} + +/*********************************************************************//** + * @brief + * The isDDCommunicating function determines whether the DD is communicating + * with the TD. + * @details \b Inputs: ddIsCommunicating + * @details \b Outputs: none + * @return TRUE if DD is communicating, FALSE if not + *************************************************************************/ +BOOL isDDCommunicating( void ) +{ + return ddIsCommunicating; +} + +/*********************************************************************//** + * @brief + * The isUICommunicating function determines whether the UI is communicating + * with the TD. + * @details \b Inputs: uiIsCommunicating + * @details \b Outputs: uiIsCommunicating + * @return TRUE if UI has checked in since last call, FALSE if not + *************************************************************************/ +BOOL isUICommunicating( void ) +{ + BOOL result = uiIsCommunicating; + + uiIsCommunicating = FALSE; + + return result; +} + +/*********************************************************************//** + * @brief * The uiCommunicated function determines whether the UI has started communicating - * since power up. - * @details \b Inputs: uiDidCommunicate - * @details \b Outputs: none - * @return TRUE if UI has communicated since power up, FALSE if not - *************************************************************************/ -BOOL uiCommunicated( void ) + * since power up. + * @details \b Inputs: uiDidCommunicate + * @details \b Outputs: none + * @return TRUE if UI has communicated since power up, FALSE if not + *************************************************************************/ +BOOL uiCommunicated( void ) { #ifdef TEST_PROCESS_TASKS_WO_UI uiDidCommunicate = TRUE; #endif - return uiDidCommunicate; + return uiDidCommunicate; } /*********************************************************************//** @@ -214,8 +215,8 @@ void setOnlyCANNode( BOOL only ) { tdIsOnlyCANNode = only; -} - +} + /*********************************************************************//** * @brief * The clearCANXmitBuffers function clears all CAN transmit buffers. @@ -233,34 +234,34 @@ } } -/*********************************************************************//** - * @brief - * The checkForCommTimeouts function checks for sub-system communication +/*********************************************************************//** + * @brief + * The checkForCommTimeouts function checks for sub-system communication * timeout errors. * @details \b Alarm: ALARM_ID_TD_UI_COMM_TIMEOUT if UI no longer communicating. - * @details \b Alarm: ALARM_ID_TD_DD_COMM_TIMEOUT if DD no longer communicating. - * @details \b Inputs: timeOfLastDDCheckIn, timeOfLastUICheckIn - * @details \b Outputs: none - * @return none - *************************************************************************/ -void checkForCommTimeouts( void ) -{ - if ( TRUE == uiDidCommunicate ) + * @details \b Alarm: ALARM_ID_TD_DD_COMM_TIMEOUT if DD no longer communicating. + * @details \b Inputs: timeOfLastDDCheckIn, timeOfLastUICheckIn + * @details \b Outputs: none + * @return none + *************************************************************************/ +void checkForCommTimeouts( void ) +{ + if ( TRUE == uiDidCommunicate ) { TD_OP_MODE_T opMode = getCurrentOperationMode(); U32 uiTO_MS = ( MODE_SERV == opMode ? UI_COMM_SERVICE_MODE_TIMEOUT_IN_MS : UI_COMM_TIMEOUT_IN_MS ); - if ( TRUE == didTimeout( timeOfLastUICheckIn, uiTO_MS ) ) + if ( TRUE == didTimeout( timeOfLastUICheckIn, uiTO_MS ) ) { #ifndef _RELEASE_ // if ( getSoftwareConfigStatus( SW_CONFIG_DISABLE_UI_COMM_ALARMS ) != SW_CONFIG_ENABLE_VALUE ) #endif - { + { #ifndef TEST_DISABLE_UI_ALARMS activateAlarmNoData( ALARM_ID_TD_UI_COMM_TIMEOUT ); #endif } - } + } if ( TRUE == didTimeout( timeOfLastDDCheckIn, DG_COMM_TIMEOUT_IN_MS ) ) { @@ -354,21 +355,21 @@ return result; -} - -/*********************************************************************//** - * @brief - * The processReceivedMessage function processes a given message. - * @details \b Inputs: none - * @details \b Outputs: message processed - * @param message Pointer to the message to process. - * @return none - *************************************************************************/ -void processReceivedMessage( MESSAGE_T *message ) +} + +/*********************************************************************//** + * @brief + * The processReceivedMessage function processes a given message. + * @details \b Inputs: none + * @details \b Outputs: message processed + * @param message Pointer to the message to process. + * @return none + *************************************************************************/ +void processReceivedMessage( MESSAGE_T *message ) { // Handle any messages from other sub-systems - handleIncomingMessage( message ); -} + handleIncomingMessage( message ); +} /*************************************************************************