3 GENERIC_CRC8::GENERIC_CRC8(uint8_t poly
)
7 for (uint16_t i
= 0; i
< crclen
; i
++)
10 for (uint8_t j
= 0; j
< 8; j
++)
12 crc
= (crc
<< 1) ^ ((crc
& 0x80) ? poly
: 0);
14 crc8tab
[i
] = crc
& 0xFF;
18 uint8_t ICACHE_RAM_ATTR
GENERIC_CRC8::calc(const uint8_t data
)
23 uint8_t ICACHE_RAM_ATTR
GENERIC_CRC8::calc(const uint8_t *data
, uint16_t len
, uint8_t crc
)
27 crc
= crc8tab
[crc
^ *data
++];
32 void Crc2Byte::init(uint8_t bits
, uint16_t poly
)
34 if (bits
== _bits
&& poly
== _poly
)
38 _bitmask
= (1 << _bits
) - 1;
39 uint16_t highbit
= 1 << (_bits
- 1);
41 for (uint16_t i
= 0; i
< crclen
; i
++)
43 crc
= i
<< (bits
- 8);
44 for (uint8_t j
= 0; j
< 8; j
++)
46 crc
= (crc
<< 1) ^ ((crc
& highbit
) ? poly
: 0);
52 uint16_t ICACHE_RAM_ATTR
Crc2Byte::calc(uint8_t *data
, uint8_t len
, uint16_t crc
)
56 crc
= (crc
<< 8) ^ _crctab
[((crc
>> (_bits
- 8)) ^ (uint16_t) *data
++) & 0x00FF];
58 return crc
& _bitmask
;