esp_async_memcpy.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. // Copyright 2020 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #pragma once
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. #include <stdint.h>
  19. #include <stdbool.h>
  20. #include "esp_err.h"
  21. /**
  22. * @brief Type of async memcpy handle
  23. *
  24. */
  25. typedef struct async_memcpy_context_t *async_memcpy_t;
  26. /**
  27. * @brief Type of async memcpy event object
  28. *
  29. */
  30. typedef struct {
  31. void *data; /*!< Event data */
  32. } async_memcpy_event_t;
  33. /**
  34. * @brief Type of async memcpy interrupt callback function
  35. *
  36. * @param mcp_hdl Handle of async memcpy
  37. * @param event Event object, which contains related data, reserved for future
  38. * @param cb_args User defined arguments, passed from esp_async_memcpy function
  39. * @return Whether a high priority task is woken up by the callback function
  40. *
  41. * @note User can call OS primitives (semaphore, mutex, etc) in the callback function.
  42. * Keep in mind, if any OS primitive wakes high priority task up, the callback should return true.
  43. */
  44. typedef bool (*async_memcpy_isr_cb_t)(async_memcpy_t mcp_hdl, async_memcpy_event_t *event, void *cb_args);
  45. /**
  46. * @brief Type of async memcpy configuration
  47. *
  48. */
  49. typedef struct {
  50. uint32_t backlog; /*!< Maximum number of streams that can be handled simultaneously */
  51. size_t sram_trans_align; /*!< DMA transfer alignment (both in size and address) for SRAM memory */
  52. size_t psram_trans_align; /*!< DMA transfer alignment (both in size and address) for PSRAM memory */
  53. uint32_t flags; /*!< Extra flags to control async memcpy feature */
  54. } async_memcpy_config_t;
  55. /**
  56. * @brief Default configuration for async memcpy
  57. *
  58. */
  59. #define ASYNC_MEMCPY_DEFAULT_CONFIG() \
  60. { \
  61. .backlog = 8, \
  62. .sram_trans_align = 0, \
  63. .psram_trans_align = 0, \
  64. .flags = 0, \
  65. }
  66. /**
  67. * @brief Install async memcpy driver
  68. *
  69. * @param[in] config Configuration of async memcpy
  70. * @param[out] asmcp Handle of async memcpy that returned from this API. If driver installation is failed, asmcp would be assigned to NULL.
  71. * @return
  72. * - ESP_OK: Install async memcpy driver successfully
  73. * - ESP_ERR_INVALID_ARG: Install async memcpy driver failed because of invalid argument
  74. * - ESP_ERR_NO_MEM: Install async memcpy driver failed because out of memory
  75. * - ESP_FAIL: Install async memcpy driver failed because of other error
  76. */
  77. esp_err_t esp_async_memcpy_install(const async_memcpy_config_t *config, async_memcpy_t *asmcp);
  78. /**
  79. * @brief Uninstall async memcpy driver
  80. *
  81. * @param[in] asmcp Handle of async memcpy driver that returned from esp_async_memcpy_install
  82. * @return
  83. * - ESP_OK: Uninstall async memcpy driver successfully
  84. * - ESP_ERR_INVALID_ARG: Uninstall async memcpy driver failed because of invalid argument
  85. * - ESP_FAIL: Uninstall async memcpy driver failed because of other error
  86. */
  87. esp_err_t esp_async_memcpy_uninstall(async_memcpy_t asmcp);
  88. /**
  89. * @brief Send an asynchronous memory copy request
  90. *
  91. * @param[in] asmcp Handle of async memcpy driver that returned from esp_async_memcpy_install
  92. * @param[in] dst Destination address (copy to)
  93. * @param[in] src Source address (copy from)
  94. * @param[in] n Number of bytes to copy
  95. * @param[in] cb_isr Callback function, which got invoked in interrupt context. Set to NULL can bypass the callback.
  96. * @param[in] cb_args User defined argument to be passed to the callback function
  97. * @return
  98. * - ESP_OK: Send memory copy request successfully
  99. * - ESP_ERR_INVALID_ARG: Send memory copy request failed because of invalid argument
  100. * - ESP_FAIL: Send memory copy request failed because of other error
  101. *
  102. * @note The callback function is invoked in interrupt context, never do blocking jobs in the callback.
  103. */
  104. 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);
  105. #ifdef __cplusplus
  106. }
  107. #endif