Bladeren bron

add: bsp/win32 build for posix too

Wendal Chen 4 jaren geleden
bovenliggende
commit
b1104d981b

+ 2 - 0
.gitignore

@@ -87,3 +87,5 @@ debug.log
 量产文件
 
 CMakefiles
+bsp/win32/build/
+

+ 7 - 7
bsp/win32/CMakeLists.txt

@@ -1,7 +1,7 @@
 
 
 # CMake 最低版本号要求
-cmake_minimum_required (VERSION 3.12)
+cmake_minimum_required (VERSION 3.5)
 
 set(CMAKE_BUILD_TYPE "Debug")
 set(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g -ggdb")
@@ -25,9 +25,9 @@ IF (WIN32)
 ELSE ()
      include_directories(${TOPROOT}/components/freertos/portable/ThirdParty/GCC/Posix)
      include_directories(${TOPROOT}/components/freertos/portable/ThirdParty/GCC/Posix/utils)
-     aux_source_directory(${TOPROOT}/components/freertos/portable/ThirdParty/GCC/Posix 
-                          ${TOPROOT}/components/freertos/portable/ThirdParty/GCC/Posix/utils
-                          MM_SRCS)
+     aux_source_directory(${TOPROOT}/components/freertos/portable/ThirdParty/GCC/Posix MM_SRCS) 
+     aux_source_directory(${TOPROOT}/components/freertos/portable/ThirdParty/GCC/Posix/utils
+                          MM2_SRCS)
 ENDIF ()
 
 aux_source_directory(./port PORT_SRCS)
@@ -37,7 +37,7 @@ aux_source_directory(${TOPROOT}/components/freertos RTOS_SRCS)
 aux_source_directory(${TOPROOT}/components/freertos/port RTOS_PORT_SRCS)
 aux_source_directory(${TOPROOT}/luat/packages/lua-cjson CJSON_SRCS)
 
-add_library(freertos10 ${PORT_SRCS} ${RTOS_SRCS} ${RTOS_PORT_SRCS} ${MM_SRCS})
+add_library(freertos10 ${PORT_SRCS} ${RTOS_SRCS} ${RTOS_PORT_SRCS} ${MM_SRCS} ${MM2_SRCS})
 add_library(lua ${LUA_SRCS})
 add_library(luatos_msys ${PORT_SRCS})
 add_library(cjson ${CJSON_SRCS})
@@ -87,5 +87,5 @@ target_link_libraries(luatos freertos10 lua luatos_msys luat winmm cjson rock_lf
 ELSE ()
 add_executable(luatos src/main_posix.c)
 target_link_libraries(luat freertos10 pthread)
-target_link_libraries(luatos freertos10 lua luatos_msys luat pthread cjson mbedtls)
-ENDIF ()
+target_link_libraries(luatos freertos10 lua luatos_msys luat pthread cjson mbedtls m)
+ENDIF ()

+ 10 - 0
bsp/win32/port/luat_base_win32.c

@@ -30,8 +30,10 @@ static const luaL_Reg loadedlibs[] = {
   {"zbuff", luaopen_zbuff},            // 
   {"mqttcore", luaopen_mqttcore},      // 
   {"libcoap", luaopen_libcoap},        // 
+#ifdef LUA_USE_WINDOWS
   {"lfs", luaopen_lfs},                //
   {"rs232.core", luaopen_rs232_core},
+#endif
   {"crypto", luaopen_crypto},
   {NULL, NULL}
 };
@@ -57,7 +59,11 @@ void luat_os_reboot(int code) {
 }
 
 const char* luat_os_bsp(void) {
+    #ifdef LUA_USE_WINDOWS
     return "win32";
+    #else
+    return "posix";
+    #endif
 }
 
 extern const struct luat_vfs_filesystem vfs_fs_posix;
@@ -121,7 +127,11 @@ static BaseType_t xTraceRunning = pdTRUE;
 
 void vApplicationIdleHook( void )
 {
+#ifdef LUA_USE_WINDOWS
     Sleep(1);
+#else
+    usleep(1000);
+#endif
 }
 
 void vAssertCalled( unsigned long ulLine, const char * const pcFileName ) {

+ 32 - 0
bsp/win32/src/main_posix.c

@@ -0,0 +1,32 @@
+
+#include <stdio.h>
+
+#include "luat_base.h"
+#include "luat_malloc.h"
+
+#include "bget.h"
+
+#include "FreeRTOS.h"
+#include "task.h"
+
+#define LUAT_HEAP_SIZE (1024*1024)
+uint8_t luavm_heap[LUAT_HEAP_SIZE] = {0};
+
+static void _luat_main(void* args) {
+    luat_main();
+}
+
+
+int win32_argc;
+char** win32_argv;
+
+// boot
+int main(int argc, char** argv) {
+    win32_argc = argc;
+    win32_argv = argv;
+    
+    bpool(luavm_heap, LUAT_HEAP_SIZE);
+    xTaskCreate( _luat_main, "luatos", 1024*16, NULL, 21, NULL );
+    vTaskStartScheduler();
+    return 0;
+}

+ 1 - 1
components/freertos/include/FreeRTOSConfig.h

@@ -39,7 +39,7 @@
  *----------------------------------------------------------*/
 
 #define configUSE_PREEMPTION					1
-#define configUSE_PORT_OPTIMISED_TASK_SELECTION	1
+#define configUSE_PORT_OPTIMISED_TASK_SELECTION	0
 #define configUSE_IDLE_HOOK						1
 #define configUSE_TICK_HOOK						0
 #define configUSE_DAEMON_TASK_STARTUP_HOOK		1

+ 2 - 2
components/freertos/portable/ThirdParty/GCC/Posix/port.c

@@ -524,8 +524,8 @@ int iRet;
      * When a thread is resumed for the first time, all signals
      * will be unblocked.
      */
-    (void)pthread_sigmask( SIG_SETMASK, &xAllSignals,
-                           *&xSchedulerOriginalSignalMask );
+    //(void)pthread_sigmask( SIG_SETMASK, &xAllSignals,
+    //                       *&xSchedulerOriginalSignalMask );
 
     /* SIG_RESUME is only used with sigwait() so doesn't need a
        handler. */

+ 2 - 0
luat/modules/luat_vfs.c

@@ -8,6 +8,8 @@
 
 #ifdef LUAT_USE_FS_VFS
 
+#undef getc
+
 static luat_vfs_t vfs= {0};
 
 int luat_vfs_init(void* params) {