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

Function crc32

libraries/CRC/CRC.cpp:176–203  ·  view source on GitHub ↗

CRC-32 POLYNOME = x32 + ..... + 1

Source from the content-addressed store, hash-verified

174
175// CRC-32 POLYNOME = x32 + ..... + 1
176uint32_t crc32(const uint8_t *array, uint16_t length, const uint32_t polynome,
177 const uint32_t startmask, const uint32_t endmask,
178 const bool reverseIn, const bool reverseOut)
179{
180 uint32_t crc = startmask;
181 while (length--)
182 {
183 if ((length & 0xFF) == 0) yield(); // RTOS
184 uint8_t data = *array++;
185 if (reverseIn) data = reverse8(data);
186 crc ^= ((uint32_t) data) << 24;
187 for (uint8_t i = 8; i; i--)
188 {
189 if (crc & (1UL << 31))
190 {
191 crc <<= 1;
192 crc ^= polynome;
193 }
194 else
195 {
196 crc <<= 1;
197 }
198 }
199 }
200 crc ^= endmask;
201 if (reverseOut) crc = reverse32(crc);
202 return crc;
203}
204
205
206// CRC-CCITT POLYNOME = x64 + ..... + 1

Callers 1

unittestFunction · 0.85

Calls 2

reverse8Function · 0.85
reverse32Function · 0.85

Tested by 1

unittestFunction · 0.68