crc32.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /* Copyright (C) 2018 RDA Technologies Limited and/or its affiliates("RDA").
  2. * All rights reserved.
  3. *
  4. * This software is supplied "AS IS" without any warranties.
  5. * RDA assumes no responsibility or liability for the use of the software,
  6. * conveys no license or title under any patent, copyright, or mask work
  7. * right to the product. RDA reserves the right to make changes in the
  8. * software without notification. RDA also make no representation or
  9. * warranty that such application will be suitable for the specified use
  10. * without further testing or modification.
  11. */
  12. #ifndef _CALCLIB_CRC32_H_
  13. #define _CALCLIB_CRC32_H_
  14. #include <stdint.h>
  15. #include <stddef.h>
  16. #include <stdbool.h>
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. /**
  21. * initial value for CRC32 calculation
  22. *
  23. * \return initial value
  24. */
  25. uint32_t crc32Init(void);
  26. /**
  27. * update of CRC32 calculation
  28. *
  29. * \param crc current value
  30. * \param p buffer for CRC 32 calculation
  31. * \param size buffer size
  32. * \return updated value
  33. */
  34. uint32_t crc32Update(uint32_t crc, const void *p, size_t size);
  35. /**
  36. * calculate CRC32
  37. *
  38. * \param p buffer for CRC 32 calculation
  39. * \param size buffer size
  40. * \return CRC32 value
  41. */
  42. uint32_t crc32Calc(const void *p, size_t length);
  43. /**
  44. * variant of CRC32 with different initial value
  45. *
  46. * This is not a common used CRC32 calculation. Don't use it unless
  47. * for backward compatible.
  48. *
  49. * \return initial value
  50. */
  51. uint32_t crc32VariantInit(void);
  52. /**
  53. * variant of CRC32 with different initial value
  54. *
  55. * This is not a common used CRC32 calculation. Don't use it unless
  56. * for backward compatible.
  57. *
  58. * \param crc current value
  59. * \param p buffer for CRC 32 calculation
  60. * \param size buffer size
  61. * \return updated value
  62. */
  63. uint32_t crc32VariantUpdate(uint32_t crc, const void *p, size_t size);
  64. /**
  65. * variant of CRC32 with different initial value
  66. *
  67. * This is not a common used CRC32 calculation. Don't use it unless
  68. * for backward compatible.
  69. *
  70. * \param p buffer for CRC 32 calculation
  71. * \param size buffer size
  72. * \return CRC32 value
  73. */
  74. uint32_t crc32VariantCalc(const void *p, size_t length);
  75. /**
  76. * initial value for CRC8/ROHC calculation
  77. *
  78. * \return CRC8/ROHC initial value
  79. */
  80. uint8_t crc8RohcInit(void);
  81. /**
  82. * update of CRC8/ROHC calculation
  83. *
  84. * \param crc current value
  85. * \param p buffer for CRC8/ROHC calculation
  86. * \param size buffer size
  87. * \return updated value
  88. */
  89. uint8_t crc8RohcUpdate(uint8_t crc, const void *p, size_t size);
  90. /**
  91. * calculate CRC8/ROHC
  92. *
  93. * poly=0x07, init=0xff, refin=true, refout=true, xorout=0x00, residue=0x00
  94. *
  95. * \param p buffer for CRC8/ROHC calculation
  96. * \param size buffer size
  97. * \return CRC8 value
  98. */
  99. uint8_t crc8RohcCalc(const void *p, size_t size);
  100. /**
  101. * calculate CRC16 used in NV
  102. *
  103. * \param p buffer for CRC16/NV calculation
  104. * \param size buffer size
  105. * \return CRC16 value
  106. */
  107. uint16_t crc16NvCalc(const void *p, size_t size);
  108. /**
  109. * calculate CRC16 used in ROM BSL
  110. *
  111. * \param p buffer
  112. * \param size buffer size
  113. * \return CRC16 value
  114. */
  115. uint16_t crc16RomBslCalc(const void *p, unsigned size);
  116. /**
  117. * check whether ROM BSL CRC16 matches
  118. *
  119. * It will check whether the last 2 bytes of the buffer is the big endian
  120. * CRC16 calculated by \p crc16RomBslCalc for the preceeding bytes.
  121. *
  122. * \param p buffer
  123. * \param size buffer size
  124. * \return
  125. * - true if the tail CR16 matches
  126. * - false if the tail CRC16 doesn't match
  127. */
  128. bool crc16RomBslCheck(const void *p, unsigned size);
  129. /**
  130. * calculate CRC16 used in FDL
  131. *
  132. * \param p buffer
  133. * \param size buffer size
  134. * \return CRC16 value
  135. */
  136. uint16_t crc16FdlCalc(const uint16_t *p, unsigned size);
  137. #ifdef __cplusplus
  138. }
  139. #endif
  140. #endif