Index: Utilities.c =================================================================== diff -u -r2c508d911fedf7fea1a081f449070aeed248b85c -r3209df98c1afd0a9dac601db5a975f7e1a83909b --- Utilities.c (.../Utilities.c) (revision 2c508d911fedf7fea1a081f449070aeed248b85c) +++ Utilities.c (.../Utilities.c) (revision 3209df98c1afd0a9dac601db5a975f7e1a83909b) @@ -14,34 +14,34 @@ * @date (original) 17-Feb-2020 * ***************************************************************************/ - + #include "Common.h" -#include "FPGA.h" -#include "Timers.h" -#include "Utilities.h" - -/** - * @addtogroup Utilities - * @{ - */ - -// ********** private definitions ********** +#include "FPGA.h" +#include "Timers.h" +#include "Utilities.h" -#define INITIAL_CRC16_VAL 0xFFFF ///< Seed for 16-bit CRC function. +/** + * @addtogroup Utilities + * @{ + */ + +// ********** private definitions ********** + +#define INITIAL_CRC16_VAL 0xFFFF ///< Seed for 16-bit CRC function. #define INITIAL_CRC08_VAL 0x00 ///< Seed for 8-bit CRC function. #define HEX_LETTER_TO_NUMBER_CONV 0x37 ///< Hex letter (i.e. A) to number conversion. -#define STR_TO_HEX_CONV_MAX_BYTES 8 ///< String to hex conversion maximum allowed bytes. +#define STR_TO_HEX_CONV_MAX_BYTES 8 ///< String to hex conversion maximum allowed bytes. #define SEMAPHORE_IN_USE_TIMEOUT_MS ( 10 * MS_PER_SECOND ) ///< Taken semaphore timeout in milliseconds. - + // ********** private data ********** /// Semaphore data structure typedef struct { U32 semaphoreStartTimeMS; ///< Semaphore start time in milliseconds. volatile BOOL isSemaphoreTaken; ///< Flag to indicate whether the semaphore is taken or not. -} SEMAPHORE_STATUS_T; +} SEMAPHORE_STATUS_T; /// CRC-32 look-up table. const U32 CRC32_TABLE[] = @@ -79,70 +79,70 @@ 0x243CC87A, 0x3AE0A73B, 0x198416F8, 0x075879B9, 0x5F4D757E, 0x41911A3F, 0x62F5ABFC, 0x7C29C4BD, 0xD2DFB272, 0xCC03DD33, 0xEF676CF0, 0xF1BB03B1, 0xA9AE0F76, 0xB7726037, 0x9416D1F4, 0x8ACABEB5, }; - -/// CRC-16 look-up table. -const U16 CRC16_TABLE[] = -{ - 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, - 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef, - 0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6, - 0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de, - 0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485, - 0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d, - 0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4, - 0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc, - 0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823, - 0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b, - 0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12, - 0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a, - 0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41, - 0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49, - 0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70, - 0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78, - 0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f, - 0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067, - 0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e, - 0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256, - 0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d, - 0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405, - 0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c, - 0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634, - 0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab, - 0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3, - 0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a, - 0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92, - 0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9, - 0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1, - 0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8, - 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0 -}; - -/// CRC-8 look-up table. -const U08 CRC8_TABLE[] = { - 0, 49, 98, 83, 196, 245, 166, 151, 185, 136, 219, 234, 125, 76, 31, 46, - 67, 114, 33, 16, 135, 182, 229, 212, 250, 203, 152, 169, 62, 15, 92, 109, - 134, 183, 228, 213, 66, 115, 32, 17, 63, 14, 93, 108, 251, 202, 153, 168, - 197, 244, 167, 150, 1, 48, 99, 82, 124, 77, 30, 47, 184, 137, 218, 235, - 61, 12, 95, 110, 249, 200, 155, 170, 132, 181, 230, 215, 64, 113, 34, 19, - 126, 79, 28, 45, 186, 139, 216, 233, 199, 246, 165, 148, 3, 50, 97, 80, - 187, 138, 217, 232, 127, 78, 29, 44, 2, 51, 96, 81, 198, 247, 164, 149, - 248, 201, 154, 171, 60, 13, 94, 111, 65, 112, 35, 18, 133, 180, 231, 214, - 122, 75, 24, 41, 190, 143, 220, 237, 195, 242, 161, 144, 7, 54, 101, 84, - 57, 8, 91, 106, 253, 204, 159, 174, 128, 177, 226, 211, 68, 117, 38, 23, - 252, 205, 158, 175, 56, 9, 90, 107, 69, 116, 39, 22, 129, 176, 227, 210, - 191, 142, 221, 236, 123, 74, 25, 40, 6, 55, 100, 85, 194, 243, 160, 145, - 71, 118, 37, 20, 131, 178, 225, 208, 254, 207, 156, 173, 58, 11, 88, 105, - 4, 53, 102, 87, 192, 241, 162, 147, 189, 140, 223, 238, 121, 72, 27, 42, - 193, 240, 163, 146, 5, 52, 103, 86, 120, 73, 26, 43, 188, 141, 222, 239, - 130, 179, 224, 209, 70, 119, 36, 21, 59, 10, 89, 104, 255, 206, 157, 172 -}; - -// variables for time windowed counts (counts # of instances in a specific window of time) -static BOOL timeWindowedCountsInitialized[ NUM_OF_TIME_WINDOWED_COUNTS ]; ///< Initialized flags for time windowed counts -static U32 timeWindowedCountsMaxCount[ NUM_OF_TIME_WINDOWED_COUNTS ]; ///< Max. counts for time windowed counts -static U32 timeWindowedCountsWindowMs[ NUM_OF_TIME_WINDOWED_COUNTS ]; ///< Time windows (in ms) for time windowed counts -static U32 timeWindowedCounts[ NUM_OF_TIME_WINDOWED_COUNTS ][ MAX_TIME_WINDOWED_COUNT ]; ///< Time stamps for instances for time windowed counts -static U32 timeWindowedCountIndexes[ NUM_OF_TIME_WINDOWED_COUNTS ]; ///< List indexes for time windowed counts + +/// CRC-16 look-up table. +const U16 CRC16_TABLE[] = +{ + 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, + 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef, + 0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6, + 0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de, + 0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485, + 0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d, + 0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4, + 0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc, + 0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823, + 0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b, + 0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12, + 0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a, + 0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41, + 0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49, + 0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70, + 0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78, + 0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f, + 0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067, + 0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e, + 0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256, + 0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d, + 0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405, + 0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c, + 0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634, + 0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab, + 0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3, + 0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a, + 0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92, + 0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9, + 0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1, + 0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8, + 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0 +}; + +/// CRC-8 look-up table. +const U08 CRC8_TABLE[] = { + 0, 49, 98, 83, 196, 245, 166, 151, 185, 136, 219, 234, 125, 76, 31, 46, + 67, 114, 33, 16, 135, 182, 229, 212, 250, 203, 152, 169, 62, 15, 92, 109, + 134, 183, 228, 213, 66, 115, 32, 17, 63, 14, 93, 108, 251, 202, 153, 168, + 197, 244, 167, 150, 1, 48, 99, 82, 124, 77, 30, 47, 184, 137, 218, 235, + 61, 12, 95, 110, 249, 200, 155, 170, 132, 181, 230, 215, 64, 113, 34, 19, + 126, 79, 28, 45, 186, 139, 216, 233, 199, 246, 165, 148, 3, 50, 97, 80, + 187, 138, 217, 232, 127, 78, 29, 44, 2, 51, 96, 81, 198, 247, 164, 149, + 248, 201, 154, 171, 60, 13, 94, 111, 65, 112, 35, 18, 133, 180, 231, 214, + 122, 75, 24, 41, 190, 143, 220, 237, 195, 242, 161, 144, 7, 54, 101, 84, + 57, 8, 91, 106, 253, 204, 159, 174, 128, 177, 226, 211, 68, 117, 38, 23, + 252, 205, 158, 175, 56, 9, 90, 107, 69, 116, 39, 22, 129, 176, 227, 210, + 191, 142, 221, 236, 123, 74, 25, 40, 6, 55, 100, 85, 194, 243, 160, 145, + 71, 118, 37, 20, 131, 178, 225, 208, 254, 207, 156, 173, 58, 11, 88, 105, + 4, 53, 102, 87, 192, 241, 162, 147, 189, 140, 223, 238, 121, 72, 27, 42, + 193, 240, 163, 146, 5, 52, 103, 86, 120, 73, 26, 43, 188, 141, 222, 239, + 130, 179, 224, 209, 70, 119, 36, 21, 59, 10, 89, 104, 255, 206, 157, 172 +}; + +// variables for time windowed counts (counts # of instances in a specific window of time) +static BOOL timeWindowedCountsInitialized[ NUM_OF_TIME_WINDOWED_COUNTS ]; ///< Initialized flags for time windowed counts +static U32 timeWindowedCountsMaxCount[ NUM_OF_TIME_WINDOWED_COUNTS ]; ///< Max. counts for time windowed counts +static U32 timeWindowedCountsWindowMs[ NUM_OF_TIME_WINDOWED_COUNTS ]; ///< Time windows (in ms) for time windowed counts +static U32 timeWindowedCounts[ NUM_OF_TIME_WINDOWED_COUNTS ][ MAX_TIME_WINDOWED_COUNT ]; ///< Time stamps for instances for time windowed counts +static U32 timeWindowedCountIndexes[ NUM_OF_TIME_WINDOWED_COUNTS ]; ///< List indexes for time windowed counts static U32 timeWindowedCountCounts[ NUM_OF_TIME_WINDOWED_COUNTS ]; ///< Current counts for time windowed counts static SEMAPHORE_STATUS_T sempahoreStatus[ NUM_OF_SEMAPHORES ]; @@ -170,54 +170,54 @@ return crc; } -/*********************************************************************//** - * @brief - * The crc16 function calculates a 16-bit CRC for a given range of bytes - * in memory. Poly = 0x1021. Not reflected. Initial value = 0xFFFF. - * @details Inputs: CRC16_TABLE[] - * @details Outputs: none - * @param address pointer to start address of memory range to calculate CRC for - * @param len number of bytes in the memory range to calculate CRC for - * @return CRC as a U16 - *************************************************************************/ -U16 crc16( const U08 *address, U32 len ) -{ - U16 crc = INITIAL_CRC16_VAL; - - while ( len-- > 0 ) - { - crc = ( crc << SHIFT_8_BITS_FOR_BYTE_SHIFT ) ^ CRC16_TABLE[ *address ^ ( ( crc >> SHIFT_8_BITS_FOR_BYTE_SHIFT ) & MASK_OFF_MSB ) ]; - address++; - } - - return crc; -} - -/*********************************************************************//** - * @brief - * The crc8 function calculates a 8-bit CRC for a given range of bytes - * in memory. - * @details Inputs: CRC8_TABLE[] - * @details Outputs: none - * @param address pointer to start address of memory range to calculate CRC for - * @param len number of bytes in the memory range to calculate CRC for - * @return CRC as a U08 - *************************************************************************/ -U08 crc8( const U08 *address, U32 len ) -{ - U08 crc = INITIAL_CRC08_VAL; - - while ( len-- > 0 ) - { - crc = CRC8_TABLE[ (*address) ^ crc ]; - address++; - } - - return crc; +/*********************************************************************//** + * @brief + * The crc16 function calculates a 16-bit CRC for a given range of bytes + * in memory. Poly = 0x1021. Not reflected. Initial value = 0xFFFF. + * @details Inputs: CRC16_TABLE[] + * @details Outputs: none + * @param address pointer to start address of memory range to calculate CRC for + * @param len number of bytes in the memory range to calculate CRC for + * @return CRC as a U16 + *************************************************************************/ +U16 crc16( const U08 *address, U32 len ) +{ + U16 crc = INITIAL_CRC16_VAL; + + while ( len-- > 0 ) + { + crc = ( crc << SHIFT_8_BITS_FOR_BYTE_SHIFT ) ^ CRC16_TABLE[ *address ^ ( ( crc >> SHIFT_8_BITS_FOR_BYTE_SHIFT ) & MASK_OFF_MSB ) ]; + address++; + } + + return crc; } /*********************************************************************//** * @brief + * The crc8 function calculates a 8-bit CRC for a given range of bytes + * in memory. + * @details Inputs: CRC8_TABLE[] + * @details Outputs: none + * @param address pointer to start address of memory range to calculate CRC for + * @param len number of bytes in the memory range to calculate CRC for + * @return CRC as a U08 + *************************************************************************/ +U08 crc8( const U08 *address, U32 len ) +{ + U08 crc = INITIAL_CRC08_VAL; + + while ( len-- > 0 ) + { + crc = CRC8_TABLE[ (*address) ^ crc ]; + address++; + } + + return crc; +} + +/*********************************************************************//** + * @brief * The crc4 function calculates a 4-bit CRC for a given range of bytes * in memory. * @details Inputs: none @@ -278,8 +278,8 @@ U32 result = ( end >= start ? end - start : ( HEX_32_BIT_FULL_SCALE - start ) + end + 1 ); return result; -} - +} + /*********************************************************************//** * @brief * The u16BiDiffWithWrap function calculates the difference between two given @@ -359,36 +359,36 @@ return result; } -/*********************************************************************//** - * @brief - * The initTimeWindowedCount function initializes a given time windowed count. - * @details Inputs: timeWindowedCountsMaxCount, timeWindowedCountsInitialized +/*********************************************************************//** + * @brief + * The initTimeWindowedCount function initializes a given time windowed count. + * @details Inputs: timeWindowedCountsMaxCount, timeWindowedCountsInitialized * @details Outputs: timeWindowedCountsMaxCount, timeWindowedCountsInitialized, alarm if - * software fault occurred - * @param cnt ID of the time windowed count to initialize - * @param maxCnt maximum number of instances in the time window for this count - * @param winMs number of ms in the time window for this count - * @return none - *************************************************************************/ -void initTimeWindowedCount( TIME_WINDOWED_COUNT_T cnt, U32 maxCnt, U32 winMs ) -{ - if ( ( cnt < NUM_OF_TIME_WINDOWED_COUNTS ) && ( maxCnt <= MAX_TIME_WINDOWED_COUNT ) ) - { - U32 i; - - // initialize a time windowed count - timeWindowedCountsMaxCount[ cnt ] = maxCnt; - timeWindowedCountsWindowMs[ cnt ] = winMs; - timeWindowedCountIndexes[ cnt ] = 0; - timeWindowedCountCounts[ cnt ] = 0; - for ( i = 0; i < MAX_TIME_WINDOWED_COUNT; i++ ) - { - timeWindowedCounts[ cnt ][ i ] = 0; - } - timeWindowedCountsInitialized[ cnt ] = TRUE; - } - else - { + * software fault occurred + * @param cnt ID of the time windowed count to initialize + * @param maxCnt maximum number of instances in the time window for this count + * @param winMs number of ms in the time window for this count + * @return none + *************************************************************************/ +void initTimeWindowedCount( TIME_WINDOWED_COUNT_T cnt, U32 maxCnt, U32 winMs ) +{ + if ( ( cnt < NUM_OF_TIME_WINDOWED_COUNTS ) && ( maxCnt <= MAX_TIME_WINDOWED_COUNT ) ) + { + U32 i; + + // initialize a time windowed count + timeWindowedCountsMaxCount[ cnt ] = maxCnt; + timeWindowedCountsWindowMs[ cnt ] = winMs; + timeWindowedCountIndexes[ cnt ] = 0; + timeWindowedCountCounts[ cnt ] = 0; + for ( i = 0; i < MAX_TIME_WINDOWED_COUNT; i++ ) + { + timeWindowedCounts[ cnt ][ i ] = 0; + } + timeWindowedCountsInitialized[ cnt ] = TRUE; + } + else + { if ( cnt < NUM_OF_TIME_WINDOWED_COUNTS ) { timeWindowedCountsInitialized[ cnt ] = FALSE; @@ -406,53 +406,53 @@ SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_UTIL_INVALID_WIN_COUNT, cnt ) #endif } - } -} - -/*********************************************************************//** - * @brief - * The incTimeWindowedCount function adds a new instance to a given time - * windowed count. Must call initTimeWindowedCount() prior to calling this - * function for a given time windowed count. + } +} + +/*********************************************************************//** + * @brief + * The incTimeWindowedCount function adds a new instance to a given time + * windowed count. Must call initTimeWindowedCount() prior to calling this + * function for a given time windowed count. * *Note - thread protection not provided - assumed function will be called - * by one task for a given time windowed count. - * @details Inputs: timeWindowedCounts, timeWindowedCountIndexes, timeWindowedCountCounts + * by one task for a given time windowed count. + * @details Inputs: timeWindowedCounts, timeWindowedCountIndexes, timeWindowedCountCounts * @details Outputs: timeWindowedCounts, timeWindowedCountIndexes, timeWindowedCountCounts, - * alarm if a software fault occurred - * @param cnt ID of the time windowed count to add an instance to - * @return TRUE if this instances brings the count to the maximum within - * this counts time window, otherwise FALSE - *************************************************************************/ -BOOL incTimeWindowedCount( TIME_WINDOWED_COUNT_T cnt ) -{ - BOOL result = FALSE; - U32 timeInMS; - - if ( ( cnt < NUM_OF_TIME_WINDOWED_COUNTS ) && ( TRUE == timeWindowedCountsInitialized[ cnt ] ) ) - { - // Replace timestamp of oldest instance in list with this new one - timeWindowedCounts[ cnt ][ timeWindowedCountIndexes[ cnt ] ] = getMSTimerCount(); - // 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 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_2_U32_DATA ( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_UTIL_TIME_WINDOWED_COUNT_ERROR, cnt ); -#else - SET_ALARM_WITH_2_U32_DATA ( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_UTIL_TIME_WINDOWED_COUNT_ERROR, cnt ); -#endif - } - - return result; + * alarm if a software fault occurred + * @param cnt ID of the time windowed count to add an instance to + * @return TRUE if this instances brings the count to the maximum within + * this counts time window, otherwise FALSE + *************************************************************************/ +BOOL incTimeWindowedCount( TIME_WINDOWED_COUNT_T cnt ) +{ + BOOL result = FALSE; + U32 timeInMS; + + if ( ( cnt < NUM_OF_TIME_WINDOWED_COUNTS ) && ( TRUE == timeWindowedCountsInitialized[ cnt ] ) ) + { + // Replace timestamp of oldest instance in list with this new one + timeWindowedCounts[ cnt ][ timeWindowedCountIndexes[ cnt ] ] = getMSTimerCount(); + // 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 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_2_U32_DATA ( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_UTIL_TIME_WINDOWED_COUNT_ERROR, cnt ); +#else + SET_ALARM_WITH_2_U32_DATA ( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_UTIL_TIME_WINDOWED_COUNT_ERROR, cnt ); +#endif + } + + return result; } /*********************************************************************//** @@ -659,7 +659,7 @@ } return status; -} +} /*********************************************************************//** * @brief @@ -765,5 +765,5 @@ { return ( TRUE == sempahoreStatus[ s ].isSemaphoreTaken ? FALSE : TRUE ); } - -/**@}*/ + +/**@}*/