summaryrefslogtreecommitdiff
path: root/bsp/simulator/drivers
diff options
context:
space:
mode:
authorMan, Jianting (Meco) <[email protected]>2021-08-17 16:56:10 -0500
committerGitHub <[email protected]>2021-08-17 16:56:10 -0500
commit3e6578916f892e4456d9dff4bbd44590a0cb4bc8 (patch)
treeb98d9fe601ce62e17b37f5b971f0cc9f965fa0e3 /bsp/simulator/drivers
parent37a9231e6219b94f7cde8bdea9251e260c4bed18 (diff)
parent196f340e5d845efd005b57a2089e0642266a79be (diff)
Merge branch 'master' into security
Diffstat (limited to 'bsp/simulator/drivers')
-rw-r--r--bsp/simulator/drivers/SConscript4
-rwxr-xr-xbsp/simulator/drivers/board.c23
-rw-r--r--bsp/simulator/drivers/board.h11
-rw-r--r--bsp/simulator/drivers/dfs_win32.c8
-rw-r--r--bsp/simulator/drivers/drv_rtc.c160
-rw-r--r--bsp/simulator/drivers/module_win32.c160
-rw-r--r--bsp/simulator/drivers/nanddrv_file.c8
-rwxr-xr-xbsp/simulator/drivers/sd_sim.c32
-rwxr-xr-xbsp/simulator/drivers/sdl_fb.c20
-rw-r--r--bsp/simulator/drivers/sst25vfxx_mtd.h8
-rw-r--r--bsp/simulator/drivers/sst25vfxx_mtd_sim.c10
-rw-r--r--bsp/simulator/drivers/tap_netif.c791
-rw-r--r--bsp/simulator/drivers/uart_console.c24
-rw-r--r--bsp/simulator/drivers/uart_console.h9
14 files changed, 331 insertions, 937 deletions
diff --git a/bsp/simulator/drivers/SConscript b/bsp/simulator/drivers/SConscript
index 593a3fdfdc..2fd17ddf80 100644
--- a/bsp/simulator/drivers/SConscript
+++ b/bsp/simulator/drivers/SConscript
@@ -26,10 +26,8 @@ if GetDepend('RT_USING_DFS') == False or GetDepend('RT_USING_DFS_WINSHAREDIR') =
SrcRemove(src, 'dfs_win32.c')
if GetDepend('RT_USING_DFS') == False or GetDepend('RT_USING_MODULE') == False:
SrcRemove(src, ['module_win32.c'])
-if GetDepend('RT_USING_TAPNETIF') == False:
- SrcRemove(src, ['tap_netif.c'])
if sys.platform[0:5]=="linux": #check whether under linux
- SrcRemove(src, ['module_win32.c', 'dfs_win32.c', 'tap_netif.c'])
+ SrcRemove(src, ['module_win32.c', 'dfs_win32.c'])
group = DefineGroup('Drivers', src, depend = [''],
CPPPATH = CPPPATH, LIBS=LIBS, LIBPATH=LIBPATH)
diff --git a/bsp/simulator/drivers/board.c b/bsp/simulator/drivers/board.c
index 2bf10263f2..4facdfa1b2 100755
--- a/bsp/simulator/drivers/board.c
+++ b/bsp/simulator/drivers/board.c
@@ -1,17 +1,12 @@
/*
- * File : board.c
- * This file is part of RT-Thread RTOS
- * COPYRIGHT (C) 2009 RT-Thread Develop Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
+ * SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2009-01-05 Bernard first implementation
*/
-
#include <rthw.h>
#include <rtthread.h>
@@ -23,7 +18,6 @@
/**
* @addtogroup simulator on win32
*/
-rt_uint8_t *heap;
rt_uint8_t *rt_hw_sram_init(void)
{
@@ -38,6 +32,10 @@ rt_uint8_t *rt_hw_sram_init(void)
exit(1);
#endif
}
+#ifdef RT_USING_HEAP
+ /* init memory system */
+ rt_system_heap_init((void*)heap, (void*)&heap[RT_HEAP_SIZE - 1]);
+#endif
return heap;
}
@@ -92,10 +90,10 @@ FINSH_FUNCTION_EXPORT_ALIAS(rt_hw_exit, __cmd_quit, exit rt-thread);
/**
* This function will initial win32
*/
-void rt_hw_board_init()
+int rt_hw_board_init(void)
{
/* init system memory */
- heap = rt_hw_sram_init();
+ rt_hw_sram_init();
uart_console_init();
@@ -106,5 +104,10 @@ void rt_hw_board_init()
#if defined(RT_USING_CONSOLE)
rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
#endif
+ /* init board */
+#ifdef RT_USING_COMPONENTS_INIT
+ rt_components_board_init();
+#endif
+ return 0;
}
/*@}*/
diff --git a/bsp/simulator/drivers/board.h b/bsp/simulator/drivers/board.h
index 7edb856505..7f2e2d2782 100644
--- a/bsp/simulator/drivers/board.h
+++ b/bsp/simulator/drivers/board.h
@@ -1,20 +1,15 @@
/*
- * File : board.h
- * This file is part of RT-Thread RTOS
- * COPYRIGHT (C) 2009, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
+ * SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2009-09-22 Bernard add board.h to this bsp
*/
-
#ifndef __BOARD_H__
#define __BOARD_H__
-void rt_hw_board_init(void);
+int rt_hw_board_init(void);
rt_uint8_t *rt_hw_sram_init(void);
/* SD Card init function */
diff --git a/bsp/simulator/drivers/dfs_win32.c b/bsp/simulator/drivers/dfs_win32.c
index b275751efb..b910c2bf83 100644
--- a/bsp/simulator/drivers/dfs_win32.c
+++ b/bsp/simulator/drivers/dfs_win32.c
@@ -1,11 +1,7 @@
/*
- * File : rtthread.h
- * This file is part of RT-Thread RTOS
- * COPYRIGHT (C) 2006-2012, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE.
+ * SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
diff --git a/bsp/simulator/drivers/drv_rtc.c b/bsp/simulator/drivers/drv_rtc.c
new file mode 100644
index 0000000000..7e19714da2
--- /dev/null
+++ b/bsp/simulator/drivers/drv_rtc.c
@@ -0,0 +1,160 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2021-04-13 armink the first version
+ */
+
+#include <sys/time.h>
+#include <string.h>
+#include <rtthread.h>
+#include <rtdevice.h>
+
+#ifdef RT_USING_RTC
+
+static struct rt_device rtc_dev;
+
+#ifdef RT_USING_ALARM
+
+static struct rt_rtc_wkalarm wkalarm;
+static struct rt_timer alarm_time;
+
+static void alarm_timeout(void *param)
+{
+ rt_alarm_update(param, 1);
+}
+
+static void soft_rtc_alarm_update(struct rt_rtc_wkalarm *palarm)
+{
+ rt_tick_t next_tick;
+
+ if (palarm->enable)
+ {
+ next_tick = RT_TICK_PER_SECOND;
+ rt_timer_control(&alarm_time, RT_TIMER_CTRL_SET_TIME, &next_tick);
+ rt_timer_start(&alarm_time);
+ }
+ else
+ {
+ rt_timer_stop(&alarm_time);
+ }
+}
+
+#endif
+
+static rt_err_t soft_rtc_control(rt_device_t dev, int cmd, void *args)
+{
+ __time32_t *t;
+ struct tm newtime;
+
+ RT_ASSERT(dev != RT_NULL);
+
+ switch (cmd)
+ {
+ case RT_DEVICE_CTRL_RTC_GET_TIME:
+ {
+ t = (__time32_t *)args;
+ SYSTEMTIME sys_time;
+
+ GetSystemTime(&sys_time);
+ newtime.tm_year = sys_time.wYear - 1900;
+ newtime.tm_mon = sys_time.wMonth - 1;
+ newtime.tm_mday = sys_time.wDay;
+ newtime.tm_hour = sys_time.wHour;
+ newtime.tm_min = sys_time.wMinute;
+ newtime.tm_sec = sys_time.wSecond;
+ *t = timegm(&newtime);
+ break;
+ }
+ case RT_DEVICE_CTRL_RTC_SET_TIME:
+ {
+#ifdef RT_USING_ALARM
+ soft_rtc_alarm_update(&wkalarm);
+#endif
+ break;
+ }
+#ifdef RT_USING_ALARM
+ case RT_DEVICE_CTRL_RTC_GET_ALARM:
+ *((struct rt_rtc_wkalarm *)args) = wkalarm;
+ break;
+ case RT_DEVICE_CTRL_RTC_SET_ALARM:
+ wkalarm = *((struct rt_rtc_wkalarm *)args);
+ soft_rtc_alarm_update(&wkalarm);
+ break;
+#endif
+ case RT_DEVICE_CTRL_RTC_GET_TIME_US:
+ {
+ long *tv_usec = (long *)args;
+ SYSTEMTIME sys_time;
+ GetSystemTime(&sys_time);
+ *tv_usec = sys_time.wMilliseconds * 1000UL;
+ break;
+ }
+ default:
+ return -RT_ERROR;
+ }
+
+ return RT_EOK;
+}
+
+#ifdef RT_USING_DEVICE_OPS
+const static struct rt_device_ops soft_rtc_ops =
+{
+ RT_NULL,
+ RT_NULL,
+ RT_NULL,
+ RT_NULL,
+ RT_NULL,
+ soft_rtc_control
+};
+#endif
+
+int rt_win_rtc_init(void)
+{
+ static rt_bool_t init_ok = RT_FALSE;
+
+ if (init_ok)
+ {
+ return 0;
+ }
+ /* make sure only one 'rtc' device */
+ RT_ASSERT(!rt_device_find("rtc"));
+
+#ifdef RT_USING_ALARM
+ rt_timer_init(&alarm_time,
+ "alarm",
+ alarm_timeout,
+ &rtc_dev,
+ 0,
+ RT_TIMER_FLAG_SOFT_TIMER | RT_TIMER_FLAG_ONE_SHOT);
+#endif
+
+ rtc_dev.type = RT_Device_Class_RTC;
+
+ /* register rtc device */
+#ifdef RT_USING_DEVICE_OPS
+ rtc_dev.ops = &soft_rtc_ops;
+#else
+ rtc_dev.init = RT_NULL;
+ rtc_dev.open = RT_NULL;
+ rtc_dev.close = RT_NULL;
+ rtc_dev.read = RT_NULL;
+ rtc_dev.write = RT_NULL;
+ rtc_dev.control = soft_rtc_control;
+#endif
+
+ /* no private */
+ rtc_dev.user_data = RT_NULL;
+
+ rt_device_register(&rtc_dev, "rtc", RT_DEVICE_FLAG_RDWR);
+
+ init_ok = RT_TRUE;
+
+ return 0;
+}
+INIT_BOARD_EXPORT(rt_win_rtc_init);
+
+#endif /* RT_USING_RTC */
diff --git a/bsp/simulator/drivers/module_win32.c b/bsp/simulator/drivers/module_win32.c
index 8fcf3ef2fe..81a98eca87 100644
--- a/bsp/simulator/drivers/module_win32.c
+++ b/bsp/simulator/drivers/module_win32.c
@@ -1,11 +1,7 @@
/*
- * File : module.c
- * This file is part of RT-Thread RTOS
- * COPYRIGHT (C) 2006 - 2013, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
+ * SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
@@ -130,7 +126,7 @@ void rt_module_unload_sethook(void (*hook)(rt_module_t module))
*/
int rt_system_module_init(void)
{
- return 0;
+ return 0;
}
/**
@@ -240,9 +236,9 @@ rt_module_t rt_module_open(const char *path)
struct dfs_filesystem *fs;
appentry_t fptr;
HINSTANCE hinstlib;
- rt_module_t module;
+ rt_module_t module;
- char * winpath = RT_NULL;
+ char * winpath = RT_NULL;
char * name = RT_NULL;
RT_DEBUG_NOT_IN_INTERRUPT;
@@ -353,60 +349,60 @@ FINSH_FUNCTION_EXPORT_ALIAS(rt_module_open, exec, exec module from a file);
#define RT_MODULE_ARG_MAX 8
static int _rt_module_split_arg(char* cmd, rt_size_t length, char* argv[])
{
- int argc = 0;
- char *ptr = cmd;
+ int argc = 0;
+ char *ptr = cmd;
- while ((ptr - cmd) < length)
- {
- /* strip bank and tab */
- while ((*ptr == ' ' || *ptr == '\t') && (ptr -cmd)< length)
- *ptr++ = '\0';
- /* check whether it's the end of line */
- if ((ptr - cmd)>= length) break;
+ while ((ptr - cmd) < length)
+ {
+ /* strip bank and tab */
+ while ((*ptr == ' ' || *ptr == '\t') && (ptr -cmd)< length)
+ *ptr++ = '\0';
+ /* check whether it's the end of line */
+ if ((ptr - cmd)>= length) break;
- /* handle string with quote */
- if (*ptr == '"')
- {
- argv[argc++] = ++ptr;
+ /* handle string with quote */
+ if (*ptr == '"')
+ {
+ argv[argc++] = ++ptr;
- /* skip this string */
- while (*ptr != '"' && (ptr-cmd) < length)
- if (*ptr ++ == '\\') ptr ++;
- if ((ptr - cmd) >= length) break;
+ /* skip this string */
+ while (*ptr != '"' && (ptr-cmd) < length)
+ if (*ptr ++ == '\\') ptr ++;
+ if ((ptr - cmd) >= length) break;
- /* skip '"' */
- *ptr ++ = '\0';
- }
- else
- {
- argv[argc++] = ptr;
- while ((*ptr != ' ' && *ptr != '\t') && (ptr - cmd) < length)
- ptr ++;
- }
+ /* skip '"' */
+ *ptr ++ = '\0';
+ }
+ else
+ {
+ argv[argc++] = ptr;
+ while ((*ptr != ' ' && *ptr != '\t') && (ptr - cmd) < length)
+ ptr ++;
+ }
- if (argc >= RT_MODULE_ARG_MAX) break;
- }
+ if (argc >= RT_MODULE_ARG_MAX) break;
+ }
- return argc;
+ return argc;
}
/* module main thread entry */
static void module_main_entry(void* parameter)
{
- int argc;
- char *argv[RT_MODULE_ARG_MAX];
- typedef int (*main_func_t)(int argc, char** argv);
+ int argc;
+ char *argv[RT_MODULE_ARG_MAX];
+ typedef int (*main_func_t)(int argc, char** argv);
- rt_module_t module = (rt_module_t) parameter;
- if (module == RT_NULL || module->module_cmd_line == RT_NULL) return;
+ rt_module_t module = (rt_module_t) parameter;
+ if (module == RT_NULL || module->module_cmd_line == RT_NULL) return;
- rt_memset(argv, 0x00, sizeof(argv));
- argc = _rt_module_split_arg((char*)module->module_cmd_line, module->module_cmd_size, argv);
- if (argc == 0) return ;
+ rt_memset(argv, 0x00, sizeof(argv));
+ argc = _rt_module_split_arg((char*)module->module_cmd_line, module->module_cmd_size, argv);
+ if (argc == 0) return ;
- /* do the main function */
- ((main_func_t)module->module_entry)(argc, argv);
- return;
+ /* do the main function */
+ ((main_func_t)module->module_entry)(argc, argv);
+ return;
}
/**
@@ -423,25 +419,25 @@ rt_module_t rt_module_exec_cmd(const char *path, const char* cmd_line, int line_
struct dfs_filesystem *fs;
appentry_t fptr;
HINSTANCE hinstlib;
- rt_module_t module;
+ rt_module_t module;
- char * winpath = RT_NULL;
+ char * winpath = RT_NULL;
char * name = RT_NULL;
- char *full_path = RT_NULL;
+ char *full_path = RT_NULL;
RT_DEBUG_NOT_IN_INTERRUPT;
/* check parameters */
RT_ASSERT(path != RT_NULL);
- if (*path != '/')
- {
- full_path = dfs_normalize_path(RT_NULL, path);
- }
- else
- {
- full_path = (const char*)path;
- }
+ if (*path != '/')
+ {
+ full_path = dfs_normalize_path(RT_NULL, path);
+ }
+ else
+ {
+ full_path = (const char*)path;
+ }
/* app module should only in DFS_WIN32 */
fs = dfs_filesystem_lookup(full_path);
@@ -456,14 +452,14 @@ rt_module_t rt_module_exec_cmd(const char *path, const char* cmd_line, int line_
if ((winpath = dfs_win32_dirdup((char *)full_path)) == RT_NULL)
{
rt_kprintf("out of memory, exit", path);
- goto __exit;
+ goto __exit;
}
hinstlib = LoadLibrary(winpath);
if (hinstlib == NULL)
{
rt_kprintf("error: unable to open %s\n", winpath);
- goto __exit;
+ goto __exit;
}
fptr = (appentry_t)GetProcAddress(hinstlib, "main");
@@ -471,21 +467,21 @@ rt_module_t rt_module_exec_cmd(const char *path, const char* cmd_line, int line_
{
rt_kprintf("error: unable to find function in %s\n", winpath);
FreeLibrary(hinstlib);
- goto __exit;
+ goto __exit;
}
- /* release winpath */
- rt_free(winpath);
+ /* release winpath */
+ rt_free(winpath);
/* get the name of the module */
name = _module_name(path);
/* allocate module */
module = (struct rt_module *)rt_object_allocate(RT_Object_Class_Module, name);
- if (!module)
- {
- goto __exit;
- }
+ if (!module)
+ {
+ goto __exit;
+ }
module->nref = 0;
module->module_entry = fptr;
@@ -498,11 +494,11 @@ rt_module_t rt_module_exec_cmd(const char *path, const char* cmd_line, int line_
if (module->module_entry != 0)
{
- /* set module argument */
- module->module_cmd_line = (rt_uint8_t*)rt_malloc(line_size + 1);
- rt_memcpy(module->module_cmd_line, cmd_line, line_size);
- module->module_cmd_line[line_size] = '\0';
- module->module_cmd_size = line_size;
+ /* set module argument */
+ module->module_cmd_line = (rt_uint8_t*)rt_malloc(line_size + 1);
+ rt_memcpy(module->module_cmd_line, cmd_line, line_size);
+ module->module_cmd_line[line_size] = '\0';
+ module->module_cmd_size = line_size;
#ifdef RT_USING_SLAB
/* init module memory allocator */
@@ -514,10 +510,10 @@ rt_module_t rt_module_exec_cmd(const char *path, const char* cmd_line, int line_
module->page_cnt = 0;
#endif
- /* create module thread */
- module->module_thread = rt_thread_create(name,
- module_main_entry, module,
- 2048, RT_THREAD_PRIORITY_MAX - 2, 10);
+ /* create module thread */
+ module->module_thread = rt_thread_create(name,
+ module_main_entry, module,
+ 2048, RT_THREAD_PRIORITY_MAX - 2, 10);
/* set module id */
module->module_thread->module_id = (void *)module;
@@ -543,11 +539,11 @@ rt_module_t rt_module_exec_cmd(const char *path, const char* cmd_line, int line_
return module;
__exit:
- if (full_path != path) rt_free(full_path);
- if (name != RT_NULL) rt_free(full_path);
- if (winpath != RT_NULL)rt_free(winpath);
+ if (full_path != path) rt_free(full_path);
+ if (name != RT_NULL) rt_free(full_path);
+ if (winpath != RT_NULL)rt_free(winpath);
- return RT_NULL;
+ return RT_NULL;
/* FreeLibrary(hinstlib); */
}
diff --git a/bsp/simulator/drivers/nanddrv_file.c b/bsp/simulator/drivers/nanddrv_file.c
index 075ed7f5d8..c47ffdbbe4 100644
--- a/bsp/simulator/drivers/nanddrv_file.c
+++ b/bsp/simulator/drivers/nanddrv_file.c
@@ -1,3 +1,11 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ */
#include <rtdevice.h>
#include <stdio.h>
#include <stdlib.h>
diff --git a/bsp/simulator/drivers/sd_sim.c b/bsp/simulator/drivers/sd_sim.c
index b317e5428d..7557fac12c 100755
--- a/bsp/simulator/drivers/sd_sim.c
+++ b/bsp/simulator/drivers/sd_sim.c
@@ -1,3 +1,11 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
@@ -5,11 +13,9 @@
#include <rtthread.h>
#include <dfs.h>
-#ifdef DEBUG
-# define SD_TRACE rt_kprintf
-#else
-# define SD_TRACE(...)
-#endif
+#define DBG_TAG "sd.sim"
+#define DBG_LVL DBG_INFO
+#include <rtdbg.h>
#define SDCARD_SIM "sd.bin"
#define SDCARD_SIZE (16*1024*1024) //16M
@@ -51,7 +57,7 @@ static rt_size_t rt_sdcard_read(rt_device_t device, rt_off_t position, void *buf
struct sdcard_device *sd;
int result = 0;
- SD_TRACE("sd read: pos %d, size %d\n", position, size);
+ LOG_I("sd read: pos %d, size %d", position, size);
rt_mutex_take(lock, RT_WAITING_FOREVER);
sd = SDCARD_DEVICE(device);
@@ -65,7 +71,7 @@ static rt_size_t rt_sdcard_read(rt_device_t device, rt_off_t position, void *buf
return size;
_err:
- SD_TRACE("sd read errors!\n");
+ LOG_E("sd read errors!");
rt_mutex_release(lock);
return 0;
}
@@ -79,7 +85,7 @@ static rt_size_t rt_sdcard_write(rt_device_t device, rt_off_t position, const vo
struct sdcard_device *sd;
int result = 0;
- SD_TRACE("sst write: pos %d, size %d\n", position, size);
+ LOG_I("sst write: pos %d, size %d", position, size);
rt_mutex_take(lock, RT_WAITING_FOREVER);
sd = SDCARD_DEVICE(device);
@@ -93,7 +99,7 @@ static rt_size_t rt_sdcard_write(rt_device_t device, rt_off_t position, const vo
return size;
_err:
- SD_TRACE("sd write errors!\n");
+ LOG_E("sd write errors!");
rt_mutex_release(lock);
return 0;
}
@@ -125,7 +131,6 @@ static rt_err_t rt_sdcard_control(rt_device_t dev, int cmd, void *args)
return RT_EOK;
}
-
rt_err_t rt_hw_sdcard_init(const char *spi_device_name)
{
int size;
@@ -136,6 +141,11 @@ rt_err_t rt_hw_sdcard_init(const char *spi_device_name)
device = &(sd->parent);
lock = rt_mutex_create("lock", RT_IPC_FLAG_FIFO);
+ if (lock == RT_NULL)
+ {
+ LOG_E("Create mutex in rt_hw_sdcard_init failed!");
+ return -RT_ERROR;
+ }
/* open sd card file, if not exist, then create it */
sd->file = fopen(SDCARD_SIM, "rb+");
@@ -156,7 +166,7 @@ rt_err_t rt_hw_sdcard_init(const char *spi_device_name)
ptr = (unsigned char *) malloc(1024 * 1024);
if (ptr == NULL)
{
- SD_TRACE("malloc error, no memory!\n");
+ LOG_E("malloc error, no memory!");
return RT_ERROR;
}
memset(ptr, 0x0, 1024 * 1024);
diff --git a/bsp/simulator/drivers/sdl_fb.c b/bsp/simulator/drivers/sdl_fb.c
index 98da565a2a..995b12219e 100755
--- a/bsp/simulator/drivers/sdl_fb.c
+++ b/bsp/simulator/drivers/sdl_fb.c
@@ -1,7 +1,13 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ */
#include <rtthread.h>
-
#include <stdio.h>
-
#ifdef _WIN32
#include <sdl.h>
#else
@@ -190,7 +196,7 @@ static void sdlfb_hw_init(void)
SDL_PixelFormatEnumToMasks(SDL_SCREEN_FORMAT, &bpp, &Rmask, &Gmask,
&Bmask, &Amask);
- _device.surface = SDL_CreateRGBSurface(0, SDL_SCREEN_WIDTH, SDL_SCREEN_HEIGHT,
+ _device.surface = SDL_CreateRGBSurface(0, SDL_SCREEN_WIDTH, SDL_SCREEN_HEIGHT,
bpp, Rmask, Gmask, Bmask, Amask);
}
@@ -215,6 +221,10 @@ static void sdlfb_hw_init(void)
rt_device_register(RT_DEVICE(&_device), "sdl", RT_DEVICE_FLAG_RDWR);
sdllock = rt_mutex_create("fb", RT_IPC_FLAG_FIFO);
+ if (sdllock == RT_NULL)
+ {
+ LOG_E("Create mutex for sdlfb failed!");
+ }
}
#ifdef _WIN32
@@ -255,7 +265,7 @@ static void *sdl_loop(void *lpParam)
int motion_tick = 50;
int mouse_id = 1;
-
+
#ifndef _WIN32
sigset_t sigmask, oldmask;
/* set the getchar without buffer */
@@ -455,7 +465,7 @@ static void *sdl_loop(void *lpParam)
exit(1);
break;
}
-
+
}
rt_hw_exit();
return 0;
diff --git a/bsp/simulator/drivers/sst25vfxx_mtd.h b/bsp/simulator/drivers/sst25vfxx_mtd.h
index cb0bb84129..202c6884a3 100644
--- a/bsp/simulator/drivers/sst25vfxx_mtd.h
+++ b/bsp/simulator/drivers/sst25vfxx_mtd.h
@@ -1,11 +1,7 @@
/*
- * File : sst25vfxx_mtd.h
- * This file is part of RT-Thread RTOS
- * COPYRIGHT (C) 2006 - 2011, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
+ * SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
diff --git a/bsp/simulator/drivers/sst25vfxx_mtd_sim.c b/bsp/simulator/drivers/sst25vfxx_mtd_sim.c
index cd8894f612..bc44699a10 100644
--- a/bsp/simulator/drivers/sst25vfxx_mtd_sim.c
+++ b/bsp/simulator/drivers/sst25vfxx_mtd_sim.c
@@ -1,11 +1,7 @@
/*
- * File : rtdef.h
- * This file is part of RT-Thread RTOS
- * COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
+ * SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
@@ -20,7 +16,7 @@
#ifdef RT_USING_MTD_NOR
#define NOR_SIM "nor.bin"
-/* JEDEC Manufacturer��s ID */
+/* JEDEC Manufacturer's ID */
#define MF_ID (0xBF)
/* JEDEC Device ID : Memory Type */
#define MT_ID (0x25)
diff --git a/bsp/simulator/drivers/tap_netif.c b/bsp/simulator/drivers/tap_netif.c
deleted file mode 100644
index a8cd865c5e..0000000000
--- a/bsp/simulator/drivers/tap_netif.c
+++ /dev/null
@@ -1,791 +0,0 @@
-/*
- * TAP-Win32 -- A kernel driver to provide virtual tap device functionality
- * on Windows. Originally derived from the CIPE-Win32
- * project by Damion K. Wilson, with extensive modifications by
- * James Yonan.
- *
- * All source code which derives from the CIPE-Win32 project is
- * Copyright (C) Damion K. Wilson, 2003, and is released under the
- * GPL version 2 (see below).
- *
- * All other source code is Copyright (C) James Yonan, 2003-2004,
- * and is released under the GPL version 2 (see below).
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program (see the file COPYING included with this
- * distribution); if not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <stdio.h>
-#include <windows.h>
-#include <winioctl.h>
-#include <rtthread.h>
-#include <netif/ethernetif.h>
-
-#define MAX_ADDR_LEN 6
-#define TAP_IFNAME "RT-net"
-
-//=============
-// TAP IOCTLs
-//=============
-
-#define TAP_CONTROL_CODE(request,method) \
- CTL_CODE (FILE_DEVICE_UNKNOWN, request, method, FILE_ANY_ACCESS)
-
-#define TAP_IOCTL_GET_MAC TAP_CONTROL_CODE (1, METHOD_BUFFERED)
-#define TAP_IOCTL_GET_VERSION TAP_CONTROL_CODE (2, METHOD_BUFFERED)
-#define TAP_IOCTL_GET_MTU TAP_CONTROL_CODE (3, METHOD_BUFFERED)
-#define TAP_IOCTL_GET_INFO TAP_CONTROL_CODE (4, METHOD_BUFFERED)
-#define TAP_IOCTL_CONFIG_POINT_TO_POINT TAP_CONTROL_CODE (5, METHOD_BUFFERED)
-#define TAP_IOCTL_SET_MEDIA_STATUS TAP_CONTROL_CODE (6, METHOD_BUFFERED)
-#define TAP_IOCTL_CONFIG_DHCP_MASQ TAP_CONTROL_CODE (7, METHOD_BUFFERED)
-#define TAP_IOCTL_GET_LOG_LINE TAP_CONTROL_CODE (8, METHOD_BUFFERED)
-#define TAP_IOCTL_CONFIG_DHCP_SET_OPT TAP_CONTROL_CODE (9, METHOD_BUFFERED)
-
-//=================
-// Registry keys
-//=================
-
-#define ADAPTER_KEY "SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}"
-
-#define NETWORK_CONNECTIONS_KEY "SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}"
-
-//======================
-// Filesystem prefixes
-//======================
-
-#define USERMODEDEVICEDIR "\\\\.\\Global\\"
-#define TAPSUFFIX ".tap"
-
-//======================
-// Compile time configuration
-//======================
-
-//#define DEBUG_TAP_WIN32
-
-#define TUN_ASYNCHRONOUS_WRITES 1
-
-#define TUN_BUFFER_SIZE 1560
-#define TUN_MAX_BUFFER_COUNT 32
-
-/*
- * The data member "buffer" must be the first element in the tun_buffer
- * structure. See the function, tap_win32_free_buffer.
- */
-typedef struct tun_buffer_s {
- unsigned char buffer [TUN_BUFFER_SIZE];
- unsigned long read_size;
- struct tun_buffer_s* next;
-} tun_buffer_t;
-
-typedef struct tap_win32_overlapped {
- HANDLE handle;
- HANDLE read_event;
- HANDLE write_event;
- HANDLE output_queue_semaphore;
- HANDLE free_list_semaphore;
- HANDLE tap_semaphore;
- CRITICAL_SECTION output_queue_cs;
- CRITICAL_SECTION free_list_cs;
- OVERLAPPED read_overlapped;
- OVERLAPPED write_overlapped;
- tun_buffer_t buffers[TUN_MAX_BUFFER_COUNT];
- tun_buffer_t* free_list;
- tun_buffer_t* output_queue_front;
- tun_buffer_t* output_queue_back;
-} tap_win32_overlapped_t;
-
-static tap_win32_overlapped_t tap_overlapped;
-
-/************************************************************************/
-/* RT-Thread Network Interface */
-/************************************************************************/
-struct tap_netif
-{
- /* inherit from ethernet device */
- struct eth_device parent;
-
- tap_win32_overlapped_t *handle;
-
- /* interface address info. */
- rt_uint8_t dev_addr[MAX_ADDR_LEN]; /* hw address */
-};
-#define NETIF_DEVICE(netif) ((struct tap_netif*)(netif))
-#define NETIF_TAP(netif) (NETIF_DEVICE(netif)->handle)
-
-static struct tap_netif tap_netif_device;
-static struct rt_semaphore sem_lock;
-
-static tun_buffer_t* get_buffer_from_free_list(tap_win32_overlapped_t* const overlapped)
-{
- tun_buffer_t* buffer = NULL;
- WaitForSingleObject(overlapped->free_list_semaphore, INFINITE);
- EnterCriticalSection(&overlapped->free_list_cs);
- buffer = overlapped->free_list;
- overlapped->free_list = buffer->next;
- LeaveCriticalSection(&overlapped->free_list_cs);
- buffer->next = NULL;
- return buffer;
-}
-
-static void put_buffer_on_free_list(tap_win32_overlapped_t* const overlapped, tun_buffer_t* const buffer)
-{
- EnterCriticalSection(&overlapped->free_list_cs);
- buffer->next = overlapped->free_list;
- overlapped->free_list = buffer;
- LeaveCriticalSection(&overlapped->free_list_cs);
- ReleaseSemaphore(overlapped->free_list_semaphore, 1, NULL);
-}
-
-static tun_buffer_t* get_buffer_from_output_queue(tap_win32_overlapped_t* const overlapped, const int block)
-{
- tun_buffer_t* buffer = NULL;
- DWORD result, timeout = block ? INFINITE : 0L;
-
- // Non-blocking call
- result = WaitForSingleObject(overlapped->output_queue_semaphore, timeout);
-
- switch (result)
- {
- // The semaphore object was signaled.
- case WAIT_OBJECT_0:
- EnterCriticalSection(&overlapped->output_queue_cs);
-
- buffer = overlapped->output_queue_front;
- overlapped->output_queue_front = buffer->next;
-
- if(overlapped->output_queue_front == NULL) {
- overlapped->output_queue_back = NULL;
- }
-
- LeaveCriticalSection(&overlapped->output_queue_cs);
- break;
-
- // Semaphore was nonsignaled, so a time-out occurred.
- case WAIT_TIMEOUT:
- // Cannot open another window.
- break;
- }
-
- return buffer;
-}
-
-static tun_buffer_t* get_buffer_from_output_queue_immediate (tap_win32_overlapped_t* const overlapped)
-{
- return get_buffer_from_output_queue(overlapped, 0);
-}
-
-static void put_buffer_on_output_queue(tap_win32_overlapped_t* const overlapped, tun_buffer_t* const buffer)
-{
- EnterCriticalSection(&overlapped->output_queue_cs);
-
- if(overlapped->output_queue_front == NULL && overlapped->output_queue_back == NULL) {
- overlapped->output_queue_front = overlapped->output_queue_back = buffer;
- } else {
- buffer->next = NULL;
- overlapped->output_queue_back->next = buffer;
- overlapped->output_queue_back = buffer;
- }
-
- LeaveCriticalSection(&overlapped->output_queue_cs);
-
- ReleaseSemaphore(overlapped->output_queue_semaphore, 1, NULL);
-}
-
-
-static int is_tap_win32_dev(const char *guid)
-{
- HKEY netcard_key;
- LONG status;
- DWORD len;
- int i = 0;
-
- status = RegOpenKeyEx(
- HKEY_LOCAL_MACHINE,
- ADAPTER_KEY,
- 0,
- KEY_READ,
- &netcard_key);
-
- if (status != ERROR_SUCCESS) {
- return FALSE;
- }
-
- for (;;) {
- char enum_name[256];
- char unit_string[256];
- HKEY unit_key;
- char component_id_string[] = "ComponentId";
- char component_id[256];
- char net_cfg_instance_id_string[] = "NetCfgInstanceId";
- char net_cfg_instance_id[256];
- DWORD data_type;
-
- len = sizeof (enum_name);
- status = RegEnumKeyEx(
- netcard_key,
- i,
- enum_name,
- &len,
- NULL,
- NULL,
- NULL,
- NULL);
-
- if (status == ERROR_NO_MORE_ITEMS)
- break;
- else if (status != ERROR_SUCCESS) {
- return FALSE;
- }
-
- rt_snprintf (unit_string, sizeof(unit_string), "%s\\%s",
- ADAPTER_KEY, enum_name);
-
- status = RegOpenKeyEx(
- HKEY_LOCAL_MACHINE,
- unit_string,
- 0,
- KEY_READ,
- &unit_key);
-
- if (status != ERROR_SUCCESS) {
- return FALSE;
- } else {
- len = sizeof (component_id);
- status = RegQueryValueEx(
- unit_key,
- component_id_string,
- NULL,
- &data_type,
- (LPBYTE)component_id,
- &len);
-
- if (!(status != ERROR_SUCCESS || data_type != REG_SZ)) {
- len = sizeof (net_cfg_instance_id);
- status = RegQueryValueEx(
- unit_key,
- net_cfg_instance_id_string,
- NULL,
- &data_type,
- (LPBYTE)net_cfg_instance_id,
- &len);
-
- if (status == ERROR_SUCCESS && data_type == REG_SZ) {
- if (/* !strcmp (component_id, TAP_COMPONENT_ID) &&*/
- !strcmp (net_cfg_instance_id, guid)) {
- RegCloseKey (unit_key);
- RegCloseKey (netcard_key);
- return TRUE;
- }
- }
- }
- RegCloseKey (unit_key);
- }
- ++i;
- }
-
- RegCloseKey (netcard_key);
- return FALSE;
-}
-
-static int get_device_guid(
- char *name,
- int name_size,
- char *actual_name,
- int actual_name_size)
-{
- LONG status;
- HKEY control_net_key;
- DWORD len;
- int i = 0;
- int stop = 0;
-
- status = RegOpenKeyEx(
- HKEY_LOCAL_MACHINE,
- NETWORK_CONNECTIONS_KEY,
- 0,
- KEY_READ,
- &control_net_key);
-
- if (status != ERROR_SUCCESS) {
- return -1;
- }
-
- while (!stop)
- {
- char enum_name[256];
- char connection_string[256];
- HKEY connection_key;
- char name_data[256];
- DWORD name_type;
- const char name_string[] = "Name";
-
- len = sizeof (enum_name);
- status = RegEnumKeyEx(
- control_net_key,
- i,
- enum_name,
- &len,
- NULL,
- NULL,
- NULL,
- NULL);
-
- if (status == ERROR_NO_MORE_ITEMS)
- break;
- else if (status != ERROR_SUCCESS) {
- return -1;
- }
-
- rt_snprintf(connection_string,
- sizeof(connection_string),
- "%s\\%s\\Connection",
- NETWORK_CONNECTIONS_KEY, enum_name);
-
- status = RegOpenKeyEx(
- HKEY_LOCAL_MACHINE,
- connection_string,
- 0,
- KEY_READ,
- &connection_key);
-
- if (status == ERROR_SUCCESS) {
- len = sizeof (name_data);
- status = RegQueryValueEx(
- connection_key,
- name_string,
- NULL,
- &name_type,
- (LPBYTE)name_data,
- &len);
-
- if (status != ERROR_SUCCESS || name_type != REG_SZ) {
- return -1;
- }
- else {
- if (is_tap_win32_dev(enum_name)) {
- rt_snprintf(name, name_size, "%s", enum_name);
- if (actual_name) {
- if (strcmp(actual_name, "") != 0) {
- if (strcmp(name_data, actual_name) != 0) {
- RegCloseKey (connection_key);
- ++i;
- continue;
- }
- }
- else {
- rt_snprintf(actual_name, actual_name_size, "%s", name_data);
- }
- }
- stop = 1;
- }
- }
-
- RegCloseKey (connection_key);
- }
- ++i;
- }
-
- RegCloseKey (control_net_key);
-
- if (stop == 0)
- return -1;
-
- return 0;
-}
-
-static int tap_win32_set_status(HANDLE handle, int status)
-{
- unsigned long len = 0;
-
- return DeviceIoControl(handle, TAP_IOCTL_SET_MEDIA_STATUS,
- &status, sizeof (status),
- &status, sizeof (status), &len, NULL);
-}
-
-static void tap_win32_overlapped_init(tap_win32_overlapped_t* const overlapped, const HANDLE handle)
-{
- overlapped->handle = handle;
-
- overlapped->read_event = CreateEvent(NULL, FALSE, FALSE, NULL);
- overlapped->write_event = CreateEvent(NULL, FALSE, FALSE, NULL);
-
- overlapped->read_overlapped.Offset = 0;
- overlapped->read_overlapped.OffsetHigh = 0;
- overlapped->read_overlapped.hEvent = overlapped->read_event;
-
- overlapped->write_overlapped.Offset = 0;
- overlapped->write_overlapped.OffsetHigh = 0;
- overlapped->write_overlapped.hEvent = overlapped->write_event;
-
- InitializeCriticalSection(&overlapped->output_queue_cs);
- InitializeCriticalSection(&overlapped->free_list_cs);
-
- overlapped->output_queue_semaphore = CreateSemaphore(
- NULL, // default security attributes
- 0, // initial count
- TUN_MAX_BUFFER_COUNT, // maximum count
- NULL); // unnamed semaphore
-
- if(!overlapped->output_queue_semaphore) {
- fprintf(stderr, "error creating output queue semaphore!\n");
- }
-
- overlapped->free_list_semaphore = CreateSemaphore(
- NULL, // default security attributes
- TUN_MAX_BUFFER_COUNT, // initial count
- TUN_MAX_BUFFER_COUNT, // maximum count
- NULL); // unnamed semaphore
-
- if(!overlapped->free_list_semaphore) {
- fprintf(stderr, "error creating free list semaphore!\n");
- }
-
- overlapped->free_list = overlapped->output_queue_front = overlapped->output_queue_back = NULL;
-
- {
- unsigned index;
- for(index = 0; index < TUN_MAX_BUFFER_COUNT; index++) {
- tun_buffer_t* element = &overlapped->buffers[index];
- element->next = overlapped->free_list;
- overlapped->free_list = element;
- }
- }
- /* To count buffers, initially no-signal. */
- overlapped->tap_semaphore = CreateSemaphore(NULL, 0, TUN_MAX_BUFFER_COUNT, NULL);
- if(!overlapped->tap_semaphore)
- fprintf(stderr, "error creating tap_semaphore.\n");
-}
-
-static int tap_win32_write(tap_win32_overlapped_t *overlapped,
- const void *buffer, unsigned long size)
-{
- unsigned long write_size;
- BOOL result;
- DWORD error;
-
- result = GetOverlappedResult( overlapped->handle, &overlapped->write_overlapped,
- &write_size, FALSE);
-
- if (!result && GetLastError() == ERROR_IO_INCOMPLETE)
- WaitForSingleObject(overlapped->write_event, INFINITE);
-
- result = WriteFile(overlapped->handle, buffer, size,
- &write_size, &overlapped->write_overlapped);
-
- if (!result) {
- switch (error = GetLastError())
- {
- case ERROR_IO_PENDING:
-#ifndef TUN_ASYNCHRONOUS_WRITES
- WaitForSingleObject(overlapped->write_event, INFINITE);
-#endif
- break;
- default:
- return -1;
- }
- }
-
- return write_size;
-}
-
-static void tap_win32_thread_entry(void* param)
-{
- tap_win32_overlapped_t *overlapped;
- unsigned long read_size;
- BOOL result;
- DWORD dwError;
- tun_buffer_t* buffer;
- struct eth_device* eth;
-
- eth = (struct eth_device*) &tap_netif_device;
- overlapped = NETIF_TAP(&tap_netif_device);
- buffer = get_buffer_from_free_list(overlapped);
-
- for (;;) {
- result = ReadFile(overlapped->handle,
- buffer->buffer,
- sizeof(buffer->buffer),
- &read_size,
- &overlapped->read_overlapped);
- if (!result) {
- dwError = GetLastError();
- if (dwError == ERROR_IO_PENDING) {
- WaitForSingleObject(overlapped->read_event, INFINITE);
- result = GetOverlappedResult( overlapped->handle, &overlapped->read_overlapped,
- &read_size, FALSE);
- if (!result) {
-#ifdef DEBUG_TAP_WIN32
- LPVOID lpBuffer;
- dwError = GetLastError();
- FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
- NULL, dwError, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
- (LPTSTR) & lpBuffer, 0, NULL );
- fprintf(stderr, "Tap-Win32: Error GetOverlappedResult %d - %s\n", dwError, lpBuffer);
- LocalFree( lpBuffer );
-#endif
- }
- } else {
-#ifdef DEBUG_TAP_WIN32
- LPVOID lpBuffer;
- FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
- NULL, dwError, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
- (LPTSTR) & lpBuffer, 0, NULL );
- fprintf(stderr, "Tap-Win32: Error ReadFile %d - %s\n", dwError, lpBuffer);
- LocalFree( lpBuffer );
-#endif
- }
- }
-
- if(read_size > 0) {
- // rt_kprintf("rx packet, length=%d\n", read_size);
-
- buffer->read_size = read_size;
- put_buffer_on_output_queue(overlapped, buffer);
-
- /* notify eth rx thread to receive packet */
- eth_device_ready(eth);
-
- buffer = get_buffer_from_free_list(overlapped);
- }
- }
-}
-
-static int tap_win32_read(tap_win32_overlapped_t *overlapped,
- rt_uint8_t **pbuf, int max_size)
-{
- int size = 0;
-
- tun_buffer_t* buffer = get_buffer_from_output_queue_immediate(overlapped);
-
- if(buffer != NULL) {
- *pbuf = buffer->buffer;
- size = (int)buffer->read_size;
- if(size > max_size) {
- size = max_size;
- }
- }
-
- return size;
-}
-
-static void tap_win32_free_buffer(tap_win32_overlapped_t *overlapped,
- rt_uint8_t *pbuf)
-{
- tun_buffer_t* buffer = (tun_buffer_t*)pbuf;
- put_buffer_on_free_list(overlapped, buffer);
-}
-
-static int tap_win32_open(tap_win32_overlapped_t **phandle,
- const char *preferred_name)
-{
- char device_path[256];
- char device_guid[0x100];
- int rc;
- HANDLE handle;
- BOOL bret;
- char name_buffer[0x100] = {0, };
- struct {
- unsigned long major;
- unsigned long minor;
- unsigned long debug;
- } version;
- DWORD version_len;
-
- if (preferred_name != NULL) {
- rt_snprintf(name_buffer, sizeof(name_buffer), "%s", preferred_name);
- }
-
- rc = get_device_guid(device_guid, sizeof(device_guid), name_buffer, sizeof(name_buffer));
- if (rc)
- return -1;
-
- rt_snprintf (device_path, sizeof(device_path), "%s%s%s",
- USERMODEDEVICEDIR,
- device_guid,
- TAPSUFFIX);
-
- handle = CreateFile (
- device_path,
- GENERIC_READ | GENERIC_WRITE,
- 0,
- 0,
- OPEN_EXISTING,
- FILE_ATTRIBUTE_SYSTEM | FILE_FLAG_OVERLAPPED,
- 0 );
-
- if (handle == INVALID_HANDLE_VALUE) {
- return -1;
- }
-
- bret = DeviceIoControl(handle, TAP_IOCTL_GET_VERSION,
- &version, sizeof (version),
- &version, sizeof (version), &version_len, NULL);
-
- if (bret == FALSE) {
- CloseHandle(handle);
- return -1;
- }
-
- if (!tap_win32_set_status(handle, TRUE)) {
- return -1;
- }
-
- tap_win32_overlapped_init(&tap_overlapped, handle);
-
- *phandle = &tap_overlapped;
- return 0;
-}
-
-static rt_err_t tap_netif_init(rt_device_t dev)
-{
- rt_thread_t tid;
- tap_win32_overlapped_t *handle;
-
- if (tap_win32_open(&handle, TAP_IFNAME) < 0) {
- printf("tap: Could not open '%s'\n", TAP_IFNAME);
- return -RT_ERROR;
- }
-
- tap_netif_device.handle = handle;
-
- /* create recv thread */
- tid = rt_thread_create("tap", tap_win32_thread_entry, RT_NULL,
- 2048, RT_THREAD_PRIORITY_MAX - 1, 10);
- if (tid != RT_NULL)
- {
- rt_thread_startup(tid);
- }
-
- rt_thread_sleep(RT_TICK_PER_SECOND);
-
- return RT_EOK;
-}
-
-static rt_err_t tap_netif_open(rt_device_t dev, rt_uint16_t oflag)
-{
- return RT_EOK;
-}
-
-static rt_err_t tap_netif_close(rt_device_t dev)
-{
- return RT_EOK;
-}
-
-static rt_size_t tap_netif_read(rt_device_t dev, rt_off_t pos, void* buffer, rt_size_t size)
-{
- rt_set_errno(-RT_ENOSYS);
- return 0;
-}
-
-static rt_size_t tap_netif_write (rt_device_t dev, rt_off_t pos, const void* buffer, rt_size_t size)
-{
- rt_set_errno(-RT_ENOSYS);
- return 0;
-}
-
-static rt_err_t tap_netif_control(rt_device_t dev, int cmd, void *args)
-{
- switch (cmd)
- {
- case NIOCTL_GADDR:
- /* get mac address */
- if (args) rt_memcpy(args, tap_netif_device.dev_addr, 6);
- else return -RT_ERROR;
- break;
-
- default :
- break;
- }
-
- return RT_EOK;
-}
-
-rt_err_t tap_netif_tx( rt_device_t dev, struct pbuf* p)
-{
- struct pbuf *q;
- char buffer[2048];
- int length;
- tap_win32_overlapped_t *handle;
- unsigned char* ptr;
-
- handle = NETIF_TAP(dev);
-
- /* lock EMAC device */
- rt_sem_take(&sem_lock, RT_WAITING_FOREVER);
-
- /* copy data to tx buffer */
- q = p;
- ptr = (rt_uint8_t*)buffer;
- while (q)
- {
- memcpy(ptr, q->payload, q->len);
- ptr += q->len;
- q = q->next;
- }
- length = p->tot_len;
-
- tap_win32_write(handle, buffer, length);
-
- /* unlock EMAC device */
- rt_sem_release(&sem_lock);
-
- return RT_EOK;
-}
-
-struct pbuf *tap_netif_rx(rt_device_t dev)
-{
- struct pbuf* p = RT_NULL;
- tap_win32_overlapped_t *handle;
- rt_uint8_t *buf;
- int max_size = 4096;
- int size;
-
- handle = NETIF_TAP(dev);
-
- size = tap_win32_read(handle, &buf, max_size);
- if (size > 0) {
- p = pbuf_alloc(PBUF_LINK, size, PBUF_RAM);
- pbuf_take(p, buf, size);
-
- tap_win32_free_buffer(handle, buf);
- }
-
- return p;
-}
-
-void tap_netif_hw_init(void)
-{
- rt_sem_init(&sem_lock, "eth_lock", 1, RT_IPC_FLAG_FIFO);
-
- tap_netif_device.dev_addr[0] = 0x00;
- tap_netif_device.dev_addr[1] = 0x60;
- tap_netif_device.dev_addr[2] = 0x37;
- /* set mac address: (only for test) */
- tap_netif_device.dev_addr[3] = 0x12;
- tap_netif_device.dev_addr[4] = 0x34;
- tap_netif_device.dev_addr[5] = 0x56;
-
- tap_netif_device.parent.parent.init = tap_netif_init;
- tap_netif_device.parent.parent.open = tap_netif_open;
- tap_netif_device.parent.parent.close = tap_netif_close;
- tap_netif_device.parent.parent.read = tap_netif_read;
- tap_netif_device.parent.parent.write = tap_netif_write;
- tap_netif_device.parent.parent.control = tap_netif_control;
- tap_netif_device.parent.parent.user_data= RT_NULL;
-
- tap_netif_device.parent.eth_rx = tap_netif_rx;
- tap_netif_device.parent.eth_tx = tap_netif_tx;
-
- eth_device_init(&(tap_netif_device.parent), "e0");
-}
diff --git a/bsp/simulator/drivers/uart_console.c b/bsp/simulator/drivers/uart_console.c
index 913daf2311..8fd799b297 100644
--- a/bsp/simulator/drivers/uart_console.c
+++ b/bsp/simulator/drivers/uart_console.c
@@ -1,5 +1,13 @@
-#include <stdio.h>
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ */
+#include <stdio.h>
#include <rthw.h>
#include <rtdevice.h>
#include <rtthread.h>
@@ -88,11 +96,11 @@ static struct termios oldt, newt;
/*simulate windows' getch(), it works!!*/
static void set_stty(void)
{
- /* get terminal input's attribute */
+ /* get terminal input's attribute */
tcgetattr(STDIN_FILENO, &oldt);
newt = oldt;
- /* set termios' local mode */
+ /* set termios' local mode */
newt.c_lflag &= ~(ECHO|ICANON);
tcsetattr(STDIN_FILENO, TCSANOW, &newt);
}
@@ -117,10 +125,10 @@ static void * ThreadforKeyGet(void * lpParam)
#ifndef _WIN32
sigset_t sigmask, oldmask;
- /* set the getchar without buffer */
- sigfillset(&sigmask);
- pthread_sigmask(SIG_BLOCK, &sigmask, &oldmask);
- set_stty();
+ /* set the getchar without buffer */
+ sigfillset(&sigmask);
+ pthread_sigmask(SIG_BLOCK, &sigmask, &oldmask);
+ set_stty();
#endif
(void)lpParam; //prevent compiler warnings
@@ -217,7 +225,7 @@ static int console_putc(struct rt_serial_device *serial, char c)
level = rt_hw_interrupt_disable();
fwrite(&c, 1, 1, stdout);
- fflush(stdout);
+ fflush(stdout);
rt_hw_interrupt_enable(level);
return 1;
}
diff --git a/bsp/simulator/drivers/uart_console.h b/bsp/simulator/drivers/uart_console.h
index 149a7a21f8..8ea20cc2f4 100644
--- a/bsp/simulator/drivers/uart_console.h
+++ b/bsp/simulator/drivers/uart_console.h
@@ -1,3 +1,12 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ */
+
#ifndef UART_CONSOLE_H__
#define UART_CONSOLE_H__