diff --git a/include/crc.h b/include/crc.h index 4a955fbfcd8..3825b36c5cc 100644 --- a/include/crc.h +++ b/include/crc.h @@ -1,182 +1,15 @@ /* - * Copyright (c) 2018 Workaround GmbH. - * Copyright (c) 2017 Intel Corporation. - * Copyright (c) 2017 Nordic Semiconductor ASA - * Copyright (c) 2015 Runtime Inc - * Copyright (c) 2018 Google LLC. + * Copyright (c) 2019 Intel Corporation * * SPDX-License-Identifier: Apache-2.0 */ -/** @file - * @brief CRC computation function - */ - #ifndef ZEPHYR_INCLUDE_CRC_H_ #define ZEPHYR_INCLUDE_CRC_H_ -#include -#include -#include - -#ifdef __cplusplus -extern "C" { +#ifndef CONFIG_COMPAT_INCLUDES +#warning "This header file has moved, include instead." #endif -/* Initial value expected to be used at the beginning of the crc8_ccitt - * computation. - */ -#define CRC8_CCITT_INITIAL_VALUE 0xFF +#include -/** - * @defgroup checksum Checksum - */ - -/** - * @defgroup crc CRC - * @ingroup checksum - * @{ - */ - -/** - * @brief Generic function for computing CRC 16 - * - * Compute CRC 16 by passing in the address of the input, the input length - * and polynomial used in addition to the initial value. - * - * @param src Input bytes for the computation - * @param len Length of the input in bytes - * @param polynomial The polynomial to use omitting the leading x^16 - * coefficient - * @param initial_value Initial value for the CRC computation - * @param pad Adds padding with zeros at the end of input bytes - * - * @return The computed CRC16 value - */ -u16_t crc16(const u8_t *src, size_t len, u16_t polynomial, - u16_t initial_value, bool pad); - -/** - * @brief Compute the CRC-16/CCITT checksum of a buffer. - * - * See ITU-T Recommendation V.41 (November 1988). Uses 0x1021 as the - * polynomial, reflects the input, and reflects the output. - * - * To calculate the CRC across non-contiguous blocks use the return - * value from block N-1 as the seed for block N. - * - * For CRC-16/CCITT, use 0 as the initial seed. Other checksums in - * the same family can be calculated by changing the seed and/or - * XORing the final value. Examples include: - * - * - X-25 (used in PPP): seed=0xffff, xor=0xffff, residual=0xf0b8 - * - * @note API changed in Zephyr 1.11. - * - * @param seed Value to seed the CRC with - * @param src Input bytes for the computation - * @param len Length of the input in bytes - * - * @return The computed CRC16 value - */ -u16_t crc16_ccitt(u16_t seed, const u8_t *src, size_t len); - -/** - * @brief Compute the CRC-16/XMODEM checksum of a buffer. - * - * The MSB first version of ITU-T Recommendation V.41 (November 1988). - * Uses 0x1021 as the polynomial with no reflection. - * - * To calculate the CRC across non-contiguous blocks use the return - * value from block N-1 as the seed for block N. - * - * For CRC-16/XMODEM, use 0 as the initial seed. Other checksums in - * the same family can be calculated by changing the seed and/or - * XORing the final value. Examples include: - * - * - CCIITT-FALSE: seed=0xffff - * - GSM: seed=0, xorout=0xffff, residue=0x1d0f - * - * @param seed Value to seed the CRC with - * @param src Input bytes for the computation - * @param len Length of the input in bytes - * - * @return The computed CRC16 value - */ -u16_t crc16_itu_t(u16_t seed, const u8_t *src, size_t len); - -/** - * @brief Compute ANSI variant of CRC 16 - * - * ANSI variant of CRC 16 is using 0x8005 as its polynomial with the initial - * value set to 0xffff. - * - * @param src Input bytes for the computation - * @param len Length of the input in bytes - * - * @return The computed CRC16 value - */ -static inline u16_t crc16_ansi(const u8_t *src, size_t len) -{ - return crc16(src, len, 0x8005, 0xffff, true); -} - -/** - * @brief Generate IEEE conform CRC32 checksum. - * - * @param *data Pointer to data on which the CRC should be calculated. - * @param len Data length. - * - * @return CRC32 value. - * - */ -u32_t crc32_ieee(const u8_t *data, size_t len); - -/** - * @brief Update an IEEE conforming CRC32 checksum. - * - * @param crc CRC32 checksum that needs to be updated. - * @param *data Pointer to data on which the CRC should be calculated. - * @param len Data length. - * - * @return CRC32 value. - * - */ -u32_t crc32_ieee_update(u32_t crc, const u8_t *data, size_t len); - -/** - * @brief Compute CCITT variant of CRC 8 - * - * Normal CCITT variant of CRC 8 is using 0x07. - * - * @param initial_value Initial value for the CRC computation - * @param buf Input bytes for the computation - * @param len Length of the input in bytes - * - * @return The computed CRC8 value - */ -u8_t crc8_ccitt(u8_t initial_value, const void *buf, size_t len); - -/** - * @brief Compute the CRC-7 checksum of a buffer. - * - * See JESD84-A441. Used by the MMC protocol. Uses 0x09 as the - * polynomial with no reflection. The CRC is left - * justified, so bit 7 of the result is bit 6 of the CRC. - * - * @param seed Value to seed the CRC with - * @param src Input bytes for the computation - * @param len Length of the input in bytes - * - * @return The computed CRC7 value - */ -u8_t crc7_be(u8_t seed, const u8_t *src, size_t len); - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif +#endif /* ZEPHYR_INCLUDE_CRC_H_ */ diff --git a/include/sys/crc.h b/include/sys/crc.h new file mode 100644 index 00000000000..bf579789b89 --- /dev/null +++ b/include/sys/crc.h @@ -0,0 +1,182 @@ +/* + * Copyright (c) 2018 Workaround GmbH. + * Copyright (c) 2017 Intel Corporation. + * Copyright (c) 2017 Nordic Semiconductor ASA + * Copyright (c) 2015 Runtime Inc + * Copyright (c) 2018 Google LLC. + * + * SPDX-License-Identifier: Apache-2.0 + */ +/** @file + * @brief CRC computation function + */ + +#ifndef ZEPHYR_INCLUDE_SYS_CRC_H_ +#define ZEPHYR_INCLUDE_SYS_CRC_H_ + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* Initial value expected to be used at the beginning of the crc8_ccitt + * computation. + */ +#define CRC8_CCITT_INITIAL_VALUE 0xFF + +/** + * @defgroup checksum Checksum + */ + +/** + * @defgroup crc CRC + * @ingroup checksum + * @{ + */ + +/** + * @brief Generic function for computing CRC 16 + * + * Compute CRC 16 by passing in the address of the input, the input length + * and polynomial used in addition to the initial value. + * + * @param src Input bytes for the computation + * @param len Length of the input in bytes + * @param polynomial The polynomial to use omitting the leading x^16 + * coefficient + * @param initial_value Initial value for the CRC computation + * @param pad Adds padding with zeros at the end of input bytes + * + * @return The computed CRC16 value + */ +u16_t crc16(const u8_t *src, size_t len, u16_t polynomial, + u16_t initial_value, bool pad); + +/** + * @brief Compute the CRC-16/CCITT checksum of a buffer. + * + * See ITU-T Recommendation V.41 (November 1988). Uses 0x1021 as the + * polynomial, reflects the input, and reflects the output. + * + * To calculate the CRC across non-contiguous blocks use the return + * value from block N-1 as the seed for block N. + * + * For CRC-16/CCITT, use 0 as the initial seed. Other checksums in + * the same family can be calculated by changing the seed and/or + * XORing the final value. Examples include: + * + * - X-25 (used in PPP): seed=0xffff, xor=0xffff, residual=0xf0b8 + * + * @note API changed in Zephyr 1.11. + * + * @param seed Value to seed the CRC with + * @param src Input bytes for the computation + * @param len Length of the input in bytes + * + * @return The computed CRC16 value + */ +u16_t crc16_ccitt(u16_t seed, const u8_t *src, size_t len); + +/** + * @brief Compute the CRC-16/XMODEM checksum of a buffer. + * + * The MSB first version of ITU-T Recommendation V.41 (November 1988). + * Uses 0x1021 as the polynomial with no reflection. + * + * To calculate the CRC across non-contiguous blocks use the return + * value from block N-1 as the seed for block N. + * + * For CRC-16/XMODEM, use 0 as the initial seed. Other checksums in + * the same family can be calculated by changing the seed and/or + * XORing the final value. Examples include: + * + * - CCIITT-FALSE: seed=0xffff + * - GSM: seed=0, xorout=0xffff, residue=0x1d0f + * + * @param seed Value to seed the CRC with + * @param src Input bytes for the computation + * @param len Length of the input in bytes + * + * @return The computed CRC16 value + */ +u16_t crc16_itu_t(u16_t seed, const u8_t *src, size_t len); + +/** + * @brief Compute ANSI variant of CRC 16 + * + * ANSI variant of CRC 16 is using 0x8005 as its polynomial with the initial + * value set to 0xffff. + * + * @param src Input bytes for the computation + * @param len Length of the input in bytes + * + * @return The computed CRC16 value + */ +static inline u16_t crc16_ansi(const u8_t *src, size_t len) +{ + return crc16(src, len, 0x8005, 0xffff, true); +} + +/** + * @brief Generate IEEE conform CRC32 checksum. + * + * @param *data Pointer to data on which the CRC should be calculated. + * @param len Data length. + * + * @return CRC32 value. + * + */ +u32_t crc32_ieee(const u8_t *data, size_t len); + +/** + * @brief Update an IEEE conforming CRC32 checksum. + * + * @param crc CRC32 checksum that needs to be updated. + * @param *data Pointer to data on which the CRC should be calculated. + * @param len Data length. + * + * @return CRC32 value. + * + */ +u32_t crc32_ieee_update(u32_t crc, const u8_t *data, size_t len); + +/** + * @brief Compute CCITT variant of CRC 8 + * + * Normal CCITT variant of CRC 8 is using 0x07. + * + * @param initial_value Initial value for the CRC computation + * @param buf Input bytes for the computation + * @param len Length of the input in bytes + * + * @return The computed CRC8 value + */ +u8_t crc8_ccitt(u8_t initial_value, const void *buf, size_t len); + +/** + * @brief Compute the CRC-7 checksum of a buffer. + * + * See JESD84-A441. Used by the MMC protocol. Uses 0x09 as the + * polynomial with no reflection. The CRC is left + * justified, so bit 7 of the result is bit 6 of the CRC. + * + * @param seed Value to seed the CRC with + * @param src Input bytes for the computation + * @param len Length of the input in bytes + * + * @return The computed CRC7 value + */ +u8_t crc7_be(u8_t seed, const u8_t *src, size_t len); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib/os/crc16_sw.c b/lib/os/crc16_sw.c index e72e93f32c0..28181c821c2 100644 --- a/lib/os/crc16_sw.c +++ b/lib/os/crc16_sw.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include +#include u16_t crc16(const u8_t *src, size_t len, u16_t polynomial, u16_t initial_value, bool pad) diff --git a/lib/os/crc32_sw.c b/lib/os/crc32_sw.c index 52e263c31ad..7308c8ed18f 100644 --- a/lib/os/crc32_sw.c +++ b/lib/os/crc32_sw.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include +#include u32_t crc32_ieee(const u8_t *data, size_t len) { diff --git a/lib/os/crc7_sw.c b/lib/os/crc7_sw.c index 2906bafb1b1..381d747d679 100644 --- a/lib/os/crc7_sw.c +++ b/lib/os/crc7_sw.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include +#include u8_t crc7_be(u8_t seed, const u8_t *src, size_t len) { diff --git a/lib/os/crc8_sw.c b/lib/os/crc8_sw.c index d426579f184..3c4f30d357f 100644 --- a/lib/os/crc8_sw.c +++ b/lib/os/crc8_sw.c @@ -5,7 +5,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include +#include static const u8_t crc8_ccitt_small_table[16] = { 0x00, 0x07, 0x0e, 0x09, 0x1c, 0x1b, 0x12, 0x15, diff --git a/subsys/disk/disk_access_sdhc.c b/subsys/disk/disk_access_sdhc.c index 26c94b91db5..5981f6d3951 100644 --- a/subsys/disk/disk_access_sdhc.c +++ b/subsys/disk/disk_access_sdhc.c @@ -12,7 +12,7 @@ LOG_MODULE_REGISTER(sdhc, CONFIG_DISK_LOG_LEVEL); #include #include #include -#include +#include #define SDHC_SECTOR_SIZE 512 #define SDHC_CMD_SIZE 6 diff --git a/subsys/fs/fcb/fcb_elem_info.c b/subsys/fs/fcb/fcb_elem_info.c index a203d893917..bed424fb785 100644 --- a/subsys/fs/fcb/fcb_elem_info.c +++ b/subsys/fs/fcb/fcb_elem_info.c @@ -5,7 +5,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include +#include #include #include "fcb_priv.h" diff --git a/subsys/fs/nffs_fs.c b/subsys/fs/nffs_fs.c index ddea5e98031..98787202915 100644 --- a/subsys/fs/nffs_fs.c +++ b/subsys/fs/nffs_fs.c @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/subsys/fs/nvs/nvs.c b/subsys/fs/nvs/nvs.c index 5f190e622c2..42da021b450 100644 --- a/subsys/fs/nvs/nvs.c +++ b/subsys/fs/nvs/nvs.c @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include "nvs_priv.h" #include diff --git a/subsys/mgmt/serial_util.c b/subsys/mgmt/serial_util.c index 2a293df1c34..da526d53c6f 100644 --- a/subsys/mgmt/serial_util.c +++ b/subsys/mgmt/serial_util.c @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/tests/application_development/cpp/src/main.cpp b/tests/application_development/cpp/src/main.cpp index 8d197ae89cb..fa8e2efb8a2 100644 --- a/tests/application_development/cpp/src/main.cpp +++ b/tests/application_development/cpp/src/main.cpp @@ -18,8 +18,8 @@ #include #include #include -#include -#include +#include +#include #include #include