soft reboot for pretending deep sleep.

This commit is contained in:
jun2sak 2021-04-12 20:53:14 +09:00
parent 15764b4c24
commit 6e9429d779
2 changed files with 19 additions and 7 deletions

19
main.c
View File

@ -404,10 +404,10 @@ STATIC bool run_code_py(safe_mode_t safe_mode) {
new_status_color(BLACK);
board_deinit();
if (!supervisor_workflow_active()) {
// Enter true deep sleep. When we wake up we'll be back at the
// top of main(), not in this loop.
// Enter deep sleep. When we wake up we'll return from
// this loop.
common_hal_alarm_enter_deep_sleep();
// Does not return.
// Does not return.
} else {
serial_write_compressed(translate("Pretending to deep sleep until alarm, CTRL-C or file write.\n"));
}
@ -426,10 +426,21 @@ STATIC bool run_code_py(safe_mode_t safe_mode) {
#if CIRCUITPY_ALARM
common_hal_alarm_pretending_deep_sleep();
bool serial_in = (serial_connected() &&
serial_bytes_available());
supervisor_set_run_reason(RUN_REASON_STARTUP);
board_init();
if (serial_in) {
bool ctrl_d = serial_read() == CHAR_CTRL_D;
if (ctrl_d) {
supervisor_set_run_reason(RUN_REASON_REPL_RELOAD);
}
return ctrl_d;
}
return true;
#else
port_idle_until_interrupt();
#endif
//return false; // to go REPL
}
}
}

View File

@ -346,7 +346,7 @@ void NORETURN common_hal_alarm_enter_deep_sleep(void) {
while(1) ;
}
// old version deep sleep code that was used in alarm_enter_deep_sleep()
// old version deep sleep code that was used in common_hal_alarm_enter_deep_sleep()
// for anyone who might want true System OFF sleep ..
#if 0
void OLD_go_system_off(void) {
@ -384,6 +384,7 @@ void common_hal_alarm_pretending_deep_sleep(void) {
alarm_reset();
#if 0
// if one of Alarm event occurred, reset myself
if (cause == NRF_SLEEP_WAKEUP_GPIO ||
cause == NRF_SLEEP_WAKEUP_TIMER ||
@ -391,9 +392,9 @@ void common_hal_alarm_pretending_deep_sleep(void) {
reset_cpu();
}
// else, just return and go into REPL
#endif
}
void common_hal_alarm_gc_collect(void) {
void* p = shared_alarm_get_wake_alarm();
gc_collect_ptr(p);
gc_collect_ptr(shared_alarm_get_wake_alarm());
}