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

fix: msgbus和timer的freertos实现有错误,修正之

Wendal Chen 5 лет назад
Родитель
Сommit
018db88551
2 измененных файлов с 12 добавлено и 4 удалено
  1. 7 0
      luat/freertos/luat_msgbus_freertos.c
  2. 5 4
      luat/freertos/luat_timer_freertos.c

+ 7 - 0
luat/freertos/luat_msgbus_freertos.c

@@ -9,14 +9,21 @@
 
 static StaticQueue_t xStaticQueue = {0};
 static QueueHandle_t xQueue = {0};
+
+#if configSUPPORT_STATIC_ALLOCATION
 static uint8_t ucQueueStorageArea[ QUEUE_LENGTH * ITEM_SIZE ];
+#endif
 
 void luat_msgbus_init(void) {
     if (!xQueue) {
+        #if configSUPPORT_STATIC_ALLOCATION
         xQueue = xQueueCreateStatic( QUEUE_LENGTH,
                                  ITEM_SIZE,
                                  ucQueueStorageArea,
                                  &xStaticQueue );
+        #else
+        xQueue = xQueueCreate(QUEUE_LENGTH, ITEM_SIZE);
+        #endif
     }
 }
 uint32_t luat_msgbus_put(rtos_msg_t* msg, size_t timeout) {

+ 5 - 4
luat/freertos/luat_timer_freertos.c

@@ -6,6 +6,7 @@
 
 #include "FreeRTOS.h"
 #include "task.h"
+#include "timers.h"
 
 #define LUAT_LOG_TAG "luat.timer"
 #include "luat_log.h"
@@ -18,7 +19,7 @@ static void luat_timer_callback(TimerHandle_t xTimer) {
     rtos_msg_t msg;
     luat_timer_t *timer = (luat_timer_t*) pvTimerGetTimerID(xTimer);
     msg.handler = timer->func;
-    msg.ptr = param;
+    msg.ptr = xTimer;
     msg.arg1 = 0;
     msg.arg2 = 0;
     int re = luat_msgbus_put(&msg, 1);
@@ -36,7 +37,7 @@ static int nextTimerSlot() {
 }
 
 int luat_timer_start(luat_timer_t* timer) {
-    osTimerId_t os_timer;
+    TimerHandle_t os_timer;
     int timerIndex;
     //LLOGD(">>luat_timer_start timeout=%ld", timer->timeout);
     timerIndex = nextTimerSlot();
@@ -71,8 +72,8 @@ int luat_timer_stop(luat_timer_t* timer) {
             break;
         }
     }
-    xTimerStop(timer->os_timer);
-    xTimerDelete(timer->os_timer);
+    xTimerStop((TimerHandle_t)timer->os_timer, 10);
+    xTimerDelete((TimerHandle_t)timer->os_timer, 10);
     return 0;
 };