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