mark alarm.wake_alarm during gc sweep

This commit is contained in:
Dan Halbert 2020-12-22 10:06:43 -05:00 committed by Scott Shawcroft
parent 0dcc659d53
commit d4e9eea397
No known key found for this signature in database
GPG Key ID: 0DFD512649C052DA
4 changed files with 30 additions and 3 deletions

4
main.c
View File

@ -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

View File

@ -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());
}

View File

@ -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:

View File

@ -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