mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-07-19 08:12:07 +08:00
4012d181e1
date: 2024-03-17T10:14:38 master commit: 7e9a909e0e57ecb31df4c87c5b9a06b1204fd034
20 lines
362 B
C
20 lines
362 B
C
#pragma once
|
|
|
|
uint8_t crc_checksum(const 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;
|
|
}
|