panda/board/crc.h

20 lines
356 B
C
Raw Normal View History

#pragma once
2020-02-25 07:26:59 +08:00
uint8_t crc_checksum(uint8_t *dat, int len, const uint8_t poly) {
2021-06-19 06:11:09 +08:00
uint8_t crc = 0xFFU;
int i;
int j;
2020-02-25 07:26:59 +08:00
for (i = len - 1; i >= 0; i--) {
crc ^= dat[i];
for (j = 0; j < 8; j++) {
if ((crc & 0x80U) != 0U) {
crc = (uint8_t)((crc << 1) ^ poly);
}
else {
crc <<= 1;
}
}
}
return crc;
}