esp_crc.h 3.0 KB

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