esp_async_memcpy_impl.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. #include <stdint.h>
  15. #include <stdbool.h>
  16. #include "esp_err.h"
  17. #include "esp_intr_alloc.h"
  18. #include "soc/soc_caps.h"
  19. #include "hal/dma_types.h"
  20. #include "freertos/FreeRTOS.h"
  21. #if SOC_CP_DMA_SUPPORTED
  22. #include "hal/cp_dma_ll.h"
  23. #include "hal/cp_dma_hal.h"
  24. #elif SOC_GDMA_SUPPORTED
  25. #include "hal/gdma_ll.h"
  26. #include "hal/gdma_hal.h"
  27. #endif
  28. /**
  29. * @brief Type of async mcp implementation layer context
  30. *
  31. */
  32. typedef struct {
  33. portMUX_TYPE hal_lock; // spin lock for HAL object
  34. #if SOC_CP_DMA_SUPPORTED
  35. cp_dma_hal_context_t hal; // CP DMA hal
  36. #elif SOC_GDMA_SUPPORTED
  37. gdma_hal_context_t hal; // General DMA hal
  38. #endif
  39. bool isr_need_yield; // if current isr needs a yield for higher priority task
  40. } async_memcpy_impl_t;
  41. /**
  42. * @brief ISR callback function, invoked when RX done event triggered
  43. *
  44. * @param impl async mcp implementation layer context pointer
  45. */
  46. void async_memcpy_isr_on_rx_done_event(async_memcpy_impl_t *impl);
  47. /**
  48. * @brief Allocate interrupt handle, register default isr handler
  49. *
  50. * @param impl async mcp implementation layer context pointer
  51. * @param int_flags interrupt flags
  52. * @param intr Returned interrupt handle
  53. * @return
  54. * - ESP_OK: Allocate interrupt handle successfully
  55. * - ESP_ERR_INVALID_ARG: Allocate interrupt handle failed because of invalid argument
  56. * - ESP_FAIL: Allocate interrupt handle failed because of other error
  57. */
  58. esp_err_t async_memcpy_impl_allocate_intr(async_memcpy_impl_t *impl, int int_flags, intr_handle_t *intr);
  59. /**
  60. * @brief Initialize async mcp implementation layer
  61. *
  62. * @param impl async mcp implementation layer context pointer
  63. * @param outlink_base Pointer to the first TX descriptor
  64. * @param inlink_base Pointer to the first RX descriptor
  65. * @return Always return ESP_OK
  66. */
  67. esp_err_t async_memcpy_impl_init(async_memcpy_impl_t *impl, dma_descriptor_t *outlink_base, dma_descriptor_t *inlink_base);
  68. /**
  69. * @brief Deinitialize async mcp implementation layer
  70. *
  71. * @param impl async mcp implementation layer context pointer
  72. * @return Always return ESP_OK
  73. */
  74. esp_err_t async_memcpy_impl_deinit(async_memcpy_impl_t *impl);
  75. /**
  76. * @brief Start async mcp (on implementation layer)
  77. *
  78. * @param impl async mcp implementation layer context pointer
  79. * @return Always return ESP_OK
  80. */
  81. esp_err_t async_memcpy_impl_start(async_memcpy_impl_t *impl);
  82. /**
  83. * @brief Stop async mcp (on implementation layer)
  84. *
  85. * @param impl async mcp implementation layer context pointer
  86. * @return Always return ESP_OK
  87. */
  88. esp_err_t async_memcpy_impl_stop(async_memcpy_impl_t *impl);
  89. /**
  90. * @brief Restart async mcp DMA engine
  91. *
  92. * @param impl async mcp implementation layer context pointer
  93. * @return Always return ESP_OK
  94. */
  95. esp_err_t async_memcpy_impl_restart(async_memcpy_impl_t *impl);
  96. /**
  97. * @brief check if buffer address is valid
  98. * @note This is related to underlying target (e.g. on esp32-s2, only buffer located in SRAM is supported)
  99. *
  100. * @param impl async mcp implementation layer context pointer
  101. * @param src Source buffer address
  102. * @param dst Destination buffer address
  103. * @return True if both address are valid
  104. */
  105. bool async_memcpy_impl_is_buffer_address_valid(async_memcpy_impl_t *impl, void *src, void *dst);
  106. /**
  107. * @brief Get the EOF RX descriptor address
  108. *
  109. * @param impl async mcp implementation layer context pointer
  110. * @return Pointer to the EOF RX descriptor
  111. */
  112. dma_descriptor_t *async_memcpy_impl_get_rx_suc_eof_descriptor(async_memcpy_impl_t *impl);