crc.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 crc_apis, uart configuration and communication related apis
  20. * @brief crc apis
  21. */
  22. /** @addtogroup crc_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 Crc16 value that is in little endian.
  45. *
  46. * @param uint16_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. uint16_t crc16_le(uint16_t crc, uint8_t const *buf, uint32_t len);
  55. /**
  56. * @brief Crc8 value that is in little endian.
  57. *
  58. * @param uint8_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. uint8_t crc8_le(uint8_t crc, uint8_t const *buf, uint32_t len);
  67. /**
  68. * @}
  69. */
  70. #ifdef __cplusplus
  71. }
  72. #endif
  73. #endif