1 /** 2 * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 * 15 * Description: Provides CRC api \n 16 * 17 * History: \n 18 * 2023-03-30, Create file. \n 19 */ 20 21 #ifndef UAPI_CRC_H 22 #define UAPI_CRC_H 23 24 #include <stdint.h> 25 26 #ifdef __cplusplus 27 #if __cplusplus 28 extern "C" { 29 #endif /* __cplusplus */ 30 #endif /* __cplusplus */ 31 32 /** 33 * @defgroup middleware_utils_algorithm_crc CRC 34 * @ingroup middleware_utils_algorithm 35 * @{ 36 */ 37 38 /** 39 * @if Eng 40 * @brief Generates a 16-bit CRC value. The polynomial is as follows: x16 + x12 + x5 + 1 (0x1021). 41 * @param [in] crc_start The original initial value is 0. Piecewise calculation is used. 42 * The previous calculation result is transferred each time. 43 * @param [in] buf Pointer to the checked buffer. 44 * @param [in] length Length of the checked buffer (unit: byte). 45 * @return CRC value. 46 * @else 47 * @brief 计算16位CRC校验值. 多项式: x16 + x12 + x5 + 1 (0x1021)。 48 * @param [in] crc_start 初始值为0。分段计算时,前一段结算的结果作为后一段计算的输入。 49 * @param [in] buf 指向待计算数据的指针,由调用校验。 50 * @param [in] length 数据长度 (单位: 字节)。 51 * @return CRC计算结果. 52 * @endif 53 */ 54 uint16_t uapi_crc16(uint16_t crc_start, const uint8_t *buf, uint32_t length); 55 56 /** 57 * @if Eng 58 * @brief Generates a 32-bit CRC value. It complies with the IEEE 802.3 CRC-32 standard (0x04C11DB7). 59 * @param [in] crc_start The original initial value is 0. Piecewise calculation is used. 60 * The previous calculation result is transferred each time. 61 * @param [in] buf Pointer to the checked buffer. 62 * @param [in] length Length of the checked buffer (unit: byte). 63 * @return CRC value. 64 * @else 65 * @brief 计算32位CRC校验值. 多项式符合IEEE 802.3 CRC-32标准(0x04C11DB7)。 66 * @param [in] crc_start 初始值为0。分段计算时,前一段结算的结果作为后一段计算的输入。 67 * @param [in] buf 指向待计算数据的指针,由调用校验。 68 * @param [in] length 数据长度 (单位: 字节)。 69 * @return CRC计算结果. 70 * @endif 71 */ 72 uint32_t uapi_crc32(uint32_t crc_start, const uint8_t *buf, uint32_t length); 73 74 /** 75 * @if Eng 76 * @brief Generates a 32-bit CRC value without two's complement. It complies with the IEEE 802.3 77 * CRC-32 standard (0x04C11DB7). 78 * @param [in] crc_start The original initial value is 0. Piecewise calculation is used. 79 * The previous calculation result is transferred each time. 80 * @param [in] buf Pointer to the checked buffer. 81 * @param [in] length Length of the checked buffer (unit: byte). 82 * @return CRC value. 83 * @else 84 * @brief 计算32位CRC校验值(无补码). 多项式符合IEEE 802.3 CRC-32标准(0x04C11DB7)。 85 * @param [in] crc_start 初始值为0。分段计算时,前一段结算的结果作为后一段计算的输入。 86 * @param [in] buf 指向待计算数据的指针,由调用校验。 87 * @param [in] length 数据长度 (单位: 字节)。 88 * @return CRC计算结果. 89 * @endif 90 */ 91 uint32_t uapi_crc32_no_comp(uint32_t crc_start, const uint8_t *buf, uint32_t length); 92 93 94 /** 95 * @} 96 */ 97 98 #ifdef __cplusplus 99 #if __cplusplus 100 } 101 #endif /* __cplusplus */ 102 #endif /* __cplusplus */ 103 104 105 #endif 106