Index: Utilities.c =================================================================== diff -u -r9b5930a3558135173b2c4068fdb7d3c63502ef9c -r37ac678630a7bf229d56a3702c5a7389f4b37ce2 --- Utilities.c (.../Utilities.c) (revision 9b5930a3558135173b2c4068fdb7d3c63502ef9c) +++ Utilities.c (.../Utilities.c) (revision 37ac678630a7bf229d56a3702c5a7389f4b37ce2) @@ -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 @@ -26,13 +26,17 @@ // ********** 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 INITIAL_CRC16_VAL 0xFFFF ///< Seed for 16-bit CRC function +#define INITIAL_CRC08_VAL 0x00 ///< Seed for 8-bit CRC function + +#define ASCII_CODE_LETTER_A 0x41 ///< ASCII code in hex for letter A. +#define ASCII_CODE_NUMBER_ZERO 0x30 ///< ASCII code in hex for number zero. +#define ASCII_CODE_NUMBER_SEVEN 0x37 ///< ASCII code in hex for number seven. // ********** private data ********** /// CRC-16 look-up table. -const U16 crc16_table[] = +const U16 CRC16_TABLE[] = { 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef, @@ -69,7 +73,7 @@ }; /// CRC-8 look-up table. -const U08 crc8_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, @@ -112,7 +116,7 @@ while ( len-- > 0 ) { - crc = ( crc << SHIFT_8_BITS_FOR_BYTE_SHIFT ) ^ crc16_table[ *address ^ ( ( crc >> SHIFT_8_BITS_FOR_BYTE_SHIFT ) & MASK_OFF_MSB ) ]; + crc = ( crc << SHIFT_8_BITS_FOR_BYTE_SHIFT ) ^ CRC16_TABLE[ *address ^ ( ( crc >> SHIFT_8_BITS_FOR_BYTE_SHIFT ) & MASK_OFF_MSB ) ]; address++; } @@ -135,7 +139,7 @@ while ( len-- > 0 ) { - crc = crc8_table[ (*address) ^ crc ]; + crc = CRC8_TABLE[ (*address) ^ crc ]; address++; } @@ -243,7 +247,7 @@ if ( ( cnt < NUM_OF_TIME_WINDOWED_COUNTS ) && ( TRUE == timeWindowedCountsInitialized[ cnt ] ) ) { - // replace timestamp of oldest instance in list with this new one + // 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 ); @@ -401,5 +405,37 @@ data->comp = ~data->data.uInt; _enable_IRQ(); } + +/*********************************************************************//** + * @brief + * The hexStrToDec function convert hex string to decimal value. + * @details Inputs: none + * @details Outputs: none + * @param valuePtr pointer to hex string to convert + * @param size size of the hex string to convert + * @return converted value of hex string + *************************************************************************/ +U32 hexStrToDec( U08 const * const valuePtr, U08 size ) +{ + U08 ii; + U08 value; + U32 result = 0; + + for ( ii = 0; ii < size; ++ii ) + { + if ( valuePtr[ii] < ASCII_CODE_LETTER_A ) + { + value = ( valuePtr[ii] - ASCII_CODE_NUMBER_ZERO ); + result = ( result << 4 ) | value; + } + else + { + value = ( valuePtr[ii] - ASCII_CODE_NUMBER_SEVEN ); + result = ( result << 4 ) | value; + } + } + + return result; +} /**@}*/