Skip to content

Commit

Permalink
zephyr/modmachine: Implement machine.reset().
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Sokolovsky committed Apr 19, 2017
1 parent 1f3887d commit 5846770
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
6 changes: 5 additions & 1 deletion zephyr/modmachine.c
Expand Up @@ -28,6 +28,7 @@

#include <stdint.h>
#include <stdio.h>
#include <misc/reboot.h>

#include "py/obj.h"
#include "py/runtime.h"
Expand All @@ -40,7 +41,8 @@
#if MICROPY_PY_MACHINE

STATIC mp_obj_t machine_reset(void) {
printf("Warning: %s is not implemented\n", __func__);
sys_reboot(SYS_REBOOT_COLD);
// Won't get here, Zephyr has infiniloop on its side
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_reset_obj, machine_reset);
Expand All @@ -53,7 +55,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_reset_cause_obj, machine_reset_cause);

STATIC const mp_rom_map_elem_t machine_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_umachine) },
#ifdef CONFIG_REBOOT

This comment has been minimized.

Copy link
@dpgeorge

dpgeorge Apr 19, 2017

Member

@pfalcon I don't grok this #ifdef: I assume it's Zephyr-specific and if it's not defined then sys_reboot is not available... but in that case I'd assume that the entire implementation in machine_reset() function should also have this #ifdef guard.

This comment has been minimized.

Copy link
@pfalcon

pfalcon Apr 19, 2017

Author Contributor

@dpgeorge : yep, everything starting with CONFIG_ are Zephyr config vars (coming from prj*.conf). E.g. minimal zephyr port doesn't have that enabled.

but in that case I'd assume that the entire implementation in machine_reset() function should also have this #ifdef guard.

Nope, for quite some time, nope! We rely on --gc-sections to save our code from becoming ifdef spaghetti. Except for some ports, which are still under suspicion: #2573

This comment has been minimized.

Copy link
@dpgeorge

dpgeorge Apr 21, 2017

Member

OK

This comment has been minimized.

Copy link
@dpgeorge

dpgeorge Apr 21, 2017

Member

But I guess my question/concert was that if the CONFIG_REBOOT was not defined then does the Zephyr header even declare the sys_reboot and SYS_REBOOT_COLD names? Well, I assume you checked that it does :)

This comment has been minimized.

Copy link
@pfalcon

pfalcon Apr 21, 2017

Author Contributor

Yep, I did ;-).

{ MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&machine_reset_obj) },
#endif
{ MP_ROM_QSTR(MP_QSTR_reset_cause), MP_ROM_PTR(&machine_reset_cause_obj) },

{ MP_ROM_QSTR(MP_QSTR_Pin), MP_ROM_PTR(&machine_pin_type) },
Expand Down
1 change: 1 addition & 0 deletions zephyr/prj_base.conf
@@ -1,4 +1,5 @@
CONFIG_LEGACY_KERNEL=n
CONFIG_REBOOT=y

CONFIG_STDOUT_CONSOLE=y
CONFIG_CONSOLE_HANDLER=y
Expand Down

0 comments on commit 5846770

Please sign in to comment.