heap_memory_layout.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * SPDX-FileCopyrightText: 2010-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 <stdbool.h>
  10. #include "sdkconfig.h"
  11. #define SOC_MEMORY_TYPE_NO_PRIOS 3
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15. /* Type descriptor holds a description for a particular type of memory on a particular SoC.
  16. */
  17. typedef struct {
  18. const char *name; ///< Name of this memory type
  19. uint32_t caps[SOC_MEMORY_TYPE_NO_PRIOS]; ///< Capabilities for this memory type (as a prioritised set)
  20. } soc_memory_type_desc_t;
  21. /* Constant table of tag descriptors for all this SoC's tags */
  22. extern const soc_memory_type_desc_t soc_memory_types[];
  23. extern const size_t soc_memory_type_count;
  24. /* Region descriptor holds a description for a particular region of memory on a particular SoC.
  25. */
  26. typedef struct {
  27. intptr_t start; ///< Start address of the region
  28. size_t size; ///< Size of the region in bytes
  29. size_t type; ///< Type of the region (index into soc_memory_types array)
  30. intptr_t iram_address; ///< If non-zero, is equivalent address in IRAM
  31. bool startup_stack; ///< If true, memory of this type is used for ROM stack during startup
  32. } soc_memory_region_t;
  33. extern const soc_memory_region_t soc_memory_regions[];
  34. extern const size_t soc_memory_region_count;
  35. /* Region descriptor holds a description for a particular region of
  36. memory reserved on this SoC for a particular use (ie not available
  37. for stack/heap usage.) */
  38. typedef struct {
  39. intptr_t start;
  40. intptr_t end;
  41. } soc_reserved_region_t;
  42. /* Use this macro to reserved a fixed region of RAM (hardcoded addresses)
  43. * for a particular purpose.
  44. *
  45. * Usually used to mark out memory addresses needed for hardware or ROM code
  46. * purposes.
  47. *
  48. * Don't call this macro from user code which can use normal C static allocation
  49. * instead.
  50. *
  51. * @param START Start address to be reserved.
  52. * @param END One after the address of the last byte to be reserved. (ie length of
  53. * the reserved region is (END - START) in bytes.
  54. * @param NAME Name for the reserved region. Must be a valid variable name,
  55. * unique to this source file.
  56. */
  57. #define SOC_RESERVE_MEMORY_REGION(START, END, NAME) \
  58. __attribute__((section(".reserved_memory_address"))) __attribute__((used)) \
  59. static soc_reserved_region_t reserved_region_##NAME = { START, END };
  60. /* Return available memory regions for this SoC. Each available memory
  61. * region is a contiguous piece of memory which is not being used by
  62. * static data, used by ROM code, or reserved by a component using
  63. * the SOC_RESERVE_MEMORY_REGION() macro.
  64. *
  65. * This result is soc_memory_regions[] minus all regions reserved
  66. * via the SOC_RESERVE_MEMORY_REGION() macro (which may also split
  67. * some regions up.)
  68. *
  69. * At startup, all available memory returned by this function is
  70. * registered as heap space.
  71. *
  72. * @note OS-level startup function only, not recommended to call from
  73. * app code.
  74. *
  75. * @param regions Pointer to an array for reading available regions into.
  76. * Size of the array should be at least the result of
  77. * soc_get_available_memory_region_max_count(). Entries in the array
  78. * will be ordered by memory address.
  79. *
  80. * @return Number of entries copied to 'regions'. Will be no greater than
  81. * the result of soc_get_available_memory_region_max_count().
  82. */
  83. size_t soc_get_available_memory_regions(soc_memory_region_t *regions);
  84. /* Return the maximum number of available memory regions which could be
  85. * returned by soc_get_available_memory_regions(). Used to size the
  86. * array passed to that function.
  87. */
  88. size_t soc_get_available_memory_region_max_count(void);
  89. #ifdef __cplusplus
  90. }
  91. #endif