X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=bertos%2Falgo%2Fcrc.h;h=9696e4f1606679d5ab53f8ad304edba209c4d72a;hb=2a398044dd1d7b2af34a96c19ad378c25b546579;hp=81a0c9265a2b6bb7996618a3566c5cde34ab3465;hpb=46fb189becafd5e812ce9a58eb4c25b586b17771;p=bertos.git diff --git a/bertos/algo/crc.h b/bertos/algo/crc.h index 81a0c926..9696e4f1 100644 --- a/bertos/algo/crc.h +++ b/bertos/algo/crc.h @@ -31,7 +31,7 @@ * * --> * - * \brief Cyclic Redundancy Check 16 (CRC). + * \brief Cyclic Redundancy Check 16 (CRC). This algorithm is the one used by the XMODEM protocol. * * \note This algorithm is incompatible with the CCITT-CRC16. * @@ -55,14 +55,10 @@ #include #include - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - +EXTERN_C_BEGIN /* CRC table */ -const uint16_t crc16tab[256]; +extern const uint16_t crc16tab[256]; /** @@ -74,12 +70,14 @@ const uint16_t crc16tab[256]; * \param c New octet (range 0-255) * \param oldcrc Previous CRC16 value (referenced twice, beware of side effects) */ -#if CPU_AVR +#if CPU_HARVARD #define UPDCRC16(c, oldcrc) (pgm_read_uint16_t(&crc16tab[((oldcrc) >> 8) ^ ((unsigned char)(c))]) ^ ((oldcrc) << 8)) #else #define UPDCRC16(c, oldcrc) ((crc16tab[((oldcrc) >> 8) ^ ((unsigned char)(c))]) ^ ((oldcrc) << 8)) #endif +/** CRC-16 init value */ +#define CRC16_INIT_VAL ((uint16_t)0) #ifdef INLINE /** @@ -87,7 +85,7 @@ const uint16_t crc16tab[256]; */ INLINE uint16_t updcrc16(uint8_t c, uint16_t oldcrc) { -#if CPU_AVR +#if CPU_HARVARD return pgm_read_uint16_t(&crc16tab[(oldcrc >> 8) ^ c]) ^ (oldcrc << 8); #else return crc16tab[(oldcrc >> 8) ^ c] ^ (oldcrc << 8); @@ -107,8 +105,10 @@ INLINE uint16_t updcrc16(uint8_t c, uint16_t oldcrc) */ extern uint16_t crc16(uint16_t crc, const void *buf, size_t len); -#ifdef __cplusplus -} -#endif /* __cplusplus */ +int crc_testSetup(void); +int crc_testRun(void); +int crc_testTearDown(void); + +EXTERN_C_END #endif /* ALGO_CRC_H */