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_HARVARD
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
00080 #define CRC16_INIT_VAL ((uint16_t)0)
00081
00082 #ifdef INLINE
00083
00086 INLINE uint16_t updcrc16(uint8_t c, uint16_t oldcrc)
00087 {
00088 #if CPU_HARVARD
00089 return pgm_read_uint16_t(&crc16tab[(oldcrc >> 8) ^ c]) ^ (oldcrc << 8);
00090 #else
00091 return crc16tab[(oldcrc >> 8) ^ c] ^ (oldcrc << 8);
00092 #endif
00093 }
00094 #endif // INLINE
00095
00096
00106 extern uint16_t crc16(uint16_t crc, const void *buf, size_t len);
00107
00108 int crc_testSetup(void);
00109 int crc_testRun(void);
00110 int crc_testTearDown(void);
00111
00112 EXTERN_C_END
00113
00114 #endif