hal_lzma.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 _HAL_LZMA_H_
  13. #define _HAL_LZMA_H_
  14. #include <stdint.h>
  15. #include <stdbool.h>
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. /**
  20. * enable LZMA hardware decompress module
  21. *
  22. * It should always be called LZMA hardware module is about to be used.
  23. * It will be called inside \p halLzmaDecompressBlock, and usually it is
  24. * not needed to call it manually.
  25. */
  26. void halLzmaEnable(void);
  27. /**
  28. * disable LZMA hardware decompress module
  29. *
  30. * It can be used after LZMA hardware module won't be used anymore. It
  31. * will be called inside \p halLzmaDecompressBlock.
  32. */
  33. void halLzmaDisable(void);
  34. /**
  35. * reset LZMA hardware decompress module
  36. *
  37. * After decompress error, LZMA hardware module should be reset. It is called
  38. * inside \p halLzmaDecompressBlock on decompress error, and usually it is not
  39. * needed to call it manually.
  40. */
  41. void halLzmaReset(void);
  42. /**
  43. * get data size from LZMA stream
  44. *
  45. * \param [in] stream LZMA stream
  46. * \return
  47. * - decompressed data size
  48. * - -1 in error
  49. */
  50. int halLzmaDataSize(const void *stream);
  51. /**
  52. * get maximum block stream size from LZMA stream
  53. *
  54. * \param [in] stream LZMA stream
  55. * \param [in] size LZMA stream size
  56. * \return
  57. * - maximum block stream size
  58. * - -1 in error
  59. */
  60. int halLzmaMaxBlockStreamSize(const void *stream, uint32_t size);
  61. /**
  62. * decompress LZMA stream
  63. *
  64. * Though LZMA can work in interrupt mode, this will use polling mode.
  65. *
  66. * Some limitations:
  67. * - \p src must be 8 bytes aligned
  68. * - \p dest must be 32 bytes aligned
  69. * - \p src_size must be the exact compressed stream size
  70. * - \p dest_size must be the exact decompressed data size
  71. * - \p dict size must be the same as compress tool
  72. * - \p src and \dest must be PSRAM/DDR address
  73. * - Hardware may overwrite destination buffer up to 32 bytes aligned. For
  74. * example, when \p dest_size is 20, then hardware may overwrite up to
  75. * address 31.
  76. *
  77. * \p src_size, \p dest_size and \p dict_size are embedded in the stream
  78. * created by compress tool.
  79. *
  80. * At decompress, hardware will calculate a *simple* CRC of the decompressed
  81. * data. This can be used to verify decompressed data, if the expected CRC
  82. * is known.
  83. *
  84. * On error, it is needed to reset LZMA hardware module. And it will be
  85. * done inside.
  86. *
  87. * There are no multi-thread protection inside.
  88. *
  89. * \param [in] src LZMA stream
  90. * \param [in] src_size LZMA stream size
  91. * \param [in] dest decompressed buffer
  92. * \param [in] dest_size decompressed data size
  93. * \param [in] dict_size dictionary size
  94. * \param [out] crc decompressed data CRC, can be NULL
  95. * \return
  96. * - true on success
  97. * - false on error
  98. */
  99. bool halLzmaDecompressBlock(const void *src, uint32_t src_size,
  100. void *dest, uint32_t dest_size,
  101. uint32_t dict_size, uint32_t *crc);
  102. /**
  103. * decompress LZMA file stream
  104. *
  105. * Limitations:
  106. * - \p src must be 8 bytes aligned
  107. * - \p dest must be 32 bytes aligned
  108. * - \p src and \dest must be PSRAM/DDR address
  109. * - Hardware may overwrite destination buffer up to 32 bytes aligned.
  110. *
  111. * Though LZMA can work in interrupt mode, this will use polling mode.
  112. *
  113. * \param [in] src LZMA file stream
  114. * \param [in] dest decompressed buffer
  115. * \return
  116. * - decompressed data size
  117. * - -1 on error
  118. */
  119. int halLzmaDecompressFile(const void *stream, void *dest);
  120. #ifdef __cplusplus
  121. }
  122. #endif
  123. #endif