Index: Utilities.c =================================================================== diff -u -rb28e0e05a9632cc46fc12378f2993a69d861a4cb -r778fe11eff6e7b8307ab4b22257e7ffc52f322f8 --- Utilities.c (.../Utilities.c) (revision b28e0e05a9632cc46fc12378f2993a69d861a4cb) +++ Utilities.c (.../Utilities.c) (revision 778fe11eff6e7b8307ab4b22257e7ffc52f322f8) @@ -100,7 +100,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 @@ -123,7 +123,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 @@ -140,6 +140,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; } /*********************************************************************//**