@@ -162,19 +162,21 @@ static void update_memory_statistics(void)
162162#ifdef ESP_PLATFORM
163163 multi_heap_info_t heap_info ;
164164 heap_caps_get_info (& heap_info , MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT );
165+ statistics .totalMemoryInt = heap_info .total_free_bytes + heap_info .total_allocated_bytes ;
165166 statistics .freeMemoryInt = heap_info .total_free_bytes ;
166167 statistics .freeBlockInt = heap_info .largest_free_block ;
167- statistics .totalMemoryInt = heap_info .total_free_bytes + heap_info .total_allocated_bytes ;
168168 heap_caps_get_info (& heap_info , MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT );
169+ statistics .totalMemoryExt = heap_info .total_free_bytes + heap_info .total_allocated_bytes ;
169170 statistics .freeMemoryExt = heap_info .total_free_bytes ;
170171 statistics .freeBlockExt = heap_info .largest_free_block ;
171- statistics .totalMemoryExt = heap_info .total_free_bytes + heap_info .total_allocated_bytes ;
172-
172+ // FIXME: We should check all the tasks' HWM to be better informed!
173173 statistics .freeStackMain = uxTaskGetStackHighWaterMark (tasks [0 ].handle );
174174#else
175- statistics .freeMemoryInt = statistics .freeBlockInt = statistics .totalMemoryInt = (1 << 28 );
176- statistics .freeMemoryExt = statistics .freeBlockExt = statistics .totalMemoryExt = (1 << 28 );
175+ statistics .freeMemoryInt = statistics .freeBlockInt = statistics .totalMemoryInt = 0x40000000 ;
177176#endif
177+ statistics .totalMemory = statistics .totalMemoryInt + statistics .totalMemoryExt ;
178+ statistics .freeMemory = statistics .freeMemoryInt + statistics .freeMemoryExt ;
179+ statistics .freeBlock = RG_MAX (statistics .freeBlockInt , statistics .freeBlockExt );
178180}
179181
180182static void update_statistics (void )
@@ -401,7 +403,6 @@ rg_app_t *rg_system_init(const rg_config_t *config)
401403 .tickTimeout = 3000000 ,
402404 .frameTime = 1000000 / 60 ,
403405 .frameskip = 1 , // This can be overriden on a per-app basis if needed, do not set 0 here!
404- .lowMemoryMode = false,
405406 .enWatchdog = true,
406407 .isColdBoot = true,
407408 .isLauncher = false,
@@ -431,6 +432,7 @@ rg_app_t *rg_system_init(const rg_config_t *config)
431432 printf ("%s %s (%s)\n" , app .name , app .version , app .buildDate );
432433 printf (" built for: %s. type: %s\n" , RG_TARGET_NAME , app .isRelease ? "release" : "dev" );
433434 printf ("========================================================\n\n" );
435+ update_memory_statistics (); // Do this early in case any of our init routines needs to know
434436
435437#ifdef RG_I2C_GPIO_DRIVER
436438 rg_i2c_init ();
@@ -479,19 +481,13 @@ rg_app_t *rg_system_init(const rg_config_t *config)
479481 memset (& panicTrace , 0 , sizeof (panicTrace ));
480482 panicTraceCleared = true;
481483
482- update_memory_statistics ();
483- app .lowMemoryMode = statistics .totalMemoryExt == 0 ;
484-
485484 app .indicatorsMask = rg_settings_get_number (NS_GLOBAL , SETTING_INDICATOR_MASK , app .indicatorsMask );
486485 app .romPath = app .bootArgs ?: "" ; // For whatever reason some of our code isn't NULL-aware, sigh..
487486
488487 rg_gui_draw_hourglass ();
489488
490489 if (config )
491490 {
492- app .sampleRate = config -> sampleRate ;
493- app .tickRate = config -> frameRate ;
494- // app.frameskip = config->frameSkip;
495491 if (config -> storageRequired && !rg_storage_ready ())
496492 {
497493 rg_display_clear (C_SKY_BLUE );
@@ -503,31 +499,30 @@ rg_app_t *rg_system_init(const rg_config_t *config)
503499 // show rom picking dialog
504500 // app.romPath = rg_gui_file_picker(_("Choose ROM"), RG_BASE_PATH_ROMS, NULL, true, false);
505501 }
506- if (config -> mallocAlwaysInternal > 0 )
507- {
508502 #ifdef ESP_PLATFORM
503+ if (config -> mallocAlwaysInternal > 0 )
509504 heap_caps_malloc_extmem_enable (config -> mallocAlwaysInternal );
510505 #endif
511- }
506+ app .sampleRate = config -> sampleRate ;
507+ app .tickRate = config -> frameRate ;
508+ // app.frameskip = config->frameSkip;
512509 app .isLauncher = config -> isLauncher ;
513510 app .handlers = config -> handlers ;
514511 }
515512
516513 if (app .sampleRate > 0 )
517- {
518514 rg_audio_init (app .sampleRate );
519- }
520515
521516 rg_system_set_tick_rate (app .tickRate );
522517 rg_system_set_timezone (rg_settings_get_string (NS_GLOBAL , SETTING_TIMEZONE , "EST+5" ));
523518 rg_system_load_time ();
524519
525- if (app .lowMemoryMode )
526- rg_gui_alert ("External memory not detected" , "Boot will continue but it will surely crash..." );
527-
528520 if (app .bootFlags & RG_BOOT_ONCE )
529521 update_boot_config (RG_APP_LAUNCHER , NULL , NULL , 0 , 0 );
530522
523+ if (statistics .totalMemory < 0x200000 )
524+ rg_gui_alert ("External memory not detected" , "Boot will continue but it will surely crash..." );
525+
531526 rg_task_create ("rg_sysmon" , & system_monitor_task , NULL , 3 * 1024 , RG_TASK_PRIORITY_5 , -1 );
532527 app .initialized = true;
533528
0 commit comments