Skip to content

Commit

Permalink
AP_Math: add CRC8_generic method
Browse files Browse the repository at this point in the history
  • Loading branch information
hendjoshsr71 committed Jun 17, 2022
1 parent 6a3c73b commit 2dd15dd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
10 changes: 10 additions & 0 deletions libraries/AP_Math/crc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
1 change: 1 addition & 0 deletions libraries/AP_Math/crc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 2dd15dd

Please sign in to comment.