esp_dma_utils.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #pragma once
  7. #include <stdlib.h>
  8. #include <stdint.h>
  9. #include "esp_err.h"
  10. #ifdef __cplusplus
  11. extern "C" {
  12. #endif
  13. /**
  14. * DMA malloc flags
  15. */
  16. /**
  17. * @brief Memory is in PSRAM
  18. */
  19. #define ESP_DMA_MALLOC_FLAG_PSRAM BIT(0)
  20. /**
  21. * @brief Helper function for malloc a DMA capable memory buffer
  22. *
  23. * @param[in] size Size in bytes, the amount of memory to allocate
  24. * @param[in] flags Flags, see `ESP_DMA_MALLOC_FLAG_x`
  25. * @param[out] out_ptr A pointer to the memory allocated successfully
  26. * @param[out] actual_size Actual size for allocation in bytes, when the size you specified doesn't meet the DMA alignment requirements, this value might be bigger than the size you specified. Set null if you don't care this value.
  27. *
  28. * @return
  29. * - ESP_OK:
  30. * - ESP_ERR_INVALID_ARG: Invalid argument
  31. * - ESP_ERR_NO_MEM: No enough memory for allocation
  32. */
  33. esp_err_t esp_dma_malloc(size_t size, uint32_t flags, void **out_ptr, size_t *actual_size);
  34. /**
  35. * @brief Helper function for calloc a DMA capable memory buffer
  36. *
  37. * @param[in] n Number of continuing chunks of memory to allocate
  38. * @param[in] size Size of one chunk, in bytes
  39. * @param[in] flags Flags, see `ESP_DMA_MALLOC_FLAG_x`
  40. * @param[out] out_ptr A pointer to the memory allocated successfully
  41. * @param[out] actual_size Actual size for allocation in bytes, when the size you specified doesn't meet the cache alignment requirements, this value might be bigger than the size you specified. Set null if you don't care this value.
  42. *
  43. * @return
  44. * - ESP_OK:
  45. * - ESP_ERR_INVALID_ARG: Invalid argument
  46. * - ESP_ERR_NO_MEM: No enough memory for allocation
  47. */
  48. esp_err_t esp_dma_calloc(size_t n, size_t size, uint32_t flags, void **out_ptr, size_t *actual_size);
  49. #ifdef __cplusplus
  50. }
  51. #endif