Index: Utilities.c =================================================================== diff -u -r7ff7e715f7a15da5f4055b33e186d58cf96fe909 -r85db35aef9a57d1efc02bb3b42fc802b65aa3646 --- Utilities.c (.../Utilities.c) (revision 7ff7e715f7a15da5f4055b33e186d58cf96fe909) +++ Utilities.c (.../Utilities.c) (revision 85db35aef9a57d1efc02bb3b42fc802b65aa3646) @@ -8,7 +8,7 @@ * @file Utilities.c * * @author (last) Sean Nash -* @date (last) 04-Sep-2020 +* @date (last) 24-Sep-2020 * * @author (original) Sean * @date (original) 17-Feb-2020 @@ -100,9 +100,8 @@ * @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: none - * Outputs: none + * @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 @@ -124,9 +123,8 @@ * @brief * The crc8 function calculates a 8-bit CRC for a given range of bytes * in memory. - * @details - * Inputs: none - * Outputs: none + * @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 @@ -142,14 +140,43 @@ } return crc; +} + +/*********************************************************************//** + * @brief + * The u32DiffWithWrap function calculates the difference between two given + * unsigned 32-bit numbers. If the second (ending) number is less than the + * first (starting) number, then the difference is calculated with a wrap past + * 32-bit full scale to zero. + * @details Inputs: none + * @details Outputs: none + * @param start first number to compute difference for + * @param end second number to compute difference for + * @return the difference between the two given numbers + *************************************************************************/ +U32 u32DiffWithWrap( U32 start, U32 end ) +{ + U32 result; + + // no wrap + if ( end >= start ) + { + result = end - start; + } + // wrapped + else + { + result = ( 0xFFFFFFFF - start ) + end + 1; + } + + return result; } /*********************************************************************//** * @brief * The initTimeWindowedCount function initializes a given time windowed count. - * @details - * Inputs: timeWindowedCountsMaxCount, timeWindowedCountsInitialized - * Outputs: timeWindowedCountsMaxCount, timeWindowedCountsInitialized, alarm if + * @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 @@ -202,9 +229,8 @@ * 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 - * Outputs: timeWindowedCounts, timeWindowedCountIndexes, timeWindowedCountCounts, + * @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 @@ -247,9 +273,8 @@ * The getCriticalData function gets the value for a given critical data * record. The integrity of the critical data is checked first. If the * critical data record fails the integrity check, a fault is triggered. - * @details - * Inputs: none - * Outputs: alarm if HD critical error occurred + * @details Inputs: none + * @details Outputs: alarm if HD critical error occurred * @param data Ptr to a critical data record * @return The data from a critical data record *************************************************************************/ @@ -284,9 +309,8 @@ * @brief * The isCriticalDataInRange function determines whether a critical data * value is within the range set for that critical data. - * @details - * Inputs: none - * Outputs: none + * @details Inputs: none + * @details Outputs: none * @param data Ptr to a critical data record * @return TRUE if given data is in range, FALSE if not *************************************************************************/ @@ -323,9 +347,8 @@ * @brief * The setCriticalData function sets the value for a given critical data * record. - * @details - * Inputs: none - * Outputs: alarm if HD critical error occurred + * @details Inputs: none + * @details Outputs: alarm if HD critical error occurred * @param data Ptr to a critical data record * @param value a value to set * @return TRUE if set was successful, FALSE if not (out of range) @@ -365,9 +388,8 @@ /*********************************************************************//** * @brief * The resetCriticalData function resets a critical data record. - * @details - * Inputs: none - * Outputs: Given critical data record is reset to unset w/ default value. + * @details Inputs: none + * @details Outputs: Given critical data record is reset to unset w/ default value. * @param data Ptr to a critical data record * @return none *************************************************************************/