summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2024-07-18 13:24:27 +1000
committerDamien George <damien@micropython.org>2024-07-20 12:18:07 +1000
commit5f3ecc29f8f0d69d15710ded3278fe055f532517 (patch)
treecbc86f92b5013e21b4f03421d2c16d1e0c552740
parent69c25ea8653566ec97690b5121bd10b753c89426 (diff)
extmod/modmachine: Use sys.exit as implementation of machine.soft_reset.
It does the same thing, raising `SystemExit`. Signed-off-by: Damien George <damien@micropython.org>
-rw-r--r--extmod/modmachine.c12
-rw-r--r--py/builtin.h2
2 files changed, 8 insertions, 6 deletions
diff --git a/extmod/modmachine.c b/extmod/modmachine.c
index a423d8067..590683594 100644
--- a/extmod/modmachine.c
+++ b/extmod/modmachine.c
@@ -24,6 +24,7 @@
* THE SOFTWARE.
*/
+#include "py/builtin.h"
#include "py/runtime.h"
#if MICROPY_PY_MACHINE
@@ -35,6 +36,10 @@
#include "drivers/dht/dht.h"
#endif
+#if !MICROPY_PY_SYS_EXIT
+#error MICROPY_PY_MACHINE requires MICROPY_PY_SYS_EXIT
+#endif
+
// The port must provide implementations of these low-level machine functions.
static void mp_machine_idle(void);
@@ -61,11 +66,6 @@ NORETURN static void mp_machine_deepsleep(size_t n_args, const mp_obj_t *args);
#include MICROPY_PY_MACHINE_INCLUDEFILE
#endif
-static mp_obj_t machine_soft_reset(void) {
- mp_raise_type(&mp_type_SystemExit);
-}
-static MP_DEFINE_CONST_FUN_OBJ_0(machine_soft_reset_obj, machine_soft_reset);
-
#if MICROPY_PY_MACHINE_BOOTLOADER
NORETURN mp_obj_t machine_bootloader(size_t n_args, const mp_obj_t *args) {
mp_machine_bootloader(n_args, args);
@@ -156,7 +156,7 @@ static const mp_rom_map_elem_t machine_module_globals_table[] = {
#endif
// Reset related functions.
- { MP_ROM_QSTR(MP_QSTR_soft_reset), MP_ROM_PTR(&machine_soft_reset_obj) },
+ { MP_ROM_QSTR(MP_QSTR_soft_reset), MP_ROM_PTR(&mp_sys_exit_obj) },
#if MICROPY_PY_MACHINE_BOOTLOADER
{ MP_ROM_QSTR(MP_QSTR_bootloader), MP_ROM_PTR(&machine_bootloader_obj) },
#endif
diff --git a/py/builtin.h b/py/builtin.h
index 81d078980..6efe3e8fa 100644
--- a/py/builtin.h
+++ b/py/builtin.h
@@ -126,6 +126,8 @@ MP_DECLARE_CONST_FUN_OBJ_2(mp_op_getitem_obj);
MP_DECLARE_CONST_FUN_OBJ_3(mp_op_setitem_obj);
MP_DECLARE_CONST_FUN_OBJ_2(mp_op_delitem_obj);
+MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mp_sys_exit_obj);
+
// Modules needed by the runtime.
extern const mp_obj_dict_t mp_module_builtins_globals;
extern const mp_obj_module_t mp_module___main__;