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 
00057 #ifdef __cplusplus
00058 extern "C" {
00059 #endif /* __cplusplus */
00060 
00061 
00062 /* CRC table */
00063 extern const uint16_t crc16tab[256];
00064 
00065 
00075 #define UPDCRC16(c, oldcrc) (crc16tab[((oldcrc) >> 8) ^ ((unsigned char)(c))] ^ ((oldcrc) << 8))
00076 
00077 
00078 #ifdef INLINE
00079 
00082 INLINE uint16_t updcrc16(uint8_t c, uint16_t oldcrc)
00083 {
00084     return crc16tab[(oldcrc >> 8) ^ c] ^ (oldcrc << 8);
00085 }
00086 #endif // INLINE
00087 
00088 
00098 extern uint16_t crc16(uint16_t crc, const void *buf, size_t len);
00099 
00100 #ifdef __cplusplus
00101 }
00102 #endif /* __cplusplus */
00103 
00104 #endif /* ALGO_CRC_H */