crc.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. // Copyright 2015-2016 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. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #ifndef ROM_CRC_H
  14. #define ROM_CRC_H
  15. #include <stdint.h>
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. /** \defgroup uart_apis, uart configuration and communication related apis
  20. * @brief uart apis
  21. */
  22. /** @addtogroup uart_apis
  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. * @brief Crc32 value that is in little endian.
  33. *
  34. * @param uint32_t crc : init crc value, use 0 at the first use.
  35. *
  36. * @param uint8_t const *buf : buffer to start calculate crc.
  37. *
  38. * @param uint32_t len : buffer length in byte.
  39. *
  40. * @return None
  41. */
  42. uint32_t crc32_le(uint32_t crc, uint8_t const *buf, uint32_t len);
  43. /**
  44. * @brief Crc32 value that is in big endian.
  45. *
  46. * @param uint32_t crc : init crc value, use 0 at the first use.
  47. *
  48. * @param uint8_t const *buf : buffer to start calculate crc.
  49. *
  50. * @param uint32_t len : buffer length in byte.
  51. *
  52. * @return None
  53. */
  54. uint32_t crc32_be(uint32_t crc, uint8_t const *buf, uint32_t len);
  55. /**
  56. * @brief Crc16 value that is in little endian.
  57. *
  58. * @param uint16_t crc : init crc value, use 0 at the first use.
  59. *
  60. * @param uint8_t const *buf : buffer to start calculate crc.
  61. *
  62. * @param uint32_t len : buffer length in byte.
  63. *
  64. * @return None
  65. */
  66. uint16_t crc16_le(uint16_t crc, uint8_t const *buf, uint32_t len);
  67. /**
  68. * @brief Crc16 value that is in big endian.
  69. *
  70. * @param uint16_t crc : init crc value, use 0 at the first use.
  71. *
  72. * @param uint8_t const *buf : buffer to start calculate crc.
  73. *
  74. * @param uint32_t len : buffer length in byte.
  75. *
  76. * @return None
  77. */
  78. uint16_t crc16_be(uint16_t crc, uint8_t const *buf, uint32_t len);
  79. /**
  80. * @brief Crc8 value that is in little endian.
  81. *
  82. * @param uint8_t crc : init crc value, use 0 at the first use.
  83. *
  84. * @param uint8_t const *buf : buffer to start calculate crc.
  85. *
  86. * @param uint32_t len : buffer length in byte.
  87. *
  88. * @return None
  89. */
  90. uint8_t crc8_le(uint8_t crc, uint8_t const *buf, uint32_t len);
  91. /**
  92. * @brief Crc8 value that is in big endian.
  93. *
  94. * @param uint32_t crc : init crc value, use 0 at the first use.
  95. *
  96. * @param uint8_t const *buf : buffer to start calculate crc.
  97. *
  98. * @param uint32_t len : buffer length in byte.
  99. *
  100. * @return None
  101. */
  102. uint8_t crc8_be(uint8_t crc, uint8_t const *buf, uint32_t len);
  103. /**
  104. * @}
  105. */
  106. #ifdef __cplusplus
  107. }
  108. #endif
  109. #endif