1 // Copyright 2015-2016 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 #ifndef ROM_CRC_H 16 #define ROM_CRC_H 17 18 #include <stdint.h> 19 20 #ifdef __cplusplus 21 extern "C" { 22 #endif 23 24 /** \defgroup crc_apis, uart configuration and communication related apis 25 * @brief crc apis 26 */ 27 28 /** @addtogroup crc_apis 29 * @{ 30 */ 31 32 33 /* Standard CRC8/16/32 algorithms. */ 34 // CRC-8 x8+x2+x1+1 0x07 35 // CRC16-CCITT x16+x12+x5+1 1021 ISO HDLC, ITU X.25, V.34/V.41/V.42, PPP-FCS 36 // CRC32: 37 //G(x) = x32 +x26 + x23 + x22 + x16 + x12 + x11 + x10 + x8 + x7 + x5 + x4 + x2 + x1 + 1 38 //If your buf is not continuous, you can use the first result to be the second parameter. 39 40 /** 41 * @brief Crc32 value that is in little endian. 42 * 43 * @param uint32_t crc : init crc value, use 0 at the first use. 44 * 45 * @param uint8_t const *buf : buffer to start calculate crc. 46 * 47 * @param uint32_t len : buffer length in byte. 48 * 49 * @return None 50 */ 51 uint32_t crc32_le(uint32_t crc, uint8_t const *buf, uint32_t len); 52 53 /** 54 * @brief Crc16 value that is in little endian. 55 * 56 * @param uint16_t crc : init crc value, use 0 at the first use. 57 * 58 * @param uint8_t const *buf : buffer to start calculate crc. 59 * 60 * @param uint32_t len : buffer length in byte. 61 * 62 * @return None 63 */ 64 uint16_t crc16_le(uint16_t crc, uint8_t const *buf, uint32_t len); 65 66 /** 67 * @brief Crc8 value that is in little endian. 68 * 69 * @param uint8_t crc : init crc value, use 0 at the first use. 70 * 71 * @param uint8_t const *buf : buffer to start calculate crc. 72 * 73 * @param uint32_t len : buffer length in byte. 74 * 75 * @return None 76 */ 77 uint8_t crc8_le(uint8_t crc, uint8_t const *buf, uint32_t len); 78 79 /** 80 * @} 81 */ 82 83 #ifdef __cplusplus 84 } 85 #endif 86 87 88 #endif 89