cpu/esp8266: changes for common heap command

This commit is contained in:
Gunar Schorcht 2019-02-03 15:27:59 +01:00 committed by Schorcht
parent 140987fc3a
commit 056a223c33
2 changed files with 10 additions and 28 deletions

View File

@ -10,7 +10,6 @@ ifneq (, $(filter esp_sdk, $(USEMODULE)))
LINKFLAGS += -Wl,-wrap=_malloc_r LINKFLAGS += -Wl,-wrap=_malloc_r
LINKFLAGS += -Wl,-wrap=_free_r LINKFLAGS += -Wl,-wrap=_free_r
LINKFLAGS += -Wl,-wrap=_realloc_r LINKFLAGS += -Wl,-wrap=_realloc_r
LINKFLAGS += -Wl,-wrap=mallinfo
endif endif
ifneq (, $(filter esp_spiffs, $(USEMODULE))) ifneq (, $(filter esp_spiffs, $(USEMODULE)))

View File

@ -74,7 +74,9 @@ void *__real_realloc(void *ptr, size_t size);
void *__real__malloc_r (struct _reent *r, size_t size); void *__real__malloc_r (struct _reent *r, size_t size);
void __real__free_r (struct _reent *r, void *ptr); void __real__free_r (struct _reent *r, void *ptr);
void *__real__realloc_r (struct _reent *r, void *ptr, size_t size); void *__real__realloc_r (struct _reent *r, void *ptr, size_t size);
struct mallinfo __real_mallinfo(void);
extern uint8_t _eheap; /* end of heap (defined in esp8266.riot-os.app.ld) */
extern uint8_t _sheap; /* start of heap (defined in esp8266.riot-os.app.ld) */
void* IRAM __wrap_malloc(size_t size) void* IRAM __wrap_malloc(size_t size)
{ {
@ -136,27 +138,6 @@ unsigned int get_free_heap_size (void)
return xPortGetFreeHeapSize(); return xPortGetFreeHeapSize();
} }
extern uint8_t _eheap; /* end of heap (defined in esp8266.riot-os.app.ld) */
extern uint8_t _sheap; /* start of heap (defined in esp8266.riot-os.app.ld) */
struct mallinfo __wrap_mallinfo(void)
{
struct mallinfo mi;
mi.arena = &_eheap - &_sheap;
mi.fordblks = get_free_heap_size();
mi.uordblks = mi.arena - mi.fordblks;
mi.keepcost = mi.fordblks;
return mi;
}
void heap_stats(void)
{
struct mallinfo minfo = __wrap_mallinfo();
ets_printf("heap: %d (used %d, free %d)\n",
minfo.arena, minfo.uordblks, minfo.fordblks);
}
void IRAM syscalls_init (void) void IRAM syscalls_init (void)
{ {
} }
@ -347,15 +328,17 @@ extern char _sheap; /* start of heap (defined in esp8266.riot-os.app.ld) */
unsigned int IRAM get_free_heap_size (void) unsigned int IRAM get_free_heap_size (void)
{ {
return (_cheap) ? &_eheap - _cheap : 0; struct mallinfo minfo = mallinfo();
return &_eheap - &_sheap - minfo.uordblks;
} }
#endif /* MODULE_ESP_SDK */
void heap_stats(void) void heap_stats(void)
{ {
struct mallinfo minfo = mallinfo(); ets_printf("heap: %u (used %d, free %u) [bytes]\n",
ets_printf("heap: %u (free %u), ", &_eheap - &_sheap, get_free_heap_size()); &_eheap - &_sheap, &_eheap - &_sheap - get_free_heap_size(),
ets_printf("sysmem: %d (used %d, free %d)\n", get_free_heap_size());
minfo.arena, minfo.uordblks, minfo.fordblks);
} }
#endif /* MODULE_ESP_SDK */ #endif /* MODULE_ESP_SDK */