2013-07-07 17:35:35 -06:00
|
|
|
/****************************************************************************
|
2022-08-12 14:13:41 +08:00
|
|
|
* include/nuttx/crc16.h
|
2013-07-07 17:35:35 -06:00
|
|
|
*
|
2024-10-02 15:59:15 +02:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*
|
2021-02-03 11:33:49 +01:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
|
* License. You may obtain a copy of the License at
|
2013-07-07 17:35:35 -06:00
|
|
|
*
|
2021-02-03 11:33:49 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2013-07-07 17:35:35 -06:00
|
|
|
*
|
2021-02-03 11:33:49 +01:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
|
* under the License.
|
2013-07-07 17:35:35 -06:00
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2022-08-12 14:13:41 +08:00
|
|
|
#ifndef __INCLUDE_NUTTX_CRC16_H
|
|
|
|
|
#define __INCLUDE_NUTTX_CRC16_H
|
2013-07-07 17:35:35 -06:00
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Included Files
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
2022-08-14 16:59:35 +08:00
|
|
|
/****************************************************************************
|
|
|
|
|
* Pre-processor Definitions
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
/* Append full suffix to avoid the penitential symbol collision */
|
|
|
|
|
|
|
|
|
|
#define crc16 crc16full
|
|
|
|
|
|
2013-07-07 17:35:35 -06:00
|
|
|
/****************************************************************************
|
|
|
|
|
* Public Function Prototypes
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
#define EXTERN extern "C"
|
|
|
|
|
extern "C"
|
|
|
|
|
{
|
|
|
|
|
#else
|
|
|
|
|
#define EXTERN extern
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Name: crc16part
|
|
|
|
|
*
|
|
|
|
|
* Description:
|
|
|
|
|
* Continue CRC calculation on a part of the buffer.
|
|
|
|
|
*
|
2025-04-07 12:26:49 +08:00
|
|
|
* The default polynomial is 0x1021 (x^16 + x^12 + x^5 + 1)
|
|
|
|
|
* See crc16xmodempart()
|
|
|
|
|
*
|
2013-07-07 17:35:35 -06:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
uint16_t crc16part(FAR const uint8_t *src, size_t len, uint16_t crc16val);
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Name: crc16
|
|
|
|
|
*
|
|
|
|
|
* Description:
|
|
|
|
|
* Return a 16-bit CRC of the contents of the 'src' buffer, length 'len'
|
|
|
|
|
*
|
2025-04-07 12:26:49 +08:00
|
|
|
* The default polynomial is 0x1021 (x^16 + x^12 + x^5 + 1)
|
|
|
|
|
* See crc16xmodem()
|
|
|
|
|
*
|
2013-07-07 17:35:35 -06:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
uint16_t crc16(FAR const uint8_t *src, size_t len);
|
|
|
|
|
|
2022-12-13 16:34:51 +08:00
|
|
|
/****************************************************************************
|
|
|
|
|
* Name: crc16ccittpart
|
|
|
|
|
*
|
|
|
|
|
* Description:
|
|
|
|
|
* Continue 16-bit CRC-CCITT calculation on a part of the buffer using the
|
|
|
|
|
* polynomial x^16+x^12+x^5+1.
|
|
|
|
|
*
|
2025-04-06 18:54:30 +08:00
|
|
|
* This function is able to calculate any CRC that uses 0x1021 as it
|
|
|
|
|
* polynomial and requires reflecting both the input and the output.
|
|
|
|
|
* The following checksums can, among others, be calculated by this
|
|
|
|
|
* function, depending on the value provided for the initial seed and the
|
|
|
|
|
* value the final calculated CRC is XORed with:
|
|
|
|
|
*
|
|
|
|
|
* - CRC-16/CCITT, CRC-16/CCITT-TRUE, CRC-16/KERMIT
|
|
|
|
|
* https://reveng.sourceforge.io/crc-catalogue/16.htm#crc.cat.crc-16-kermit
|
|
|
|
|
* initial seed: 0x0000, xor output: 0x0000
|
|
|
|
|
*
|
2022-12-13 16:34:51 +08:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
uint16_t crc16ccittpart(FAR const uint8_t *src, size_t len,
|
|
|
|
|
uint16_t crc16val);
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Name: crc16ccitt
|
|
|
|
|
*
|
|
|
|
|
* Description:
|
|
|
|
|
* Return a 16-bit CRC-CCITT of the contents of the 'src' buffer, length
|
|
|
|
|
* 'len' using the polynomial x^16+x^12+x^5+1.
|
|
|
|
|
*
|
2025-04-06 18:54:30 +08:00
|
|
|
* This function is able to calculate any CRC that uses 0x1021 as it
|
|
|
|
|
* polynomial and requires reflecting both the input and the output.
|
|
|
|
|
* The following checksums can, among others, be calculated by this
|
|
|
|
|
* function, depending on the value provided for the initial seed and the
|
|
|
|
|
* value the final calculated CRC is XORed with:
|
|
|
|
|
*
|
|
|
|
|
* - CRC-16/CCITT, CRC-16/CCITT-TRUE, CRC-16/KERMIT
|
|
|
|
|
* https://reveng.sourceforge.io/crc-catalogue/16.htm#crc.cat.crc-16-kermit
|
|
|
|
|
* initial seed: 0x0000, xor output: 0x0000
|
|
|
|
|
*
|
2022-12-13 16:34:51 +08:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
uint16_t crc16ccitt(FAR const uint8_t *src, size_t len);
|
|
|
|
|
|
2025-04-06 19:39:44 +08:00
|
|
|
/****************************************************************************
|
|
|
|
|
* Name: crc16ibm
|
|
|
|
|
*
|
|
|
|
|
* Description:
|
|
|
|
|
* Return a 16-bit CRC-ANSI of the contents of the 'src' buffer, length
|
|
|
|
|
* 'len' using the polynomial 0x8005 (x^16 + x^15 + x^2 + 1).
|
|
|
|
|
*
|
|
|
|
|
* The ANSI variant of CRC-16 uses 0x8005 (0xA001 reflected) as its
|
|
|
|
|
* polynomial with the initial * value set to 0x0000.
|
|
|
|
|
*
|
|
|
|
|
* The following checksums can, among others, be calculated by this
|
|
|
|
|
* function, depending on the value provided for the initial seed and
|
|
|
|
|
* the value the final calculated CRC is XORed with:
|
|
|
|
|
*
|
|
|
|
|
* - ARC, CRC-16, CRC-16/LHA, CRC-IBM
|
|
|
|
|
* https://reveng.sourceforge.io/crc-catalogue/16.htm#crc.cat.crc-16-arc
|
|
|
|
|
* poly: 0x8005 (0xA001) initial seed: 0x0000, xor output: 0x0000
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
uint16_t crc16ibmpart(FAR const uint8_t *src, size_t len,
|
|
|
|
|
uint16_t crc16val);
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Name: crc16ibm
|
|
|
|
|
*
|
|
|
|
|
* Description:
|
|
|
|
|
* Return a 16-bit CRC-ANSI of the contents of the 'src' buffer, length
|
|
|
|
|
* 'len' using the polynomial 0x8005 (x^16 + x^15 + x^2 + 1).
|
|
|
|
|
*
|
|
|
|
|
* The ANSI variant of CRC-16 uses 0x8005 (0xA001 reflected) as its
|
|
|
|
|
* polynomial with the initial * value set to 0x0000.
|
|
|
|
|
*
|
|
|
|
|
* The following checksums can, among others, be calculated by this
|
|
|
|
|
* function, depending on the value provided for the initial seed and
|
|
|
|
|
* the value the final calculated CRC is XORed with:
|
|
|
|
|
*
|
|
|
|
|
* - ARC, CRC-16, CRC-16/LHA, CRC-IBM
|
|
|
|
|
* https://reveng.sourceforge.io/crc-catalogue/16.htm#crc.cat.crc-16-arc
|
|
|
|
|
* poly: 0x8005 (0xA001) initial seed: 0x0000, xor output: 0x0000
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
uint16_t crc16ibm(FAR const uint8_t *src, size_t len);
|
|
|
|
|
|
2025-04-07 12:26:49 +08:00
|
|
|
/****************************************************************************
|
|
|
|
|
* Name: crc16xmodempart
|
|
|
|
|
*
|
|
|
|
|
* Description:
|
|
|
|
|
* Continue CRC calculation on a part of the buffer.
|
|
|
|
|
*
|
|
|
|
|
* Return a 16-bit CRC-XMODEM of the contents of the 'src' buffer, length
|
|
|
|
|
* 'len', using the polynomial 0x1021 (x^16 + x^12 + x^5 + 1).
|
|
|
|
|
*
|
|
|
|
|
* The following checksums can, among others, be calculated by this
|
|
|
|
|
* function, depending on the value provided for the initial seed and
|
|
|
|
|
* the value the final calculated CRC is XORed with:
|
|
|
|
|
*
|
|
|
|
|
* - Alias: CRC-16/ACORN, CRC-16/LTE, CRC-16/V-41-MSB, XMODEM, ZMODEM
|
|
|
|
|
* https://reveng.sourceforge.io/crc-catalogue/16.htm#crc.cat.crc-16-xmodem
|
|
|
|
|
* poly: 0x1021 initial seed: 0x0000, xor output: 0x0000
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
uint16_t crc16xmodempart(FAR const uint8_t *src, size_t len,
|
|
|
|
|
uint16_t crc16val);
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Name: crc16xmodem
|
|
|
|
|
*
|
|
|
|
|
* Description:
|
|
|
|
|
* Return a 16-bit CRC-XMODEM of the contents of the 'src' buffer, length
|
|
|
|
|
* 'len', using the polynomial 0x1021 (x^16 + x^12 + x^5 + 1).
|
|
|
|
|
*
|
|
|
|
|
* The following checksums can, among others, be calculated by this
|
|
|
|
|
* function, depending on the value provided for the initial seed and
|
|
|
|
|
* the value the final calculated CRC is XORed with:
|
|
|
|
|
*
|
|
|
|
|
* - Alias: CRC-16/ACORN, CRC-16/LTE, CRC-16/V-41-MSB, XMODEM, ZMODEM
|
|
|
|
|
* https://reveng.sourceforge.io/crc-catalogue/16.htm#crc.cat.crc-16-xmodem
|
|
|
|
|
* poly: 0x1021 initial seed: 0x0000, xor output: 0x0000
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
uint16_t crc16xmodem(FAR const uint8_t *src, size_t len);
|
|
|
|
|
|
2013-07-07 17:35:35 -06:00
|
|
|
#undef EXTERN
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2022-08-12 14:13:41 +08:00
|
|
|
#endif /* __INCLUDE_NUTTX_CRC16_H */
|