1 // Copyright 2015-2019 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 #pragma once
15
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19
20 #include <stdint.h>
21
22 // This header is only a wrapper on ROM CRC API
23 #include "esp_rom_crc.h"
24
25 /**
26 * @brief CRC32 value in little endian.
27 *
28 * @param crc: Initial CRC value (result of last calculation or 0 for the first time)
29 * @param buf: Data buffer that used to calculate the CRC value
30 * @param len: Length of the data buffer
31 * @return CRC32 value
32 */
esp_crc32_le(uint32_t crc,uint8_t const * buf,uint32_t len)33 static inline uint32_t esp_crc32_le(uint32_t crc, uint8_t const *buf, uint32_t len)
34 {
35 return esp_rom_crc32_le(crc, buf, len);
36 }
37
38 /**
39 * @brief CRC32 value in big endian.
40 *
41 * @param crc: Initial CRC value (result of last calculation or 0 for the first time)
42 * @param buf: Data buffer that used to calculate the CRC value
43 * @param len: Length of the data buffer
44 * @return CRC32 value
45 */
esp_crc32_be(uint32_t crc,uint8_t const * buf,uint32_t len)46 static inline uint32_t esp_crc32_be(uint32_t crc, uint8_t const *buf, uint32_t len)
47 {
48 return esp_rom_crc32_be(crc, buf, len);
49 }
50
51 /**
52 * @brief CRC16 value in little endian.
53 *
54 * @param crc: Initial CRC value (result of last calculation or 0 for the first time)
55 * @param buf: Data buffer that used to calculate the CRC value
56 * @param len: Length of the data buffer
57 * @return CRC16 value
58 */
esp_crc16_le(uint16_t crc,uint8_t const * buf,uint32_t len)59 static inline uint16_t esp_crc16_le(uint16_t crc, uint8_t const *buf, uint32_t len)
60 {
61 return esp_rom_crc16_le(crc, buf, len);
62 }
63
64 /**
65 * @brief CRC16 value in big endian.
66 *
67 * @param crc: Initial CRC value (result of last calculation or 0 for the first time)
68 * @param buf: Data buffer that used to calculate the CRC value
69 * @param len: Length of the data buffer
70 * @return CRC16 value
71 */
esp_crc16_be(uint16_t crc,uint8_t const * buf,uint32_t len)72 static inline uint16_t esp_crc16_be(uint16_t crc, uint8_t const *buf, uint32_t len)
73 {
74 return esp_rom_crc16_be(crc, buf, len);
75 }
76
77 /**
78 * @brief CRC8 value in little endian.
79 *
80 * @param crc: Initial CRC value (result of last calculation or 0 for the first time)
81 * @param buf: Data buffer that used to calculate the CRC value
82 * @param len: Length of the data buffer
83 * @return CRC8 value
84 */
esp_crc8_le(uint8_t crc,uint8_t const * buf,uint32_t len)85 static inline uint8_t esp_crc8_le(uint8_t crc, uint8_t const *buf, uint32_t len)
86 {
87 return esp_rom_crc8_le(crc, buf, len);
88 }
89
90 /**
91 * @brief CRC8 value in big endian.
92 *
93 * @param crc: Initial CRC value (result of last calculation or 0 for the first time)
94 * @param buf: Data buffer that used to calculate the CRC value
95 * @param len: Length of the data buffer
96 * @return CRC8 value
97 */
esp_crc8_be(uint8_t crc,uint8_t const * buf,uint32_t len)98 static inline uint8_t esp_crc8_be(uint8_t crc, uint8_t const *buf, uint32_t len)
99 {
100 return esp_rom_crc8_be(crc, buf, len);
101 }
102
103 #ifdef __cplusplus
104 }
105 #endif
106