Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions ports/raspberrypi/common-hal/alarm/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ mp_obj_t common_hal_alarm_light_sleep_until_alarms(size_t n_alarms, const mp_obj

mp_obj_t wake_alarm = mp_const_none;

// Save current clocks.
uint32_t saved_sleep_en0 = clocks_hw->sleep_en0;
uint32_t saved_sleep_en1 = clocks_hw->sleep_en1;

while (!mp_hal_is_interrupted()) {
RUN_BACKGROUND_TASKS;
// Detect if interrupt was alarm or ctrl-C interrupt.
Expand All @@ -163,21 +167,25 @@ mp_obj_t common_hal_alarm_light_sleep_until_alarms(size_t n_alarms, const mp_obj
break;
}

// Prune the clock for sleep
// Prune the clocks for sleep.
clocks_hw->sleep_en0 &= RP_LIGHTSLEEP_EN0_MASK;
clocks_hw->sleep_en1 = RP_LIGHTSLEEP_EN1_MASK;

// Enable System Control Block (SCB) deep sleep
uint save = scb_hw->scr;
scb_hw->scr = save | M0PLUS_SCR_SLEEPDEEP_BITS;
scb_hw->scr |= M0PLUS_SCR_SLEEPDEEP_BITS;

__wfi();
}

// Restore clocks so other wfi() uses, like time.sleep(), won't use the light-sleep settings.
clocks_hw->sleep_en0 = saved_sleep_en0;
clocks_hw->sleep_en1 = saved_sleep_en1;

if (mp_hal_is_interrupted()) {
return mp_const_none; // Shouldn't be given to python code because exception handling should kick in.
}


alarm_reset();
return wake_alarm;
}
Expand Down