crc.h 2.7 KB

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