Index: firmware/App/Services/Interrupts.c =================================================================== diff -u -r439894cb0508e69af3ece09ae57a62feac09e3f2 -r8f5feed92f41a476d5656038bcdfe884e17bd593 --- firmware/App/Services/Interrupts.c (.../Interrupts.c) (revision 439894cb0508e69af3ece09ae57a62feac09e3f2) +++ firmware/App/Services/Interrupts.c (.../Interrupts.c) (revision 8f5feed92f41a476d5656038bcdfe884e17bd593) @@ -1,4 +1,4 @@ -/************************************************************************** +/**********************************************************************//** * * Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. * @@ -24,13 +24,21 @@ #include "Interrupts.h" #include "FPGA.h" #include "SystemComm.h" +#include "Utilities.h" #ifdef DEBUG_ENABLED #include "SystemCommMessages.h" -#endif +#endif +/** + * @addtogroup Interrupts + * @{ + */ + // ********** private definitions ********** + +#define MAX_COMM_ERRORS 5 ///< Maximum number of a given comm error for a given time window. +#define COMM_ERROR_TIME_WINDOW_MS (10 * SEC_PER_MIN * MS_PER_SECOND) ///< Time window for comm error counts. - // ********** private data ********** #ifdef DEBUG_ENABLED @@ -46,24 +54,49 @@ static U32 can1ParityCnt = 0; // ********** private function prototypes ********** + +/*********************************************************************//** + * @brief + * The initInterrupts function initializes the Interrupts module. + * @details + * Inputs : none + * Outputs : Interrupts module initialized. + * @return none + *************************************************************************/ +void initInterrupts( void ) +{ + // initialize various time windowed counts for monitoring CAN & UART errors and warnings + initTimeWindowedCount( TIME_WINDOWED_COUNT_CAN_PASSIVE, MAX_COMM_ERRORS, COMM_ERROR_TIME_WINDOW_MS ); + initTimeWindowedCount( TIME_WINDOWED_COUNT_CAN_OFF, MAX_COMM_ERRORS, COMM_ERROR_TIME_WINDOW_MS ); + initTimeWindowedCount( TIME_WINDOWED_COUNT_CAN_PARITY, MAX_COMM_ERRORS, COMM_ERROR_TIME_WINDOW_MS ); + initTimeWindowedCount( TIME_WINDOWED_COUNT_FPGA_UART_FRAME_ERROR, MAX_COMM_ERRORS, COMM_ERROR_TIME_WINDOW_MS ); + initTimeWindowedCount( TIME_WINDOWED_COUNT_FPGA_UART_OVERRUN, MAX_COMM_ERRORS, COMM_ERROR_TIME_WINDOW_MS ); +} - -/************************************************************************* - * @brief phantomInterrupt +/*********************************************************************//** + * @brief * The phantomInterrupt function handles phantom interrupts. * @details * Inputs : none * Outputs : phantom interrupt handled. - * @param none * @return none *************************************************************************/ void phantomInterrupt(void) { // TODO - what to do with phantom interrupts? +#ifdef DEBUG_ENABLED + { + char debugStr[ 256 ]; + + sprintf( debugStr, "DG-phantom interrupt\n" ); + sendDebugData( (U08*)debugStr, strlen(debugStr) ); + sendDebugDataToUI( (U08*)debugStr ); + } +#endif } -/************************************************************************* - * @brief canMessageNotification +/*********************************************************************//** + * @brief * The canMessageNotification function handles CAN message notifications. * @details * Inputs : none @@ -80,8 +113,8 @@ } } -/************************************************************************* - * @brief canErrorNotification +/*********************************************************************//** + * @brief * The canErrorNotification function handles CAN error notifications. * @details * Inputs : none @@ -104,6 +137,10 @@ if ( notification & canLEVEL_PARITY_ERR ) { can1ParityCnt++; + if ( TRUE == incTimeWindowedCount( TIME_WINDOWED_COUNT_CAN_PARITY ) ) + { + SET_ALARM_WITH_1_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_CAN_PARITY_ERROR ) + } #ifdef DEBUG_ENABLED sprintf( debugStr, "CAN parity error:%5d \n", can1ParityCnt ); sendDebugData( (U08*)debugStr, strlen(debugStr) ); @@ -113,6 +150,10 @@ else if ( notification & canLEVEL_BUS_OFF ) { can1BusOffCnt++; + if ( TRUE == incTimeWindowedCount( TIME_WINDOWED_COUNT_CAN_OFF ) ) + { + SET_ALARM_WITH_1_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_CAN_OFF_ERROR ) + } #ifdef DEBUG_ENABLED sprintf( debugStr, "CAN bus off error:%5d \n", can1BusOffCnt ); sendDebugData( (U08*)debugStr, strlen(debugStr) ); @@ -131,6 +172,10 @@ else if ( notification & canLEVEL_PASSIVE ) { can1PassiveCnt++; + if ( TRUE == incTimeWindowedCount( TIME_WINDOWED_COUNT_CAN_PASSIVE ) ) + { + SET_ALARM_WITH_1_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_CAN_PASSIVE_WARNING ) + } #ifdef DEBUG_ENABLED sprintf( debugStr, "CAN passive warning:%5d \n", can1PassiveCnt ); sendDebugData( (U08*)debugStr, strlen(debugStr) ); @@ -144,8 +189,8 @@ } } -/************************************************************************* - * @brief sciNotification +/*********************************************************************//** + * @brief * The sciNotification function handles UART communication error interrupts. \n * Frame and Over-run errors are handled. * @details @@ -168,6 +213,10 @@ { sci2FrameErrorCnt++; clearSCI2CommErrors(); + if ( TRUE == incTimeWindowedCount( TIME_WINDOWED_COUNT_FPGA_UART_FRAME_ERROR ) ) + { + SET_ALARM_WITH_1_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_FPGA_UART_FRAME_ERROR ) + } // TODO - try to do something to recover (+ max retries = comm fault) #ifdef DEBUG_ENABLED sprintf( debugStr, "FPGA UART FR err:%5d \n", sci2FrameErrorCnt ); @@ -179,6 +228,10 @@ { sci2OverrunErrorCnt++; clearSCI2CommErrors(); + if ( TRUE == incTimeWindowedCount( TIME_WINDOWED_COUNT_FPGA_UART_OVERRUN ) ) + { + SET_ALARM_WITH_1_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_FPGA_UART_OVERRUN_ERROR ) + } // TODO - try to do something to recover (+ max retries = comm fault) #ifdef DEBUG_ENABLED sprintf( debugStr, "FPGA UART OR err:%5d \n", sci2OverrunErrorCnt ); @@ -212,8 +265,8 @@ #endif } -/************************************************************************* - * @brief dmaGroupANotification +/*********************************************************************//** + * @brief * The dmaGroupANotification function handles communication DMA interrupts. * @details * Inputs : none @@ -258,4 +311,5 @@ } } } - + +/**@}*/