crc.h 3.2 KB

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