2017-12-13 21:57:38 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2017 Nordic Semiconductor ASA
|
|
|
|
* Copyright (c) 2015 Runtime Inc
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
2018-03-11 05:20:18 +08:00
|
|
|
#include <crc8.h>
|
2017-12-13 21:57:38 +08:00
|
|
|
|
2018-09-29 17:38:54 +08:00
|
|
|
static const u8_t crc8_ccitt_small_table[16] = {
|
2017-12-13 21:57:38 +08:00
|
|
|
0x00, 0x07, 0x0e, 0x09, 0x1c, 0x1b, 0x12, 0x15,
|
|
|
|
0x38, 0x3f, 0x36, 0x31, 0x24, 0x23, 0x2a, 0x2d
|
|
|
|
};
|
|
|
|
|
2018-03-11 05:20:18 +08:00
|
|
|
u8_t crc8_ccitt(u8_t val, const void *buf, size_t cnt)
|
2017-12-13 21:57:38 +08:00
|
|
|
{
|
|
|
|
int i;
|
2018-03-11 05:20:18 +08:00
|
|
|
const u8_t *p = buf;
|
2017-12-13 21:57:38 +08:00
|
|
|
|
|
|
|
for (i = 0; i < cnt; i++) {
|
|
|
|
val ^= p[i];
|
|
|
|
val = (val << 4) ^ crc8_ccitt_small_table[val >> 4];
|
|
|
|
val = (val << 4) ^ crc8_ccitt_small_table[val >> 4];
|
|
|
|
}
|
|
|
|
return val;
|
|
|
|
}
|