瀏覽代碼

add:支持获取sys最大和已使用内存

Dozingfiretruck 3 年之前
父節點
當前提交
d20bd1ec18
共有 3 個文件被更改,包括 25 次插入21 次删除
  1. 0 20
      app/port/luat_base_air101.c
  2. 22 0
      app/port/luat_malloc_air101.c
  3. 3 1
      platform/sys/wm_main.c

+ 0 - 20
app/port/luat_base_air101.c

@@ -240,26 +240,6 @@ void luat_openlibs(lua_State *L) {
 #include "FreeRTOS.h"
 #include "task.h"
 
-#if configUSE_HEAP3
-extern size_t xTotalHeapSize;
-extern size_t xFreeBytesRemaining;
-extern size_t xFreeBytesMin;
-#endif
-
-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;
-#else
-  *used = configTOTAL_HEAP_SIZE - xPortGetFreeHeapSize();
-	*max_used = *used;
-  *total = configTOTAL_HEAP_SIZE;
-#endif
-}
-
-
 const char* luat_os_bsp(void)
 {
 #ifdef AIR103

+ 22 - 0
app/port/luat_malloc_air101.c

@@ -39,6 +39,28 @@ void* luat_heap_realloc(void* ptr, size_t len) {
 void* luat_heap_calloc(size_t count, size_t _size) {
     return tls_mem_calloc(count, _size);
 }
+
+#if configUSE_HEAP3
+extern size_t xTotalHeapSize;
+extern size_t xFreeBytesRemaining;
+extern size_t xFreeBytesMin;
+#endif
+
+extern unsigned int heap_size_max;
+extern unsigned int total_mem_size;
+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;
+#else
+    *used = heap_size_max - total_mem_size - xPortGetFreeHeapSize();
+    *max_used = *used;
+    *total = heap_size_max;
+#endif
+}
+
 //------------------------------------------------
 
 //------------------------------------------------

+ 3 - 1
platform/sys/wm_main.c

@@ -267,7 +267,7 @@ unsigned int tls_get_wifi_ver(void)
 {
 	return (WiFiVer[0]<<16)|(WiFiVer[1]<<8)|WiFiVer[2];
 }
-
+unsigned int heap_size_max;
 unsigned int total_mem_size;
 void tls_mem_get_init_available_size(void)
 {
@@ -301,6 +301,8 @@ void task_start (void *data)
 #if TLS_CONFIG_CRYSTAL_24M
     tls_wl_hw_using_24m_crystal();
 #endif
+    heap_size_max = (unsigned int)&__heap_end - (unsigned int)&__heap_start;
+    total_mem_size = heap_size_max;
 
 	//tls_mem_get_init_available_size();
     /* must call first to configure gpio Alternate functions according the hardware design */