diff --git a/libraries/AP_Math/crc.cpp b/libraries/AP_Math/crc.cpp index 90274771663de2..38843f939f4da5 100644 --- a/libraries/AP_Math/crc.cpp +++ b/libraries/AP_Math/crc.cpp @@ -90,6 +90,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) { diff --git a/libraries/AP_Math/crc.h b/libraries/AP_Math/crc.h index dc8daaaf6d3d40..23d87d2ea6970d 100644 --- a/libraries/AP_Math/crc.h +++ b/libraries/AP_Math/crc.h @@ -19,6 +19,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);