@@ -132,7 +132,7 @@ static void reset_devices(void) {
132
132
#endif
133
133
}
134
134
135
- STATIC void start_mp (supervisor_allocation * heap , bool first_run ) {
135
+ STATIC void start_mp (supervisor_allocation * heap ) {
136
136
supervisor_workflow_reset ();
137
137
138
138
// Stack limit should be less than real stack size, so we have a chance
@@ -176,14 +176,6 @@ STATIC void start_mp(supervisor_allocation *heap, bool first_run) {
176
176
mp_obj_list_append (mp_sys_path , MP_OBJ_NEW_QSTR (MP_QSTR__slash_lib ));
177
177
178
178
mp_obj_list_init ((mp_obj_list_t * )mp_sys_argv , 0 );
179
-
180
- #if CIRCUITPY_ALARM
181
- // Record which alarm woke us up, if any. An object may be created so the heap must be functional.
182
- // There is no alarm if this is not the first time code.py or the REPL has been run.
183
- shared_alarm_save_wake_alarm (first_run ? common_hal_alarm_create_wake_alarm () : mp_const_none );
184
- // Reset alarm module only after we retrieved the wakeup alarm.
185
- alarm_reset ();
186
- #endif
187
179
}
188
180
189
181
STATIC void stop_mp (void ) {
@@ -373,7 +365,7 @@ STATIC void print_code_py_status_message(safe_mode_t safe_mode) {
373
365
}
374
366
}
375
367
376
- STATIC bool run_code_py (safe_mode_t safe_mode , bool first_run , bool * simulate_reset ) {
368
+ STATIC bool run_code_py (safe_mode_t safe_mode , bool * simulate_reset ) {
377
369
bool serial_connected_at_start = serial_connected ();
378
370
bool printed_safe_mode_message = false;
379
371
#if CIRCUITPY_AUTORELOAD_DELAY_MS > 0
@@ -409,8 +401,8 @@ STATIC bool run_code_py(safe_mode_t safe_mode, bool first_run, bool *simulate_re
409
401
410
402
supervisor_allocation * heap = allocate_remaining_memory ();
411
403
412
- // Prepare the VM state. Includes an alarm check/reset for sleep.
413
- start_mp (heap , first_run );
404
+ // Prepare the VM state.
405
+ start_mp (heap );
414
406
415
407
#if CIRCUITPY_USB
416
408
usb_setup_with_vm ();
@@ -853,12 +845,12 @@ STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) {
853
845
#endif
854
846
}
855
847
856
- STATIC int run_repl (bool first_run ) {
848
+ STATIC int run_repl (void ) {
857
849
int exit_code = PYEXEC_FORCED_EXIT ;
858
850
stack_resize ();
859
851
filesystem_flush ();
860
852
supervisor_allocation * heap = allocate_remaining_memory ();
861
- start_mp (heap , first_run );
853
+ start_mp (heap );
862
854
863
855
#if CIRCUITPY_USB
864
856
usb_setup_with_vm ();
@@ -968,6 +960,12 @@ int __attribute__((used)) main(void) {
968
960
safe_mode = NO_CIRCUITPY ;
969
961
}
970
962
963
+ #if CIRCUITPY_ALARM
964
+ // Record which alarm woke us up, if any.
965
+ // common_hal_alarm_record_wake_alarm() should return a static, non-heap object
966
+ shared_alarm_save_wake_alarm (common_hal_alarm_record_wake_alarm ());
967
+ #endif
968
+
971
969
// Reset everything and prep MicroPython to run boot.py.
972
970
reset_port ();
973
971
// Port-independent devices, like CIRCUITPY_BLEIO_HCI.
@@ -1001,20 +999,18 @@ int __attribute__((used)) main(void) {
1001
999
// Boot script is finished, so now go into REPL or run code.py.
1002
1000
int exit_code = PYEXEC_FORCED_EXIT ;
1003
1001
bool skip_repl = true;
1004
- bool first_run = true;
1005
- bool simulate_reset ;
1002
+ bool simulate_reset = true;
1006
1003
for (;;) {
1007
- simulate_reset = false;
1008
1004
if (!skip_repl ) {
1009
- exit_code = run_repl (first_run );
1005
+ exit_code = run_repl ();
1010
1006
supervisor_set_run_reason (RUN_REASON_REPL_RELOAD );
1011
1007
}
1012
1008
if (exit_code == PYEXEC_FORCED_EXIT ) {
1013
- if (!first_run ) {
1009
+ if (!simulate_reset ) {
1014
1010
serial_write_compressed (translate ("soft reboot\n" ));
1015
1011
}
1016
1012
if (pyexec_mode_kind == PYEXEC_MODE_FRIENDLY_REPL ) {
1017
- skip_repl = run_code_py (safe_mode , first_run , & simulate_reset );
1013
+ skip_repl = run_code_py (safe_mode , & simulate_reset );
1018
1014
} else {
1019
1015
skip_repl = false;
1020
1016
}
@@ -1025,7 +1021,11 @@ int __attribute__((used)) main(void) {
1025
1021
// Either the REPL or code.py has run and finished.
1026
1022
// If code.py did a fake deep sleep, pretend that we are running code.py for
1027
1023
// the first time after a hard reset. This will preserve any alarm information.
1028
- first_run = simulate_reset ;
1024
+ if (!simulate_reset ) {
1025
+ #if CIRCUITPY_ALARM
1026
+ shared_alarm_save_wake_alarm (mp_const_none );
1027
+ #endif
1028
+ }
1029
1029
}
1030
1030
mp_deinit ();
1031
1031
return 0 ;
0 commit comments