crc.h
Go to the documentation of this file.00001
00052 #ifndef ALGO_CRC_H
00053 #define ALGO_CRC_H
00054
00055 #include <cfg/compiler.h>
00056 #include <cpu/pgm.h>
00057
00058 EXTERN_C_BEGIN
00059
00060
00061 extern const uint16_t crc16tab[256];
00062
00063
00073 #if CPU_AVR
00074 #define UPDCRC16(c, oldcrc) (pgm_read_uint16_t(&crc16tab[((oldcrc) >> 8) ^ ((unsigned char)(c))]) ^ ((oldcrc) << 8))
00075 #else
00076 #define UPDCRC16(c, oldcrc) ((crc16tab[((oldcrc) >> 8) ^ ((unsigned char)(c))]) ^ ((oldcrc) << 8))
00077 #endif
00078
00079
00080 #ifdef INLINE
00081
00084 INLINE uint16_t updcrc16(uint8_t c, uint16_t oldcrc)
00085 {
00086 #if CPU_AVR
00087 return pgm_read_uint16_t(&crc16tab[(oldcrc >> 8) ^ c]) ^ (oldcrc << 8);
00088 #else
00089 return crc16tab[(oldcrc >> 8) ^ c] ^ (oldcrc << 8);
00090 #endif
00091 }
00092 #endif // INLINE
00093
00094
00104 extern uint16_t crc16(uint16_t crc, const void *buf, size_t len);
00105
00106 EXTERN_C_END
00107
00108 #endif