Skip to content

Commit 15eeabc

Browse files
committed
Add support for atomvm_free_heap_size key to system_info/1 on STM32 platform
Adds support for getting the current free heap size on STM32 platform using `erlang:system_info(atomvm_free_heap_size)`. Signed-off-by: Winford <winford@object.stream>
1 parent 172895f commit 15eeabc

File tree

1 file changed

+10
-2
lines changed
  • src/platforms/stm32/src/lib

1 file changed

+10
-2
lines changed

src/platforms/stm32/src/lib/sys.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ void *_sbrk_r(struct _reent *reent, ptrdiff_t diff)
8282
return _old_brk;
8383
}
8484

85+
static int sys_get_free_heap()
86+
{
87+
return (int) ((uint8_t *) (((uintptr_t) &_stack - RESERVE_STACK_SIZE))) - (_cur_brk == NULL ? (int) &_ebss : (int) _cur_brk);
88+
}
89+
8590
// Monotonically increasing number of milliseconds from reset
8691
static volatile uint64_t system_millis;
8792

@@ -263,11 +268,14 @@ Context *sys_create_port(GlobalContext *glb, const char *driver_name, term opts)
263268

264269
term sys_get_info(Context *ctx, term key)
265270
{
266-
UNUSED(ctx);
267-
UNUSED(key);
271+
GlobalContext *glb = ctx->global;
272+
if (key == globalcontext_existing_term_from_atom_string(glb, ATOM_STR("\x15", "atomvm_free_heap_size"))) {
273+
return term_from_int32(sys_get_free_heap());
274+
}
268275
return UNDEFINED_ATOM;
269276
}
270277

278+
271279
void sys_enable_flash_cache()
272280
{
273281
flash_unlock_option_bytes();

0 commit comments

Comments
 (0)