diff --git a/3rdparty/libcrc/.gitignore b/3rdparty/libcrc/.gitignore new file mode 100644 index 000000000000..961438e7482d --- /dev/null +++ b/3rdparty/libcrc/.gitignore @@ -0,0 +1,21 @@ +*~ +.*.swp +lib/*.lib +lib/*.a +obj/*.obj +obj/*.o +test/obj/*.obj +test/obj/*.o +examples/obj/*.obj +examples/obj/*.o +precalc/obj/*.obj +precalc/obj/*.o +tab/gentab32.inc +tab/gentab64.inc +make.exe +testall.exe +testall +tstcrc.exe +tstcrc +bin/prc.exe +bin/prc diff --git a/3rdparty/libcrc/include/checksum.h b/3rdparty/libcrc/include/checksum.h new file mode 100644 index 000000000000..505f41292c52 --- /dev/null +++ b/3rdparty/libcrc/include/checksum.h @@ -0,0 +1,116 @@ +/* + * Library: libcrc + * File: include/checksum.h + * Author: Lammert Bies + * + * This file is licensed under the MIT License as stated below + * + * Copyright (c) 1999-2018 Lammert Bies + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * Description + * ----------- + * The headerfile include/checksum.h contains the definitions and prototypes + * for routines that can be used to calculate several kinds of checksums. + */ + +#ifndef DEF_LIBCRC_CHECKSUM_H +#define DEF_LIBCRC_CHECKSUM_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +/* + * #define CRC_POLY_xxxx + * + * The constants of the form CRC_POLY_xxxx define the polynomials for some well + * known CRC calculations. + */ + +#define CRC_POLY_16 0xA001 +#define CRC_POLY_32 0xEDB88320ul +#define CRC_POLY_64 0x42F0E1EBA9EA3693ull +#define CRC_POLY_CCITT 0x1021 +#define CRC_POLY_DNP 0xA6BC +#define CRC_POLY_KERMIT 0x8408 +#define CRC_POLY_SICK 0x8005 + +/* + * #define CRC_START_xxxx + * + * The constants of the form CRC_START_xxxx define the values that are used for + * initialization of a CRC value for common used calculation methods. + */ + +#define CRC_START_8 0x00 +#define CRC_START_16 0x0000 +#define CRC_START_MODBUS 0xFFFF +#define CRC_START_XMODEM 0x0000 +#define CRC_START_CCITT_1D0F 0x1D0F +#define CRC_START_CCITT_FFFF 0xFFFF +#define CRC_START_KERMIT 0x0000 +#define CRC_START_SICK 0x0000 +#define CRC_START_DNP 0x0000 +#define CRC_START_32 0xFFFFFFFFul +#define CRC_START_64_ECMA 0x0000000000000000ull +#define CRC_START_64_WE 0xFFFFFFFFFFFFFFFFull + +/* + * Prototype list of global functions + */ + +unsigned char* checksum_NMEA(const unsigned char* input_str, unsigned char* result); +uint8_t crc_8(const unsigned char* input_str, size_t num_bytes); +uint16_t crc_16(const unsigned char* input_str, size_t num_bytes); +uint32_t crc_32(const unsigned char* input_str, size_t num_bytes); +uint64_t crc_64_ecma(const unsigned char* input_str, size_t num_bytes); +uint64_t crc_64_we(const unsigned char* input_str, size_t num_bytes); +uint16_t crc_ccitt_1d0f(const unsigned char* input_str, size_t num_bytes); +uint16_t crc_ccitt_ffff(const unsigned char* input_str, size_t num_bytes); +uint16_t crc_dnp(const unsigned char* input_str, size_t num_bytes); +uint16_t crc_kermit(const unsigned char* input_str, size_t num_bytes); +uint16_t crc_modbus(const unsigned char* input_str, size_t num_bytes); +uint16_t crc_sick(const unsigned char* input_str, size_t num_bytes); +uint16_t crc_xmodem(const unsigned char* input_str, size_t num_bytes); +uint8_t update_crc_8(uint8_t crc, unsigned char c); +uint16_t update_crc_16(uint16_t crc, unsigned char c); +uint32_t update_crc_32(uint32_t crc, unsigned char c); +uint64_t update_crc_64_ecma(uint64_t crc, unsigned char c); +uint16_t update_crc_ccitt(uint16_t crc, unsigned char c); +uint16_t update_crc_dnp(uint16_t crc, unsigned char c); +uint16_t update_crc_kermit(uint16_t crc, unsigned char c); +uint16_t update_crc_sick(uint16_t crc, unsigned char c, unsigned char prev_byte); + +/* + * Global CRC lookup tables + */ + +extern const uint32_t crc_tab32[]; +extern const uint64_t crc_tab64[]; + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // DEF_LIBCRC_CHECKSUM_H diff --git a/3rdparty/libcrc/src/crcccitt.c b/3rdparty/libcrc/src/crcccitt.c new file mode 100644 index 000000000000..2b7ad3adb029 --- /dev/null +++ b/3rdparty/libcrc/src/crcccitt.c @@ -0,0 +1,119 @@ +/* + * Library: libcrc + * File: src/crcccitt.c + * Author: Lammert Bies + * + * This file is licensed under the MIT License as stated below + * + * Copyright (c) 1999-2016 Lammert Bies + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * Description + * ----------- + * The module src/crcccitt.c contains routines which are used to calculate the + * CCITT CRC values of a string of bytes. + */ + +#include +#include +#include + +#include "../tab/gentab_ccitt.inc" +#include "checksum.h" + +static uint16_t crc_ccitt_generic(const unsigned char* input_str, size_t num_bytes, + uint16_t start_value); + +/* + * uint16_t crc_xmodem( const unsigned char *input_str, size_t num_bytes ); + * + * The function crc_xmodem() performs a one-pass calculation of an X-Modem CRC + * for a byte string that has been passed as a parameter. + */ + +uint16_t crc_xmodem(const unsigned char* input_str, size_t num_bytes) { + return crc_ccitt_generic(input_str, num_bytes, CRC_START_XMODEM); + +} /* crc_xmodem */ + +/* + * uint16_t crc_ccitt_1d0f( const unsigned char *input_str, size_t num_bytes ); + * + * The function crc_ccitt_1d0f() performs a one-pass calculation of the CCITT + * CRC for a byte string that has been passed as a parameter. The initial value + * 0x1d0f is used for the CRC. + */ + +uint16_t crc_ccitt_1d0f(const unsigned char* input_str, size_t num_bytes) { + return crc_ccitt_generic(input_str, num_bytes, CRC_START_CCITT_1D0F); + +} /* crc_ccitt_1d0f */ + +/* + * uint16_t crc_ccitt_ffff( const unsigned char *input_str, size_t num_bytes ); + * + * The function crc_ccitt_ffff() performs a one-pass calculation of the CCITT + * CRC for a byte string that has been passed as a parameter. The initial value + * 0xffff is used for the CRC. + */ + +uint16_t crc_ccitt_ffff(const unsigned char* input_str, size_t num_bytes) { + return crc_ccitt_generic(input_str, num_bytes, CRC_START_CCITT_FFFF); + +} /* crc_ccitt_ffff */ + +/* + * static uint16_t crc_ccitt_generic( const unsigned char *input_str, size_t num_bytes, uint16_t + * start_value ); + * + * The function crc_ccitt_generic() is a generic implementation of the CCITT + * algorithm for a one-pass calculation of the CRC for a byte string. The + * function accepts an initial start value for the crc. + */ + +static uint16_t crc_ccitt_generic(const unsigned char* input_str, size_t num_bytes, + uint16_t start_value) { + uint16_t crc; + const unsigned char* ptr; + size_t a; + + crc = start_value; + ptr = input_str; + + if (ptr != NULL) + for (a = 0; a < num_bytes; a++) { + crc = (crc << 8) ^ crc_tabccitt[((crc >> 8) ^ (uint16_t)*ptr++) & 0x00FF]; + } + + return crc; + +} /* crc_ccitt_generic */ + +/* + * uint16_t update_crc_ccitt( uint16_t crc, unsigned char c ); + * + * The function update_crc_ccitt() calculates a new CRC-CCITT value based on + * the previous value of the CRC and the next byte of the data to be checked. + */ + +uint16_t update_crc_ccitt(uint16_t crc, unsigned char c) { + return (crc << 8) ^ crc_tabccitt[((crc >> 8) ^ (uint16_t)c) & 0x00FF]; + +} /* update_crc_ccitt */ diff --git a/3rdparty/libcrc/tab/gentab_ccitt.inc b/3rdparty/libcrc/tab/gentab_ccitt.inc new file mode 100644 index 000000000000..e3699471421a --- /dev/null +++ b/3rdparty/libcrc/tab/gentab_ccitt.inc @@ -0,0 +1,270 @@ +/* + * Library: libcrc + * File: tab/gentab_ccitt.inc + * Author: Auto generated by the precalc program + * + * PLEASE DO NOT CHANGE THIS FILE! + * =============================== + * This file was automatically generated and will be overwritten whenever the + * library is recompiled. All manually added changes will be lost in that case. + */ + +const uint16_t crc_tabccitt[256] = { + 0x0000u, + 0x1021u, + 0x2042u, + 0x3063u, + 0x4084u, + 0x50A5u, + 0x60C6u, + 0x70E7u, + 0x8108u, + 0x9129u, + 0xA14Au, + 0xB16Bu, + 0xC18Cu, + 0xD1ADu, + 0xE1CEu, + 0xF1EFu, + 0x1231u, + 0x0210u, + 0x3273u, + 0x2252u, + 0x52B5u, + 0x4294u, + 0x72F7u, + 0x62D6u, + 0x9339u, + 0x8318u, + 0xB37Bu, + 0xA35Au, + 0xD3BDu, + 0xC39Cu, + 0xF3FFu, + 0xE3DEu, + 0x2462u, + 0x3443u, + 0x0420u, + 0x1401u, + 0x64E6u, + 0x74C7u, + 0x44A4u, + 0x5485u, + 0xA56Au, + 0xB54Bu, + 0x8528u, + 0x9509u, + 0xE5EEu, + 0xF5CFu, + 0xC5ACu, + 0xD58Du, + 0x3653u, + 0x2672u, + 0x1611u, + 0x0630u, + 0x76D7u, + 0x66F6u, + 0x5695u, + 0x46B4u, + 0xB75Bu, + 0xA77Au, + 0x9719u, + 0x8738u, + 0xF7DFu, + 0xE7FEu, + 0xD79Du, + 0xC7BCu, + 0x48C4u, + 0x58E5u, + 0x6886u, + 0x78A7u, + 0x0840u, + 0x1861u, + 0x2802u, + 0x3823u, + 0xC9CCu, + 0xD9EDu, + 0xE98Eu, + 0xF9AFu, + 0x8948u, + 0x9969u, + 0xA90Au, + 0xB92Bu, + 0x5AF5u, + 0x4AD4u, + 0x7AB7u, + 0x6A96u, + 0x1A71u, + 0x0A50u, + 0x3A33u, + 0x2A12u, + 0xDBFDu, + 0xCBDCu, + 0xFBBFu, + 0xEB9Eu, + 0x9B79u, + 0x8B58u, + 0xBB3Bu, + 0xAB1Au, + 0x6CA6u, + 0x7C87u, + 0x4CE4u, + 0x5CC5u, + 0x2C22u, + 0x3C03u, + 0x0C60u, + 0x1C41u, + 0xEDAEu, + 0xFD8Fu, + 0xCDECu, + 0xDDCDu, + 0xAD2Au, + 0xBD0Bu, + 0x8D68u, + 0x9D49u, + 0x7E97u, + 0x6EB6u, + 0x5ED5u, + 0x4EF4u, + 0x3E13u, + 0x2E32u, + 0x1E51u, + 0x0E70u, + 0xFF9Fu, + 0xEFBEu, + 0xDFDDu, + 0xCFFCu, + 0xBF1Bu, + 0xAF3Au, + 0x9F59u, + 0x8F78u, + 0x9188u, + 0x81A9u, + 0xB1CAu, + 0xA1EBu, + 0xD10Cu, + 0xC12Du, + 0xF14Eu, + 0xE16Fu, + 0x1080u, + 0x00A1u, + 0x30C2u, + 0x20E3u, + 0x5004u, + 0x4025u, + 0x7046u, + 0x6067u, + 0x83B9u, + 0x9398u, + 0xA3FBu, + 0xB3DAu, + 0xC33Du, + 0xD31Cu, + 0xE37Fu, + 0xF35Eu, + 0x02B1u, + 0x1290u, + 0x22F3u, + 0x32D2u, + 0x4235u, + 0x5214u, + 0x6277u, + 0x7256u, + 0xB5EAu, + 0xA5CBu, + 0x95A8u, + 0x8589u, + 0xF56Eu, + 0xE54Fu, + 0xD52Cu, + 0xC50Du, + 0x34E2u, + 0x24C3u, + 0x14A0u, + 0x0481u, + 0x7466u, + 0x6447u, + 0x5424u, + 0x4405u, + 0xA7DBu, + 0xB7FAu, + 0x8799u, + 0x97B8u, + 0xE75Fu, + 0xF77Eu, + 0xC71Du, + 0xD73Cu, + 0x26D3u, + 0x36F2u, + 0x0691u, + 0x16B0u, + 0x6657u, + 0x7676u, + 0x4615u, + 0x5634u, + 0xD94Cu, + 0xC96Du, + 0xF90Eu, + 0xE92Fu, + 0x99C8u, + 0x89E9u, + 0xB98Au, + 0xA9ABu, + 0x5844u, + 0x4865u, + 0x7806u, + 0x6827u, + 0x18C0u, + 0x08E1u, + 0x3882u, + 0x28A3u, + 0xCB7Du, + 0xDB5Cu, + 0xEB3Fu, + 0xFB1Eu, + 0x8BF9u, + 0x9BD8u, + 0xABBBu, + 0xBB9Au, + 0x4A75u, + 0x5A54u, + 0x6A37u, + 0x7A16u, + 0x0AF1u, + 0x1AD0u, + 0x2AB3u, + 0x3A92u, + 0xFD2Eu, + 0xED0Fu, + 0xDD6Cu, + 0xCD4Du, + 0xBDAAu, + 0xAD8Bu, + 0x9DE8u, + 0x8DC9u, + 0x7C26u, + 0x6C07u, + 0x5C64u, + 0x4C45u, + 0x3CA2u, + 0x2C83u, + 0x1CE0u, + 0x0CC1u, + 0xEF1Fu, + 0xFF3Eu, + 0xCF5Du, + 0xDF7Cu, + 0xAF9Bu, + 0xBFBAu, + 0x8FD9u, + 0x9FF8u, + 0x6E17u, + 0x7E36u, + 0x4E55u, + 0x5E74u, + 0x2E93u, + 0x3EB2u, + 0x0ED1u, + 0x1EF0u +}; + diff --git a/3rdparty/mbed-os/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_11/libraries/crc16/crc16.c b/3rdparty/mbed-os/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_11/libraries/crc16/crc16.c deleted file mode 100644 index cf63a3c93bd2..000000000000 --- a/3rdparty/mbed-os/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_11/libraries/crc16/crc16.c +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2013 Nordic Semiconductor ASA - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list - * of conditions and the following disclaimer. - * - * 2. Redistributions in binary form, except as embedded into a Nordic Semiconductor ASA - * integrated circuit in a product or a software update for such product, must reproduce - * the above copyright notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of its contributors may be - * used to endorse or promote products derived from this software without specific prior - * written permission. - * - * 4. This software, with or without modification, must only be used with a - * Nordic Semiconductor ASA integrated circuit. - * - * 5. Any software provided in binary or object form under this license must not be reverse - * engineered, decompiled, modified and/or disassembled. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include "crc16.h" - -#include - -uint16_t crc16_compute(uint8_t const* p_data, uint32_t size, uint16_t const* p_crc) { - uint16_t crc = (p_crc == NULL) ? 0xFFFF : *p_crc; - - for (uint32_t i = 0; i < size; i++) { - crc = (uint8_t)(crc >> 8) | (crc << 8); - crc ^= p_data[i]; - crc ^= (uint8_t)(crc & 0xFF) >> 4; - crc ^= (crc << 8) << 4; - crc ^= ((crc & 0xFF) << 4) << 1; - } - - return crc; -} diff --git a/3rdparty/mbed-os/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_11/libraries/crc16/crc16.h b/3rdparty/mbed-os/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_11/libraries/crc16/crc16.h deleted file mode 100644 index d925880f6cca..000000000000 --- a/3rdparty/mbed-os/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_11/libraries/crc16/crc16.h +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (c) 2013 Nordic Semiconductor ASA - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list - * of conditions and the following disclaimer. - * - * 2. Redistributions in binary form, except as embedded into a Nordic Semiconductor ASA - * integrated circuit in a product or a software update for such product, must reproduce - * the above copyright notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of its contributors may be - * used to endorse or promote products derived from this software without specific prior - * written permission. - * - * 4. This software, with or without modification, must only be used with a - * Nordic Semiconductor ASA integrated circuit. - * - * 5. Any software provided in binary or object form under this license must not be reverse - * engineered, decompiled, modified and/or disassembled. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -/** @file - * - * @defgroup crc_compute CRC compute - * @{ - * @ingroup hci_transport - * - * @brief This module implements CRC-16-CCITT (polynomial 0x1021) with 0xFFFF initial value. - * The data can be passed in multiple blocks. - */ - -#ifndef CRC16_H__ -#define CRC16_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -/**@brief Function for calculating CRC-16 in blocks. - * - * Feed each consecutive data block into this function, along with the current value of p_crc as - * returned by the previous call of this function. The first call of this function should pass NULL - * as the initial value of the crc in p_crc. - * - * @param[in] p_data The input data block for computation. - * @param[in] size The size of the input data block in bytes. - * @param[in] p_crc The previous calculated CRC-16 value or NULL if first call. - * - * @return The updated CRC-16 value, based on the input supplied. - */ -uint16_t crc16_compute(uint8_t const* p_data, uint32_t size, uint16_t const* p_crc); - -#ifdef __cplusplus -} // extern "C" -#endif - -#endif // CRC16_H__ - -/** @} */ diff --git a/CMakeLists.txt b/CMakeLists.txt index e33d2ef463a3..d32cb98bc43d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -434,7 +434,7 @@ target_include_directories( target_include_directories( tvm_objs PUBLIC "topi/include") -set(CRC16_INCLUDE_PATH "3rdparty/mbed-os/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_11/libraries/crc16") +set(CRC16_INCLUDE_PATH "3rdparty/libcrc/include") target_include_directorieS( tvm_objs PRIVATE "${CRC16_INCLUDE_PATH}") diff --git a/LICENSE b/LICENSE index 1c7ab8205141..1314c16fa74f 100644 --- a/LICENSE +++ b/LICENSE @@ -212,7 +212,6 @@ Apache Software Foundation License 2.0 3rdparty/bfloat16/bfloat16.cc 3rdparty/dlpack 3rdparty/dmlc-core -3rdparty/mbed-os BSD 2-clause License @@ -231,6 +230,7 @@ BSD 2-clause License + zlib License MIT License ----------- +3rdparty/libcrc 3rdparty/cma 3rdparty/compiler-rt/builtin_fp16.h diff --git a/cmake/modules/StandaloneCrt.cmake b/cmake/modules/StandaloneCrt.cmake index 770c6a82789d..73c85d13e2ef 100644 --- a/cmake/modules/StandaloneCrt.cmake +++ b/cmake/modules/StandaloneCrt.cmake @@ -32,9 +32,10 @@ if(USE_MICRO) function(tvm_crt_define_targets) # Build an isolated build directory, separate from the TVM tree. - set(CRC16_PATH "3rdparty/mbed-os/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_11/libraries/crc16") list(APPEND CRT_FILE_COPY_JOBS - "${CRC16_PATH} *.h -> include *.c -> src/runtime/crt/utvm_rpc_common" + "3rdparty/libcrc/include *.h -> include" + "3rdparty/libcrc/src crcccitt.c -> src/runtime/crt/utvm_rpc_common" + "3rdparty/libcrc/tab gentab_ccitt.inc -> src/runtime/crt/tab" "3rdparty/dlpack/include *.h -> include" "3rdparty/dmlc-core/include *.h -> include" "include/tvm/runtime c_*_api.h -> include/tvm/runtime" diff --git a/include/tvm/runtime/crt/rpc_common/framing.h b/include/tvm/runtime/crt/rpc_common/framing.h index a6b9cd349088..32a0f56dab11 100644 --- a/include/tvm/runtime/crt/rpc_common/framing.h +++ b/include/tvm/runtime/crt/rpc_common/framing.h @@ -25,7 +25,6 @@ #ifndef TVM_RUNTIME_CRT_RPC_COMMON_FRAMING_H_ #define TVM_RUNTIME_CRT_RPC_COMMON_FRAMING_H_ -#include #include #include #include @@ -35,6 +34,8 @@ namespace tvm { namespace runtime { namespace micro_rpc { +uint16_t crc16_compute(const uint8_t* data, size_t data_size_bytes, uint16_t* previous_crc); + enum class Escape : uint8_t { kEscapeStart = 0xff, kEscapeNop = 0xfe, kPacketStart = 0xfd }; class PacketFieldSizeBytes { diff --git a/licenses/LICENSE.libcrc.txt b/licenses/LICENSE.libcrc.txt new file mode 100644 index 000000000000..0552660c4870 --- /dev/null +++ b/licenses/LICENSE.libcrc.txt @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 1999-2016 Lammert Bies + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/python/tvm/micro/build.py b/python/tvm/micro/build.py index 7b881db4c391..da0cc45cfeb6 100644 --- a/python/tvm/micro/build.py +++ b/python/tvm/micro/build.py @@ -60,10 +60,7 @@ def path(self): RUNTIME_LIB_SRC_DIRS = [os.path.join(CRT_ROOT_DIR, n) for n in CRT_RUNTIME_LIB_NAMES] + [ - os.path.join( - TVM_ROOT_DIR, - "3rdparty/mbed-os/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_11/" "libraries/crc16", - ) + os.path.join(TVM_ROOT_DIR, "3rdparty/libcrc/src") ] @@ -76,8 +73,7 @@ def path(self): "include_dirs": [ f"{TVM_ROOT_DIR}/include", f"{TVM_ROOT_DIR}/3rdparty/dlpack/include", - f"{TVM_ROOT_DIR}/3rdparty/mbed-os/targets/TARGET_NORDIC/TARGET_NRF5x/" - "TARGET_SDK_11/libraries/crc16/", + f"{TVM_ROOT_DIR}/3rdparty/libcrc/include", f"{TVM_ROOT_DIR}/3rdparty/dmlc-core/include", f"{CRT_ROOT_DIR}/include", ], diff --git a/src/runtime/crt/utvm_rpc_common/framing.cc b/src/runtime/crt/utvm_rpc_common/framing.cc index e40ea071f3dd..857ed2a23bec 100644 --- a/src/runtime/crt/utvm_rpc_common/framing.cc +++ b/src/runtime/crt/utvm_rpc_common/framing.cc @@ -22,6 +22,7 @@ * \brief Framing for RPC. */ +#include #include #include #include @@ -44,6 +45,15 @@ namespace tvm { namespace runtime { namespace micro_rpc { +uint16_t crc16_compute(const uint8_t* data, size_t data_size_bytes, uint16_t* previous_crc) { + uint16_t crc = (previous_crc != nullptr ? *previous_crc : 0xffff); + for (size_t i = 0; i < data_size_bytes; ++i) { + crc = update_crc_ccitt(crc, data[i]); + } + + return crc; +} + template static constexpr uint8_t to_integral(E e) { return static_cast(e); @@ -131,7 +141,7 @@ tvm_crt_error_t Unframer::ConsumeInput(uint8_t* buffer, size_t buffer_size_bytes // escape byte has already been parsed, update the CRC include only the escape byte. This // readies the unframer to consume the kPacketStart byte on the next Write() call. uint8_t escape_start = to_integral(Escape::kEscapeStart); - crc_ = crc16_compute(&escape_start, 1, NULL); + crc_ = crc16_compute(&escape_start, 1, nullptr); to_return = kTvmErrorFramingShortPacket; saw_escape_start_ = true; diff --git a/tests/crt/framing_test.cc b/tests/crt/framing_test.cc index ed3587b497cc..241e23d877cb 100644 --- a/tests/crt/framing_test.cc +++ b/tests/crt/framing_test.cc @@ -146,7 +146,7 @@ class UnframerTest : public ::testing::Test { TEST_F(UnframerTest, PacketTooLong) { const uint8_t escape[2] = {uint8_t(Escape::kEscapeStart), uint8_t(Escape::kPacketStart)}; - uint16_t crc = crc16_compute(escape, sizeof(escape), nullptr); + uint16_t crc = tvm::runtime::micro_rpc::crc16_compute(escape, sizeof(escape), nullptr); size_t bytes_consumed; EXPECT_EQ(kTvmErrorNoError, unframer_.Write(escape, sizeof(escape), &bytes_consumed)); EXPECT_EQ(sizeof(escape), bytes_consumed); @@ -156,7 +156,7 @@ TEST_F(UnframerTest, PacketTooLong) { for (size_t i = 0; i < sizeof(packet_length); i++) { ASSERT_NE('\xff', packet_length_bytes[i]); } - crc = crc16_compute(packet_length_bytes, sizeof(packet_length), &crc); + crc = tvm::runtime::micro_rpc::crc16_compute(packet_length_bytes, sizeof(packet_length), &crc); EXPECT_EQ(kTvmErrorNoError, unframer_.Write(packet_length_bytes, sizeof(packet_length), &bytes_consumed)); EXPECT_EQ(sizeof(packet_length), bytes_consumed); @@ -168,7 +168,7 @@ TEST_F(UnframerTest, PacketTooLong) { long_payload[i] = 0; } } - crc = crc16_compute(long_payload, sizeof(long_payload), &crc); + crc = tvm::runtime::micro_rpc::crc16_compute(long_payload, sizeof(long_payload), &crc); EXPECT_EQ(kTvmErrorWriteStreamShortWrite, unframer_.Write(long_payload, sizeof(long_payload), &bytes_consumed)); EXPECT_EQ(write_stream_.capacity(), bytes_consumed);