Browse Source

add: 添加httpsrv库的编译

Wendal Chen 3 years ago
parent
commit
96948b261a
4 changed files with 98 additions and 18 deletions
  1. 7 0
      app/port/luat_base_air101.c
  2. 7 5
      app/port/luat_conf_bsp.h
  3. 45 10
      app/port/luat_malloc_air101.c
  4. 39 3
      xmake.lua

+ 7 - 0
app/port/luat_base_air101.c

@@ -189,6 +189,9 @@ static const luaL_Reg loadedlibs[] = {
 #ifdef LUAT_USE_W5500
   {"w5500", luaopen_w5500},
 #endif
+#ifdef LUAT_USE_HTTPSRV
+  {"httpsrv", luaopen_httpsrv},
+#endif
 #ifdef LUAT_USE_FTP
   {"ftp", luaopen_ftp},
 #endif
@@ -223,6 +226,10 @@ static const luaL_Reg loadedlibs[] = {
 #ifdef LUAT_USE_WLAN
   {"wlan", luaopen_wlan},
 #endif
+#ifdef LUAT_USE_PROFILER
+  {"profiler", luaopen_profiler},
+#endif
+  // {"opus", luaopen_opus},
   {NULL, NULL}
 };
 

+ 7 - 5
app/port/luat_conf_bsp.h

@@ -53,19 +53,21 @@
 // i2s
 //#define LUAt_USE_I2S 1
 
-// 外置网络支持
-// #define LUAT_USE_DHCP 1
-// #define LUAT_USE_DNS 1
-
+// wlan库相关
 // #define LUAT_USE_WLAN
 // #define LUAT_USE_LWIP
 // #define LUAT_USE_NETWORK
 // #define LUAT_USE_DNS
+// #define LUAT_USE_SNTP
+// #define LUAT_USE_HTTPSRV
+
+// 外置网络支持
+// #define LUAT_USE_W5500_XXX
+// #define LUAT_USE_DHCP
 
 // 内存不足, 无法开启TLS
 // #define LUAT_USE_TLS
 
-// #define LUAT_USE_SNTP
 
 #define LUAT_USE_IOTAUTH 1
 

+ 45 - 10
app/port/luat_malloc_air101.c

@@ -12,6 +12,12 @@
 #include "luat_log.h"
 #include "wm_mem.h"
 
+void* __wrap_malloc(size_t len);
+void  __wrap_free(void* ptr);
+void* __wrap_calloc(size_t itemCount, size_t itemSize);
+void* __wrap_zalloc(size_t size);
+void* __wrap_realloc(void*ptr, size_t len);
+
 #ifdef LUAT_USE_WLAN
 #define LUAT_HEAP_MIN_SIZE (100*1024)
 #undef LUAT_HEAP_SIZE
@@ -93,24 +99,53 @@ void luat_heap_init(void) {
 
 //------------------------------------------------
 //  管理系统内存
+#ifdef LUAT_USE_PROFILER_XXX
+void* luat_heap_malloc(size_t len) {
+    void* ptr = __wrap_malloc(len);
+    printf("luat_heap_malloc %p %d\n", ptr, len);
+    return ptr;
+}
+
+void luat_heap_free(void* ptr) {
+    if (ptr == NULL)
+        return;
+    printf("luat_heap_free %p\n", ptr);
+    __wrap_free(ptr);
+}
 
+void* luat_heap_realloc(void* ptr, size_t len) {
+    void* nptr = __wrap_realloc(ptr, len);
+    printf("luat_heap_realloc %p %d %p\n", ptr, len, nptr);
+    return nptr;
+}
+
+void* luat_heap_calloc(size_t count, size_t _size) {
+    void* ptr = __wrap_calloc(count, _size);
+    printf("luat_heap_calloc %p\n", ptr);
+    return ptr;
+}
+#else
 void* luat_heap_malloc(size_t len) {
-    return tls_mem_alloc(len);
+    if (len == 212) {
+        printf("luat_heap_malloc %d\n", len);
+    }
+    return __wrap_malloc(len);
 }
 
 void luat_heap_free(void* ptr) {
     if (ptr == NULL)
         return;
-    tls_mem_free(ptr);
+    __wrap_free(ptr);
 }
 
 void* luat_heap_realloc(void* ptr, size_t len) {
-    return tls_mem_realloc(ptr, len);
+    return __wrap_realloc(ptr, len);
 }
 
 void* luat_heap_calloc(size_t count, size_t _size) {
-    return tls_mem_calloc(count, _size);
+    return __wrap_calloc(count, _size);
 }
+#endif
 
 extern unsigned int heap_size_max;
 extern unsigned int total_mem_size;
@@ -239,7 +274,7 @@ void* __wrap_malloc(size_t len) {
     #ifdef LUAT_USE_PROFILER
     void* ptr = pvPortMalloc(len);
     if (luat_profiler_memdebug) {
-        printf("malloc %d %p\n", len, ptr);
+        // printf("malloc %d %p\n", len, ptr);
         if (ptr == NULL)
             return NULL;
         for (size_t i = 0; i < LUAT_PROFILER_MEMDEBUG_ADDR_COUNT; i++)
@@ -262,8 +297,8 @@ void __wrap_free(void* ptr) {
     if (ptr == NULL)
         return;
     #ifdef LUAT_USE_PROFILER
-    if (luat_profiler_memdebug)
-        printf("free %p\n", ptr);
+    // if (luat_profiler_memdebug)
+    //     printf("free %p\n", ptr);
     #endif
     u32 addr = (u32)ptr;
     if (addr >= 0x20000000 && addr <= 0x40000000) {
@@ -287,7 +322,7 @@ void* __wrap_realloc(void*ptr, size_t len) {
     #ifdef LUAT_USE_PROFILER
     void* newptr = pvPortRealloc(ptr, len);
     if (luat_profiler_memdebug && newptr) {
-        printf("realloc %p %d %p\n", ptr, len, newptr);
+        // printf("realloc %p %d %p\n", ptr, len, newptr);
         uint32_t addr = (uint32_t)ptr;
         uint32_t naddr = (uint32_t)newptr;
         if (ptr == newptr) {
@@ -351,7 +386,7 @@ void* __wrap_calloc(size_t itemCount, size_t itemSize) {
     void* ptr = pvPortMalloc(itemCount * itemSize);
     #ifdef LUAT_USE_PROFILER
     if (luat_profiler_memdebug) {
-        printf("calloc %p %d\n", ptr, itemCount * itemSize);
+        // printf("calloc %p %d\n", ptr, itemCount * itemSize);
         if (ptr) {
             for (size_t i = 0; i < LUAT_PROFILER_MEMDEBUG_ADDR_COUNT; i++)
             {
@@ -374,7 +409,7 @@ void* __wrap_zalloc(size_t size) {
     void* ptr = pvPortMalloc(size);
     #ifdef LUAT_USE_PROFILER
     if (luat_profiler_memdebug) {
-        printf("zalloc %p %d\n", ptr, size);
+        // printf("zalloc %p %d\n", ptr, size);
         if (ptr) {
             for (size_t i = 0; i < LUAT_PROFILER_MEMDEBUG_ADDR_COUNT; i++)
             {

+ 39 - 3
xmake.lua

@@ -288,9 +288,9 @@ target("network")
     add_includedirs(luatos.."components/network/http_parser",{public = true})
     add_files(luatos.."components/network/http_parser/*.c")
     
-    -- libftp
-    -- add_includedirs(luatos.."components/network/libftp",{public = true})
-    -- add_files(luatos.."components/network/libftp/*.c")
+    -- httpsrv
+    add_includedirs(luatos.."components/network/httpsrv/inc",{public = true})
+    add_files(luatos.."components/network/httpsrv/src/*.c")
 
     
     -- http
@@ -370,6 +370,7 @@ target("air10x")
     add_deps("u8g2")
     add_deps("eink")
     add_deps("network")
+    -- add_deps("opus131")
 
     -- add files
     add_files("app/*.c")
@@ -532,6 +533,20 @@ target("air10x")
     -- add_includedirs(luatos.."components/nes/port")
     -- add_files(luatos.."components/nes/**.c")
 
+    -- profiler
+    add_files(luatos.."components/mempool/profiler/**.c")
+    add_includedirs(luatos.."components/mempool/profiler/include")
+
+    
+    -- local opus_dir = luatos .. "components/opus/"
+    -- add_includedirs(opus_dir .. "opus-1.3.1/src", 
+    --                 opus_dir .. "opus-1.3.1/include", 
+    --                 opus_dir .. "opus-1.3.1/silk", 
+    --                 opus_dir .. "opus-1.3.1/silk/fixed", 
+    --                 opus_dir .. "opus-1.3.1/celt")
+    -- add_defines("FIXED_POINT=1", "USE_ALLOCA=1", "OPUS_BUILD=1")
+    -- add_files(opus_dir .. "bind/*.c")
+
 	after_build(function(target)
         sdk_dir = target:toolchains()[1]:sdkdir().."/"
         os.exec(sdk_dir .. "bin/csky-elfabiv2-objcopy -O binary $(buildir)/out/"..TARGET_NAME..".elf $(buildir)/out/"..TARGET_NAME..".bin")
@@ -620,3 +635,24 @@ target("air10x")
     end)
 target_end()
 
+--[[
+target("opus131")
+    set_kind("static")
+    set_plat("cross")
+    set_arch("c-sky")
+    set_optimize("fastest")
+    local opus_dir = luatos .. "/components/opus/"
+    add_includedirs(opus_dir .. "opus-1.3.1/src", 
+                    opus_dir .. "opus-1.3.1/include", 
+                    opus_dir .. "opus-1.3.1/silk", 
+                    opus_dir .. "opus-1.3.1/silk/fixed", 
+                    opus_dir .. "opus-1.3.1/celt")
+
+    add_defines("FIXED_POINT=1", "USE_ALLOCA=1", "OPUS_BUILD=1")
+
+    add_files(opus_dir .. "opus-1.3.1/src/*.c", opus_dir .. "opus-1.3.1/silk/*.c", opus_dir .. "opus-1.3.1/silk/fixed/*.c")
+    add_files(opus_dir .. "opus-1.3.1/celt/*.c")
+    -- add_files(opus_dir .. "opusfile-0.11/src/*.c")
+    -- add_files(opus_dir .. "libogg-1.3.5/src/*.c")
+target_end()
+]]