@@ -117,12 +117,12 @@ static size_t PLACE_IN_DTCM_BSS(_pystack[CIRCUITPY_PYSTACK_SIZE / sizeof(size_t)
117
117
#endif
118
118
119
119
static void reset_devices (void ) {
120
- #if CIRCUITPY_BLEIO_HCI
120
+ #if CIRCUITPY_BLEIO_HCI
121
121
bleio_reset ();
122
- #endif
122
+ #endif
123
123
}
124
124
125
- STATIC void start_mp (supervisor_allocation * heap ) {
125
+ STATIC void start_mp (supervisor_allocation * heap ) {
126
126
autoreload_stop ();
127
127
supervisor_workflow_reset ();
128
128
@@ -135,13 +135,13 @@ STATIC void start_mp(supervisor_allocation* heap) {
135
135
}
136
136
137
137
138
- #if MICROPY_MAX_STACK_USAGE
138
+ #if MICROPY_MAX_STACK_USAGE
139
139
// _ezero (same as _ebss) is an int, so start 4 bytes above it.
140
140
if (stack_get_bottom () != NULL ) {
141
141
mp_stack_set_bottom (stack_get_bottom ());
142
142
mp_stack_fill_with_sentinel ();
143
143
}
144
- #endif
144
+ #endif
145
145
146
146
// Sync the file systems in case any used RAM from the GC to cache. As soon
147
147
// as we re-init the GC all bets are off on the cache.
@@ -201,8 +201,8 @@ STATIC void stop_mp(void) {
201
201
202
202
// Look for the first file that exists in the list of filenames, using mp_import_stat().
203
203
// Return its index. If no file found, return -1.
204
- STATIC const char * first_existing_file_in_list (const char * const * filenames ) {
205
- for (int i = 0 ; filenames [i ] != (char * )"" ; i ++ ) {
204
+ STATIC const char * first_existing_file_in_list (const char * const * filenames ) {
205
+ for (int i = 0 ; filenames [i ] != (char * )"" ; i ++ ) {
206
206
mp_import_stat_t stat = mp_import_stat (filenames [i ]);
207
207
if (stat == MP_IMPORT_STAT_FILE ) {
208
208
return filenames [i ];
@@ -211,8 +211,8 @@ STATIC const char* first_existing_file_in_list(const char * const * filenames) {
211
211
return NULL ;
212
212
}
213
213
214
- STATIC bool maybe_run_list (const char * const * filenames , pyexec_result_t * exec_result ) {
215
- const char * filename = first_existing_file_in_list (filenames );
214
+ STATIC bool maybe_run_list (const char * const * filenames , pyexec_result_t * exec_result ) {
215
+ const char * filename = first_existing_file_in_list (filenames );
216
216
if (filename == NULL ) {
217
217
return false;
218
218
}
@@ -226,10 +226,10 @@ STATIC bool maybe_run_list(const char * const * filenames, pyexec_result_t* exec
226
226
}
227
227
228
228
STATIC void count_strn (void * data , const char * str , size_t len ) {
229
- * (size_t * )data += len ;
229
+ * (size_t * )data += len ;
230
230
}
231
231
232
- STATIC void cleanup_after_vm (supervisor_allocation * heap , mp_obj_t exception ) {
232
+ STATIC void cleanup_after_vm (supervisor_allocation * heap , mp_obj_t exception ) {
233
233
// Get the traceback of any exception from this run off the heap.
234
234
// MP_OBJ_SENTINEL means "this run does not contribute to traceback storage, don't touch it"
235
235
// MP_OBJ_NULL (=0) means "this run completed successfully, clear any stored traceback"
@@ -249,13 +249,12 @@ STATIC void cleanup_after_vm(supervisor_allocation* heap, mp_obj_t exception) {
249
249
// making it fail, but at this point I believe they are not worth spending code on.
250
250
if (prev_traceback_allocation != NULL ) {
251
251
vstr_t vstr ;
252
- vstr_init_fixed_buf (& vstr , traceback_len , (char * )prev_traceback_allocation -> ptr );
252
+ vstr_init_fixed_buf (& vstr , traceback_len , (char * )prev_traceback_allocation -> ptr );
253
253
mp_print_t print = {& vstr , (mp_print_strn_t )vstr_add_strn };
254
254
mp_obj_print_exception (& print , exception );
255
- ((char * )prev_traceback_allocation -> ptr )[traceback_len ] = '\0' ;
255
+ ((char * )prev_traceback_allocation -> ptr )[traceback_len ] = '\0' ;
256
256
}
257
- }
258
- else {
257
+ } else {
259
258
prev_traceback_allocation = NULL ;
260
259
}
261
260
}
@@ -335,17 +334,17 @@ STATIC bool run_code_py(safe_mode_t safe_mode) {
335
334
uint8_t next_code_stickiness_situation = SUPERVISOR_NEXT_CODE_OPT_NEWLY_SET ;
336
335
337
336
if (safe_mode == NO_SAFE_MODE ) {
338
- static const char * const supported_filenames [] = STRING_LIST (
337
+ static const char * const supported_filenames [] = STRING_LIST (
339
338
"code.txt" , "code.py" , "main.py" , "main.txt" );
340
339
#if CIRCUITPY_FULL_BUILD
341
- static const char * const double_extension_filenames [] = STRING_LIST (
340
+ static const char * const double_extension_filenames [] = STRING_LIST (
342
341
"code.txt.py" , "code.py.txt" , "code.txt.txt" ,"code.py.py" ,
343
342
"main.txt.py" , "main.py.txt" , "main.txt.txt" ,"main.py.py" );
344
343
#endif
345
344
346
345
stack_resize ();
347
346
filesystem_flush ();
348
- supervisor_allocation * heap = allocate_remaining_memory ();
347
+ supervisor_allocation * heap = allocate_remaining_memory ();
349
348
350
349
// Prepare the VM state. Includes an alarm check/reset for sleep.
351
350
start_mp (heap );
@@ -356,14 +355,14 @@ STATIC bool run_code_py(safe_mode_t safe_mode) {
356
355
357
356
// Check if a different run file has been allocated
358
357
if (next_code_allocation ) {
359
- ((next_code_info_t * )next_code_allocation -> ptr )-> options &= ~SUPERVISOR_NEXT_CODE_OPT_NEWLY_SET ;
360
- next_code_options = ((next_code_info_t * )next_code_allocation -> ptr )-> options ;
361
- if (((next_code_info_t * )next_code_allocation -> ptr )-> filename [0 ] != '\0' ) {
362
- const char * next_list [] = {((next_code_info_t * )next_code_allocation -> ptr )-> filename , "" };
358
+ ((next_code_info_t * )next_code_allocation -> ptr )-> options &= ~SUPERVISOR_NEXT_CODE_OPT_NEWLY_SET ;
359
+ next_code_options = ((next_code_info_t * )next_code_allocation -> ptr )-> options ;
360
+ if (((next_code_info_t * )next_code_allocation -> ptr )-> filename [0 ] != '\0' ) {
361
+ const char * next_list [] = {((next_code_info_t * )next_code_allocation -> ptr )-> filename , "" };
363
362
// This is where the user's python code is actually executed:
364
363
found_main = maybe_run_list (next_list , & result );
365
364
if (!found_main ) {
366
- serial_write (((next_code_info_t * )next_code_allocation -> ptr )-> filename );
365
+ serial_write (((next_code_info_t * )next_code_allocation -> ptr )-> filename );
367
366
serial_write_compressed (translate (" not found.\n" ));
368
367
}
369
368
}
@@ -374,14 +373,14 @@ STATIC bool run_code_py(safe_mode_t safe_mode) {
374
373
found_main = maybe_run_list (supported_filenames , & result );
375
374
// If that didn't work, double check the extensions
376
375
#if CIRCUITPY_FULL_BUILD
377
- if (!found_main ){
376
+ if (!found_main ) {
378
377
found_main = maybe_run_list (double_extension_filenames , & result );
379
378
if (found_main ) {
380
379
serial_write_compressed (translate ("WARNING: Your code filename has two extensions\n" ));
381
380
}
382
381
}
383
382
#else
384
- (void ) found_main ;
383
+ (void )found_main ;
385
384
#endif
386
385
}
387
386
@@ -400,7 +399,7 @@ STATIC bool run_code_py(safe_mode_t safe_mode) {
400
399
// the options because it can be treated like any other reason-for-stickiness bit. The
401
400
// source is different though: it comes from the options that will apply to the next run,
402
401
// while the rest of next_code_options is what applied to this run.
403
- if (next_code_allocation != NULL && (((next_code_info_t * )next_code_allocation -> ptr )-> options & SUPERVISOR_NEXT_CODE_OPT_NEWLY_SET )) {
402
+ if (next_code_allocation != NULL && (((next_code_info_t * )next_code_allocation -> ptr )-> options & SUPERVISOR_NEXT_CODE_OPT_NEWLY_SET )) {
404
403
next_code_options |= SUPERVISOR_NEXT_CODE_OPT_NEWLY_SET ;
405
404
}
406
405
@@ -562,7 +561,7 @@ STATIC bool run_code_py(safe_mode_t safe_mode) {
562
561
}
563
562
564
563
#if !CIRCUITPY_STATUS_LED
565
- port_interrupt_after_ticks (time_to_epaper_refresh );
564
+ port_interrupt_after_ticks (time_to_epaper_refresh );
566
565
#endif
567
566
#endif
568
567
@@ -645,72 +644,70 @@ STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) {
645
644
&& safe_mode == NO_SAFE_MODE
646
645
&& MP_STATE_VM (vfs_mount_table ) != NULL ;
647
646
648
- if (!ok_to_run ) {
649
- return ;
650
- }
651
-
652
- static const char * const boot_py_filenames [] = STRING_LIST ("boot.py" , "boot.txt" );
647
+ static const char * const boot_py_filenames [] = STRING_LIST ("boot.py" , "boot.txt" );
653
648
654
649
// Do USB setup even if boot.py is not run.
655
650
656
- supervisor_allocation * heap = allocate_remaining_memory ();
651
+ supervisor_allocation * heap = allocate_remaining_memory ();
657
652
start_mp (heap );
658
653
659
- #if CIRCUITPY_USB
654
+ #if CIRCUITPY_USB
660
655
// Set up default USB values after boot.py VM starts but before running boot.py.
661
656
usb_set_defaults ();
662
- #endif
663
-
664
- #ifdef CIRCUITPY_BOOT_OUTPUT_FILE
665
- vstr_t boot_text ;
666
- vstr_init (& boot_text , 512 );
667
- boot_output = & boot_text ;
668
657
#endif
669
658
670
- // Write version info
671
- mp_printf (& mp_plat_print , "%s\nBoard ID:%s\n" , MICROPY_FULL_VERSION_INFO , CIRCUITPY_BOARD_ID );
672
-
673
659
pyexec_result_t result = {0 , MP_OBJ_NULL , 0 };
674
660
675
- bool found_boot = maybe_run_list (boot_py_filenames , & result );
676
- (void ) found_boot ;
661
+ if (ok_to_run ) {
662
+ #ifdef CIRCUITPY_BOOT_OUTPUT_FILE
663
+ vstr_t boot_text ;
664
+ vstr_init (& boot_text , 512 );
665
+ boot_output = & boot_text ;
666
+ #endif
667
+
668
+ // Write version info
669
+ mp_printf (& mp_plat_print , "%s\nBoard ID:%s\n" , MICROPY_FULL_VERSION_INFO , CIRCUITPY_BOARD_ID );
670
+
671
+ bool found_boot = maybe_run_list (boot_py_filenames , & result );
672
+ (void )found_boot ;
677
673
678
674
679
- #ifdef CIRCUITPY_BOOT_OUTPUT_FILE
680
- // Get the base filesystem.
681
- fs_user_mount_t * vfs = (fs_user_mount_t * ) MP_STATE_VM (vfs_mount_table )-> obj ;
682
- FATFS * fs = & vfs -> fatfs ;
675
+ #ifdef CIRCUITPY_BOOT_OUTPUT_FILE
676
+ // Get the base filesystem.
677
+ fs_user_mount_t * vfs = (fs_user_mount_t * )MP_STATE_VM (vfs_mount_table )-> obj ;
678
+ FATFS * fs = & vfs -> fatfs ;
683
679
684
- boot_output = NULL ;
685
- bool write_boot_output = (common_hal_mcu_processor_get_reset_reason () == RESET_REASON_POWER_ON );
686
- FIL boot_output_file ;
687
- if (f_open (fs , & boot_output_file , CIRCUITPY_BOOT_OUTPUT_FILE , FA_READ ) == FR_OK ) {
688
- char * file_contents = m_new (char , boot_text .alloc );
689
- UINT chars_read ;
690
- if (f_read (& boot_output_file , file_contents , 1 + boot_text .len , & chars_read ) == FR_OK ) {
691
- write_boot_output =
692
- (chars_read != boot_text .len ) || (memcmp (boot_text .buf , file_contents , chars_read ) != 0 );
680
+ boot_output = NULL ;
681
+ bool write_boot_output = (common_hal_mcu_processor_get_reset_reason () == RESET_REASON_POWER_ON );
682
+ FIL boot_output_file ;
683
+ if (f_open (fs , & boot_output_file , CIRCUITPY_BOOT_OUTPUT_FILE , FA_READ ) == FR_OK ) {
684
+ char * file_contents = m_new (char , boot_text .alloc );
685
+ UINT chars_read ;
686
+ if (f_read (& boot_output_file , file_contents , 1 + boot_text .len , & chars_read ) == FR_OK ) {
687
+ write_boot_output =
688
+ (chars_read != boot_text .len ) || (memcmp (boot_text .buf , file_contents , chars_read ) != 0 );
689
+ }
690
+ // no need to f_close the file
693
691
}
694
- // no need to f_close the file
695
- }
696
692
697
- if (write_boot_output ) {
698
- // Wait 1 second before opening CIRCUITPY_BOOT_OUTPUT_FILE for write,
699
- // in case power is momentary or will fail shortly due to, say a low, battery.
700
- mp_hal_delay_ms (1000 );
701
-
702
- // USB isn't up, so we can write the file.
703
- // operating at the oofatfs (f_open) layer means the usb concurrent write permission
704
- // is not even checked!
705
- f_open (fs , & boot_output_file , CIRCUITPY_BOOT_OUTPUT_FILE , FA_WRITE | FA_CREATE_ALWAYS );
706
- UINT chars_written ;
707
- f_write (& boot_output_file , boot_text .buf , boot_text .len , & chars_written );
708
- f_close (& boot_output_file );
709
- filesystem_flush ();
693
+ if (write_boot_output ) {
694
+ // Wait 1 second before opening CIRCUITPY_BOOT_OUTPUT_FILE for write,
695
+ // in case power is momentary or will fail shortly due to, say a low, battery.
696
+ mp_hal_delay_ms (1000 );
697
+
698
+ // USB isn't up, so we can write the file.
699
+ // operating at the oofatfs (f_open) layer means the usb concurrent write permission
700
+ // is not even checked!
701
+ f_open (fs , & boot_output_file , CIRCUITPY_BOOT_OUTPUT_FILE , FA_WRITE | FA_CREATE_ALWAYS );
702
+ UINT chars_written ;
703
+ f_write (& boot_output_file , boot_text .buf , boot_text .len , & chars_written );
704
+ f_close (& boot_output_file );
705
+ filesystem_flush ();
706
+ }
707
+ #endif
710
708
}
711
- #endif
712
709
713
- #if CIRCUITPY_USB
710
+ #if CIRCUITPY_USB
714
711
// Some data needs to be carried over from the USB settings in boot.py
715
712
// to the next VM, while the heap is still available.
716
713
// Its size can vary, so save it temporarily on the stack,
@@ -719,21 +716,21 @@ STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) {
719
716
size_t size = usb_boot_py_data_size ();
720
717
uint8_t usb_boot_py_data [size ];
721
718
usb_get_boot_py_data (usb_boot_py_data , size );
722
- #endif
719
+ #endif
723
720
724
721
cleanup_after_vm (heap , result .exception );
725
722
726
- #if CIRCUITPY_USB
723
+ #if CIRCUITPY_USB
727
724
// Now give back the data we saved from the heap going away.
728
725
usb_return_boot_py_data (usb_boot_py_data , size );
729
- #endif
726
+ #endif
730
727
}
731
728
732
729
STATIC int run_repl (void ) {
733
730
int exit_code = PYEXEC_FORCED_EXIT ;
734
731
stack_resize ();
735
732
filesystem_flush ();
736
- supervisor_allocation * heap = allocate_remaining_memory ();
733
+ supervisor_allocation * heap = allocate_remaining_memory ();
737
734
start_mp (heap );
738
735
739
736
#if CIRCUITPY_USB
@@ -878,7 +875,7 @@ void gc_collect(void) {
878
875
879
876
// This collects root pointers from the VFS mount table. Some of them may
880
877
// have lost their references in the VM even though they are mounted.
881
- gc_collect_root ((void * * )& MP_STATE_VM (vfs_mount_table ), sizeof (mp_vfs_mount_t ) / sizeof (mp_uint_t ));
878
+ gc_collect_root ((void * * )& MP_STATE_VM (vfs_mount_table ), sizeof (mp_vfs_mount_t ) / sizeof (mp_uint_t ));
882
879
883
880
background_callback_gc_collect ();
884
881
@@ -908,18 +905,20 @@ void gc_collect(void) {
908
905
909
906
// This naively collects all object references from an approximate stack
910
907
// range.
911
- gc_collect_root ((void * * )sp , ((uint32_t )port_stack_get_top () - sp ) / sizeof (uint32_t ));
908
+ gc_collect_root ((void * * )sp , ((uint32_t )port_stack_get_top () - sp ) / sizeof (uint32_t ));
912
909
gc_collect_end ();
913
910
}
914
911
915
912
void NORETURN nlr_jump_fail (void * val ) {
916
913
reset_into_safe_mode (MICROPY_NLR_JUMP_FAIL );
917
- while (true) {}
914
+ while (true) {
915
+ }
918
916
}
919
917
920
918
void NORETURN __fatal_error (const char * msg ) {
921
919
reset_into_safe_mode (MICROPY_FATAL_ERROR );
922
- while (true) {}
920
+ while (true) {
921
+ }
923
922
}
924
923
925
924
#ifndef NDEBUG
0 commit comments