From 4e2f6eabb34b3a50bdbdb13204f0fff2be352714 Mon Sep 17 00:00:00 2001 From: chao an Date: Sun, 6 Apr 2025 18:54:30 +0800 Subject: [PATCH] libs/libc/crc16: add some comments for crc16ccitt The search table of ccitt should describe more algorithm details: - CRC-16/CCITT, CRC-16/CCITT-TRUE, CRC-16/KERMIT initial seed: 0x0000, xor output: 0x0000 : width=16 : poly=0x1021 : init=0x0000 : refin=true : refout=true : xorout=0x0000 : check=0x2189 : residue=0x0000 : name="CRC-16/KERMIT" https://reveng.sourceforge.io/crc-catalogue/16.htm#crc.cat.crc-16-kermit Signed-off-by: chao an --- include/nuttx/crc16.h | 20 ++++++++++++++++++++ libs/libc/misc/lib_crc16ccitt.c | 20 ++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/include/nuttx/crc16.h b/include/nuttx/crc16.h index 1caa6812d73..c5dd73971f5 100644 --- a/include/nuttx/crc16.h +++ b/include/nuttx/crc16.h @@ -77,6 +77,16 @@ uint16_t crc16(FAR const uint8_t *src, size_t len); * Continue 16-bit CRC-CCITT calculation on a part of the buffer using the * polynomial x^16+x^12+x^5+1. * + * 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 + * ****************************************************************************/ uint16_t crc16ccittpart(FAR const uint8_t *src, size_t len, @@ -89,6 +99,16 @@ uint16_t crc16ccittpart(FAR const uint8_t *src, size_t len, * 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. * + * 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 + * ****************************************************************************/ uint16_t crc16ccitt(FAR const uint8_t *src, size_t len); diff --git a/libs/libc/misc/lib_crc16ccitt.c b/libs/libc/misc/lib_crc16ccitt.c index e041d9ce4f7..21a574088b8 100644 --- a/libs/libc/misc/lib_crc16ccitt.c +++ b/libs/libc/misc/lib_crc16ccitt.c @@ -82,6 +82,16 @@ static uint16_t crc16ccitt_tab[256] = * Continue 16-bit CRC-CCITT calculation on a part of the buffer using the * polynomial x^16+x^12+x^5+1. * + * 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 + * ****************************************************************************/ uint16_t crc16ccittpart(FAR const uint8_t *src, size_t len, @@ -105,6 +115,16 @@ uint16_t crc16ccittpart(FAR const uint8_t *src, size_t len, * 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. * + * 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 + * ****************************************************************************/ uint16_t crc16ccitt(FAR const uint8_t *src, size_t len)