Index: Utilities.c =================================================================== diff -u -r0c3a25f3d3f45560322c8be2dd2fe8e4ba8f5651 -rc639b7a9238140949b634e8a920973f6b0699776 --- Utilities.c (.../Utilities.c) (revision 0c3a25f3d3f45560322c8be2dd2fe8e4ba8f5651) +++ Utilities.c (.../Utilities.c) (revision c639b7a9238140949b634e8a920973f6b0699776) @@ -157,7 +157,7 @@ *************************************************************************/ void initTimeWindowedCount( TIME_WINDOWED_COUNT_T cnt, U32 maxCnt, U32 winMs ) { - if ( cnt < NUM_OF_TIME_WINDOWED_COUNTS ) + if ( ( cnt < NUM_OF_TIME_WINDOWED_COUNTS ) && ( maxCnt <= MAX_TIME_WINDOWED_COUNT ) ) { U32 i; @@ -172,12 +172,17 @@ } timeWindowedCountsInitialized[ cnt ] = TRUE; } + else + { + timeWindowedCountsInitialized[ cnt ] = FALSE; + } } /*********************************************************************//** * @brief * The incTimeWindowedCount function adds a new instance to a given time \n - * windowed count. + * windowed count. Must call initTimeWindowedCount() prior to calling this \n + * function for a given time windowed count. * *Note - thread protection not provided - assumed function will be called \n * by one task for a given time windowed count. * @details @@ -194,19 +199,27 @@ if ( ( cnt < NUM_OF_TIME_WINDOWED_COUNTS ) && ( TRUE == timeWindowedCountsInitialized[ cnt ] ) ) { - // replace oldest instance in list with this new one + // replace timestamp of oldest instance in list with this new one timeWindowedCounts[ cnt ][ timeWindowedCountIndexes[ cnt ] ] = getMSTimerCount(); - // move index to next position (may wrap) + // move index to next position in list (may wrap) timeWindowedCountIndexes[ cnt ] = INC_WRAP( timeWindowedCountIndexes[ cnt ], 0, timeWindowedCountsMaxCount[ cnt ] - 1 ); // update list count timeWindowedCountCounts[ cnt ] = INC_CAP( timeWindowedCountCounts[ cnt ], timeWindowedCountsMaxCount[ cnt ] ); - // check if too many instances in window of time + // check if too many instances within time window timeInMS = calcTimeSince( timeWindowedCounts[ cnt ][ timeWindowedCountIndexes[ cnt ] ] ); if ( ( timeWindowedCountCounts[ cnt ] >= timeWindowedCountsMaxCount[ cnt ] ) && ( timeInMS <= timeWindowedCountsWindowMs[ cnt ] ) ) { result = TRUE; } } + else + { +#ifdef _DG_ + SET_ALARM_WITH_1_U32_DATA ( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_UTIL_TIME_WINDOWED_COUNT_ERROR ); +#else + SET_ALARM_WITH_1_U32_DATA ( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_UTIL_TIME_WINDOWED_COUNT_ERROR ); +#endif + } return result; }