Index: firmware/App/Services/Utilities.c =================================================================== diff -u -rb8160225a28a2ba4d6dff4d0433e55465c737a14 -rc74c1d99a011dd0fb7f98f183faecda675221fce --- firmware/App/Services/Utilities.c (.../Utilities.c) (revision b8160225a28a2ba4d6dff4d0433e55465c737a14) +++ firmware/App/Services/Utilities.c (.../Utilities.c) (revision c74c1d99a011dd0fb7f98f183faecda675221fce) @@ -1,9 +1,3 @@ -/* - * Utilities.c - * - * Created on: Aug 4, 2024 - * Author: fw - */ #ifndef _VECTORCAST_ // This header file is disabled in VectorCAST because this is a TI library and VectorCAST uses GNU 7.4 compiler for testing @@ -12,10 +6,18 @@ #include "Utilities.h" -#define INITIAL_CRC16_VAL 0xFFFF ///< Seed for 16-bit CRC function. -#define SHIFT_24_BITS 24 ///< Number of bits to shift in order to shift 3 bytes +/** + * @addtogroup Utilities + * @{ + */ +// ********** private definitions ********** +#define INITIAL_CRC16_VAL 0xFFFF ///< Seed for 16-bit CRC function. +#define SHIFT_24_BITS 24 ///< Number of bits to shift in order to shift 3 bytes. + +// ********** private data ********** + /// CRC-32 look-up table. const U32 CRC32_TABLE[] = { @@ -90,7 +92,15 @@ 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0 }; - +/*********************************************************************//** + * @brief + * The runFWIntegrityTest function runs the firmware integrity test on the + * firmware that is in the flash. It returns whether the integrity passed or + * failed. + * @details \b Inputs: none + * @details \b Outputs: none + * @return TRUE if integrity test passed otherwise, FALSE + *************************************************************************/ BOOL runFWIntegrityTest( void ) { U32 remainingSize = 0; @@ -100,7 +110,7 @@ CRC_TABLE const * const crcTablePtr = (CRC_TABLE *)FIRMWARE_CRC_TABLE_ADDRESS; CRC_RECORD const * currentRecordPtr = &crcTablePtr->recs[ currentRecord ]; - BOOL integrityStatus = TRUE; + BOOL integrityStatus = TRUE; do { @@ -131,31 +141,52 @@ return integrityStatus; } -U16 crc16( U08 *address, U32 len ) +/*********************************************************************//** + * @brief + * The crc32 function calculates a 32-bit CRC for a given range of bytes + * in memory. Poly = 0x1EDC6F41. Not reflected. Initial value = 0x00000000. + * @details \b Inputs: CRC32_TABLE[] + * @details \b Outputs: none + * @param initialValue initial CRC seed value + * @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 32-bit CRC + *************************************************************************/ +U32 crc32( U32 initialValue, U08 *address, U32 len ) { - U16 crc = INITIAL_CRC16_VAL; + U32 crc = initialValue; 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 ) ^ CRC32_TABLE[ *address ^ ( crc >> SHIFT_24_BITS ) ]; address++; } return crc; } -U32 crc32( U32 initialValue, U08 *address, U32 len ) +/*********************************************************************//** + * @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 \b Inputs: CRC16_TABLE[] + * @details \b 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 16-bit CRC + *************************************************************************/ +U16 crc16( U08 *address, U32 len ) { - U32 crc = initialValue; + U16 crc = INITIAL_CRC16_VAL; while ( len-- > 0 ) { - crc = ( crc << SHIFT_8_BITS_FOR_BYTE_SHIFT ) ^ CRC32_TABLE[ *address ^ ( crc >> SHIFT_24_BITS ) ]; + crc = ( crc << SHIFT_8_BITS_FOR_BYTE_SHIFT ) ^ CRC16_TABLE[ *address ^ ( ( crc >> SHIFT_8_BITS_FOR_BYTE_SHIFT ) & MASK_OFF_MSB ) ]; address++; } return crc; } +/**@}*/ -