File tree 1 file changed +11
-3
lines changed
ports/raspberrypi/common-hal/alarm
1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -141,6 +141,10 @@ mp_obj_t common_hal_alarm_light_sleep_until_alarms(size_t n_alarms, const mp_obj
141
141
142
142
mp_obj_t wake_alarm = mp_const_none ;
143
143
144
+ // Save current clocks.
145
+ uint32_t saved_sleep_en0 = clocks_hw -> sleep_en0 ;
146
+ uint32_t saved_sleep_en1 = clocks_hw -> sleep_en1 ;
147
+
144
148
while (!mp_hal_is_interrupted ()) {
145
149
RUN_BACKGROUND_TASKS ;
146
150
// Detect if interrupt was alarm or ctrl-C interrupt.
@@ -163,21 +167,25 @@ mp_obj_t common_hal_alarm_light_sleep_until_alarms(size_t n_alarms, const mp_obj
163
167
break ;
164
168
}
165
169
166
- // Prune the clock for sleep
170
+ // Prune the clocks for sleep.
167
171
clocks_hw -> sleep_en0 &= RP_LIGHTSLEEP_EN0_MASK ;
168
172
clocks_hw -> sleep_en1 = RP_LIGHTSLEEP_EN1_MASK ;
169
173
170
174
// Enable System Control Block (SCB) deep sleep
171
- uint save = scb_hw -> scr ;
172
- scb_hw -> scr = save | M0PLUS_SCR_SLEEPDEEP_BITS ;
175
+ scb_hw -> scr |= M0PLUS_SCR_SLEEPDEEP_BITS ;
173
176
174
177
__wfi ();
175
178
}
176
179
180
+ // Restore clocks so other wfi() uses, like time.sleep(), won't use the light-sleep settings.
181
+ clocks_hw -> sleep_en0 = saved_sleep_en0 ;
182
+ clocks_hw -> sleep_en1 = saved_sleep_en1 ;
183
+
177
184
if (mp_hal_is_interrupted ()) {
178
185
return mp_const_none ; // Shouldn't be given to python code because exception handling should kick in.
179
186
}
180
187
188
+
181
189
alarm_reset ();
182
190
return wake_alarm ;
183
191
}
You can’t perform that action at this time.
0 commit comments