File tree Expand file tree Collapse file tree 1 file changed +11
-3
lines changed
ports/raspberrypi/common-hal/alarm Expand file tree Collapse file tree 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
141141
142142 mp_obj_t wake_alarm = mp_const_none ;
143143
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+
144148 while (!mp_hal_is_interrupted ()) {
145149 RUN_BACKGROUND_TASKS ;
146150 // 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
163167 break ;
164168 }
165169
166- // Prune the clock for sleep
170+ // Prune the clocks for sleep.
167171 clocks_hw -> sleep_en0 &= RP_LIGHTSLEEP_EN0_MASK ;
168172 clocks_hw -> sleep_en1 = RP_LIGHTSLEEP_EN1_MASK ;
169173
170174 // 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 ;
173176
174177 __wfi ();
175178 }
176179
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+
177184 if (mp_hal_is_interrupted ()) {
178185 return mp_const_none ; // Shouldn't be given to python code because exception handling should kick in.
179186 }
180187
188+
181189 alarm_reset ();
182190 return wake_alarm ;
183191}
You can’t perform that action at this time.
0 commit comments