esp_async_memcpy.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. /**
  14. * @brief Type of async memcpy handle
  15. *
  16. */
  17. typedef struct async_memcpy_context_t *async_memcpy_t;
  18. /**
  19. * @brief Type of async memcpy event object
  20. *
  21. */
  22. typedef struct {
  23. void *data; /*!< Event data */
  24. } async_memcpy_event_t;
  25. /**
  26. * @brief Type of async memcpy interrupt callback function
  27. *
  28. * @param mcp_hdl Handle of async memcpy
  29. * @param event Event object, which contains related data, reserved for future
  30. * @param cb_args User defined arguments, passed from esp_async_memcpy function
  31. * @return Whether a high priority task is woken up by the callback function
  32. *
  33. * @note User can call OS primitives (semaphore, mutex, etc) in the callback function.
  34. * Keep in mind, if any OS primitive wakes high priority task up, the callback should return true.
  35. */
  36. typedef bool (*async_memcpy_isr_cb_t)(async_memcpy_t mcp_hdl, async_memcpy_event_t *event, void *cb_args);
  37. /**
  38. * @brief Type of async memcpy configuration
  39. *
  40. */
  41. typedef struct {
  42. uint32_t backlog; /*!< Maximum number of streams that can be handled simultaneously */
  43. size_t sram_trans_align; /*!< DMA transfer alignment (both in size and address) for SRAM memory */
  44. size_t psram_trans_align; /*!< DMA transfer alignment (both in size and address) for PSRAM memory */
  45. uint32_t flags; /*!< Extra flags to control async memcpy feature */
  46. } async_memcpy_config_t;
  47. /**
  48. * @brief Default configuration for async memcpy
  49. *
  50. */
  51. #define ASYNC_MEMCPY_DEFAULT_CONFIG() \
  52. { \
  53. .backlog = 8, \
  54. .sram_trans_align = 0, \
  55. .psram_trans_align = 0, \
  56. .flags = 0, \
  57. }
  58. /**
  59. * @brief Install async memcpy driver
  60. *
  61. * @param[in] config Configuration of async memcpy
  62. * @param[out] asmcp Handle of async memcpy that returned from this API. If driver installation is failed, asmcp would be assigned to NULL.
  63. * @return
  64. * - ESP_OK: Install async memcpy driver successfully
  65. * - ESP_ERR_INVALID_ARG: Install async memcpy driver failed because of invalid argument
  66. * - ESP_ERR_NO_MEM: Install async memcpy driver failed because out of memory
  67. * - ESP_FAIL: Install async memcpy driver failed because of other error
  68. */
  69. esp_err_t esp_async_memcpy_install(const async_memcpy_config_t *config, async_memcpy_t *asmcp);
  70. /**
  71. * @brief Uninstall async memcpy driver
  72. *
  73. * @param[in] asmcp Handle of async memcpy driver that returned from esp_async_memcpy_install
  74. * @return
  75. * - ESP_OK: Uninstall async memcpy driver successfully
  76. * - ESP_ERR_INVALID_ARG: Uninstall async memcpy driver failed because of invalid argument
  77. * - ESP_FAIL: Uninstall async memcpy driver failed because of other error
  78. */
  79. esp_err_t esp_async_memcpy_uninstall(async_memcpy_t asmcp);
  80. /**
  81. * @brief Send an asynchronous memory copy request
  82. *
  83. * @param[in] asmcp Handle of async memcpy driver that returned from esp_async_memcpy_install
  84. * @param[in] dst Destination address (copy to)
  85. * @param[in] src Source address (copy from)
  86. * @param[in] n Number of bytes to copy
  87. * @param[in] cb_isr Callback function, which got invoked in interrupt context. Set to NULL can bypass the callback.
  88. * @param[in] cb_args User defined argument to be passed to the callback function
  89. * @return
  90. * - ESP_OK: Send memory copy request successfully
  91. * - ESP_ERR_INVALID_ARG: Send memory copy request failed because of invalid argument
  92. * - ESP_FAIL: Send memory copy request failed because of other error
  93. *
  94. * @note The callback function is invoked in interrupt context, never do blocking jobs in the callback.
  95. */
  96. 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);
  97. #ifdef __cplusplus
  98. }
  99. #endif