esp_async_memcpy.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. * SPDX-FileCopyrightText: 2020-2021 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #pragma once
  7. #ifdef __cplusplus
  8. extern "C" {
  9. #endif
  10. #include <stdint.h>
  11. #include <stdbool.h>
  12. #include "esp_err.h"
  13. #include "esp_etm.h"
  14. /**
  15. * @brief Type of async memcpy handle
  16. *
  17. */
  18. typedef struct async_memcpy_context_t *async_memcpy_t;
  19. /**
  20. * @brief Type of async memcpy event object
  21. *
  22. */
  23. typedef struct {
  24. void *data; /*!< Event data */
  25. } async_memcpy_event_t;
  26. /**
  27. * @brief Type of async memcpy interrupt callback function
  28. *
  29. * @param mcp_hdl Handle of async memcpy
  30. * @param event Event object, which contains related data, reserved for future
  31. * @param cb_args User defined arguments, passed from esp_async_memcpy function
  32. * @return Whether a high priority task is woken up by the callback function
  33. *
  34. * @note User can call OS primitives (semaphore, mutex, etc) in the callback function.
  35. * Keep in mind, if any OS primitive wakes high priority task up, the callback should return true.
  36. */
  37. typedef bool (*async_memcpy_isr_cb_t)(async_memcpy_t mcp_hdl, async_memcpy_event_t *event, void *cb_args);
  38. /**
  39. * @brief Type of async memcpy configuration
  40. *
  41. */
  42. typedef struct {
  43. uint32_t backlog; /*!< Maximum number of streams that can be handled simultaneously */
  44. size_t sram_trans_align; /*!< DMA transfer alignment (both in size and address) for SRAM memory */
  45. size_t psram_trans_align; /*!< DMA transfer alignment (both in size and address) for PSRAM memory */
  46. uint32_t flags; /*!< Extra flags to control async memcpy feature */
  47. } async_memcpy_config_t;
  48. /**
  49. * @brief Default configuration for async memcpy
  50. *
  51. */
  52. #define ASYNC_MEMCPY_DEFAULT_CONFIG() \
  53. { \
  54. .backlog = 8, \
  55. .sram_trans_align = 0, \
  56. .psram_trans_align = 0, \
  57. .flags = 0, \
  58. }
  59. /**
  60. * @brief Install async memcpy driver
  61. *
  62. * @param[in] config Configuration of async memcpy
  63. * @param[out] asmcp Handle of async memcpy that returned from this API. If driver installation is failed, asmcp would be assigned to NULL.
  64. * @return
  65. * - ESP_OK: Install async memcpy driver successfully
  66. * - ESP_ERR_INVALID_ARG: Install async memcpy driver failed because of invalid argument
  67. * - ESP_ERR_NO_MEM: Install async memcpy driver failed because out of memory
  68. * - ESP_FAIL: Install async memcpy driver failed because of other error
  69. */
  70. esp_err_t esp_async_memcpy_install(const async_memcpy_config_t *config, async_memcpy_t *asmcp);
  71. /**
  72. * @brief Uninstall async memcpy driver
  73. *
  74. * @param[in] asmcp Handle of async memcpy driver that returned from esp_async_memcpy_install
  75. * @return
  76. * - ESP_OK: Uninstall async memcpy driver successfully
  77. * - ESP_ERR_INVALID_ARG: Uninstall async memcpy driver failed because of invalid argument
  78. * - ESP_FAIL: Uninstall async memcpy driver failed because of other error
  79. */
  80. esp_err_t esp_async_memcpy_uninstall(async_memcpy_t asmcp);
  81. /**
  82. * @brief Send an asynchronous memory copy request
  83. *
  84. * @note The callback function is invoked in interrupt context, never do blocking jobs in the callback.
  85. *
  86. * @param[in] asmcp Handle of async memcpy driver that returned from esp_async_memcpy_install
  87. * @param[in] dst Destination address (copy to)
  88. * @param[in] src Source address (copy from)
  89. * @param[in] n Number of bytes to copy
  90. * @param[in] cb_isr Callback function, which got invoked in interrupt context. Set to NULL can bypass the callback.
  91. * @param[in] cb_args User defined argument to be passed to the callback function
  92. * @return
  93. * - ESP_OK: Send memory copy request successfully
  94. * - ESP_ERR_INVALID_ARG: Send memory copy request failed because of invalid argument
  95. * - ESP_FAIL: Send memory copy request failed because of other error
  96. */
  97. esp_err_t esp_async_memcpy(async_memcpy_t asmcp, void *dst, void *src, size_t n, async_memcpy_isr_cb_t cb_isr, void *cb_args);
  98. /**
  99. * @brief Async memory copy specific events that supported by the ETM module
  100. */
  101. typedef enum {
  102. ASYNC_MEMCPY_ETM_EVENT_COPY_DONE, /*!< memory copy finished */
  103. } async_memcpy_etm_event_t;
  104. /**
  105. * @brief Get the ETM event handle for async memcpy done signal
  106. *
  107. * @note The created ETM event object can be deleted later by calling `esp_etm_del_event`
  108. *
  109. * @param[in] asmcp Handle of async memcpy driver that returned from `esp_async_memcpy_install`
  110. * @param[in] event_type ETM event type
  111. * @param[out] out_event Returned ETM event handle
  112. * @return
  113. * @return
  114. * - ESP_OK: Get ETM event successfully
  115. * - ESP_ERR_INVALID_ARG: Get ETM event failed because of invalid argument
  116. * - ESP_ERR_NOT_SUPPORTED: Get ETM event failed because the DMA hardware doesn't support ETM submodule
  117. * - ESP_FAIL: Get ETM event failed because of other error
  118. */
  119. esp_err_t esp_async_memcpy_new_etm_event(async_memcpy_t asmcp, async_memcpy_etm_event_t event_type, esp_etm_event_handle_t *out_event);
  120. #ifdef __cplusplus
  121. }
  122. #endif