MCPcopy Create free account
hub / github.com/RobTillaart/Arduino / crc8

Function crc8

libraries/CRC/CRC.cpp:74–101  ·  view source on GitHub ↗

CRC POLYNOME = x8 + x5 + x4 + 1 = 1001 1000 = 0x8C

Source from the content-addressed store, hash-verified

72
73// CRC POLYNOME = x8 + x5 + x4 + 1 = 1001 1000 = 0x8C
74uint8_t crc8(const uint8_t *array, uint16_t length, const uint8_t polynome,
75 const uint8_t startmask, const uint8_t endmask,
76 const bool reverseIn, const bool reverseOut)
77{
78 uint8_t crc = startmask;
79 while (length--)
80 {
81 if ((length & 0xFF) == 0) yield(); // RTOS
82 uint8_t data = *array++;
83 if (reverseIn) data = reverse8(data);
84 crc ^= data;
85 for (uint8_t i = 8; i; i--)
86 {
87 if (crc & 0x80)
88 {
89 crc <<= 1;
90 crc ^= polynome;
91 }
92 else
93 {
94 crc <<= 1;
95 }
96 }
97 }
98 crc ^= endmask;
99 if (reverseOut) crc = reverse8(crc);
100 return crc;
101}
102
103
104// CRC POLYNOME = x12 + x3 + x2 + 1 = 0000 1000 0000 1101 = 0x80D

Callers 7

readStatusMethod · 0.85
readDataMethod · 0.85
unittestFunction · 0.85
readTemperatureMethod · 0.85
readHumidityMethod · 0.85
readStatusMethod · 0.85
readDataMethod · 0.85

Calls 1

reverse8Function · 0.85

Tested by 1

unittestFunction · 0.68