Skip to content

Commit

Permalink
extmod/modmachine: Use sys.exit as implementation of machine.soft_reset.
Browse files Browse the repository at this point in the history
It does the same thing, raising `SystemExit`.

Signed-off-by: Damien George <[email protected]>
  • Loading branch information
dpgeorge committed Jul 20, 2024
1 parent 69c25ea commit 5f3ecc2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 6 additions & 6 deletions extmod/modmachine.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* THE SOFTWARE.
*/

#include "py/builtin.h"
#include "py/runtime.h"

#if MICROPY_PY_MACHINE
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions py/builtin.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__;
Expand Down

0 comments on commit 5f3ecc2

Please sign in to comment.