AP_Math: add CRC8_generic method

This commit is contained in:
Joshua Henderson 2022-04-26 21:09:20 -04:00 committed by Peter Barker
parent 78e9846f4e
commit 8e634f05d9
2 changed files with 11 additions and 0 deletions

View File

@ -92,6 +92,16 @@ uint8_t crc_crc8(const uint8_t *p, uint8_t len)
return crc & 0xFF;
}
// CRC8 that does not use a lookup table: for generic polynomials
uint8_t crc8_generic(const uint8_t *buf, const uint16_t buf_len, const uint8_t polynomial)
{
uint8_t crc = 0;
for (uint16_t i = 0; i < buf_len; i++) {
crc = crc8_dvb(buf[i], crc, polynomial);
}
return crc;
}
// crc8 from betaflight
uint8_t crc8_dvb_s2(uint8_t crc, uint8_t a)
{

View File

@ -21,6 +21,7 @@
uint16_t crc_crc4(uint16_t *data);
uint8_t crc_crc8(const uint8_t *p, uint8_t len);
uint8_t crc8_generic(const uint8_t *buf, const uint16_t buf_len, const uint8_t polynomial); // CRC8 that does not use a lookup table for generic polynomials
uint8_t crc8_dvb_s2(uint8_t crc, uint8_t a);
uint8_t crc8_dvb(uint8_t crc, uint8_t a, uint8_t seed);
uint8_t crc8_dvb_s2_update(uint8_t crc, const void *data, uint32_t length);