BeRTOS
crc.h
Go to the documentation of this file.
00001 
00051 #ifndef ALGO_CRC_H
00052 #define ALGO_CRC_H
00053 
00054 #include "cfg/cfg_arch.h"
00055 
00056 #include <cfg/compiler.h>
00057 #include <cpu/pgm.h>
00058 
00059 EXTERN_C_BEGIN
00060 
00061 /* CRC table */
00062 extern const uint16_t crc16tab[256];
00063 
00064 
00074 #if CPU_HARVARD && !(defined(ARCH_BOOT) && (ARCH & ARCH_BOOT))
00075     #define UPDCRC16(c, oldcrc) (pgm_read_uint16_t(&crc16tab[((oldcrc) >> 8) ^ ((unsigned char)(c))]) ^ ((oldcrc) << 8))
00076 #else
00077     #define UPDCRC16(c, oldcrc) ((crc16tab[((oldcrc) >> 8) ^ ((unsigned char)(c))]) ^ ((oldcrc) << 8))
00078 #endif
00079 
00081 #define CRC16_INIT_VAL ((uint16_t)0)
00082 
00083 #ifdef INLINE
00084 
00087 INLINE uint16_t updcrc16(uint8_t c, uint16_t oldcrc)
00088 {
00089 #if CPU_HARVARD && !(defined(ARCH_BOOT) && (ARCH & ARCH_BOOT))
00090     return pgm_read_uint16_t(&crc16tab[(oldcrc >> 8) ^ c]) ^ (oldcrc << 8);
00091 #else
00092     return crc16tab[(oldcrc >> 8) ^ c] ^ (oldcrc << 8);
00093 #endif
00094 }
00095 #endif // INLINE
00096 
00097 
00107 extern uint16_t crc16(uint16_t crc, const void *buf, size_t len);
00108 
00109 int crc_testSetup(void);
00110 int crc_testRun(void);
00111 int crc_testTearDown(void);
00112 
00113 EXTERN_C_END
00114 
00115 #endif /* ALGO_CRC_H */