From 17886828c8cb682092b8ba18db0723598c3a7b73 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 31 May 2016 17:31:28 +0100 Subject: [PATCH] cc3200/gccollect: Use MP_STATE_THREAD(stack_top) to get top of stack. --- cc3200/mptask.c | 7 +++++-- cc3200/util/gccollect.c | 12 ++---------- cc3200/util/gccollect.h | 1 - 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/cc3200/mptask.c b/cc3200/mptask.c index 80d76f90e9..eb673b08cf 100644 --- a/cc3200/mptask.c +++ b/cc3200/mptask.c @@ -28,6 +28,7 @@ #include #include "py/mpconfig.h" +#include "py/stackctrl.h" #include "py/obj.h" #include "py/runtime.h" #include "py/gc.h" @@ -104,9 +105,8 @@ static const char fresh_boot_py[] = "# boot.py -- run on boot-up\r\n" ******************************************************************************/ void TASK_Micropython (void *pvParameters) { - // initialize the garbage collector with the top of our stack + // get the top of the stack to initialize the garbage collector uint32_t sp = gc_helper_get_sp(); - gc_collect_init (sp); bool safeboot = false; mptask_pre_init(); @@ -122,6 +122,9 @@ soft_reset: mp_thread_init(); #endif + // initialise the stack pointer for the main thread (must be done after mp_thread_init) + mp_stack_set_top((void*)sp); + // GC init gc_init(&_boot, &_eheap); diff --git a/cc3200/util/gccollect.c b/cc3200/util/gccollect.c index bc9cba4b8d..8963852f7a 100644 --- a/cc3200/util/gccollect.c +++ b/cc3200/util/gccollect.c @@ -29,23 +29,15 @@ #include #include "py/mpconfig.h" +#include "py/mpstate.h" #include "py/gc.h" #include "py/mpthread.h" #include "gccollect.h" #include "gchelper.h" -/****************************************************************************** -DECLARE PRIVATE DATA - ******************************************************************************/ -static uint32_t stackend; - - /****************************************************************************** DECLARE PUBLIC FUNCTIONS ******************************************************************************/ -void gc_collect_init (uint32_t sp) { - stackend = sp; -} void gc_collect(void) { // start the GC @@ -56,7 +48,7 @@ void gc_collect(void) { mp_uint_t sp = gc_helper_get_regs_and_sp(regs); // trace the stack, including the registers (since they live on the stack in this function) - gc_collect_root((void**)sp, (stackend - sp) / sizeof(uint32_t)); + gc_collect_root((void**)sp, ((mp_uint_t)MP_STATE_THREAD(stack_top) - sp) / sizeof(uint32_t)); // trace root pointers from any threads #if MICROPY_PY_THREAD diff --git a/cc3200/util/gccollect.h b/cc3200/util/gccollect.h index 24cd60288e..281e84aa83 100644 --- a/cc3200/util/gccollect.h +++ b/cc3200/util/gccollect.h @@ -38,5 +38,4 @@ extern uint32_t _eheap; extern uint32_t _stack; extern uint32_t _estack; -void gc_collect_init (uint32_t sp); void gc_collect(void);