memory: track biggest free block instead of total RAM

This accounts for memory fragmentation
Tested on multiple runs - restarts all good.
This commit is contained in:
irriden
2023-07-05 20:26:11 +00:00
parent 215efba46c
commit 0b7920b79a

View File

@@ -225,9 +225,10 @@ pub fn make_event_loop(
fn restart_esp_if_memory_low() {
unsafe {
let size = esp_idf_sys::heap_caps_get_free_size(4);
let threshold = 65000;
log::info!("Available DRAM: {}, Restart Threshold: {}", size, threshold);
if size < threshold {
let block = esp_idf_sys::heap_caps_get_largest_free_block(4);
let threshold = 35000;
log::info!("Available DRAM: {}, Max block: {}, Restart Threshold: {}", size, block, threshold);
if block < threshold {
log::info!("Restarting esp!");
esp_idf_sys::esp_restart();
}