esp_heap_caps_init.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. * @param start Start address of new region.
  48. * @param end End address of new region.
  49. *
  50. * @return ESP_OK on success, ESP_ERR_INVALID_ARG if a parameter is invalid, ESP_ERR_NOT_FOUND if the
  51. * specified start address doesn't reside in a known region, or any error returned by heap_caps_add_region_with_caps().
  52. */
  53. esp_err_t heap_caps_add_region(intptr_t start, intptr_t end);
  54. /**
  55. * @brief Add a region of memory to the collection of heaps at runtime, with custom capabilities.
  56. *
  57. * Similar to heap_caps_add_region(), only custom memory capabilities are specified by the caller.
  58. *
  59. * @param caps Ordered array of capability masks for the new region, in order of priority. Must have length
  60. * SOC_MEMORY_TYPE_NO_PRIOS. Does not need to remain valid after the call returns.
  61. * @param start Start address of new region.
  62. * @param end End address of new region.
  63. *
  64. * @return
  65. * - ESP_OK on success
  66. * - ESP_ERR_INVALID_ARG if a parameter is invalid
  67. * - ESP_ERR_NO_MEM if no memory to register new heap.
  68. * - ESP_ERR_INVALID_SIZE if the memory region is too small to fit a heap
  69. * - ESP_FAIL if region overlaps the start and/or end of an existing region
  70. */
  71. esp_err_t heap_caps_add_region_with_caps(const uint32_t caps[], intptr_t start, intptr_t end);
  72. #ifdef __cplusplus
  73. }
  74. #endif