Skip to content

Commit

Permalink
zephyr/main: Use mp_stack API instead of local pointer for stack top.
Browse files Browse the repository at this point in the history
The MP_STATE_THREAD(stack_top) is always available so use it instead of
creating a separate variable.  This also allows gc_collect() to be used as
an independent function, without real_main() being called.
  • Loading branch information
kklimek authored and dpgeorge committed Oct 29, 2019
1 parent a8138b7 commit 53f3cbc
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions ports/zephyr/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
#include TEST
#endif

static char *stack_top;
static char heap[MICROPY_HEAP_SIZE];

void init_zephyr(void) {
Expand Down Expand Up @@ -79,9 +78,7 @@ void init_zephyr(void) {
}

int real_main(void) {
int stack_dummy;
stack_top = (char*)&stack_dummy;
mp_stack_set_top(stack_top);
mp_stack_ctrl_init();
// Make MicroPython's stack limit somewhat smaller than full stack available
mp_stack_set_limit(CONFIG_MAIN_STACK_SIZE - 512);

Expand Down Expand Up @@ -130,7 +127,7 @@ void gc_collect(void) {
// pointers from CPU registers, and thus may function incorrectly.
void *dummy;
gc_collect_start();
gc_collect_root(&dummy, ((mp_uint_t)stack_top - (mp_uint_t)&dummy) / sizeof(mp_uint_t));
gc_collect_root(&dummy, ((mp_uint_t)MP_STATE_THREAD(stack_top) - (mp_uint_t)&dummy) / sizeof(mp_uint_t));
gc_collect_end();
//gc_dump_info();
}
Expand Down

0 comments on commit 53f3cbc

Please sign in to comment.