X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=bertos%2Falgo%2Fcrc.h;h=c5c1eefddb5b161061bb66e9c7e4d53385f91ef0;hb=e25def702d296525e367cad3f0fafc743627e3a2;hp=d6a1f45de21ca688c7b83615d3287b15a85a4a9a;hpb=791e167e053bdd9250d34a9a5ccae6ccde4d6679;p=bertos.git diff --git a/bertos/algo/crc.h b/bertos/algo/crc.h index d6a1f45d..c5c1eefd 100644 --- a/bertos/algo/crc.h +++ b/bertos/algo/crc.h @@ -27,11 +27,11 @@ * the GNU General Public License. * * Copyright 2003, 2004 Develer S.r.l. (http://www.develer.com/) - * Copyright 1999 Bernardo Innocenti + * Copyright 1999 Bernie Innocenti * * --> * - * \brief XModem-CRC16 algorithm (interface) + * \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. * @@ -43,19 +43,20 @@ * to Stephen Satchell, Satchell Evaluations and Chuck Forsberg, * Omen Technology. * - * \version $Id$ - * \author Bernardo Innocenti + * \author Bernie Innocenti + * + * $WIZ$ module_name = "crc16" */ #ifndef ALGO_CRC_H #define ALGO_CRC_H -#include +#include "cfg/cfg_arch.h" -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ +#include +#include +EXTERN_C_BEGIN /* CRC table */ extern const uint16_t crc16tab[256]; @@ -70,16 +71,26 @@ extern const uint16_t crc16tab[256]; * \param c New octet (range 0-255) * \param oldcrc Previous CRC16 value (referenced twice, beware of side effects) */ -#define UPDCRC16(c, oldcrc) (crc16tab[((oldcrc) >> 8) ^ ((unsigned char)(c))] ^ ((oldcrc) << 8)) +#if CPU_HARVARD && !(defined(ARCH_BOOT) && (ARCH & ARCH_BOOT)) + #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 /** - * \brief Compute the updated CRC16 value for one octet (macro version) + * \brief Compute the updated CRC16 value for one octet (inline version) */ INLINE uint16_t updcrc16(uint8_t c, uint16_t oldcrc) { +#if CPU_HARVARD && !(defined(ARCH_BOOT) && (ARCH & ARCH_BOOT)) + return pgm_read_uint16_t(&crc16tab[(oldcrc >> 8) ^ c]) ^ (oldcrc << 8); +#else return crc16tab[(oldcrc >> 8) ^ c] ^ (oldcrc << 8); +#endif } #endif // INLINE @@ -95,8 +106,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 */