Add dual-license information.
[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  * This file is part of DevLib - See devlib/README for information.
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.2  2004/06/03 11:27:09  bernie
18  * Add dual-license information.
19  *
20  * Revision 1.1  2004/06/03 08:58:16  bernie
21  * Import into DevLib
22  *
23  */
24 #ifndef CRC_H
25 #define CRC_H
26
27 #ifdef __cplusplus
28 extern "C" {
29 #endif /* __cplusplus */
30
31 #include <stdint.h> // uint16_t
32 #include <stddef.h> // size_t
33
34 /* CRC table */
35 extern const uint16_t crc16tab[256];
36
37
38 /*!
39  * updcrc macro derived from article Copyright (C) 1986 Stephen Satchell.
40  * \note First argument must be in range 0 to 255.
41  * \note Second argument is referenced twice.
42  *
43  * Programmers may incorporate any or all code into their programs,
44  * giving proper credit within the source. Publication of the
45  * source routines is permitted so long as proper credit is given
46  * to Stephen Satchell, Satchell Evaluations and Chuck Forsberg,
47  * Omen Technology.
48  */
49 #define UPDCRC16(c, oldcrc) (crc16tab[((oldcrc) >> 8) ^ ((unsigned char)(c))] ^ ((oldcrc) << 8))
50
51 /*!
52  * This function implements the CRC 16 calculation on a buffer.
53  *
54  * \param crc  Current CRC16 value.
55  * \param buf  The buffer to perform CRC calculation on.
56  * \param len  The length of the Buffer.
57  *
58  * \return The updated CRC 16 value.
59  */
60 extern uint16_t crc16(uint16_t crc, const void *buf, size_t len);
61
62 #ifdef __cplusplus
63 }
64 #endif /* __cplusplus */
65
66 #endif /* CRC_H */