summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Halbert <halbert@halwitz.org>2020-12-22 10:06:43 -0500
committerScott Shawcroft <scott@tannewt.org>2020-12-22 08:11:01 -0800
commitd4e9eea397c887d9eceb5f4c6aba117a4dc3d03b (patch)
tree5a3d07f361df6fea8bdcd9cffac444c5eb871d75
parent0dcc659d536034637009e3c5cb7713c35c002929 (diff)
mark alarm.wake_alarm during gc sweep
-rwxr-xr-xmain.c4
-rw-r--r--ports/esp32s2/common-hal/alarm/__init__.c8
-rw-r--r--shared-bindings/alarm/__init__.c13
-rw-r--r--shared-bindings/alarm/__init__.h8
4 files changed, 30 insertions, 3 deletions
diff --git a/main.c b/main.c
index d940f93d1..27ed6ff11 100755
--- a/main.c
+++ b/main.c
@@ -613,6 +613,10 @@ void gc_collect(void) {
background_callback_gc_collect();
+ #if CIRCUITPY_ALARM
+ common_hal_alarm_gc_collect();
+ #endif
+
#if CIRCUITPY_DISPLAYIO
displayio_gc_collect();
#endif
diff --git a/ports/esp32s2/common-hal/alarm/__init__.c b/ports/esp32s2/common-hal/alarm/__init__.c
index 5d1f3e95d..9f19f1afc 100644
--- a/ports/esp32s2/common-hal/alarm/__init__.c
+++ b/ports/esp32s2/common-hal/alarm/__init__.c
@@ -25,10 +25,12 @@
* THE SOFTWARE.
*/
+#include "py/gc.h"
#include "py/obj.h"
#include "py/objtuple.h"
#include "py/runtime.h"
+#include "shared-bindings/alarm/__init__.h"
#include "shared-bindings/alarm/pin/PinAlarm.h"
#include "shared-bindings/alarm/SleepMemory.h"
#include "shared-bindings/alarm/time/TimeAlarm.h"
@@ -38,8 +40,6 @@
#include "supervisor/port.h"
#include "supervisor/shared/workflow.h"
-#include "common-hal/alarm/__init__.h"
-
#include "esp_sleep.h"
#include "components/soc/soc/esp32s2/include/soc/rtc_cntl_reg.h"
@@ -159,3 +159,7 @@ void NORETURN alarm_enter_deep_sleep(void) {
// We don't need to worry about resetting them in the interim.
esp_deep_sleep_start();
}
+
+void common_hal_alarm_gc_collect(void) {
+ gc_collect_ptr(alarm_get_wake_alarm());
+}
diff --git a/shared-bindings/alarm/__init__.c b/shared-bindings/alarm/__init__.c
index 700fe020e..778674f6d 100644
--- a/shared-bindings/alarm/__init__.c
+++ b/shared-bindings/alarm/__init__.c
@@ -199,7 +199,18 @@ STATIC mp_map_elem_t alarm_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_SleepMemory), MP_OBJ_FROM_PTR(&alarm_sleep_memory_type) },
{ MP_ROM_QSTR(MP_QSTR_sleep_memory), MP_OBJ_FROM_PTR(&alarm_sleep_memory_obj) },
};
-STATIC MP_DEFINE_MUTABLE_DICT(alarm_module_globals, alarm_module_globals_table);
+MP_DEFINE_MUTABLE_DICT(alarm_module_globals, alarm_module_globals_table);
+
+// Fetch value from module dict.
+mp_obj_t alarm_get_wake_alarm(void) {
+ mp_map_elem_t *elem =
+ mp_map_lookup(&alarm_module_globals.map, MP_ROM_QSTR(MP_QSTR_wake_alarm), MP_MAP_LOOKUP);
+ if (elem) {
+ return elem->value;
+ } else {
+ return NULL;
+ }
+}
STATIC void alarm_set_wake_alarm(mp_obj_t alarm) {
// Equivalent of:
diff --git a/shared-bindings/alarm/__init__.h b/shared-bindings/alarm/__init__.h
index 8c4b6cad9..a90405da6 100644
--- a/shared-bindings/alarm/__init__.h
+++ b/shared-bindings/alarm/__init__.h
@@ -31,6 +31,9 @@
#include "common-hal/alarm/__init__.h"
+// Make module dict available elsewhere, so we can fetch
+extern mp_obj_dict_t alarm_module_globals;
+
extern mp_obj_t common_hal_alarm_light_sleep_until_alarms(size_t n_alarms, const mp_obj_t *alarms);
// Deep sleep is a two step process. Alarms are set when the VM is valid but
@@ -43,6 +46,10 @@ 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);
+// Fetches value from module dict.
+extern mp_obj_t alarm_get_wake_alarm(void);
+
+extern void common_hal_alarm_gc_collect(void);
extern mp_obj_t common_hal_alarm_get_wake_alarm(void);
// Used by wake-up code.
@@ -52,4 +59,5 @@ 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);
+
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_ALARM___INIT___H