Index: firmware/App/Services/Interrupts.c =================================================================== diff -u -rde5a0d43bdef611d963d11855bc958a8d8899a09 -r8dad6fab1c33602ad94908fd31b8b15153a9eb6e --- firmware/App/Services/Interrupts.c (.../Interrupts.c) (revision de5a0d43bdef611d963d11855bc958a8d8899a09) +++ firmware/App/Services/Interrupts.c (.../Interrupts.c) (revision 8dad6fab1c33602ad94908fd31b8b15153a9eb6e) @@ -24,63 +24,97 @@ #include "AlarmMgmt.h" #include "BloodFlow.h" -#include "Comm.h" +#include "Comm.h" #include "DialInFlow.h" #include "DialOutFlow.h" #include "Interrupts.h" #include "FPGA.h" #include "SystemComm.h" #include "TaskGeneral.h" #include "TaskPriority.h" -#include "TaskTimer.h" +#include "TaskTimer.h" +#include "Utilities.h" #ifdef DEBUG_ENABLED #include "SystemCommMessages.h" #endif -// ********** private definitions ********** +/** + * @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. + +#define HET1_EDGE_BP_ROTOR_HALL_SENSOR 0 ///< HET1 edge detector associated with blood pump rotor hall sensor. +#define HET1_EDGE_DPI_ROTOR_HALL_SENSOR 1 ///< HET1 edge detector associated with dialysate inlet pump rotor hall sensor. +#define HET1_EDGE_DPO_ROTOR_HALL_SENSOR 2 ///< HET1 edge detector associated with dialysate outlet pump rotor hall sensor. -#define HET1_EDGE_BP_ROTOR_HALL_SENSOR 0 -#define HET1_EDGE_DPI_ROTOR_HALL_SENSOR 1 -#define HET1_EDGE_DPO_ROTOR_HALL_SENSOR 2 - // ********** private data ********** #ifdef DEBUG_ENABLED static U32 sci1FrameErrorCnt = 0; static U32 sci1OverrunErrorCnt = 0; #endif -static U32 sci2FrameErrorCnt = 0; -static U32 sci2OverrunErrorCnt = 0; +static U32 sci2FrameErrorCnt = 0; ///< FPGA serial frame error counter. +static U32 sci2OverrunErrorCnt = 0; ///< FPGA serial overrun error counter. -static U32 can1PassiveCnt = 0; -static U32 can1WarningCnt = 0; -static U32 can1BusOffCnt = 0; -static U32 can1ParityCnt = 0; +static U32 can1PassiveCnt = 0; ///< CAN passive mode counter. +static U32 can1WarningCnt = 0; ///< CAN warning mode counter. +static U32 can1BusOffCnt = 0; ///< CAN buss off mode counter. +static U32 can1ParityCnt = 0; ///< CAN parity error counter. // ********** 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 * 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, "HD-phantom interrupt\n" ); + sendDebugData( (U08*)debugStr, strlen(debugStr) ); + sendDebugDataToUI( (U08*)debugStr ); + } +#endif } -/************************************************************************* +/*********************************************************************//** * @brief * The rtiNotification function handles real-time interrupt notifications. * @details * Inputs : none * Outputs : RTI notification handled. - * @param notification : Which RTI timer caused this interrupt. + * @param notification Which RTI timer caused this interrupt * @return none *************************************************************************/ void rtiNotification(uint32 notification) @@ -109,14 +143,14 @@ } } -/************************************************************************* +/*********************************************************************//** * @brief * The canMessageNotification function handles CAN message notifications. * @details * Inputs : none * Outputs : CAN message notification handled. - * @param node : which CAN controller - * @param messageBox : which message box triggered the message notification + * @param node which CAN controller + * @param messageBox which message box triggered the message notification * @return none *************************************************************************/ void canMessageNotification(canBASE_t *node, uint32 messageBox) @@ -127,79 +161,91 @@ } } -/************************************************************************* +/*********************************************************************//** * @brief * The canErrorNotification function handles CAN error notifications. * @details * Inputs : none * Outputs : CAN error notification handled. - * @param node : which CAN controller - * @param notification : canLEVEL_PASSIVE (0x20) : When RX- or TX error counter are between 32 and 63 \n - * canLEVEL_WARNING (0x40) : When RX- or TX error counter are between 64 and 127 \n - * canLEVEL_BUS_OFF (0x80) : When RX- or TX error counter are between 128 and 255 \n - * canLEVEL_PARITY_ERR (0x100): When parity error detected on CAN RAM read access + * @param node which CAN controller + * @param notification canLEVEL_PASSIVE (0x20) : When RX- or TX error counter are between 32 and 63 + * canLEVEL_WARNING (0x40) : When RX- or TX error counter are between 64 and 127 + * canLEVEL_BUS_OFF (0x80) : When RX- or TX error counter are between 128 and 255 + * canLEVEL_PARITY_ERR (0x100): When parity error detected on CAN RAM read access * @return none *************************************************************************/ void canErrorNotification(canBASE_t *node, uint32 notification) { #ifdef DEBUG_ENABLED - // TODO - temporary debug code - remove later char debugStr[ 256 ]; -#endif +#endif + if ( node == canREG1 ) { if ( notification & canLEVEL_PARITY_ERR ) { can1ParityCnt++; + if ( TRUE == incTimeWindowedCount( TIME_WINDOWED_COUNT_CAN_PARITY ) ) + { + SET_ALARM_WITH_1_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_CAN_PARITY_ERROR ) + } #ifdef DEBUG_ENABLED - // TODO - temporary debug code - remove later - sprintf( debugStr, "CAN parity error:%5d \n", can1ParityCnt ); - sendDebugData( (U08*)debugStr, strlen(debugStr) ); + sprintf( debugStr, "CAN parity error:%5d \n", can1ParityCnt ); + sendDebugData( (U08*)debugStr, strlen(debugStr) ); + sendDebugDataToUI( (U08*)debugStr ); #endif } else if ( notification & canLEVEL_BUS_OFF ) { can1BusOffCnt++; + if ( TRUE == incTimeWindowedCount( TIME_WINDOWED_COUNT_CAN_OFF ) ) + { + SET_ALARM_WITH_1_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_CAN_OFF_ERROR ) + } #ifdef DEBUG_ENABLED - // TODO - temporary debug code - remove later - sprintf( debugStr, "CAN bus off error:%5d \n", can1BusOffCnt ); - sendDebugData( (U08*)debugStr, strlen(debugStr) ); + sprintf( debugStr, "CAN bus off error:%5d \n", can1BusOffCnt ); + sendDebugData( (U08*)debugStr, strlen(debugStr) ); + sendDebugDataToUI( (U08*)debugStr ); #endif } else if ( notification & canLEVEL_WARNING ) { can1WarningCnt++; #ifdef DEBUG_ENABLED - // TODO - temporary debug code - remove later - sprintf( debugStr, "CAN bus warning:%5d \n", can1WarningCnt ); - sendDebugData( (U08*)debugStr, strlen(debugStr) ); + 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_HD_SOFTWARE_FAULT, SW_FAULT_ID_CAN_PASSIVE_WARNING ) + } #ifdef DEBUG_ENABLED - // TODO - temporary debug code - remove later - sprintf( debugStr, "CAN passive warning:%5d \n", can1PassiveCnt ); - sendDebugData( (U08*)debugStr, strlen(debugStr) ); + sprintf( debugStr, "CAN passive warning:%5d \n", can1PassiveCnt ); + sendDebugData( (U08*)debugStr, strlen(debugStr) ); + sendDebugDataToUI( (U08*)debugStr ); #endif } else { - // ignore - other bits undefined + // ignore - other notifications undefined } } } -/************************************************************************* +/*********************************************************************//** * @brief - * The sciNotification function handles UART communication error interrupts. \n + * 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) + * @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) @@ -215,22 +261,28 @@ { sci2FrameErrorCnt++; clearSCI2CommErrors(); - // TODO - try to do something to recover (+ max retries = comm fault) + if ( TRUE == incTimeWindowedCount( TIME_WINDOWED_COUNT_FPGA_UART_FRAME_ERROR ) ) + { + SET_ALARM_WITH_1_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_FPGA_UART_FRAME_ERROR ) + } #ifdef DEBUG_ENABLED - // TODO - temporary debug code - remove later - sprintf( debugStr, "FPGA UART frame error:%5d \n", sci2FrameErrorCnt ); + 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(); - // TODO - try to do something to recover (+ max retries = comm fault) + if ( TRUE == incTimeWindowedCount( TIME_WINDOWED_COUNT_FPGA_UART_OVERRUN ) ) + { + SET_ALARM_WITH_1_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_FPGA_UART_OVERRUN_ERROR ) + } #ifdef DEBUG_ENABLED - // TODO - temporary debug code - remove later - sprintf( debugStr, "FPGA UART overrun error:%5d \n", sci2OverrunErrorCnt ); + sprintf( debugStr, "FPGA UART OR err:%5d \n", sci2OverrunErrorCnt ); sendDebugData( (U08*)debugStr, strlen(debugStr) ); + sendDebugDataToUI( (U08*)debugStr ); #endif } } @@ -241,34 +293,30 @@ { sci1FrameErrorCnt++; clearSCI1CommErrors(); - // TODO - try to do something to recover (+ max retries = comm fault) - - // TODO - temporary debug code - remove later - sprintf( debugStr, "Debug UART frame error:%5d \n", sci1FrameErrorCnt ); + 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(); - // TODO - try to do something to recover (+ max retries = comm fault) - - // TODO - temporary debug code - remove later - sprintf( debugStr, "Debug UART overrun error:%5d \n", sci1OverrunErrorCnt ); + 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. - * @param inttype : type of DMA interrupt - * @param channel : DMA channel that caused the interrupt + * @param inttype type of DMA interrupt + * @param channel DMA channel that caused the interrupt * @return none *************************************************************************/ void dmaGroupANotification(dmaInterrupt_t inttype, uint32 channel) @@ -308,14 +356,14 @@ } } -/************************************************************************* +/*********************************************************************//** * @brief * The edgeNotification function handles rotor hall sensor interrupts. * @details * Inputs : none * Outputs : Rotor hall sensor interrupt is handled according to pin associated with given edge. - * @param hetREG : HET controller associated with the edge. - * @param edge : Which edge was detected. + * @param hetREG HET controller associated with the edge + * @param edge Which edge was detected * @return none *************************************************************************/ void edgeNotification(hetBASE_t * hetREG, uint32 edge) @@ -339,8 +387,10 @@ break; default: - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_SOFTWARE_FAULT, SW_FAULT_ID_INTERRUPTS_INVALID_EDGE_DETECTED, edge ) + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_INTERRUPTS_INVALID_EDGE_DETECTED, edge ) break; } } } + +/**@}*/