2021-01-23 11:39:57 +01:00
|
|
|
/*
|
|
|
|
* CRC16 (CCITT) Checksum Algorithm
|
|
|
|
*
|
|
|
|
* Copyright (c) 2021 Wind River Systems, Inc.
|
|
|
|
*
|
|
|
|
* Author:
|
|
|
|
* Bin Meng <bin.meng@windriver.com>
|
|
|
|
*
|
|
|
|
* From Linux kernel v5.10 include/linux/crc-ccitt.h
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-2.0
|
|
|
|
*/
|
|
|
|
|
2022-05-06 15:49:09 +02:00
|
|
|
#ifndef CRC_CCITT_H
|
|
|
|
#define CRC_CCITT_H
|
2021-01-23 11:39:57 +01:00
|
|
|
|
|
|
|
extern uint16_t const crc_ccitt_table[256];
|
|
|
|
extern uint16_t const crc_ccitt_false_table[256];
|
|
|
|
|
|
|
|
extern uint16_t crc_ccitt(uint16_t crc, const uint8_t *buffer, size_t len);
|
|
|
|
extern uint16_t crc_ccitt_false(uint16_t crc, const uint8_t *buffer, size_t len);
|
|
|
|
|
|
|
|
static inline uint16_t crc_ccitt_byte(uint16_t crc, const uint8_t c)
|
|
|
|
{
|
|
|
|
return (crc >> 8) ^ crc_ccitt_table[(crc ^ c) & 0xff];
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint16_t crc_ccitt_false_byte(uint16_t crc, const uint8_t c)
|
|
|
|
{
|
|
|
|
return (crc << 8) ^ crc_ccitt_false_table[(crc >> 8) ^ c];
|
|
|
|
}
|
|
|
|
|
2022-05-06 15:49:09 +02:00
|
|
|
#endif /* CRC_CCITT_H */
|