瀏覽代碼

fix: bsp/linux的sys可用了,sys.wait正常

Wendal Chen 3 年之前
父節點
當前提交
601b7450bc
共有 3 個文件被更改,包括 32 次插入5 次删除
  1. 21 5
      bsp/linux/port/luat_timer_linux.c
  2. 5 0
      bsp/linux/src/main.c
  3. 6 0
      luat/vfs/luat_fs_inline.c

+ 21 - 5
bsp/linux/port/luat_timer_linux.c

@@ -1,8 +1,9 @@
-
+#define _POSIX_C_SOURCE 199309L
 #include "luat_base.h"
 #include "luat_malloc.h"
 #include "luat_timer.h"
 #include "luat_msgbus.h"
+#include <pthread.h>
 
 
 #define LUAT_LOG_TAG "timer"
@@ -12,7 +13,7 @@
 #include <math.h>
 #include <unistd.h>
 
-#define TIMER_COUNT 32
+#define TIMER_COUNT 128
 typedef struct sysp_timer {
     luat_timer_t* timer;
     uint32_t starttime;
@@ -22,7 +23,7 @@ static sysp_timer_t timers[TIMER_COUNT] = {0};
 
 // 获取当前时间
 uint32_t get_timestamp(void) {
-    struct timespec _t;
+    struct timespec _t = {0};
     clock_gettime(CLOCK_REALTIME, &_t);
     uint32_t timenow = _t.tv_sec*1000 + lround(_t.tv_nsec/1e6);
     //printf("time now > %u\n", timenow);
@@ -66,7 +67,7 @@ static int nextTimerSlot() {
 }
 
 int luat_timer_start(luat_timer_t* timer) {
-    int os_timer;
+    // int os_timer;
     int timerIndex;
     //LLOGD(">>luat_timer_start timeout=%ld", timer->timeout);
     timerIndex = nextTimerSlot();
@@ -74,7 +75,7 @@ int luat_timer_start(luat_timer_t* timer) {
     if (timerIndex < 0) {
         return 1; // too many timer!!
     }
-    os_timer = timerIndex;
+    // os_timer = timerIndex;
     //LLOGD("timer id=%ld, osTimerNew=%p", timerIndex, os_timer);
     timers[timerIndex].timer = timer;
     timers[timerIndex].starttime = get_timestamp();
@@ -115,3 +116,18 @@ int luat_timer_mdelay(size_t ms) {
 }
 
 
+static pthread_mutex_t mp;
+static pthread_cond_t cv;
+
+void *timer_thread_start(void *args) {
+    // printf("timer thread started\r\n");
+    struct timespec to = {0};
+    pthread_mutex_lock(&mp);
+    to.tv_sec = 0;
+    to.tv_nsec = 100;
+    while (1) {
+        pthread_cond_timedwait(&cv, &mp, &to);
+        luat_timer_check();
+    }
+    return NULL;
+}

+ 5 - 0
bsp/linux/src/main.c

@@ -6,6 +6,7 @@
 #include "luat_msgbus.h"
 #include "luat_fs.h"
 #include <stdlib.h>
+#include <pthread.h>
 
 #include "bget.h"
 
@@ -14,6 +15,7 @@
 
 #define LUAT_HEAP_SIZE (1024*1024)
 uint8_t luavm_heap[LUAT_HEAP_SIZE] = {0};
+void *timer_thread_start(void *);
 
 // void luat_log_init_win32(void);
 
@@ -66,6 +68,9 @@ int main(int argc, char** argv) {
     xTaskCreate( _lvgl_handler, "lvgl", 1024*2, NULL, 23, NULL );
 #endif
 
+    pthread_t t;
+    pthread_create(&t, NULL, &timer_thread_start, NULL);
+
     // xTaskCreate( _luat_main, "luatos", 1024*16, NULL, 21, NULL );
     // vTaskStartScheduler();
     _luat_main(NULL);

+ 6 - 0
luat/vfs/luat_fs_inline.c

@@ -26,8 +26,11 @@ FILE* luat_vfs_inline_fopen(void* userdata, const char *filename, const char *mo
     //LLOGD("open inline %s", filename);
     luadb_file_t* file = NULL;
 #ifdef LUAT_CONF_VM_64bit
+    #ifdef LUA_USE_LINUX
     file = luat_inline2_libs_64bit_size64;
+    #else
     file = luat_inline2_libs_64bit_size32;
+    #endif
 #else
     file = luat_inline2_libs;
 #endif
@@ -124,8 +127,11 @@ int luat_vfs_inline_fexist(void* userdata, const char *filename) {
     //LLOGD("open fexist %s", filename);
     luadb_file_t* file = NULL;
 #ifdef LUAT_CONF_VM_64bit
+    #ifdef LUA_USE_LINUX
     file = luat_inline2_libs_64bit_size64;
+    #else
     file = luat_inline2_libs_64bit_size32;
+    #endif
 #else
     file = luat_inline2_libs;
 #endif