Skip to content

Commit 34ad8fd

Browse files
committed
Backport ESP.getXXXHeap() methods from Core 1.0.4
1 parent a481fac commit 34ad8fd

File tree

2 files changed

+58
-2
lines changed

2 files changed

+58
-2
lines changed

cores/esp32/Esp.cpp

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,53 @@ void EspClass::restart(void)
112112
esp_restart();
113113
}
114114

115+
//uint32_t EspClass::getFreeHeap(void)
116+
//{
117+
// return esp_get_free_heap_size();
118+
//}
119+
120+
uint32_t EspClass::getHeapSize(void)
121+
{
122+
multi_heap_info_t info;
123+
heap_caps_get_info(&info, MALLOC_CAP_INTERNAL);
124+
return info.total_free_bytes + info.total_allocated_bytes;
125+
}
126+
115127
uint32_t EspClass::getFreeHeap(void)
116128
{
117-
return esp_get_free_heap_size();
129+
return heap_caps_get_free_size(MALLOC_CAP_INTERNAL);
130+
}
131+
132+
uint32_t EspClass::getMinFreeHeap(void)
133+
{
134+
return heap_caps_get_minimum_free_size(MALLOC_CAP_INTERNAL);
135+
}
136+
137+
uint32_t EspClass::getMaxAllocHeap(void)
138+
{
139+
return heap_caps_get_largest_free_block(MALLOC_CAP_INTERNAL);
140+
}
141+
142+
uint32_t EspClass::getPsramSize(void)
143+
{
144+
multi_heap_info_t info;
145+
heap_caps_get_info(&info, MALLOC_CAP_SPIRAM);
146+
return info.total_free_bytes + info.total_allocated_bytes;
147+
}
148+
149+
uint32_t EspClass::getFreePsram(void)
150+
{
151+
return heap_caps_get_free_size(MALLOC_CAP_SPIRAM);
152+
}
153+
154+
uint32_t EspClass::getMinFreePsram(void)
155+
{
156+
return heap_caps_get_minimum_free_size(MALLOC_CAP_SPIRAM);
157+
}
158+
159+
uint32_t EspClass::getMaxAllocPsram(void)
160+
{
161+
return heap_caps_get_largest_free_block(MALLOC_CAP_SPIRAM);
118162
}
119163

120164
uint8_t EspClass::getChipRevision(void)

cores/esp32/Esp.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,19 @@ class EspClass
5656
EspClass() {}
5757
~EspClass() {}
5858
void restart();
59-
uint32_t getFreeHeap();
59+
60+
//Internal RAM
61+
uint32_t getHeapSize(); //total heap size
62+
uint32_t getFreeHeap(); //available heap
63+
uint32_t getMinFreeHeap(); //lowest level of free heap since boot
64+
uint32_t getMaxAllocHeap(); //largest block of heap that can be allocated at once
65+
66+
//SPI RAM
67+
uint32_t getPsramSize();
68+
uint32_t getFreePsram();
69+
uint32_t getMinFreePsram();
70+
uint32_t getMaxAllocPsram();
71+
6072
uint8_t getChipRevision();
6173
uint32_t getCpuFreqMHz() { return CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ; }
6274
uint32_t getCycleCount();

0 commit comments

Comments
 (0)