6969/******************************************************************************
7070 DECLARE PRIVATE FUNCTIONS
7171 ******************************************************************************/
72- STATIC void main_init_sflash_filesystem (void );
73- STATIC void main_enter_ap_mode (void );
74- STATIC void main_create_main_py (void );
72+ STATIC void mptask_pre_init (void );
73+ STATIC void mptask_init_sflash_filesystem (void );
74+ STATIC void mptask_enter_ap_mode (void );
75+ STATIC void mptask_create_main_py (void );
7576
7677/******************************************************************************
7778 DECLARE PUBLIC DATA
@@ -100,39 +101,18 @@ void TASK_Micropython (void *pvParameters) {
100101 bool safeboot ;
101102 FRESULT res ;
102103
103- #if MICROPY_HW_ENABLE_RTC
104- pybrtc_init ();
105- #endif
106-
107104#ifdef DEBUG
108105 safeboot = false;
109106#else
110107 safeboot = mperror_safe_boot_requested ();
111108#endif
112109
113- // Create the simple link spawn task
114- ASSERT (OSI_OK == VStartSimpleLinkSpawnTask (SIMPLELINK_SPAWN_TASK_PRIORITY ));
115-
116- // Allocate memory for the flash file system
117- ASSERT ((sflash_fatfs = mem_Malloc (sizeof (FATFS ))) != NULL );
118- #if MICROPY_HW_HAS_SDCARD
119- pybsd_init0 ();
120- #endif
121-
122- #ifdef DEBUG
123- ASSERT (OSI_OK == osi_TaskCreate (TASK_Servers ,
124- (const signed char * )"Servers" ,
125- SERVERS_STACK_SIZE , NULL , SERVERS_PRIORITY , & svTaskHandle ));
126- #else
127- ASSERT (OSI_OK == osi_TaskCreate (TASK_Servers ,
128- (const signed char * )"Servers" ,
129- SERVERS_STACK_SIZE , NULL , SERVERS_PRIORITY , NULL ));
130- #endif
110+ mptask_pre_init ();
131111
132112soft_reset :
133113
134114 // GC init
135- gc_init (& _heap , & _eheap );
115+ gc_init (& _boot , & _eheap );
136116
137117 // Micro Python init
138118 mp_init ();
@@ -167,13 +147,13 @@ void TASK_Micropython (void *pvParameters) {
167147
168148 mperror_enable_heartbeat ();
169149
170- main_enter_ap_mode ();
150+ mptask_enter_ap_mode ();
171151
172152 // enable telnet and ftp servers
173153 servers_enable ();
174154
175155 // initialize the serial flash file system
176- main_init_sflash_filesystem ();
156+ mptask_init_sflash_filesystem ();
177157
178158 // append the SFLASH paths to the system path
179159 mp_obj_list_append (mp_sys_path , MP_OBJ_NEW_QSTR (MP_QSTR__slash_SFLASH ));
@@ -268,8 +248,34 @@ void TASK_Micropython (void *pvParameters) {
268248/******************************************************************************
269249 DEFINE PRIVATE FUNCTIONS
270250 ******************************************************************************/
251+ __attribute__ ((section (".boot" )))
252+ STATIC void mptask_pre_init (void ) {
253+ #if MICROPY_HW_ENABLE_RTC
254+ pybrtc_init ();
255+ #endif
256+
257+ // Create the simple link spawn task
258+ ASSERT (OSI_OK == VStartSimpleLinkSpawnTask (SIMPLELINK_SPAWN_TASK_PRIORITY ));
259+
260+ // Allocate memory for the flash file system
261+ ASSERT ((sflash_fatfs = mem_Malloc (sizeof (FATFS ))) != NULL );
262+
263+ #if MICROPY_HW_HAS_SDCARD
264+ pybsd_init0 ();
265+ #endif
266+
267+ #ifdef DEBUG
268+ ASSERT (OSI_OK == osi_TaskCreate (TASK_Servers ,
269+ (const signed char * )"Servers" ,
270+ SERVERS_STACK_SIZE , NULL , SERVERS_PRIORITY , & svTaskHandle ));
271+ #else
272+ ASSERT (OSI_OK == osi_TaskCreate (TASK_Servers ,
273+ (const signed char * )"Servers" ,
274+ SERVERS_STACK_SIZE , NULL , SERVERS_PRIORITY , NULL ));
275+ #endif
276+ }
271277
272- STATIC void main_init_sflash_filesystem (void ) {
278+ STATIC void mptask_init_sflash_filesystem (void ) {
273279 // Initialise the local flash filesystem.
274280 // Create it if needed, and mount in on /sflash.
275281 // try to mount the flash
@@ -283,13 +289,13 @@ STATIC void main_init_sflash_filesystem (void) {
283289 __fatal_error ("could not create /SFLASH file system" );
284290 }
285291 // create empty main.py
286- main_create_main_py ();
292+ mptask_create_main_py ();
287293 } else if (res == FR_OK ) {
288294 // mount sucessful
289295 FILINFO fno ;
290296 if (FR_OK != f_stat ("/SFLASH/MAIN.PY" , & fno )) {
291297 // create empty main.py
292- main_create_main_py ();
298+ mptask_create_main_py ();
293299 }
294300 } else {
295301 __fatal_error ("could not create /SFLASH file system" );
@@ -321,14 +327,14 @@ STATIC void main_init_sflash_filesystem (void) {
321327 }
322328}
323329
324- STATIC void main_enter_ap_mode (void ) {
330+ STATIC void mptask_enter_ap_mode (void ) {
325331 // Enable simplelink in low power mode
326332 wlan_sl_enable (ROLE_AP , SERVERS_DEF_AP_SSID , strlen (SERVERS_DEF_AP_SSID ), SERVERS_DEF_AP_SECURITY ,
327333 SERVERS_DEF_AP_KEY , strlen (SERVERS_DEF_AP_KEY ), SERVERS_DEF_AP_CHANNEL );
328334 wlan_set_pm_policy (SL_NORMAL_POLICY );
329335}
330336
331- STATIC void main_create_main_py (void ) {
337+ STATIC void mptask_create_main_py (void ) {
332338 // create empty main.py
333339 FIL fp ;
334340 f_open (& fp , "/SFLASH/MAIN.PY" , FA_WRITE | FA_CREATE_ALWAYS );
0 commit comments