crc.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. #define ESP_ROM_HAS_CRC8LE 1
  17. #define ESP_ROM_HAS_CRC16LE 1
  18. #define ESP_ROM_HAS_CRC32LE 1
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. /** \defgroup crc_apis, uart configuration and communication related apis
  23. * @brief crc apis
  24. */
  25. /** @addtogroup crc_apis
  26. * @{
  27. */
  28. /* Standard CRC8/16/32 algorithms. */
  29. // CRC-8 x8+x2+x1+1 0x07
  30. // CRC16-CCITT x16+x12+x5+1 1021 ISO HDLC, ITU X.25, V.34/V.41/V.42, PPP-FCS
  31. // CRC32:
  32. //G(x) = x32 +x26 + x23 + x22 + x16 + x12 + x11 + x10 + x8 + x7 + x5 + x4 + x2 + x1 + 1
  33. //If your buf is not continuous, you can use the first result to be the second parameter.
  34. /**
  35. * @brief Crc32 value that is in little endian.
  36. *
  37. * @param uint32_t crc : init crc value, use 0 at the first use.
  38. *
  39. * @param uint8_t const *buf : buffer to start calculate crc.
  40. *
  41. * @param uint32_t len : buffer length in byte.
  42. *
  43. * @return None
  44. */
  45. uint32_t crc32_le(uint32_t crc, uint8_t const *buf, uint32_t len);
  46. /**
  47. * @brief Crc16 value that is in little endian.
  48. *
  49. * @param uint16_t crc : init crc value, use 0 at the first use.
  50. *
  51. * @param uint8_t const *buf : buffer to start calculate crc.
  52. *
  53. * @param uint32_t len : buffer length in byte.
  54. *
  55. * @return None
  56. */
  57. uint16_t crc16_le(uint16_t crc, uint8_t const *buf, uint32_t len);
  58. /**
  59. * @brief Crc8 value that is in little endian.
  60. *
  61. * @param uint8_t crc : init crc value, use 0 at the first use.
  62. *
  63. * @param uint8_t const *buf : buffer to start calculate crc.
  64. *
  65. * @param uint32_t len : buffer length in byte.
  66. *
  67. * @return None
  68. */
  69. uint8_t crc8_le(uint8_t crc, uint8_t const *buf, uint32_t len);
  70. /**
  71. * @}
  72. */
  73. #ifdef __cplusplus
  74. }
  75. #endif
  76. #endif