ae28e4d3253ea601b595c30d450530e3fe034179
[bertos.git] / mware / crc.h
1 /*!
2  * \file
3  * <!--
4  * Copyright 2003,2004 Develer S.r.l. (http://www.develer.com/)
5  * Copyright 1999 Bernardo Innocenti <bernie@develer.com>
6  * All rights reserved.
7  * -->
8  *
9  * \brief Definitions for CRC generator
10  * \version $Id$
11  *
12  * \author Bernardo Innocenti <bernie@develer.com>
13  */
14
15 /*
16  * $Log$
17  * Revision 1.1  2004/06/03 08:58:16  bernie
18  * Import into DevLib
19  *
20  */
21 #ifndef CRC_H
22 #define CRC_H
23
24 #ifdef __cplusplus
25 extern "C" {
26 #endif /* __cplusplus */
27
28 #include <stdint.h> // uint16_t
29 #include <stddef.h> // size_t
30
31 /* CRC table */
32 extern const uint16_t crc16tab[256];
33
34
35 /*!
36  * updcrc macro derived from article Copyright (C) 1986 Stephen Satchell.
37  * \note First argument must be in range 0 to 255.
38  * \note Second argument is referenced twice.
39  *
40  * Programmers may incorporate any or all code into their programs,
41  * giving proper credit within the source. Publication of the
42  * source routines is permitted so long as proper credit is given
43  * to Stephen Satchell, Satchell Evaluations and Chuck Forsberg,
44  * Omen Technology.
45  */
46 #define UPDCRC16(c, oldcrc) (crc16tab[((oldcrc) >> 8) ^ ((unsigned char)(c))] ^ ((oldcrc) << 8))
47
48 /*!
49  * This function implements the CRC 16 calculation on a buffer.
50  *
51  * \param crc  Current CRC16 value.
52  * \param buf  The buffer to perform CRC calculation on.
53  * \param len  The length of the Buffer.
54  *
55  * \return The updated CRC 16 value.
56  */
57 extern uint16_t crc16(uint16_t crc, const void *buf, size_t len);
58
59 #ifdef __cplusplus
60 }
61 #endif /* __cplusplus */
62
63 #endif /* CRC_H */