esp_heap_caps_init.h 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // Copyright 2017 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. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #pragma once
  14. #include "esp_err.h"
  15. #include "esp_heap_caps.h"
  16. #include "soc/soc_memory_layout.h"
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. /**
  21. * @brief Initialize the capability-aware heap allocator.
  22. *
  23. * This is called once in the IDF startup code. Do not call it
  24. * at other times.
  25. */
  26. void heap_caps_init(void);
  27. /**
  28. * @brief Enable heap(s) in memory regions where the startup stacks are located.
  29. *
  30. * On startup, the pro/app CPUs have a certain memory region they use as stack, so we
  31. * cannot do allocations in the regions these stack frames are. When FreeRTOS is
  32. * completely started, they do not use that memory anymore and heap(s) there can
  33. * be enabled.
  34. */
  35. void heap_caps_enable_nonos_stack_heaps(void);
  36. /**
  37. * @brief Add a region of memory to the collection of heaps at runtime.
  38. *
  39. * Most memory regions are defined in soc_memory_layout.c for the SoC,
  40. * and are registered via heap_caps_init(). Some regions can't be used
  41. * immediately and are later enabled via heap_caps_enable_nonos_stack_heaps().
  42. *
  43. * Call this function to add a region of memory to the heap at some later time.
  44. *
  45. * This function does not consider any of the "reserved" regions or other data in soc_memory_layout, caller needs to
  46. * consider this themselves.
  47. *
  48. * All memory within the region specified by start & end parameters must be otherwise unused.
  49. *
  50. * The capabilities of the newly registered memory will be determined by the start address, as looked up in the regions
  51. * specified in soc_memory_layout.c.
  52. *
  53. * Use heap_caps_add_region_with_caps() to register a region with custom capabilities.
  54. *
  55. * @param start Start address of new region.
  56. * @param end End address of new region.
  57. *
  58. * @return ESP_OK on success, ESP_ERR_INVALID_ARG if a parameter is invalid, ESP_ERR_NOT_FOUND if the
  59. * specified start address doesn't reside in a known region, or any error returned by heap_caps_add_region_with_caps().
  60. */
  61. esp_err_t heap_caps_add_region(intptr_t start, intptr_t end);
  62. /**
  63. * @brief Add a region of memory to the collection of heaps at runtime, with custom capabilities.
  64. *
  65. * Similar to heap_caps_add_region(), only custom memory capabilities are specified by the caller.
  66. *
  67. * @param caps Ordered array of capability masks for the new region, in order of priority. Must have length
  68. * SOC_MEMORY_TYPE_NO_PRIOS. Does not need to remain valid after the call returns.
  69. * @param start Start address of new region.
  70. * @param end End address of new region.
  71. *
  72. * @return
  73. * - ESP_OK on success
  74. * - ESP_ERR_INVALID_ARG if a parameter is invalid
  75. * - ESP_ERR_NO_MEM if no memory to register new heap.
  76. * - ESP_ERR_INVALID_SIZE if the memory region is too small to fit a heap
  77. * - ESP_FAIL if region overlaps the start and/or end of an existing region
  78. */
  79. esp_err_t heap_caps_add_region_with_caps(const uint32_t caps[], intptr_t start, intptr_t end);
  80. #ifdef __cplusplus
  81. }
  82. #endif