ソースを参照

add: 当同时启用wlan/ble/tls时,调整内存分配策略

Wendal Chen 1 年間 前
コミット
2e764cae24
3 ファイル変更33 行追加3 行削除
  1. 11 3
      app/port/luat_malloc_air101.c
  2. 21 0
      buildx.lua
  3. 1 0
      xmake.lua

+ 11 - 3
app/port/luat_malloc_air101.c

@@ -61,7 +61,7 @@ extern int luat_profiler_memdebug;
 extern luat_profiler_mem_t profiler_memregs[];
 #endif
 
-
+extern uint32_t __ram_end;
 
 void luat_heap_init(void) {
 	// 毕竟sram还是快很多的, 优先sram吧
@@ -95,10 +95,18 @@ void luat_heap_init(void) {
 		return;
 	}
 #else
+    // LLOGD("__ram_end %08X", (uint32_t)&__ram_end);
+    char* ptr = (void*)(0x20028000);
+    size_t heap2_size = LUAT_HEAP_P2_SIZE;
+    #if defined(LUAT_USE_NIMBLE) && defined(LUAT_USE_TLS) && defined(LUAT_USE_WLAN)
+    heap2_size -= 32*1024;
+    ptr += 32*1024;
+    #endif
+
 #ifndef LUAT_USE_TLSF
-	bpool((void*)(0x20028000), LUAT_HEAP_P2_SIZE);
+	bpool(ptr, heap2_size);
 #else
-	luavm_tlsf_ext = tlsf_add_pool(0x20028000 - LUAT_HEAP_P2_SIZE), LUAT_HEAP_P2_SIZE);
+	luavm_tlsf_ext = tlsf_add_pool(ptr, heap2_size);
 #endif
 	#endif
 }

+ 21 - 0
buildx.lua

@@ -13,6 +13,10 @@ function chip()
     local custom_data = io.readfile("$(projectdir)/app/port/luat_conf_bsp.h")
     local FDB_CONF = conf_data:find("\r#define LUAT_USE_FDB") or conf_data:find("\n#define LUAT_USE_FDB") or conf_data:find("\r#define LUAT_USE_FSKV") or conf_data:find("\n#define LUAT_USE_FSKV") 
     local FOTA_CONF = conf_data:find("\r#define LUAT_USE_FOTA") or conf_data:find("\n#define LUAT_USE_FOTA")
+    local WLAN_CONF = conf_data:find("\r#define LUAT_USE_WLAN") or conf_data:find("\n#define LUAT_USE_WLAN")
+    local NIMBLE_CONF = conf_data:find("\r#define LUAT_USE_NIMBLE") or conf_data:find("\n#define LUAT_USE_NIMBLE")
+    local TLS_CONF = conf_data:find("\r#define LUAT_USE_TLS") or conf_data:find("\n#define LUAT_USE_TLS")
+
 
     -- 根据型号判断flash大小
     local is_air101 = custom_data:find("\r#define AIR101") or custom_data:find("\n#define AIR101")
@@ -25,6 +29,11 @@ function chip()
         flash_size = 2*1024*1024
     end
 
+    -- 如果是air601/690,那么wlan肯定是开启的
+    if is_air601 or is_air690 then
+        WLAN_CONF = true
+    end
+
     -- 然后, 根据flash大小, 计算flash的分区
     local flash_fs_size = LUAT_FS_SIZE * 1024                  -- 这个直接取宏定义的值
     local flash_script_size = LUAT_SCRIPT_SIZE * 1024          -- 这个直接取宏定义的值
@@ -55,6 +64,12 @@ function chip()
     elseif is_air690 then TARGET_NAME = "AIR690"
     else TARGET_NAME = "AIR10X" end
 
+    -- 处理内存大小
+    local ram_end = 0x20028000
+    if WLAN_CONF and NIMBLE_CONF and TLS_CONF then
+        ram_end = ram_end + 32 * 1024
+    end
+
     local result = {}
 
     result.target_name = TARGET_NAME
@@ -77,6 +92,12 @@ function chip()
     result.use_fdb = FDB_CONF
     result.bsp_version = AIR10X_VERSION
     result.use_64bit = VM_64BIT
+    result.use_wlan = WLAN_CONF
+    result.use_nimble = NIMBLE_CONF
+    result.use_tls = TLS_CONF
+    result.ram_end = ram_end
+
+
 
     return result
 end

+ 1 - 0
xmake.lua

@@ -482,6 +482,7 @@ target("air10x")
         local ld_data = io.readfile("./ld/xt804.ld")
         local ld_data_n = ld_data:gsub("SRAM_O", string.format("0x%X", chip.flash_app_offset))
         ld_data_n = ld_data_n:gsub("SRAM_L", string.format("0x%X", chip.flash_app_size))
+        ld_data_n = ld_data_n:gsub("RAM_END", string.format("0x%X", chip.ram_end))
         io.writefile("./ld/air101_103.ld", ld_data_n)
 
         TARGET_NAME = chip.target_name