Просмотр исходного кода

fix: 默认freertos timer的实现需要修正一下

Wendal Chen 4 лет назад
Родитель
Сommit
36edb27fa2
1 измененных файлов с 12 добавлено и 10 удалено
  1. 12 10
      luat/freertos/luat_timer_freertos.c

+ 12 - 10
luat/freertos/luat_timer_freertos.c

@@ -3,11 +3,9 @@
 #include "luat_malloc.h"
 #include "luat_timer.h"
 #include "luat_msgbus.h"
-
 #include "FreeRTOS.h"
 #include "task.h"
 #include "timers.h"
-
 #define LUAT_LOG_TAG "timer"
 #include "luat_log.h"
 
@@ -22,7 +20,8 @@ static void luat_timer_callback(TimerHandle_t xTimer) {
     msg.ptr = timer;
     msg.arg1 = 0;
     msg.arg2 = 0;
-    int re = luat_msgbus_put(&msg, 0);
+    luat_msgbus_put(&msg, 0);
+    // int re = luat_msgbus_put(&msg, 0);
     //LLOGD("timer msgbus re=%ld", re);
 }
 
@@ -41,29 +40,31 @@ int luat_timer_start(luat_timer_t* timer) {
     int timerIndex;
     //LLOGD(">>luat_timer_start timeout=%ld", timer->timeout);
     timerIndex = nextTimerSlot();
-    //LLOGD("timer id=%ld", timerIndex);
     if (timerIndex < 0) {
+        LLOGE("too many timers");
         return 1; // too many timer!!
     }
     os_timer = xTimerCreate("luat_timer", timer->timeout / portTICK_RATE_MS, timer->repeat, timer, luat_timer_callback);
     //LLOGD("timer id=%ld, osTimerNew=%p", timerIndex, os_timer);
     if (!os_timer) {
+        LLOGE("xTimerCreate FAIL");
         return -1;
     }
     timers[timerIndex] = timer;
     
     timer->os_timer = os_timer;
-    int re = xTimerStart(os_timer, 0);
+    int re = xTimerStart(os_timer, 1);
     //LLOGD("timer id=%ld timeout=%ld start=%ld", timerIndex, timer->timeout, re);
     if (re != pdPASS) {
-        xTimerDelete(os_timer, 0);
-        timers[timerIndex] = 0;
+        LLOGE("xTimerStart FAIL");
+        xTimerDelete(os_timer, 1);
+        timers[timerIndex] = NULL;
     }
     return re == pdPASS ? 0 : -1;
 }
 
 int luat_timer_stop(luat_timer_t* timer) {
-    if (!timer)
+    if (timer == NULL || timer->os_timer == NULL)
         return 1;
     for (size_t i = 0; i < FREERTOS_TIMER_COUNT; i++)
     {
@@ -72,8 +73,9 @@ int luat_timer_stop(luat_timer_t* timer) {
             break;
         }
     }
-    xTimerStop((TimerHandle_t)timer->os_timer, 10);
-    xTimerDelete((TimerHandle_t)timer->os_timer, 10);
+    xTimerStop((TimerHandle_t)timer->os_timer, 1);
+    xTimerDelete((TimerHandle_t)timer->os_timer, 1);
+    timer->os_timer = NULL;
     return 0;
 };