X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=bertos%2Falgo%2Fcrc.c;h=d4293f9e063e82d4b7a90359d80a76f928b12eeb;hb=ce0a95c32a39e3eed1d3f2aa5ff4395bebdb99ed;hp=684ddbd9c1868041d893cb1917b8fdca78df90a1;hpb=4cc44c9888a0336b9d01121ec0b7ad95f4a76195;p=bertos.git diff --git a/bertos/algo/crc.c b/bertos/algo/crc.c index 684ddbd9..d4293f9e 100644 --- a/bertos/algo/crc.c +++ b/bertos/algo/crc.c @@ -33,16 +33,30 @@ * * \brief CRC table and support routines * - * \version $Id$ * \author Bernie Innocenti */ #include "crc.h" +/* + * The boot on AVR cpu is placed at the end of flash memory, but the avr + * address memory by byte and the pointers are 16bits long, so we are able + * to address 64Kbyte memory max. For this reason we can't read the crctab + * from flash, because it is placed at the end of memory. This is true every + * time we have an AVR cpu with more that 64Kbyte of flash. To fix this problem + * we let the compiler copy the table in RAM at startup. Obviously this solution + * is not efficent, but for now this is the only way. + */ +#if CPU_HARVARD && !(defined(ARCH_BOOT) && (ARCH & ARCH_BOOT)) + #define CRC_TABLE const uint16_t PROGMEM crc16tab[256] +#else + #define CRC_TABLE const uint16_t crc16tab[256] +#endif + /** * crctab calculated by Mark G. Mendel, Network Systems Corporation */ -const uint16_t crc16tab[256] = { +CRC_TABLE = { 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef, 0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6,