Jelajahi Sumber

add: 添加heap4,合并原有的heap2+gcc malloc的内存区域.

经测试, 开启TLS支持是没有希望的, 砍掉大量的库可以节省一些内存,但这又有什么意义呢
Wendal Chen 2 tahun lalu
induk
melakukan
1412adaebc

+ 31 - 0
app/port/heap_wrap.c

@@ -0,0 +1,31 @@
+#include "wm_include.h"
+#include "FreeRTOS.h"
+
+void* __wrap_malloc(size_t len) {
+    return pvPortMalloc(len);
+}
+
+void __wrap_free(void* ptr) {
+    return vPortFree(ptr);
+}
+
+void *pvPortRealloc( void *pv, size_t xWantedSize );
+void* __wrap_realloc(void*ptr, size_t len) {
+    return pvPortRealloc(ptr, len);
+}
+
+void* __wrap_calloc(size_t itemCount, size_t itemSize) {
+    void* ptr = pvPortMalloc(itemCount * itemSize);
+    if (ptr == NULL)
+        return NULL;
+    memset(ptr, 0, itemCount * itemSize);
+    return ptr;
+}
+
+void* __wrap_zalloc(size_t size) {
+    void* ptr = pvPortMalloc(size);
+    if (ptr == NULL)
+        return NULL;
+    memset(ptr, 0, size);
+    return ptr;
+}

+ 10 - 0
app/port/luat_malloc_air101.c

@@ -6,6 +6,7 @@
 #include <string.h>//add for memset
 #include "bget.h"
 #include "luat_malloc.h"
+#include "FreeRTOS.h"
 
 #define LUAT_LOG_TAG "heap"
 #include "luat_log.h"
@@ -48,12 +49,21 @@ extern size_t xFreeBytesMin;
 
 extern unsigned int heap_size_max;
 extern unsigned int total_mem_size;
+extern size_t __heap_start;
+extern size_t __heap_end;
 void luat_meminfo_sys(size_t* total, size_t* used, size_t* max_used)
 {
 #if configUSE_HEAP3
     *used = xTotalHeapSize - xFreeBytesRemaining;
     *max_used = xTotalHeapSize - xFreeBytesMin;
     *total = xTotalHeapSize;
+#elif configUSE_HEAP4
+    extern void vPortGetHeapStats( HeapStats_t *pxHeapStats );
+    HeapStats_t stat = {0};
+    vPortGetHeapStats(&stat);
+    *total = (size_t)(&__heap_end) - (size_t)(&__heap_start);
+    *max_used = *total - stat.xMinimumEverFreeBytesRemaining;
+    *used = (*total) - (stat.xAvailableHeapSpaceInBytes);
 #else
     *used = heap_size_max - total_mem_size;
     *max_used = *used;

+ 2 - 2
ld/AIR101.ld

@@ -27,7 +27,7 @@ MEMORY
 	V-SRAM : ORIGIN = 0x20000000 , LENGTH = 0x100   /* off-chip SRAM 8MB */
 }
 
-__min_heap_size = 0x2000;
+__min_heap_size = 0x100;
 PROVIDE (__ram_end  = 0x20028000);
 PROVIDE (__heap_end = __ram_end);
 
@@ -152,7 +152,7 @@ SECTIONS
   __bss_end__ = .;
  } > REGION_BSS
  ._user_heap : {
-  . = ALIGN(0x4) ;
+  . = ALIGN(0x8) ;
   __heap_start = .;
   . += __min_heap_size;
   . = ALIGN(0x4) ;

+ 2 - 2
ld/AIR103.ld

@@ -27,7 +27,7 @@ MEMORY
 	V-SRAM : ORIGIN = 0x20000000 , LENGTH = 0x100     /* off-chip SRAM 8MB */
 }
 
-__min_heap_size = 0x2000;
+__min_heap_size = 0x100;
 PROVIDE (__ram_end  = 0x20028000);
 PROVIDE (__heap_end = __ram_end);
 
@@ -152,7 +152,7 @@ SECTIONS
   __bss_end__ = .;
  } > REGION_BSS
  ._user_heap : {
-  . = ALIGN(0x4) ;
+  . = ALIGN(0x8) ;
   __heap_start = .;
   . += __min_heap_size;
   . = ALIGN(0x4) ;

+ 3 - 1
platform/common/mem/wm_mem.c

@@ -17,6 +17,8 @@
 #include "list.h"
 #include <string.h>
 
+#if 0
+
 extern u8 tls_get_isr_count(void);
 /**
  * This variable is set if the memory mananger has been initialized.
@@ -853,4 +855,4 @@ END:
 }
 
 
-
+#endif

+ 20 - 0
platform/common/mem/wm_mem2.c

@@ -0,0 +1,20 @@
+#include "wm_osal.h"
+#include "wm_mem.h"
+#include "list.h"
+#include <string.h>
+#include "FreeRTOS.h"
+#include "stdio.h"
+
+void * mem_alloc_debug(u32 size) {
+    return malloc(size);
+}
+void mem_free_debug(void *p) {
+    free(p);
+}
+void * mem_realloc_debug(void *mem_address, u32 size) {
+    return realloc(mem_address, size);
+}
+
+void *mem_calloc_debug(u32 length, u32 size) {
+    return calloc(length, size);
+}

+ 1 - 1
platform/sys/wm_main.c

@@ -244,7 +244,7 @@ int main(void)
     csi_vic_set_wakeup_irq(TIMER_IRQn);
     csi_vic_set_wakeup_irq(WDG_IRQn);
 	/*should be here because main stack will be allocated and deallocated after task delete*/
-	tls_mem_get_init_available_size();
+	// tls_mem_get_init_available_size();
 	
     /*configure wake up source end*/
 	TaskStartStk = tls_mem_alloc(sizeof(u32)*TASK_START_STK_SIZE);

+ 1 - 0
src/os/rtos/include/FreeRTOSConfig.h

@@ -83,6 +83,7 @@
 #define configUSE_16_BIT_TICKS		0	
 #define configIDLE_SHOULD_YIELD		1	
 #define configUSE_HEAP3				0
+#define configUSE_HEAP4				1
 
 #define configQUEUE_REGISTRY_SIZE 	0
 #define configSEMAPHORE_INIT_VALUE	5	

+ 9 - 1
xmake.lua

@@ -42,7 +42,7 @@ set_toolchains("csky@csky")
 local flto = ""
 
 --add macro defination
-add_defines("GCC_COMPILE=1","TLS_CONFIG_CPU_XT804=1","NIMBLE_FTR=1","__LUATOS__")
+add_defines("GCC_COMPILE=1","TLS_CONFIG_CPU_XT804=1","NIMBLE_FTR=1","__LUATOS__","__USER_CODE__")
 
 set_warnings("allextra")
 
@@ -103,6 +103,12 @@ add_includedirs("include/arch/xt804/csi_dsp")
 add_includedirs("platform/sys")
 add_includedirs("src/app/mbedtls/ports")
 
+add_ldflags(" -Wl,--wrap=malloc ",{force = true})
+add_ldflags(" -Wl,--wrap=free ",{force = true})
+add_ldflags(" -Wl,--wrap=zalloc ",{force = true})
+add_ldflags(" -Wl,--wrap=calloc ",{force = true})
+add_ldflags(" -Wl,--wrap=realloc ",{force = true})
+
 target("app")
     set_kind("static")
     set_plat("cross")
@@ -158,6 +164,8 @@ target("blehost")
     add_includedirs("include/arch/xt804",{public = true})
     add_includedirs("include/arch/xt804/csi_core",{public = true})
 
+    remove_files("src/app/bleapp/wm_ble_server_wifi_app.c")
+
 target_end()
 
 target("lvgl")