Index: Utilities.c =================================================================== diff -u -r7ff7e715f7a15da5f4055b33e186d58cf96fe909 -r7971a36491e30a84139068d7e00b416cf1ea3ee1 --- Utilities.c (.../Utilities.c) (revision 7ff7e715f7a15da5f4055b33e186d58cf96fe909) +++ Utilities.c (.../Utilities.c) (revision 7971a36491e30a84139068d7e00b416cf1ea3ee1) @@ -101,7 +101,7 @@ * 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 + * Inputs: crc16_table[] * 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 @@ -125,7 +125,7 @@ * The crc8 function calculates a 8-bit CRC for a given range of bytes * in memory. * @details - * Inputs: none + * Inputs: crc8_table[] * 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 @@ -142,6 +142,36 @@ } return crc; +} + +/*********************************************************************//** + * @brief + * The crc8 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; } /*********************************************************************//**