MeshProtocolSimulator  1.0.0
Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
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. reset() method is called at the method begin. 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. reset() method is called at the method begin. 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. reset() method is called at the method begin. 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. reset() method is called at the method begin. 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. reset() method is called at the method begin. 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. reset() method is called at the method begin. 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. reset() method is called at the method begin. 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. reset() method is called at the method begin. 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. reset() method is called at the method begin. 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. reset() method is called at the method begin. 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. reset() method is called at the method begin. 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. reset() method is called at the method begin. 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. reset() method is called at the method begin. 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. reset() method is called at the method begin. 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. reset() method is called at the method begin. 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. reset() method is called at the method begin. 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. reset() method is called at the method begin. 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. reset() method is called at the method begin. More...
 
uint32_t 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. 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.
 

Static Public Attributes

static const bool isCustomPolynomialSupported = 0
 True when custom polynomials are supported. Methods setPolynomial7(), setPolynomial8(), setPolynomial16(), setPolynomial32() will work correctly. If not, CRC-32 polynomial is used.
 
static const bool isIOReverseSupported = 0
 True when input / output reversion (reflection) is supported.
 
static const bool isCustomInitValueSupported = 0
 True when custom initial value is supported, if not, 0xFFFFFFFFUL is set.
 

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:

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

◆ append() [1/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.

◆ append() [2/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.

◆ 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.

◆ append() [4/9]

uint32_t HardwareCRC::append ( const uint16_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.

◆ append() [5/9]

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

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.

◆ append() [6/9]

uint32_t HardwareCRC::append ( const uint32_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.

◆ append() [7/9]

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

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.

◆ append() [8/9]

uint32_t HardwareCRC::append ( const uint8_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.

◆ append() [9/9]

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

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.

◆ begin()

bool HardwareCRC::begin ( )
inline

Enables CRC hardware calculation unit.

Returns
Returns true when periphery was enabled.

◆ check() [1/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.

◆ check() [2/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.

◆ check() [3/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.

◆ check() [4/6]

bool HardwareCRC::check ( const uint16_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.

◆ check() [5/6]

bool HardwareCRC::check ( const uint32_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.

◆ check() [6/6]

bool HardwareCRC::check ( const uint8_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.

◆ compute() [1/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.

◆ compute() [2/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.

◆ compute() [3/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.

◆ compute() [4/6]

uint32_t HardwareCRC::compute ( const uint16_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.

◆ compute() [5/6]

uint32_t HardwareCRC::compute ( const uint32_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.

◆ compute() [6/6]

uint32_t HardwareCRC::compute ( const uint8_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.

◆ computeAndWriteToEnd() [1/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.

◆ computeAndWriteToEnd() [2/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.

◆ computeAndWriteToEnd() [3/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.

◆ computeAndWriteToEnd() [4/6]

uint32_t HardwareCRC::computeAndWriteToEnd ( uint16_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.

◆ computeAndWriteToEnd() [5/6]

uint32_t HardwareCRC::computeAndWriteToEnd ( uint32_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.

◆ computeAndWriteToEnd() [6/6]

uint32_t HardwareCRC::computeAndWriteToEnd ( uint8_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.

◆ getCheckValue()

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

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.

◆ getInitValue()

uint32_t HardwareCRC::getInitValue ( )
inline

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

Returns
Returns initial value.

◆ 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.

◆ 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.

◆ 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.

◆ getPolynomial()

uint32_t HardwareCRC::getPolynomial ( )
inline

Gets polynomial, that was set.

Returns
Returns polynomial.

◆ getPolynomialLength()

uint8_t HardwareCRC::getPolynomialLength ( )
inline

Gets polynomial length in bits.

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

◆ reset()

void HardwareCRC::reset ( uint32_t  initValue = DEFAULT_HCRC_INITVAL)
inline

Resets calculation and sets initial value.

Parameters
initValueInitial calculation value.

◆ setInputReverse()

bool HardwareCRC::setInputReverse ( bool  reverse)
inline

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

Returns
Returns true when input reflection is supported.

◆ setInputReverseSize()

void HardwareCRC::setInputReverseSize ( uint32_t  reverse)
inlineprotected

Sets input reverse size to CR register.

Parameters
reverseSize to set.

◆ setOutputReverse()

bool HardwareCRC::setOutputReverse ( bool  reverse)
inline

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.

◆ setPolynomial16()

bool HardwareCRC::setPolynomial16 ( uint32_t  polynomial = CRC16_POLY)
inline

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)
inline

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.

◆ setPolynomial7()

bool HardwareCRC::setPolynomial7 ( uint32_t  polynomial = CRC7_POLY)
inline

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)
inline

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.

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