blob: 7a5124901847f32af32fba7eb0a44e3f2d30488a [file] [log] [blame]
Ingo Albrecht383134b2010-07-15 22:43:52 +02001/*
2 * This was copied from the linux kernel and adjusted for our types.
3 */
4/*
5 * crc16.h - CRC-16 routine
6 *
7 * Implements the standard CRC-16:
8 * Width 16
9 * Poly 0x8005 (x^16 + x^15 + x^2 + 1)
10 * Init 0
11 *
12 * Copyright (c) 2005 Ben Gardner <bgardner@wabtec.com>
13 *
14 * This source code is licensed under the GNU General Public License,
15 * Version 2. See the file COPYING for more details.
16 */
17
18#ifndef __CRC16_H
19#define __CRC16_H
20
21#include <stdint.h>
22
23#include <sys/types.h>
24
25extern uint16_t const crc16_table[256];
26
27extern uint16_t crc16(uint16_t crc, const uint8_t *buffer, size_t len);
28
29static inline uint16_t crc16_byte(uint16_t crc, const uint8_t data)
30{
31 return (crc >> 8) ^ crc16_table[(crc ^ data) & 0xff];
32}
33
34#endif /* __CRC16_H */