-
-
Notifications
You must be signed in to change notification settings - Fork 65
Open
Description
Space in MuxTO is very tight; depending on compiler version, it can't be built to fit into the available 12k of flash.
This piece of code is (should be) a drop-in replacement for the CRC function in crc16.cpp. It does bitwise calculation of the CRC instead of the table-driven byte-at-a-time algorithm that is currently used. This is presumably about 8x slower (which I believe shouldn't matter), but it eliminates the 512byte crc_table, making it about 1/40th the flash size.
(CRC Algorithm tested on a desktop, and code compiles in Arduino. Not yet tested in an actual Nano every...)
/*
* "reflected" (LSB first) CCITT CRC-16
*/
uint16_t POLY = 0x8408; // bit reversed 0x1021
uint16_t CRC::next(uint8_t newchar, uint16_t crc) {
int j;
uint_fast16_t crcshadow = crc ^ newchar; // move some uxth instructions outside the bit loop.
for (j = 0; j < 8; j++) {
if (crcshadow & 1) { // Check if LSB is set
crcshadow = (crcshadow >> 1) ^ POLY;
} else {
crcshadow >>= 1;
}
}
return crcshadow;
}
Metadata
Metadata
Assignees
Labels
No labels