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.
crc8_nibble.cpp
Go to the documentation of this file.
1 
20 #if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_SAMD)
21  #include <avr/pgmspace.h>
22 #else
23  #include <pgmspace.h>
24 #endif
25 #include "crc8_nibble.hpp" // header file converted by AceCRC
26 #include <stdlib.h>
27 #include <stdint.h>
28 
29 namespace ace_crc {
30 namespace crc8_nibble {
31 
32 
33 
37 static const crc_t crc_table[16] PROGMEM = {
38  0x00, 0x07, 0x0e, 0x09, 0x1c, 0x1b, 0x12, 0x15, 0x38, 0x3f, 0x36, 0x31, 0x24, 0x23, 0x2a, 0x2d
39 };
40 
41 
42 crc_t crc_update(crc_t crc, const void *data, size_t data_len)
43 {
44  const unsigned char *d = (const unsigned char *)data;
45  uint8_t tbl_idx;
46 
47  while (data_len--) {
48  tbl_idx = (crc >> 4) ^ (*d >> 4);
49  crc = (pgm_read_byte(crc_table + (tbl_idx & 0x0f))) ^ (crc << 4);
50  tbl_idx = (crc >> 4) ^ (*d >> 0);
51  crc = (pgm_read_byte(crc_table + (tbl_idx & 0x0f))) ^ (crc << 4);
52  d++;
53  }
54  return crc & 0xff;
55 }
56 
57 } // crc8_nibble
58 } // ace_crc
uint16_t crc_t
The type of the CRC values.
Functions and types for CRC checks.
uint8_t crc_t
The type of the CRC values.
Definition: crc8_nibble.hpp:68