57 lines
2.4 KiB
C
57 lines
2.4 KiB
C
|
/**
|
||
|
* \file
|
||
|
* Functions and types for CRC checks.
|
||
|
*
|
||
|
* Generated on Sat May 12 09:39:22 2018
|
||
|
* by pycrc v0.9.1, https://pycrc.org
|
||
|
* using the configuration:
|
||
|
* - Width = 4
|
||
|
* - Poly = 0x3
|
||
|
* - XorIn = 0x0
|
||
|
* - ReflectIn = False
|
||
|
* - XorOut = 0x0
|
||
|
* - ReflectOut = False
|
||
|
* - Algorithm = table-driven
|
||
|
*/
|
||
|
#include "crc4itu.h" /* include the header file generated with pycrc */
|
||
|
#include <stdlib.h>
|
||
|
#include <stdint.h>
|
||
|
|
||
|
|
||
|
|
||
|
/**
|
||
|
* Static table used for the table_driven implementation.
|
||
|
*/
|
||
|
static const crc_t crc_table[256] = {
|
||
|
0x00, 0x03, 0x06, 0x05, 0x0c, 0x0f, 0x0a, 0x09, 0x0b, 0x08, 0x0d, 0x0e, 0x07, 0x04, 0x01, 0x02,
|
||
|
0x05, 0x06, 0x03, 0x00, 0x09, 0x0a, 0x0f, 0x0c, 0x0e, 0x0d, 0x08, 0x0b, 0x02, 0x01, 0x04, 0x07,
|
||
|
0x0a, 0x09, 0x0c, 0x0f, 0x06, 0x05, 0x00, 0x03, 0x01, 0x02, 0x07, 0x04, 0x0d, 0x0e, 0x0b, 0x08,
|
||
|
0x0f, 0x0c, 0x09, 0x0a, 0x03, 0x00, 0x05, 0x06, 0x04, 0x07, 0x02, 0x01, 0x08, 0x0b, 0x0e, 0x0d,
|
||
|
0x07, 0x04, 0x01, 0x02, 0x0b, 0x08, 0x0d, 0x0e, 0x0c, 0x0f, 0x0a, 0x09, 0x00, 0x03, 0x06, 0x05,
|
||
|
0x02, 0x01, 0x04, 0x07, 0x0e, 0x0d, 0x08, 0x0b, 0x09, 0x0a, 0x0f, 0x0c, 0x05, 0x06, 0x03, 0x00,
|
||
|
0x0d, 0x0e, 0x0b, 0x08, 0x01, 0x02, 0x07, 0x04, 0x06, 0x05, 0x00, 0x03, 0x0a, 0x09, 0x0c, 0x0f,
|
||
|
0x08, 0x0b, 0x0e, 0x0d, 0x04, 0x07, 0x02, 0x01, 0x03, 0x00, 0x05, 0x06, 0x0f, 0x0c, 0x09, 0x0a,
|
||
|
0x0e, 0x0d, 0x08, 0x0b, 0x02, 0x01, 0x04, 0x07, 0x05, 0x06, 0x03, 0x00, 0x09, 0x0a, 0x0f, 0x0c,
|
||
|
0x0b, 0x08, 0x0d, 0x0e, 0x07, 0x04, 0x01, 0x02, 0x00, 0x03, 0x06, 0x05, 0x0c, 0x0f, 0x0a, 0x09,
|
||
|
0x04, 0x07, 0x02, 0x01, 0x08, 0x0b, 0x0e, 0x0d, 0x0f, 0x0c, 0x09, 0x0a, 0x03, 0x00, 0x05, 0x06,
|
||
|
0x01, 0x02, 0x07, 0x04, 0x0d, 0x0e, 0x0b, 0x08, 0x0a, 0x09, 0x0c, 0x0f, 0x06, 0x05, 0x00, 0x03,
|
||
|
0x09, 0x0a, 0x0f, 0x0c, 0x05, 0x06, 0x03, 0x00, 0x02, 0x01, 0x04, 0x07, 0x0e, 0x0d, 0x08, 0x0b,
|
||
|
0x0c, 0x0f, 0x0a, 0x09, 0x00, 0x03, 0x06, 0x05, 0x07, 0x04, 0x01, 0x02, 0x0b, 0x08, 0x0d, 0x0e,
|
||
|
0x03, 0x00, 0x05, 0x06, 0x0f, 0x0c, 0x09, 0x0a, 0x08, 0x0b, 0x0e, 0x0d, 0x04, 0x07, 0x02, 0x01,
|
||
|
0x06, 0x05, 0x00, 0x03, 0x0a, 0x09, 0x0c, 0x0f, 0x0d, 0x0e, 0x0b, 0x08, 0x01, 0x02, 0x07, 0x04
|
||
|
};
|
||
|
|
||
|
|
||
|
crc_t crc4itu_update(crc_t crc, const void *data, size_t data_len)
|
||
|
{
|
||
|
const unsigned char *d = (const unsigned char *)data;
|
||
|
unsigned int tbl_idx;
|
||
|
|
||
|
while (data_len--) {
|
||
|
tbl_idx = (crc << 4) ^ *d;
|
||
|
crc = crc_table[tbl_idx] & 0xf;
|
||
|
d++;
|
||
|
}
|
||
|
return crc & 0xf;
|
||
|
}
|