From: (no author) <(no author)@38d2e660-2303-0410-9eaa-f027e97ec537> Date: Wed, 5 Aug 2009 07:57:59 +0000 (+0000) Subject: Move crc16tab in PROGMEM for AVR chips (Thanks to M. Cialdi, Powersoft). X-Git-Tag: 2.2.0~198 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=46fb189becafd5e812ce9a58eb4c25b586b17771;p=bertos.git Move crc16tab in PROGMEM for AVR chips (Thanks to M. Cialdi, Powersoft). Save some RAM bytes by moving crc table into PROGMEM. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@2770 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/bertos/algo/crc.c b/bertos/algo/crc.c index 684ddbd9..96007add 100644 --- a/bertos/algo/crc.c +++ b/bertos/algo/crc.c @@ -42,7 +42,7 @@ /** * crctab calculated by Mark G. Mendel, Network Systems Corporation */ -const uint16_t crc16tab[256] = { +const uint16_t PROGMEM crc16tab[256] = { 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef, 0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6, diff --git a/bertos/algo/crc.h b/bertos/algo/crc.h index 483f2192..81a0c926 100644 --- a/bertos/algo/crc.h +++ b/bertos/algo/crc.h @@ -53,6 +53,8 @@ #define ALGO_CRC_H #include +#include + #ifdef __cplusplus extern "C" { @@ -60,7 +62,7 @@ extern "C" { /* CRC table */ -extern const uint16_t crc16tab[256]; +const uint16_t crc16tab[256]; /** @@ -72,7 +74,11 @@ extern const uint16_t crc16tab[256]; * \param c New octet (range 0-255) * \param oldcrc Previous CRC16 value (referenced twice, beware of side effects) */ -#define UPDCRC16(c, oldcrc) (crc16tab[((oldcrc) >> 8) ^ ((unsigned char)(c))] ^ ((oldcrc) << 8)) +#if CPU_AVR + #define UPDCRC16(c, oldcrc) (pgm_read_uint16_t(&crc16tab[((oldcrc) >> 8) ^ ((unsigned char)(c))]) ^ ((oldcrc) << 8)) +#else + #define UPDCRC16(c, oldcrc) ((crc16tab[((oldcrc) >> 8) ^ ((unsigned char)(c))]) ^ ((oldcrc) << 8)) +#endif #ifdef INLINE @@ -81,7 +87,11 @@ extern const uint16_t crc16tab[256]; */ INLINE uint16_t updcrc16(uint8_t c, uint16_t oldcrc) { +#if CPU_AVR + return pgm_read_uint16_t(&crc16tab[(oldcrc >> 8) ^ c]) ^ (oldcrc << 8); +#else return crc16tab[(oldcrc >> 8) ^ c] ^ (oldcrc << 8); +#endif } #endif // INLINE