Index: firmware/App/Services/Interrupts.c =================================================================== diff -u -r5e0cd9b5be11ff4b2acaadbdcafc4ffe05172aa1 -r7d4711edd7b40cd3e29f43e766f79a8a09586fe9 --- firmware/App/Services/Interrupts.c (.../Interrupts.c) (revision 5e0cd9b5be11ff4b2acaadbdcafc4ffe05172aa1) +++ firmware/App/Services/Interrupts.c (.../Interrupts.c) (revision 7d4711edd7b40cd3e29f43e766f79a8a09586fe9) @@ -1,17 +1,17 @@ /************************************************************************** * -* Copyright (c) 2019-2020 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 Interrupts.c +* @file Interrupts.c * -* @author (last) Sean Nash -* @date (last) 13-Aug-2020 +* @author (last) Dara Navaei +* @date (last) 23-Sep-2023 * -* @author (original) Dara Navaei -* @date (original) 05-Nov-2019 +* @author (original) Dara Navaei +* @date (original) 05-Nov-2019 * ***************************************************************************/ @@ -29,9 +29,6 @@ #include "TaskPriority.h" #include "TaskTimer.h" #include "Utilities.h" -#ifdef DEBUG_ENABLED - #include "SystemCommMessages.h" -#endif /** * @addtogroup Interrupts @@ -44,67 +41,48 @@ #define COMM_ERROR_TIME_WINDOW_MS (10 * SEC_PER_MIN * MS_PER_SECOND) ///< Time window for comm error counts. // ********** private data ********** + +static BOOL sci2FEOEError = FALSE; ///< FPGA serial frame or overrun flag; -#ifdef DEBUG_ENABLED - static U32 sci1FrameErrorCnt = 0; - static U32 sci1OverrunErrorCnt = 0; -#endif -static U32 sci2FrameErrorCnt = 0; ///< SCI2 frame error count. -static U32 sci2OverrunErrorCnt = 0; ///< SCI2 overrun error count. +static U32 can1WarningCnt; ///< CAN1 warning count. +static U32 can1BusOffCnt; ///< CAN1 bus offline count. +static U32 can1ParityCnt; ///< CAN1 parity count. -static U32 can1PassiveCnt = 0; ///< CAN1 passive count. -static U32 can1WarningCnt = 0; ///< CAN1 warning count. -static U32 can1BusOffCnt = 0; ///< CAN1 bus offline count. -static U32 can1ParityCnt = 0; ///< CAN1 parity count. - -// ********** private function prototypes ********** - /*********************************************************************//** * @brief * The initInterrupts function initializes the Interrupts module. - * @details - * Inputs : none - * Outputs : Interrupts module initialized + * @details Inputs: none + * @details Outputs: Interrupts module initialized * @return none *************************************************************************/ void initInterrupts( void ) { + can1WarningCnt = 0; + can1BusOffCnt = 0; + can1ParityCnt = 0; + // 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 * The phantomInterrupt function handles phantom interrupts. - * @details - * Inputs : none - * Outputs : phantom interrupt handled + * @details Inputs: none + * @details Outputs: phantom interrupt handled * @return none *************************************************************************/ void phantomInterrupt( void ) { - // TODO - what to do with phantom interrupts? -#ifdef DEBUG_ENABLED - { - char debugStr[ 50 ]; - - strcpy( debugStr, "DG-phantom interrupt\n" ); - sendDebugData( (U08*)debugStr, strlen(debugStr) ); - sendDebugDataToUI( (U08*)debugStr ); - } -#endif + SET_ALARM_WITH_1_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_PHANTOM_INTERRUPT ) } /*********************************************************************//** * @brief * The rtiNotification function handles real-time interrupt notifications. - * @details - * Inputs : none - * Outputs : RTI notification handled + * @details Inputs: none + * @details Outputs: RTI notification handled * @param notification Which RTI timer caused this interrupt * @return none *************************************************************************/ @@ -129,17 +107,16 @@ break; default: - // TODO - s/w fault? + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_INVALID_RTI_NOTIFICATION, notification ) break; } } /*********************************************************************//** * @brief * The canMessageNotification function handles CAN message notifications. - * @details - * Inputs : none - * Outputs : CAN message notification handled + * @details Inputs: none + * @details Outputs: CAN message notification handled * @param node which CAN controller * @param messageBox which message box triggered the message notification * @return none @@ -155,9 +132,8 @@ /*********************************************************************//** * @brief * The canErrorNotification function handles CAN error notifications. - * @details - * Inputs : none - * Outputs : CAN error notification handled. + * @details Inputs: none + * @details Outputs: CAN error notification handled. * @param node which CAN controller * @param notification CAN error notification: * canLEVEL_PASSIVE (0x20) : When RX- or TX error counter are between 32 and 63 \n @@ -168,145 +144,74 @@ *************************************************************************/ void canErrorNotification(canBASE_t *node, uint32 notification) { -#ifdef DEBUG_ENABLED - char debugStr[ 256 ]; -#endif - if ( node == canREG1 ) { + // Parity error - message RAM is corrupted 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) ); - sendDebugDataToUI( (U08*)debugStr ); -#endif } + // Bus off - our transmitter has counted 255+ errors 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) ); - sendDebugDataToUI( (U08*)debugStr ); -#endif } + // Warning - our transmitter has counted 96+ errors else if ( notification & canLEVEL_WARNING ) { can1WarningCnt++; -#ifdef DEBUG_ENABLED - sprintf( debugStr, "CAN bus warning:%5d \n", can1WarningCnt ); - sendDebugData( (U08*)debugStr, strlen(debugStr) ); - sendDebugDataToUI( (U08*)debugStr ); -#endif } - 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) ); - sendDebugDataToUI( (U08*)debugStr ); -#endif - } else { - // ignore - other notifications undefined + // Ignore - other notifications - unhandled } } -} +} -/*********************************************************************//** - * @brief - * The sciNotification function handles UART communication error interrupts. - * Frame and Over-run errors are handled. - * @details - * Inputs : none - * Outputs : UART error interrupts handled. - * @param sci pointer to the SCI peripheral that detected the error - * @param flags error flag(s) - * @return none - *************************************************************************/ -void sciNotification(sciBASE_t *sci, uint32 flags) -{ -#ifdef DEBUG_ENABLED - // TODO - temporary debug code - remove later - char debugStr[ 256 ]; -#endif +/*********************************************************************//** + * @brief + * The sciNotification function handles UART communication error interrupts. + * Frame and Over-run errors are handled. + * @details Inputs: none + * @details Outputs: UART error interrupts handled. + * @param sci Pointer to the SCI peripheral that detected the error + * @param flags error flag(s) + * @return none + *************************************************************************/ +void sciNotification(sciBASE_t *sci, uint32 flags) +{ +#ifndef _VECTORCAST_ + // Cannot set the pointers to be equal in VectorCAST. Can define pointers but the user does not have any control on the address of it + if ( sci == scilinREG ) +#endif + { + if ( ( flags & SCI_FE_INT ) != 0 ) + { + sci2FEOEError = TRUE; + scilinREG->FLR |= SCI_FE_INT; + } + + if ( ( flags & SCI_OE_INT ) != 0 ) + { + sci2FEOEError = TRUE; + scilinREG->FLR |= SCI_OE_INT; + } + } +} - if ( sci == scilinREG ) - { - if ( ( flags & SCI_FE_INT ) != 0 ) - { - 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 ) - } -#ifdef DEBUG_ENABLED - sprintf( debugStr, "FPGA UART FR err:%5d \n", sci2FrameErrorCnt ); - sendDebugData( (U08*)debugStr, strlen(debugStr) ); - sendDebugDataToUI( (U08*)debugStr ); -#endif - } - if ( ( flags & SCI_OE_INT ) != 0 ) - { - 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 ) - } -#ifdef DEBUG_ENABLED - sprintf( debugStr, "FPGA UART OR err:%5d \n", sci2OverrunErrorCnt ); - sendDebugData( (U08*)debugStr, strlen(debugStr) ); - sendDebugDataToUI( (U08*)debugStr ); -#endif - } - } -#ifdef DEBUG_ENABLED - else if ( sci == sciREG ) - { - if ( ( flags & SCI_FE_INT ) != 0 ) - { - sci1FrameErrorCnt++; - clearSCI1CommErrors(); - sprintf( debugStr, "Debug UART FR err:%5d \n", sci1FrameErrorCnt ); - sendDebugData( (U08*)debugStr, strlen(debugStr) ); - sendDebugDataToUI( (U08*)debugStr ); - } - if ( ( flags & SCI_OE_INT ) != 0 ) - { - sci1OverrunErrorCnt++; - clearSCI1CommErrors(); - sprintf( debugStr, "Debug UART OR err:%5d \n", sci1OverrunErrorCnt ); - sendDebugData( (U08*)debugStr, strlen(debugStr) ); - sendDebugDataToUI( (U08*)debugStr ); - } - } -#endif -} - /*********************************************************************//** * @brief * The dmaGroupANotification function handles communication DMA interrupts. - * @details - * Inputs : none - * Outputs : DMA interrupt is handled. + * @details Inputs: none + * @details Outputs: DMA interrupt is handled. * @param inttype type of DMA interrupt * @param channel DMA channel that caused the interrupt * @return none @@ -322,30 +227,36 @@ signalFPGAReceiptCompleted(); break; -#ifdef DEBUG_ENABLED - case DMA_CH1: // PC receive channel - clearSCI1DMAReceiveInterrupt(); - // handle received packet from PC - handleUARTMsgRecvPacketInterrupt(); - break; -#endif case DMA_CH2: // FPGA transmit channel clearSCI2DMATransmitInterrupt(); signalFPGATransmitCompleted(); break; -#ifdef DEBUG_ENABLED - case DMA_CH3: // PC transmit channel - clearSCI1DMATransmitInterrupt(); - // send next pending packet to PC (if any) - handleUARTMsgXmitPacketInterrupt(); - break; -#endif default: // TODO - ignore? break; } } -} +} + +/*********************************************************************//** + * @brief + * The getSci2FEOEError function returns the sci2FEOEError (OE - Overrun, + * FE - Framing Error) status and resets the status if TRUE + * @details Inputs: sci2FEOEError + * @details Outputs: none + * @return sci2 FE / OE error + *************************************************************************/ +BOOL getSci2FEOEError( void ) +{ + BOOL returnValue = sci2FEOEError; + if ( TRUE == returnValue ) + { + sci2FEOEError = FALSE; + } + + return returnValue; +} + /**@}*/