Skip to content

Commit

Permalink
ports/all: deinit builtin modules on soft-reset.
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
  • Loading branch information
pi-anl committed Oct 23, 2024
1 parent f66ea31 commit 3fb1c8b
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ports/esp32/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include "py/repl.h"
#include "py/gc.h"
#include "py/mphal.h"
#include "py/objmodule.h"
#include "shared/readline/readline.h"
#include "shared/runtime/pyexec.h"
#include "shared/timeutils/timeutils.h"
Expand Down Expand Up @@ -182,6 +183,10 @@ void mp_task(void *pvParameter) {
mp_thread_deinit();
#endif

#if MICROPY_MODULE_BUILTIN_INIT
mp_module_builtin_deinit();
#endif

gc_sweep_all();

// Free any native code pointers that point to iRAM.
Expand Down
4 changes: 4 additions & 0 deletions ports/esp8266/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "py/mperrno.h"
#include "py/mphal.h"
#include "py/gc.h"
#include "py/objmodule.h"

#include "extmod/misc.h"
#include "extmod/modmachine.h"
Expand Down Expand Up @@ -88,6 +89,9 @@ static void mp_reset(void) {
}

void soft_reset(void) {
#if MICROPY_MODULE_BUILTIN_INIT
mp_module_builtin_deinit();
#endif
gc_sweep_all();
mp_hal_stdout_tx_str("MPY: soft reboot\r\n");
mp_hal_delay_us(10000); // allow UART to flush output
Expand Down
4 changes: 4 additions & 0 deletions ports/mimxrt/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "py/gc.h"
#include "py/mperrno.h"
#include "py/stackctrl.h"
#include "py/objmodule.h"
#include "shared/readline/readline.h"
#include "shared/runtime/gchelper.h"
#include "shared/runtime/pyexec.h"
Expand Down Expand Up @@ -159,6 +160,9 @@ int main(void) {
machine_uart_deinit_all();
machine_pwm_deinit_all();
soft_timer_deinit();
#if MICROPY_MODULE_BUILTIN_INIT
mp_module_builtin_deinit();
#endif
gc_sweep_all();
mp_deinit();
}
Expand Down
6 changes: 6 additions & 0 deletions ports/nrf/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "py/lexer.h"
#include "py/parse.h"
#include "py/obj.h"
#include "py/objmodule.h"
#include "py/runtime.h"
#include "py/stackctrl.h"
#include "py/gc.h"
Expand Down Expand Up @@ -292,6 +293,11 @@ void NORETURN _start(void) {
pwm_deinit_all();
#endif

#if MICROPY_MODULE_BUILTIN_INIT
mp_module_builtin_deinit();
#endif

gc_sweep_all();
mp_deinit();

printf("MPY: soft reboot\n");
Expand Down
4 changes: 4 additions & 0 deletions ports/qemu/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "py/stackctrl.h"
#include "py/gc.h"
#include "py/mperrno.h"
#include "py/objmodule.h"
#include "shared/runtime/gchelper.h"
#include "shared/runtime/pyexec.h"

Expand Down Expand Up @@ -60,6 +61,9 @@ int main(int argc, char **argv) {

mp_printf(&mp_plat_print, "MPY: soft reboot\n");

#if MICROPY_MODULE_BUILTIN_INIT
mp_module_builtin_deinit();
#endif
gc_sweep_all();
mp_deinit();
}
Expand Down
5 changes: 5 additions & 0 deletions ports/renesas-ra/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "py/gc.h"
#include "py/mperrno.h"
#include "py/mphal.h"
#include "py/objmodule.h"
#include "shared/readline/readline.h"
#include "shared/runtime/pyexec.h"
#include "shared/runtime/softtimer.h"
Expand Down Expand Up @@ -435,6 +436,10 @@ int main(void) {
pyb_thread_deinit();
#endif

#if MICROPY_MODULE_BUILTIN_INIT
mp_module_builtin_deinit();
#endif

MICROPY_BOARD_END_SOFT_RESET(&state);

gc_sweep_all();
Expand Down
5 changes: 5 additions & 0 deletions ports/rp2/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "py/gc.h"
#include "py/mperrno.h"
#include "py/mphal.h"
#include "py/objmodule.h"
#include "extmod/modbluetooth.h"
#include "extmod/modnetwork.h"
#include "shared/readline/readline.h"
Expand Down Expand Up @@ -242,6 +243,10 @@ int main(int argc, char **argv) {
mp_usbd_deinit();
#endif

#if MICROPY_MODULE_BUILTIN_INIT
mp_module_builtin_deinit();
#endif

// Hook for resetting anything right at the end of a soft reset command.
MICROPY_BOARD_END_SOFT_RESET();

Expand Down
4 changes: 4 additions & 0 deletions ports/samd/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "py/gc.h"
#include "py/mperrno.h"
#include "py/stackctrl.h"
#include "py/objmodule.h"
#include "shared/readline/readline.h"
#include "shared/runtime/gchelper.h"
#include "shared/runtime/pyexec.h"
Expand Down Expand Up @@ -98,6 +99,9 @@ void samd_main(void) {
#if MICROPY_HW_ENABLE_USB_RUNTIME_DEVICE
mp_usbd_deinit();
#endif
#if MICROPY_MODULE_BUILTIN_INIT
mp_module_builtin_deinit();
#endif
gc_sweep_all();
#if MICROPY_PY_MACHINE_I2C || MICROPY_PY_MACHINE_SPI || MICROPY_PY_MACHINE_UART
sercom_deinit_all();
Expand Down
5 changes: 5 additions & 0 deletions ports/stm32/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "py/gc.h"
#include "py/mperrno.h"
#include "py/mphal.h"
#include "py/objmodule.h"
#include "shared/readline/readline.h"
#include "shared/runtime/pyexec.h"
#include "shared/runtime/softtimer.h"
Expand Down Expand Up @@ -698,6 +699,10 @@ void stm32_main(uint32_t reset_mode) {
MP_STATE_PORT(pyb_stdio_uart) = NULL;
#endif

#if MICROPY_MODULE_BUILTIN_INIT
mp_module_builtin_deinit();
#endif

MICROPY_BOARD_END_SOFT_RESET(&state);

gc_sweep_all();
Expand Down
5 changes: 5 additions & 0 deletions ports/unix/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "py/builtin.h"
#include "py/repl.h"
#include "py/gc.h"
#include "py/objmodule.h"
#include "py/objstr.h"
#include "py/cstack.h"
#include "py/mphal.h"
Expand Down Expand Up @@ -774,6 +775,10 @@ MP_NOINLINE int main_(int argc, char **argv) {
mp_thread_deinit();
#endif

#if MICROPY_MODULE_BUILTIN_INIT
mp_module_builtin_deinit();
#endif

#if defined(MICROPY_UNIX_COVERAGE)
gc_sweep_all();
#endif
Expand Down
5 changes: 5 additions & 0 deletions ports/zephyr/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include "py/gc.h"
#include "py/mphal.h"
#include "py/stackctrl.h"
#include "py/objmodule.h"
#include "shared/runtime/gchelper.h"
#include "shared/runtime/pyexec.h"
#include "shared/readline/readline.h"
Expand Down Expand Up @@ -172,6 +173,10 @@ int real_main(void) {
gc_collect();
#endif

#if MICROPY_MODULE_BUILTIN_INIT
mp_module_builtin_deinit();
#endif

gc_sweep_all();
mp_deinit();

Expand Down

0 comments on commit 3fb1c8b

Please sign in to comment.