@@ -35,7 +35,7 @@ typedef struct _openpie_syscall_result_t {
3535#define _debug (s ) __syscall2(SYS_DEBUG, (int)s, (int)strlen(s));
3636mp_obj_t usystem_debug (mp_obj_t );
3737
38- mp_obj_t parse_2 (void * ret ) {
38+ mp_obj_t parse_msgpack_result (void * ret ) {
3939 if (ret == NULL ) {
4040 return mp_const_none ;
4141 } else {
@@ -168,7 +168,7 @@ STATIC mp_obj_t usystem_invoke(size_t n_args, const mp_obj_t *args) {
168168
169169 void * result = (void * ) __syscall3 (SYS_INVOKE , 0 , (int ) data , (int ) size );
170170
171- mp_obj_t vals = parse_2 (result );
171+ mp_obj_t vals = parse_msgpack_result (result );
172172
173173 size_t count = 0 ;
174174 mp_obj_t * items = NULL ;
@@ -206,18 +206,25 @@ MP_DEFINE_CONST_FUN_OBJ_VAR(usystem_invoke_obj, 2, usystem_invoke);
206206STATIC mp_obj_t usystem_signal (mp_obj_t ticks_obj ) {
207207 mp_int_t ticks = mp_obj_get_int (ticks_obj );
208208 void * result = (void * ) __syscall2 (SYS_SIGNAL , SYS_SIGNAL_REQUEST , (int ) ticks ); // sleep with ticks
209- return parse_2 (result );
209+ return parse_msgpack_result (result );
210210}
211211
212212MP_DEFINE_CONST_FUN_OBJ_1 (usystem_signal_obj , usystem_signal );
213213
214214
215- STATIC mp_obj_t usystem_components () {
216- void * result = (byte * ) __syscall1 (SYS_REQUEST , SYS_REQUEST_COMPONENTS );
217- return parse_2 (result );
215+ STATIC mp_obj_t usystem_components (size_t n_args , const mp_obj_t * args ) {
216+ if (n_args == 0 ) {
217+ void * result = (byte * ) __syscall3 (SYS_REQUEST , SYS_REQUEST_COMPONENTS , 0 , 0 );
218+ return parse_msgpack_result (result );
219+ } else {
220+ size_t len = 0 ;
221+ const char * buf = mp_obj_str_get_data (args [0 ], & len );
222+ void * result = (byte * )__syscall3 (SYS_REQUEST , SYS_REQUEST_COMPONENTS , (int ) buf , (int ) len );
223+ return parse_msgpack_result (result );
224+ }
218225}
219226
220- MP_DEFINE_CONST_FUN_OBJ_0 (usystem_components_obj , usystem_components );
227+ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN (usystem_components_obj , 0 , 1 , usystem_components );
221228
222229
223230STATIC mp_obj_t usystem_methods (mp_obj_t address_obj ) {
@@ -231,7 +238,7 @@ STATIC mp_obj_t usystem_methods(mp_obj_t address_obj) {
231238 msgpack_dump_close (writer );
232239
233240 void * result = (void * ) __syscall3 (SYS_REQUEST , SYS_REQUEST_METHODS , (int ) data , (int ) size );
234- return parse_2 (result );
241+ return parse_msgpack_result (result );
235242}
236243
237244MP_DEFINE_CONST_FUN_OBJ_1 (usystem_methods_obj , usystem_methods );
@@ -249,7 +256,7 @@ STATIC mp_obj_t usystem_annotations(mp_obj_t address_obj, mp_obj_t method_obj) {
249256 msgpack_dump_close (writer );
250257
251258 void * result = (void * ) __syscall3 (SYS_REQUEST , SYS_REQUEST_ANNOTATIONS , (int ) data , (int ) size );
252- return parse_2 (result );
259+ return parse_msgpack_result (result );
253260}
254261
255262MP_DEFINE_CONST_FUN_OBJ_2 (usystem_annotations_obj , usystem_annotations );
@@ -271,6 +278,16 @@ mp_obj_t usystem_reboot() {
271278MP_DEFINE_CONST_FUN_OBJ_0 (usystem_reboot_obj , usystem_reboot );
272279
273280
281+ mp_obj_t usystem_crash (mp_obj_t message_obj ) {
282+ size_t len = 0 ;
283+ const char * message = mp_obj_str_get_data (message_obj , & len );
284+ __syscall3 (SYS_CONTROL , SYS_CONTROL_CRASH , (int ) message , (int ) len );
285+ __fatal_error ("crash failure" );
286+ }
287+
288+ MP_DEFINE_CONST_FUN_OBJ_1 (usystem_crash_obj , usystem_crash );
289+
290+
274291mp_obj_t usystem_debug (mp_obj_t obj ) {
275292 size_t len = 0 ;
276293 const char * buf = mp_obj_str_get_data (obj , & len );
@@ -299,6 +316,7 @@ STATIC const mp_rom_map_elem_t machine_module_globals_table[] = {
299316 {MP_ROM_QSTR (MP_QSTR_annotations ), MP_ROM_PTR (& usystem_annotations_obj )},
300317 {MP_ROM_QSTR (MP_QSTR_shutdown ), MP_ROM_PTR (& usystem_shutdown_obj )},
301318 {MP_ROM_QSTR (MP_QSTR_reboot ), MP_ROM_PTR (& usystem_reboot_obj )},
319+ {MP_ROM_QSTR (MP_QSTR_crash ), MP_ROM_PTR (& usystem_crash_obj )},
302320 {MP_ROM_QSTR (MP_QSTR_debug ), MP_ROM_PTR (& usystem_debug_obj )},
303321
304322 {MP_ROM_QSTR (MP_QSTR_mem8 ), MP_ROM_PTR (& machine_mem8_obj )},
0 commit comments