AP_Math: added smaller footprint crc32
This commit is contained in:
parent
5898dc757c
commit
ff2cfbaafb
@ -167,6 +167,7 @@ static const uint32_t crc32_tab[] = {
|
||||
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
|
||||
};
|
||||
|
||||
|
||||
uint32_t crc_crc32(uint32_t crc, const uint8_t *buf, uint32_t size)
|
||||
{
|
||||
for (uint32_t i=0; i<size; i++) {
|
||||
@ -176,6 +177,21 @@ uint32_t crc_crc32(uint32_t crc, const uint8_t *buf, uint32_t size)
|
||||
return crc;
|
||||
}
|
||||
|
||||
// smaller (and slower) crc32 for bootloader
|
||||
uint32_t crc32_small(uint32_t crc, const uint8_t *buf, uint32_t size)
|
||||
{
|
||||
while (size--) {
|
||||
const uint8_t byte = *buf++;
|
||||
crc ^= byte;
|
||||
for (uint8_t i=0; i<8; i++) {
|
||||
const uint32_t mask = -(crc & 1);
|
||||
crc >>= 1;
|
||||
crc ^= (0xEDB88320 & mask);
|
||||
}
|
||||
}
|
||||
return crc;
|
||||
}
|
||||
|
||||
/*
|
||||
* Copyright (C) 2010 Swift Navigation Inc.
|
||||
* Contact: Fergus Noble <fergus@swift-nav.com>
|
||||
|
@ -22,6 +22,7 @@ uint8_t crc_crc8(const uint8_t *p, uint8_t len);
|
||||
uint16_t crc_xmodem_update(uint16_t crc, uint8_t data);
|
||||
uint16_t crc_xmodem(const uint8_t *data, uint16_t len);
|
||||
uint32_t crc_crc32(uint32_t crc, const uint8_t *buf, uint32_t size);
|
||||
uint32_t crc32_small(uint32_t crc, const uint8_t *buf, uint32_t size);
|
||||
|
||||
// Copyright (C) 2010 Swift Navigation Inc.
|
||||
// Contact: Fergus Noble <fergus@swift-nav.com>
|
||||
|
Loading…
Reference in New Issue
Block a user