Sfoglia il codice sorgente

add:freertos统一使用主库移植

Dozingfiretruck 3 anni fa
parent
commit
9e03ad965c

+ 1 - 0
luatos/components/luat/CMakeLists.txt

@@ -8,6 +8,7 @@ idf_component_register(SRC_DIRS ${LUATOS_ROOT}/luat/modules
                                 ${LUATOS_ROOT}/luat/vfs
                                 ${LUATOS_ROOT}/lua/src
                                 ${srcs}
+                                ${LUATOS_ROOT}/luat/freertos
                                 ${LUATOS_ROOT}/components/shell
                                 ${LUATOS_ROOT}/components/ymodem
                                 ${LUATOS_ROOT}/components/cmux

+ 0 - 3
luatos/components/luat/port/luat_gpio_idf5.c

@@ -104,9 +104,6 @@ int luat_gpio_setup(luat_gpio_t *gpio) {
         if (gpio->irq_cb) {
             gpio_isr_cb[pin].irq_cb = gpio->irq_cb;
             gpio_isr_cb[pin].irq_args = gpio->irq_args;
-            // gpio_isr_handler_add(pin, gpio->irq_cb, (void*)pin);
-        // }else{
-            // gpio_isr_handler_add(pin, gpio_isr_handler, (void *)pin);
         }
         gpio_isr_handler_add(pin, gpio_isr_handler, (void *)pin);
     }

+ 0 - 43
luatos/components/luat/port/luat_msgbus_idf5.c

@@ -1,43 +0,0 @@
-
-#include "luat_msgbus.h"
-
-#include "freertos/FreeRTOS.h"
-#include "freertos/queue.h"
-
-#define QUEUE_LENGTH 0xFF
-#define ITEM_SIZE sizeof(rtos_msg_t)
-
-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) {
-    if (xQueue == NULL)
-        return 1;
-    return xQueueSendFromISR(xQueue, msg, NULL) == pdTRUE ? 0 : 1;
-}
-uint32_t luat_msgbus_get(rtos_msg_t* msg, size_t timeout) {
-    if (xQueue == NULL)
-        return 1;
-    return xQueueReceive(xQueue, msg, timeout) == pdTRUE ? 0 : 1;
-}
-uint32_t luat_msgbus_freesize(void) {
-    if (xQueue == NULL)
-        return 1;
-    return 1;
-}

+ 0 - 102
luatos/components/luat/port/luat_timer_idf5.c

@@ -1,102 +0,0 @@
-
-#include "luat_base.h"
-#include "luat_malloc.h"
-#include "luat_timer.h"
-#include "luat_msgbus.h"
-#include "freertos/FreeRTOS.h"
-#include "freertos/task.h"
-#include "freertos/timers.h"
-#define LUAT_LOG_TAG "timer"
-#include "luat_log.h"
-
-#define FREERTOS_TIMER_COUNT 32
-static luat_timer_t* timers[FREERTOS_TIMER_COUNT] = {0};
-
-static void luat_timer_callback(TimerHandle_t xTimer) {
-    //LLOGD("timer callback");
-    rtos_msg_t msg;
-    size_t timer_id = (size_t)pvTimerGetTimerID(xTimer);
-    luat_timer_t *timer = luat_timer_get(timer_id);
-    if (timer == NULL)
-        return;
-    msg.handler = timer->func;
-    msg.ptr = timer;
-    msg.arg1 = timer_id;
-    msg.arg2 = 0;
-    luat_msgbus_put(&msg, 0);
-    // int re = luat_msgbus_put(&msg, 0);
-    //LLOGD("timer msgbus re=%ld", re);
-}
-
-static int nextTimerSlot() {
-    for (size_t i = 0; i < FREERTOS_TIMER_COUNT; i++)
-    {
-        if (timers[i] == NULL) {
-            return i;
-        }
-    }
-    return -1;
-}
-
-int luat_timer_start(luat_timer_t* timer) {
-    TimerHandle_t os_timer;
-    int timerIndex;
-    //LLOGD(">>luat_timer_start timeout=%ld", timer->timeout);
-    timerIndex = nextTimerSlot();
-    if (timerIndex < 0) {
-        LLOGE("too many timers");
-        return 1; // too many timer!!
-    }
-    os_timer = xTimerCreate("luat_timer", timer->timeout, 0 == timer->repeat ? 0 : 1, (void*)(timer->id), 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, 5);
-    //LLOGD("timer id=%ld timeout=%ld start=%ld", timerIndex, timer->timeout, re);
-    if (re != pdPASS) {
-        LLOGE("xTimerStart FAIL");
-        xTimerDelete(os_timer, 5);
-        timers[timerIndex] = NULL;
-    }
-    return re == pdPASS ? 0 : -1;
-}
-
-int luat_timer_stop(luat_timer_t* timer) {
-    if (timer == NULL || timer->os_timer == NULL)
-        return 1;
-    for (size_t i = 0; i < FREERTOS_TIMER_COUNT; i++)
-    {
-        if (timers[i] == timer) {
-            timers[i] = NULL;
-            break;
-        }
-    }
-    xTimerStop((TimerHandle_t)timer->os_timer, 1);
-    xTimerDelete((TimerHandle_t)timer->os_timer, 1);
-    timer->os_timer = NULL;
-    return 0;
-};
-
-luat_timer_t* luat_timer_get(size_t timer_id) {
-    for (size_t i = 0; i < FREERTOS_TIMER_COUNT; i++)
-    {
-        if (timers[i] && timers[i]->id == timer_id) {
-            return timers[i];
-        }
-    }
-    return NULL;
-}
-
-
-int luat_timer_mdelay(size_t ms) {
-    if (ms > 0) {
-        vTaskDelay(ms);
-    }
-    return 0;
-}
-