MeshProtocolSimulator
1.0.0
|
Go to the documentation of this file.
15 #ifndef HARDWARECRC_H_
16 #define HARDWARECRC_H_
21 #include "Simulation.h"
33 #define CRC_X0 (0x01UL)
34 #define CRC_X1 (0x01UL << 1U)
35 #define CRC_X2 (0x01UL << 2U)
36 #define CRC_X3 (0x01UL << 3U)
37 #define CRC_X4 (0x01UL << 4U)
38 #define CRC_X5 (0x01UL << 5U)
39 #define CRC_X6 (0x01UL << 6U)
40 #define CRC_X7 (0x01UL << 7U)
41 #define CRC_X8 (0x01UL << 8U)
42 #define CRC_X9 (0x01UL << 9U)
43 #define CRC_X10 (0x01UL << 10U)
44 #define CRC_X11 (0x01UL << 11U)
45 #define CRC_X12 (0x01UL << 12U)
46 #define CRC_X13 (0x01UL << 13U)
47 #define CRC_X14 (0x01UL << 14U)
48 #define CRC_X15 (0x01UL << 15U)
49 #define CRC_X16 (0x01UL << 16U)
50 #define CRC_X17 (0x01UL << 17U)
51 #define CRC_X18 (0x01UL << 18U)
52 #define CRC_X19 (0x01UL << 19U)
53 #define CRC_X20 (0x01UL << 20U)
54 #define CRC_X21 (0x01UL << 21U)
55 #define CRC_X22 (0x01UL << 22U)
56 #define CRC_X23 (0x01UL << 23U)
57 #define CRC_X24 (0x01UL << 24U)
58 #define CRC_X25 (0x01UL << 25U)
59 #define CRC_X26 (0x01UL << 26U)
60 #define CRC_X27 (0x01UL << 27U)
61 #define CRC_X28 (0x01UL << 28U)
62 #define CRC_X29 (0x01UL << 29U)
63 #define CRC_X30 (0x01UL << 30U)
64 #define CRC_X31 (0x01UL << 31U)
74 #define CRC32_POLY (0x04C11DB7UL)
75 #define CRC16_POLY (0x8005UL)
76 #define CRC8_POLY (0x31UL)
77 #define CRC7_POLY (0x09UL)
83 #define DEFAULT_HCRC_INITVAL (0xFFFFFFFFUL) //Default initial value
86 #define HCRC_POLYSIZE_MASK (0x18) //B00011000
88 #define HCRC_32BIT_POLYSIZE (0x00)
89 #define HCRC_16BIT_POLYSIZE (0x08)
90 #define HCRC_8BIT_POLYSIZE (0x10)
91 #define HCRC_7BIT_POLYSIZE (HCRC_POLYSIZE_MASK)
94 #define HCRC_OUT_REVERSE_MASK (0x80) //B10000000
96 #define HCRC_OUT_REVERSE_ENABLED HCRC_OUT_REVERSE_MASK
97 #define HCRC_OUT_REVERSE_DISABLED (0x0)
100 #define HCRC_IN_REVERSE_MASK (0x60) //B01100000
102 #define HCRC_IN_REVERSE_ENABLED_BYTE (0x20)
103 #define HCRC_IN_REVERSE_ENABLED_HALFWORD (0x40)
104 #define HCRC_IN_REVERSE_ENABLED_WORD HCRC_IN_REVERSE_MASK
105 #define HCRC_IN_REVERSE_DISABLED (0x0)
220 void reset(uint32_t initValue = DEFAULT_HCRC_INITVAL) {
230 uint32_t
append(
const uint8_t data, uint32_t finalXOR = 0x00) {
242 uint32_t
append(
const uint8_t* data, uint32_t dataLength, uint32_t finalXOR = 0x00) {
254 uint32_t
append(
const int8_t* data, uint32_t dataLength, uint32_t finalXOR = 0x00){
255 return append((
const uint8_t*)data, dataLength, finalXOR);
265 uint32_t
append(
const uint16_t data, uint32_t finalXOR = 0x00) {
277 uint32_t
append(
const uint16_t* data, uint32_t dataLength, uint32_t finalXOR = 0x00) {
289 uint32_t
append(
const int16_t* data, uint32_t dataLength, uint32_t finalXOR = 0x00){
290 return append((
const uint16_t*)data, dataLength, finalXOR);
300 uint32_t
append(
const uint32_t data, uint32_t finalXOR = 0x00) {
312 uint32_t
append(
const uint32_t* data, uint32_t dataLength, uint32_t finalXOR = 0x00) {
324 uint32_t
append (
const int32_t* data, uint32_t dataLength, uint32_t finalXOR = 0x00){
325 return append((
const uint32_t*)data, dataLength, finalXOR);
337 uint32_t
compute(
const uint8_t* data, uint32_t dataLength, uint32_t initValue = DEFAULT_HCRC_INITVAL, uint32_t finalXOR = 0x00) {
350 uint32_t
compute(
const int8_t* data, uint32_t dataLength, uint32_t initValue = DEFAULT_HCRC_INITVAL, uint32_t finalXOR = 0x00){
351 return compute((
const uint8_t*)data, dataLength, initValue, finalXOR);
363 uint32_t
compute(
const uint16_t* data, uint32_t dataLength, uint32_t initValue = DEFAULT_HCRC_INITVAL, uint32_t finalXOR = 0x00) {
376 uint32_t
compute(
const int16_t* data, uint32_t dataLength, uint32_t initValue = DEFAULT_HCRC_INITVAL, uint32_t finalXOR = 0x00){
377 return compute((
const uint16_t*)data, dataLength, initValue, finalXOR);
389 uint32_t
compute(
const uint32_t* data, uint32_t dataLength, uint32_t initValue = DEFAULT_HCRC_INITVAL, uint32_t finalXOR = 0x00) {
402 uint32_t
compute(
const int32_t* data, uint32_t dataLength, uint32_t initValue = DEFAULT_HCRC_INITVAL, uint32_t finalXOR = 0x00){
403 return compute((
const uint32_t*)data, dataLength, initValue, finalXOR);
415 uint32_t
computeAndWriteToEnd(uint8_t* data, uint32_t dataLength, uint32_t initValue = DEFAULT_HCRC_INITVAL, uint32_t finalXOR = 0x00) {
428 uint32_t
computeAndWriteToEnd(int8_t* data, uint32_t dataLength, uint32_t initValue = DEFAULT_HCRC_INITVAL, uint32_t finalXOR = 0x00){
441 uint32_t
computeAndWriteToEnd(uint16_t* data, uint32_t dataLength, uint32_t initValue = DEFAULT_HCRC_INITVAL, uint32_t finalXOR = 0x00) {
454 uint32_t
computeAndWriteToEnd(int16_t* data, uint32_t dataLength, uint32_t initValue = DEFAULT_HCRC_INITVAL, uint32_t finalXOR = 0x00){
467 uint32_t
computeAndWriteToEnd(uint32_t* data, uint32_t dataLength, uint32_t initValue = DEFAULT_HCRC_INITVAL, uint32_t finalXOR = 0x00) {
480 uint32_t
computeAndWriteToEnd(int32_t* data, uint32_t dataLength, uint32_t initValue = DEFAULT_HCRC_INITVAL, uint32_t finalXOR = 0x00){
493 bool check(
const uint8_t* data, uint32_t dataLength, uint32_t initValue = DEFAULT_HCRC_INITVAL, uint32_t finalXOR = 0x00) {
506 bool check(
const int8_t* data, uint32_t dataLength, uint32_t initValue = DEFAULT_HCRC_INITVAL, uint32_t finalXOR = 0x00){
507 return check((
const uint8_t*)data, dataLength, initValue, finalXOR);
519 bool check(
const uint16_t* data, uint32_t dataLength, uint32_t initValue = DEFAULT_HCRC_INITVAL, uint32_t finalXOR = 0x00) {
532 bool check(
const int16_t* data, uint32_t dataLength, uint32_t initValue = DEFAULT_HCRC_INITVAL, uint32_t finalXOR = 0x00){
533 return check((
const uint16_t*)data, dataLength, initValue, finalXOR);
545 bool check(
const uint32_t* data, uint32_t dataLength, uint32_t initValue = DEFAULT_HCRC_INITVAL, uint32_t finalXOR = 0x00) {
558 bool check(
const int32_t* data, uint32_t dataLength, uint32_t initValue = DEFAULT_HCRC_INITVAL, uint32_t finalXOR = 0x00){
559 return check((
const uint32_t*)data, dataLength, initValue, finalXOR);
568 uint32_t
getCheckValue(uint32_t initValue = DEFAULT_HCRC_INITVAL,uint32_t finalXOR = 0x00) {
594 #if CRC_IO_REV_SUPP == (0x1)
595 return (inputReverse & HCRC_IN_REVERSE_MASK) != HCRC_IN_REVERSE_DISABLED;
606 #if CRC_IO_REV_SUPP == (0x1)
607 return (CRC->CR & HCRC_OUT_REVERSE_MASK) == HCRC_OUT_REVERSE_ENABLED;
642 uint8_t lastCR = 0xFF;
643 #if CRC_CUST_POLY == (0x1)
644 uint32_t lastPoly = 0;
646 #if CRC_CUST_INIT_VAL == (0x1)
647 uint32_t lastInit = 0;
649 uint32_t lastFXOR = 0;
650 uint32_t lastCRCCheckValue = 0;
663 uint8_t inputReverse = HCRC_IN_REVERSE_DISABLED;
void end()
Disables hardware CRC calculation unit.
Definition: HardwareCRC.h:616
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 b...
Definition: HardwareCRC.h:532
uint32_t getPolynomial()
Gets polynomial, that was set.
Definition: HardwareCRC.h:187
uint32_t append(const uint16_t data, uint32_t finalXOR=0x00)
Appends another data to previous CRC calculation and calculates new CRC value.
Definition: HardwareCRC.h:265
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.
Definition: HardwareCRC.h:402
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....
Definition: HardwareCRC.h:568
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 arr...
Definition: HardwareCRC.h:480
void setInputReverseSize(uint32_t reverse)
Sets input reverse size to CR register.
Definition: HardwareCRC.h:660
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.
Definition: HardwareCRC.h:277
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.
Definition: HardwareCRC.h:389
static const bool isCustomPolynomialSupported
True when custom polynomials are supported. Methods setPolynomial7(), setPolynomial8(),...
Definition: HardwareCRC.h:627
Calculate CRC simply and fast using this class. Calculation is done using hardware CRC calculation un...
Definition: HardwareCRC.h:132
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 arr...
Definition: HardwareCRC.h:441
bool setOutputReverse(bool reverse)
Sets, if output CRC data bits will be reversed(reflected) or not.
Definition: HardwareCRC.h:585
void reset(uint32_t initValue=DEFAULT_HCRC_INITVAL)
Resets calculation and sets initial value.
Definition: HardwareCRC.h:220
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.
Definition: HardwareCRC.h:337
bool setPolynomial32(uint32_t polynomial=CRC32_POLY)
Sets CRC-32 polynomial.
Definition: HardwareCRC.h:179
uint8_t getPolynomialLength()
Gets polynomial length in bits.
Definition: HardwareCRC.h:195
uint32_t getInitValue()
Gets initial value, that was set using reset(), compute() or computeAndWriteToEnd() method.
Definition: HardwareCRC.h:203
uint32_t append(const uint8_t data, uint32_t finalXOR=0x00)
Appends another data to previous CRC calculation and calculates new CRC value.
Definition: HardwareCRC.h:230
uint32_t getLastCRC(uint32_t finalXOR=0x00)
Gets last calculated CRC result.
Definition: HardwareCRC.h:212
bool setPolynomial16(uint32_t polynomial=CRC16_POLY)
Sets CRC-16 polynomial.
Definition: HardwareCRC.h:169
static const bool isCustomInitValueSupported
True when custom initial value is supported, if not, 0xFFFFFFFFUL is set.
Definition: HardwareCRC.h:637
uint32_t append(const uint32_t data, uint32_t finalXOR=0x00)
Appends another data to previous CRC calculation and calculates new CRC value.
Definition: HardwareCRC.h:300
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.
Definition: HardwareCRC.h:324
static const bool isIOReverseSupported
True when input / output reversion (reflection) is supported.
Definition: HardwareCRC.h:632
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.
Definition: HardwareCRC.h:363
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 arr...
Definition: HardwareCRC.h:454
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.
Definition: HardwareCRC.h:376
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 arr...
Definition: HardwareCRC.h:428
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.
Definition: HardwareCRC.h:312
bool getInputReverse()
Gets, if input data bits will be reversed(reflected) or not.
Definition: HardwareCRC.h:593
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 arr...
Definition: HardwareCRC.h:467
bool setPolynomial8(uint32_t polynomial=CRC8_POLY)
Sets CRC-8 polynomial.
Definition: HardwareCRC.h:159
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.
Definition: HardwareCRC.h:350
bool setInputReverse(bool reverse)
Sets, if input data bits will be reversed(reflected) or not.
Definition: HardwareCRC.h:576
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 b...
Definition: HardwareCRC.h:558
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 arr...
Definition: HardwareCRC.h:415
bool setPolynomial7(uint32_t polynomial=CRC7_POLY)
Sets CRC-7 polynomial.
Definition: HardwareCRC.h:149
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 b...
Definition: HardwareCRC.h:545
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.
Definition: HardwareCRC.h:254
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.
Definition: HardwareCRC.h:289
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 b...
Definition: HardwareCRC.h:493
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.
Definition: HardwareCRC.h:242
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 b...
Definition: HardwareCRC.h:506
bool getOutputReverse()
Gets, if output CRC data bits will be reversed(reflected) or not.
Definition: HardwareCRC.h:605
bool begin()
Enables CRC hardware calculation unit.
Definition: HardwareCRC.h:139
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 b...
Definition: HardwareCRC.h:519