Skip to content

Commit

Permalink
update wake-alarm implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
microdev1 committed Dec 30, 2020
1 parent b83bdc5 commit 0bad611
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 10 deletions.
2 changes: 1 addition & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ STATIC void start_mp(supervisor_allocation* heap) {

#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();
alarm_save_wake_alarm();
// Reset alarm module only after we retrieved the wakeup alarm.
alarm_reset();
#endif
Expand Down
2 changes: 1 addition & 1 deletion ports/esp32s2/common-hal/alarm/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ STATIC void _idle_until_alarm(void) {
RUN_BACKGROUND_TASKS;
// Allow ctrl-C interrupt.
if (alarm_woken_from_sleep()) {
alarm_save_wake_alarm();
return;
}

port_idle_until_interrupt();
}
}
Expand Down
10 changes: 3 additions & 7 deletions shared-bindings/alarm/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,21 +227,17 @@ mp_obj_t alarm_get_wake_alarm(void) {
}
}

STATIC void alarm_set_wake_alarm(mp_obj_t alarm) {
// Initialize .wake_alarm value.
void alarm_save_wake_alarm(void) {
// Equivalent of:
// alarm.wake_alarm = alarm
mp_map_elem_t *elem =
mp_map_lookup(&alarm_module_globals.map, MP_ROM_QSTR(MP_QSTR_wake_alarm), MP_MAP_LOOKUP);
if (elem) {
elem->value = alarm;
elem->value = common_hal_alarm_get_wake_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,
Expand Down
2 changes: 1 addition & 1 deletion shared-bindings/alarm/__init__.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ extern void common_hal_alarm_gc_collect(void);
extern mp_obj_t common_hal_alarm_get_wake_alarm(void);

// Used by wake-up code.
void alarm_save_wakeup_alarm(void);
void alarm_save_wake_alarm(void);


// True if an alarm is alerting. This is most useful for pretend deep sleep.
Expand Down

0 comments on commit 0bad611

Please sign in to comment.