1 // Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD 2 // 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 #pragma once 16 17 #include <stdint.h> 18 19 #ifdef __cplusplus 20 extern "C" { 21 #endif 22 23 /** \defgroup crc_apis, uart configuration and communication related apis 24 * @brief crc apis 25 */ 26 27 /** @addtogroup crc_apis 28 * @{ 29 */ 30 31 /* Standard CRC8/16/32 algorithms. */ 32 // CRC-8 x8+x2+x1+1 0x07 33 // CRC16-CCITT x16+x12+x5+1 1021 ISO HDLC, ITU X.25, V.34/V.41/V.42, PPP-FCS 34 // CRC32: 35 //G(x) = x32 +x26 + x23 + x22 + x16 + x12 + x11 + x10 + x8 + x7 + x5 + x4 + x2 + x1 + 1 36 //If your buf is not continuous, you can use the first result to be the second parameter. 37 38 /** 39 * @brief Crc32 value that is in little endian. 40 * 41 * @param uint32_t crc : init crc value, use 0 at the first use. 42 * 43 * @param uint8_t const *buf : buffer to start calculate crc. 44 * 45 * @param uint32_t len : buffer length in byte. 46 * 47 * @return None 48 */ 49 uint32_t crc32_le(uint32_t crc, uint8_t const *buf, uint32_t len); 50 51 /** 52 * @brief Crc32 value that is in big endian. 53 * 54 * @param uint32_t crc : init crc value, use 0 at the first use. 55 * 56 * @param uint8_t const *buf : buffer to start calculate crc. 57 * 58 * @param uint32_t len : buffer length in byte. 59 * 60 * @return None 61 */ 62 uint32_t crc32_be(uint32_t crc, uint8_t const *buf, uint32_t len); 63 64 /** 65 * @brief Crc16 value that is in little endian. 66 * 67 * @param uint16_t crc : init crc value, use 0 at the first use. 68 * 69 * @param uint8_t const *buf : buffer to start calculate crc. 70 * 71 * @param uint32_t len : buffer length in byte. 72 * 73 * @return None 74 */ 75 uint16_t crc16_le(uint16_t crc, uint8_t const *buf, uint32_t len); 76 77 /** 78 * @brief Crc16 value that is in big endian. 79 * 80 * @param uint16_t crc : init crc value, use 0 at the first use. 81 * 82 * @param uint8_t const *buf : buffer to start calculate crc. 83 * 84 * @param uint32_t len : buffer length in byte. 85 * 86 * @return None 87 */ 88 uint16_t crc16_be(uint16_t crc, uint8_t const *buf, uint32_t len); 89 90 /** 91 * @brief Crc8 value that is in little endian. 92 * 93 * @param uint8_t crc : init crc value, use 0 at the first use. 94 * 95 * @param uint8_t const *buf : buffer to start calculate crc. 96 * 97 * @param uint32_t len : buffer length in byte. 98 * 99 * @return None 100 */ 101 uint8_t crc8_le(uint8_t crc, uint8_t const *buf, uint32_t len); 102 103 /** 104 * @brief Crc8 value that is in big endian. 105 * 106 * @param uint32_t crc : init crc value, use 0 at the first use. 107 * 108 * @param uint8_t const *buf : buffer to start calculate crc. 109 * 110 * @param uint32_t len : buffer length in byte. 111 * 112 * @return None 113 */ 114 uint8_t crc8_be(uint8_t crc, uint8_t const *buf, uint32_t len); 115 116 /** 117 * @} 118 */ 119 120 #ifdef __cplusplus 121 } 122 #endif 123