Skip to content

Commit 80c110e

Browse files
committed
Add more methods to access memory properties
1 parent 65511b2 commit 80c110e

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

Diff for: cores/esp32/Esp.cpp

+34
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,50 @@ void EspClass::restart(void)
112112
esp_restart();
113113
}
114114

115+
uint32_t EspClass::getHeapSize(void)
116+
{
117+
multi_heap_info_t info;
118+
heap_caps_get_info(&info, MALLOC_CAP_INTERNAL);
119+
return info.total_free_bytes + info.total_allocated_bytes;
120+
}
121+
115122
uint32_t EspClass::getFreeHeap(void)
116123
{
117124
return heap_caps_get_free_size(MALLOC_CAP_INTERNAL);
118125
}
119126

127+
uint32_t EspClass::getMinFreeHeap(void)
128+
{
129+
return heap_caps_get_minimum_free_size(MALLOC_CAP_INTERNAL);
130+
}
131+
132+
uint32_t EspClass::getMaxAllocHeap(void)
133+
{
134+
return heap_caps_get_largest_free_block(MALLOC_CAP_INTERNAL);
135+
}
136+
137+
uint32_t EspClass::getPsramSize(void)
138+
{
139+
multi_heap_info_t info;
140+
heap_caps_get_info(&info, MALLOC_CAP_SPIRAM);
141+
return info.total_free_bytes + info.total_allocated_bytes;
142+
}
143+
120144
uint32_t EspClass::getFreePsram(void)
121145
{
122146
return heap_caps_get_free_size(MALLOC_CAP_SPIRAM);
123147
}
124148

149+
uint32_t EspClass::getMinFreePsram(void)
150+
{
151+
return heap_caps_get_minimum_free_size(MALLOC_CAP_SPIRAM);
152+
}
153+
154+
uint32_t EspClass::getMaxAllocPsram(void)
155+
{
156+
return heap_caps_get_largest_free_block(MALLOC_CAP_SPIRAM);
157+
}
158+
125159
uint8_t EspClass::getChipRevision(void)
126160
{
127161
esp_chip_info_t chip_info;

Diff for: cores/esp32/Esp.h

+12-1
Original file line numberDiff line numberDiff line change
@@ -56,8 +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();
6068
uint32_t getFreePsram();
69+
uint32_t getMinFreePsram();
70+
uint32_t getMaxAllocPsram();
71+
6172
uint8_t getChipRevision();
6273
uint8_t getCpuFreqMHz(){ return CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ; }
6374
uint32_t getCycleCount();

0 commit comments

Comments
 (0)