Firmware SDK
twr_crc.c
1 #include <twr_crc.h>
2 
3 uint8_t twr_crc8(const uint8_t polynomial, const void *buffer, size_t length, const uint8_t initialization)
4 {
5  uint8_t crc = initialization;
6  uint8_t *_buffer = (uint8_t *) buffer;
7 
8  while (length--)
9  {
10  crc ^= *_buffer++;
11 
12  for ( int i = 8; i; --i )
13  {
14  crc = ( crc & 0x80 )
15  ? (crc << 1) ^ polynomial
16  : (crc << 1);
17  }
18  }
19  return crc;
20 }
uint8_t twr_crc8(const uint8_t polynomial, const void *buffer, size_t length, const uint8_t initialization)
Calculate CRC8.
Definition: twr_crc.c:3