esp_async_memcpy.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. uint32_t flags; /*!< Extra flags to control async memcpy feature */
  52. } async_memcpy_config_t;
  53. /**
  54. * @brief Default configuration for async memcpy
  55. *
  56. */
  57. #define ASYNC_MEMCPY_DEFAULT_CONFIG() \
  58. { \
  59. .backlog = 8, \
  60. .flags = 0, \
  61. }
  62. /**
  63. * @brief Install async memcpy driver
  64. *
  65. * @param[in] config Configuration of async memcpy
  66. * @param[out] asmcp Handle of async memcpy that returned from this API. If driver installation is failed, asmcp would be assigned to NULL.
  67. * @return
  68. * - ESP_OK: Install async memcpy driver successfully
  69. * - ESP_ERR_INVALID_ARG: Install async memcpy driver failed because of invalid argument
  70. * - ESP_ERR_NO_MEM: Install async memcpy driver failed because out of memory
  71. * - ESP_FAIL: Install async memcpy driver failed because of other error
  72. */
  73. esp_err_t esp_async_memcpy_install(const async_memcpy_config_t *config, async_memcpy_t *asmcp);
  74. /**
  75. * @brief Uninstall async memcpy driver
  76. *
  77. * @param[in] asmcp Handle of async memcpy driver that returned from esp_async_memcpy_install
  78. * @return
  79. * - ESP_OK: Uninstall async memcpy driver successfully
  80. * - ESP_ERR_INVALID_ARG: Uninstall async memcpy driver failed because of invalid argument
  81. * - ESP_FAIL: Uninstall async memcpy driver failed because of other error
  82. */
  83. esp_err_t esp_async_memcpy_uninstall(async_memcpy_t asmcp);
  84. /**
  85. * @brief Send an asynchronous memory copy request
  86. *
  87. * @param[in] asmcp Handle of async memcpy driver that returned from esp_async_memcpy_install
  88. * @param[in] dst Destination address (copy to)
  89. * @param[in] src Source address (copy from)
  90. * @param[in] n Number of bytes to copy
  91. * @param[in] cb_isr Callback function, which got invoked in interrupt context. Set to NULL can bypass the callback.
  92. * @param[in] cb_args User defined argument to be passed to the callback function
  93. * @return
  94. * - ESP_OK: Send memory copy request successfully
  95. * - ESP_ERR_INVALID_ARG: Send memory copy request failed because of invalid argument
  96. * - ESP_FAIL: Send memory copy request failed because of other error
  97. *
  98. * @note The callback function is invoked in interrupt context, never do blocking jobs in the callback.
  99. */
  100. 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);
  101. #ifdef __cplusplus
  102. }
  103. #endif