|
| 1 | +#include "string.h" |
| 2 | +#include "esp_heap_caps.h" |
| 3 | +#include "py/runtime.h" |
| 4 | + |
| 5 | +static mp_obj_t esp_memory_print_summary(void) { |
| 6 | + char buffer[128]; |
| 7 | + sprintf(buffer, |
| 8 | + " Biggest / Free / Total\n" |
| 9 | + " SRAM : [%8d / %8d / %8d]\n" |
| 10 | + "PSRAM : [%8d / %8d / %8d]", |
| 11 | + (int)heap_caps_get_largest_free_block(MALLOC_CAP_INTERNAL), |
| 12 | + (int)heap_caps_get_free_size(MALLOC_CAP_INTERNAL), |
| 13 | + (int)heap_caps_get_total_size(MALLOC_CAP_INTERNAL), |
| 14 | + (int)heap_caps_get_largest_free_block(MALLOC_CAP_SPIRAM), |
| 15 | + (int)heap_caps_get_free_size(MALLOC_CAP_SPIRAM), |
| 16 | + (int)heap_caps_get_total_size(MALLOC_CAP_SPIRAM)); |
| 17 | + printf("%s\n", buffer); |
| 18 | + |
| 19 | + return mp_const_none; |
| 20 | +} |
| 21 | +static MP_DEFINE_CONST_FUN_OBJ_0(esp_memory_print_summary_obj, esp_memory_print_summary); |
| 22 | + |
| 23 | +static const mp_rom_map_elem_t esp_memory_module_globals_table[] = { |
| 24 | + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_esp_memory) }, |
| 25 | + { MP_ROM_QSTR(MP_QSTR_print_summary), MP_ROM_PTR(&esp_memory_print_summary_obj) }, |
| 26 | +}; |
| 27 | +static MP_DEFINE_CONST_DICT(esp_memory_module_globals, esp_memory_module_globals_table); |
| 28 | + |
| 29 | +// Define module object. |
| 30 | +const mp_obj_module_t esp_memory_module = { |
| 31 | + .base = { &mp_type_module }, |
| 32 | + .globals = (mp_obj_dict_t *)&esp_memory_module_globals, |
| 33 | +}; |
| 34 | + |
| 35 | +// Register the module to make it available in Python. |
| 36 | +MP_REGISTER_MODULE(MP_QSTR_esp_memory, esp_memory_module); |
0 commit comments