le_crc.h

Go to the documentation of this file.
1 /**
2  * @page c_crc CRC32 API
3  *
4  * @subpage le_crc.h "API Reference"
5  *
6  * <HR>
7  *
8  * This module provides APIs for computing CRC of a binary buffer.
9  *
10  * CRC (Cyclic Redundancy Check) are used to verify the integrity of data, like file, messages, etc...
11  *
12  * @section Crc32 Computing a CRC32
13  *
14  * - @c le_crc_Crc32() - Compute the CRC32 of a memory buffer
15  *
16  * The CRC32 is computed by the function @ref le_crc_Crc32. It takes a base buffer address, a length
17  * and a CRC32. When the CRC32 is expected to be first computed, the value @ref LE_CRC_START_CRC32
18  * needs to be set as crc32 value.
19  *
20  * @note It is possible to compute a "global" CRC32 of a huge amount of data by splitting into small
21  * blocks and continue computing the CRC32 on each one.
22  *
23  * This code compute the whole CRC32 of amount of data splitted into an array of small blocks:
24  * @code
25  * #define MAX_BLOCKS 4 // Maximum number of blocks
26  *
27  * typedef struct
28  * {
29  * size_t blockSize; // size of the block
30  * uint8_t *blockPtr; // pointer of the data
31  * }
32  * block_t;
33  *
34  * uint32_t ComputeArrayCRC32
35  * (
36  * block_t blockArray[]
37  * )
38  * {
39  * uint32_t crc = LE_CRC_START_CRC32; // New CRC initialized
40  * int iBlock;
41  *
42  * for (iBlock = 0; iBlock < MAX_BLOCKS; iBlock++)
43  * {
44  * if (blockArray[iBlock].blockPtr)
45  * {
46  * crc = le_crc_Crc32(blockArray[iBlock].blockPtr,
47  * blockArray[iBlock].blockSize,
48  * crc);
49  * }
50  * }
51  * return crc;
52  * }
53  * @endcode
54  *
55  * <HR>
56  *
57  * Copyright (C) Sierra Wireless Inc.
58  *
59  */
60 
61 //--------------------------------------------------------------------------------------------------
62 /** @file le_crc.h
63  *
64  * Legato @ref c_crc include file.
65  *
66  * Copyright (C) Sierra Wireless Inc.
67  */
68 //--------------------------------------------------------------------------------------------------
69 
70 #ifndef LEGATO_CRC_INCLUDE_GUARD
71 #define LEGATO_CRC_INCLUDE_GUARD
72 
73 #ifndef LE_COMPONENT_NAME
74 #define LE_COMPONENT_NAME
75 #endif
76 
77 //--------------------------------------------------------------------------------------------------
78 /**
79  * Initial value for CRC32 calculation
80  */
81 //--------------------------------------------------------------------------------------------------
82 #define LE_CRC_START_CRC32 0xFFFFFFFFU
83 
84 //--------------------------------------------------------------------------------------------------
85 /**
86  * This function is used to calculate a CRC-32
87  *
88  * @return
89  * - 32-bit CRC
90  */
91 //--------------------------------------------------------------------------------------------------
92 uint32_t le_crc_Crc32
93 (
94  const uint8_t *addressPtr, ///< [IN] Input buffer
95  size_t size, ///< [IN] Number of bytes to read
96  uint32_t crc ///< [IN] Starting CRC seed
97 );
98 
99 #endif // LEGATO_CRC_INCLUDE_GUARD
uint32_t le_crc_Crc32(const uint8_t *addressPtr, size_t size, uint32_t crc)