AceCRC  1.1.0
Cyclic Redundancy Check (CRC) algorithms (e.g. crc16ccitt, crc32) programmatically converted from C99 code generated by pycrc (https://pycrc.org) to Arduino C++ using namespaces and PROGMEM flash memory.
crc16modbus_bit.cpp
Go to the documentation of this file.
1 
20 #include "crc16modbus_bit.hpp" // header file converted by AceCRC
21 #include <stdlib.h>
22 #include <stdint.h>
23 #include <stdbool.h>
24 
25 namespace ace_crc {
26 namespace crc16modbus_bit {
27 
28 
29 
30 crc_t crc_reflect(crc_t data, size_t data_len)
31 {
32  unsigned int i;
33  crc_t ret;
34 
35  ret = data & 0x01;
36  for (i = 1; i < data_len; i++) {
37  data >>= 1;
38  ret = (ret << 1) | (data & 0x01);
39  }
40  return ret;
41 }
42 
43 
44 crc_t crc_update(crc_t crc, const void *data, size_t data_len)
45 {
46  const unsigned char *d = (const unsigned char *)data;
47  uint8_t i;
48  crc_t bit;
49  unsigned char c;
50 
51  while (data_len--) {
52  c = *d++;
53  for (i = 0x01; i & 0xff; i <<= 1) {
54  bit = (crc & 0x8000) ^ ((c & i) ? 0x8000 : 0);
55  crc <<= 1;
56  if (bit) {
57  crc ^= 0x8005;
58  }
59  }
60  crc &= 0xffff;
61  }
62  return crc & 0xffff;
63 }
64 
65 } // crc16modbus_bit
66 } // ace_crc
crc_t crc_reflect(crc_t data, size_t data_len)
Reflect all bits of a data word of data_len bytes.
Functions and types for CRC checks.
uint16_t crc_t
The type of the CRC values.