mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-09-10 02:03:57 +08:00
eefc084302
version: sunnypilot v2025.003.000 (dev) date: 2025-12-18T05:48:43 master commit: 16c052af0835f049a67b80251d8cc1114fc08bb4
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;
|
|
}
|