Index: firmware/App/Services/SystemCommTD.c =================================================================== diff -u -r3b3713c0d5445b83f339021972728ff58bd3e6e5 -r3518e8a088c32e75c0c8960d5e629a7401095feb --- firmware/App/Services/SystemCommTD.c (.../SystemCommTD.c) (revision 3b3713c0d5445b83f339021972728ff58bd3e6e5) +++ firmware/App/Services/SystemCommTD.c (.../SystemCommTD.c) (revision 3518e8a088c32e75c0c8960d5e629a7401095feb) @@ -15,15 +15,15 @@ * ***************************************************************************/ -#include #include // For memcpy() #include "can.h" #include "sci.h" #include "sys_dma.h" #include "Comm.h" -#include "Interrupts.h" +#include "Interrupts.h" +#include "Messaging.h" #include "OperationModes.h" #include "SystemCommTD.h" #include "Timers.h" @@ -36,57 +36,58 @@ // ********** 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_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 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_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_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 -// ********** private data ********** - /// Array of out-going CAN buffers. -const COMM_BUFFER_T CAN_OUT_BUFFERS[ NUM_OF_CAN_OUT_BUFFERS ] = -{ - COMM_BUFFER_OUT_CAN_TD_ALARM, - COMM_BUFFER_OUT_CAN_TD_2_DD, - COMM_BUFFER_OUT_CAN_TD_2_UI, - COMM_BUFFER_OUT_CAN_TD_BROADCAST, - COMM_BUFFER_OUT_CAN_PC -}; - +const COMM_BUFFER_T CAN_OUT_BUFFERS[ NUM_OF_CAN_OUT_BUFFERS ] = +{ + COMM_BUFFER_OUT_CAN_TD_ALARM, + COMM_BUFFER_OUT_CAN_TD_2_DD, + COMM_BUFFER_OUT_CAN_TD_2_UI, + COMM_BUFFER_OUT_CAN_TD_BROADCAST, + COMM_BUFFER_OUT_CAN_PC +}; + /// Array of in-coming CAN buffers. -const COMM_BUFFER_T CAN_IN_BUFFERS[ NUM_OF_CAN_IN_BUFFERS ] = -{ +const COMM_BUFFER_T CAN_IN_BUFFERS[ NUM_OF_CAN_IN_BUFFERS ] = +{ COMM_BUFFER_IN_CAN_DD_ALARM, - COMM_BUFFER_IN_CAN_RO_ALARM, - COMM_BUFFER_IN_CAN_UI_ALARM, - COMM_BUFFER_IN_CAN_DD_2_TD, + COMM_BUFFER_IN_CAN_RO_ALARM, + COMM_BUFFER_IN_CAN_UI_ALARM, + COMM_BUFFER_IN_CAN_DD_2_TD, COMM_BUFFER_IN_CAN_UI_2_TD, COMM_BUFFER_IN_CAN_DD_BROADCAST, - COMM_BUFFER_IN_CAN_RO_BROADCAST, - COMM_BUFFER_IN_CAN_UI_BROADCAST, - COMM_BUFFER_IN_CAN_PC, -}; + COMM_BUFFER_IN_CAN_RO_BROADCAST, + COMM_BUFFER_IN_CAN_UI_BROADCAST, + COMM_BUFFER_IN_CAN_PC, +}; + +// ********** 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 timeOfLastDGCheckIn = 0; ///< Last time DG 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 +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 uiDidCommunicate = FALSE; ///< Has UI every sent a message // ********** private function prototypes ********** /*********************************************************************//** * @brief - * The initSystemCommTD function initializes the SystemComm module. - * @details Inputs: none - * @details Outputs: SystemComm module initialized. + * 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 ) @@ -103,16 +104,16 @@ /*********************************************************************//** * @brief - * The checkInFromDG function checks in the DG with the HD - indicating that - * the DG is communicating. - * @details Inputs: none - * @details Outputs: ddIsCommunicating + * The checkInFromDG 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 checkInFromDG( void ) { ddIsCommunicating = TRUE; - timeOfLastDGCheckIn = getMSTimerCount(); + timeOfLastDDCheckIn = getMSTimerCount(); if ( TRUE == isAlarmActive( ALARM_ID_TD_DD_COMM_TIMEOUT ) ) { @@ -122,17 +123,17 @@ /*********************************************************************//** * @brief - * The checkInFromUI function checks in the UI with the HD - indicating that + * The checkInFromUI function checks in the UI with the TD - indicating that * the UI is communicating. - * @details Inputs: none - * @details Outputs: uiIsCommunicating + * @details \b Inputs: none + * @details \b Outputs: uiIsCommunicating, timeOfLastUICheckIn, uiDidCommunicate * @return none *************************************************************************/ void checkInFromUI( void ) { if ( FALSE == uiDidCommunicate ) - { // Start DG check-in timer when UI first communicates - timeOfLastDGCheckIn = getMSTimerCount(); + { // Start DD check-in timer when UI first communicates + timeOfLastDDCheckIn = getMSTimerCount(); } uiIsCommunicating = TRUE; @@ -144,9 +145,9 @@ * @brief * The isDDCommunicating function determines whether the DD is communicating * with the TD. - * @details Inputs: ddIsCommunicating - * @details Outputs: none - * @return TRUE if DG has checked in since last call, FALSE if not + * @details \b Inputs: ddIsCommunicating + * @details \b Outputs: none + * @return TRUE if DD is communicating, FALSE if not *************************************************************************/ BOOL isDDCommunicating( void ) { @@ -156,9 +157,9 @@ /*********************************************************************//** * @brief * The isUICommunicating function determines whether the UI is communicating - * with the HD. - * @details Inputs: uiIsCommunicating - * @details Outputs: none + * 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 ) @@ -172,27 +173,24 @@ /*********************************************************************//** * @brief - * The uiCommunicated function determines whether the UI has communicated. - * @details Inputs: none - * @details Outputs: none + * 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 ) { -#ifdef SIMULATE_UI - uiDidCommunicate = TRUE; -#endif - return uiDidCommunicate; } /*********************************************************************//** * @brief - * The isOnlyCANNode function determines whether the HD is the only node + * The isOnlyCANNode function determines whether the TD is the only node * currently on the CAN bus. - * @details Inputs: tdIsOnlyCANNode - * @details Outputs: none - * @return TRUE if HD is only node on CAN bus, FALSE if not + * @details \b Inputs: tdIsOnlyCANNode + * @details \b Outputs: none + * @return TRUE if TD is only node on CAN bus, FALSE if not *************************************************************************/ BOOL isOnlyCANNode( void ) { @@ -201,11 +199,12 @@ /*********************************************************************//** * @brief - * The setOnlyCANNode function sets whether the HD is the only node + * The setOnlyCANNode function sets whether the TD is the only node * currently on the CAN bus. - * @details Inputs: none - * @details Outputs: tdIsOnlyCANNode - * @return only TRUE if HD is only node on CAN bus, FALSE if not + * @details \b Inputs: none + * @details \b Outputs: tdIsOnlyCANNode + * @param only Flag indicating whether the TD is the only node on the CAN bus. + * @return none *************************************************************************/ void setOnlyCANNode( BOOL only ) { @@ -215,8 +214,8 @@ /*********************************************************************//** * @brief * The clearCANXmitBuffers function clears all CAN transmit buffers. - * @details Inputs: CAN_OUT_BUFFERS[] - * @details Outputs: CAN transmit buffers cleared. + * @details \b Inputs: CAN_OUT_BUFFERS[] + * @details \b Outputs: CAN transmit buffers cleared. * @return none *************************************************************************/ void clearCANXmitBuffers( void ) @@ -229,38 +228,23 @@ } } - -/************************************************************************* -********************** TRANSMIT SUPPORT FUNCTIONS ************************ -*************************************************************************/ - - - -/************************************************************************* -********************** RECEIVE SUPPORT FUNCTIONS ************************* -*************************************************************************/ - - /*********************************************************************//** * @brief * The checkForCommTimeouts function checks for sub-system communication - * timeout errors. - * @details Inputs: timeOfLastDGCheckIn, timeOfLastUICheckIn - * @details Outputs: possibly a comm t/o alarm + * 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 ) { TD_OP_MODE_T opMode = getCurrentOperationMode(); - U32 uiTO_MS = UI_COMM_TIMEOUT_IN_MS; + U32 uiTO_MS = ( MODE_SERV == opMode ? UI_COMM_SERVICE_MODE_TIMEOUT_IN_MS : UI_COMM_TIMEOUT_IN_MS ); - // in service mode, allow up to 2 minutes for UI to check-in (for lock-down) - if ( MODE_SERV == opMode ) - { - uiTO_MS = UI_COMM_SERVICE_MODE_TIMEOUT_IN_MS; - } if ( TRUE == didTimeout( timeOfLastUICheckIn, uiTO_MS ) ) { #ifndef _RELEASE_ @@ -271,9 +255,9 @@ } } - if ( TRUE == didTimeout( timeOfLastDGCheckIn, DG_COMM_TIMEOUT_IN_MS ) ) + if ( TRUE == didTimeout( timeOfLastDDCheckIn, DG_COMM_TIMEOUT_IN_MS ) ) { -#ifndef RUN_WITHOUT_DG +#ifndef RUN_WITHOUT_DD // Only alarm on DG comm loss while in the treatment workflow if ( MODE_PRET == opMode || MODE_TREA == opMode || MODE_POST == opMode ) { @@ -294,10 +278,12 @@ /*********************************************************************//** * @brief * The checkTooManyBadMsgCRCs function checks for too many bad message CRCs - * within a set period of time. Assumed function is being called when a new - * bad CRC is detected so a new bad CRC will be added to the list. - * @details Inputs: badCRCTimeStamps[], badCRCListIdx, badCRCListCount - * @details Outputs: possibly a "too many bad CRCs" alarm + * within a set period of time. + * @note Assumed function is being called when a new bad CRC is detected. + * @details \b Alarm: ALARM_ID_TD_COMM_TOO_MANY_BAD_CRCS if too many (5) bad + * CRCs detected in the last 10 minutes. + * @details \b Inputs: none + * @details \b Outputs: none * @return none *************************************************************************/ void checkTooManyBadMsgCRCs( void ) @@ -310,11 +296,13 @@ /*********************************************************************//** * @brief - * The getInBufferID function gets the buffer ID for a given buffer index. - * @details Inputs: CAN_IN_BUFFERS[] - * @details Outputs: none + * The getInBufferID function gets the incoming communication buffer ID for + * a given buffer index. + * @details \b Alarm: ALARM_ID_TD_SOFTWARE_FAULT if given buffer index is invalid. + * @details \b Inputs: CAN_IN_BUFFERS[] + * @details \b Outputs: none * @param idx incoming buffer index (e.g. 0 indicates first incoming buffer) - * @return buffer id associated with given incoming buffer index + * @return ID of buffer associated with given incoming buffer index *************************************************************************/ COMM_BUFFER_T getInBufferID( U32 idx ) { @@ -327,19 +315,21 @@ } else { - // TODO - s/w fault + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_SOFTWARE_FAULT, SW_FAULT_ID_SYSTEM_COMM_INVALID_BUFFER_INDEX1, idx ) } return result; } /*********************************************************************//** * @brief - * The getOutBufferID function gets the buffer ID for a given buffer index. - * @details Inputs: CAN_OUT_BUFFERS[] - * @details Outputs: none + * The getOutBufferID function gets the outgoing communication buffer ID for + * a given buffer index. + * @details \b Alarm: ALARM_ID_TD_SOFTWARE_FAULT if given buffer index is invalid. + * @details \b Inputs: CAN_OUT_BUFFERS[] + * @details \b Outputs: none * @param idx outgoing buffer index (e.g. 0 indicates first outgoing buffer) - * @return buffer id associated with given outgoing buffer index + * @return ID of buffer associated with given outgoing buffer index *************************************************************************/ COMM_BUFFER_T getOutBufferID( U32 idx ) { @@ -352,7 +342,7 @@ } else { - // TODO - s/w fault + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_SOFTWARE_FAULT, SW_FAULT_ID_SYSTEM_COMM_INVALID_BUFFER_INDEX2, idx ) } return result; @@ -362,9 +352,9 @@ /*********************************************************************//** * @brief * The processReceivedMessage function processes a given message. - * @details Inputs: none - * @details Outputs: message processed - * @param message pointer to message to process + * @details \b Inputs: none + * @details \b Outputs: message processed + * @param message Pointer to the message to process. * @return none *************************************************************************/ void processReceivedMessage( MESSAGE_T *message )