You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
356 B
20 lines
356 B
2 years ago
|
#pragma once
|
||
|
|
||
|
uint8_t crc_checksum(uint8_t *dat, int len, const uint8_t poly) {
|
||
|
uint8_t crc = 0xFFU;
|
||
|
int i;
|
||
|
int j;
|
||
|
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;
|
||
|
}
|