Arduino Core for STM32  1.0
HardwareCRC Class Reference

Calculate CRC simply and fast using this class. Calculation is done using hardware CRC calculation unit. More...

#include <HardwareCRC.h>

Public Member Functions

bool begin ()
 Enables CRC hardware calculation unit. More...
 
bool setPolynomial7 (uint32_t polynomial=CRC7_POLY)
 Sets CRC-7 polynomial. More...
 
bool setPolynomial8 (uint32_t polynomial=CRC8_POLY)
 Sets CRC-8 polynomial. More...
 
bool setPolynomial16 (uint32_t polynomial=CRC16_POLY)
 Sets CRC-16 polynomial. More...
 
bool setPolynomial32 (uint32_t polynomial=CRC32_POLY)
 Sets CRC-32 polynomial. More...
 
uint32_t getPolynomial ()
 Gets polynomial, that was set. More...
 
uint8_t getPolynomialLength ()
 Gets polynomial length in bits. More...
 
uint32_t getInitValue ()
 Gets initial value, that was set using reset(), compute() or computeAndWriteToEnd() method. More...
 
uint32_t getLastCRC (uint32_t finalXOR=0x00)
 Gets last calculated CRC result. More...
 
void reset (uint32_t initValue=DEFAULT_HCRC_INITVAL)
 Resets calculation and sets initial value. More...
 
uint32_t append (const uint8_t data, uint32_t finalXOR=0x00)
 Appends another data to previous CRC calculation and calculates new CRC value. More...
 
uint32_t append (const uint8_t *data, uint32_t dataLength, uint32_t finalXOR=0x00)
 Appends another data to previous CRC calculation and calculates new CRC value. More...
 
uint32_t append (const int8_t *data, uint32_t dataLength, uint32_t finalXOR=0x00)
 Appends another data to previous CRC calculation and calculates new CRC value. More...
 
uint32_t append (const uint16_t data, uint32_t finalXOR=0x00)
 Appends another data to previous CRC calculation and calculates new CRC value. More...
 
uint32_t append (const uint16_t *data, uint32_t dataLength, uint32_t finalXOR=0x00)
 Appends another data to previous CRC calculation and calculates new CRC value. More...
 
uint32_t append (const int16_t *data, uint32_t dataLength, uint32_t finalXOR=0x00)
 Appends another data to previous CRC calculation and calculates new CRC value. More...
 
uint32_t append (const uint32_t data, uint32_t finalXOR=0x00)
 Appends another data to previous CRC calculation and calculates new CRC value. More...
 
uint32_t append (const uint32_t *data, uint32_t dataLength, uint32_t finalXOR=0x00)
 Appends another data to previous CRC calculation and calculates new CRC value. More...
 
uint32_t append (const int32_t *data, uint32_t dataLength, uint32_t finalXOR=0x00)
 Appends another data to previous CRC calculation and calculates new CRC value. More...
 
uint32_t compute (const uint8_t *data, uint32_t dataLength, uint32_t initValue=DEFAULT_HCRC_INITVAL, uint32_t finalXOR=0x00)
 Resets and computes CRC value of the whole array. More...
 
uint32_t compute (const int8_t *data, uint32_t dataLength, uint32_t initValue=DEFAULT_HCRC_INITVAL, uint32_t finalXOR=0x00)
 Resets and computes CRC value of the whole array. More...
 
uint32_t compute (const uint16_t *data, uint32_t dataLength, uint32_t initValue=DEFAULT_HCRC_INITVAL, uint32_t finalXOR=0x00)
 Resets and computes CRC value of the whole array. More...
 
uint32_t compute (const int16_t *data, uint32_t dataLength, uint32_t initValue=DEFAULT_HCRC_INITVAL, uint32_t finalXOR=0x00)
 Resets and computes CRC value of the whole array. More...
 
uint32_t compute (const uint32_t *data, uint32_t dataLength, uint32_t initValue=DEFAULT_HCRC_INITVAL, uint32_t finalXOR=0x00)
 Resets and computes CRC value of the whole array. More...
 
uint32_t compute (const int32_t *data, uint32_t dataLength, uint32_t initValue=DEFAULT_HCRC_INITVAL, uint32_t finalXOR=0x00)
 Resets and computes CRC value of the whole array. More...
 
uint32_t computeAndWriteToEnd (uint8_t *data, uint32_t dataLength, uint32_t initValue=DEFAULT_HCRC_INITVAL, uint32_t finalXOR=0x00)
 Resets, computes CRC value of the whole array and attaches calculated CRC value at the end of the array. More...
 
uint32_t computeAndWriteToEnd (int8_t *data, uint32_t dataLength, uint32_t initValue=DEFAULT_HCRC_INITVAL, uint32_t finalXOR=0x00)
 Resets, computes CRC value of the whole array and attaches calculated CRC value at the end of the array. More...
 
uint32_t computeAndWriteToEnd (uint16_t *data, uint32_t dataLength, uint32_t initValue=DEFAULT_HCRC_INITVAL, uint32_t finalXOR=0x00)
 Resets, computes CRC value of the whole array and attaches calculated CRC value at the end of the array. More...
 
uint32_t computeAndWriteToEnd (int16_t *data, uint32_t dataLength, uint32_t initValue=DEFAULT_HCRC_INITVAL, uint32_t finalXOR=0x00)
 Resets, computes CRC value of the whole array and attaches calculated CRC value at the end of the array. More...
 
uint32_t computeAndWriteToEnd (uint32_t *data, uint32_t dataLength, uint32_t initValue=DEFAULT_HCRC_INITVAL, uint32_t finalXOR=0x00)
 Resets, computes CRC value of the whole array and attaches calculated CRC value at the end of the array. More...
 
uint32_t computeAndWriteToEnd (int32_t *data, uint32_t dataLength, uint32_t initValue=DEFAULT_HCRC_INITVAL, uint32_t finalXOR=0x00)
 Resets, computes CRC value of the whole array and attaches calculated CRC value at the end of the array. More...
 
bool check (const uint8_t *data, uint32_t dataLength, uint32_t initValue=DEFAULT_HCRC_INITVAL, uint32_t finalXOR=0x00)
 Checks if the array (with CRC attached at the end) is valid. More...
 
bool check (const int8_t *data, uint32_t dataLength, uint32_t initValue=DEFAULT_HCRC_INITVAL, uint32_t finalXOR=0x00)
 Checks if the array (with CRC attached at the end) is valid. More...
 
bool check (const uint16_t *data, uint32_t dataLength, uint32_t initValue=DEFAULT_HCRC_INITVAL, uint32_t finalXOR=0x00)
 Checks if the array (with CRC attached at the end) is valid. More...
 
bool check (const int16_t *data, uint32_t dataLength, uint32_t initValue=DEFAULT_HCRC_INITVAL, uint32_t finalXOR=0x00)
 Checks if the array (with CRC attached at the end) is valid. More...
 
bool check (const uint32_t *data, uint32_t dataLength, uint32_t initValue=DEFAULT_HCRC_INITVAL, uint32_t finalXOR=0x00)
 Checks if the array (with CRC attached at the end) is valid. More...
 
bool check (const int32_t *data, uint32_t dataLength, uint32_t initValue=DEFAULT_HCRC_INITVAL, uint32_t finalXOR=0x00)
 Checks if the array (with CRC attached at the end) is valid. More...
 
uint32_t getCheckValue (uint32_t initValue=DEFAULT_HCRC_INITVAL, uint32_t finalXOR=0x00)
 Calculates CRC check value. More...
 
bool setInputReverse (bool reverse)
 Sets, if input data bits will be reversed(reflected) or not. More...
 
bool setOutputReverse (bool reverse)
 Sets, if output CRC data bits will be reversed(reflected) or not. More...
 
bool getInputReverse ()
 Gets, if input data bits will be reversed(reflected) or not. More...
 
bool getOutputReverse ()
 Gets, if output CRC data bits will be reversed(reflected) or not. More...
 
void end ()
 Disables hardware CRC calculation unit. More...
 

Static Public Attributes

static const bool isCustomPolynomialSupported = CRC_CUST_POLY
 True when custom polynomials are supported. More...
 
static const bool isIOReverseSupported = CRC_IO_REV_SUPP
 True when input / output reversion (reflection) is supported. More...
 
static const bool isCustomInitValueSupported = CRC_CUST_INIT_VAL
 True when custom initial value is supported, if not, 0xFFFFFFFFUL is set. More...
 

Protected Member Functions

void setInputReverseSize (uint32_t reverse)
 Sets input reverse size to CR register. More...
 

Protected Attributes

uint8_t lastCR = 0xFF
 
uint32_t lastFXOR = 0
 
uint32_t lastCRCCheckValue = 0
 
uint8_t inputReverse = HCRC_IN_REVERSE_DISABLED
 

Detailed Description

Calculate CRC simply and fast using this class. Calculation is done using hardware CRC calculation unit.

Pros and cons

Pros:

  • Fully programmable polynomial with programmable size (7, 8, 16, 32 bits).
  • Handles 8-,16-, 32-bit data size.
  • Programmable CRC initial value.
  • Programmable final XOR value.
  • Hardware CRC computation is done in 4 AHB clock cycles (HCLK) for the 32-bit data size. 2 AHB clock cycles (HCLK) for the 16-bit data size. 1 AHB clock cycle (HCLK) for the 8-bit data size.
  • Supports input/output reflection. Cons:
  • Not every method is supported on all MCUs.

TODO

Todo:
Add support for little and big endian.
See also
HardwareCRC.h
Default CRC polynomials
CRC polynomial terms
Hardware CRC documentation

Member Function Documentation

◆ begin()

bool HardwareCRC::begin ( )

Enables CRC hardware calculation unit.

Returns
Returns true when periphery was enabled.
Examples
HarwareCRCExample.
Here is the call graph for this function:

◆ setPolynomial7()

bool HardwareCRC::setPolynomial7 ( uint32_t  polynomial = CRC7_POLY)

Sets CRC-7 polynomial.

Parameters
polynomialCustom CRC-7 polynomial. See CRC_Poly_Terms to create custom polynomial, or see Def_CRC_Poly to use most used polynomials.
Note
CRC-7 polynomial has to be odd and lower or equal than 0x7F.
Returns
Returns true when polynomial is correct and was set.

◆ setPolynomial8()

bool HardwareCRC::setPolynomial8 ( uint32_t  polynomial = CRC8_POLY)

Sets CRC-8 polynomial.

Parameters
polynomialCustom CRC-8 polynomial. See CRC_Poly_Terms to create custom polynomial, or see Def_CRC_Poly to use most used polynomials.
Note
CRC-8 polynomial has to be odd and lower or equal than 0xFF.
Returns
Returns true when polynomial is correct and was set.
Examples
HarwareCRCExample.

◆ setPolynomial16()

bool HardwareCRC::setPolynomial16 ( uint32_t  polynomial = CRC16_POLY)

Sets CRC-16 polynomial.

Parameters
polynomialCustom CRC-16 polynomial. See CRC_Poly_Terms to create custom polynomial, or see Def_CRC_Poly to use most used polynomials.
Note
CRC-16 polynomial has to be odd and lower or equal than 0xFFFF.
Returns
Returns true when polynomial is correct and was set.

◆ setPolynomial32()

bool HardwareCRC::setPolynomial32 ( uint32_t  polynomial = CRC32_POLY)

Sets CRC-32 polynomial.

Parameters
polynomialCustom CRC-32 polynomial. See CRC_Poly_Terms to create custom polynomial, or see Def_CRC_Poly to use most used polynomials.
Note
CRC-32 polynomial has to be odd and lower or equal than 0xFFFFFFFF.
Returns
Returns true when polynomial is correct and was set.
Examples
HarwareCRCExample.

◆ getPolynomial()

uint32_t HardwareCRC::getPolynomial ( )
inline

Gets polynomial, that was set.

Returns
Returns polynomial.

◆ getPolynomialLength()

uint8_t HardwareCRC::getPolynomialLength ( )

Gets polynomial length in bits.

Returns
Returns polynomial length in bits. Possible values: 32, 16, 8, 7.

◆ getInitValue()

uint32_t HardwareCRC::getInitValue ( )
inline

Gets initial value, that was set using reset(), compute() or computeAndWriteToEnd() method.

Returns
Returns initial value.

◆ getLastCRC()

uint32_t HardwareCRC::getLastCRC ( uint32_t  finalXOR = 0x00)
inline

Gets last calculated CRC result.

Parameters
paramfinalXOR Value, that is used to XOR by bits the calculated result. Set to 0 if you want to disable final XORing.
Returns
Returns last calculated CRC result.

◆ reset()

void HardwareCRC::reset ( uint32_t  initValue = DEFAULT_HCRC_INITVAL)

Resets calculation and sets initial value.

Parameters
initValueInitial calculation value.
Examples
HarwareCRCExample.

◆ append() [1/9]

uint32_t HardwareCRC::append ( const uint8_t  data,
uint32_t  finalXOR = 0x00 
)

Appends another data to previous CRC calculation and calculates new CRC value.

Parameters
dataOne byte to add.
finalXORValue, that is used to XOR by bits the calculated result. Set to 0 if you want to disable final XORing.
Note
When input reverse is enabled, bits of whole word are reversed. For example: 0x0F => 0xF0
Returns
Returns calculated CRC value from the begin of the calculation. Calculation is restarted when reset(), begin(), compute(), computeAndWriteToEnd() or check() method were used.
Examples
HarwareCRCExample.
Here is the call graph for this function:

◆ append() [2/9]

uint32_t HardwareCRC::append ( const uint8_t *  data,
uint32_t  dataLength,
uint32_t  finalXOR = 0x00 
)

Appends another data to previous CRC calculation and calculates new CRC value.

Parameters
dataByte array to add.
Note
When input reverse is enabled, bits of whole word are reversed. For example: 0x0F => 0xF0
Parameters
dataLengthCount of bytes in data array.
finalXORValue, that is used to XOR by bits the calculated result. Set to 0 if you want to disable final XORing.
Returns
Returns calculated CRC value from the begin of the calculation. Calculation is restarted when reset(), begin(), compute(), computeAndWriteToEnd() or check() method were used.
Here is the call graph for this function:

◆ append() [3/9]

uint32_t HardwareCRC::append ( const int8_t *  data,
uint32_t  dataLength,
uint32_t  finalXOR = 0x00 
)
inline

Appends another data to previous CRC calculation and calculates new CRC value.

Parameters
dataByte array to add.
Note
When input reverse is enabled, bits of whole word are reversed. For example: 0x0F => 0xF0
Parameters
dataLengthCount of bytes in data array.
finalXORValue, that is used to XOR by bits the calculated result. Set to 0 if you want to disable final XORing.
Returns
Returns calculated CRC value from the begin of the calculation. Calculation is restarted when reset(), begin(), compute(), computeAndWriteToEnd() or check() method were used.
Here is the call graph for this function:

◆ append() [4/9]

uint32_t HardwareCRC::append ( const uint16_t  data,
uint32_t  finalXOR = 0x00 
)

Appends another data to previous CRC calculation and calculates new CRC value.

Parameters
dataOne half-word (2 bytes) to add.
Note
When input reverse is enabled, bits of whole word are reversed. For example: 0x0FFF => 0xFFF0
Parameters
finalXORValue, that is used to XOR by bits the calculated result. Set to 0 if you want to disable final XORing.
Returns
Returns calculated CRC value from the begin of the calculation. Calculation is restarted when reset(), begin(), compute(), computeAndWriteToEnd() or check() method were used.
Here is the call graph for this function:

◆ append() [5/9]

uint32_t HardwareCRC::append ( const uint16_t *  data,
uint32_t  dataLength,
uint32_t  finalXOR = 0x00 
)

Appends another data to previous CRC calculation and calculates new CRC value.

Parameters
dataArray of half-words (2 bytes) to add.
Note
When input reverse is enabled, bits of whole word are reversed. For example: 0x0FFF => 0xFFF0
Parameters
dataLengthCount of half-words in data array.
finalXORValue, that is used to XOR by bits the calculated result. Set to 0 if you want to disable final XORing.
Returns
Returns calculated CRC value from the begin of the calculation. Calculation is restarted when reset(), begin(), compute(), computeAndWriteToEnd() or check() method were used.
Here is the call graph for this function:

◆ append() [6/9]

uint32_t HardwareCRC::append ( const int16_t *  data,
uint32_t  dataLength,
uint32_t  finalXOR = 0x00 
)
inline

Appends another data to previous CRC calculation and calculates new CRC value.

Parameters
dataArray of half-words (2 bytes) to add.
Note
When input reverse is enabled, bits of whole word are reversed. For example: 0x0FFF => 0xFFF0
Parameters
dataLengthCount of half-words in data array.
finalXORValue, that is used to XOR by bits the calculated result. Set to 0 if you want to disable final XORing.
Returns
Returns calculated CRC value from the begin of the calculation. Calculation is restarted when reset(), begin(), compute(), computeAndWriteToEnd() or check() method were used.
Here is the call graph for this function:

◆ append() [7/9]

uint32_t HardwareCRC::append ( const uint32_t  data,
uint32_t  finalXOR = 0x00 
)

Appends another data to previous CRC calculation and calculates new CRC value.

Parameters
dataOne word (4 bytes) to add.
Note
When input reverse is enabled, bits of whole word are reversed. For example: 0x0F0FFFFF => 0xFFFFF0F0
Parameters
finalXORValue, that is used to XOR by bits the calculated result. Set to 0 if you want to disable final XORing.
Returns
Returns calculated CRC value from the begin of the calculation. Calculation is restarted when reset(), begin(), compute(), computeAndWriteToEnd() or check() method were used.
Here is the call graph for this function:

◆ append() [8/9]

uint32_t HardwareCRC::append ( const uint32_t *  data,
uint32_t  dataLength,
uint32_t  finalXOR = 0x00 
)

Appends another data to previous CRC calculation and calculates new CRC value.

Parameters
dataArray of words (4 bytes) to add.
Note
When input reverse is enabled, bits of whole word are reversed. For example: 0x0F0FFFFF => 0xFFFFF0F0
Parameters
dataLengthCount of words in data array.
finalXORValue, that is used to XOR by bits the calculated result. Set to 0 if you want to disable final XORing.
Returns
Returns calculated CRC value from the begin of the calculation. Calculation is restarted when reset(), begin(), compute(), computeAndWriteToEnd() or check() method were used.
Here is the call graph for this function:

◆ append() [9/9]

uint32_t HardwareCRC::append ( const int32_t *  data,
uint32_t  dataLength,
uint32_t  finalXOR = 0x00 
)
inline

Appends another data to previous CRC calculation and calculates new CRC value.

Parameters
dataArray of words (4 bytes) to add.
Note
When input reverse is enabled, bits of whole word are reversed. For example: 0x0F0FFFFF => 0xFFFFF0F0
Parameters
dataLengthCount of words in data array.
finalXORValue, that is used to XOR by bits the calculated result. Set to 0 if you want to disable final XORing.
Returns
Returns calculated CRC value from the begin of the calculation. Calculation is restarted when reset(), begin(), compute(), computeAndWriteToEnd() or check() method were used.
Here is the call graph for this function:

◆ compute() [1/6]

uint32_t HardwareCRC::compute ( const uint8_t *  data,
uint32_t  dataLength,
uint32_t  initValue = DEFAULT_HCRC_INITVAL,
uint32_t  finalXOR = 0x00 
)

Resets and computes CRC value of the whole array.

reset() method is called at the method begin.

Parameters
dataArray of bytes to compute.
Note
When input reverse is enabled, bits of whole word are reversed. For example: 0x0F => 0xF0
Parameters
dataLengthCount of bytes in data array.
initValueInitial calculation value.
finalXORValue, that is used to XOR by bits the calculated result. Set to 0 if you want to disable final XORing.
Returns
Returns calculated CRC value.
Examples
HarwareCRCExample.
Here is the call graph for this function:

◆ compute() [2/6]

uint32_t HardwareCRC::compute ( const int8_t *  data,
uint32_t  dataLength,
uint32_t  initValue = DEFAULT_HCRC_INITVAL,
uint32_t  finalXOR = 0x00 
)
inline

Resets and computes CRC value of the whole array.

reset() method is called at the method begin.

Parameters
dataArray of bytes to compute.
Note
When input reverse is enabled, bits of whole word are reversed. For example: 0x0F => 0xF0
Parameters
dataLengthCount of bytes in data array.
initValueInitial calculation value.
finalXORValue, that is used to XOR by bits the calculated result. Set to 0 if you want to disable final XORing.
Returns
Returns calculated CRC value.
Here is the call graph for this function:

◆ compute() [3/6]

uint32_t HardwareCRC::compute ( const uint16_t *  data,
uint32_t  dataLength,
uint32_t  initValue = DEFAULT_HCRC_INITVAL,
uint32_t  finalXOR = 0x00 
)

Resets and computes CRC value of the whole array.

reset() method is called at the method begin.

Parameters
dataArray of half-words (2 bytes) to add.
Note
When input reverse is enabled, bits of whole word are reversed. For example: 0x0FFF => 0xFFF0
Parameters
dataLengthCount of half-words (2 bytes) in data array.
initValueInitial calculation value.
finalXORValue, that is used to XOR by bits the calculated result. Set to 0 if you want to disable final XORing.
Returns
Returns calculated CRC value.
Here is the call graph for this function:

◆ compute() [4/6]

uint32_t HardwareCRC::compute ( const int16_t *  data,
uint32_t  dataLength,
uint32_t  initValue = DEFAULT_HCRC_INITVAL,
uint32_t  finalXOR = 0x00 
)
inline

Resets and computes CRC value of the whole array.

reset() method is called at the method begin.

Parameters
dataArray of half-words (2 bytes) to add.
Note
When input reverse is enabled, bits of whole word are reversed. For example: 0x0FFF => 0xFFF0
Parameters
dataLengthCount of half-words (2 bytes) in data array.
initValueInitial calculation value.
finalXORValue, that is used to XOR by bits the calculated result. Set to 0 if you want to disable final XORing.
Returns
Returns calculated CRC value.
Here is the call graph for this function:

◆ compute() [5/6]

uint32_t HardwareCRC::compute ( const uint32_t *  data,
uint32_t  dataLength,
uint32_t  initValue = DEFAULT_HCRC_INITVAL,
uint32_t  finalXOR = 0x00 
)

Resets and computes CRC value of the whole array.

reset() method is called at the method begin.

Parameters
dataArray of words (4 bytes) to add.
Note
When input reverse is enabled, bits of whole word are reversed. For example: 0x0F0FFFFF => 0xFFFFF0F0
Parameters
dataLengthCount of words (4 bytes) in data array.
initValueInitial calculation value.
finalXORValue, that is used to XOR by bits the calculated result. Set to 0 if you want to disable final XORing.
Returns
Returns calculated CRC value.
Here is the call graph for this function:

◆ compute() [6/6]

uint32_t HardwareCRC::compute ( const int32_t *  data,
uint32_t  dataLength,
uint32_t  initValue = DEFAULT_HCRC_INITVAL,
uint32_t  finalXOR = 0x00 
)
inline

Resets and computes CRC value of the whole array.

reset() method is called at the method begin.

Parameters
dataArray of words (4 bytes) to add.
Note
When input reverse is enabled, bits of whole word are reversed. For example: 0x0F0FFFFF => 0xFFFFF0F0
Parameters
dataLengthCount of words (4 bytes) in data array.
initValueInitial calculation value.
finalXORValue, that is used to XOR by bits the calculated result. Set to 0 if you want to disable final XORing.
Returns
Returns calculated CRC value.
Here is the call graph for this function:

◆ computeAndWriteToEnd() [1/6]

uint32_t HardwareCRC::computeAndWriteToEnd ( uint8_t *  data,
uint32_t  dataLength,
uint32_t  initValue = DEFAULT_HCRC_INITVAL,
uint32_t  finalXOR = 0x00 
)

Resets, computes CRC value of the whole array and attaches calculated CRC value at the end of the array.

reset() method is called at the method begin.

Parameters
dataArray of bytes to compute. At the end of array must be reserved 4 bytes when CRC-32, 2 bytes when CRC-16 and 1 byte when CRC-8 or CRC-7 is used.
Note
When input reverse is enabled, bits of whole word are reversed. For example: 0x0F => 0xF0
Parameters
dataLengthCount of bytes in data array. Excluding bytes reserved for CRC value.
initValueInitial calculation value.
finalXORValue, that is used to XOR by bits the calculated result. Set to 0 if you want to disable final XORing.
Returns
Returns calculated CRC value.
Examples
HarwareCRCExample.
Here is the call graph for this function:

◆ computeAndWriteToEnd() [2/6]

uint32_t HardwareCRC::computeAndWriteToEnd ( int8_t *  data,
uint32_t  dataLength,
uint32_t  initValue = DEFAULT_HCRC_INITVAL,
uint32_t  finalXOR = 0x00 
)
inline

Resets, computes CRC value of the whole array and attaches calculated CRC value at the end of the array.

reset() method is called at the method begin.

Parameters
dataArray of bytes to compute. At the end of array must be reserved 4 bytes when CRC-32, 2 bytes when CRC-16 and 1 byte when CRC-8 or CRC-7 is used.
Note
When input reverse is enabled, bits of whole word are reversed. For example: 0x0F => 0xF0
Parameters
dataLengthCount of bytes in data array. Excluding bytes reserved for CRC value.
initValueInitial calculation value.
finalXORValue, that is used to XOR by bits the calculated result. Set to 0 if you want to disable final XORing.
Returns
Returns calculated CRC value.
Here is the call graph for this function:

◆ computeAndWriteToEnd() [3/6]

uint32_t HardwareCRC::computeAndWriteToEnd ( uint16_t *  data,
uint32_t  dataLength,
uint32_t  initValue = DEFAULT_HCRC_INITVAL,
uint32_t  finalXOR = 0x00 
)

Resets, computes CRC value of the whole array and attaches calculated CRC value at the end of the array.

reset() method is called at the method begin.

Parameters
dataArray of half-words (2 bytes) to add. At the end of array must be reserved 4 bytes when CRC-32, 2 bytes when CRC-16 and 1 byte when CRC-8 or CRC-7 is used.
Note
When input reverse is enabled, bits of whole word are reversed. For example: 0x0FFF => 0xFFF0
Parameters
dataLengthCount of half-words (2 bytes) in data array. Excluding bytes reserved for CRC value.
initValueInitial calculation value.
finalXORValue, that is used to XOR by bits the calculated result. Set to 0 if you want to disable final XORing.
Returns
Returns calculated CRC value.
Here is the call graph for this function:

◆ computeAndWriteToEnd() [4/6]

uint32_t HardwareCRC::computeAndWriteToEnd ( int16_t *  data,
uint32_t  dataLength,
uint32_t  initValue = DEFAULT_HCRC_INITVAL,
uint32_t  finalXOR = 0x00 
)
inline

Resets, computes CRC value of the whole array and attaches calculated CRC value at the end of the array.

reset() method is called at the method begin.

Parameters
dataArray of half-words (2 bytes) to add. At the end of array must be reserved 4 bytes when CRC-32, 2 bytes when CRC-16 and 1 byte when CRC-8 or CRC-7 is used.
Note
When input reverse is enabled, bits of whole word are reversed. For example: 0x0FFF => 0xFFF0
Parameters
dataLengthCount of half-words (2 bytes) in data array. Excluding bytes reserved for CRC value.
initValueInitial calculation value.
finalXORValue, that is used to XOR by bits the calculated result. Set to 0 if you want to disable final XORing.
Returns
Returns calculated CRC value.
Here is the call graph for this function:

◆ computeAndWriteToEnd() [5/6]

uint32_t HardwareCRC::computeAndWriteToEnd ( uint32_t *  data,
uint32_t  dataLength,
uint32_t  initValue = DEFAULT_HCRC_INITVAL,
uint32_t  finalXOR = 0x00 
)

Resets, computes CRC value of the whole array and attaches calculated CRC value at the end of the array.

reset() method is called at the method begin.

Parameters
dataArray of words (4 bytes) to add. At the end of array must be reserved 4 bytes when CRC-32, 2 bytes when CRC-16 and 1 byte when CRC-8 or CRC-7 is used.
Note
When input reverse is enabled, bits of whole word are reversed. For example: 0x0F0FFFFF => 0xFFFFF0F0
Parameters
dataLengthCount of words (4 bytes) in data array. Excluding bytes reserved for CRC value.
initValueInitial calculation value.
finalXORValue, that is used to XOR by bits the calculated result. Set to 0 if you want to disable final XORing.
Returns
Returns calculated CRC value.
Here is the call graph for this function:

◆ computeAndWriteToEnd() [6/6]

uint32_t HardwareCRC::computeAndWriteToEnd ( int32_t *  data,
uint32_t  dataLength,
uint32_t  initValue = DEFAULT_HCRC_INITVAL,
uint32_t  finalXOR = 0x00 
)
inline

Resets, computes CRC value of the whole array and attaches calculated CRC value at the end of the array.

reset() method is called at the method begin.

Parameters
dataArray of words (4 bytes) to add. At the end of array must be reserved 4 bytes when CRC-32, 2 bytes when CRC-16 and 1 byte when CRC-8 or CRC-7 is used.
Note
When input reverse is enabled, bits of whole word are reversed. For example: 0x0F0FFFFF => 0xFFFFF0F0
Parameters
dataLengthCount of words (4 bytes) in data array. Excluding bytes reserved for CRC value.
initValueInitial calculation value.
finalXORValue, that is used to XOR by bits the calculated result. Set to 0 if you want to disable final XORing.
Returns
Returns calculated CRC value.
Here is the call graph for this function:

◆ check() [1/6]

bool HardwareCRC::check ( const uint8_t *  data,
uint32_t  dataLength,
uint32_t  initValue = DEFAULT_HCRC_INITVAL,
uint32_t  finalXOR = 0x00 
)

Checks if the array (with CRC attached at the end) is valid.

reset() method is called at the method begin.

Parameters
dataArray of bytes to check. CRC has to be at the end of the array.
Note
When input reverse is enabled, bits of whole word are reversed. For example: 0x0F0FFFFF => 0xFFFFF0F0
Parameters
dataLengthCount of bytes in data array (excluding CRC).
initValueInitial calculation value.
finalXORValue, that is used to XOR by bits the calculated result. Set to 0 if you want to disable final XORing.
Returns
Returns true when array is valid.
Examples
HarwareCRCExample.
Here is the call graph for this function:

◆ check() [2/6]

bool HardwareCRC::check ( const int8_t *  data,
uint32_t  dataLength,
uint32_t  initValue = DEFAULT_HCRC_INITVAL,
uint32_t  finalXOR = 0x00 
)
inline

Checks if the array (with CRC attached at the end) is valid.

reset() method is called at the method begin.

Parameters
dataArray of bytes to check. CRC has to be at the end of the array.
Note
When input reverse is enabled, bits of whole word are reversed. For example: 0x0F0FFFFF => 0xFFFFF0F0
Parameters
dataLengthCount of bytes in data array (excluding CRC).
initValueInitial calculation value.
finalXORValue, that is used to XOR by bits the calculated result. Set to 0 if you want to disable final XORing.
Returns
Returns true when array is valid.
Here is the call graph for this function:

◆ check() [3/6]

bool HardwareCRC::check ( const uint16_t *  data,
uint32_t  dataLength,
uint32_t  initValue = DEFAULT_HCRC_INITVAL,
uint32_t  finalXOR = 0x00 
)

Checks if the array (with CRC attached at the end) is valid.

reset() method is called at the method begin.

Parameters
dataArray of half-words (2 bytes) to check. CRC has to be at the end of the array.
Note
When input reverse is enabled, bits of whole word are reversed. For example: 0x0FFF => 0xFFF0
Parameters
dataLengthCount of half-words (2 bytes) in data array (excluding CRC).
initValueInitial calculation value.
finalXORValue, that is used to XOR by bits the calculated result. Set to 0 if you want to disable final XORing.
Returns
Returns true when array is valid.
Here is the call graph for this function:

◆ check() [4/6]

bool HardwareCRC::check ( const int16_t *  data,
uint32_t  dataLength,
uint32_t  initValue = DEFAULT_HCRC_INITVAL,
uint32_t  finalXOR = 0x00 
)
inline

Checks if the array (with CRC attached at the end) is valid.

reset() method is called at the method begin.

Parameters
dataArray of half-words (2 bytes) to check. CRC has to be at the end of the array.
Note
When input reverse is enabled, bits of whole word are reversed. For example: 0x0FFF => 0xFFF0
Parameters
dataLengthCount of half-words (2 bytes) in data array (excluding CRC).
initValueInitial calculation value.
finalXORValue, that is used to XOR by bits the calculated result. Set to 0 if you want to disable final XORing.
Returns
Returns true when array is valid.
Here is the call graph for this function:

◆ check() [5/6]

bool HardwareCRC::check ( const uint32_t *  data,
uint32_t  dataLength,
uint32_t  initValue = DEFAULT_HCRC_INITVAL,
uint32_t  finalXOR = 0x00 
)

Checks if the array (with CRC attached at the end) is valid.

reset() method is called at the method begin.

Parameters
dataArray of words (4 bytes) to check. CRC has to be at the end of the array.
Note
When input reverse is enabled, bits of whole word are reversed. For example: 0x0F0FFFFF => 0xFFFFF0F0
Parameters
dataLengthCount of words (4 bytes) in data array (excluding CRC).
initValueInitial calculation value.
finalXORValue, that is used to XOR by bits the calculated result. Set to 0 if you want to disable final XORing.
Returns
Returns true when array is valid.
Here is the call graph for this function:

◆ check() [6/6]

bool HardwareCRC::check ( const int32_t *  data,
uint32_t  dataLength,
uint32_t  initValue = DEFAULT_HCRC_INITVAL,
uint32_t  finalXOR = 0x00 
)
inline

Checks if the array (with CRC attached at the end) is valid.

reset() method is called at the method begin.

Parameters
dataArray of words (4 bytes) to check. CRC has to be at the end of the array.
Note
When input reverse is enabled, bits of whole word are reversed. For example: 0x0F0FFFFF => 0xFFFFF0F0
Parameters
dataLengthCount of words (4 bytes) in data array (excluding CRC).
initValueInitial calculation value.
finalXORValue, that is used to XOR by bits the calculated result. Set to 0 if you want to disable final XORing.
Returns
Returns true when array is valid.
Here is the call graph for this function:

◆ getCheckValue()

uint32_t HardwareCRC::getCheckValue ( uint32_t  initValue = DEFAULT_HCRC_INITVAL,
uint32_t  finalXOR = 0x00 
)

Calculates CRC check value.

When settings were not changed, last check value is returned. To validate array(with CRC at the end), compute it's CRC value again and compare to the check value.

Parameters
initValueInitial calculation value.
finalXORValue, that is used to XOR by bits the calculated result. Set to 0 if you want to disable final XORing.
Returns
Returns check value.
Here is the call graph for this function:

◆ setInputReverse()

bool HardwareCRC::setInputReverse ( bool  reverse)

Sets, if input data bits will be reversed(reflected) or not.

Returns
Returns true when input reflection is supported.
Examples
HarwareCRCExample.
Here is the call graph for this function:

◆ setOutputReverse()

bool HardwareCRC::setOutputReverse ( bool  reverse)

Sets, if output CRC data bits will be reversed(reflected) or not.

Note
Output is reversed immediately after calling this method. It can be used in run-time.
Returns
Returns true when output reflection is supported.
Examples
HarwareCRCExample.

◆ getInputReverse()

bool HardwareCRC::getInputReverse ( )
inline

Gets, if input data bits will be reversed(reflected) or not.

Returns
Returns true when input data bits will be reversed(reflected) or not.

◆ getOutputReverse()

bool HardwareCRC::getOutputReverse ( )
inline

Gets, if output CRC data bits will be reversed(reflected) or not.

Returns
Returns true when output CRC data bits will be reversed(reflected) or not.

◆ end()

void HardwareCRC::end ( )

Disables hardware CRC calculation unit.

◆ setInputReverseSize()

void HardwareCRC::setInputReverseSize ( uint32_t  reverse)
protected

Sets input reverse size to CR register.

Parameters
reverseSize to set.

Member Data Documentation

◆ isCustomPolynomialSupported

const bool HardwareCRC::isCustomPolynomialSupported = CRC_CUST_POLY
static

True when custom polynomials are supported.

Methods setPolynomial7(), setPolynomial8(), setPolynomial16(), setPolynomial32() will work correctly. If not, CRC-32 polynomial is used.

◆ isIOReverseSupported

const bool HardwareCRC::isIOReverseSupported = CRC_IO_REV_SUPP
static

True when input / output reversion (reflection) is supported.

◆ isCustomInitValueSupported

const bool HardwareCRC::isCustomInitValueSupported = CRC_CUST_INIT_VAL
static

True when custom initial value is supported, if not, 0xFFFFFFFFUL is set.

◆ lastCR

uint8_t HardwareCRC::lastCR = 0xFF
protected

◆ lastFXOR

uint32_t HardwareCRC::lastFXOR = 0
protected

◆ lastCRCCheckValue

uint32_t HardwareCRC::lastCRCCheckValue = 0
protected

◆ inputReverse

uint8_t HardwareCRC::inputReverse = HCRC_IN_REVERSE_DISABLED
protected

The documentation for this class was generated from the following files: