esp_cache_private.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. #include "esp_bit_defs.h"
  11. #ifdef __cplusplus
  12. extern "C" {
  13. #endif
  14. /**
  15. * Cache malloc flags
  16. */
  17. /**
  18. * @brief Memory is in PSRAM
  19. */
  20. #define ESP_CACHE_MALLOC_FLAG_PSRAM BIT(0)
  21. /**
  22. * @brief Memory is capable to be accessed by DMA
  23. */
  24. #define ESP_CACHE_MALLOC_FLAG_DMA BIT(1)
  25. /**
  26. * @brief Helper function for malloc a cache aligned data memory buffer
  27. *
  28. * @param[in] size Size in bytes, the amount of memory to allocate
  29. * @param[in] flags Flags, see `ESP_CACHE_MALLOC_FLAG_x`
  30. * @param[out] out_ptr A pointer to the memory allocated successfully
  31. * @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.
  32. *
  33. * @return
  34. * - ESP_OK:
  35. * - ESP_ERR_INVALID_ARG: Invalid argument
  36. * - ESP_ERR_NO_MEM: No enough memory for allocation
  37. */
  38. esp_err_t esp_cache_aligned_malloc(size_t size, uint32_t flags, void **out_ptr, size_t *actual_size);
  39. /**
  40. * @brief Helper function for calloc a cache aligned data memory buffer
  41. *
  42. * @param[in] n Number of continuing chunks of memory to allocate
  43. * @param[in] size Size of one chunk, in bytes
  44. * @param[in] flags Flags, see `ESP_CACHE_MALLOC_FLAG_x`
  45. * @param[out] out_ptr A pointer to the memory allocated successfully
  46. * @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.
  47. *
  48. * @return
  49. * - ESP_OK:
  50. * - ESP_ERR_INVALID_ARG: Invalid argument
  51. * - ESP_ERR_NO_MEM: No enough memory for allocation
  52. */
  53. esp_err_t esp_cache_aligned_calloc(size_t n, size_t size, uint32_t flags, void **out_ptr, size_t *actual_size);
  54. /**
  55. * @brief Get Cache alignment requirement for data
  56. *
  57. * @param[in] flags Flags, see `ESP_CACHE_MALLOC_FLAG_x`
  58. * @param[out] out_alignment Alignment
  59. *
  60. * @return
  61. * - ESP_OK:
  62. * - ESP_ERR_INVALID_ARG: Invalid argument
  63. */
  64. esp_err_t esp_cache_get_alignment(uint32_t flags, size_t *out_alignment);
  65. #ifdef __cplusplus
  66. }
  67. #endif