Index: firmware/App/Services/SystemCommDD.c =================================================================== diff -u -r090cfb22a7c0b4738299c3fb411ca77aaba8d968 -r9102c5da21a15bdaf4bb3bc38795ceb064e3c443 --- firmware/App/Services/SystemCommDD.c (.../SystemCommDD.c) (revision 090cfb22a7c0b4738299c3fb411ca77aaba8d968) +++ firmware/App/Services/SystemCommDD.c (.../SystemCommDD.c) (revision 9102c5da21a15bdaf4bb3bc38795ceb064e3c443) @@ -16,18 +16,16 @@ ***************************************************************************/ #include // for memcpy() -#include #include "can.h" #include "sci.h" #include "sys_dma.h" #include "Comm.h" -//#include "DrainPump.h" -//#include "Heaters.h" #include "Interrupts.h" #include "OperationModes.h" #include "Messaging.h" +#include "SystemCommDD.h" #include "Timers.h" #include "Utilities.h" @@ -38,15 +36,15 @@ // ********** private definitions ********** -#define TD_COMM_TIMEOUT_IN_MS 2000 ///< TD has not sent any broadcast messages for this much time +#define TD_COMM_TIMEOUT_IN_MS 2000 ///< TD has not sent any broadcast messages for this much time +#define RO_COMM_TIMEOUT_IN_MS 2000 ///< RO has not sent any broadcast messages 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_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 +#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. @@ -76,14 +74,16 @@ static volatile BOOL ddIsOnlyCANNode = TRUE; ///< flag indicating whether DG is alone on CAN bus. static OVERRIDE_U32_T tdCommunicationStatus = {0, 0, 0, 0}; ///< has TD sent a message since last check static volatile U32 timeOfLastTDCheckIn = 0; ///< last time we received an TD broadcast +static OVERRIDE_U32_T roCommunicationStatus = {0, 0, 0, 0}; ///< has RO sent a message since last check +static volatile U32 timeOfLastROCheckIn = 0; ///< last time we received an RO broadcast // ********** private function prototypes ********** /*********************************************************************//** * @brief - * The initSystemCommDD function initializes the DD SystemComm module. + * The initSystemCommDD function initializes the DD SystemComm unit. * @details \b Inputs: none - * @details \b Outputs: SystemComm module initialized. + * @details \b Outputs: SystemComm unit initialized. * @return none *************************************************************************/ void initSystemCommDD( void ) @@ -96,14 +96,51 @@ // 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 checkInFromTD function checks in the TD with the DD - indicating that + * the TD is communicating. + * @details \b Inputs: none + * @details \b Outputs: tdCommunicationStatus, timeOfLastTDCheckIn + * @return none + *************************************************************************/ +void checkInFromTD( void ) +{ + tdCommunicationStatus.data = TRUE; + timeOfLastTDCheckIn = getMSTimerCount(); + +// if ( TRUE == isAlarmActive( ALARM_ID_DD_TD_COMM_TIMEOUT ) ) +// { +// clearAlarmCondition( ALARM_ID_DD_TD_COMM_TIMEOUT ); +// } } /*********************************************************************//** * @brief + * The checkInFromRO function checks in the RO with the DD - indicating that + * the RO is communicating. + * @details \b Inputs: none + * @details \b Outputs: roCommunicationStatus, timeOfLastROCheckIn + * @return none + *************************************************************************/ +void checkInFromRO( void ) +{ + roCommunicationStatus.data = TRUE; + timeOfLastROCheckIn = getMSTimerCount(); + +// if ( TRUE == isAlarmActive( ALARM_ID_DD_RO_COMM_TIMEOUT ) ) +// { +// clearAlarmCondition( ALARM_ID_DD_RO_COMM_TIMEOUT ); +// } +} + +/*********************************************************************//** + * @brief * The isTDCommunicating function determines whether the TD is communicating * with the DD. - * @details \b Inputs: tdIsCommunicating + * @details \b Inputs: tdCommunicationStatus * @details \b Outputs: none * @return TRUE if TD has broadcast since last call, FALSE if not *************************************************************************/ @@ -114,6 +151,19 @@ /*********************************************************************//** * @brief + * The isROCommunicating function determines whether the RO is communicating + * with the DD. + * @details \b Inputs: roCommunicationStatus + * @details \b Outputs: none + * @return TRUE if RO has broadcast since last call, FALSE if not + *************************************************************************/ +BOOL isROCommunicating( void ) +{ + return getU32OverrideValue( &roCommunicationStatus ); +} + +/*********************************************************************//** + * @brief * The isOnlyCANNode function determines whether the DD is the only node * currently on the CAN bus. * @details \b Inputs: ddIsOnlyCANNode @@ -158,7 +208,7 @@ /*********************************************************************//** * @brief * The checkForCommTimeouts function checks for sub-system communication timeout errors. - * @details \b Inputs: timeOfLastDGCheckIn, timeOfLastUICheckIn + * @details \b Inputs: timeOfLastTDCheckIn, timeOfLastROCheckIn * @details \b Outputs: possibly a comm t/o alarm * @return none *************************************************************************/ @@ -170,14 +220,21 @@ setTDOperationMode( 0, 0 ); // If TD off or not connected, consider TD mode is fault. //stopHeater( DG_TRIMMER_HEATER ); // If TD off or not connected, ensure trimmer heater is off. } + + if ( TRUE == didTimeout( timeOfLastROCheckIn, RO_COMM_TIMEOUT_IN_MS ) ) + { + roCommunicationStatus.data = FALSE; + //setROOperationMode( 0, 0 ); // If RO off or not connected, consider RO mode is fault. + } } - /*********************************************************************//** * @brief * The getInBufferID function gets the buffer ID for a given buffer index. * @details \b Inputs: CAN_IN_BUFFERS[] * @details \b Outputs: none + * @details \b Alarm: ALARM_ID_DD_SOFTWARE_FAULT when invalid CAN Input + * buffer is seen. * @param idx incoming buffer index (e.g. 0 indicates first incoming buffer) * @return buffer id associated with given incoming buffer index *************************************************************************/ @@ -192,7 +249,7 @@ } else { - // TODO - s/w fault + SET_ALARM_WITH_1_U32_DATA( ALARM_ID_DD_SOFTWARE_FAULT, SW_FAULT_ID_CAN_IN_INVALID_BUFFER ) } return result; @@ -213,16 +270,17 @@ { if ( TRUE == incTimeWindowedCount( TIME_WINDOWED_COUNT_BAD_MSG_CRC ) ) { - SET_ALARM_WITH_1_U32_DATA( ALARM_ID_DD_COMM_TOO_MANY_BAD_CRCS, 2 ); // 2 for DG + SET_ALARM_WITH_1_U32_DATA( ALARM_ID_DD_COMM_TOO_MANY_BAD_CRCS, 2 ); // 2 for DD } } - /*********************************************************************//** * @brief * The getOutBufferID function gets the buffer ID for a given buffer index. * @details \b Inputs: CAN_OUT_BUFFERS[] * @details \b Outputs: none + * @details \b Alarm: ALARM_ID_DD_SOFTWARE_FAULT when invalid CAN Output + * buffer is seen. * @param idx outgoing buffer index (e.g. 0 indicates first outgoing buffer) * @return buffer id associated with given outgoing buffer index *************************************************************************/ @@ -237,7 +295,7 @@ } else { - // TODO - s/w fault + SET_ALARM_WITH_1_U32_DATA( ALARM_ID_DD_SOFTWARE_FAULT, SW_FAULT_ID_CAN_OUT_INVALID_BUFFER ) } return result; @@ -266,45 +324,35 @@ /*********************************************************************//** * @brief - * The testSetTDCommunicationStatus function sets the override + * The testTDCommunicationStatusOverride function sets the override * of the TD communication status. * @details \b Inputs: none * @details \b Outputs: tdCommunicationStatus - * @return TRUE if reset successful, FALSE if not + * @param message Override message from Dialin which includes the flag + * value to override for the Td communication status. + * @return TRUE if override successful, FALSE if not *************************************************************************/ -BOOL testSetTDCommunicationStatus( U32 value ) +BOOL testTDCommunicationStatusOverride( MESSAGE_T *message ) { - BOOL result = FALSE; + BOOL result = u32Override( message, &tdCommunicationStatus, FALSE, TRUE ); - if (TRUE == isTestingActivated() ) - { - result = TRUE; - tdCommunicationStatus.ovData = value; - tdCommunicationStatus.override = OVERRIDE_KEY; - - } return result; } /*********************************************************************//** * @brief - * The testResetTDCommuncationStatus function resets the override - * of the TD communication status. + * The testROCommunicationStatusOverride function sets the override + * of the RO communication status. * @details \b Inputs: none - * @details \b Outputs: tdCommunicationStatus - * @return TRUE if reset successful, FALSE if not + * @details \b Outputs: roCommunicationStatus + * @param message Override message from Dialin which includes the flag + * value to override for the RO communication status. + * @return TRUE if override successful, FALSE if not *************************************************************************/ -BOOL testResetTDCommuncationStatus( void ) +BOOL testROCommunicationStatusOverride( MESSAGE_T *message ) { - BOOL result = FALSE; + BOOL result = u32Override( message, &roCommunicationStatus, FALSE, TRUE ); - if (TRUE == isTestingActivated() ) - { - result = TRUE; - tdCommunicationStatus.override = OVERRIDE_RESET; - tdCommunicationStatus.ovData = tdCommunicationStatus.ovInitData; - - } return result; }