|
28 | 28 | #include "runtime.h" |
29 | 29 | #include "repl.h" |
30 | 30 | #include "gc.h" |
| 31 | +#include "gccollect.h" |
31 | 32 | #include "systick.h" |
32 | 33 | #include "led.h" |
33 | 34 | #include "servo.h" |
|
47 | 48 |
|
48 | 49 | int errno; |
49 | 50 |
|
50 | | -extern uint32_t _heap_start; |
51 | | - |
52 | 51 | static FATFS fatfs0; |
53 | 52 |
|
54 | 53 | void flash_error(int n) { |
@@ -180,6 +179,7 @@ static mp_obj_t pyb_info(void) { |
180 | 179 | printf("_ebss=%p\n", &_ebss); |
181 | 180 | printf("_estack=%p\n", &_estack); |
182 | 181 | printf("_etext=%p\n", &_etext); |
| 182 | + printf("_ram_start=%p\n", &_ram_start); |
183 | 183 | printf("_heap_start=%p\n", &_heap_start); |
184 | 184 | } |
185 | 185 |
|
@@ -455,38 +455,6 @@ bool do_file(const char *filename) { |
455 | 455 | } |
456 | 456 | } |
457 | 457 |
|
458 | | -#define RAM_START (0x20000000) // fixed for chip |
459 | | -#define HEAP_END (0x2001c000) // tunable |
460 | | -#define RAM_END (0x20020000) // fixed for chip |
461 | | - |
462 | | -void gc_helper_get_regs_and_clean_stack(machine_uint_t *regs, machine_uint_t heap_end); |
463 | | - |
464 | | -void gc_collect(void) { |
465 | | - uint32_t start = sys_tick_counter; |
466 | | - gc_collect_start(); |
467 | | - gc_collect_root((void**)RAM_START, (((uint32_t)&_heap_start) - RAM_START) / 4); |
468 | | - machine_uint_t regs[10]; |
469 | | - gc_helper_get_regs_and_clean_stack(regs, HEAP_END); |
470 | | - gc_collect_root((void**)HEAP_END, (RAM_END - HEAP_END) / 4); // will trace regs since they now live in this function on the stack |
471 | | - gc_collect_end(); |
472 | | - uint32_t ticks = sys_tick_counter - start; // TODO implement a function that does this properly |
473 | | - |
474 | | - if (0) { |
475 | | - // print GC info |
476 | | - gc_info_t info; |
477 | | - gc_info(&info); |
478 | | - printf("GC@%lu %lums\n", start, ticks); |
479 | | - printf(" %lu total\n", info.total); |
480 | | - printf(" %lu : %lu\n", info.used, info.free); |
481 | | - printf(" 1=%lu 2=%lu m=%lu\n", info.num_1block, info.num_2block, info.max_block); |
482 | | - } |
483 | | -} |
484 | | - |
485 | | -mp_obj_t pyb_gc(void) { |
486 | | - gc_collect(); |
487 | | - return mp_const_none; |
488 | | -} |
489 | | - |
490 | 458 | mp_obj_t pyb_gpio(uint n_args, mp_obj_t *args) { |
491 | 459 | //assert(1 <= n_args && n_args <= 2); |
492 | 460 |
|
@@ -655,7 +623,7 @@ int main(void) { |
655 | 623 | rt_store_attr(m, MP_QSTR_source_dir, rt_make_function_n(1, pyb_source_dir)); |
656 | 624 | rt_store_attr(m, MP_QSTR_main, rt_make_function_n(1, pyb_main)); |
657 | 625 | rt_store_attr(m, MP_QSTR_sync, rt_make_function_n(0, pyb_sync)); |
658 | | - rt_store_attr(m, MP_QSTR_gc, rt_make_function_n(0, pyb_gc)); |
| 626 | + rt_store_attr(m, MP_QSTR_gc, (mp_obj_t)&pyb_gc_obj); |
659 | 627 | rt_store_attr(m, MP_QSTR_delay, rt_make_function_n(1, pyb_delay)); |
660 | 628 | #if MICROPY_HW_HAS_SWITCH |
661 | 629 | rt_store_attr(m, MP_QSTR_switch, (mp_obj_t)&pyb_switch_obj); |
|
0 commit comments