3333#include "gccollect.h"
3434
3535#if defined(PLAT_RDA )
36- unsigned int ReadSP (void )
37- {
36+ unsigned int ReadSP (void ) {
3837 uint32_t res ;
3938 __asm volatile (
4039 "move %0, $29\n"
41- :"=r" (res )
40+ : "=r" (res )
4241 :
4342 :
44- );
45-
43+ );
44+
4645 return res ;
4746}
4847#elif defined(PLAT_ECR6600 )
4948
5049#else
51- unsigned int ReadSP (void )
52- {
50+ unsigned int ReadSP (void ) {
5351 uint32_t res ;
5452 __asm volatile (
5553 "mov %0, r13\n"
56- :"=r" (res )
54+ : "=r" (res )
5755 :
5856 :
59- );
60-
57+ );
58+
6159 return res ;
6260}
6361#endif
6462
65- void gc_stacktop_set (void * ptr )
66- {
63+ void gc_stacktop_set (void * ptr ) {
6764 MP_STATE_PORT (global_stacktop_ptr ) = ptr ;
6865}
6966
@@ -72,31 +69,26 @@ void gc_collect(void) {
7269 #if 0
7370 uint32_t start = mp_hal_ticks_us ();
7471 #endif
75- #if defined(PLAT_ECR6600 )
76- int val = 0 ;
77- #endif
72+ #if defined(PLAT_ECR6600 )
73+ int val = 0 ;
74+ #endif
7875 // start the GC
7976 gc_collect_start ();
80- #if defined(PLAT_ECR6600 )
81- uintptr_t sp = (uintptr_t )& val ;
82- #else
77+ #if defined(PLAT_ECR6600 )
78+ uintptr_t sp = (uintptr_t )& val ;
79+ #else
8380 // get the registers and the sp
8481 uintptr_t sp = (uintptr_t )ReadSP ();
85- #endif
86- if (mp_is_python_thread ())
87- {
82+ #endif
83+ if (mp_is_python_thread ()) {
8884 // trace the stack, including the registers (since they live on the stack in this function)
8985 gc_collect_root ((void * * )sp , ((uint32_t )MP_STATE_THREAD (stack_top ) - sp ) / sizeof (uint32_t ));
90- }
91- else if (NULL != MP_STATE_PORT (global_stacktop_ptr ))
92- {
86+ } else if (NULL != MP_STATE_PORT (global_stacktop_ptr )) {
9387 gc_collect_root ((void * * )sp , ((uint32_t )MP_STATE_PORT (global_stacktop_ptr ) - sp ) / sizeof (uint32_t ));
88+ } else {
89+ // do nothing
9490 }
95- else
96- {
97- //do nothing
98- }
99-
91+
10092 // trace root pointers from any threads
10193 #if MICROPY_PY_THREAD
10294 mp_thread_gc_others ();
@@ -117,4 +109,4 @@ void gc_collect(void) {
117109 #endif
118110}
119111
120- MP_REGISTER_ROOT_POINTER (volatile void * global_stacktop_ptr );
112+ MP_REGISTER_ROOT_POINTER (volatile void * global_stacktop_ptr );
0 commit comments