ModbusMaster
v2.0.1
Arduino library for communicating with Modbus slaves over RS232/485 (via RTU protocol).
crc16.h
Go to the documentation of this file.
1
20
/* Copyright (c) 2002, 2003, 2004 Marek Michalkiewicz
21
Copyright (c) 2005, 2007 Joerg Wunsch
22
Copyright (c) 2013 Dave Hylands
23
Copyright (c) 2013 Frederic Nadeau
24
Copyright (c) 2015 Doc Walker
25
All rights reserved.
26
27
Redistribution and use in source and binary forms, with or without
28
modification, are permitted provided that the following conditions are met:
29
30
* Redistributions of source code must retain the above copyright
31
notice, this list of conditions and the following disclaimer.
32
33
* Redistributions in binary form must reproduce the above copyright
34
notice, this list of conditions and the following disclaimer in
35
the documentation and/or other materials provided with the
36
distribution.
37
38
* Neither the name of the copyright holders nor the names of
39
contributors may be used to endorse or promote products derived
40
from this software without specific prior written permission.
41
42
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
43
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
45
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
46
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
47
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
48
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
49
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
50
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
51
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
52
POSSIBILITY OF SUCH DAMAGE. */
53
54
55
#ifndef _UTIL_CRC16_H_
56
#define _UTIL_CRC16_H_
57
58
71
static
uint16_t
crc16_update
(uint16_t crc, uint8_t a)
72
{
73
int
i;
74
75
crc ^= a;
76
for
(i = 0; i < 8; ++i)
77
{
78
if
(crc & 1)
79
crc = (crc >> 1) ^ 0xA001;
80
else
81
crc = (crc >> 1);
82
}
83
84
return
crc;
85
}
86
87
88
#endif
/* _UTIL_CRC16_H_ */
crc16_update
static uint16_t crc16_update(uint16_t crc, uint8_t a)
Processor-independent CRC-16 calculation.
Definition:
crc16.h:71
src
util
crc16.h
Generated by
1.8.12