/** * \file * * * \brief CCITT Cyclic Redundancy Check (CRC-CCITT). * * \note This algorithm is incompatible with the CRC16. * * \author Francesco Sacchi * * $WIZ$ module_name = "crc-ccitt" */ #ifndef ALGO_CRC_CCITT_H #define ALGO_CRC_CCITT_H #include #include EXTERN_C_BEGIN /* CRC table */ extern const uint16_t crc_ccitt_tab[256]; /** * \brief Compute the updated CRC-CCITT value for one octet (inline version) */ INLINE uint16_t updcrc_ccitt(uint8_t c, uint16_t oldcrc) { return (oldcrc >> 8) ^ pgm_read16(&crc_ccitt_tab[(oldcrc ^ c) & 0xff]); } /** CRC-CCITT init value */ #define CRC_CCITT_INIT_VAL ((uint16_t)0xFFFF) /** * This function implements the CRC-CCITT calculation on a buffer. * * \param crc Current CRC-CCITT value. * \param buf The buffer to perform CRC calculation on. * \param len The length of the Buffer. * * \return The updated CRC-CCITT value. */ extern uint16_t crc_ccitt(uint16_t crc, const void *buf, size_t len); EXTERN_C_END #endif /* ALGO_CRC_CCITT_H */