1
6
7
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
162
163
164
165
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
193
194
195
196
/* ... */
#include <stdlib.h>
#include <stdint.h>
#include "soc/soc.h"
#include "heap_memory_layout.h"
#include "esp_heap_caps.h"
#include "sdkconfig.h"6 includes
#ifdef CONFIG_ESP32_IRAM_AS_8BIT_ACCESSIBLE_MEMORY
#define MALLOC_IRAM_CAP MALLOC_CAP_EXEC|MALLOC_CAP_32BIT|MALLOC_CAP_IRAM_8BIT
#else
#define MALLOC_IRAM_CAP MALLOC_CAP_EXEC|MALLOC_CAP_32BIT
#endif
/* ... */
enum {
SOC_MEMORY_TYPE_DRAM = 0,
SOC_MEMORY_TYPE_DIRAM = 1,
SOC_MEMORY_TYPE_IRAM = 2,
SOC_MEMORY_TYPE_SPIRAM = 3,
SOC_MEMORY_TYPE_RTCRAM = 4,
SOC_MEMORY_TYPE_NUM,
}{ ... };
const soc_memory_type_desc_t soc_memory_types[] = {
[SOC_MEMORY_TYPE_DRAM] = { "DRAM", { MALLOC_CAP_8BIT|MALLOC_CAP_DEFAULT, MALLOC_CAP_INTERNAL|MALLOC_CAP_DMA|MALLOC_CAP_32BIT, 0 }},
[SOC_MEMORY_TYPE_DIRAM] = { "D/IRAM", { 0, MALLOC_CAP_DMA|MALLOC_CAP_8BIT|MALLOC_CAP_INTERNAL|MALLOC_CAP_DEFAULT, MALLOC_CAP_32BIT|MALLOC_CAP_EXEC }},
[SOC_MEMORY_TYPE_IRAM] = { "IRAM", { MALLOC_CAP_INTERNAL|MALLOC_IRAM_CAP, 0, 0 }},
[SOC_MEMORY_TYPE_SPIRAM] = { "SPIRAM", { MALLOC_CAP_SPIRAM|MALLOC_CAP_DEFAULT, 0, MALLOC_CAP_8BIT|MALLOC_CAP_32BIT}},
[SOC_MEMORY_TYPE_RTCRAM] = { "RTCRAM", { MALLOC_CAP_RTCRAM, MALLOC_CAP_8BIT|MALLOC_CAP_DEFAULT, MALLOC_CAP_INTERNAL|MALLOC_CAP_32BIT|MALLOC_CAP_EXEC }},
}{...};
const size_t soc_memory_type_count = sizeof(soc_memory_types)/sizeof(soc_memory_type_desc_t);
/* ... */
const soc_memory_region_t soc_memory_regions[] = {
#ifdef CONFIG_SPIRAM
{ SOC_EXTRAM_DATA_LOW, SOC_EXTRAM_DATA_SIZE, SOC_MEMORY_TYPE_SPIRAM, 0, false},
#endif
{ 0x3FFAE000, 0x2000, SOC_MEMORY_TYPE_DRAM, 0, false},
{ 0x3FFB0000, 0x8000, SOC_MEMORY_TYPE_DRAM, 0, false},
{ 0x3FFB8000, 0x8000, SOC_MEMORY_TYPE_DRAM, 0, false},
{ 0x3FFC0000, 0x2000, SOC_MEMORY_TYPE_DRAM, 0, false},
{ 0x3FFC2000, 0x2000, SOC_MEMORY_TYPE_DRAM, 0, false},
{ 0x3FFC4000, 0x2000, SOC_MEMORY_TYPE_DRAM, 0, false},
{ 0x3FFC6000, 0x2000, SOC_MEMORY_TYPE_DRAM, 0, false},
{ 0x3FFC8000, 0x2000, SOC_MEMORY_TYPE_DRAM, 0, false},
{ 0x3FFCA000, 0x2000, SOC_MEMORY_TYPE_DRAM, 0, false},
{ 0x3FFCC000, 0x2000, SOC_MEMORY_TYPE_DRAM, 0, false},
{ 0x3FFCE000, 0x2000, SOC_MEMORY_TYPE_DRAM, 0, false},
{ 0x3FFD0000, 0x2000, SOC_MEMORY_TYPE_DRAM, 0, false},
{ 0x3FFD2000, 0x2000, SOC_MEMORY_TYPE_DRAM, 0, false},
{ 0x3FFD4000, 0x2000, SOC_MEMORY_TYPE_DRAM, 0, false},
{ 0x3FFD6000, 0x2000, SOC_MEMORY_TYPE_DRAM, 0, false},
{ 0x3FFD8000, 0x2000, SOC_MEMORY_TYPE_DRAM, 0, false},
{ 0x3FFDA000, 0x2000, SOC_MEMORY_TYPE_DRAM, 0, false},
{ 0x3FFDC000, 0x2000, SOC_MEMORY_TYPE_DRAM, 0, false},
{ 0x3FFDE000, 0x2000, SOC_MEMORY_TYPE_DRAM, 0, false},
{ 0x3FFE0000, 0x4000, SOC_MEMORY_TYPE_DIRAM, 0x400BC000,true},
{ 0x3FFE4000, 0x4000, SOC_MEMORY_TYPE_DIRAM, 0x400B8000,true},
{ 0x3FFE8000, 0x8000, SOC_MEMORY_TYPE_DIRAM, 0x400B0000,true},
{ 0x3FFF0000, 0x8000, SOC_MEMORY_TYPE_DIRAM, 0x400A8000,true},
{ 0x3FFF8000, 0x4000, SOC_MEMORY_TYPE_DIRAM, 0x400A4000,true},
{ 0x3FFFC000, 0x4000, SOC_MEMORY_TYPE_DIRAM, 0x400A0000,true},
{ 0x40070000, 0x8000, SOC_MEMORY_TYPE_IRAM, 0, false},
{ 0x40078000, 0x8000, SOC_MEMORY_TYPE_IRAM, 0, false},
{ 0x40080000, 0x2000, SOC_MEMORY_TYPE_IRAM, 0, false},
{ 0x40082000, 0x2000, SOC_MEMORY_TYPE_IRAM, 0, false},
{ 0x40084000, 0x2000, SOC_MEMORY_TYPE_IRAM, 0, false},
{ 0x40086000, 0x2000, SOC_MEMORY_TYPE_IRAM, 0, false},
{ 0x40088000, 0x2000, SOC_MEMORY_TYPE_IRAM, 0, false},
{ 0x4008A000, 0x2000, SOC_MEMORY_TYPE_IRAM, 0, false},
{ 0x4008C000, 0x2000, SOC_MEMORY_TYPE_IRAM, 0, false},
{ 0x4008E000, 0x2000, SOC_MEMORY_TYPE_IRAM, 0, false},
{ 0x40090000, 0x2000, SOC_MEMORY_TYPE_IRAM, 0, false},
{ 0x40092000, 0x2000, SOC_MEMORY_TYPE_IRAM, 0, false},
{ 0x40094000, 0x2000, SOC_MEMORY_TYPE_IRAM, 0, false},
{ 0x40096000, 0x2000, SOC_MEMORY_TYPE_IRAM, 0, false},
{ 0x40098000, 0x2000, SOC_MEMORY_TYPE_IRAM, 0, false},
{ 0x4009A000, 0x2000, SOC_MEMORY_TYPE_IRAM, 0, false},
{ 0x4009C000, 0x2000, SOC_MEMORY_TYPE_IRAM, 0, false},
{ 0x4009E000, 0x2000, SOC_MEMORY_TYPE_IRAM, 0, false},
#ifdef CONFIG_ESP_SYSTEM_ALLOW_RTC_FAST_MEM_AS_HEAP
{ SOC_RTC_DRAM_LOW, 0x2000, SOC_MEMORY_TYPE_RTCRAM, 0, false},
#endif
}{...};
const size_t soc_memory_region_count = sizeof(soc_memory_regions)/sizeof(soc_memory_region_t);
/* ... */
SOC_RESERVE_MEMORY_REGION(SOC_CACHE_PRO_LOW, SOC_CACHE_PRO_HIGH, cpu0_cache);
#ifndef CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE
SOC_RESERVE_MEMORY_REGION(SOC_CACHE_APP_LOW, SOC_CACHE_APP_HIGH, cpu1_cache);
#endif
/* ... */
SOC_RESERVE_MEMORY_REGION(0x3ffe0000, 0x3ffe0440, rom_pro_data);
#ifndef CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE
SOC_RESERVE_MEMORY_REGION(0x3ffe3f20, 0x3ffe4350, rom_app_data);
#endif
SOC_RESERVE_MEMORY_REGION(0x3ffae000, 0x3ffae6e0, rom_data);
#if CONFIG_ESP32_MEMMAP_TRACEMEM
#if CONFIG_ESP32_MEMMAP_TRACEMEM_TWOBANKS
SOC_RESERVE_MEMORY_REGION(0x3fff8000, 0x40000000, trace_mem);
#else
SOC_RESERVE_MEMORY_REGION(0x3fffc000, 0x40000000, trace_mem);
#endif/* ... */
#endif
#ifdef CONFIG_SPIRAM
/* ... */
SOC_RESERVE_MEMORY_REGION(SOC_EXTRAM_DATA_LOW, SOC_EXTRAM_DATA_HIGH, spi_ram);/* ... */
#endif
extern int _data_start, _heap_start, _heap_end, _iram_start, _iram_end, _rtc_force_fast_end, _rtc_noinit_end;
extern int _rtc_fast_reserved_start, _rtc_fast_reserved_end;
extern int _rtc_slow_reserved_start, _rtc_slow_reserved_end;
SOC_RESERVE_MEMORY_REGION((intptr_t)&_data_start, (intptr_t)&_heap_start, dram_data);
SOC_RESERVE_MEMORY_REGION((intptr_t)&_iram_start, (intptr_t)&_iram_end, iram_code);
#ifdef CONFIG_ESP_SYSTEM_ESP32_SRAM1_REGION_AS_IRAM
SOC_RESERVE_MEMORY_REGION((intptr_t) &_heap_end, 0x40000000, sram1_iram);
#endif
#ifdef CONFIG_ESP_SYSTEM_ALLOW_RTC_FAST_MEM_AS_HEAP
#ifdef CONFIG_ESP32_RTCDATA_IN_FAST_MEM
SOC_RESERVE_MEMORY_REGION(SOC_RTC_DRAM_LOW, (intptr_t)&_rtc_noinit_end, rtcram_data);
#else
SOC_RESERVE_MEMORY_REGION(SOC_RTC_DRAM_LOW, (intptr_t)&_rtc_force_fast_end, rtcram_data);
#endif/* ... */
#endif
SOC_RESERVE_MEMORY_REGION((intptr_t)&_rtc_fast_reserved_start, (intptr_t)&_rtc_fast_reserved_end, rtc_fast_reserved_data);
SOC_RESERVE_MEMORY_REGION((intptr_t)&_rtc_slow_reserved_start, (intptr_t)&_rtc_slow_reserved_end, rtc_reserved_data);