Skip to content

Commit 1676ba7

Browse files
committed
pybricks/experimental: Add functions to reboot or intentionally crash the brick
This was being used to test watchdog and exception handler implementation.
1 parent 4484552 commit 1676ba7

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

pybricks/experimental/pb_module_experimental.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "py/runtime.h"
1212
#include "py/mperrno.h"
1313

14+
#include <pbdrv/reset.h>
1415
#include <pbio/util.h>
1516

1617
#include <pybricks/util_mp/pb_obj_helper.h>
@@ -58,9 +59,32 @@ static mp_obj_t experimental_hello_world(size_t n_args, const mp_obj_t *pos_args
5859
// See also experimental_globals_table below. This function object is added there to make it importable.
5960
static MP_DEFINE_CONST_FUN_OBJ_KW(experimental_hello_world_obj, 0, experimental_hello_world);
6061

62+
// pybricks.experimental.reset
63+
static mp_obj_t experimental_reset(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
64+
PB_PARSE_ARGS_FUNCTION(n_args, pos_args, kw_args,
65+
PB_ARG_REQUIRED(reset_type));
66+
67+
mp_int_t reset_type = pb_obj_get_int(reset_type_in);
68+
69+
pbdrv_reset(reset_type);
70+
71+
return mp_const_none;
72+
}
73+
static MP_DEFINE_CONST_FUN_OBJ_KW(experimental_reset_obj, 0, experimental_reset);
74+
75+
// pybricks.experimental.crash
76+
static mp_obj_t experimental_crash(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
77+
__asm__ volatile (".word 0xffffffff");
78+
79+
return mp_const_none;
80+
}
81+
static MP_DEFINE_CONST_FUN_OBJ_KW(experimental_crash_obj, 0, experimental_crash);
82+
6183
static const mp_rom_map_elem_t experimental_globals_table[] = {
6284
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_experimental) },
6385
{ MP_ROM_QSTR(MP_QSTR_hello_world), MP_ROM_PTR(&experimental_hello_world_obj) },
86+
{ MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&experimental_reset_obj) },
87+
{ MP_ROM_QSTR(MP_QSTR_crash), MP_ROM_PTR(&experimental_crash_obj) },
6488
};
6589
static MP_DEFINE_CONST_DICT(pb_module_experimental_globals, experimental_globals_table);
6690

0 commit comments

Comments
 (0)