heap_memory_layout.h 4.2 KB

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