4 * Copyright 2003, 2004 Develer S.r.l. (http://www.develer.com/)
5 * Copyright 1999 Bernardo Innocenti <bernie@develer.com>
6 * This file is part of DevLib - See README.devlib for information.
9 * \brief XModem-CRC16 algorithm (interface)
11 * \note This algorithm is incompatible with the CCITT-CRC16.
13 * This code is based on the article Copyright 1986 Stephen Satchell.
15 * Programmers may incorporate any or all code into their programs,
16 * giving proper credit within the source. Publication of the
17 * source routines is permitted so long as proper credit is given
18 * to Stephen Satchell, Satchell Evaluations and Chuck Forsberg,
22 * \author Bernardo Innocenti <bernie@develer.com>
27 *#* Revision 1.1 2007/06/07 09:09:41 batt
28 *#* Move crc routines to algos/.
30 *#* Revision 1.7 2006/07/19 12:56:27 bernie
31 *#* Convert to new Doxygen style.
33 *#* Revision 1.6 2005/11/04 16:20:02 bernie
34 *#* Fix reference to README.devlib in header.
36 *#* Revision 1.5 2005/04/11 19:10:28 bernie
37 *#* Include top-level headers from cfg/ subdir.
39 *#* Revision 1.4 2004/08/25 14:12:09 rasky
40 *#* Aggiornato il comment block dei log RCS
42 *#* Revision 1.3 2004/08/15 05:47:26 bernie
43 *#* updcrc16(): inline version of UPDCRC16(); Cleanup documentation.
45 *#* Revision 1.2 2004/06/03 11:27:09 bernie
46 *#* Add dual-license information.
48 *#* Revision 1.1 2004/06/03 08:58:16 bernie
49 *#* Import into DevLib
55 #include <cfg/compiler.h>
59 #endif /* __cplusplus */
63 extern const uint16_t crc16tab[256];
67 * \brief Compute the updated CRC16 value for one octet (macro version)
69 * \note This version is only intended for old/broken compilers.
70 * Use the inline function in new code.
72 * \param c New octet (range 0-255)
73 * \param oldcrc Previous CRC16 value (referenced twice, beware of side effects)
75 #define UPDCRC16(c, oldcrc) (crc16tab[((oldcrc) >> 8) ^ ((unsigned char)(c))] ^ ((oldcrc) << 8))
80 * \brief Compute the updated CRC16 value for one octet (macro version)
82 INLINE uint16_t updcrc16(uint8_t c, uint16_t oldcrc)
84 return crc16tab[(oldcrc >> 8) ^ c] ^ (oldcrc << 8);
90 * This function implements the CRC 16 calculation on a buffer.
92 * \param crc Current CRC16 value.
93 * \param buf The buffer to perform CRC calculation on.
94 * \param len The length of the Buffer.
96 * \return The updated CRC16 value.
98 extern uint16_t crc16(uint16_t crc, const void *buf, size_t len);
102 #endif /* __cplusplus */