Skip to content

Commit b75311f

Browse files
committed
WIP selective collect
1 parent b9f631e commit b75311f

32 files changed

Lines changed: 302 additions & 156 deletions

File tree

main.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1134,6 +1134,7 @@ int __attribute__((used)) main(void) {
11341134
}
11351135

11361136
void gc_collect(void) {
1137+
uint32_t start_time = supervisor_ticks_ms32();
11371138
gc_collect_start();
11381139

11391140
mp_uint_t regs[10];
@@ -1175,6 +1176,9 @@ void gc_collect(void) {
11751176
// range.
11761177
gc_collect_root((void **)sp, ((mp_uint_t)port_stack_get_top() - sp) / sizeof(mp_uint_t));
11771178
gc_collect_end();
1179+
uint32_t end_time = supervisor_ticks_ms32();
1180+
uint32_t duration = end_time - start_time;
1181+
console_uart_printf("GC took %dms\r\n", duration);
11781182
}
11791183

11801184
// Ports may provide an implementation of this function if it is needed
@@ -1196,12 +1200,14 @@ static void NORETURN __fatal_error(const char *msg) {
11961200
#if CIRCUITPY_DEBUG == 0
11971201
reset_into_safe_mode(SAFE_MODE_HARD_FAULT);
11981202
#endif
1203+
console_uart_printf(msg);
1204+
console_uart_printf("\r\n");
11991205
while (true) {
12001206
}
12011207
}
12021208

12031209
void MP_WEAK __assert_func(const char *file, int line, const char *func, const char *expr) {
1204-
mp_printf(&mp_plat_print, "Assertion '%s' failed, at file %s:%d\n", expr, file, line);
1210+
console_uart_printf("Assertion '%s' failed, at file %s:%d\r\n", expr, file, line);
12051211
__fatal_error("Assertion failed");
12061212
}
12071213
#endif

ports/raspberrypi/boards/adafruit_fruit_jam/mpconfigboard.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
#define DEFAULT_SPI_BUS_MOSI (&pin_GPIO31)
1818
#define DEFAULT_SPI_BUS_MISO (&pin_GPIO28)
1919

20-
#define DEFAULT_USB_HOST_DATA_PLUS (&pin_GPIO1)
21-
#define DEFAULT_USB_HOST_DATA_MINUS (&pin_GPIO2)
22-
#define DEFAULT_USB_HOST_5V_POWER (&pin_GPIO11)
20+
// #define DEFAULT_USB_HOST_DATA_PLUS (&pin_GPIO1)
21+
// #define DEFAULT_USB_HOST_DATA_MINUS (&pin_GPIO2)
22+
// #define DEFAULT_USB_HOST_5V_POWER (&pin_GPIO11)
2323

2424
#define DEFAULT_DVI_BUS_CLK_DN (&pin_GPIO12)
2525
#define DEFAULT_DVI_BUS_CLK_DP (&pin_GPIO13)
@@ -39,9 +39,9 @@
3939

4040
#define CIRCUITPY_PSRAM_CHIP_SELECT (&pin_GPIO47)
4141

42-
// #define CIRCUITPY_CONSOLE_UART_TX (&pin_GPIO44)
43-
// #define CIRCUITPY_CONSOLE_UART_RX (&pin_GPIO45)
42+
#define CIRCUITPY_CONSOLE_UART_TX (&pin_GPIO44)
43+
#define CIRCUITPY_CONSOLE_UART_RX (&pin_GPIO45)
4444

45-
// #define CIRCUITPY_DEBUG_TINYUSB 0
45+
#define CIRCUITPY_DEBUG_TINYUSB 1
4646

4747
#define CIRCUITPY_SAVES_PARTITION_SIZE (2 * 1024 * 1024)

ports/raspberrypi/supervisor/port.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,8 +438,11 @@ void reset_to_bootloader(void) {
438438
}
439439

440440
void reset_cpu(void) {
441-
watchdog_reboot(0, SRAM_END, 0);
442-
watchdog_start_tick(12);
441+
console_uart_printf("reset cpu\n");
442+
gpio_init(29);
443+
gpio_set_dir(29, GPIO_OUT);
444+
gpio_set_function(29, GPIO_FUNC_SIO);
445+
gpio_put(29, 1);
443446

444447
while (true) {
445448
__wfi();
@@ -570,7 +573,10 @@ __attribute__((used)) void __not_in_flash_func(isr_hardfault)(void) {
570573
// Only safe mode from core 0 which is running CircuitPython. Core 1 faulting
571574
// should not be fatal to CP. (Fingers crossed.)
572575
if (get_core_num() == 0) {
576+
console_uart_printf("Hard fault on core 0\n");
573577
reset_into_safe_mode(SAFE_MODE_HARD_FAULT);
578+
} else {
579+
console_uart_printf("Core 1 faulting\n");
574580
}
575581
while (true) {
576582
asm ("nop;");

ports/unix/mpconfigport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ typedef long mp_off_t;
112112

113113
// Always enable GC.
114114
#define MICROPY_ENABLE_GC (1)
115+
#define MICROPY_ENABLE_SELECTIVE_COLLECT (1)
115116

116117
#if !(defined(MICROPY_GCREGS_SETJMP) || defined(__x86_64__) || defined(__i386__) || defined(__thumb2__) || defined(__thumb__) || defined(__arm__))
117118
// Fall back to setjmp() implementation for discovery of GC pointers in registers.

py/bc.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,14 +302,14 @@ static inline void mp_module_context_alloc_tables(mp_module_context_t *context,
302302
#if MICROPY_EMIT_BYTECODE_USES_QSTR_TABLE
303303
size_t nq = (n_qstr * sizeof(qstr_short_t) + sizeof(mp_uint_t) - 1) / sizeof(mp_uint_t);
304304
size_t no = n_obj;
305-
mp_uint_t *mem = m_new(mp_uint_t, nq + no);
305+
mp_uint_t *mem = m_malloc_items(nq + no);
306306
context->constants.qstr_table = (qstr_short_t *)mem;
307307
context->constants.obj_table = (mp_obj_t *)(mem + nq);
308308
#else
309309
if (n_obj == 0) {
310310
context->constants.obj_table = NULL;
311311
} else {
312-
context->constants.obj_table = m_new(mp_obj_t, n_obj);
312+
context->constants.obj_table = m_malloc_items(n_obj);
313313
}
314314
#endif
315315
}

py/circuitpy_mpconfig.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ extern void common_hal_mcu_enable_interrupts(void);
6262
#define MICROPY_EMIT_X64 (0)
6363
#define MICROPY_ENABLE_DOC_STRING (0)
6464
#define MICROPY_ENABLE_FINALISER (1)
65+
#define MICROPY_ENABLE_SELECTIVE_COLLECT (1)
6566
#define MICROPY_ENABLE_GC (1)
6667
#define MICROPY_ENABLE_PYSTACK (1)
6768
#define MICROPY_TRACKED_ALLOC (CIRCUITPY_SSL_MBEDTLS)

py/compile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3688,7 +3688,7 @@ void mp_compile_to_raw_code(mp_parse_tree_t *parse_tree, qstr source_file, bool
36883688

36893689
mp_obj_t mp_compile(mp_parse_tree_t *parse_tree, qstr source_file, bool is_repl) {
36903690
mp_compiled_module_t cm;
3691-
cm.context = m_new_obj(mp_module_context_t);
3691+
cm.context = m_malloc_with_collect(sizeof(mp_module_context_t));
36923692
cm.context->module.globals = mp_globals_get();
36933693
mp_compile_to_raw_code(parse_tree, source_file, is_repl, &cm);
36943694
// return function that executes the outer module

0 commit comments

Comments
 (0)