cc3200/gccollect: Use MP_STATE_THREAD(stack_top) to get top of stack.

This commit is contained in:
Damien George 2016-05-31 17:31:28 +01:00
parent 3b0fbfe4e5
commit 17886828c8
3 changed files with 7 additions and 13 deletions

View File

@ -28,6 +28,7 @@
#include <stdint.h>
#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);

View File

@ -29,23 +29,15 @@
#include <stdint.h>
#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

View File

@ -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);