Browse Source

move: rtt只是其中一个bsp实现, 移动 luat/rtt 到 bsp/rtt

Wendal Chen 4 năm trước cách đây
mục cha
commit
c54eaaa3a0

+ 2 - 1
bsp/air100st/rtt/luat/SConscript

@@ -6,7 +6,8 @@ from building import *
 
 cwd = str(Dir('#'))
 #print(">>>" + cwd)
-objs = SConscript(os.path.join(cwd, '../../../lua/SConscript'))
+objs = SConscript(os.path.join(cwd, '../../rtt/SConscript'))
+objs = objs + SConscript(os.path.join(cwd, '../../../lua/SConscript'))
 objs = objs + SConscript(os.path.join(cwd, '../../../luat/SConscript'))
 
 src = Glob('*.c')

+ 2 - 1
bsp/air640w/rtt/luat/SConscript

@@ -3,7 +3,8 @@ import os
 Import('RTT_ROOT')
 
 cwd = str(Dir('#'))
-objs = SConscript(os.path.join(cwd, '../../../lua/SConscript'))
+objs = SConscript(os.path.join(cwd, '../../rtt/SConscript'))
+objs = objs + SConscript(os.path.join(cwd, '../../../lua/SConscript'))
 objs = objs + SConscript(os.path.join(cwd, '../../../luat/SConscript'))
 objs = objs + SConscript(os.path.join(cwd, '../../../components/network/lwip/SConscript'))
 objs = objs + SConscript(os.path.join(cwd, '../../../components/lcd/SConscript'))

+ 11 - 0
bsp/rtt/SConscript

@@ -0,0 +1,11 @@
+Import('RTT_ROOT')
+Import('rtconfig')
+from building import *
+
+cwd = GetCurrentDir()
+src	= Glob('*.c')
+CPPPATH = [cwd]
+
+group = DefineGroup('rtt', src, depend = [], CPPPATH = CPPPATH)
+
+Return('group')

+ 0 - 0
luat/rtt/luat_adc_rtt.c → bsp/rtt/luat_adc_rtt.c


+ 0 - 0
luat/rtt/luat_crypto_rtt.c → bsp/rtt/luat_crypto_rtt.c


+ 0 - 0
luat/rtt/luat_disp_rtt.c → bsp/rtt/luat_disp_rtt.c


+ 0 - 0
luat/rtt/luat_fs_rtt.c → bsp/rtt/luat_fs_rtt.c


+ 0 - 0
luat/rtt/luat_gpio_rtt.c → bsp/rtt/luat_gpio_rtt.c


+ 0 - 0
luat/rtt/luat_http_rtt.c → bsp/rtt/luat_http_rtt.c


+ 0 - 0
luat/rtt/luat_i2c_rtt.c → bsp/rtt/luat_i2c_rtt.c


+ 0 - 0
luat/rtt/luat_lib_utest.c → bsp/rtt/luat_lib_utest.c


+ 0 - 0
luat/rtt/luat_lib_wlan.c → bsp/rtt/luat_lib_wlan.c


+ 0 - 0
luat/rtt/luat_luadb_rtt.c → bsp/rtt/luat_luadb_rtt.c


+ 0 - 0
luat/rtt/luat_malloc_rtt.c → bsp/rtt/luat_malloc_rtt.c


+ 0 - 0
luat/rtt/luat_msgbus_rtt.c → bsp/rtt/luat_msgbus_rtt.c


+ 0 - 0
luat/rtt/luat_msh_rtt.c → bsp/rtt/luat_msh_rtt.c


+ 0 - 0
luat/rtt/luat_netclient_rtt.c → bsp/rtt/luat_netclient_rtt.c


+ 0 - 0
luat/rtt/luat_pwm_rtt.c → bsp/rtt/luat_pwm_rtt.c


+ 206 - 206
luat/rtt/luat_rtt_base.c → bsp/rtt/luat_rtt_base.c

@@ -1,206 +1,206 @@
-
-#include "luat_base.h"
-#include "luat_malloc.h"
-#include "rtthread.h"
-#include "stdio.h"
-#include "luat_msgbus.h"
-#include "rthw.h"
-// #include "vsprintf.h"
-
-#define DBG_TAG           "rtt.base"
-#define DBG_LVL           DBG_INFO
-#include <rtdbg.h>
-
-RT_WEAK void luat_timer_us_delay(size_t us) {
-    rt_hw_us_delay(us);
-}
-
-int luaopen_lwip(lua_State *L);
-
-// fix for mled加密库
-// rtt的方法名称变了. rt_hwcrypto_dev_dufault --> rt_hwcrypto_dev_default
-#ifdef RT_USING_HWCRYPTO
-#include <hwcrypto.h>
-RT_WEAK struct rt_hwcrypto_device *rt_hwcrypto_dev_dufault(void) {
-    return rt_hwcrypto_dev_default();
-}
-#endif
-
-// 文件系统初始化函数, 做个虚拟的
-RT_WEAK int luat_fs_init(void) {return 0;}
-
-static const luaL_Reg loadedlibs[] = {
-  {"_G", luaopen_base}, // _G
-  {LUA_LOADLIBNAME, luaopen_package}, // require
-  {LUA_COLIBNAME, luaopen_coroutine}, // coroutine协程库
-  {LUA_TABLIBNAME, luaopen_table},    // table库,操作table类型的数据结构
-  {LUA_IOLIBNAME, luaopen_io},        // io库,操作文件
-  {LUA_OSLIBNAME, luaopen_os},        // os库,已精简
-  {LUA_STRLIBNAME, luaopen_string},   // string库,字符串操作
-  {LUA_MATHLIBNAME, luaopen_math},    // math 数值计算
-//  {LUA_UTF8LIBNAME, luaopen_utf8},
-  {LUA_DBLIBNAME, luaopen_debug},     // debug库,已精简
-#if defined(LUA_COMPAT_BITLIB)
-  {LUA_BITLIBNAME, luaopen_bit32},    // 不太可能启用
-#endif
-// 往下是RTT环境下加载的库
-  {"rtos", luaopen_rtos},             // rtos底层库, 核心功能是队列和定时器
-  {"log", luaopen_log},               // 日志库
-  {"timer", luaopen_timer},           // 延时库
-  {"json", luaopen_cjson},            // json的序列化和反序列化
-  {"pack", luaopen_pack},             // pack.pack/pack.unpack
-  {"uart", luaopen_uart},             // 串口操作
-  {"mqttcore",luaopen_mqttcore},      // MQTT 协议封装
-  {"zbuff",luaopen_zbuff},            // zbuff库
-//  {"utest", luaopen_utest},
-#ifdef RT_USING_PIN
-  {"gpio", luaopen_gpio},              // GPIO脚的操作
-  {"sensor", luaopen_sensor},          // 传感器操作
-#endif
-#ifdef RT_USING_WIFI
-  {"wlan", luaopen_wlan},              // wlan/wifi联网操作
-#endif
-#ifdef SAL_USING_POSIX
-  {"socket", luaopen_socket},          // 套接字操作
-  {"http", luaopen_http},              // http库
-  // {"libcoap", luaopen_libcoap},        // 处理COAP数据包
-#endif
-#ifdef RT_USING_I2C
-  {"i2c", luaopen_i2c},                // I2C操作
-#endif
-#ifdef RT_USING_SPI
-  {"spi", luaopen_spi},                // SPI操作
-#endif
-#ifdef LUAT_USE_LCD
-  {"lcd",    luaopen_lcd},
-#endif
-#ifdef PKG_USING_U8G2
-  {"disp", luaopen_disp},              // 显示屏
-  {"u8g2", luaopen_u8g2},              // u8g2
-#endif
-#ifdef RT_USING_HWCRYPTO
-  {"crypto", luaopen_crypto},          // 加密和hash库
-#endif
-#ifdef RT_USING_PWM
-  {"pwm", luaopen_pwm},                //  PWM
-#endif
-  {"fs",   luaopen_fs},                // 文件系统库
-  // {"dbg",  luaopen_dbg},               // 调试库
-  // {"eink",  luaopen_eink},               // 电子墨水屏
-  // {"lfs2", luaopen_lfs2},              // spi flash ==> littelfs
-  // {"lwip", luaopen_lwip},              // lwip
-  {NULL, NULL}
-};
-
-// 按不同的rtconfig加载不同的库函数
-void luat_openlibs(lua_State *L) {
-    // 初始化队列服务
-    luat_msgbus_init();
-    //print_list_mem("done>luat_msgbus_init");
-    // 加载系统库
-    const luaL_Reg *lib;
-    /* "require" functions from 'loadedlibs' and set results to global table */
-    for (lib = loadedlibs; lib->func; lib++) {
-        luaL_requiref(L, lib->name, lib->func, 1);
-        lua_pop(L, 1);  /* remove lib */
-        //extern void print_list_mem(const char* name);
-        //print_list_mem(lib->name);
-    }
-}
-
-void luat_os_reboot(int code) {
-    rt_hw_cpu_reset();
-}
-
-void sys_start_standby(int ms);
-
-RT_WEAK void luat_os_standy(int timeout) {
-    #ifdef BSP_USING_WM_LIBRARIES
-        #ifdef BSP_USING_STANDBY
-            sys_start_standby(timeout);
-        #endif
-    #endif
-}
-
-RT_WEAK const char* luat_os_bsp(void) {
-    #ifdef BSP_USING_WM_LIBRARIES
-        return "w60x";
-    #else
-        #ifdef SOC_FAMILY_STM32
-            return "stm32";
-        #else
-            return "_";
-        #endif
-    #endif
-}
-
-
-RT_WEAK void rt_hw_us_delay(rt_uint32_t us)
-{
-    ; // nop
-}
-
-#ifndef SOC_FAMILY_STM32
-RT_WEAK void rt_hw_cpu_reset() {
-    ; // nop
-}
-#endif
-
-// watchdog
-
-#ifdef BSP_USING_WDT
-#include <rtdevice.h>
-static rt_uint32_t wdg_timeout = 15;       /* 溢出时间,单位:秒*/
-static rt_device_t wdg_dev;    /* 看门狗设备句柄 */
-static int wdt_chk(void) {
-    wdg_dev = rt_device_find("wdt");
-    if (wdg_dev == RT_NULL) {
-        wdg_dev = rt_device_find("wdg");
-        if (wdg_dev == RT_NULL) {
-            LOG_I("watchdog is miss");
-            return RT_EOK;
-        }
-    }
-    LOG_I("watchdog found, enable it");
-    rt_device_init(wdg_dev);
-    rt_device_control(wdg_dev, RT_DEVICE_CTRL_WDT_SET_TIMEOUT, (void *)wdg_timeout);
-    rt_device_control(wdg_dev, RT_DEVICE_CTRL_WDT_START, (void *)wdg_timeout);
-    //rt_thread_idle_sethook(idle_hook);
-    return RT_EOK;
-}
-INIT_DEVICE_EXPORT(wdt_chk);
-
-#define THREAD_PRIORITY         25
-#define THREAD_TIMESLICE        5
-
-ALIGN(RT_ALIGN_SIZE)
-static char rtt_wdt_stack[256];
-static struct rt_thread rtt_wdt;
-static int rtt_wdt_feed(void* args) {
-    while (1) {
-        if (wdg_dev)
-            rt_device_control(wdg_dev, RT_DEVICE_CTRL_WDT_KEEPALIVE, NULL);
-        rt_thread_mdelay(5000);
-    }
-    return 0;
-}
-static int rtt_wdt_thread_start() {
-    rt_thread_init(&rtt_wdt,
-                   "rtt_wdt",
-                   rtt_wdt_feed,
-                   RT_NULL,
-                   &rtt_wdt_stack[0],
-                   sizeof(rtt_wdt_stack),
-                   THREAD_PRIORITY - 1, THREAD_TIMESLICE);
-    rt_thread_startup(&rtt_wdt);
-}
-INIT_COMPONENT_EXPORT(rtt_wdt_thread_start);
-#endif
-
-void luat_os_entry_cri(void) {
-  rt_interrupt_enter();
-}
-
-void luat_os_exit_cri(void) {
-  rt_interrupt_leave();
-}
+
+#include "luat_base.h"
+#include "luat_malloc.h"
+#include "rtthread.h"
+#include "stdio.h"
+#include "luat_msgbus.h"
+#include "rthw.h"
+// #include "vsprintf.h"
+
+#define DBG_TAG           "rtt.base"
+#define DBG_LVL           DBG_INFO
+#include <rtdbg.h>
+
+RT_WEAK void luat_timer_us_delay(size_t us) {
+    rt_hw_us_delay(us);
+}
+
+int luaopen_lwip(lua_State *L);
+
+// fix for mled加密库
+// rtt的方法名称变了. rt_hwcrypto_dev_dufault --> rt_hwcrypto_dev_default
+#ifdef RT_USING_HWCRYPTO
+#include <hwcrypto.h>
+RT_WEAK struct rt_hwcrypto_device *rt_hwcrypto_dev_dufault(void) {
+    return rt_hwcrypto_dev_default();
+}
+#endif
+
+// 文件系统初始化函数, 做个虚拟的
+RT_WEAK int luat_fs_init(void) {return 0;}
+
+static const luaL_Reg loadedlibs[] = {
+  {"_G", luaopen_base}, // _G
+  {LUA_LOADLIBNAME, luaopen_package}, // require
+  {LUA_COLIBNAME, luaopen_coroutine}, // coroutine协程库
+  {LUA_TABLIBNAME, luaopen_table},    // table库,操作table类型的数据结构
+  {LUA_IOLIBNAME, luaopen_io},        // io库,操作文件
+  {LUA_OSLIBNAME, luaopen_os},        // os库,已精简
+  {LUA_STRLIBNAME, luaopen_string},   // string库,字符串操作
+  {LUA_MATHLIBNAME, luaopen_math},    // math 数值计算
+//  {LUA_UTF8LIBNAME, luaopen_utf8},
+  {LUA_DBLIBNAME, luaopen_debug},     // debug库,已精简
+#if defined(LUA_COMPAT_BITLIB)
+  {LUA_BITLIBNAME, luaopen_bit32},    // 不太可能启用
+#endif
+// 往下是RTT环境下加载的库
+  {"rtos", luaopen_rtos},             // rtos底层库, 核心功能是队列和定时器
+  {"log", luaopen_log},               // 日志库
+  {"timer", luaopen_timer},           // 延时库
+  {"json", luaopen_cjson},            // json的序列化和反序列化
+  {"pack", luaopen_pack},             // pack.pack/pack.unpack
+  {"uart", luaopen_uart},             // 串口操作
+  {"mqttcore",luaopen_mqttcore},      // MQTT 协议封装
+  {"zbuff",luaopen_zbuff},            // zbuff库
+//  {"utest", luaopen_utest},
+#ifdef RT_USING_PIN
+  {"gpio", luaopen_gpio},              // GPIO脚的操作
+  {"sensor", luaopen_sensor},          // 传感器操作
+#endif
+#ifdef RT_USING_WIFI
+  {"wlan", luaopen_wlan},              // wlan/wifi联网操作
+#endif
+#ifdef SAL_USING_POSIX
+  {"socket", luaopen_socket},          // 套接字操作
+  {"http", luaopen_http},              // http库
+  // {"libcoap", luaopen_libcoap},        // 处理COAP数据包
+#endif
+#ifdef RT_USING_I2C
+  {"i2c", luaopen_i2c},                // I2C操作
+#endif
+#ifdef RT_USING_SPI
+  {"spi", luaopen_spi},                // SPI操作
+#endif
+#ifdef LUAT_USE_LCD
+  {"lcd",    luaopen_lcd},
+#endif
+#ifdef PKG_USING_U8G2
+  {"disp", luaopen_disp},              // 显示屏
+  {"u8g2", luaopen_u8g2},              // u8g2
+#endif
+#ifdef RT_USING_HWCRYPTO
+  {"crypto", luaopen_crypto},          // 加密和hash库
+#endif
+#ifdef RT_USING_PWM
+  {"pwm", luaopen_pwm},                //  PWM
+#endif
+  {"fs",   luaopen_fs},                // 文件系统库
+  // {"dbg",  luaopen_dbg},               // 调试库
+  // {"eink",  luaopen_eink},               // 电子墨水屏
+  // {"lfs2", luaopen_lfs2},              // spi flash ==> littelfs
+  // {"lwip", luaopen_lwip},              // lwip
+  {NULL, NULL}
+};
+
+// 按不同的rtconfig加载不同的库函数
+void luat_openlibs(lua_State *L) {
+    // 初始化队列服务
+    luat_msgbus_init();
+    //print_list_mem("done>luat_msgbus_init");
+    // 加载系统库
+    const luaL_Reg *lib;
+    /* "require" functions from 'loadedlibs' and set results to global table */
+    for (lib = loadedlibs; lib->func; lib++) {
+        luaL_requiref(L, lib->name, lib->func, 1);
+        lua_pop(L, 1);  /* remove lib */
+        //extern void print_list_mem(const char* name);
+        //print_list_mem(lib->name);
+    }
+}
+
+void luat_os_reboot(int code) {
+    rt_hw_cpu_reset();
+}
+
+void sys_start_standby(int ms);
+
+RT_WEAK void luat_os_standy(int timeout) {
+    #ifdef BSP_USING_WM_LIBRARIES
+        #ifdef BSP_USING_STANDBY
+            sys_start_standby(timeout);
+        #endif
+    #endif
+}
+
+RT_WEAK const char* luat_os_bsp(void) {
+    #ifdef BSP_USING_WM_LIBRARIES
+        return "w60x";
+    #else
+        #ifdef SOC_FAMILY_STM32
+            return "stm32";
+        #else
+            return "_";
+        #endif
+    #endif
+}
+
+
+RT_WEAK void rt_hw_us_delay(rt_uint32_t us)
+{
+    ; // nop
+}
+
+#ifndef SOC_FAMILY_STM32
+RT_WEAK void rt_hw_cpu_reset() {
+    ; // nop
+}
+#endif
+
+// watchdog
+
+#ifdef BSP_USING_WDT
+#include <rtdevice.h>
+static rt_uint32_t wdg_timeout = 15;       /* 溢出时间,单位:秒*/
+static rt_device_t wdg_dev;    /* 看门狗设备句柄 */
+static int wdt_chk(void) {
+    wdg_dev = rt_device_find("wdt");
+    if (wdg_dev == RT_NULL) {
+        wdg_dev = rt_device_find("wdg");
+        if (wdg_dev == RT_NULL) {
+            LOG_I("watchdog is miss");
+            return RT_EOK;
+        }
+    }
+    LOG_I("watchdog found, enable it");
+    rt_device_init(wdg_dev);
+    rt_device_control(wdg_dev, RT_DEVICE_CTRL_WDT_SET_TIMEOUT, (void *)wdg_timeout);
+    rt_device_control(wdg_dev, RT_DEVICE_CTRL_WDT_START, (void *)wdg_timeout);
+    //rt_thread_idle_sethook(idle_hook);
+    return RT_EOK;
+}
+INIT_DEVICE_EXPORT(wdt_chk);
+
+#define THREAD_PRIORITY         25
+#define THREAD_TIMESLICE        5
+
+ALIGN(RT_ALIGN_SIZE)
+static char rtt_wdt_stack[256];
+static struct rt_thread rtt_wdt;
+static int rtt_wdt_feed(void* args) {
+    while (1) {
+        if (wdg_dev)
+            rt_device_control(wdg_dev, RT_DEVICE_CTRL_WDT_KEEPALIVE, NULL);
+        rt_thread_mdelay(5000);
+    }
+    return 0;
+}
+static int rtt_wdt_thread_start() {
+    rt_thread_init(&rtt_wdt,
+                   "rtt_wdt",
+                   rtt_wdt_feed,
+                   RT_NULL,
+                   &rtt_wdt_stack[0],
+                   sizeof(rtt_wdt_stack),
+                   THREAD_PRIORITY - 1, THREAD_TIMESLICE);
+    rt_thread_startup(&rtt_wdt);
+}
+INIT_COMPONENT_EXPORT(rtt_wdt_thread_start);
+#endif
+
+void luat_os_entry_cri(void) {
+  rt_interrupt_enter();
+}
+
+void luat_os_exit_cri(void) {
+  rt_interrupt_leave();
+}

+ 0 - 0
luat/rtt/luat_socket_rtt.c → bsp/rtt/luat_socket_rtt.c


+ 0 - 0
luat/rtt/luat_spi_rtt.c → bsp/rtt/luat_spi_rtt.c


+ 0 - 0
luat/rtt/luat_sys_rtt.c → bsp/rtt/luat_sys_rtt.c


+ 0 - 0
luat/rtt/luat_timer_rtt.c → bsp/rtt/luat_timer_rtt.c


+ 204 - 204
luat/rtt/luat_uart_rtt.c → bsp/rtt/luat_uart_rtt.c

@@ -1,204 +1,204 @@
-#include "luat_base.h"
-#include "luat_malloc.h"
-#include "luat_msgbus.h"
-#include "luat_uart.h"
-#include "luat_log.h"
-
-#include "rtthread.h"
-#include <rtdevice.h>
-#include "drivers/serial.h"
-
-#define DBG_TAG           "rtt.uart"
-#define DBG_LVL           DBG_WARNING
-#include <rtdbg.h>
-
-//串口数量,编号从0开始
-#define MAX_DEVICE_COUNT 10
-//存放串口设备句柄
-static rt_device_t serials[MAX_DEVICE_COUNT];
-static uint8_t serials_marks[MAX_DEVICE_COUNT];
-static uint8_t uart_init_complete = 0;
-
-int luat_uart_rtt_init() {
-    if (uart_init_complete) return 0;
-    char name[8];
-    name[0] = 'u';
-    name[1] = 'a';
-    name[2] = 'r';
-    name[3] = 't';
-    name[5] = 0;
-    
-    // 搜索uart0, uart1, ....
-    for (size_t i = 0; i < MAX_DEVICE_COUNT; i++)
-    {
-        name[4] = '0' + i;
-        serials[i] = rt_device_find(name);
-        //LOG_I("uart device dev=0x%08X uart.id=%ld", serials[i], i);
-    }
-    uart_init_complete = 1;
-    return 0;
-}
-INIT_COMPONENT_EXPORT(luat_uart_rtt_init);
-
-static int get_uart_id(rt_device_t dev) {
-    int i;
-    for(i=0;i<MAX_DEVICE_COUNT;i++)
-    {
-        if (serials[i] == dev) {
-            //LOG_I("uart device dev->id=%d uart.id=%ld", dev->device_id, i);
-            return i;
-        }
-    }
-    LOG_W("not uart device dev=0x%08X", dev);
-    return -1;
-}
-
-int luat_uart_exist(int uartid) {
-    if (uartid < 0 || uartid >= MAX_DEVICE_COUNT) {
-        return 0;
-    }
-    luat_uart_rtt_init();
-    return serials[uartid] ? 1 : 0;
-}
-
-//接收数据回调
-static rt_err_t uart_input_cb(rt_device_t dev, rt_size_t size)
-{
-    int uart_id = get_uart_id(dev);
-    LOG_I("uart receive rtt cb, id=%ld", uart_id);
-    if (uart_id < 0) {
-        return RT_EOK;
-    }
-    if (serials_marks[uart_id]) {
-        // 前一个回调都还没读呢
-        return RT_EOK;
-    }
-    serials_marks[uart_id] = 1;
-    rtos_msg_t msg;
-    msg.handler = l_uart_handler;
-    msg.ptr = RT_NULL;
-    msg.arg1 = uart_id;
-    msg.arg2 = size;
-    luat_msgbus_put(&msg, 1);
-    return RT_EOK;
-}
-
-//串口发送完成事件回调
-static rt_err_t uart_sent_cb(rt_device_t dev, void *buffer)
-{
-    int uart_id = get_uart_id(dev);
-    LOG_I("uart sent rtt cb, id=%ld", uart_id);
-    if (uart_id < 0) {
-        return RT_EOK;
-    }
-    rtos_msg_t msg;
-    msg.handler = l_uart_handler;
-    msg.arg1 = uart_id;
-    msg.arg2 = 0;
-    msg.ptr = buffer;
-    luat_msgbus_put(&msg, 1);
-    return RT_EOK;
-}
-
-int luat_uart_setup(luat_uart_t* uart)
-{
-    if(uart->id > MAX_DEVICE_COUNT)
-    {
-        return -1;
-    }
-    rt_device_t dev = serials[uart->id];
-    if (dev == RT_NULL) {
-        return -2;
-    }
-
-    struct serial_configure config = RT_SERIAL_CONFIG_DEFAULT;
-    config.baud_rate = uart->baud_rate;
-    config.data_bits = uart->data_bits;
-    config.stop_bits = uart->stop_bits - 1;
-    //config.bufsz     = uart->bufsz;
-    config.bufsz     = 512;
-    config.parity    = uart->parity;
-    config.bit_order = uart->bit_order;
-    rt_device_control(dev, RT_DEVICE_CTRL_CONFIG, &config);
-
-    rt_err_t re = rt_device_open(dev, RT_DEVICE_FLAG_INT_RX);
-    if(re != RT_EOK)
-        return re;//失败了
-    return re;
-}
-#ifdef FALSE123
-#include "wm_uart.h"
-int tls_uart_dma_write(char *buf, u16 writesize, void (*cmpl_callback) (void *p), u16 uart_no);
-#endif
-int luat_uart_write(int uartid, void* data, size_t length)
-{
-    if(!luat_uart_exist(uartid)) {
-        LOG_W("uart id=%d not exist", uartid);
-        return -1;
-    }
-    if (serials[uartid]->open_flag == 0) {
-        LOG_W("uart id=%d is closed", uartid);
-        return -1;
-    }
-    if (uartid == 1)
-    {
-    #ifdef FALSE123
-        int re = tls_uart_dma_write(data, length, RT_NULL, 1);
-        LOG_I("tls_uart_dma_write re=%d", re);
-        return 0;
-    #endif
-    }
-    int re = rt_device_write(serials[uartid], 0, data, length);
-    LOG_I("luat_uart_write id=%ld re=%ld length=%ld", uartid, re, length);
-    return re;
-}
-
-int luat_uart_read(int uartid, void* buffer, size_t length)
-{
-    if(!luat_uart_exist(uartid)) {
-        LOG_W("uart id=%d not exist", uartid);
-        return -1;
-    }
-    if (serials[uartid]->open_flag == 0) {
-        LOG_W("uart id=%d is closed", uartid);
-        return -1;
-    }
-    serials_marks[uartid] = 0;
-    int re = rt_device_read(serials[uartid], -1, buffer, length);
-    return re;
-}
-
-int luat_uart_close(int uartid)
-{
-    if(!luat_uart_exist(uartid)) {
-        LOG_W("uart id=%d not exist", uartid);
-        return 0;
-    }
-    int re = rt_device_close(serials[uartid]);
-    return re;
-}
-
-int luat_setup_cb(int uartid, int received, int sent) {
-    if (!luat_uart_exist(uartid)) {
-        LOG_W("uart id=%d not exist", uartid);
-        return -1;
-    }
-    if (received) {
-        LOG_I("uart id=%d set rx_indicate", uartid);
-        rt_device_set_rx_indicate(serials[uartid], uart_input_cb);
-    }
-    else {
-        LOG_I("uart id=%d unset rx_indicate", uartid);
-        rt_device_set_rx_indicate(serials[uartid], RT_NULL);
-    }
-
-    if (sent) {
-        LOG_I("uart id=%d set tx_complete", uartid);
-        rt_device_set_tx_complete(serials[uartid], uart_sent_cb);
-    }
-    else {
-        LOG_I("uart id=%d unset tx_complete", uartid);
-        rt_device_set_tx_complete(serials[uartid], RT_NULL);
-    }
-    return 0;
-}
+#include "luat_base.h"
+#include "luat_malloc.h"
+#include "luat_msgbus.h"
+#include "luat_uart.h"
+#include "luat_log.h"
+
+#include "rtthread.h"
+#include <rtdevice.h>
+#include "drivers/serial.h"
+
+#define DBG_TAG           "rtt.uart"
+#define DBG_LVL           DBG_WARNING
+#include <rtdbg.h>
+
+//串口数量,编号从0开始
+#define MAX_DEVICE_COUNT 10
+//存放串口设备句柄
+static rt_device_t serials[MAX_DEVICE_COUNT];
+static uint8_t serials_marks[MAX_DEVICE_COUNT];
+static uint8_t uart_init_complete = 0;
+
+int luat_uart_rtt_init() {
+    if (uart_init_complete) return 0;
+    char name[8];
+    name[0] = 'u';
+    name[1] = 'a';
+    name[2] = 'r';
+    name[3] = 't';
+    name[5] = 0;
+    
+    // 搜索uart0, uart1, ....
+    for (size_t i = 0; i < MAX_DEVICE_COUNT; i++)
+    {
+        name[4] = '0' + i;
+        serials[i] = rt_device_find(name);
+        //LOG_I("uart device dev=0x%08X uart.id=%ld", serials[i], i);
+    }
+    uart_init_complete = 1;
+    return 0;
+}
+INIT_COMPONENT_EXPORT(luat_uart_rtt_init);
+
+static int get_uart_id(rt_device_t dev) {
+    int i;
+    for(i=0;i<MAX_DEVICE_COUNT;i++)
+    {
+        if (serials[i] == dev) {
+            //LOG_I("uart device dev->id=%d uart.id=%ld", dev->device_id, i);
+            return i;
+        }
+    }
+    LOG_W("not uart device dev=0x%08X", dev);
+    return -1;
+}
+
+int luat_uart_exist(int uartid) {
+    if (uartid < 0 || uartid >= MAX_DEVICE_COUNT) {
+        return 0;
+    }
+    luat_uart_rtt_init();
+    return serials[uartid] ? 1 : 0;
+}
+
+//接收数据回调
+static rt_err_t uart_input_cb(rt_device_t dev, rt_size_t size)
+{
+    int uart_id = get_uart_id(dev);
+    LOG_I("uart receive rtt cb, id=%ld", uart_id);
+    if (uart_id < 0) {
+        return RT_EOK;
+    }
+    if (serials_marks[uart_id]) {
+        // 前一个回调都还没读呢
+        return RT_EOK;
+    }
+    serials_marks[uart_id] = 1;
+    rtos_msg_t msg;
+    msg.handler = l_uart_handler;
+    msg.ptr = RT_NULL;
+    msg.arg1 = uart_id;
+    msg.arg2 = size;
+    luat_msgbus_put(&msg, 1);
+    return RT_EOK;
+}
+
+//串口发送完成事件回调
+static rt_err_t uart_sent_cb(rt_device_t dev, void *buffer)
+{
+    int uart_id = get_uart_id(dev);
+    LOG_I("uart sent rtt cb, id=%ld", uart_id);
+    if (uart_id < 0) {
+        return RT_EOK;
+    }
+    rtos_msg_t msg;
+    msg.handler = l_uart_handler;
+    msg.arg1 = uart_id;
+    msg.arg2 = 0;
+    msg.ptr = buffer;
+    luat_msgbus_put(&msg, 1);
+    return RT_EOK;
+}
+
+int luat_uart_setup(luat_uart_t* uart)
+{
+    if(uart->id > MAX_DEVICE_COUNT)
+    {
+        return -1;
+    }
+    rt_device_t dev = serials[uart->id];
+    if (dev == RT_NULL) {
+        return -2;
+    }
+
+    struct serial_configure config = RT_SERIAL_CONFIG_DEFAULT;
+    config.baud_rate = uart->baud_rate;
+    config.data_bits = uart->data_bits;
+    config.stop_bits = uart->stop_bits - 1;
+    //config.bufsz     = uart->bufsz;
+    config.bufsz     = 512;
+    config.parity    = uart->parity;
+    config.bit_order = uart->bit_order;
+    rt_device_control(dev, RT_DEVICE_CTRL_CONFIG, &config);
+
+    rt_err_t re = rt_device_open(dev, RT_DEVICE_FLAG_INT_RX);
+    if(re != RT_EOK)
+        return re;//失败了
+    return re;
+}
+#ifdef FALSE123
+#include "wm_uart.h"
+int tls_uart_dma_write(char *buf, u16 writesize, void (*cmpl_callback) (void *p), u16 uart_no);
+#endif
+int luat_uart_write(int uartid, void* data, size_t length)
+{
+    if(!luat_uart_exist(uartid)) {
+        LOG_W("uart id=%d not exist", uartid);
+        return -1;
+    }
+    if (serials[uartid]->open_flag == 0) {
+        LOG_W("uart id=%d is closed", uartid);
+        return -1;
+    }
+    if (uartid == 1)
+    {
+    #ifdef FALSE123
+        int re = tls_uart_dma_write(data, length, RT_NULL, 1);
+        LOG_I("tls_uart_dma_write re=%d", re);
+        return 0;
+    #endif
+    }
+    int re = rt_device_write(serials[uartid], 0, data, length);
+    LOG_I("luat_uart_write id=%ld re=%ld length=%ld", uartid, re, length);
+    return re;
+}
+
+int luat_uart_read(int uartid, void* buffer, size_t length)
+{
+    if(!luat_uart_exist(uartid)) {
+        LOG_W("uart id=%d not exist", uartid);
+        return -1;
+    }
+    if (serials[uartid]->open_flag == 0) {
+        LOG_W("uart id=%d is closed", uartid);
+        return -1;
+    }
+    serials_marks[uartid] = 0;
+    int re = rt_device_read(serials[uartid], -1, buffer, length);
+    return re;
+}
+
+int luat_uart_close(int uartid)
+{
+    if(!luat_uart_exist(uartid)) {
+        LOG_W("uart id=%d not exist", uartid);
+        return 0;
+    }
+    int re = rt_device_close(serials[uartid]);
+    return re;
+}
+
+int luat_setup_cb(int uartid, int received, int sent) {
+    if (!luat_uart_exist(uartid)) {
+        LOG_W("uart id=%d not exist", uartid);
+        return -1;
+    }
+    if (received) {
+        LOG_I("uart id=%d set rx_indicate", uartid);
+        rt_device_set_rx_indicate(serials[uartid], uart_input_cb);
+    }
+    else {
+        LOG_I("uart id=%d unset rx_indicate", uartid);
+        rt_device_set_rx_indicate(serials[uartid], RT_NULL);
+    }
+
+    if (sent) {
+        LOG_I("uart id=%d set tx_complete", uartid);
+        rt_device_set_tx_complete(serials[uartid], uart_sent_cb);
+    }
+    else {
+        LOG_I("uart id=%d unset tx_complete", uartid);
+        rt_device_set_tx_complete(serials[uartid], RT_NULL);
+    }
+    return 0;
+}

+ 0 - 0
luat/rtt/rtt_airkiss.c → bsp/rtt/rtt_airkiss.c


+ 0 - 0
luat/rtt/webclient.c → bsp/rtt/webclient.c


+ 0 - 0
luat/rtt/webclient.h → bsp/rtt/webclient.h


+ 0 - 17
luat/rtt/SConscript

@@ -1,17 +0,0 @@
-Import('RTT_ROOT')
-Import('rtconfig')
-from building import *
-
-cwd = GetCurrentDir()
-src	= Glob('*.c')
-CPPPATH = [cwd,  cwd + "/../include", 
-                 cwd + "/../packages/vsprintf", 
-                 cwd + "/../packages/lfs",
-                 cwd + "/../packages/airkiss",
-                 cwd + "/../packages/fatfs",
-                 cwd + "/../packages/u8g2",
-                 ]
-
-group = DefineGroup('rtt', src, depend = [], CPPPATH = CPPPATH)
-
-Return('group')

+ 6 - 1
luat/vfs/SConscript

@@ -1,7 +1,12 @@
 from building import *
 
 cwd = GetCurrentDir()
-src = Glob('*.c')
+src	= []
+for p in os.listdir(cwd) :
+    if p.endswith(".c"):
+        src += [p]
+
+src.remove('luat_fs_fatfs.c')
 
 CPPPATH = [cwd]