esp_heap_caps_init.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * SPDX-FileCopyrightText: 2017-2022 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #pragma once
  7. #include "esp_err.h"
  8. #include "esp_heap_caps.h"
  9. #ifdef __cplusplus
  10. extern "C" {
  11. #endif
  12. /**
  13. * @brief Initialize the capability-aware heap allocator.
  14. *
  15. * This is called once in the IDF startup code. Do not call it
  16. * at other times.
  17. */
  18. void heap_caps_init(void);
  19. /**
  20. * @brief Enable heap(s) in memory regions where the startup stacks are located.
  21. *
  22. * On startup, the pro/app CPUs have a certain memory region they use as stack, so we
  23. * cannot do allocations in the regions these stack frames are. When FreeRTOS is
  24. * completely started, they do not use that memory anymore and heap(s) there can
  25. * be enabled.
  26. */
  27. void heap_caps_enable_nonos_stack_heaps(void);
  28. /**
  29. * @brief Add a region of memory to the collection of heaps at runtime.
  30. *
  31. * Most memory regions are defined in soc_memory_layout.c for the SoC,
  32. * and are registered via heap_caps_init(). Some regions can't be used
  33. * immediately and are later enabled via heap_caps_enable_nonos_stack_heaps().
  34. *
  35. * Call this function to add a region of memory to the heap at some later time.
  36. *
  37. * This function does not consider any of the "reserved" regions or other data in soc_memory_layout, caller needs to
  38. * consider this themselves.
  39. *
  40. * All memory within the region specified by start & end parameters must be otherwise unused.
  41. *
  42. * The capabilities of the newly registered memory will be determined by the start address, as looked up in the regions
  43. * specified in soc_memory_layout.c.
  44. *
  45. * Use heap_caps_add_region_with_caps() to register a region with custom capabilities.
  46. *
  47. * @note Please refer to following example for memory regions allowed for addition to heap based on an existing region
  48. * (address range for demonstration purpose only):
  49. @verbatim
  50. Existing region: 0x1000 <-> 0x3000
  51. New region: 0x1000 <-> 0x3000 (Allowed)
  52. New region: 0x1000 <-> 0x2000 (Allowed)
  53. New region: 0x0000 <-> 0x1000 (Allowed)
  54. New region: 0x3000 <-> 0x4000 (Allowed)
  55. New region: 0x0000 <-> 0x2000 (NOT Allowed)
  56. New region: 0x0000 <-> 0x4000 (NOT Allowed)
  57. New region: 0x1000 <-> 0x4000 (NOT Allowed)
  58. New region: 0x2000 <-> 0x4000 (NOT Allowed)
  59. @endverbatim
  60. *
  61. * @param start Start address of new region.
  62. * @param end End address of new region.
  63. *
  64. * @return ESP_OK on success, ESP_ERR_INVALID_ARG if a parameter is invalid, ESP_ERR_NOT_FOUND if the
  65. * specified start address doesn't reside in a known region, or any error returned by heap_caps_add_region_with_caps().
  66. */
  67. esp_err_t heap_caps_add_region(intptr_t start, intptr_t end);
  68. /**
  69. * @brief Add a region of memory to the collection of heaps at runtime, with custom capabilities.
  70. *
  71. * Similar to heap_caps_add_region(), only custom memory capabilities are specified by the caller.
  72. *
  73. * @note Please refer to following example for memory regions allowed for addition to heap based on an existing region
  74. * (address range for demonstration purpose only):
  75. @verbatim
  76. Existing region: 0x1000 <-> 0x3000
  77. New region: 0x1000 <-> 0x3000 (Allowed)
  78. New region: 0x1000 <-> 0x2000 (Allowed)
  79. New region: 0x0000 <-> 0x1000 (Allowed)
  80. New region: 0x3000 <-> 0x4000 (Allowed)
  81. New region: 0x0000 <-> 0x2000 (NOT Allowed)
  82. New region: 0x0000 <-> 0x4000 (NOT Allowed)
  83. New region: 0x1000 <-> 0x4000 (NOT Allowed)
  84. New region: 0x2000 <-> 0x4000 (NOT Allowed)
  85. @endverbatim
  86. *
  87. * @param caps Ordered array of capability masks for the new region, in order of priority. Must have length
  88. * SOC_MEMORY_TYPE_NO_PRIOS. Does not need to remain valid after the call returns.
  89. * @param start Start address of new region.
  90. * @param end End address of new region.
  91. *
  92. * @return
  93. * - ESP_OK on success
  94. * - ESP_ERR_INVALID_ARG if a parameter is invalid
  95. * - ESP_ERR_NO_MEM if no memory to register new heap.
  96. * - ESP_ERR_INVALID_SIZE if the memory region is too small to fit a heap
  97. * - ESP_FAIL if region overlaps the start and/or end of an existing region
  98. */
  99. esp_err_t heap_caps_add_region_with_caps(const uint32_t caps[], intptr_t start, intptr_t end);
  100. #ifdef __cplusplus
  101. }
  102. #endif