esp_crc.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #pragma once
  7. #ifdef __cplusplus
  8. extern "C" {
  9. #endif
  10. #include <stdint.h>
  11. // This header is only a wrapper on ROM CRC API
  12. #include "esp_rom_crc.h"
  13. /**
  14. * @brief CRC32 value in little endian.
  15. *
  16. * @param crc: Initial CRC value (result of last calculation or 0 for the first time)
  17. * @param buf: Data buffer that used to calculate the CRC value
  18. * @param len: Length of the data buffer
  19. * @return CRC32 value
  20. */
  21. static inline uint32_t esp_crc32_le(uint32_t crc, uint8_t const *buf, uint32_t len)
  22. {
  23. return esp_rom_crc32_le(crc, buf, len);
  24. }
  25. /**
  26. * @brief CRC32 value in big endian.
  27. *
  28. * @param crc: Initial CRC value (result of last calculation or 0 for the first time)
  29. * @param buf: Data buffer that used to calculate the CRC value
  30. * @param len: Length of the data buffer
  31. * @return CRC32 value
  32. */
  33. static inline uint32_t esp_crc32_be(uint32_t crc, uint8_t const *buf, uint32_t len)
  34. {
  35. return esp_rom_crc32_be(crc, buf, len);
  36. }
  37. /**
  38. * @brief CRC16 value in little endian.
  39. *
  40. * @param crc: Initial CRC value (result of last calculation or 0 for the first time)
  41. * @param buf: Data buffer that used to calculate the CRC value
  42. * @param len: Length of the data buffer
  43. * @return CRC16 value
  44. */
  45. static inline uint16_t esp_crc16_le(uint16_t crc, uint8_t const *buf, uint32_t len)
  46. {
  47. return esp_rom_crc16_le(crc, buf, len);
  48. }
  49. /**
  50. * @brief CRC16 value in big endian.
  51. *
  52. * @param crc: Initial CRC value (result of last calculation or 0 for the first time)
  53. * @param buf: Data buffer that used to calculate the CRC value
  54. * @param len: Length of the data buffer
  55. * @return CRC16 value
  56. */
  57. static inline uint16_t esp_crc16_be(uint16_t crc, uint8_t const *buf, uint32_t len)
  58. {
  59. return esp_rom_crc16_be(crc, buf, len);
  60. }
  61. /**
  62. * @brief CRC8 value in little endian.
  63. *
  64. * @param crc: Initial CRC value (result of last calculation or 0 for the first time)
  65. * @param buf: Data buffer that used to calculate the CRC value
  66. * @param len: Length of the data buffer
  67. * @return CRC8 value
  68. */
  69. static inline uint8_t esp_crc8_le(uint8_t crc, uint8_t const *buf, uint32_t len)
  70. {
  71. return esp_rom_crc8_le(crc, buf, len);
  72. }
  73. /**
  74. * @brief CRC8 value in big endian.
  75. *
  76. * @param crc: Initial CRC value (result of last calculation or 0 for the first time)
  77. * @param buf: Data buffer that used to calculate the CRC value
  78. * @param len: Length of the data buffer
  79. * @return CRC8 value
  80. */
  81. static inline uint8_t esp_crc8_be(uint8_t crc, uint8_t const *buf, uint32_t len)
  82. {
  83. return esp_rom_crc8_be(crc, buf, len);
  84. }
  85. #ifdef __cplusplus
  86. }
  87. #endif