forked from iRobotEducation/root-robot-ble-protocol
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrc.c
42 lines (40 loc) · 1006 Bytes
/
crc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/**
* \file
* Functions and types for CRC checks.
*
* Generated on Thu Sep 27 11:30:10 2018
* by pycrc v0.9.1, https://pycrc.org
* using the configuration:
* - Width = 8
* - Poly = 0x07
* - XorIn = 0x00
* - ReflectIn = False
* - XorOut = 0x00
* - ReflectOut = False
* - Algorithm = bit-by-bit-fast
*/
#include "crc.h" /* include the header file generated with pycrc */
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
crc_t crc_update(crc_t crc, const void *data, size_t data_len) {
const unsigned char *d = (const unsigned char *)data;
unsigned int i;
bool bit;
unsigned char c;
while (data_len--) {
c = *d++;
for (i = 0x80; i > 0; i >>= 1) {
bit = crc & 0x80;
if (c & i) {
bit = !bit;
}
crc <<= 1;
if (bit) {
crc ^= 0x07;
}
}
crc &= 0xff;
}
return crc & 0xff;
}