Sfoglia il codice sorgente

remove: bsp/win32已经完全用luatos-soc-pc替代,删除主库里的bsp文件

Wendal Chen 2 anni fa
parent
commit
3cda9931b5
53 ha cambiato i file con 0 aggiunte e 4773 eliminazioni
  1. 0 62
      bsp/win32/README.md
  2. BIN
      bsp/win32/example.gif
  3. 0 917
      bsp/win32/include/dirent.h
  4. 0 138
      bsp/win32/include/luat_conf_bsp.h
  5. 0 30
      bsp/win32/luf_test/abc.lua
  6. BIN
      bsp/win32/luf_test/abc.luf
  7. 0 18
      bsp/win32/luf_test/disk/main.lua
  8. 0 116
      bsp/win32/luf_test/luadb.lua
  9. 0 22
      bsp/win32/luf_test/main.lua
  10. 0 32
      bsp/win32/luf_test/main_luf.lua
  11. 0 44
      bsp/win32/luf_test/main_test.lua
  12. 0 404
      bsp/win32/luf_test/sys.lua
  13. 0 1
      bsp/win32/luf_test/toburn.bat
  14. 0 1
      bsp/win32/luf_test/toimg.bat
  15. 0 11
      bsp/win32/main.lua
  16. 0 26
      bsp/win32/module_test/001task.lua
  17. 0 34
      bsp/win32/module_test/002json.lua
  18. 0 73
      bsp/win32/module_test/003zbuff.lua
  19. 0 68
      bsp/win32/module_test/004crypto.lua
  20. 0 36
      bsp/win32/module_test/005io.lua
  21. 0 57
      bsp/win32/module_test/006fatfs.lua
  22. 0 33
      bsp/win32/module_test/007lfs2.lua
  23. 0 49
      bsp/win32/module_test/010lvgl.lua
  24. 0 11
      bsp/win32/module_test/012vmx.lua
  25. 0 19
      bsp/win32/module_test/013cwait.lua
  26. 0 43
      bsp/win32/module_test/014iotauth.lua
  27. 0 41
      bsp/win32/module_test/015miniz.lua
  28. 0 19
      bsp/win32/module_test/readme.md
  29. 0 25
      bsp/win32/module_test/test.sh
  30. 0 128
      bsp/win32/port/luat_base_win32.c
  31. 0 14
      bsp/win32/port/luat_crypto_win32.c
  32. 0 61
      bsp/win32/port/luat_fs_win32.c
  33. 0 73
      bsp/win32/port/luat_gpio_win32.c
  34. 0 34
      bsp/win32/port/luat_i2c_win32.c
  35. 0 80
      bsp/win32/port/luat_lib_win32.c
  36. 0 86
      bsp/win32/port/luat_log_win32.c
  37. 0 89
      bsp/win32/port/luat_malloc_win32.c
  38. 0 17
      bsp/win32/port/luat_mcu_win32.c
  39. 0 73
      bsp/win32/port/luat_msgbus_win32.c
  40. 0 21
      bsp/win32/port/luat_sfd_onchip_win32.c
  41. 0 49
      bsp/win32/port/luat_spi_device.c
  42. 0 84
      bsp/win32/port/luat_spi_win32.c
  43. 0 125
      bsp/win32/port/luat_timer_win32.c
  44. 0 29
      bsp/win32/port/luat_u8g2_win32.c
  45. 0 101
      bsp/win32/port/luat_uart_win32.c
  46. 0 614
      bsp/win32/src/lua.c
  47. 0 89
      bsp/win32/src/main_win32.c
  48. 0 21
      bsp/win32/tools/luat_uart/.gitignore
  49. 0 26
      bsp/win32/tools/luat_uart/Cargo.toml
  50. 0 301
      bsp/win32/tools/luat_uart/src/lib.rs
  51. 0 96
      bsp/win32/tools/update_inline_sys.lua
  52. 0 95
      bsp/win32/tools/update_luadb_inline.lua
  53. 0 137
      bsp/win32/xmake.lua

+ 0 - 62
bsp/win32/README.md

@@ -1,62 +0,0 @@
-
-# LuatOS@Win32
-
-* 底层rtos FreeRTOSv202012.00
-* 编译环境msys, 工具cmake/make/gcc
-* 文件系统,win32原生文件系统,以工作目录为基点
-* 默认luavm和rtos内存分配均为 1MByte
-
-下载[预编译好的luatos.exe](https://nightly.link/openLuat/LuatOS/workflows/win32/master)
-
-## 简易编译说明
-
-* 下载msys环境, 并安装好gcc和make
-* 到Cmake官网下载独立的cmake最新版
-* 进入msys环境, cd到本bsp目录,执行 `./build_cmake.sh`
-
-编译完成后, 会在build目录生成 `luatos.exe`
-
-提示: 使用`mingw32.exe`/`mingw64.exe`启动编译环境, 可以编译出不依赖`msys-2.0.dll`的exe文件
-
-https://www.thinbug.com/q/37524839
-
-## 简单用法
-
-* 新建一个目录, 将 `luatos.exe` 拷贝进去(可选,执行时使用全路径也可以)
-* 在目录内新建main.lua, 写入以下内容
-
-```lua
-local sys = require "sys"
-
-log.info("sys", "from win32")
-
-sys.taskInit(function ()
-    while true do
-        log.info("hi", os.date())
-        log.info("sys", rtos.meminfo("sys"))
-        log.info("lua", rtos.meminfo("lua"))
-        sys.wait(1000)
-    end
-end)
-
-sys.run()
-
-```
-
-### 启动方式1,命令行参数
-
-进入cmd或ps命令行后, cd到main.lua所在目录, 确保luatos.exe 也在同一目录下或者在PATH内
-
-```
-luatos.exe main.lua
-```
-
-### 启动方式1,交互模式
-
-1. 双击luatos.exe启动
-2. 输入 `load("main.lua")()`
-
-## 更多调用示例
-
-参考 https://gitee.com/openLuat/LuatOS/tree/master/demo/lvgl/win32
-

BIN
bsp/win32/example.gif


+ 0 - 917
bsp/win32/include/dirent.h

@@ -1,917 +0,0 @@
-/*
- * Dirent interface for Microsoft Visual Studio
- * Version 1.21
- *
- * Copyright (C) 2006-2012 Toni Ronkko
- * This file is part of dirent.  Dirent may be freely distributed
- * under the MIT license.  For all details and documentation, see
- * https://github.com/tronkko/dirent
- */
-#ifndef DIRENT_H
-#define DIRENT_H
-
-/*
- * Define architecture flags so we don't need to include windows.h.
- * Avoiding windows.h makes it simpler to use windows sockets in conjunction
- * with dirent.h.
- */
-#if !defined(_68K_) && !defined(_MPPC_) && !defined(_X86_) && !defined(_IA64_) && !defined(_AMD64_) && defined(_M_IX86)
-#   define _X86_
-#endif
-#if !defined(_68K_) && !defined(_MPPC_) && !defined(_X86_) && !defined(_IA64_) && !defined(_AMD64_) && defined(_M_AMD64)
-#define _AMD64_
-#endif
-
-#include <stdio.h>
-#include <stdarg.h>
-#include <windef.h>
-#include <winbase.h>
-#include <wchar.h>
-#include <string.h>
-#include <stdlib.h>
-#include <malloc.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <errno.h>
-
-/* Indicates that d_type field is available in dirent structure */
-#define _DIRENT_HAVE_D_TYPE
-
-/* Indicates that d_namlen field is available in dirent structure */
-#define _DIRENT_HAVE_D_NAMLEN
-
-/* Entries missing from MSVC 6.0 */
-#if !defined(FILE_ATTRIBUTE_DEVICE)
-#   define FILE_ATTRIBUTE_DEVICE 0x40
-#endif
-
-/* File type and permission flags for stat(), general mask */
-#if !defined(S_IFMT)
-#   define S_IFMT _S_IFMT
-#endif
-
-/* Directory bit */
-#if !defined(S_IFDIR)
-#   define S_IFDIR _S_IFDIR
-#endif
-
-/* Character device bit */
-#if !defined(S_IFCHR)
-#   define S_IFCHR _S_IFCHR
-#endif
-
-/* Pipe bit */
-#if !defined(S_IFFIFO)
-#   define S_IFFIFO _S_IFFIFO
-#endif
-
-/* Regular file bit */
-#if !defined(S_IFREG)
-#   define S_IFREG _S_IFREG
-#endif
-
-/* Read permission */
-#if !defined(S_IREAD)
-#   define S_IREAD _S_IREAD
-#endif
-
-/* Write permission */
-#if !defined(S_IWRITE)
-#   define S_IWRITE _S_IWRITE
-#endif
-
-/* Execute permission */
-#if !defined(S_IEXEC)
-#   define S_IEXEC _S_IEXEC
-#endif
-
-/* Pipe */
-#if !defined(S_IFIFO)
-#   define S_IFIFO _S_IFIFO
-#endif
-
-/* Block device */
-#if !defined(S_IFBLK)
-#   define S_IFBLK 0
-#endif
-
-/* Link */
-#if !defined(S_IFLNK)
-#   define S_IFLNK 0
-#endif
-
-/* Socket */
-#if !defined(S_IFSOCK)
-#   define S_IFSOCK 0
-#endif
-
-/* Read user permission */
-#if !defined(S_IRUSR)
-#   define S_IRUSR S_IREAD
-#endif
-
-/* Write user permission */
-#if !defined(S_IWUSR)
-#   define S_IWUSR S_IWRITE
-#endif
-
-/* Execute user permission */
-#if !defined(S_IXUSR)
-#   define S_IXUSR 0
-#endif
-
-/* Read group permission */
-#if !defined(S_IRGRP)
-#   define S_IRGRP 0
-#endif
-
-/* Write group permission */
-#if !defined(S_IWGRP)
-#   define S_IWGRP 0
-#endif
-
-/* Execute group permission */
-#if !defined(S_IXGRP)
-#   define S_IXGRP 0
-#endif
-
-/* Read others permission */
-#if !defined(S_IROTH)
-#   define S_IROTH 0
-#endif
-
-/* Write others permission */
-#if !defined(S_IWOTH)
-#   define S_IWOTH 0
-#endif
-
-/* Execute others permission */
-#if !defined(S_IXOTH)
-#   define S_IXOTH 0
-#endif
-
-/* Maximum length of file name */
-#if !defined(PATH_MAX)
-#   define PATH_MAX MAX_PATH
-#endif
-#if !defined(FILENAME_MAX)
-#   define FILENAME_MAX MAX_PATH
-#endif
-#if !defined(NAME_MAX)
-#   define NAME_MAX FILENAME_MAX
-#endif
-
-/* File type flags for d_type */
-#define DT_UNKNOWN 0
-#define DT_REG S_IFREG
-#define DT_DIR S_IFDIR
-#define DT_FIFO S_IFIFO
-#define DT_SOCK S_IFSOCK
-#define DT_CHR S_IFCHR
-#define DT_BLK S_IFBLK
-#define DT_LNK S_IFLNK
-
-/* Macros for converting between st_mode and d_type */
-#define IFTODT(mode) ((mode) & S_IFMT)
-#define DTTOIF(type) (type)
-
-/*
- * File type macros.  Note that block devices, sockets and links cannot be
- * distinguished on Windows and the macros S_ISBLK, S_ISSOCK and S_ISLNK are
- * only defined for compatibility.  These macros should always return false
- * on Windows.
- */
-#if !defined(S_ISFIFO)
-#   define S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFIFO)
-#endif
-#if !defined(S_ISDIR)
-#   define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
-#endif
-#if !defined(S_ISREG)
-#   define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
-#endif
-#if !defined(S_ISLNK)
-#   define S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK)
-#endif
-#if !defined(S_ISSOCK)
-#   define S_ISSOCK(mode) (((mode) & S_IFMT) == S_IFSOCK)
-#endif
-#if !defined(S_ISCHR)
-#   define S_ISCHR(mode) (((mode) & S_IFMT) == S_IFCHR)
-#endif
-#if !defined(S_ISBLK)
-#   define S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK)
-#endif
-
-/* Return the exact length of d_namlen without zero terminator */
-#define _D_EXACT_NAMLEN(p) ((p)->d_namlen)
-
-/* Return number of bytes needed to store d_namlen */
-#define _D_ALLOC_NAMLEN(p) (PATH_MAX)
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-/* Wide-character version */
-struct _wdirent {
-    /* Always zero */
-    long d_ino;
-
-    /* Structure size */
-    unsigned short d_reclen;
-
-    /* Length of name without \0 */
-    size_t d_namlen;
-
-    /* File type */
-    int d_type;
-
-    /* File name */
-    wchar_t d_name[PATH_MAX];
-};
-typedef struct _wdirent _wdirent;
-
-struct _WDIR {
-    /* Current directory entry */
-    struct _wdirent ent;
-
-    /* Private file data */
-    WIN32_FIND_DATAW data;
-
-    /* True if data is valid */
-    int cached;
-
-    /* Win32 search handle */
-    HANDLE handle;
-
-    /* Initial directory name */
-    wchar_t *patt;
-};
-typedef struct _WDIR _WDIR;
-
-static _WDIR *_wopendir (const wchar_t *dirname);
-static struct _wdirent *_wreaddir (_WDIR *dirp);
-static int _wclosedir (_WDIR *dirp);
-static void _wrewinddir (_WDIR* dirp);
-
-
-/* For compatibility with Symbian */
-#define wdirent _wdirent
-#define WDIR _WDIR
-#define wopendir _wopendir
-#define wreaddir _wreaddir
-#define wclosedir _wclosedir
-#define wrewinddir _wrewinddir
-
-
-/* Multi-byte character versions */
-struct dirent {
-    /* Always zero */
-    long d_ino;
-
-    /* Structure size */
-    unsigned short d_reclen;
-
-    /* Length of name without \0 */
-    size_t d_namlen;
-
-    /* File type */
-    int d_type;
-
-    /* File name */
-    char d_name[PATH_MAX];
-};
-typedef struct dirent dirent;
-
-struct DIR {
-    struct dirent ent;
-    struct _WDIR *wdirp;
-};
-typedef struct DIR DIR;
-
-static DIR *opendir (const char *dirname);
-static struct dirent *readdir (DIR *dirp);
-static int closedir (DIR *dirp);
-static void rewinddir (DIR* dirp);
-
-
-/* Internal utility functions */
-static WIN32_FIND_DATAW *dirent_first (_WDIR *dirp);
-static WIN32_FIND_DATAW *dirent_next (_WDIR *dirp);
-
-static int dirent_mbstowcs_s(
-    size_t *pReturnValue,
-    wchar_t *wcstr,
-    size_t sizeInWords,
-    const char *mbstr,
-    size_t count);
-
-static int dirent_wcstombs_s(
-    size_t *pReturnValue,
-    char *mbstr,
-    size_t sizeInBytes,
-    const wchar_t *wcstr,
-    size_t count);
-
-static void dirent_set_errno (int error);
-
-/*
- * Open directory stream DIRNAME for read and return a pointer to the
- * internal working area that is used to retrieve individual directory
- * entries.
- */
-static _WDIR*
-_wopendir(
-    const wchar_t *dirname)
-{
-    _WDIR *dirp = NULL;
-    int error;
-
-    /* Must have directory name */
-    if (dirname == NULL  ||  dirname[0] == '\0') {
-        dirent_set_errno (ENOENT);
-        return NULL;
-    }
-
-    /* Allocate new _WDIR structure */
-    dirp = (_WDIR*) malloc (sizeof (struct _WDIR));
-    if (dirp != NULL) {
-        DWORD n;
-
-        /* Reset _WDIR structure */
-        dirp->handle = INVALID_HANDLE_VALUE;
-        dirp->patt = NULL;
-        dirp->cached = 0;
-
-        /* Compute the length of full path plus zero terminator */
-        n = GetFullPathNameW (dirname, 0, NULL, NULL);
-
-        /* Allocate room for absolute directory name and search pattern */
-        dirp->patt = (wchar_t*) malloc (sizeof (wchar_t) * n + 16);
-        if (dirp->patt) {
-
-            /*
-             * Convert relative directory name to an absolute one.  This
-             * allows rewinddir() to function correctly even when current
-             * working directory is changed between opendir() and rewinddir().
-             */
-            n = GetFullPathNameW (dirname, n, dirp->patt, NULL);
-            if (n > 0) {
-                wchar_t *p;
-
-                /* Append search pattern \* to the directory name */
-                p = dirp->patt + n;
-                if (dirp->patt < p) {
-                    switch (p[-1]) {
-                    case '\\':
-                    case '/':
-                    case ':':
-                        /* Directory ends in path separator, e.g. c:\temp\ */
-                        /*NOP*/;
-                        break;
-
-                    default:
-                        /* Directory name doesn't end in path separator */
-                        *p++ = '\\';
-                    }
-                }
-                *p++ = '*';
-                *p = '\0';
-
-                /* Open directory stream and retrieve the first entry */
-                if (dirent_first (dirp)) {
-                    /* Directory stream opened successfully */
-                    error = 0;
-                } else {
-                    /* Cannot retrieve first entry */
-                    error = 1;
-                    dirent_set_errno (ENOENT);
-                }
-
-            } else {
-                /* Cannot retrieve full path name */
-                dirent_set_errno (ENOENT);
-                error = 1;
-            }
-
-        } else {
-            /* Cannot allocate memory for search pattern */
-            error = 1;
-        }
-
-    } else {
-        /* Cannot allocate _WDIR structure */
-        error = 1;
-    }
-
-    /* Clean up in case of error */
-    if (error  &&  dirp) {
-        _wclosedir (dirp);
-        dirp = NULL;
-    }
-
-    return dirp;
-}
-
-/*
- * Read next directory entry.  The directory entry is returned in dirent
- * structure in the d_name field.  Individual directory entries returned by
- * this function include regular files, sub-directories, pseudo-directories
- * "." and ".." as well as volume labels, hidden files and system files.
- */
-static struct _wdirent*
-_wreaddir(
-    _WDIR *dirp)
-{
-    WIN32_FIND_DATAW *datap;
-    struct _wdirent *entp;
-
-    /* Read next directory entry */
-    datap = dirent_next (dirp);
-    if (datap) {
-        size_t n;
-        DWORD attr;
-        
-        /* Pointer to directory entry to return */
-        entp = &dirp->ent;
-
-        /* 
-         * Copy file name as wide-character string.  If the file name is too
-         * long to fit in to the destination buffer, then truncate file name
-         * to PATH_MAX characters and zero-terminate the buffer.
-         */
-        n = 0;
-        while (n + 1 < PATH_MAX  &&  datap->cFileName[n] != 0) {
-            entp->d_name[n] = datap->cFileName[n];
-            n++;
-        }
-        dirp->ent.d_name[n] = 0;
-
-        /* Length of file name excluding zero terminator */
-        entp->d_namlen = n;
-
-        /* File type */
-        attr = datap->dwFileAttributes;
-        if ((attr & FILE_ATTRIBUTE_DEVICE) != 0) {
-            entp->d_type = DT_CHR;
-        } else if ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0) {
-            entp->d_type = DT_DIR;
-        } else {
-            entp->d_type = DT_REG;
-        }
-
-        /* Reset dummy fields */
-        entp->d_ino = 0;
-        entp->d_reclen = sizeof (struct _wdirent);
-
-    } else {
-
-        /* Last directory entry read */
-        entp = NULL;
-
-    }
-
-    return entp;
-}
-
-/*
- * Close directory stream opened by opendir() function.  This invalidates the
- * DIR structure as well as any directory entry read previously by
- * _wreaddir().
- */
-static int
-_wclosedir(
-    _WDIR *dirp)
-{
-    int ok;
-    if (dirp) {
-
-        /* Release search handle */
-        if (dirp->handle != INVALID_HANDLE_VALUE) {
-            FindClose (dirp->handle);
-            dirp->handle = INVALID_HANDLE_VALUE;
-        }
-
-        /* Release search pattern */
-        if (dirp->patt) {
-            free (dirp->patt);
-            dirp->patt = NULL;
-        }
-
-        /* Release directory structure */
-        free (dirp);
-        ok = /*success*/0;
-
-    } else {
-        /* Invalid directory stream */
-        dirent_set_errno (EBADF);
-        ok = /*failure*/-1;
-    }
-    return ok;
-}
-
-/*
- * Rewind directory stream such that _wreaddir() returns the very first
- * file name again.
- */
-static void
-_wrewinddir(
-    _WDIR* dirp)
-{
-    if (dirp) {
-        /* Release existing search handle */
-        if (dirp->handle != INVALID_HANDLE_VALUE) {
-            FindClose (dirp->handle);
-        }
-
-        /* Open new search handle */
-        dirent_first (dirp);
-    }
-}
-
-/* Get first directory entry (internal) */
-static WIN32_FIND_DATAW*
-dirent_first(
-    _WDIR *dirp)
-{
-    WIN32_FIND_DATAW *datap;
-
-    /* Open directory and retrieve the first entry */
-    dirp->handle = FindFirstFileW (dirp->patt, &dirp->data);
-    if (dirp->handle != INVALID_HANDLE_VALUE) {
-
-        /* a directory entry is now waiting in memory */
-        datap = &dirp->data;
-        dirp->cached = 1;
-
-    } else {
-
-        /* Failed to re-open directory: no directory entry in memory */
-        dirp->cached = 0;
-        datap = NULL;
-
-    }
-    return datap;
-}
-
-/* Get next directory entry (internal) */
-static WIN32_FIND_DATAW*
-dirent_next(
-    _WDIR *dirp)
-{
-    WIN32_FIND_DATAW *p;
-
-    /* Get next directory entry */
-    if (dirp->cached != 0) {
-
-        /* A valid directory entry already in memory */
-        p = &dirp->data;
-        dirp->cached = 0;
-
-    } else if (dirp->handle != INVALID_HANDLE_VALUE) {
-
-        /* Get the next directory entry from stream */
-        if (FindNextFileW (dirp->handle, &dirp->data) != FALSE) {
-            /* Got a file */
-            p = &dirp->data;
-        } else {
-            /* The very last entry has been processed or an error occured */
-            FindClose (dirp->handle);
-            dirp->handle = INVALID_HANDLE_VALUE;
-            p = NULL;
-        }
-
-    } else {
-
-        /* End of directory stream reached */
-        p = NULL;
-
-    }
-
-    return p;
-}
-
-/* 
- * Open directory stream using plain old C-string.
- */
-static DIR*
-opendir(
-    const char *dirname) 
-{
-    struct DIR *dirp;
-    int error;
-
-    /* Must have directory name */
-    if (dirname == NULL  ||  dirname[0] == '\0') {
-        dirent_set_errno (ENOENT);
-        return NULL;
-    }
-
-    /* Allocate memory for DIR structure */
-    dirp = (DIR*) malloc (sizeof (struct DIR));
-    if (dirp) {
-        wchar_t wname[PATH_MAX];
-        size_t n;
-
-        /* Convert directory name to wide-character string */
-        error = dirent_mbstowcs_s (&n, wname, PATH_MAX, dirname, PATH_MAX);
-        if (!error) {
-
-            /* Open directory stream using wide-character name */
-            dirp->wdirp = _wopendir (wname);
-            if (dirp->wdirp) {
-                /* Directory stream opened */
-                error = 0;
-            } else {
-                /* Failed to open directory stream */
-                error = 1;
-            }
-
-        } else {
-            /* 
-             * Cannot convert file name to wide-character string.  This
-             * occurs if the string contains invalid multi-byte sequences or
-             * the output buffer is too small to contain the resulting
-             * string.
-             */
-            error = 1;
-        }
-
-    } else {
-        /* Cannot allocate DIR structure */
-        error = 1;
-    }
-
-    /* Clean up in case of error */
-    if (error  &&  dirp) {
-        free (dirp);
-        dirp = NULL;
-    }
-
-    return dirp;
-}
-
-/*
- * Read next directory entry.
- *
- * When working with text consoles, please note that file names returned by
- * readdir() are represented in the default ANSI code page while any output to
- * console is typically formatted on another code page.  Thus, non-ASCII
- * characters in file names will not usually display correctly on console.  The
- * problem can be fixed in two ways: (1) change the character set of console
- * to 1252 using chcp utility and use Lucida Console font, or (2) use
- * _cprintf function when writing to console.  The _cprinf() will re-encode
- * ANSI strings to the console code page so many non-ASCII characters will
- * display correcly.
- */
-static struct dirent*
-readdir(
-    DIR *dirp) 
-{
-    WIN32_FIND_DATAW *datap;
-    struct dirent *entp;
-
-    /* Read next directory entry */
-    datap = dirent_next (dirp->wdirp);
-    if (datap) {
-        size_t n;
-        int error;
-
-        /* Attempt to convert file name to multi-byte string */
-        error = dirent_wcstombs_s(
-            &n, dirp->ent.d_name, PATH_MAX, datap->cFileName, PATH_MAX);
-
-        /* 
-         * If the file name cannot be represented by a multi-byte string,
-         * then attempt to use old 8+3 file name.  This allows traditional
-         * Unix-code to access some file names despite of unicode
-         * characters, although file names may seem unfamiliar to the user.
-         *
-         * Be ware that the code below cannot come up with a short file
-         * name unless the file system provides one.  At least
-         * VirtualBox shared folders fail to do this.
-         */
-        if (error  &&  datap->cAlternateFileName[0] != '\0') {
-            error = dirent_wcstombs_s(
-                &n, dirp->ent.d_name, PATH_MAX, 
-                datap->cAlternateFileName, PATH_MAX);
-        }
-
-        if (!error) {
-            DWORD attr;
-
-            /* Initialize directory entry for return */
-            entp = &dirp->ent;
-
-            /* Length of file name excluding zero terminator */
-            entp->d_namlen = n - 1;
-
-            /* File attributes */
-            attr = datap->dwFileAttributes;
-            if ((attr & FILE_ATTRIBUTE_DEVICE) != 0) {
-                entp->d_type = DT_CHR;
-            } else if ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0) {
-                entp->d_type = DT_DIR;
-            } else {
-                entp->d_type = DT_REG;
-            }
-
-            /* Reset dummy fields */
-            entp->d_ino = 0;
-            entp->d_reclen = sizeof (struct dirent);
-
-        } else {
-            /* 
-             * Cannot convert file name to multi-byte string so construct
-             * an errornous directory entry and return that.  Note that
-             * we cannot return NULL as that would stop the processing
-             * of directory entries completely.
-             */
-            entp = &dirp->ent;
-            entp->d_name[0] = '?';
-            entp->d_name[1] = '\0';
-            entp->d_namlen = 1;
-            entp->d_type = DT_UNKNOWN;
-            entp->d_ino = 0;
-            entp->d_reclen = 0;
-        }
-
-    } else {
-        /* No more directory entries */
-        entp = NULL;
-    }
-
-    return entp;
-}
-
-/*
- * Close directory stream.
- */
-static int
-closedir(
-    DIR *dirp) 
-{
-    int ok;
-    if (dirp) {
-
-        /* Close wide-character directory stream */
-        ok = _wclosedir (dirp->wdirp);
-        dirp->wdirp = NULL;
-
-        /* Release multi-byte character version */
-        free (dirp);
-
-    } else {
-
-        /* Invalid directory stream */
-        dirent_set_errno (EBADF);
-        ok = /*failure*/-1;
-
-    }
-    return ok;
-}
-
-/*
- * Rewind directory stream to beginning.
- */
-static void
-rewinddir(
-    DIR* dirp) 
-{
-    /* Rewind wide-character string directory stream */
-    _wrewinddir (dirp->wdirp);
-}
-
-/* Convert multi-byte string to wide character string */
-static int
-dirent_mbstowcs_s(
-    size_t *pReturnValue,
-    wchar_t *wcstr,
-    size_t sizeInWords,
-    const char *mbstr,
-    size_t count)
-{
-    int error;
-
-#if defined(_MSC_VER)  &&  _MSC_VER >= 1400
-
-    /* Microsoft Visual Studio 2005 or later */
-    error = mbstowcs_s (pReturnValue, wcstr, sizeInWords, mbstr, count);
-
-#else
-
-    /* Older Visual Studio or non-Microsoft compiler */
-    size_t n;
-
-    /* Convert to wide-character string (or count characters) */
-    n = mbstowcs (wcstr, mbstr, sizeInWords);
-    if (!wcstr  ||  n < count) {
-
-        /* Zero-terminate output buffer */
-        if (wcstr  &&  sizeInWords) {
-            if (n >= sizeInWords) {
-                n = sizeInWords - 1;
-            }
-            wcstr[n] = 0;
-        }
-
-        /* Length of resuting multi-byte string WITH zero terminator */
-        if (pReturnValue) {
-            *pReturnValue = n + 1;
-        }
-
-        /* Success */
-        error = 0;
-
-    } else {
-
-        /* Could not convert string */
-        error = 1;
-
-    }
-
-#endif
-
-    return error;
-}
-
-/* Convert wide-character string to multi-byte string */
-static int
-dirent_wcstombs_s(
-    size_t *pReturnValue,
-    char *mbstr,
-    size_t sizeInBytes, /* max size of mbstr */
-    const wchar_t *wcstr,
-    size_t count)
-{
-    int error;
-
-#if defined(_MSC_VER)  &&  _MSC_VER >= 1400
-
-    /* Microsoft Visual Studio 2005 or later */
-    error = wcstombs_s (pReturnValue, mbstr, sizeInBytes, wcstr, count);
-
-#else
-
-    /* Older Visual Studio or non-Microsoft compiler */
-    size_t n;
-
-    /* Convert to multi-byte string (or count the number of bytes needed) */
-    n = wcstombs (mbstr, wcstr, sizeInBytes);
-    if (!mbstr  ||  n < count) {
-
-        /* Zero-terminate output buffer */
-        if (mbstr  &&  sizeInBytes) {
-            if (n >= sizeInBytes) {
-                n = sizeInBytes - 1;
-            }
-            mbstr[n] = '\0';
-        }
-
-        /* Lenght of resulting multi-bytes string WITH zero-terminator */
-        if (pReturnValue) {
-            *pReturnValue = n + 1;
-        }
-
-        /* Success */
-        error = 0;
-
-    } else {
-
-        /* Cannot convert string */
-        error = 1;
-
-    }
-
-#endif
-
-    return error;
-}
-
-/* Set errno variable */
-static void
-dirent_set_errno(
-    int error)
-{
-#if defined(_MSC_VER)  &&  _MSC_VER >= 1400
-
-    /* Microsoft Visual Studio 2005 and later */
-    _set_errno (error);
-
-#else
-
-    /* Non-Microsoft compiler or older Microsoft compiler */
-    errno = error;
-
-#endif
-}
-
-
-#ifdef __cplusplus
-}
-#endif
-#endif /*DIRENT_H*/
-

+ 0 - 138
bsp/win32/include/luat_conf_bsp.h

@@ -1,138 +0,0 @@
-
-#ifndef LUAT_CONF_BSP
-#define LUAT_CONF_BSP
-
-#include "stdint.h"
-
-#define LUAT_BSP_VERSION "V0003"
-#define LUAT_USE_CMDLINE_ARGS 1
-// 启用64位虚拟机
-#define LUAT_CONF_VM_64bit
-#define LUAT_RTOS_API_NOTOK 1
-#define LUAT_RET int
-#define LUAT_RT_RET_TYPE	void
-#define LUAT_RT_CB_PARAM void *param
-#define LUAT_RTOS_API_NOTOK 1
-
-//#define LUAT_CONF_LUASTATE_NOT_STATIC
-
-// #define LUAT_CONF_LAUX_BUFFSIZE 1024
-
-// #define LUA_COMPAT_BITLIB 1
-
-//#define LUAT_CONF_DISABLE_ROTABLE
-
-#define LUA_USE_VFS_FILENAME_OFFSET 1
-
-#define LUAT_USE_FS_VFS 1
-
-#define LUAT_USE_VFS_INLINE_LIB 1
-
-// #define LUAT_USE_FATFS 1
-
-// #define LUAT_MEMORY_OPT_G_FUNCS 1
-
-#define LUAT_COMPILER_NOWEAK 1
-
-#define LUAT_USE_LOG_ASYNC_THREAD 0
-
-#define LUAT_FORCE_WIN32 1
-
-//---------------------
-// UI
-// LCD  是彩屏, 若使用LVGL就必须启用LCD
-#define LUAT_USE_LCD
-#define LUAT_LCD_COLOR_DEPTH 16
-// EINK 是墨水屏
-// #define LUAT_USE_EINK
-
-//---------------------
-// U8G2
-// 单色屏, 支持i2c/spi
-// #define LUAT_USE_DISP
-#define LUAT_USE_U8G2
-#define U8G2_USE_SH1106
-#define U8G2_USE_ST7567
-
-/**************FONT*****************/
-// Luat Fonts
-#define LUAT_USE_FONTS
-/**********U8G2&LCD FONT*************/
-#define USE_U8G2_OPPOSANSM_ENGLISH
-#define USE_U8G2_UNIFONT_SYMBOLS
-#define USE_U8G2_OPPOSANSM8_CHINESE
-#define USE_U8G2_OPPOSANSM10_CHINESE
-#define USE_U8G2_OPPOSANSM12_CHINESE
-// #define USE_U8G2_OPPOSANSM14_CHINESE
-#define USE_U8G2_OPPOSANSM16_CHINESE
-#define USE_U8G2_OPPOSANSM18_CHINESE
-#define USE_U8G2_OPPOSANSM20_CHINESE
-#define USE_U8G2_OPPOSANSM22_CHINESE
-#define USE_U8G2_OPPOSANSM24_CHINESE
-#define USE_U8G2_OPPOSANSM32_CHINESE
-
-#define LUAT_USE_TJPGD
-
-#define LV_TICK_CUSTOM     1
-#define LV_TICK_CUSTOM_INCLUDE "stdio.h"
-unsigned int get_timestamp(void);
-#define LV_TICK_CUSTOM_SYS_TIME_EXPR ((uint32_t)get_timestamp())     /*Expression evaluating to current system time in ms*/
-
-#define LV_COLOR_16_SWAP 1
-#define LV_COLOR_DEPTH 16
-
-#define LUAT_USE_LVGL_SDL2 1
-#define LUAT_USE_LCD_SDL2 1
-#define LUAT_USE_LCD_CUSTOM_DRAW 1
-
-#define LUAT_USE_LVGL 1
-#define LV_MEM_CUSTOM 1
-#define LUAT_LV_DEBUG 0
-#define LUAT_USE_LVGL_INDEV 1
-#define LV_USE_LOG 1
-
-#define LUAT_USE_LVGL_ARC   //圆弧 无依赖
-#define LUAT_USE_LVGL_BAR   //进度条 无依赖
-#define LUAT_USE_LVGL_BTN   //按钮 依赖容器CONT
-#define LUAT_USE_LVGL_BTNMATRIX   //按钮矩阵 无依赖
-#define LUAT_USE_LVGL_CALENDAR   //日历 无依赖
-#define LUAT_USE_LVGL_CANVAS   //画布 依赖图片IMG
-#define LUAT_USE_LVGL_CHECKBOX   //复选框 依赖按钮BTN 标签LABEL
-#define LUAT_USE_LVGL_CHART   //图表 无依赖
-#define LUAT_USE_LVGL_CONT   //容器 无依赖
-#define LUAT_USE_LVGL_CPICKER   //颜色选择器 无依赖
-#define LUAT_USE_LVGL_DROPDOWN   //下拉列表 依赖页面PAGE 标签LABEL
-#define LUAT_USE_LVGL_GAUGE   //仪表 依赖进度条BAR 仪表(弧形刻度)LINEMETER
-#define LUAT_USE_LVGL_IMG   //图片 依赖标签LABEL
-#define LUAT_USE_LVGL_IMGBTN   //图片按钮 依赖按钮BTN
-#define LUAT_USE_LVGL_KEYBOARD   //键盘 依赖图片按钮IMGBTN
-#define LUAT_USE_LVGL_LABEL   //标签 无依赖
-#define LUAT_USE_LVGL_LED   //LED 无依赖
-#define LUAT_USE_LVGL_LINE   //线 无依赖
-#define LUAT_USE_LVGL_LIST   //列表 依赖页面PAGE 按钮BTN 标签LABEL
-#define LUAT_USE_LVGL_LINEMETER   //仪表(弧形刻度) 无依赖
-#define LUAT_USE_LVGL_OBJMASK   //对象蒙版 无依赖
-#define LUAT_USE_LVGL_MSGBOX   //消息框 依赖图片按钮IMGBTN 标签LABEL
-#define LUAT_USE_LVGL_PAGE   //页面 依赖容器CONT
-#define LUAT_USE_LVGL_SPINNER   //旋转器 依赖圆弧ARC 动画ANIM
-#define LUAT_USE_LVGL_ROLLER   //滚筒 无依赖
-#define LUAT_USE_LVGL_SLIDER   //滑杆 依赖进度条BAR
-#define LUAT_USE_LVGL_SPINBOX   //数字调整框 无依赖
-#define LUAT_USE_LVGL_SWITCH   //开关 依赖滑杆SLIDER
-#define LUAT_USE_LVGL_TEXTAREA   //文本框 依赖标签LABEL 页面PAGE
-#define LUAT_USE_LVGL_TABLE   //表格 依赖标签LABEL
-#define LUAT_USE_LVGL_TABVIEW   //页签 依赖页面PAGE 图片按钮IMGBTN
-#define LUAT_USE_LVGL_TILEVIEW   //平铺视图 依赖页面PAGE
-#define LUAT_USE_LVGL_WIN   //窗口 依赖容器CONT 按钮BTN 标签LABEL 图片IMG 页面PAGE
-
-
-#define LV_FONT_OPPOSANS_M_8
-#define LV_FONT_OPPOSANS_M_10
-#define LV_FONT_OPPOSANS_M_12
-#define LV_FONT_OPPOSANS_M_14
-#define LV_FONT_OPPOSANS_M_16
-#define LV_FONT_OPPOSANS_M_18
-#define LV_FONT_OPPOSANS_M_20
-#define LV_FONT_OPPOSANS_M_22
-
-#endif

+ 0 - 30
bsp/win32/luf_test/abc.lua

@@ -1,30 +0,0 @@
-
-local abc = {}
-abc.version = 1
--- abc[1] = 123
--- abc["hi"] = function (name)
---     log.info("*abc*", name)
--- --     return "Hi, ".. name, function ()
--- --         os.exit(123)
--- --     end
---     return "hi, ".. name
--- end
--- _G.print(1)
--- log.info("abc", "Great")
--- -- return abc
--- wendal = 1
-
-function abc.h2(name) 
-    local function hi12345678901234567890123456789012345678902()
-        
-    end
-    hi12345678901234567890123456789012345678902()
-
-    if sys == nil then
-        print()
-    end
-
-    return "hi, " .. name, function() end
-end
-
-return abc

BIN
bsp/win32/luf_test/abc.luf


+ 0 - 18
bsp/win32/luf_test/disk/main.lua

@@ -1,18 +0,0 @@
-
-PROJECT = "luf2"
-VERSION = "1.0.0"
-
-log.info("main", "hi")
-
--- local sys = require ("sys")
-
--- log.info("main", "sys", sys)
-
--- sys.taskInit(function()
---     while true do
---         log.info("sys", "task loop")
---         sys.wait(1000)
---     end
--- end)
-
--- sys.run()

+ 0 - 116
bsp/win32/luf_test/luadb.lua

@@ -1,116 +0,0 @@
-
--- 读取命令行参数
-local srcpath = "disk"
-if arg[1] then
-    srcpath = arg[1]
-end
-
-
-local function lsdir(path, files, shortname)
-    local exe = io.popen("dir /b " .. (shortname and " " or " /s ") .. path)
-    if exe then
-        for line in exe:lines() do
-            table.insert(files, line)
-        end
-        exe:close()
-    end
-end
-
-
-local function oscall(cmd, quite, cwd)
-    if cwd and Base_CWD then
-        lfs.chdir(cwd)
-    end
-    if tool_debug then
-        log.info("cmd", cmd)
-    end
-    local exe = io.popen(cmd)
-    if exe then
-        for line in exe:lines() do
-            if not quite then
-                log.info("cmd", line)
-            end
-        end
-        exe:close()
-    end
-    if cwd and Base_CWD then
-        lfs.chdir(Base_CWD)
-    end
-end
-
-function TLD(buff, T, D)
-    buff:pack("bb", T, D:len())
-    buff:write(D)
-end
-
-local files = {}
-lsdir(srcpath, files, true)
--- oscall("mkdir tmp")
-
-local buff = zbuff.create(256*1024)
-local magic = string.char(0x5A, 0xA5, 0X5A, 0xA5)
-
--- -- 先写入magic
---buff:pack("bbbbbb", 0x01, 0x04, 0XA5, 0x5A, 0xA5, 0x5A)
-TLD(buff, 0x01, magic)
-
--- 然后是版本号
---buff:write(string.char(0x02, 0x02, 0x00, 0x02))
-TLD(buff, 0x02, string.char(0x00, 0x02))
-
--- head长度
-buff:write(string.char(0x03, 0x04))
-buff:pack("I", 0x18)
-
--- 文件数量
-buff:write(string.char(0x04, 0x02))
-buff:pack("H", #files)
-
--- CRC值
-buff:write(string.char(0xFE, 0x02))
-buff:pack("H", 0xFFFF)
-
-for _, value in ipairs(files) do
-    TLD(buff, 0x01, magic)
-    local tname = value
-    local data = nil
-    if value:sub(-4) == ".lua" then
-        tname = value .. "c"
-        local func, err = loadfile(srcpath .. "\\" .. value)
-        if err then
-            log.error("luac", "bad lua format", err)
-            os.exit(1)
-        end
-        -- if value == "main.lua" then
-            -- data = string.dump(func)
-            -- io.writeFile(tname, string.dump(func))
-        -- else
-            -- io.writeFile("tmp\\" .. tname, luf.dump(func, false, 0x80E0000 + buff:seek(0, zbuff.SEEK_CUR) + 3*2 + tname:len() + 4 + 2))
-            -- log.info("what pos", buff:seek(0, zbuff.SEEK_CUR))
-            -- log.info(">> pos", string.format("%08X", 0x080E0000 + buff:seek(0, zbuff.SEEK_CUR) + 3*2 + tname:len() + 4 + 2 + 64))
-            -- data = luf.dump(func, false, 0x80E0000 + buff:seek(0, zbuff.SEEK_CUR) + 3*2 + tname:len() + 4 + 2)
-            data = luf.dump(func, false, 0x080E0033)
-            log.info("iowrite", tname, #data)
-            io.writeFile(tname, data)
-        -- end
-    else
-        data = io.readFile(srcpath .. "\\" .. value)
-    end
-    -- log.info("luadb1", tname, #data, buff:seek(0, zbuff.SEEK_CUR))
-    TLD(buff, 0x02, tname)
-    TLD(buff, 0x03, pack.pack("I", #data))
-    TLD(buff, 0xFE, string.char(0xFF, 0xFF))
-    log.info("luadb2", tname, #data, buff:seek(0, zbuff.SEEK_CUR), string.format("%02X", buff:seek(0, zbuff.SEEK_CUR)))
-    -- log.info(">> pos", string.format("%08X", 0x80E0000 + buff:seek(0, zbuff.SEEK_CUR)))
-    buff:write(data)
-    log.info("luadb3", tname, #data, buff:seek(0, zbuff.SEEK_CUR))
-end
-
-local data = buff:toStr(0, buff:seek(0, zbuff.SEEK_CUR))
-log.info("target", #data)
-
-io.writeFile("disk.bin", data)
-
---print(json.encode(arg))
-
-os.exit(0)

+ 0 - 22
bsp/win32/luf_test/main.lua

@@ -1,22 +0,0 @@
-
-log.info("main", "hi")
-
-local func = loadfile("sys.lua")
-log.info("func", func)
-buff = zbuff.create(32*1024)
-data = luf.dump(func, false, buff)
-
-buff:write(data)
-
-func2 = luf.undump(data)
-
-local sys = func2()
-
-sys.taskInit(function()
-    while true do
-        log.info("sys", "task loop")
-        sys.wait(1000)
-    end
-end)
-
-sys.run()

+ 0 - 32
bsp/win32/luf_test/main_luf.lua

@@ -1,32 +0,0 @@
-
-log.info("main", "hi")
-
-local func = loadfile("sys.lua")
-log.info("func", func)
-buff = zbuff.create(32*1024)
-data = luf.dump(func, false, buff)
-buff:write(data)
-
---buff:write(data)
-
-io.writeFile("sys.luf", data)
-io.writeFile("sys.luac", string.dump(func))
-io.writeFile("sys.luacs", string.dump(func, true))
-
-f = load(data)
-log.info("load", f)
-if f then
-    log.info("load", "f?")
-    sys = f()
-    sys.publish("ABC", 123)
-    log.info("load sys", sys)
-    sys.taskInit(function()
-        log.info("sys", "wait 1s")
-        sys.wait(1000)
-        log.info("os", "exit now")
-        os.exit()
-    end)
-    sys.run()
-end
-
-os.exit(0)

+ 0 - 44
bsp/win32/luf_test/main_test.lua

@@ -1,44 +0,0 @@
-
-log.info("main", "hi")
-
-local func = loadfile("abc.lua")
-log.info("func", func)
-buff = zbuff.create(32*1024)
-data = luf.dump(func, false, buff)
-
-buff:write(data)
-buff:seek(0, zbuff.SEEK_SET)
-
-log.info("data", #data)
--- print(data:toHex())
-
-io.writeFile("abc.luf", data)
-io.writeFile("abc.luac", string.dump(func))
-io.writeFile("abc.luacs", string.dump(func, true))
-
-func2 = luf.undump(data)
-
-if func2 then
-    log.info("func??", func2)
-    -- luf.cmp(func, func2)
-    local abc = func2()
-    log.info("table?", type(abc))
-    log.info("table?", json.encode(abc))
-    if abc.version then
-        log.info("abc", abc["version"])
-    else
-        log.info("abc", "no version")
-    end
-    if abc.h2 then
-        log.info("abc", abc.h2("wendal"))
-    else
-        log.info("abc", "no hi function")
-    end
-    log.info("func??", "end", abc[1])
-else
-    log.info("func", "nil!!!")
-end
-
-log.info("change?", buff:toStr(0, #data) == data)
-
-os.exit(0)

+ 0 - 404
bsp/win32/luf_test/sys.lua

@@ -1,404 +0,0 @@
---- 模块功能:Luat协程调度框架
---module(..., package.seeall)
-
-local sys = {}
-
-local table = _G.table
-local unpack = table.unpack
-local rtos = _G.rtos
-local coroutine = _G.coroutine
-local log = _G.log
-
--- lib脚本版本号,只要lib中的任何一个脚本做了修改,都需要更新此版本号
-SCRIPT_LIB_VER = "1.0.0"
-
--- TaskID最大值
-local TASK_TIMER_ID_MAX = 0x1FFFFF
--- msgId 最大值(请勿修改否则会发生msgId碰撞的危险)
-local MSG_TIMER_ID_MAX = 0x7FFFFF
-
--- 任务定时器id
-local taskTimerId = 0
--- 消息定时器id
-local msgId = TASK_TIMER_ID_MAX
--- 定时器id表
-local timerPool = {}
-local taskTimerPool = {}
---消息定时器参数表
-local para = {}
---定时器是否循环表
---local loop = {}
---lua脚本运行出错时,是否回退为本地烧写的版本
---local sRollBack = true
-
-_G.COROUTINE_ERROR_ROLL_BACK = true
-_G.COROUTINE_ERROR_RESTART = true
-
--- 对coroutine.resume加一个修饰器用于捕获协程错误
---local rawcoresume = coroutine.resume
-local function wrapper(co,...)
-    local arg = {...}
-    if not arg[1] then
-        local traceBack = debug.traceback(co)
-        traceBack = (traceBack and traceBack~="") and (arg[2].."\r\n"..traceBack) or arg[2]
-        log.error("coroutine.resume",traceBack)
-        --if errDump and type(errDump.appendErr)=="function" then
-        --    errDump.appendErr(traceBack)
-        --end
-        if _G.COROUTINE_ERROR_ROLL_BACK then
-            sys.timerStart(assert,500,false,traceBack)
-        elseif _G.COROUTINE_ERROR_RESTART then
-            rtos.reboot()
-        end
-    end
-    return ...
-end
-sys.coresume = function(...)
-    local arg = {...}
-    return wrapper(arg[1], coroutine.resume(...))
-end
-
---- Task任务延时函数,只能用于任务函数中
--- @number ms  整数,最大等待126322567毫秒
--- @return 定时结束返回nil,被其他线程唤起返回调用线程传入的参数
--- @usage sys.wait(30)
-function sys.wait(ms)
-    -- 参数检测,参数不能为负值
-    --assert(ms > 0, "The wait time cannot be negative!")
-    -- 选一个未使用的定时器ID给该任务线程
-    while true do
-        if taskTimerId >= TASK_TIMER_ID_MAX - 1 then
-            taskTimerId = 0
-        else
-            taskTimerId = taskTimerId + 1
-        end
-        if taskTimerPool[taskTimerId] == nil then
-            break
-        end
-    end
-    local timerid = taskTimerId
-    taskTimerPool[coroutine.running()] = timerid
-    timerPool[timerid] = coroutine.running()
-    -- 调用core的rtos定时器
-    if 1 ~= rtos.timer_start(timerid, ms) then log.debug("rtos.timer_start error") return end
-    -- 挂起调用的任务线程
-    local message = {coroutine.yield()}
-    if #message ~= 0 then
-        rtos.timer_stop(timerid)
-        taskTimerPool[coroutine.running()] = nil
-        timerPool[timerid] = nil
-        return unpack(message)
-    end
-end
-
---- Task任务的条件等待函数(包括事件消息和定时器消息等条件),只能用于任务函数中。
--- @param id 消息ID
--- @number ms 等待超时时间,单位ms,最大等待126322567毫秒
--- @return result 接收到消息返回true,超时返回false
--- @return data 接收到消息返回消息参数
--- @usage result, data = sys.waitUntil("SIM_IND", 120000)
-function sys.waitUntil(id, ms)
-    sys.subscribe(id, coroutine.running())
-    local message = ms and {sys.wait(ms)} or {coroutine.yield()}
-    sys.unsubscribe(id, coroutine.running())
-    return message[1] ~= nil, unpack(message, 2, #message)
-end
-
---- Task任务的条件等待函数扩展(包括事件消息和定时器消息等条件),只能用于任务函数中。
--- @param id 消息ID
--- @number ms 等待超时时间,单位ms,最大等待126322567毫秒
--- @return message 接收到消息返回message,超时返回false
--- @return data 接收到消息返回消息参数
--- @usage result, data = sys.waitUntilExt("SIM_IND", 120000)
-function sys.waitUntilExt(id, ms)
-    sys.subscribe(id, coroutine.running())
-    local message = ms and {sys.wait(ms)} or {coroutine.yield()}
-    sys.unsubscribe(id, coroutine.running())
-    if message[1] ~= nil then return unpack(message) end
-    return false
-end
-
---- 创建一个任务线程,在模块最末行调用该函数并注册模块中的任务函数,main.lua导入该模块即可
--- @param fun 任务函数名,用于resume唤醒时调用
--- @param ... 任务函数fun的可变参数
--- @return co  返回该任务的线程号
--- @usage sys.taskInit(task1,'a','b')
-function sys.taskInit(fun, ...)
-    local co = coroutine.create(fun)
-    sys.coresume(co, ...)
-    return co
-end
-
------------------------------------------- rtos消息回调处理部分 ------------------------------------------
---[[
-函数名:cmpTable
-功能  :比较两个table的内容是否相同,注意:table中不能再包含table
-参数  :
-t1:第一个table
-t2:第二个table
-返回值:相同返回true,否则false
-]]
-local function cmpTable(t1, t2)
-    if not t2 then return #t1 == 0 end
-    if #t1 == #t2 then
-        for i = 1, #t1 do
-            if unpack(t1, i, i) ~= unpack(t2, i, i) then
-                return false
-            end
-        end
-        return true
-    end
-    return false
-end
-
---- 关闭定时器
--- @param val 值为number时,识别为定时器ID,值为回调函数时,需要传参数
--- @param ... val值为函数时,函数的可变参数
--- @return 无
--- @usage timerStop(1)
-function sys.timerStop(val, ...)
-    -- val 为定时器ID
-    if type(val) == 'number' then
-        timerPool[val], para[val] = nil
-        rtos.timer_stop(val)
-    else
-        for k, v in pairs(timerPool) do
-            -- 回调函数相同
-            if type(v) == 'table' and v.cb == val or v == val then
-                -- 可变参数相同
-                if cmpTable({...}, para[k]) then
-                    rtos.timer_stop(k)
-                    timerPool[k], para[k] = nil
-                    break
-                end
-            end
-        end
-    end
-end
-
---- 关闭同一回调函数的所有定时器
--- @param fnc 定时器回调函数
--- @return 无
--- @usage timerStopAll(cbFnc)
-function sys.timerStopAll(fnc)
-    for k, v in pairs(timerPool) do
-        if type(v) == "table" and v.cb == fnc or v == fnc then
-            rtos.timer_stop(k)
-            timerPool[k], para[k] = nil
-        end
-    end
-end
-
-function sys.timerAdvStart(fnc, ms, _repeat, ...)
-    --回调函数和时长检测
-    --assert(fnc ~= nil, "sys.timerStart(first param) is nil !")
-    --assert(ms > 0, "sys.timerStart(Second parameter) is <= zero !")
-    -- 关闭完全相同的定时器
-    local arg = {...}
-    if #arg == 0 then
-        sys.timerStop(fnc)
-    else
-        sys.timerStop(fnc, ...)
-    end
-    -- 为定时器申请ID,ID值 1-20 留给任务,20-30留给消息专用定时器
-    while true do
-        if msgId >= MSG_TIMER_ID_MAX then msgId = TASK_TIMER_ID_MAX end
-        msgId = msgId + 1
-        if timerPool[msgId] == nil then
-            timerPool[msgId] = fnc
-            break
-        end
-    end
-    --调用底层接口启动定时器
-    if rtos.timer_start(msgId, ms, _repeat) ~= 1 then return end
-    --如果存在可变参数,在定时器参数表中保存参数
-    if #arg ~= 0 then
-        para[msgId] = arg
-    end
-    --返回定时器id
-    return msgId
-end
-
---- 开启一个定时器
--- @param fnc 定时器回调函数
--- @number ms 整数,最大定时126322567毫秒
--- @param ... 可变参数 fnc的参数
--- @return number 定时器ID,如果失败,返回nil
-function sys.timerStart(fnc, ms, ...)
-    return sys.timerAdvStart(fnc, ms, 0, ...)
-end
-
---- 开启一个循环定时器
--- @param fnc 定时器回调函数
--- @number ms 整数,最大定时126322567毫秒
--- @param ... 可变参数 fnc的参数
--- @return number 定时器ID,如果失败,返回nil
-function sys.timerLoopStart(fnc, ms, ...)
-    return sys.timerAdvStart(fnc, ms, -1, ...)
-end
-
---- 判断某个定时器是否处于开启状态
--- @param val 有两种形式
---一种是开启定时器时返回的定时器id,此形式时不需要再传入可变参数...就能唯一标记一个定时器
---另一种是开启定时器时的回调函数,此形式时必须再传入可变参数...才能唯一标记一个定时器
--- @param ... 可变参数
--- @return number 开启状态返回true,否则nil
-function sys.timerIsActive(val, ...)
-    if type(val) == "number" then
-        return timerPool[val]
-    else
-        for k, v in pairs(timerPool) do
-            if v == val then
-                if cmpTable({...}, para[k]) then return true end
-            end
-        end
-    end
-end
-
-
------------------------------------------- LUA应用消息订阅/发布接口 ------------------------------------------
--- 订阅者列表
-local subscribers = {}
---内部消息队列
-local messageQueue = {}
-
---- 订阅消息
--- @param id 消息id
--- @param callback 消息回调处理
--- @usage subscribe("NET_STATUS_IND", callback)
-function sys.subscribe(id, callback)
-    --if not id or type(id) == "boolean" or (type(callback) ~= "function" and type(callback) ~= "thread") then
-    --    log.warn("warning: sys.subscribe invalid parameter", id, callback)
-    --    return
-    --end
-    --log.debug("sys", "subscribe", id, callback)
-    if type(id) == "table" then
-        -- 支持多topic订阅
-        for _, v in pairs(id) do sys.subscribe(v, callback) end
-        return
-    end
-    if not subscribers[id] then subscribers[id] = {} end
-    subscribers[id][callback] = true
-end
---- 取消订阅消息
--- @param id 消息id
--- @param callback 消息回调处理
--- @usage unsubscribe("NET_STATUS_IND", callback)
-function sys.unsubscribe(id, callback)
-    --if not id or type(id) == "boolean" or (type(callback) ~= "function" and type(callback) ~= "thread") then
-    --    log.warn("warning: sys.unsubscribe invalid parameter", id, callback)
-    --    return
-    --end
-    --log.debug("sys", "unsubscribe", id, callback)
-    if type(id) == "table" then
-        -- 支持多topic订阅
-        for _, v in pairs(id) do sys.unsubscribe(v, callback) end
-        return
-    end
-    if subscribers[id] then subscribers[id][callback] = nil end
-    -- 判断消息是否无其他订阅
-    for k, _ in pairs(subscribers[id]) do
-        return
-    end
-    subscribers[id] = nil
-end
-
---- 发布内部消息,存储在内部消息队列中
--- @param ... 可变参数,用户自定义
--- @return 无
--- @usage publish("NET_STATUS_IND")
-function sys.publish(...)
-    table.insert(messageQueue, {...})
-end
-
--- 分发消息
-local function dispatch()
-    while true do
-        if #messageQueue == 0 then
-            break
-        end
-        local message = table.remove(messageQueue, 1)
-        if subscribers[message[1]] then
-            for callback, _ in pairs(subscribers[message[1]]) do
-                if type(callback) == "function" then
-                    callback(unpack(message, 2, #message))
-                elseif type(callback) == "thread" then
-                    sys.coresume(callback, unpack(message))
-                end
-            end
-        end
-    end
-end
-
--- rtos消息回调
---local handlers = {}
---setmetatable(handlers, {__index = function() return function() end end, })
-
---- 注册rtos消息回调处理函数
--- @number id 消息类型id
--- @param handler 消息处理函数
--- @return 无
--- @usage rtos.on(rtos.MSG_KEYPAD, function(param) handle keypad message end)
---function sys.on(id, handler)
---    handlers[id] = handler
---end
-
------------------------------------------- Luat 主调度框架  ------------------------------------------
-local function safeRun()
-    -- 分发内部消息
-    dispatch()
-    -- 阻塞读取外部消息
-    local msg, param, exparam = rtos.receive(rtos.INF_TIMEOUT)
-    --log.info("sys", msg, param, exparam, tableNSize(timerPool), tableNSize(para), tableNSize(taskTimerPool), tableNSize(subscribers))
-    -- 空消息?
-    if not msg or msg == 0 then
-        -- 无任何操作
-    -- 判断是否为定时器消息,并且消息是否注册
-    elseif msg == rtos.MSG_TIMER and timerPool[param] then
-        if param < TASK_TIMER_ID_MAX then
-            local taskId = timerPool[param]
-            timerPool[param] = nil
-            if taskTimerPool[taskId] == param then
-                taskTimerPool[taskId] = nil
-                sys.coresume(taskId)
-            end
-        else
-            local cb = timerPool[param]
-            --如果不是循环定时器,从定时器id表中删除此定时器
-            if exparam == 0 then timerPool[param] = nil end
-            if para[param] ~= nil then
-                cb(unpack(para[param]))
-                if exparam == 0 then para[param] = nil end
-            else
-                cb()
-            end
-            --如果是循环定时器,继续启动此定时器
-            --if loop[param] then rtos.timer_start(param, loop[param]) end
-        end
-    --其他消息(音频消息、充电管理消息、按键消息等)
-    --elseif type(msg) == "number" then
-    --    handlers[msg](param, exparam)
-    --else
-    --    handlers[msg.id](msg)
-    end
-end
-
---- run()从底层获取core消息并及时处理相关消息,查询定时器并调度各注册成功的任务线程运行和挂起
--- @return 无
--- @usage sys.run()
-function sys.run()
-    --local result, err
-    while true do
-        --if sRollBack then
-            safeRun()
-        --else
-        --    result, err = pcall(safeRun)
-        --    if not result then rtos.restart(err) end
-        --end
-    end
-end
-
-_G.sys_pub = sys.publish
-
-return sys
-----------------------------

+ 0 - 1
bsp/win32/luf_test/toburn.bat

@@ -1 +0,0 @@
-wm_tool.exe -dl script.img -ds 115200 -ws 115200 -c COM83 -rs rts

+ 0 - 1
bsp/win32/luf_test/toimg.bat

@@ -1 +0,0 @@
-wm_tool.exe -b disk.bin -it 1 -fc 0 -ih 20008000 -ra 80E0000 -ua 0 -nh 0  -un 0 -o script

+ 0 - 11
bsp/win32/main.lua

@@ -1,11 +0,0 @@
---加载sys库
-_G.sys = require("sys")
-
-log.info("vmx", "create ...")
-vm = vmx.create()
-
-vmx.exec(vm, "log.info('inside', 'vmx')")
-
-log.info("vmx", "all done")
-
-os.exit(0)

+ 0 - 26
bsp/win32/module_test/001task.lua

@@ -1,26 +0,0 @@
-local sys = require("../lib/sys")
-
-_G.temp = 1
-sys.timerStart(function ()
-    temp = 2
-end,1)
-
-sys.timerStart(function ()
-    assert(temp == 2,"timer error")
-end,100)
-
-_G.taskCheck = nil
-sys.taskInit(function ()
-    sys.wait(1)
-    taskCheck = true
-end)
-
-sys.timerStart(function ()
-    assert(taskCheck,"task error")
-end,100)
-
-sys.timerStart(function ()
-    os.exit(0)
-end,50)
-
-sys.run()

+ 0 - 34
bsp/win32/module_test/002json.lua

@@ -1,34 +0,0 @@
-
-local t = {
-    a = 1,
-    b = "abc",
-    c = {
-        1,2,3,4
-    },
-    d = {
-        x = false,
-        j = 111111
-    },
-    aaaa = 6666
-}
-
-local s = json.encode(t)
-log.info("json",s)
-
-local st = json.decode(s)
-
-
-for i,j in pairs(t) do
-    if type(j) == "number" or type(j) == "string" or type(j) == "boolean" then
-        assert(j==st[i],i,"json decode error")
-        log.info("check",i,st[i])
-    else
-        for ii,jj in pairs(j) do
-            if type(jj) == "number" or type(jj) == "string" or type(jj) == "boolean" then
-                assert(jj==st[i][ii],i,"json decode error")
-                log.info("check",i,ii,st[i][ii])
-            end
-        end
-    end
-end
-

+ 0 - 73
bsp/win32/module_test/003zbuff.lua

@@ -1,73 +0,0 @@
-local buff = zbuff.create(15,6)
-for i=0,14 do
-    log.info("read byte",i,buff[i])
-    assert(buff[i] == 6,"init error")
-end
-
-local writeLen = buff:write("abcde")
-log.info("writeLen string",writeLen)
-assert(writeLen == 5,"string write length error")
-writeLen = buff:write(0x31,0x32,0x33,0x34,0x35)
-log.info("writeLen numbers",writeLen)
-assert(writeLen == 5,"numbers write length error")
-
-buff:seek(0)
-local readData = buff:read(5)
-log.info("readData1",readData)
-assert(readData == "abcde","read data1 error")
-readData = buff:read(5)
-log.info("readData2",readData)
-assert(readData == "12345","read data2 error")
-
-log.info("write bytes")
-for i=0,9 do
-    buff[i] = i * 2
-end
-
-for i=0,9 do
-    log.info("read byte",i,buff[i])
-    assert(buff[i] == i * 2,"read byte error")
-end
-
-buff:seek(0)
-writeLen = buff:pack(">bbbIAIII",1,2,3,4,"abc",666,2,3)
-log.info("pack write length",writeLen)
-assert(writeLen == 15,"pack write length error")
-
-buff:seek(0)
-local len,b1,b2,b3,b4,s,i1 = buff:unpack(">bbbIA3III")
-log.info("unpack read",len,b1,b2,b3,b4,s,i1)
-assert(len == 14,"pack read length error")
-assert(b1 == 1,"pack read b1 error")
-assert(b2 == 2,"pack read b2 error")
-assert(b3 == 3,"pack read b3 error")
-assert(b4 == 4,"pack read b4 error")
-assert(s == "abc","pack read s error")
-assert(i1 == 666,"pack read I error")
-
-local buff = zbuff.create(30,0)
-buff:del()
-assert(buff:used() == 0,"del error")
-buff:resize(1024)
-assert(buff:len() == 1024,"resize error")
-buff:copy(nil, "123")
-assert(buff:used() == 3,"copy error")
-assert(buff:query() == "123","query error")
-buff:set(1,0x30,1)
-assert(buff:query() == "103","set error")
-buff:set(0,0x30,3)
-assert(buff:query() == "000","set error")
-buff:copy(0, 0x12,0x34,0x56,0x78)
-assert(buff:used() == 4,"copy error")
-assert(buff:query(0, 4, true) == 0x12345678,"query error")
-assert(buff:query(0, 2, true) == 0x1234,"query error")
-
-assert(buff[2] == 0x56,"copy error")
-local buff2 = zbuff.create(16)
-buff2:set(0, 0xaa)
-buff2:seek(0,zbuff.SEEK_END)
-buff:copy(2, buff2)
-assert(buff:used() == 18,"copy error")
-assert(buff[3] == 0xaa,"copy error")
-buff:del(-1)
-assert(buff:used() == 17,"del error")

+ 0 - 68
bsp/win32/module_test/004crypto.lua

@@ -1,68 +0,0 @@
-local md5 = crypto.md5("abc")
-log.info("md5 result",md5)
-assert(md5:upper() == "900150983CD24FB0D6963F7D28E17F72","md5 error")
-
-local hmac_md5 = crypto.hmac_md5("abc", "1234567890")
-log.info("hmac_md5 result",hmac_md5)
-assert(hmac_md5:upper() == "416478FC0ACE1C4AB37F85F4F86A16B1","hmac_md5 error")
-
-local sha1 = crypto.sha1("abc")
-log.info("sha1 result",sha1)
-assert(sha1:upper() == "A9993E364706816ABA3E25717850C26C9CD0D89D","sha1 error")
-
-local hmac_sha1 = crypto.hmac_sha1("abc", "1234567890")
-log.info("hmac_sha1 result",hmac_sha1)
-assert(hmac_sha1:upper() == "DAE54822C0DAF6C115C97B0AD62C7BCBE9D5E6FC","hmac_md5 error")
-
-local sha256 = crypto.sha256("abc")
-log.info("sha256 result",sha256)
-assert(sha256:upper() == "BA7816BF8F01CFEA414140DE5DAE2223B00361A396177A9CB410FF61F20015AD","sha256 error")
-
-local hmac_sha256 = crypto.hmac_sha256("abc", "1234567890")
-log.info("hmac_sha256 result",hmac_sha256)
-assert(hmac_sha256:upper() == "86055184805B4A466A7BE398FF4A7159F9055EA7EEF339FC94DCEC6F165898BA","hmac_sha256 error")
-
-local sha512 = crypto.sha512("abc")
-log.info("sha512 result",sha512)
-assert(sha512:upper() == "DDAF35A193617ABACC417349AE20413112E6FA4E89A97EA20A9EEEE64B55D39A2192992A274FC1A836BA3C23A3FEEBBD454D4423643CE80E2A9AC94FA54CA49F","sha512 error")
-
-local hmac_sha512 = crypto.hmac_sha512("abc", "1234567890")
-log.info("hmac_sha512 result",hmac_sha512)
-assert(hmac_sha512:upper() == "0F92B9AC88949E0BF7C9F1E6F9901BAB8EDFDC9E561DFDE428BC4339961A0569AD01B44343AA56E439949655D15C4D28492D459E75015489920243F3C9986F2A","hmac_sha512 error")
-
-local data_encrypt = crypto.cipher_encrypt("AES-128-ECB", "PKCS7", "12345678901234 > 123456000000000", "1234567890123456")
-log.info("AES", "aes-128-ecb encrypt", data_encrypt:toHex())
-assert(data_encrypt:toHex():upper() == "A37DE67837A1A3006E47A7BC25AA0ECCEF744534DF0A80686810235A6450E2E2050187A0CDE5A9872CBAB091AB73E553", "AES aes-128-ecb encrypt error")
-
-local data_decrypt = crypto.cipher_decrypt("AES-128-ECB", "PKCS7", data_encrypt, "1234567890123456")
-log.info("AES", "aes-128-ecb decrypt", data_decrypt)
-assert(data_decrypt:upper() == "12345678901234 > 123456000000000", "AES aes-128-ecb decrypt error")
-
-local data2_encrypt = crypto.cipher_encrypt("AES-128-CBC", "PKCS7", "12345678901234 > 123456", "1234567890123456", "1234567890666666")
-log.info("AES", "aes-128-cbc encrypt", data2_encrypt:toHex())
-assert(data2_encrypt:toHex():upper() == "26D98EA512AE92BC487536B83F2BE99B467649A9700338F4B4FF75AA2654DD2C", "AES aes-128-cbc encrypt error")
-
-local data2_decrypt = crypto.cipher_decrypt("AES-128-CBC", "PKCS7", data2_encrypt, "1234567890123456", "1234567890666666")
-log.info("AES", "aes-128-cbc decrypt", data2_decrypt)
-assert(data2_decrypt:upper() == "12345678901234 > 123456", "AES aes-128-cbc decrypt error")
-
-local crc16 = crypto.crc16("IBM", "1234567890")
-log.info("crc16", crc16)
-assert(crc16 == 50554, "crc16 error")
-
-local crc16_modbus = crypto.crc16_modbus("1234567890")
-log.info("crc16_modbus", crc16_modbus)
-assert(crc16_modbus == 49674, "crc16_modbus error")
-
-local crc32 = crypto.crc32("1234567890")
-log.info("crc32", crc32)
-assert(crc32 == 639479525, "crc32 error")
-
-local crc8 = crypto.crc8("1234567890", 0x31, 0xff, false)
-log.info("crc8", crc8)
-assert(crc8 == 208, "crc8 error")
-
-local ts = 1646796576
-local otp = crypto.totp("VK54ZXPO74ISEM2E", ts)
-log.info("totp", otp)
-assert(otp == 522113, "totp error")

+ 0 - 36
bsp/win32/module_test/005io.lua

@@ -1,36 +0,0 @@
-
-
-local sys = require "sys"
-
-sys.taskInit(function()
-    sys.wait(100) -- 特意的,检验sys.run在运行
-
-    -- 读写文件1000次
-    for i = 1, 100, 1 do
-        local f = io.open("T", "wb")
-        assert(f)
-        local data = os.date()
-        f:write(data)
-        f:close()
-        f = io.open("T", "rb")
-        assert(f)
-        assert(f:read("a") == data)
-        f:close()
-    end
-
-    -- 快捷读写文件1000次
-    for i = 1, 100, 1 do
-        os.remove("T")
-        io.writeFile("T", os.date())
-        io.readFile("T")
-    end
-
-    log.info("sys", "all done")
-    os.exit(0)
-end)
-
-os.remove("T")
-io.writeFile("T", string.char(0, 0, 1, 2, 4, 0))
-assert(io.fileSize("T") == 6)
-
-sys.run()

+ 0 - 57
bsp/win32/module_test/006fatfs.lua

@@ -1,57 +0,0 @@
-
-
--- local sys = require "sys"
-
-log.info("sys", "from win32")
-
--- sys.taskInit(function ()
-    -- sys.wait(1000)
-
-    if fatfs ~= nil then
-        fatfs.debug(1)
-        fatfs.mount("ram", 64*1024)
-        fatfs.mkfs("ram")
-        -- sys.wait(100)
-        local data, err = fatfs.getfree("ram")
-        if data then
-            log.info("fatfs", "ramdisk", json.encode(data))
-        else
-            log.info("fatfs", "ramdisk", "err", err)
-        end
-        -- fatfs 在vfs中的前缀总是/sdcard
-        local str = string.char(0, 1, 2, 0, 4, 6, 7, 0xff):rep(1024)
-        local f = io.open("/sd/abc.txt", "wb")
-        assert(f ~= nil, "fatfs io error")
-        if f then
-            f:write(str)
-            f:write(string.rep("zzz", 1024))
-            f:close()
-        end
-        log.info("fatfs", "file size", io.fileSize("/sd/abc.txt"))
-        assert(io.fileSize("/sd/abc.txt") == str:len() + 3*1024)
-        f = io.open("/sd/abc.txt", "rb")
-        assert(f ~= nil, "fatfs io error")
-        if f then
-            local data = f:read(str:len())
-            log.info("from fatfs-vfs", data:len())
-            assert(data == str, "fatfs r/w error")
-            local offset = f:seek("set", str:len() + 1024)
-            assert(offset == str:len() + 1024)
-            log.info("fatfs", "offset now", offset)
-            log.info("why", f:read(3))
-            assert(f:read(3) == "zzz")
-            f:seek("end", 0)
-            assert(f:read(1024) == nil)
-            f:seek("set", 0)
-            assert(f:read(str:len() + 3) == str .. "zzz")
-        end
-        local ret, files = io.lsdir("/sd")
-        assert(files ~= nil, "fatfs lsdir shall work")
-        log.info("fatfs", "lsdir", json.encode(files))
-        log.info("bye")
-        -- sys.wait(1000)
-    end
-    os.exit(0)
--- end)
-
--- sys.run()

+ 0 - 33
bsp/win32/module_test/007lfs2.lua

@@ -1,33 +0,0 @@
-
-
-local sys = require "sys"
-
-log.info("sys", "from win32")
-
-sys.taskInit(function ()
-    sys.wait(1000)
-
-    if lfs2 ~= nil then
-        local buff = zbuff.create(64*1024)
-        local drv = sfd.init("zbuff", buff)
-        if drv then
-            lfs2.mount("/mem", drv, true)
-            --lfs2.mkfs("/mem")
-            local f = io.open("/mem/abc.txt", "w")
-            if f then
-                f:write("Hi, from LuatOS")
-                f:close()
-            end
-            f = io.open("/mem/abc.txt", "r")
-            if f then
-                local data = f:read("a")
-                log.info("from lfs2-vfs", data)
-                assert(data == "Hi, from LuatOS", "lfs2 r/w error")
-            end
-        end
-    end
-
-    os.exit(0)
-end)
-
-sys.run()

+ 0 - 49
bsp/win32/module_test/010lvgl.lua

@@ -1,49 +0,0 @@
-
-
-local sys = require "sys"
-
-log.info("sys", "from win32")
-
-sys.taskInit(function ()
-    sys.wait(1000)
-
-    if lfs2 ~= nil then
-        local buff = zbuff.create(64*1024)
-        local drv = sfd.init("zbuff", buff)
-        if drv then
-            lfs2.mount("/mem", drv, true)
-            --lfs2.mkfs("/mem")
-            local f = io.open("/mem/abc.txt", "w")
-            if f then
-                f:write("Hi, from LuatOS")
-                f:close()
-            end
-            f = io.open("/mem/abc.txt", "r")
-            if f then
-                log.info("from lfs2-vfs", f:read("a"))
-            end
-        end
-    end
-
-    log.info("lvgl", lvgl.init())
-    
-    local scr = lvgl.obj_create(nil, nil)
-    local btn = lvgl.btn_create(scr)
-    local btn2 = lvgl.btn_create(scr)
-    lvgl.obj_align(btn, lvgl.scr_act(), lvgl.ALIGN_CENTER, 0, 0)
-    lvgl.obj_align(btn2, lvgl.scr_act(), lvgl.ALIGN_CENTER, 0, 50)
-    local label = lvgl.label_create(btn)
-    local label2 = lvgl.label_create(btn2)
-    lvgl.label_set_text(label, "LuatOS!")
-    lvgl.label_set_text(label2, "Hi")
-
-    lvgl.scr_load(scr)
-
-    log.info("abc", "=====================")
-
-    sys.wait(3000)
-
-    os.exit()
-end)
-
-sys.run()

+ 0 - 11
bsp/win32/module_test/012vmx.lua

@@ -1,11 +0,0 @@
---加载sys库
--- _G.sys = require("sys")
-
--- log.info("vmx", "create ...")
--- vm = vmx.create()
-
--- vmx.exec(vm, "log.info('inside', 'vmx')")
-
--- log.info("vmx", "all done")
-
-os.exit(0)

+ 0 - 19
bsp/win32/module_test/013cwait.lua

@@ -1,19 +0,0 @@
---加载sys库
-_G.sys = require("sys")
-
-log.info("start","cwait test")
-sys.taskInit(function()
-    for i=1,5 do
-        log.info("testCwaitDelay.start",os.time())
-        local r = win32.testCwaitDelay(100).wait()
-        log.info("testCwaitDelay",type(r),r)
-        if r ~= true then os.exit(1) end
-        log.info("testCwaitDelay.end",os.time())
-    end
-
-    log.info("testCwaitError",win32.testCwaitError().wait())
-
-    os.exit(0)
-end)
-
-sys.run()

+ 0 - 43
bsp/win32/module_test/014iotauth.lua

@@ -1,43 +0,0 @@
-
--- LuaTools需要PROJECT和VERSION这两个信息
-PROJECT = "helloworld"
-VERSION = "1.0.0"
-
--- 引入必要的库文件(lua编写), 内部库不需要require
-local sys = require "sys"
-
-log.info("main", "hello world")
-
-print(_VERSION)
-
-sys.taskInit(function()
-    assert(iotauth, "iotauth exist")
-    local client_id,user_name,password = iotauth.onenet("qDPGh8t81z", "45463968338A185E", "MTIzNDU2")
-    log.info("onenet", client_id,user_name,password)
-
-    local client_id,user_name,password = iotauth.iotda("6203cc94c7fb24029b110408_88888888","123456789")
-    log.info("iotda",client_id,user_name,password)
-
-    local client_id,user_name,password = iotauth.tuya(" 6c95875d0f5ba69607nzfl","fb803786602df760")
-    log.info("tuya",client_id,user_name,password)
-
-    local client_id,user_name,password = iotauth.baidu("abcd123","mydevice","ImSeCrEt0I1M2jkl")
-    log.info("baidu",client_id,user_name,password)
-
-    local client_id,user_name,password = iotauth.qcloud("LD8S5J1L07","test","acyv3QDJrRa0fW5UE58KnQ==")
-    log.info("qcloud",client_id,user_name,password)
-
-    local client_id,user_name,password = iotauth.aliyun("123456789","abcdefg","Y877Bgo8X5owd3lcB5wWDjryNPoB")
-    log.info("aliyun",client_id,user_name,password)
-
-
-    
-    os.exit()
-end)
-
-
-
--- 用户代码已结束---------------------------------------------
--- 结尾总是这一句
-sys.run()
--- sys.run()之后后面不要加任何语句!!!!!

+ 0 - 41
bsp/win32/module_test/015miniz.lua

@@ -1,41 +0,0 @@
-
--- LuaTools需要PROJECT和VERSION这两个信息
-PROJECT = "miniz"
-VERSION = "1.0.0"
-
--- 引入必要的库文件(lua编写), 内部库不需要require
-local sys = require "sys"
-
-log.info("main", "hello world")
-
-print(_VERSION)
-
-sys.taskInit(function()
-    local bigdata = "1221341252345234634564576"
-    for i=10,1,-1 do
-        bigdata = bigdata .. tostring(i) .. bigdata
-    end
-
-    local cdata = miniz.compress(bigdata) 
-    -- lua 的 字符串相当于有长度的char[],可存放包括0x00的一切数据
-    assert(cdata, "compress fail!!")
-    if cdata then
-        -- 检查压缩前后的数据大小
-        log.info("miniz", "before", #bigdata, "after", #cdata)
-        log.info("miniz", "cdata as hex", cdata:toHex())
-    
-        -- 解压, 得到原文
-        local udata = miniz.compress(cdata)
-        --log.info("miniz", "udata", udata)
-        assert(udata == bigdata, "compress data NOT match")
-    end
-
-    os.exit()
-end)
-
-
-
--- 用户代码已结束---------------------------------------------
--- 结尾总是这一句
-sys.run()
--- sys.run()之后后面不要加任何语句!!!!!

+ 0 - 19
bsp/win32/module_test/readme.md

@@ -1,19 +0,0 @@
-# 单元测试
-
-## 用途
-
-本文件夹的脚本,用于测试函数是否运行正确
-
-## 编写测试脚本
-
-原则上每个包都需要测试脚本,仅测试win32条件下编译进来的包
-
-每个测试脚本,尽量多加打印日志信息,并且在不符合测试结果时,及时`assert(false,"原因")`
-
-## 测试
-
-复制`luatos.exe`到本文件夹,运行`test.sh`即可开始测试
-
-## 自动测试
-
-脚本提交后,会在GitHub上进行自动测试。建议每次push前,先自己测一遍

+ 0 - 25
bsp/win32/module_test/test.sh

@@ -1,25 +0,0 @@
-echo -e "\e[1;33m===== test start =====\e[0m"
-
-result=0
-
-script=( ./*.lua )
-for file in "${script[@]}"
-do
-    script_output=$(./luatos.exe $file)
-    if grep -q "E/lua.err" <<< "$script_output";
-    then
-        echo -e "[\e[1;31mfail\e[0m] $file"
-        echo "$script_output"
-        result=1
-    else
-        echo -e "[\e[1;32mpass\e[0m] $file"
-    fi
-done
-if [ $result -eq 0 ]
-then
-    echo -e "\e[1;33m==== all tests passed ====\e[0m"
-else
-    echo -e "\e[1;31m==== not pass ====\e[0m"
-fi
-
-exit $result

+ 0 - 128
bsp/win32/port/luat_base_win32.c

@@ -1,128 +0,0 @@
-#include "luat_base.h"
-#include "luat_msgbus.h"
-#include "luat_fs.h"
-#include "luat_timer.h"
-#include <stdlib.h>
-
-#ifdef LUAT_USE_LVGL
-#include "lvgl.h"
-void luat_lv_fs_init(void);
-void lv_bmp_init(void);
-void lv_png_init(void);
-void lv_split_jpeg_init(void);
-#endif
-
-LUAMOD_API int luaopen_win32( lua_State *L );
-int luaopen_lfs(lua_State * L);
-int luaopen_rs232_core(lua_State * L);
-
-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
-  {"rtos", luaopen_rtos},             // rtos底层库, 核心功能是队列和定时器
-  {"log", luaopen_log},               // 日志库
-  {"timer", luaopen_timer},           // 延时库
-  {"pack", luaopen_pack},             // pack.pack/pack.unpack
-  {"json", luaopen_cjson},             // json
-  {"win32", luaopen_win32},            // windows 32 tools
-  {"zbuff", luaopen_zbuff},            // 
-  {"libcoap", luaopen_libcoap},        // 
-  {"crypto", luaopen_crypto},
-// #ifdef LUAT_USE_FATFS
-//   {"fatfs", luaopen_fatfs},
-// #endif
-  {"sfd",   luaopen_sfd},
-  {"lfs2",   luaopen_lfs2},
-  {"gpio",   luaopen_gpio},
-  {"i2c",   luaopen_i2c},
-  {"spi",   luaopen_spi},
-  {"uart",    luaopen_uart},
-  // {"vmx",    luaopen_vmx},
-#ifdef LUAT_USE_LCD
-  {"lcd",    luaopen_lcd},
-#endif
-#ifdef LUAT_USE_LCD
-  {"u8g2", luaopen_u8g2},
-#endif
-#ifdef LUAT_USE_LVGL
-  {"lvgl",   luaopen_lvgl},
-#endif
-  {"iotauth", luaopen_iotauth},
-  {"miniz", luaopen_miniz},
-  {"protobuf", luaopen_protobuf},
-  {"libgnss", luaopen_libgnss},
-  {"rsa", luaopen_rsa},
-  {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) {
-    exit(code);
-}
-
-const char* luat_os_bsp(void) {
-    #ifdef LUA_USE_WINDOWS
-    return "win32";
-    #else
-    return "posix";
-    #endif
-}
-
-
-void vConfigureTimerForRunTimeStats( void ) {}
-
-/** 设备进入待机模式 */
-void luat_os_standy(int timeout) {
-    return; // nop
-}
-
-void luat_ota_reboot(int timeout_ms) {
-  if (timeout_ms > 0)
-    luat_timer_mdelay(timeout_ms);
-  exit(0);
-}
-
-#include "windows.h"
-#include <io.h>
-
-#include <time.h>
-#include <math.h>
-
-// 获取当前时间
-uint32_t get_timestamp(void) {
-    // struct timespec _t;
-    // clock_gettime(CLOCK_REALTIME, &_t);
-    // uint32_t timenow = _t.tv_sec*1000 + lround(_t.tv_nsec/1e6);
-    // //printf("time now > %u\n", timenow);
-    LARGE_INTEGER ticks;
-    QueryPerformanceCounter(&ticks);
-    return ticks.QuadPart;
-}
-
-

+ 0 - 14
bsp/win32/port/luat_crypto_win32.c

@@ -1,14 +0,0 @@
-
-#include "luat_base.h"
-#include "luat_crypto.h"
-#define LUAT_LOG_TAG "crypto"
-#include "luat_log.h"
-#include <stdlib.h>
-
-int luat_crypto_trng(char* buff, size_t len) {
-    for (size_t i = 0; i < len; i++)
-    {
-        buff[i] = (char) rand();
-    }
-    return 0;
-}

+ 0 - 61
bsp/win32/port/luat_fs_win32.c

@@ -1,61 +0,0 @@
-#include "luat_base.h"
-#include "luat_fs.h"
-#include "luat_mem.h"
-#include "luat_luadb.h"
-
-#ifdef LUAT_USE_LVGL
-#include "lvgl.h"
-void luat_lv_fs_init(void);
-void lv_bmp_init(void);
-void lv_png_init(void);
-void lv_split_jpeg_init(void);
-#endif
-
-extern const struct luat_vfs_filesystem vfs_fs_posix;
-// extern const struct luat_vfs_filesystem vfs_fs_onefile;
-extern const struct luat_vfs_filesystem vfs_fs_luadb;
-extern const char* luat_luadb_mock;
-
-// #ifdef LUAT_USE_VFS_INLINE_LIB
-// extern const luadb_file_t *luat_inline2_libs_64bit;
-// #endif
-
-typedef struct luat_fs_onefile
-{
-    char* ptr;
-    uint32_t  size;
-    uint32_t  offset;
-}luat_fs_onefile_t;
-
-int luat_fs_init(void) {
-	#ifdef LUAT_USE_FS_VFS
-	// vfs进行必要的初始化
-	luat_vfs_init(NULL);
-	// 注册vfs for posix 实现
-	luat_vfs_reg(&vfs_fs_posix);
-	luat_vfs_reg(&vfs_fs_luadb);
-
-	luat_fs_conf_t conf = {
-		.busname = "",
-		.type = "posix",
-		.filesystem = "posix",
-		.mount_point = "", // window环境下, 需要支持任意路径的读取,不能强制要求必须是/
-	};
-	luat_fs_mount(&conf);
-	luat_fs_conf_t conf2 = {
-		.busname = (char*)luat_luadb_mock,
-		.type = "luadb",
-		.filesystem = "luadb",
-		.mount_point = "/luadb/",
-	};
-	luat_fs_mount(&conf2);
-	#endif
-
-	#ifdef LUAT_USE_LVGL
-	luat_lv_fs_init();
-	lv_bmp_init();
-	lv_png_init();
-	lv_split_jpeg_init();
-	#endif
-	return 0;
-}

+ 0 - 73
bsp/win32/port/luat_gpio_win32.c

@@ -1,73 +0,0 @@
-#include "luat_base.h"
-#include "luat_gpio.h"
-#include "luat_msgbus.h"
-
-// 模拟GPIO在win32下的实现
-
-#define LUAT_WIN32_GPIO_COUNT (32)
-
-int l_gpio_handler(lua_State *L, void* ptr) ;
-
-typedef struct gpio_state {
-    luat_gpio_t gpio;
-    uint8_t open;
-    uint8_t state;
-}gpio_state_t;
-
-gpio_state_t win32gpios[LUAT_WIN32_GPIO_COUNT] = {0};
-
-int luat_gpio_setup(luat_gpio_t* gpio) {
-    if (gpio->pin < 0 || gpio->pin >= LUAT_WIN32_GPIO_COUNT) {
-        return -1;
-    }
-    memcpy(&win32gpios[gpio->pin], gpio, sizeof(luat_gpio_t));
-    win32gpios[gpio->pin].open = 1;
-    if (gpio->mode == Luat_GPIO_OUTPUT) {
-        win32gpios[gpio->pin].state = gpio->irq;
-    }
-    else {
-        win32gpios[gpio->pin].state = 0;
-    }
-    return 0;
-}
-
-int luat_gpio_set(int pin, int level) {
-    if (pin < 0 || pin >= LUAT_WIN32_GPIO_COUNT) {
-        return -1;
-    }
-    if (win32gpios[pin].open == 0) {
-        return -1;
-    }
-    
-    if (win32gpios[pin].state != level) {
-        win32gpios[pin].state = level;
-        rtos_msg_t msg = {0};
-        msg.ptr = NULL;
-        msg.arg1 = pin;
-        msg.arg2 = level;
-        msg.handler = l_gpio_handler;
-        luat_msgbus_put(&msg, 0);
-    };
-    return 0;
-}
-
-int luat_gpio_get(int pin) {
-    if (pin < 0 || pin >= LUAT_WIN32_GPIO_COUNT) {
-        return 0;
-    }
-    if (win32gpios[pin].open == 0) {
-        return 0;
-    }
-    return win32gpios[pin].state;
-}
-
-void luat_gpio_close(int pin) {
-    if (pin < 0 || pin >= LUAT_WIN32_GPIO_COUNT) {
-        return;
-    }
-    win32gpios[pin].open = 0;
-}
-
-void luat_gpio_pulse(int pin, uint8_t *level, uint16_t len, uint16_t delay_ns) {
-
-}

+ 0 - 34
bsp/win32/port/luat_i2c_win32.c

@@ -1,34 +0,0 @@
-
-#include "luat_base.h"
-#include "luat_i2c.h"
-
-#define LUAT_LOG_TAG "luat.i2c"
-#include "luat_log.h"
-
-int luat_i2c_exist(int id) {
-    return id == 0;
-}
-    
-int luat_i2c_setup(int id, int speed) {
-    return 0;
-}
-
-int luat_i2c_close(int id) {
-    return 0;
-}
-
-int luat_i2c_send(int id, int addr, void* buff, size_t len, uint8_t stop) {
-    return 0;
-}
-
-int luat_i2c_recv(int id, int addr, void* buff, size_t len) {
-    return 0;
-}
-
-int luat_i2c_transfer(int id, int addr, uint8_t *reg, size_t reg_len, uint8_t *buff, size_t len) {
-    return 0;
-}
-
-int luat_i2c_no_block_transfer(int id, int addr, uint8_t is_read, uint8_t *reg, size_t reg_len, uint8_t *buff, size_t len, uint16_t Toms, void *CB, void *pParam) {
-	return 0;
-}

+ 0 - 80
bsp/win32/port/luat_lib_win32.c

@@ -1,80 +0,0 @@
-
-#include "luat_base.h"
-#include "luat_mem.h"
-#include "luat_timer.h"
-
-#define LUAT_LOG_TAG "win32"
-#include "luat_log.h"
-
-extern int cmdline_argc;
-extern char** cmdline_argv;
-
-static int l_win32_args(lua_State *L) {
-    int index = luaL_optinteger(L, 1, 2);
-    lua_newtable(L);
-    if (cmdline_argc > index) {
-        for (size_t i = index; i < cmdline_argc; i++)
-        {
-            //printf("args[%d] %s\n", i, win32_argv[i]);
-            lua_pushinteger(L, i + 1 - index);
-            lua_pushstring(L, cmdline_argv[i]);
-            lua_settable(L, -3);
-        }
-    }
-
-    return 1;
-}
-
-static int timer_handler(lua_State *L, void* ptr) {
-    luat_timer_t *timer = (luat_timer_t *)ptr;
-    uint64_t* idp = (uint64_t*)timer->id;
-    lua_pushboolean(L,1);
-    luat_cbcwait(L, *idp, 1);
-    return 0;
-}
-
-static int l_test_cwait_delay(lua_State *L) {
-    lua_gettop(L);
-    if (lua_isinteger(L, 1)) {
-        lua_Integer ms = luaL_checkinteger(L, 1);
-        if (ms)
-        {
-            uint64_t id = luat_pushcwait(L);
-            luat_timer_t *timer = (luat_timer_t*)luat_heap_malloc(sizeof(luat_timer_t));
-
-            uint64_t* idp = (uint64_t*)luat_heap_malloc(sizeof(uint64_t));
-            memcpy(idp, &id, sizeof(uint64_t));
-
-            timer->id = (size_t)idp;
-            timer->timeout = ms;
-            timer->repeat = 0;
-            timer->func = &timer_handler;
-
-            int re = luat_timer_start(timer);
-            return 1;
-        }
-    }
-    return 0;
-}
-
-static int l_test_cwait_error(lua_State *L) {
-    lua_pushstring(L,"result1");
-    lua_pushstring(L,"result2");
-    lua_pushstring(L,"result3");
-    luat_pushcwait_error(L,3);
-    return 1;
-}
-
-#include "rotable.h"
-static const rotable_Reg reg_win32[] =
-{
-    { "args",      l_win32_args,   0},
-    { "testCwaitDelay",      l_test_cwait_delay,   0},
-    { "testCwaitError",      l_test_cwait_error,   0},
-	{ NULL,                 NULL,   0}
-};
-
-LUAMOD_API int luaopen_win32( lua_State *L ) {
-    luat_newlib(L, reg_win32);
-    return 1;
-}

+ 0 - 86
bsp/win32/port/luat_log_win32.c

@@ -1,86 +0,0 @@
-
-#include "luat_base.h"
-#include "luat_log.h"
-#include "luat_uart.h"
-#include "luat_mem.h"
-#include "printf.h"
-
-#include <stdio.h>
-
-typedef struct log_msg {
-    char* buff;
-}log_msg_t;
-
-static uint8_t luat_log_uart_port = 0;
-static uint8_t luat_log_level_cur = LUAT_LOG_DEBUG;
-
-void luat_log_init_win32(void) {
-}
-
-void luat_log_set_uart_port(int port) {
-    luat_log_uart_port = port;
-}
-
-void luat_print(const char* _str) {
-    luat_nprint((char*)_str, strlen(_str));
-}
-
-void luat_nprint(char *s, size_t l) {
-    char buff[4*1024];
-    memcpy(buff, s, l);
-    buff[l] = 0;
-    printf("%s", buff);
-}
-
-void luat_log_set_level(int level) {
-    luat_log_level_cur = level;
-}
-int luat_log_get_level() {
-    return luat_log_level_cur;
-}
-#define LOGLOG_SIZE 1024
-void luat_log_log(int level, const char* tag, const char* _fmt, ...) {
-    if (luat_log_level_cur > level) return;
-    char buff[LOGLOG_SIZE] = {0};
-    char *tmp = (char *)buff;
-    switch (level)
-        {
-        case LUAT_LOG_DEBUG:
-            buff[0] = 'D';
-            break;
-        case LUAT_LOG_INFO:
-            buff[0] = 'I';
-            break;
-        case LUAT_LOG_WARN:
-            buff[0] = 'W';
-            break;
-        case LUAT_LOG_ERROR:
-            buff[0] = 'E';
-            break;
-        default:
-            buff[0] = '?';
-            break;
-        }
-    buff[1] = '/';
-    tmp += 2;
-    memcpy(tmp, tag, strlen(tag));
-    buff[2+strlen(tag)] = ' ';
-    tmp += strlen(tag) + 1;
-
-    va_list args;
-    va_start(args, _fmt);
-    size_t len = vsnprintf_(tmp, LOGLOG_SIZE, _fmt, args);
-    va_end(args);
-    if (len > 0) {
-        len = strlen(buff);
-        // if (len > LOGLOG_SIZE - 2)
-        //     len = LOGLOG_SIZE - 2;
-        // buff[len] = '\r';
-        // buff[len+1] = '\n';
-        // luat_nprint(buff, len+2);
-        if (len > LOGLOG_SIZE - 1)
-            len = LOGLOG_SIZE - 1;
-        buff[len] = '\n';
-        luat_nprint(buff, len+1);
-    }
-}

+ 0 - 89
bsp/win32/port/luat_malloc_win32.c

@@ -1,89 +0,0 @@
-
-// 这个文件包含 系统heap和lua heap的默认实现
-
-
-#include <stdlib.h>
-#include <string.h>//add for memset
-#include "bget.h"
-#include "luat_mem.h"
-
-#define LUAT_LOG_TAG "vmheap"
-#include "luat_log.h"
-
-//------------------------------------------------
-//  管理系统内存
-
-void* luat_heap_malloc(size_t len) {
-    return malloc(len);
-}
-
-void luat_heap_free(void* ptr) {
-    free(ptr);
-}
-
-void* luat_heap_realloc(void* ptr, size_t len) {
-    return realloc(ptr, len);
-}
-
-void* luat_heap_calloc(size_t count, size_t _size) {
-    void *ptr = luat_heap_malloc(count * _size);
-    if (ptr) {
-        memset(ptr, 0, _size);
-    }
-    return ptr;
-}
-//------------------------------------------------
-
-//------------------------------------------------
-// ---------- 管理 LuaVM所使用的内存----------------
-void* luat_heap_alloc(void *ud, void *ptr, size_t osize, size_t nsize) {
-    if (0) {
-        if (ptr) {
-            if (nsize) {
-                // 缩放内存块
-                LLOGD("realloc %p from %d to %d", ptr, osize, nsize);
-            }
-            else {
-                // 释放内存块
-                LLOGD("free %p ", ptr);
-                brel(ptr);
-                return NULL;
-            }
-        }
-        else {
-            // 申请内存块
-            ptr = bget(nsize);
-            LLOGD("malloc %p type=%d size=%d", ptr, osize, nsize);
-            return ptr;
-        }
-    }
-
-    if (nsize)
-    {
-    	void* ptmp = bgetr(ptr, nsize);
-    	if(ptmp == NULL && osize >= nsize)
-    	{
-    		return ptr;
-    	}
-        return ptmp;
-    }
-    brel(ptr);
-    return NULL;
-}
-
-void luat_meminfo_luavm(size_t *total, size_t *used, size_t *max_used) {
-	long curalloc, totfree, maxfree;
-	unsigned long nget, nrel;
-	bstats(&curalloc, &totfree, &maxfree, &nget, &nrel);
-	*used = curalloc;
-	*max_used = bstatsmaxget();
-    *total = curalloc + totfree;
-}
-
-void luat_meminfo_sys(size_t *total, size_t *used, size_t *max_used) {
-	*used = 0;
-	*max_used = 0;
-    *total = 0;
-}
-
-//-----------------------------------------------------------------------------

+ 0 - 17
bsp/win32/port/luat_mcu_win32.c

@@ -1,17 +0,0 @@
-#include "luat_base.h"
-#include "luat_mcu.h"
-#include "windows.h"
-
-long luat_mcu_ticks(void) {
-    return GetTickCount();
-}
-
-int luat_mcu_us_period(void) {
-    return 1;
-}
-
-static uint64_t tick64;
-uint64_t luat_mcu_tick64(void) {
-    tick64 ++;
-    return tick64;
-}

+ 0 - 73
bsp/win32/port/luat_msgbus_win32.c

@@ -1,73 +0,0 @@
-/**
- * @file luat_msgbus_win32.c
- * @author wendal (wendal1985@gamil.com)
- * @brief 基于win32的ThreadMessage机制实现的msgbus
- * @version 0.1
- * @date 2022-03-27
- * 
- * @copyright Copyright (c) 2022 OpenLuat & AirM2M
- * 
- */
-#include "luat_base.h"
-#include "luat_msgbus.h"
-#include "luat_timer.h"
-#include "luat_mem.h"
-#include <stdbool.h>
-
-#include "windows.h"
-#include "windowsx.h"
-
-#define LUAT_LOG_TAG "msgbus"
-#include "luat_log.h"
-
-
-static DWORD luat_main_thread_id;
-
-void luat_msgbus_init(void) {
-    luat_main_thread_id = GetCurrentThreadId();
-    // LLOGD("main thread id %d", luat_main_thread_id);
-}
-uint32_t luat_msgbus_put(rtos_msg_t* msg, size_t timeout) {
-    rtos_msg_t* tmp = luat_heap_malloc(sizeof(rtos_msg_t));
-    memcpy(tmp, msg, sizeof(rtos_msg_t));
-    PostThreadMessageA(luat_main_thread_id, WM_COMMAND, (WPARAM)tmp, 0);
-    return 0;
-}
-
-
-uint32_t luat_msgbus_get(rtos_msg_t* rtmsg, size_t timeout) {
-    MSG msg;
-    rtos_msg_t* tmp;
-    bool ret = FALSE;
-    if ((ret = GetMessageA(&msg,NULL,0,0)) == 0) {
-      exit(0);
-      return 0;
-    }
-    
-    
-    int mouse_x, mouse_y;
-    bool mouse_pressed;
-    switch (msg.message)
-    {
-    case WM_COMMAND:
-        tmp = (rtos_msg_t*)msg.wParam;
-        if (tmp != NULL) {
-            memcpy(rtmsg, tmp, sizeof(rtos_msg_t));
-            luat_heap_free(tmp);
-            return 0;
-        }
-        break;
-    default:
-        DispatchMessage(&msg);
-        break;
-    }
-    return 1;
-}
-
-uint32_t luat_msgbus_freesize(void) {
-    return 1;
-}
-
-uint8_t luat_msgbus_is_empty(void) {
-    return 1;
-}

+ 0 - 21
bsp/win32/port/luat_sfd_onchip_win32.c

@@ -1,21 +0,0 @@
-#include "luat_base.h"
-#include "luat_sfd.h"
-
-int sfd_onchip_init (void* userdata) {
-    return -1;
-}
-int sfd_onchip_status (void* userdata) {
-    return -1;
-}
-int sfd_onchip_read (void* userdata, char* buff, size_t offset, size_t len) {
-    return -1;
-}
-int sfd_onchip_write (void* userdata, const char* buff, size_t offset, size_t len) {
-    return -1;
-}
-int sfd_onchip_erase (void* userdata, size_t offset, size_t len) {
-    return -1;
-}
-int sfd_onchip_ioctl (void* userdata, size_t cmd, void* buff) {
-    return -1;
-}

+ 0 - 49
bsp/win32/port/luat_spi_device.c

@@ -1,49 +0,0 @@
-#include "luat_base.h"
-#include "luat_gpio.h"
-#include "luat_spi.h"
-
-#define LUAT_SPI_CS_SELECT 0
-#define LUAT_SPI_CS_CLEAR  1
-
-
-// luat_spi_device_t* 在lua层看到的是一个userdata
-int luat_spi_device_setup(luat_spi_device_t* spi_dev) {
-    luat_spi_bus_setup(spi_dev);
-    luat_gpio_mode(spi_dev->spi_config.cs, Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, Luat_GPIO_HIGH); // CS
-    return 0;
-}
-
-//关闭SPI设备,成功返回0
-int luat_spi_device_close(luat_spi_device_t* spi_dev) {
-    return luat_spi_close(spi_dev->bus_id);
-}
-
-//收发SPI数据,返回接收字节数
-int luat_spi_device_transfer(luat_spi_device_t* spi_dev, const char* send_buf, size_t send_length, char* recv_buf, size_t recv_length) {
-    luat_spi_device_config(spi_dev);
-    luat_gpio_set(spi_dev->spi_config.cs, LUAT_SPI_CS_SELECT);
-    int ret = luat_spi_transfer(spi_dev->bus_id, send_buf, send_length, recv_buf, recv_length);
-    // int ret = luat_spi_send(spi_dev->bus_id, send_buf, send_length);
-    // ret = luat_spi_recv(spi_dev->bus_id, recv_buf, recv_length);
-    luat_gpio_set(spi_dev->spi_config.cs, LUAT_SPI_CS_CLEAR);
-    return ret;
-}
-
-//收SPI数据,返回接收字节数
-int luat_spi_device_recv(luat_spi_device_t* spi_dev, char* recv_buf, size_t length) {
-    luat_spi_device_config(spi_dev);
-    luat_gpio_set(spi_dev->spi_config.cs, LUAT_SPI_CS_SELECT);
-    int ret = luat_spi_recv(spi_dev->bus_id, recv_buf, length);
-    luat_gpio_set(spi_dev->spi_config.cs, LUAT_SPI_CS_CLEAR);
-    return ret;
-}
-
-//发SPI数据,返回发送字节数
-int luat_spi_device_send(luat_spi_device_t* spi_dev, const char* send_buf, size_t length) {
-    luat_spi_device_config(spi_dev);
-    luat_gpio_set(spi_dev->spi_config.cs, LUAT_SPI_CS_SELECT);
-    int ret = luat_spi_send(spi_dev->bus_id, send_buf, length);
-    luat_gpio_set(spi_dev->spi_config.cs, LUAT_SPI_CS_CLEAR);
-    return ret;
-}
-

+ 0 - 84
bsp/win32/port/luat_spi_win32.c

@@ -1,84 +0,0 @@
-
-#include "luat_base.h"
-#include "luat_gpio.h"
-#include "luat_msgbus.h"
-#include "luat_spi.h"
-
-// 模拟SPI在win32下的实现
-// TODO 当需要返回数据时, 调用lua方法获取需要返回的数据
-
-#define LUAT_WIN32_SPI_COUNT (3)
-
-typedef struct win32spi {
-    luat_spi_t spi;
-    uint8_t open;
-}win32spi_t;
-
-win32spi_t win32spis[LUAT_WIN32_SPI_COUNT] = {0};
-
-int luat_spi_device_config(luat_spi_device_t* spi_dev){
-    return 0;
-}
-
-int luat_spi_bus_setup(luat_spi_device_t* spi_dev){
-    int bus_id = spi_dev->bus_id;
-    if (bus_id < 0 || bus_id >= LUAT_WIN32_SPI_COUNT) {
-        return -1;
-    }
-    memcpy(&win32spis[bus_id].spi, &(spi_dev->spi_config), sizeof(luat_spi_t));
-    win32spis[bus_id].open = 1;
-    return 0;
-}
-
-int luat_spi_setup(luat_spi_t* spi) {
-    if (spi->id < 0 || spi->id >= LUAT_WIN32_SPI_COUNT) {
-        return -1;
-    }
-    memcpy(&win32spis[spi->id].spi, spi, sizeof(luat_spi_t));
-    win32spis[spi->id].open = 1;
-    return 0;
-}
-//关闭SPI,成功返回0
-int luat_spi_close(int spi_id) {
-    if (spi_id < 0 || spi_id >= LUAT_WIN32_SPI_COUNT) {
-        return -1;
-    }
-    win32spis[spi_id].open = 0;
-    return 0;
-}
-//收发SPI数据,返回接收字节数
-int luat_spi_transfer(int spi_id, const char* send_buf, size_t send_length, char* recv_buf, size_t recv_length) {
-    if (spi_id < 0 || spi_id >= LUAT_WIN32_SPI_COUNT) {
-        return -1;
-    }
-    if (win32spis[spi_id].open == 0)
-        return -1;
-    memset(recv_buf, 0, recv_length);
-    return recv_length;
-}
-//收SPI数据,返回接收字节数
-int luat_spi_recv(int spi_id, char* recv_buf, size_t length) {
-    if (spi_id < 0 || spi_id >= LUAT_WIN32_SPI_COUNT) {
-        return -1;
-    }
-    if (win32spis[spi_id].open == 0)
-        return -1;
-    memset(recv_buf, 0, length);
-    return length;
-}
-//发SPI数据,返回发送字节数
-int luat_spi_send(int spi_id, const char* send_buf, size_t length) {
-    if (spi_id < 0 || spi_id >= LUAT_WIN32_SPI_COUNT) {
-        return -1;
-    }
-    if (win32spis[spi_id].open == 0)
-        return -1;
-    return length;
-}
-
-int luat_spi_change_speed(int spi_id, uint32_t speed){
-    return 0;
-}
-
-
-

+ 0 - 125
bsp/win32/port/luat_timer_win32.c

@@ -1,125 +0,0 @@
-/**
- * @file luat_timer_emulator.c
- * @author wendal (wendal1985@gamil.com)
- * @brief 基于win32的timer实现
- * @version 0.1
- * @date 2022-03-27
- * 
- * @copyright Copyright (c) 2022 OpenLuat & AirM2M
- * 
- */
-#include "luat_base.h"
-#include "luat_mem.h"
-#include "luat_timer.h"
-#include "luat_msgbus.h"
-
-#include "windows.h"
-#include <io.h>
-
-#define LUAT_LOG_TAG "timer"
-#include "luat_log.h"
-
-#define WIN32_TIMER_COUNT 64
-
-static luat_timer_t* timers[WIN32_TIMER_COUNT] = {0};
-
-void CALLBACK TimeProc( 
-    HWND hwnd,       
-    UINT message,     
-    UINT idTimer,     
-    DWORD dwTime) {
-    rtos_msg_t msg;
-    msg.arg1 = 0;
-    msg.arg2 = 0;
-
-    // LLOGD("timer callback");
-
-    for (size_t i = 0; i < WIN32_TIMER_COUNT; i++)
-    {
-        if (timers[i] && (UINT_PTR)(timers[i]->os_timer) == idTimer) {
-            msg.handler = timers[i]->func;
-            msg.ptr = timers[i];
-            msg.arg1 = timers[i]->id;
-            luat_msgbus_put(&msg, 0);
-            // LLOGD("timer msgbus index=%ld", i);
-        }
-    }
-    
-}
-
-static int nextTimerSlot() {
-    for (size_t i = 0; i < WIN32_TIMER_COUNT; i++)
-    {
-        if (timers[i] == NULL) {
-            return i;
-        }
-    }
-    return -1;
-}
-
-int luat_timer_start(luat_timer_t* 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!!
-    }
-    UINT_PTR timer_id = SetTimer(NULL, 0, timer->timeout,TimeProc);
-    timer->os_timer = (void*)timer_id;
-    timers[timerIndex] = timer;
-    return 0;
-}
-
-int luat_timer_stop(luat_timer_t* timer) {
-    for (size_t i = 0; i < WIN32_TIMER_COUNT; i++)
-    {
-        if (timers[i] && timers[i] == timer) {
-            timers[i] = NULL;
-            KillTimer(NULL, (UINT_PTR)timer->os_timer);
-        }
-    }
-    
-    return 0;
-};
-
-luat_timer_t* luat_timer_get(size_t timer_id) {
-    for (size_t i = 0; i < WIN32_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) {
-        Sleep(1000);
-    }
-    return 0;
-}
-
-static void usleep(unsigned long usec)
-{
-    HANDLE timer;
-    LARGE_INTEGER interval;
-    interval.QuadPart = -(10 * usec);
-
-    timer = CreateWaitableTimer(NULL, TRUE, NULL);
-    SetWaitableTimer(timer, &interval, 0, NULL, NULL, 0);
-    WaitForSingleObject(timer, INFINITE);
-    CloseHandle(timer);
-}
-
-void luat_timer_us_delay(size_t us) {
-    if (us)
-        usleep(us);
-}
-
-void luat_rtos_task_sleep(uint32_t ms) {
-    if (ms > 0) {
-        Sleep(1000);
-    }
-}

+ 0 - 29
bsp/win32/port/luat_u8g2_win32.c

@@ -1,29 +0,0 @@
-#include "luat_base.h"
-#include "u8g2.h"
-#include "luat_u8g2.h"
-
-uint8_t u8x8_luat_gpio_and_delay(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr);
-uint8_t u8x8_luat_byte_hw_i2c(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr);
-uint8_t u8x8_luat_byte_4wire_hw_spi(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr);
-
-uint8_t u8x8_luat_gpio_and_delay_default(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr);
-uint8_t u8x8_luat_byte_hw_i2c_default(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr);
-uint8_t u8x8_luat_byte_4wire_hw_spi_default(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr);
-
-int luat_u8g2_setup_default(luat_u8g2_conf_t *conf);
-
-int luat_u8g2_setup(luat_u8g2_conf_t *conf) {
-    return luat_u8g2_setup_default(conf);
-}
-
-uint8_t u8x8_luat_gpio_and_delay(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr) {
-    return u8x8_luat_gpio_and_delay_default(u8x8, msg, arg_int, arg_ptr);
-}
-
-uint8_t u8x8_luat_byte_hw_i2c(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr) {
-    return u8x8_luat_byte_hw_i2c_default(u8x8, msg, arg_int, arg_ptr);
-}
-
-uint8_t u8x8_luat_byte_4wire_hw_spi(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr) {
-    return u8x8_luat_byte_4wire_hw_spi_default(u8x8, msg, arg_int, arg_ptr);
-}

+ 0 - 101
bsp/win32/port/luat_uart_win32.c

@@ -1,101 +0,0 @@
-#include "luat_base.h"
-#include "luat_mem.h"
-#include "luat_msgbus.h"
-#include "luat_uart.h"
-#include "luat_log.h"
-#include "windows.h"
-
-#define LUAT_LOG_TAG           "luat.uart"
-
-int l_uart_handler(lua_State *L, void* ptr);
-
-//检测串口存不存在
-int (*luat_uart_exist_extern)(int id)  = NULL;
-//打开串口
-int (*luat_uart_open_extern)(int id,int br,int db, int sb, int para)  = NULL;
-//关闭串口
-int (*luat_uart_close_extern)(int id)  = NULL;
-//读取数据
-int (*luat_uart_read_extern)(int id,void* buff, size_t len)  = NULL;
-//发送数据
-int (*luat_uart_send_extern)(int id,void* buff, size_t len)  = NULL;
-//配置接收回调
-int (*luat_uart_recv_cb_extern)(int id,void (*)(int id, int len))  = NULL;
-//配置发送回调
-int (*luat_uart_sent_cb_extern)(int id,void (*)(int id, int len))  = NULL;
-//获取可用串口列表
-int (*luat_uart_get_list_extern)(uint8_t* list, size_t buff_len)  = NULL;
-
-void luat_uart_initial_win32()
-{
-    HMODULE module = LoadLibraryA("luat_uart.dll");
-    if (module == NULL) {
-        LLOGE("uart library initial error!");
-        return;
-    }
-    luat_uart_exist_extern = (int (*)(int))GetProcAddress(module, "luat_uart_exist_extern");
-    luat_uart_open_extern = (int (*)(int,int,int,int,int))GetProcAddress(module, "luat_uart_open_extern");
-    luat_uart_close_extern = (int (*)(int))GetProcAddress(module, "luat_uart_close_extern");
-    luat_uart_read_extern = (int (*)(int,void*,size_t))GetProcAddress(module, "luat_uart_read_extern");
-    luat_uart_send_extern = (int (*)(int,void*,size_t))GetProcAddress(module, "luat_uart_send_extern");
-    luat_uart_recv_cb_extern = (int (*)(int,void (*)(int, const char *, int)))GetProcAddress(module, "luat_uart_recv_cb_extern");
-    luat_uart_sent_cb_extern = (int (*)(int,void (*)(int, int)))GetProcAddress(module, "luat_uart_sent_cb_extern");
-    luat_uart_get_list_extern = (int (*)(uint8_t*,size_t))GetProcAddress(module, "luat_uart_get_list_extern");
-    //FreeLibrary(module);//感觉用不到
-}
-
-int luat_uart_exist(int uartid) 
-{
-    return luat_uart_exist_extern(uartid);
-}
-
-int luat_uart_list(uint8_t* list, size_t buff_len){
-    return luat_uart_get_list_extern(list,buff_len);
-}
-
-int luat_uart_setup(luat_uart_t* uart)
-{
-    return luat_uart_open_extern(uart->id,uart->baud_rate,uart->data_bits,uart->stop_bits,uart->parity);
-}
-
-int luat_uart_write(int uartid, void* data, size_t length)
-{
-    return luat_uart_send_extern(uartid,data,length);
-}
-
-int luat_uart_read(int uartid, void* buffer, size_t length)
-{
-    return luat_uart_read_extern(uartid,buffer,length);
-}
-
-int luat_uart_close(int uartid)
-{
-    return luat_uart_close_extern(uartid);
-}
-
-
-
-void luat_uart_recv_cb(int id, int len)
-{
-    rtos_msg_t msg;
-    msg.handler = l_uart_handler;
-    msg.ptr = NULL;
-    msg.arg1 = id;
-    msg.arg2 = len;
-    luat_msgbus_put(&msg, 1);
-}
-
-int luat_setup_cb(int uartid, int received, int sent) {
-    if (!luat_uart_exist(uartid)) {
-        LLOGW("uart id=%d not exist", uartid);
-        return -1;
-    }
-    if (received) {
-        return luat_uart_recv_cb_extern(uartid,luat_uart_recv_cb);
-    }
-    if (sent) {
-        LLOGW("[waring] win32 uart lib do not support uart sent cb function %d", uartid);
-        return 1;
-    }
-    return 0;
-}

+ 0 - 614
bsp/win32/src/lua.c

@@ -1,614 +0,0 @@
-/*
-** $Id: lua.c,v 1.230.1.1 2017/04/19 17:29:57 roberto Exp $
-** Lua stand-alone interpreter
-** See Copyright Notice in lua.h
-*/
-
-#define lua_c
-
-#include "lprefix.h"
-
-
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "lua.h"
-
-#include "lauxlib.h"
-#include "lualib.h"
-
-LUALIB_API void luat_openlibs (lua_State *L);
-
-#if !defined(LUA_PROMPT)
-#define LUA_PROMPT		"> "
-#define LUA_PROMPT2		">> "
-#endif
-
-#if !defined(LUA_PROGNAME)
-#define LUA_PROGNAME		"lua"
-#endif
-
-#if !defined(LUA_MAXINPUT)
-#define LUA_MAXINPUT		512
-#endif
-
-#if !defined(LUA_INIT_VAR)
-#define LUA_INIT_VAR		"LUA_INIT"
-#endif
-
-#define LUA_INITVARVERSION	LUA_INIT_VAR LUA_VERSUFFIX
-
-
-/*
-** lua_stdin_is_tty detects whether the standard input is a 'tty' (that
-** is, whether we're running lua interactively).
-*/
-#if !defined(lua_stdin_is_tty)	/* { */
-
-#if defined(LUA_USE_POSIX)	/* { */
-
-#include <unistd.h>
-#define lua_stdin_is_tty()	isatty(0)
-
-#elif defined(LUA_USE_WINDOWS)	/* }{ */
-
-#include <io.h>
-#include <windows.h>
-
-#define lua_stdin_is_tty()	_isatty(_fileno(stdin))
-
-#else				/* }{ */
-
-/* ISO C definition */
-#define lua_stdin_is_tty()	1  /* assume stdin is a tty */
-
-#endif				/* } */
-
-#endif				/* } */
-
-
-/*
-** lua_readline defines how to show a prompt and then read a line from
-** the standard input.
-** lua_saveline defines how to "save" a read line in a "history".
-** lua_freeline defines how to free a line read by lua_readline.
-*/
-#if !defined(lua_readline)	/* { */
-
-#if defined(LUA_USE_READLINE)	/* { */
-
-#include <readline/readline.h>
-#include <readline/history.h>
-#define lua_readline(L,b,p)	((void)L, ((b)=readline(p)) != NULL)
-#define lua_saveline(L,line)	((void)L, add_history(line))
-#define lua_freeline(L,b)	((void)L, free(b))
-
-#else				/* }{ */
-
-#define lua_readline(L,b,p) \
-        ((void)L, fputs(p, stdout), fflush(stdout),  /* show prompt */ \
-        fgets(b, LUA_MAXINPUT, stdin) != NULL)  /* get line */
-#define lua_saveline(L,line)	{ (void)L; (void)line; }
-#define lua_freeline(L,b)	{ (void)L; (void)b; }
-
-#endif				/* } */
-
-#endif				/* } */
-
-
-
-
-static lua_State *globalL = NULL;
-
-static const char *progname = LUA_PROGNAME;
-
-
-/*
-** Hook set by signal function to stop the interpreter.
-*/
-static void lstop (lua_State *L, lua_Debug *ar) {
-  (void)ar;  /* unused arg. */
-  lua_sethook(L, NULL, 0, 0);  /* reset hook */
-  luaL_error(L, "interrupted!");
-}
-
-
-/*
-** Function to be called at a C signal. Because a C signal cannot
-** just change a Lua state (as there is no proper synchronization),
-** this function only sets a hook that, when called, will stop the
-** interpreter.
-*/
-static void laction (int i) {
-  signal(i, SIG_DFL); /* if another SIGINT happens, terminate process */
-  lua_sethook(globalL, lstop, LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1);
-}
-
-
-static void print_usage (const char *badoption) {
-  lua_writestringerror("%s: ", progname);
-  if (badoption[1] == 'e' || badoption[1] == 'l')
-    lua_writestringerror("'%s' needs argument\n", badoption);
-  else
-    lua_writestringerror("unrecognized option '%s'\n", badoption);
-  lua_writestringerror(
-  "usage: %s [options] [script [args]]\n"
-  "Available options are:\n"
-  "  -e stat  execute string 'stat'\n"
-  "  -i       enter interactive mode after executing 'script'\n"
-  "  -l name  require library 'name' into global 'name'\n"
-  "  -v       show version information\n"
-  "  -E       ignore environment variables\n"
-  "  --       stop handling options\n"
-  "  -        stop handling options and execute stdin\n"
-  ,
-  progname);
-}
-
-
-/*
-** Prints an error message, adding the program name in front of it
-** (if present)
-*/
-static void l_message (const char *pname, const char *msg) {
-  if (pname) lua_writestringerror("%s: ", pname);
-  lua_writestringerror("%s\n", msg);
-}
-
-
-/*
-** Check whether 'status' is not OK and, if so, prints the error
-** message on the top of the stack. It assumes that the error object
-** is a string, as it was either generated by Lua or by 'msghandler'.
-*/
-static int report (lua_State *L, int status) {
-  if (status != LUA_OK) {
-    const char *msg = lua_tostring(L, -1);
-    l_message(progname, msg);
-    lua_pop(L, 1);  /* remove message */
-  }
-  return status;
-}
-
-
-/*
-** Message handler used to run all chunks
-*/
-static int msghandler (lua_State *L) {
-  const char *msg = lua_tostring(L, 1);
-  if (msg == NULL) {  /* is error object not a string? */
-    if (luaL_callmeta(L, 1, "__tostring") &&  /* does it have a metamethod */
-        lua_type(L, -1) == LUA_TSTRING)  /* that produces a string? */
-      return 1;  /* that is the message */
-    else
-      msg = lua_pushfstring(L, "(error object is a %s value)",
-                               luaL_typename(L, 1));
-  }
-  luaL_traceback(L, L, msg, 1);  /* append a standard traceback */
-  return 1;  /* return the traceback */
-}
-
-
-/*
-** Interface to 'lua_pcall', which sets appropriate message function
-** and C-signal handler. Used to run all chunks.
-*/
-static int docall (lua_State *L, int narg, int nres) {
-  int status;
-  int base = lua_gettop(L) - narg;  /* function index */
-  lua_pushcfunction(L, msghandler);  /* push message handler */
-  lua_insert(L, base);  /* put it under function and args */
-  globalL = L;  /* to be available to 'laction' */
-  signal(SIGINT, laction);  /* set C-signal handler */
-  status = lua_pcall(L, narg, nres, base);
-  signal(SIGINT, SIG_DFL); /* reset C-signal handler */
-  lua_remove(L, base);  /* remove message handler from the stack */
-  return status;
-}
-
-
-static void print_version (void) {
-  lua_writestring(LUA_COPYRIGHT, strlen(LUA_COPYRIGHT));
-  lua_writeline();
-  lua_writestring("Enhance by LuatOS. call os.exit() for quit", strlen("Enhance by LuatOS. call os.exit() for quit"));
-  lua_writeline();
-}
-
-
-/*
-** Create the 'arg' table, which stores all arguments from the
-** command line ('argv'). It should be aligned so that, at index 0,
-** it has 'argv[script]', which is the script name. The arguments
-** to the script (everything after 'script') go to positive indices;
-** other arguments (before the script name) go to negative indices.
-** If there is no script name, assume interpreter's name as base.
-*/
-static void createargtable (lua_State *L, char **argv, int argc, int script) {
-  int i, narg;
-  if (script == argc) script = 0;  /* no script name? */
-  narg = argc - (script + 1);  /* number of positive indices */
-  lua_createtable(L, narg, script + 1);
-  for (i = 0; i < argc; i++) {
-    lua_pushstring(L, argv[i]);
-    lua_rawseti(L, -2, i - script);
-  }
-  lua_setglobal(L, "arg");
-}
-
-
-static int dochunk (lua_State *L, int status) {
-  if (status == LUA_OK) status = docall(L, 0, 0);
-  return report(L, status);
-}
-
-
-static int dofile (lua_State *L, const char *name) {
-  return dochunk(L, luaL_loadfile(L, name));
-}
-
-
-static int dostring (lua_State *L, const char *s, const char *name) {
-  return dochunk(L, luaL_loadbuffer(L, s, strlen(s), name));
-}
-
-
-/*
-** Calls 'require(name)' and stores the result in a global variable
-** with the given name.
-*/
-static int dolibrary (lua_State *L, const char *name) {
-  int status;
-  lua_getglobal(L, "require");
-  lua_pushstring(L, name);
-  status = docall(L, 1, 1);  /* call 'require(name)' */
-  if (status == LUA_OK)
-    lua_setglobal(L, name);  /* global[name] = require return */
-  return report(L, status);
-}
-
-
-/*
-** Returns the string to be used as a prompt by the interpreter.
-*/
-static const char *get_prompt (lua_State *L, int firstline) {
-  const char *p;
-  lua_getglobal(L, firstline ? "_PROMPT" : "_PROMPT2");
-  p = lua_tostring(L, -1);
-  if (p == NULL) p = (firstline ? LUA_PROMPT : LUA_PROMPT2);
-  return p;
-}
-
-/* mark in error messages for incomplete statements */
-#define EOFMARK		"<eof>"
-#define marklen		(sizeof(EOFMARK)/sizeof(char) - 1)
-
-
-/*
-** Check whether 'status' signals a syntax error and the error
-** message at the top of the stack ends with the above mark for
-** incomplete statements.
-*/
-static int incomplete (lua_State *L, int status) {
-  if (status == LUA_ERRSYNTAX) {
-    size_t lmsg;
-    const char *msg = lua_tolstring(L, -1, &lmsg);
-    if (lmsg >= marklen && strcmp(msg + lmsg - marklen, EOFMARK) == 0) {
-      lua_pop(L, 1);
-      return 1;
-    }
-  }
-  return 0;  /* else... */
-}
-
-
-/*
-** Prompt the user, read a line, and push it into the Lua stack.
-*/
-static int pushline (lua_State *L, int firstline) {
-  char buffer[LUA_MAXINPUT];
-  char *b = buffer;
-  size_t l;
-  const char *prmt = get_prompt(L, firstline);
-  int readstatus = lua_readline(L, b, prmt);
-  if (readstatus == 0)
-    return 0;  /* no input (prompt will be popped by caller) */
-  lua_pop(L, 1);  /* remove prompt */
-  l = strlen(b);
-  if (l > 0 && b[l-1] == '\n')  /* line ends with newline? */
-    b[--l] = '\0';  /* remove it */
-  if (firstline && b[0] == '=')  /* for compatibility with 5.2, ... */
-    lua_pushfstring(L, "return %s", b + 1);  /* change '=' to 'return' */
-  else
-    lua_pushlstring(L, b, l);
-  lua_freeline(L, b);
-  return 1;
-}
-
-
-/*
-** Try to compile line on the stack as 'return <line>;'; on return, stack
-** has either compiled chunk or original line (if compilation failed).
-*/
-static int addreturn (lua_State *L) {
-  const char *line = lua_tostring(L, -1);  /* original line */
-  const char *retline = lua_pushfstring(L, "return %s;", line);
-  int status = luaL_loadbuffer(L, retline, strlen(retline), "=stdin");
-  if (status == LUA_OK) {
-    lua_remove(L, -2);  /* remove modified line */
-    if (line[0] != '\0')  /* non empty? */
-      lua_saveline(L, line);  /* keep history */
-  }
-  else
-    lua_pop(L, 2);  /* pop result from 'luaL_loadbuffer' and modified line */
-  return status;
-}
-
-
-/*
-** Read multiple lines until a complete Lua statement
-*/
-static int multiline (lua_State *L) {
-  for (;;) {  /* repeat until gets a complete statement */
-    size_t len;
-    const char *line = lua_tolstring(L, 1, &len);  /* get what it has */
-    int status = luaL_loadbuffer(L, line, len, "=stdin");  /* try it */
-    if (!incomplete(L, status) || !pushline(L, 0)) {
-      lua_saveline(L, line);  /* keep history */
-      return status;  /* cannot or should not try to add continuation line */
-    }
-    lua_pushliteral(L, "\n");  /* add newline... */
-    lua_insert(L, -2);  /* ...between the two lines */
-    lua_concat(L, 3);  /* join them */
-  }
-}
-
-
-/*
-** Read a line and try to load (compile) it first as an expression (by
-** adding "return " in front of it) and second as a statement. Return
-** the final status of load/call with the resulting function (if any)
-** in the top of the stack.
-*/
-static int loadline (lua_State *L) {
-  int status;
-  lua_settop(L, 0);
-  if (!pushline(L, 1))
-    return -1;  /* no input */
-  if ((status = addreturn(L)) != LUA_OK)  /* 'return ...' did not work? */
-    status = multiline(L);  /* try as command, maybe with continuation lines */
-  lua_remove(L, 1);  /* remove line from the stack */
-  lua_assert(lua_gettop(L) == 1);
-  return status;
-}
-
-
-/*
-** Prints (calling the Lua 'print' function) any values on the stack
-*/
-static void l_print (lua_State *L) {
-  int n = lua_gettop(L);
-  if (n > 0) {  /* any result to be printed? */
-    luaL_checkstack(L, LUA_MINSTACK, "too many results to print");
-    lua_getglobal(L, "print");
-    lua_insert(L, 1);
-    if (lua_pcall(L, n, 0, 0) != LUA_OK)
-      l_message(progname, lua_pushfstring(L, "error calling 'print' (%s)",
-                                             lua_tostring(L, -1)));
-  }
-}
-
-
-/*
-** Do the REPL: repeatedly read (load) a line, evaluate (call) it, and
-** print any results.
-*/
-static void doREPL (lua_State *L) {
-  int status;
-  const char *oldprogname = progname;
-  progname = NULL;  /* no 'progname' on errors in interactive mode */
-  while ((status = loadline(L)) != -1) {
-    if (status == LUA_OK)
-      status = docall(L, 0, LUA_MULTRET);
-    if (status == LUA_OK) l_print(L);
-    else report(L, status);
-  }
-  lua_settop(L, 0);  /* clear stack */
-  lua_writeline();
-  progname = oldprogname;
-}
-
-
-/*
-** Push on the stack the contents of table 'arg' from 1 to #arg
-*/
-static int pushargs (lua_State *L) {
-  int i, n;
-  if (lua_getglobal(L, "arg") != LUA_TTABLE)
-    luaL_error(L, "'arg' is not a table");
-  n = (int)luaL_len(L, -1);
-  luaL_checkstack(L, n + 3, "too many arguments to script");
-  for (i = 1; i <= n; i++)
-    lua_rawgeti(L, -i, i);
-  lua_remove(L, -i);  /* remove table from the stack */
-  return n;
-}
-
-
-static int handle_script (lua_State *L, char **argv) {
-  int status;
-  const char *fname = argv[0];
-  if (strcmp(fname, "-") == 0 && strcmp(argv[-1], "--") != 0)
-    fname = NULL;  /* stdin */
-  status = luaL_loadfile(L, fname);
-  if (status == LUA_OK) {
-    int n = pushargs(L);  /* push arguments to script */
-    status = docall(L, n, LUA_MULTRET);
-  }
-  return report(L, status);
-}
-
-
-
-/* bits of various argument indicators in 'args' */
-#define has_error	1	/* bad option */
-#define has_i		2	/* -i */
-#define has_v		4	/* -v */
-#define has_e		8	/* -e */
-#define has_E		16	/* -E */
-
-/*
-** Traverses all arguments from 'argv', returning a mask with those
-** needed before running any Lua code (or an error code if it finds
-** any invalid argument). 'first' returns the first not-handled argument
-** (either the script name or a bad argument in case of error).
-*/
-static int collectargs (char **argv, int *first) {
-  int args = 0;
-  int i;
-  for (i = 1; argv[i] != NULL; i++) {
-    *first = i;
-    if (argv[i][0] != '-')  /* not an option? */
-        return args;  /* stop handling options */
-    switch (argv[i][1]) {  /* else check option */
-      case '-':  /* '--' */
-        if (argv[i][2] != '\0')  /* extra characters after '--'? */
-          return has_error;  /* invalid option */
-        *first = i + 1;
-        return args;
-      case '\0':  /* '-' */
-        return args;  /* script "name" is '-' */
-      case 'E':
-        if (argv[i][2] != '\0')  /* extra characters after 1st? */
-          return has_error;  /* invalid option */
-        args |= has_E;
-        break;
-      case 'i':
-        args |= has_i;  /* (-i implies -v) *//* FALLTHROUGH */
-      case 'v':
-        if (argv[i][2] != '\0')  /* extra characters after 1st? */
-          return has_error;  /* invalid option */
-        args |= has_v;
-        break;
-      case 'e':
-        args |= has_e;  /* FALLTHROUGH */
-      case 'l':  /* both options need an argument */
-        if (argv[i][2] == '\0') {  /* no concatenated argument? */
-          i++;  /* try next 'argv' */
-          if (argv[i] == NULL || argv[i][0] == '-')
-            return has_error;  /* no next argument or it is another option */
-        }
-        break;
-      default:  /* invalid option */
-        return has_error;
-    }
-  }
-  *first = i;  /* no script name */
-  return args;
-}
-
-
-/*
-** Processes options 'e' and 'l', which involve running Lua code.
-** Returns 0 if some code raises an error.
-*/
-static int runargs (lua_State *L, char **argv, int n) {
-  int i;
-  for (i = 1; i < n; i++) {
-    int option = argv[i][1];
-    lua_assert(argv[i][0] == '-');  /* already checked */
-    if (option == 'e' || option == 'l') {
-      int status;
-      const char *extra = argv[i] + 2;  /* both options need an argument */
-      if (*extra == '\0') extra = argv[++i];
-      lua_assert(extra != NULL);
-      status = (option == 'e')
-               ? dostring(L, extra, "=(command line)")
-               : dolibrary(L, extra);
-      if (status != LUA_OK) return 0;
-    }
-  }
-  return 1;
-}
-
-
-
-static int handle_luainit (lua_State *L) {
-  const char *name = "=" LUA_INITVARVERSION;
-  const char *init = getenv(name + 1);
-  if (init == NULL) {
-    name = "=" LUA_INIT_VAR;
-    init = getenv(name + 1);  /* try alternative name */
-  }
-  if (init == NULL) return LUA_OK;
-  else if (init[0] == '@')
-    return dofile(L, init+1);
-  else
-    return dostring(L, init, name);
-}
-
-
-/*
-** Main body of stand-alone interpreter (to be called in protected mode).
-** Reads the options and handles them all.
-*/
-static int pmain (lua_State *L) {
-  int argc = (int)lua_tointeger(L, 1);
-  char **argv = (char **)lua_touserdata(L, 2);
-  int script;
-  int args = collectargs(argv, &script);
-  luaL_checkversion(L);  /* check that interpreter has correct version */
-  if (argv[0] && argv[0][0]) progname = argv[0];
-  if (args == has_error) {  /* bad arg? */
-    print_usage(argv[script]);  /* 'script' has index of bad arg. */
-    return 0;
-  }
-  if (args & has_v)  /* option '-v'? */
-    print_version();
-  if (args & has_E) {  /* option '-E'? */
-    lua_pushboolean(L, 1);  /* signal for libraries to ignore env. vars. */
-    lua_setfield(L, LUA_REGISTRYINDEX, "LUA_NOENV");
-  }
-  luat_openlibs(L);  /* open standard libraries */
-  createargtable(L, argv, argc, script);  /* create table 'arg' */
-  if (!(args & has_E)) {  /* no option '-E'? */
-    if (handle_luainit(L) != LUA_OK)  /* run LUA_INIT */
-      return 0;  /* error running LUA_INIT */
-  }
-  if (!runargs(L, argv, script))  /* execute arguments -e and -l */
-    return 0;  /* something failed */
-  if (script < argc &&  /* execute main script (if there is one) */
-      handle_script(L, argv + script) != LUA_OK)
-    return 0;
-  if (args & has_i)  /* -i option? */
-    doREPL(L);  /* do read-eval-print loop */
-  else if (script == argc && !(args & (has_e | has_v))) {  /* no arguments? */
-    if (lua_stdin_is_tty()) {  /* running in interactive mode? */
-      print_version();
-      doREPL(L);  /* do read-eval-print loop */
-    }
-    else dofile(L, NULL);  /* executes stdin as a file */
-  }
-  lua_pushboolean(L, 1);  /* signal no errors */
-  return 1;
-}
-
-void* luat_heap_alloc(void *ud, void *ptr, size_t osize, size_t nsize);
-
-int lua_main (int argc, char **argv) {
-  int status, result;
-  lua_State *L = lua_newstate(luat_heap_alloc, NULL);;  /* create state */
-  if (L == NULL) {
-    l_message(argv[0], "cannot create state: not enough memory");
-    return EXIT_FAILURE;
-  }
-  lua_pushcfunction(L, &pmain);  /* to call 'pmain' in protected mode */
-  lua_pushinteger(L, argc);  /* 1st argument */
-  lua_pushlightuserdata(L, argv); /* 2nd argument */
-  status = lua_pcall(L, 2, 1, 0);  /* do the call */
-  result = lua_toboolean(L, -1);  /* get result */
-  report(L, status);
-  lua_close(L);
-  return (result && status == LUA_OK) ? EXIT_SUCCESS : EXIT_FAILURE;
-}

+ 0 - 89
bsp/win32/src/main_win32.c

@@ -1,89 +0,0 @@
-
-#include <stdio.h>
-
-#include "luat_base.h"
-#include "luat_mem.h"
-#include "luat_msgbus.h"
-#include "luat_fs.h"
-
-#include "bget.h"
-
-#include "windows.h"
-#include <io.h>
-
-#define LUAT_LOG_TAG "main"
-#include "luat_log.h"
-
-#define LUAT_HEAP_SIZE (1024*1024)
-uint8_t luavm_heap[LUAT_HEAP_SIZE] = {0};
-
-int cmdline_argc;
-char** cmdline_argv;
-
-int lua_main (int argc, char **argv);
-
-void luat_log_init_win32(void);
-void luat_uart_initial_win32(void);
-
-static void _luat_main(void* args) {
-    //luat_main();
-    luat_fs_init();
-    lua_main(cmdline_argc, cmdline_argv);
-    exit(0);
-}
-
-#ifdef LUAT_USE_LVGL
-
-#include "lvgl.h"
-static int luat_lvg_handler(lua_State* L, void* ptr) {
-    //LLOGD("CALL lv_task_handler");
-    // lv_tick_inc(25);
-    lv_task_handler();
-    return 0;
-}
-
-static void CALLBACK _lvgl_handler(HWND hwnd,       
-    UINT message,     
-    UINT idTimer,     
-    DWORD dwTime) {
-    rtos_msg_t msg = {0};
-    msg.handler = luat_lvg_handler;
-    luat_msgbus_put(&msg, 0);
-}
-#endif
-
-BOOL WINAPI consoleHandler(DWORD signal) {
-    if (signal == CTRL_C_EVENT) {
-        printf("Ctrl-C handled\n"); // do cleanup
-        exit(1);
-    }
-    return TRUE;
-}
-
-// boot
-int main(int argc, char** argv) {
-    cmdline_argc = argc;
-    cmdline_argv = argv;
-    if (cmdline_argc > 1) {
-        size_t len = strlen(cmdline_argv[1]);
-        if (cmdline_argv[1][0] != '-') {
-            if (cmdline_argv[1][len - 1] == '/' || cmdline_argv[1][len - 1] == '\\') {
-                printf("chdir %s %d\n", cmdline_argv[1], chdir(cmdline_argv[1]));
-                cmdline_argc = 1;
-            }
-        }
-    }
-    
-    luat_log_init_win32();
-    luat_uart_initial_win32();
-
-    SetConsoleCtrlHandler(consoleHandler, TRUE);
-    bpool(luavm_heap, LUAT_HEAP_SIZE);
-#ifdef LUAT_USE_LVGL
-    lv_init();
-    SetTimer(NULL, 0, 25, _lvgl_handler);
-#endif
-
-    _luat_main(NULL);
-    return 0;
-}

+ 0 - 21
bsp/win32/tools/luat_uart/.gitignore

@@ -1,21 +0,0 @@
-
-# Created by https://www.toptal.com/developers/gitignore/api/rust
-# Edit at https://www.toptal.com/developers/gitignore?templates=rust
-
-### Rust ###
-# Generated by Cargo
-# will have compiled files and executables
-debug/
-target/
-
-# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
-# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
-Cargo.lock
-
-# These are backup files generated by rustfmt
-**/*.rs.bk
-
-# MSVC Windows builds of rustc generate these, which store debugging information
-*.pdb
-
-# End of https://www.toptal.com/developers/gitignore/api/rust

+ 0 - 26
bsp/win32/tools/luat_uart/Cargo.toml

@@ -1,26 +0,0 @@
-[package]
-name = "luat_uart"
-version = "0.1.0"
-authors = ["chenxuuu <lolicon@papapoi.com>"]
-edition = "2021"
-
-# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
-
-[dependencies]
-serialport = "4"
-lazy_static = "1.4"
-
-
-[lib]
-name = "luat_uart" #生成dll的文件名
-crate-type = ["dylib"]
-
-# ~/.cargo/config
-# [target.x86_64-pc-windows-msvc]
-# rustflags = ["-C", "target-feature=+crt-static"]
-# [target.i686-pc-windows-msvc]
-# rustflags = ["-C", "target-feature=+crt-static"]
-
-#编译x86目标的dll
-#rustup target add i686-pc-windows-msvc
-#cargo build --release --target=i686-pc-windows-msvc

+ 0 - 301
bsp/win32/tools/luat_uart/src/lib.rs

@@ -1,301 +0,0 @@
-use lazy_static::*;
-use std::{os::raw::*, sync::Mutex, thread, collections::HashMap};
-
-pub type RecvCB = unsafe extern fn(c_int,c_int);
-pub type SentCB = unsafe extern fn(c_int,c_int);
-
-lazy_static! {
-    //是不是还开着
-    static ref UART_IS_CLOSED: Mutex<HashMap<i32,bool>> = Mutex::new(HashMap::new());
-    //接收回调
-    static ref UART_RECV_CB: Mutex<HashMap<i32,RecvCB>> = Mutex::new(HashMap::new());
-    //发送回调
-    static ref UART_SENT_CB: Mutex<HashMap<i32,SentCB>> = Mutex::new(HashMap::new());
-    //是否有数据等待发送
-    static ref UART_WAIT_SEND: Mutex<HashMap<i32,bool>> = Mutex::new(HashMap::new());
-    //等待发送的数据是?
-    static ref UART_WAIT_SEND_DATA: Mutex<HashMap<i32,Vec<u8>>> = Mutex::new(HashMap::new());
-    //接收到的数据缓冲区
-    static ref UART_BUFF: Mutex<HashMap<i32,Vec<u8>>> = Mutex::new(HashMap::new());
-}
-
-//检查串口是不是开着(只检查标记)
-fn check_port_is_open(port: i32) -> bool {
-    let map = UART_IS_CLOSED.lock().unwrap();
-    match map.get(&port) {
-        Some(b) if *b => false,
-        _ => true
-    }
-}
-
-//切掉开头的数据
-fn vec_cut(v: &mut Vec<u8>, start: usize) {
-    for i in 0..v.len() - start {
-        v[i] = v[i + start];
-    }
-    v.resize(v.len() - start, 0);
-}
-
-
-// //检测串口存不存在
-// int (*luat_uart_exist_extern)(int id)  = NULL;
-#[no_mangle]
-pub extern fn luat_uart_exist_extern(port: i32) -> i32 {
-    let port = format!("COM{}",port);
-    match serialport::available_ports() {
-        Ok(l) => {
-            if l.iter().any(|i|i.port_name == port) {
-                return 1;
-            }
-        },
-        _ => ()
-    };
-    0
-}
-
-// //获取可用串口列表
-// int (*luat_uart_get_list_extern)(uint8_t* list, size_t buff_len)  = NULL;
-#[no_mangle]
-pub extern fn luat_uart_get_list_extern(list: *mut u8, buff_len: usize) -> i32 {
-    match serialport::available_ports() {
-        Ok(l) => {
-            let len = if l.len() > buff_len {buff_len} else {l.len()};
-            let buff = unsafe{std::slice::from_raw_parts_mut(list, len)};
-            for i in 0..len {
-                buff[i] = l[i].port_name.replace("COM", "").parse().unwrap();
-            }
-            len.try_into().unwrap()
-        },
-        _ => 0
-    }
-}
-
-// //打开串口
-// int (*luat_uart_open_extern)(int id,int br,int db, int sb, int para)  = NULL;
-#[no_mangle]
-pub extern fn luat_uart_open_extern(port: i32, baud_rate: i32, data_bits: i32, stop_bits: i32, parity: i32) -> i32 {
-    let mut uart = match serialport::new(format!("COM{}",port), baud_rate.try_into().unwrap())
-        .timeout(std::time::Duration::from_millis(5))
-        .data_bits(match data_bits {
-            5 => serialport::DataBits::Five,
-            6 => serialport::DataBits::Six,
-            7 => serialport::DataBits::Seven,
-            _ => serialport::DataBits::Eight
-        })
-        .stop_bits(match stop_bits {
-            2 => serialport::StopBits::Two,
-            _ => serialport::StopBits::One
-        })
-        .parity(match parity {
-            1 => serialport::Parity::Odd,
-            2 => serialport::Parity::Even,
-            _ => serialport::Parity::None
-        })
-        .open() {
-            Ok(r) => r,
-            Err(_) => return 1,
-        };
-    uart.write_request_to_send(false).unwrap();//防止之前没退出复位状态
-
-    
-    {
-        //先开个接收缓冲
-        let map = &mut *UART_BUFF.lock().unwrap();
-        map.insert(port, vec![]);
-        //关闭状态肯定不能为真
-        let map = &mut *UART_IS_CLOSED.lock().unwrap();
-        map.remove(&port);
-    }
-
-    //接收线程
-    thread::spawn(move || {
-        loop {
-            let mut serial_buf: Vec<u8> = vec![0; 1024];
-            let len = match uart.read(serial_buf.as_mut_slice()) {
-                Err(e) => {
-                    if e.kind() == std::io::ErrorKind::TimedOut {//接收超时不算错误
-                        0
-                    } else {//串口断了
-                        let map = &mut *UART_IS_CLOSED.lock().unwrap();
-                        map.insert(port, true);
-                        return
-                    }
-                },
-                Ok(r) => r,
-            };
-            //有数据上来
-            if len > 0 {
-                {
-                    let map = &mut *UART_BUFF.lock().unwrap();
-                    //数据读出来
-                    let uart_data = match map.get_mut(&port) {
-                        Some(b) => b,
-                        _ => return//不太可能发生
-                    };
-                    for i in 0..len {
-                        uart_data.push(serial_buf[i]);
-                    }
-                }
-                {
-                    //触发接收回调
-                    let map = &mut *UART_RECV_CB.lock().unwrap();
-                    match map.get(&port) {
-                        Some(b) => {
-                            unsafe{
-                                b(port,len.try_into().unwrap());
-                            }
-                        },
-                        _ => ()
-                    };
-                }
-            }
-            {//串口是不是被关了?
-                let map = &mut *UART_IS_CLOSED.lock().unwrap();
-                match map.get(&port) {
-                    Some(b) if *b => return,//真被关了
-                    _ => ()
-                };
-            }
-            {//是不是有待发送数据?
-                let wait_map = &mut *UART_WAIT_SEND.lock().unwrap();
-                let wait_send = {
-                    match wait_map.get_mut(&port) {
-                        Some(b) if *b => true,//有待发送数据
-                        _ => false
-                    }
-                };
-                if wait_send {
-                    let map = &mut *UART_WAIT_SEND_DATA.lock().unwrap();
-                    if let Some(data) = map.get_mut(&port) {
-                        let r = match uart.write(data.as_slice()) {
-                            Ok(_) => true,
-                            Err(_) => false
-                        };
-                        data.clear();
-                        if !r{//发失败了,说明串口关了
-                            println!("\r\n[waring] win32 uart send data failed, maybe disconnected?\r\n");
-                        }
-                    }
-                    wait_map.remove(&port);
-                }
-            }
-        }
-    });
-    0
-}
-
-
-// //关闭串口
-// int (*luat_uart_close_extern)(int id)  = NULL;
-#[no_mangle]
-pub extern fn luat_uart_close_extern(id: i32) -> i32 {
-    {
-        let map = &mut *UART_IS_CLOSED.lock().unwrap();
-        map.insert(id, true);
-    }
-    {
-        let map = &mut *UART_RECV_CB.lock().unwrap();
-        map.remove(&id);
-    }
-    {
-        let map = &mut *UART_SENT_CB.lock().unwrap();
-        map.remove(&id);
-    }
-    {
-        let map = &mut *UART_WAIT_SEND.lock().unwrap();
-        map.remove(&id);
-    }
-    {
-        let map = &mut *UART_WAIT_SEND_DATA.lock().unwrap();
-        map.remove(&id);
-    }
-    {
-        let map = &mut *UART_BUFF.lock().unwrap();
-        map.remove(&id);
-    }
-    0
-}
-
-
-// //读取数据
-// int (*luat_uart_read_extern)(int id,void* buff, size_t len)  = NULL;
-#[no_mangle]
-pub extern fn luat_uart_read_extern(port: i32, buff: *mut u8, len: usize) -> i32 {
-    //看看串口开没开
-    if !check_port_is_open(port) {
-        return 0;
-    }
-    let map = &mut *UART_BUFF.lock().unwrap();
-    //数据读出来
-    let read_buff = match map.get_mut(&port) {
-        Some(b) => b,
-        _ => return 0
-    };
-
-    //判断下缓冲区有没有那么大,别超了
-    let len = if read_buff.len() >= len {
-        len
-    } else {
-        read_buff.len()
-    };
-    let buff = unsafe{std::slice::from_raw_parts_mut(buff, len)};
-    //把数据扔到buff
-    buff.clone_from_slice(&read_buff[0..len]);
-    //切掉已经读到的数据
-    vec_cut(read_buff, len);
-
-    len.try_into().unwrap()
-}
-
-
-// //发送数据
-// int (*luat_uart_send_extern)(int id,void* buff, size_t len)  = NULL;
-#[no_mangle]
-pub extern fn luat_uart_send_extern(port: i32, buff: *const u8, len: usize) -> i32 {
-    //看看串口开没开
-    if !check_port_is_open(port) {
-        return 0;
-    }
-    let map = &mut *UART_WAIT_SEND_DATA.lock().unwrap();
-    //数据读出来
-    let send_buff = match map.get_mut(&port) {
-        Some(b) => b,
-        _ => {
-            map.insert(port, vec![]);
-            map.get_mut(&port).unwrap()
-        }
-    };
-
-    //数据塞进去
-    let buff = unsafe{std::slice::from_raw_parts(buff, len)};
-    for i in 0..len {
-        send_buff.push(buff[i]);
-    }
-
-    let map = &mut *UART_WAIT_SEND.lock().unwrap();
-    //待发送标记
-    map.insert(port, true);
-
-    len.try_into().unwrap()
-}
-
-// //配置接收回调
-// int (*luat_uart_recv_cb_extern)(int id,void (*)(int id, int len))  = NULL;
-#[no_mangle]
-pub extern fn luat_uart_recv_cb_extern(port: i32, cb: RecvCB) -> i32 {
-    let map = &mut *UART_RECV_CB.lock().unwrap();
-    map.insert(port, cb);
-    0
-}
-
-
-// //配置发送回调
-// int (*luat_uart_sent_cb_extern)(int id,void (*)(int id, int len))  = NULL;
-#[no_mangle]
-pub extern fn luat_uart_sent_cb_extern(_port: i32, _cb: SentCB) -> i32 {
-    // let map = &mut *UART_SENT_CB.lock().unwrap();
-    // map.insert(port, cb);
-    // 1
-    println!("\r\n[waring] win32 uart lib do not support uart sent cb function\r\n");
-    1
-}

+ 0 - 96
bsp/win32/tools/update_inline_sys.lua

@@ -1,96 +0,0 @@
-
-local function lsdir(path, files, shortname)
-    local exe = io.popen("dir /b " .. (shortname and " " or " /s ") .. path)
-    if exe then
-        for line in exe:lines() do
-            table.insert(files, line)
-        end
-        exe:close()
-    end
-end
-
-
-local function oscall(cmd, quite, cwd)
-    if cwd and Base_CWD then
-        lfs.chdir(cwd)
-    end
-    if tool_debug then
-        log.info("cmd", cmd)
-    end
-    local exe = io.popen(cmd)
-    if exe then
-        for line in exe:lines() do
-            if not quite then
-                log.info("cmd", line)
-            end
-        end
-        exe:close()
-    end
-    if cwd and Base_CWD then
-        lfs.chdir(Base_CWD)
-    end
-end
-
-function TLD(buff, T, D)
-    buff:pack("bb", T, D:len())
-    buff:write(D)
-end
-
-local files = {}
-lsdir("lib", files, true)
-oscall("mkdir tmp")
-
-local buff = zbuff.create(256*1024)
--- local magic = string.char(0x5A, 0xA5, 0X5A, 0xA5)
-
--- -- 先写入magic
--- --buff:pack("bbbbbb", 0x01, 0x04, 0XA5, 0x5A, 0xA5, 0x5A)
--- TLD(buff, 0x01, magic)
-
--- -- 然后是版本号
--- --buff:write(string.char(0x02, 0x02, 0x00, 0x02))
--- TLD(buff, 0x02, string.char(0x00, 0x02))
-
--- -- head长度
--- buff:write(string.char(0x03, 0x04))
--- buff:pack("I", 0x12)
-
--- -- 文件数量
--- buff:write(string.char(0x04, 0x02))
--- buff:pack("H", #files)
-
--- -- CRC值
--- buff:write(string.char(0xFE, 0x02))
--- buff:pack("H", 0xFFFF)
-
-for _, value in ipairs(files) do
-    -- TLD(buff, 0x01, magic)
-    -- TLD(buff, 0x02, value .. "c")
-    oscall("..\\air640w\\tools\\luac_536_32bits.exe -s -o tmp\\".. value .. "c lib\\" .. value)
-    -- TLD(buff, 0x03, pack.pack("I", io.fileSize("tmp\\" .. value .. "c")))
-    -- TLD(buff, 0xFE, string.char(0xFF, 0xFF))
-    buff:write(io.readFile("tmp\\" .. value .. "c"))
-end
-
-local data = buff:toStr(0, buff:seek(0, zbuff.SEEK_CUR))
-log.info("target", #data)
-
-local f = io.open("..\\..\\luat\\vfs\\luat_inline_sys.c", "wb")
-if f then
-    f:write([[#include "luat_base.h"]])
-    f:write("\n\nconst uint32_t luat_inline_sys_size = " .. tostring(#data) ..";\n")
-    f:write("const char luat_inline_sys[] = {\n")
-    local index = 0
-    local max = #data
-    while index < max do
-        if index % 8 == 0 then
-            f:write("\n")
-        end
-        f:write(string.format("0x%02X, ", buff[index]))
-        index = index + 1
-    end
-    f:write("};\n")
-    f:close()
-end
-
-os.exit(0)

+ 0 - 95
bsp/win32/tools/update_luadb_inline.lua

@@ -1,95 +0,0 @@
-
-local function lsdir(path, files, shortname)
-    local exe = io.popen("dir /b " .. (shortname and " " or " /s ") .. path)
-    if exe then
-        for line in exe:lines() do
-            table.insert(files, line)
-        end
-        exe:close()
-    end
-end
-
-
-local function oscall(cmd, quite, cwd)
-    if cwd and Base_CWD then
-        lfs.chdir(cwd)
-    end
-    if tool_debug then
-        log.info("cmd", cmd)
-    end
-    local exe = io.popen(cmd)
-    if exe then
-        for line in exe:lines() do
-            if not quite then
-                log.info("cmd", line)
-            end
-        end
-        exe:close()
-    end
-    if cwd and Base_CWD then
-        lfs.chdir(Base_CWD)
-    end
-end
-
-function TLD(buff, T, D)
-    buff:pack("bb", T, D:len())
-    buff:write(D)
-end
-
-local files = {}
-lsdir("lib", files, true)
-oscall("mkdir tmp")
-
-local buff = zbuff.create(256*1024)
-local magic = string.char(0x5A, 0xA5, 0X5A, 0xA5)
-
--- 先写入magic
---buff:pack("bbbbbb", 0x01, 0x04, 0XA5, 0x5A, 0xA5, 0x5A)
-TLD(buff, 0x01, magic)
-
--- 然后是版本号
---buff:write(string.char(0x02, 0x02, 0x00, 0x02))
-TLD(buff, 0x02, string.char(0x00, 0x02))
-
--- head长度
-buff:write(string.char(0x03, 0x04))
-buff:pack("I", 0x12)
-
--- 文件数量
-buff:write(string.char(0x04, 0x02))
-buff:pack("H", #files)
-
--- CRC值
-buff:write(string.char(0xFE, 0x02))
-buff:pack("H", 0xFFFF)
-
-for _, value in ipairs(files) do
-    TLD(buff, 0x01, magic)
-    TLD(buff, 0x02, value .. "c")
-    oscall("..\\air640w\\tools\\luac_536_32bits.exe -s -o tmp\\".. value .. "c lib\\" .. value)
-    TLD(buff, 0x03, pack.pack("I", io.fileSize("tmp\\" .. value .. "c")))
-    TLD(buff, 0xFE, string.char(0xFF, 0xFF))
-    buff:write(io.readFile("tmp\\" .. value .. "c"))
-end
-
-local data = buff:toStr(0, buff:seek(0, zbuff.SEEK_CUR))
-log.info("target", #data)
-
-local f = io.open("..\\..\\luat\\vfs\\luat_luadb_inline.c", "wb")
-if f then
-    f:write([[#include "luat_base.h"]])
-    f:write("\n\nconst char luadb_inline[] = {\n")
-    local index = 0
-    local max = #data
-    while index < max do
-        if index % 8 == 0 then
-            f:write("\n")
-        end
-        f:write(string.format("0x%02X, ", buff[index]))
-        index = index + 1
-    end
-    f:write("};\n")
-    f:close()
-end
-
-os.exit(0)

+ 0 - 137
bsp/win32/xmake.lua

@@ -1,137 +0,0 @@
-set_project("LuatOS-BSP")
-set_xmakever("2.6.3")
-
-set_version("0.0.3", {build = "%Y%m%d%H%M"})
-add_rules("mode.debug", "mode.release")
-
--- 这里用llvm和clang了,尝试一下
-add_requires("llvm 15.0.7")
-set_toolchains("@llvm")
-
-local luatos = "../../"
-
--- set warning all as error
-set_warnings("allextra")
-set_optimize("fastest")
--- set language: c11
-set_languages("c11", "cxx11")
-
-add_defines("__LUATOS__", "__XMAKE_BUILD__", "WIN32")
-add_ldflags("-lwinmm","-luser32","-lncrypt","-lAdvapi32","-lGdi32")
-
-add_requires("libsdl")
-add_packages("libsdl")
-
-target("luatos")
-    -- set kind
-    set_kind("binary")
-    set_targetdir("$(buildir)/out")
-    
-    -- add deps
-
-    add_files("src/*.c",{public = true})
-    add_files("port/*.c",{public = true})
-    add_includedirs("include",{public = true})
-
-    add_includedirs(luatos.."lua/include",{public = true})
-    add_files(luatos.."lua/src/*.c")
-
-    -- weak
-    add_files(luatos.."/luat/weak/luat_malloc_weak.c",
-            luatos.."/luat/weak/luat_mem_weak.c")
-
-    -- printf
-    add_includedirs(luatos.."components/printf",{public = true})
-    add_files(luatos.."components/printf/*.c")
-    
-    add_includedirs(luatos.."luat/include",{public = true})
-    -- add_files(luatos.."luat/modules/*.c")
-
-    add_files(luatos.."luat/modules/crc.c"
-            ,luatos.."luat/modules/luat_base.c"
-            ,luatos.."luat/modules/luat_lib_fs.c"
-            ,luatos.."luat/modules/luat_lib_rtos.c"
-            ,luatos.."luat/modules/luat_lib_timer.c"
-            ,luatos.."luat/modules/luat_lib_log.c"
-            ,luatos.."luat/modules/luat_lib_zbuff.c"
-            ,luatos.."luat/modules/luat_lib_pack.c"
-            ,luatos.."luat/modules/luat_lib_crypto.c"
-            ,luatos.."luat/modules/luat_lib_libcoap.c"
-            ,luatos.."luat/modules/luat_lib_uart.c"
-            ,luatos.."luat/modules/luat_lib_gpio.c"
-            ,luatos.."luat/modules/luat_lib_i2c.c"
-            ,luatos.."luat/modules/luat_lib_spi.c"
-            ,luatos.."luat/modules/luat_irq.c"
-            )
-
-    add_files(luatos.."luat/vfs/*.c")
-    -- lfs
-    add_includedirs(luatos.."components/lfs")
-    add_files(luatos.."components/lfs/*.c")
-
-    add_files(luatos.."components/sfd/*.c")
-    -- lua-cjson
-    add_includedirs(luatos.."components/lua-cjson")
-    add_files(luatos.."components/lua-cjson/*.c")
-    -- miniz
-    add_includedirs(luatos.."components/miniz")
-    add_files(luatos.."components/miniz/*.c")
-
-    -- add_includedirs(luatos.."components/common")
-    -- add_files(luatos.."components/common/*.c")
-
-    -- add_includedirs(luatos.."components/fatfs")
-    -- add_files(luatos.."components/fatfs/*.c")
-
-    -- sdl2
-    add_includedirs(luatos.."components/ui/sdl2")
-    add_files(luatos.."components/ui/sdl2/*.c")
-    -- u8g2
-    add_includedirs(luatos.."components/u8g2")
-    add_files(luatos.."components/u8g2/*.c")
-    -- lcd
-    add_includedirs(luatos.."components/lcd")
-    add_files(luatos.."components/lcd/*.c")
-    -- lvgl
-    add_includedirs(luatos.."components/lvgl")
-    add_includedirs(luatos.."components/lvgl/binding")
-    add_includedirs(luatos.."components/lvgl/gen")
-    add_includedirs(luatos.."components/lvgl/src")
-    add_includedirs(luatos.."components/lvgl/font")
-    add_includedirs(luatos.."components/lvgl/src/lv_font")
-    add_includedirs(luatos.."components/lvgl/sdl2")
-    add_files(luatos.."components/lvgl/**.c")
-    -- 默认不编译lv的demos, 节省大量的编译时间
-    remove_files(luatos.."components/lvgl/lv_demos/**.c")
-    -- -- eink
-    -- add_includedirs(luatos.."components/eink")
-    -- add_includedirs(luatos.."components/epaper")
-    -- add_files(luatos.."components/eink/*.c")
-    -- add_files(luatos.."components/epaper/*.c")
-    -- tjpgd
-    add_files(luatos.."components/tjpgd/*.c")
-    add_includedirs(luatos.."components/tjpgd")
-    -- cjson
-    add_includedirs(luatos.."components/cjson")
-    add_files(luatos.."components/cjson/*.c")
-    -- mbedtls
-    add_files(luatos.."components/mbedtls/library/*.c")
-    add_includedirs(luatos.."components/mbedtls/include")
-    -- iotauth
-    add_includedirs(luatos.."components/iotauth")
-    add_files(luatos.."components/iotauth/*.c")
-    -- qrcode
-    add_includedirs(luatos.."components/qrcode")
-    add_files(luatos.."components/qrcode/*.c")
-    -- crypto
-    add_files(luatos.."components/crypto/**.c")
-    -- protobuf
-    add_includedirs(luatos.."components/serialization/protobuf")
-    add_files(luatos.."components/serialization/protobuf/*.c")
-    -- libgnss
-    add_includedirs(luatos.."components/minmea")
-    add_files(luatos.."components/minmea/*.c")
-    -- rsa
-    add_files(luatos.."components/rsa/**.c")
-    
-target_end()