Skip to content

Commit 1788682

Browse files
committed
cc3200/gccollect: Use MP_STATE_THREAD(stack_top) to get top of stack.
1 parent 3b0fbfe commit 1788682

3 files changed

Lines changed: 7 additions & 13 deletions

File tree

cc3200/mptask.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <stdint.h>
2929

3030
#include "py/mpconfig.h"
31+
#include "py/stackctrl.h"
3132
#include "py/obj.h"
3233
#include "py/runtime.h"
3334
#include "py/gc.h"
@@ -104,9 +105,8 @@ static const char fresh_boot_py[] = "# boot.py -- run on boot-up\r\n"
104105
******************************************************************************/
105106

106107
void TASK_Micropython (void *pvParameters) {
107-
// initialize the garbage collector with the top of our stack
108+
// get the top of the stack to initialize the garbage collector
108109
uint32_t sp = gc_helper_get_sp();
109-
gc_collect_init (sp);
110110

111111
bool safeboot = false;
112112
mptask_pre_init();
@@ -122,6 +122,9 @@ void TASK_Micropython (void *pvParameters) {
122122
mp_thread_init();
123123
#endif
124124

125+
// initialise the stack pointer for the main thread (must be done after mp_thread_init)
126+
mp_stack_set_top((void*)sp);
127+
125128
// GC init
126129
gc_init(&_boot, &_eheap);
127130

cc3200/util/gccollect.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,15 @@
2929
#include <stdint.h>
3030

3131
#include "py/mpconfig.h"
32+
#include "py/mpstate.h"
3233
#include "py/gc.h"
3334
#include "py/mpthread.h"
3435
#include "gccollect.h"
3536
#include "gchelper.h"
3637

37-
/******************************************************************************
38-
DECLARE PRIVATE DATA
39-
******************************************************************************/
40-
static uint32_t stackend;
41-
42-
4338
/******************************************************************************
4439
DECLARE PUBLIC FUNCTIONS
4540
******************************************************************************/
46-
void gc_collect_init (uint32_t sp) {
47-
stackend = sp;
48-
}
4941

5042
void gc_collect(void) {
5143
// start the GC
@@ -56,7 +48,7 @@ void gc_collect(void) {
5648
mp_uint_t sp = gc_helper_get_regs_and_sp(regs);
5749

5850
// trace the stack, including the registers (since they live on the stack in this function)
59-
gc_collect_root((void**)sp, (stackend - sp) / sizeof(uint32_t));
51+
gc_collect_root((void**)sp, ((mp_uint_t)MP_STATE_THREAD(stack_top) - sp) / sizeof(uint32_t));
6052

6153
// trace root pointers from any threads
6254
#if MICROPY_PY_THREAD

cc3200/util/gccollect.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,4 @@ extern uint32_t _eheap;
3838
extern uint32_t _stack;
3939
extern uint32_t _estack;
4040

41-
void gc_collect_init (uint32_t sp);
4241
void gc_collect(void);

0 commit comments

Comments
 (0)