esp_async_memcpy.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /*
  2. * SPDX-FileCopyrightText: 2020-2023 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #pragma once
  7. #include <stdint.h>
  8. #include <stdbool.h>
  9. #include "soc/soc_caps.h"
  10. #include "esp_err.h"
  11. #include "esp_etm.h"
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15. /**
  16. * @brief Async memory copy driver handle
  17. */
  18. typedef struct async_memcpy_context_t *async_memcpy_handle_t;
  19. /** @cond */
  20. /// @brief legacy driver handle type
  21. typedef async_memcpy_handle_t async_memcpy_t;
  22. /** @endcond */
  23. /**
  24. * @brief Async memory copy event data
  25. */
  26. typedef struct {
  27. void *data; /*!< Event data */
  28. } async_memcpy_event_t;
  29. /**
  30. * @brief Type of async memcpy interrupt callback function
  31. *
  32. * @param mcp_hdl Handle of async memcpy
  33. * @param event Event object, which contains related data, reserved for future
  34. * @param cb_args User defined arguments, passed from esp_async_memcpy function
  35. * @return Whether a high priority task is woken up by the callback function
  36. *
  37. * @note User can call OS primitives (semaphore, mutex, etc) in the callback function.
  38. * Keep in mind, if any OS primitive wakes high priority task up, the callback should return true.
  39. */
  40. typedef bool (*async_memcpy_isr_cb_t)(async_memcpy_handle_t mcp_hdl, async_memcpy_event_t *event, void *cb_args);
  41. /**
  42. * @brief Type of async memcpy configuration
  43. */
  44. typedef struct {
  45. uint32_t backlog; /*!< Maximum number of transactions that can be prepared in the background */
  46. size_t sram_trans_align; /*!< DMA transfer alignment (both in size and address) for SRAM memory */
  47. size_t psram_trans_align; /*!< DMA transfer alignment (both in size and address) for PSRAM memory */
  48. uint32_t flags; /*!< Extra flags to control async memcpy feature */
  49. } async_memcpy_config_t;
  50. /**
  51. * @brief Default configuration for async memcpy
  52. */
  53. #define ASYNC_MEMCPY_DEFAULT_CONFIG() \
  54. { \
  55. .backlog = 8, \
  56. .sram_trans_align = 0, \
  57. .psram_trans_align = 0, \
  58. .flags = 0, \
  59. }
  60. #if SOC_AHB_GDMA_SUPPORTED
  61. /**
  62. * @brief Install async memcpy driver, with AHB-GDMA as the backend
  63. *
  64. * @param[in] config Configuration of async memcpy
  65. * @param[out] mcp Returned driver handle
  66. * @return
  67. * - ESP_OK: Install async memcpy driver successfully
  68. * - ESP_ERR_INVALID_ARG: Install async memcpy driver failed because of invalid argument
  69. * - ESP_ERR_NO_MEM: Install async memcpy driver failed because out of memory
  70. * - ESP_FAIL: Install async memcpy driver failed because of other error
  71. */
  72. esp_err_t esp_async_memcpy_install_gdma_ahb(const async_memcpy_config_t *config, async_memcpy_handle_t *mcp);
  73. #endif // SOC_AHB_GDMA_SUPPORTED
  74. #if SOC_AXI_GDMA_SUPPORTED
  75. /**
  76. * @brief Install async memcpy driver, with AXI-GDMA as the backend
  77. *
  78. * @param[in] config Configuration of async memcpy
  79. * @param[out] mcp Returned driver handle
  80. * @return
  81. * - ESP_OK: Install async memcpy driver successfully
  82. * - ESP_ERR_INVALID_ARG: Install async memcpy driver failed because of invalid argument
  83. * - ESP_ERR_NO_MEM: Install async memcpy driver failed because out of memory
  84. * - ESP_FAIL: Install async memcpy driver failed because of other error
  85. */
  86. esp_err_t esp_async_memcpy_install_gdma_axi(const async_memcpy_config_t *config, async_memcpy_handle_t *mcp);
  87. #endif // SOC_AXI_GDMA_SUPPORTED
  88. #if SOC_CP_DMA_SUPPORTED
  89. /**
  90. * @brief Install async memcpy driver, with CPDMA as the backend
  91. *
  92. * @note CPDMA is a CPU peripheral, aiming for memory copy.
  93. *
  94. * @param[in] config Configuration of async memcpy
  95. * @param[out] mcp Returned driver handle
  96. * @return
  97. * - ESP_OK: Install async memcpy driver successfully
  98. * - ESP_ERR_INVALID_ARG: Install async memcpy driver failed because of invalid argument
  99. * - ESP_ERR_NO_MEM: Install async memcpy driver failed because out of memory
  100. * - ESP_FAIL: Install async memcpy driver failed because of other error
  101. */
  102. esp_err_t esp_async_memcpy_install_cpdma(const async_memcpy_config_t *config, async_memcpy_handle_t *mcp);
  103. #endif // SOC_CP_DMA_SUPPORTED
  104. /**
  105. * @brief Install async memcpy driver with the default DMA backend
  106. *
  107. * @note On chip with CPDMA support, CPDMA is the default choice.
  108. * On chip with AHB-GDMA support, AHB-GDMA is the default choice.
  109. *
  110. * @param[in] config Configuration of async memcpy
  111. * @param[out] mcp Returned driver handle
  112. * @return
  113. * - ESP_OK: Install async memcpy driver successfully
  114. * - ESP_ERR_INVALID_ARG: Install async memcpy driver failed because of invalid argument
  115. * - ESP_ERR_NO_MEM: Install async memcpy driver failed because out of memory
  116. * - ESP_FAIL: Install async memcpy driver failed because of other error
  117. */
  118. esp_err_t esp_async_memcpy_install(const async_memcpy_config_t *config, async_memcpy_handle_t *mcp);
  119. /**
  120. * @brief Uninstall async memcpy driver
  121. *
  122. * @param[in] mcp Handle of async memcpy driver that returned from `esp_async_memcpy_install`
  123. * @return
  124. * - ESP_OK: Uninstall async memcpy driver successfully
  125. * - ESP_ERR_INVALID_ARG: Uninstall async memcpy driver failed because of invalid argument
  126. * - ESP_FAIL: Uninstall async memcpy driver failed because of other error
  127. */
  128. esp_err_t esp_async_memcpy_uninstall(async_memcpy_handle_t mcp);
  129. /**
  130. * @brief Send an asynchronous memory copy request
  131. *
  132. * @note The callback function is invoked in interrupt context, never do blocking jobs in the callback.
  133. *
  134. * @param[in] mcp Handle of async memcpy driver that returned from `esp_async_memcpy_install`
  135. * @param[in] dst Destination address (copy to)
  136. * @param[in] src Source address (copy from)
  137. * @param[in] n Number of bytes to copy
  138. * @param[in] cb_isr Callback function, which got invoked in interrupt context. Set to NULL can bypass the callback.
  139. * @param[in] cb_args User defined argument to be passed to the callback function
  140. * @return
  141. * - ESP_OK: Send memory copy request successfully
  142. * - ESP_ERR_INVALID_ARG: Send memory copy request failed because of invalid argument
  143. * - ESP_FAIL: Send memory copy request failed because of other error
  144. */
  145. esp_err_t esp_async_memcpy(async_memcpy_handle_t mcp, void *dst, void *src, size_t n, async_memcpy_isr_cb_t cb_isr, void *cb_args);
  146. #if SOC_GDMA_SUPPORT_ETM
  147. /**
  148. * @brief Async memory copy specific events that supported by the ETM module
  149. */
  150. typedef enum {
  151. ASYNC_MEMCPY_ETM_EVENT_COPY_DONE, /*!< memory copy finished */
  152. } async_memcpy_etm_event_t;
  153. /**
  154. * @brief Get the ETM event handle for async memcpy done signal
  155. *
  156. * @note The created ETM event object can be deleted later by calling `esp_etm_del_event`
  157. *
  158. * @param[in] mcp Handle of async memcpy driver that returned from `esp_async_memcpy_install`
  159. * @param[in] event_type ETM event type
  160. * @param[out] out_event Returned ETM event handle
  161. * @return
  162. * - ESP_OK: Get ETM event successfully
  163. * - ESP_ERR_INVALID_ARG: Get ETM event failed because of invalid argument
  164. * - ESP_ERR_NOT_SUPPORTED: Get ETM event failed because the DMA hardware doesn't support ETM submodule
  165. * - ESP_FAIL: Get ETM event failed because of other error
  166. */
  167. esp_err_t esp_async_memcpy_new_etm_event(async_memcpy_handle_t mcp, async_memcpy_etm_event_t event_type, esp_etm_event_handle_t *out_event);
  168. #endif // SOC_GDMA_SUPPORT_ETM
  169. #ifdef __cplusplus
  170. }
  171. #endif