Index: Utilities.c =================================================================== diff -u -r4b3e011f99900660c9c9f23d3ea50a07cb61e64b -r7c49409b1bfeee8fd788fe1cd2a6dbf2abda7fea --- Utilities.c (.../Utilities.c) (revision 4b3e011f99900660c9c9f23d3ea50a07cb61e64b) +++ Utilities.c (.../Utilities.c) (revision 7c49409b1bfeee8fd788fe1cd2a6dbf2abda7fea) @@ -104,7 +104,7 @@ * @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 + * @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 @@ -127,7 +127,7 @@ * @brief * The crc8 function calculates a 8-bit CRC for a given range of bytes * in memory. - * @details Inputs: 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 @@ -144,6 +144,36 @@ } 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; } /*********************************************************************//**