SleepMemory + set alarm.wake_alarm
This commit is contained in:
parent
55f4110983
commit
cf938983e9
12
main.c
12
main.c
|
@ -112,9 +112,6 @@ STATIC void start_mp(supervisor_allocation* heap) {
|
|||
reset_status_led();
|
||||
autoreload_stop();
|
||||
supervisor_workflow_reset();
|
||||
#if CIRCUITPY_ALARM
|
||||
alarm_reset();
|
||||
#endif
|
||||
|
||||
// Stack limit should be less than real stack size, so we have a chance
|
||||
// to recover from limit hit. (Limit is measured in bytes.)
|
||||
|
@ -158,6 +155,13 @@ STATIC void start_mp(supervisor_allocation* heap) {
|
|||
|
||||
mp_obj_list_init(mp_sys_argv, 0);
|
||||
|
||||
#if CIRCUITPY_ALARM
|
||||
// Record which alarm woke us up, if any. An object may be created so the heap must be functional.
|
||||
alarm_save_wakeup_alarm();
|
||||
// Reset alarm module only after we retrieved the wakeup alarm.
|
||||
alarm_reset();
|
||||
#endif
|
||||
|
||||
#if CIRCUITPY_NETWORK
|
||||
network_module_init();
|
||||
#endif
|
||||
|
@ -285,6 +289,7 @@ STATIC bool run_code_py(safe_mode_t safe_mode) {
|
|||
filesystem_flush();
|
||||
supervisor_allocation* heap = allocate_remaining_memory();
|
||||
start_mp(heap);
|
||||
|
||||
found_main = maybe_run_list(supported_filenames, &result);
|
||||
#if CIRCUITPY_FULL_BUILD
|
||||
if (!found_main){
|
||||
|
@ -354,7 +359,6 @@ STATIC bool run_code_py(safe_mode_t safe_mode) {
|
|||
serial_write_compressed(translate("Woken up by alarm.\n"));
|
||||
board_init();
|
||||
supervisor_set_run_reason(RUN_REASON_STARTUP);
|
||||
// TODO: Reset any volatile memory the user may have access to.
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -52,6 +52,7 @@ mp_obj_t alarm_time_timealarm_get_wakeup_alarm(size_t n_alarms, const mp_obj_t *
|
|||
alarm_time_time_alarm_obj_t *timer = m_new_obj(alarm_time_time_alarm_obj_t);
|
||||
timer->base.type = &alarm_time_time_alarm_type;
|
||||
// TODO: Set monotonic_time based on the RTC state.
|
||||
timer->monotonic_time = 0.0f;
|
||||
return timer;
|
||||
}
|
||||
|
||||
|
|
|
@ -197,7 +197,7 @@ STATIC mp_map_elem_t alarm_module_globals_table[] = {
|
|||
};
|
||||
STATIC MP_DEFINE_MUTABLE_DICT(alarm_module_globals, alarm_module_globals_table);
|
||||
|
||||
void common_hal_alarm_set_wake_alarm(mp_obj_t alarm) {
|
||||
STATIC void alarm_set_wake_alarm(mp_obj_t alarm) {
|
||||
// Equivalent of:
|
||||
// alarm.wake_alarm = alarm
|
||||
mp_map_elem_t *elem =
|
||||
|
@ -207,6 +207,11 @@ void common_hal_alarm_set_wake_alarm(mp_obj_t alarm) {
|
|||
}
|
||||
}
|
||||
|
||||
// Initialize .wake_alarm value.
|
||||
void alarm_save_wakeup_alarm(void) {
|
||||
alarm_set_wake_alarm(common_hal_alarm_get_wake_alarm());
|
||||
}
|
||||
|
||||
const mp_obj_module_t alarm_module = {
|
||||
.base = { &mp_type_module },
|
||||
.globals = (mp_obj_dict_t*)&alarm_module_globals,
|
||||
|
|
|
@ -43,8 +43,11 @@ extern void common_hal_alarm_set_deep_sleep_alarms(size_t n_alarms, const mp_obj
|
|||
// Deep sleep is entered outside of the VM so we omit the `common_hal_` prefix.
|
||||
extern NORETURN void alarm_enter_deep_sleep(void);
|
||||
|
||||
extern mp_obj_t common_hal_alarm_get_wake_alarm(void);
|
||||
|
||||
// Used by wake-up code.
|
||||
extern void common_hal_alarm_set_wake_alarm(mp_obj_t alarm);
|
||||
void alarm_save_wakeup_alarm(void);
|
||||
|
||||
|
||||
// True if an alarm is alerting. This is most useful for pretend deep sleep.
|
||||
extern bool alarm_woken_from_sleep(void);
|
||||
|
|
Loading…
Reference in New Issue