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