[simulator] 增加RTC配置项(默认开启)
This commit is contained in:
parent
e43548f46f
commit
569facb12d
|
@ -164,7 +164,9 @@ CONFIG_RT_SERIAL_RB_BUFSZ=64
|
||||||
# CONFIG_RT_USING_MTD_NOR is not set
|
# CONFIG_RT_USING_MTD_NOR is not set
|
||||||
# CONFIG_RT_USING_MTD_NAND is not set
|
# CONFIG_RT_USING_MTD_NAND is not set
|
||||||
# CONFIG_RT_USING_PM is not set
|
# CONFIG_RT_USING_PM is not set
|
||||||
# CONFIG_RT_USING_RTC is not set
|
CONFIG_RT_USING_RTC=y
|
||||||
|
# CONFIG_RT_USING_ALARM is not set
|
||||||
|
# CONFIG_RT_USING_SOFT_RTC is not set
|
||||||
# CONFIG_RT_USING_SDIO is not set
|
# CONFIG_RT_USING_SDIO is not set
|
||||||
# CONFIG_RT_USING_SPI is not set
|
# CONFIG_RT_USING_SPI is not set
|
||||||
# CONFIG_RT_USING_WDT is not set
|
# CONFIG_RT_USING_WDT is not set
|
||||||
|
@ -705,8 +707,10 @@ CONFIG_NETDEV_IPV6=0
|
||||||
CONFIG_SOC_SIMULATOR=y
|
CONFIG_SOC_SIMULATOR=y
|
||||||
|
|
||||||
#
|
#
|
||||||
# Onboard Peripheral Drivers
|
# Peripheral Drivers
|
||||||
#
|
#
|
||||||
CONFIG_RT_USING_DFS_WINSHAREDIR=y
|
CONFIG_RT_USING_DFS_WINSHAREDIR=y
|
||||||
|
CONFIG_BSP_USING_RTC=y
|
||||||
|
# CONFIG_BSP_USING_ALARM is not set
|
||||||
CONFIG_BSP_USING_SOCKET=y
|
CONFIG_BSP_USING_SOCKET=y
|
||||||
# CONFIG_BSP_USING_LVGL is not set
|
# CONFIG_BSP_USING_LVGL is not set
|
||||||
|
|
|
@ -24,13 +24,24 @@ config SOC_SIMULATOR
|
||||||
select RT_USING_USER_MAIN
|
select RT_USING_USER_MAIN
|
||||||
default y
|
default y
|
||||||
|
|
||||||
menu "Onboard Peripheral Drivers"
|
menu "Peripheral Drivers"
|
||||||
|
|
||||||
config RT_USING_DFS_WINSHAREDIR
|
config RT_USING_DFS_WINSHAREDIR
|
||||||
bool "Enable shared file system between Windows"
|
bool "Enable shared file system between Windows"
|
||||||
select RT_USING_POSIX_FS
|
select RT_USING_POSIX_FS
|
||||||
default y
|
default y
|
||||||
|
|
||||||
|
config BSP_USING_RTC
|
||||||
|
bool "Enable RTC"
|
||||||
|
select RT_USING_RTC
|
||||||
|
default y
|
||||||
|
|
||||||
|
config BSP_USING_ALARM
|
||||||
|
bool "Enable RTC alarm"
|
||||||
|
select RT_USING_ALARM
|
||||||
|
depends on BSP_USING_RTC
|
||||||
|
default n
|
||||||
|
|
||||||
config BSP_USING_SOCKET
|
config BSP_USING_SOCKET
|
||||||
bool "Enable BSD Socket"
|
bool "Enable BSD Socket"
|
||||||
select RT_USING_POSIX_FS
|
select RT_USING_POSIX_FS
|
||||||
|
|
|
@ -42,7 +42,7 @@ static int mnt_init(void)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LOG_W("[sd0] File System on SD ('sd0') initialization failed!");
|
LOG_W("[sd0] File System on SD ('sd0') initialization failed!");
|
||||||
LOG_W("[sd0] Try to format and re-mount again...");
|
LOG_W("[sd0] Try to format and re-mount...");
|
||||||
if (dfs_mkfs("elm", "sd0") == 0)
|
if (dfs_mkfs("elm", "sd0") == 0)
|
||||||
{
|
{
|
||||||
if (dfs_mount("sd0", "/sd", "elm", 0, 0) == 0)
|
if (dfs_mount("sd0", "/sd", "elm", 0, 0) == 0)
|
||||||
|
|
|
@ -38,6 +38,8 @@ else:
|
||||||
LIBPATH.append(os.path.abspath(os.path.join(cwd, '../SDL2/lib/x86')))
|
LIBPATH.append(os.path.abspath(os.path.join(cwd, '../SDL2/lib/x86')))
|
||||||
CPPPATH.append(os.path.abspath(os.path.join(cwd, '../SDL2/include')))
|
CPPPATH.append(os.path.abspath(os.path.join(cwd, '../SDL2/include')))
|
||||||
|
|
||||||
|
if GetDepend('BSP_USING_RTC') == False:
|
||||||
|
SrcRemove(src, 'drv_rtc.c')
|
||||||
if GetDepend('RT_USING_DFS') == False or GetDepend('RT_USING_DFS_ELMFAT') == False:
|
if GetDepend('RT_USING_DFS') == False or GetDepend('RT_USING_DFS_ELMFAT') == False:
|
||||||
SrcRemove(src, 'sd_sim.c')
|
SrcRemove(src, 'sd_sim.c')
|
||||||
if GetDepend('RT_USING_DFS') == False or GetDepend('RT_USING_MTD_NAND') == False:
|
if GetDepend('RT_USING_DFS') == False or GetDepend('RT_USING_MTD_NAND') == False:
|
||||||
|
|
|
@ -6,19 +6,15 @@
|
||||||
* Change Logs:
|
* Change Logs:
|
||||||
* Date Author Notes
|
* Date Author Notes
|
||||||
* 2021-04-13 armink the first version
|
* 2021-04-13 armink the first version
|
||||||
|
* 2022-05-17 Meco Man improve and beautify
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <string.h>
|
|
||||||
#include <rtthread.h>
|
|
||||||
#include <rtdevice.h>
|
#include <rtdevice.h>
|
||||||
|
|
||||||
#ifdef RT_USING_RTC
|
|
||||||
|
|
||||||
static struct rt_device rtc_dev;
|
static struct rt_device rtc_dev;
|
||||||
|
|
||||||
#ifdef RT_USING_ALARM
|
#ifdef BSP_USING_ALARM
|
||||||
|
|
||||||
static struct rt_rtc_wkalarm wkalarm;
|
static struct rt_rtc_wkalarm wkalarm;
|
||||||
static struct rt_timer alarm_time;
|
static struct rt_timer alarm_time;
|
||||||
|
|
||||||
|
@ -42,15 +38,15 @@ static void soft_rtc_alarm_update(struct rt_rtc_wkalarm *palarm)
|
||||||
rt_timer_stop(&alarm_time);
|
rt_timer_stop(&alarm_time);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif /* BSP_USING_ALARM */
|
||||||
#endif
|
|
||||||
|
|
||||||
static void get_rtc_timeval(struct timeval *tv)
|
static void get_rtc_timeval(struct timeval *tv)
|
||||||
{
|
{
|
||||||
struct tm newtime = { 0 };
|
struct tm newtime = { 0 };
|
||||||
SYSTEMTIME sys_time;
|
SYSTEMTIME sys_time;
|
||||||
|
|
||||||
GetSystemTime(&sys_time);
|
GetSystemTime(&sys_time); /* get RTC from Windows */
|
||||||
|
|
||||||
newtime.tm_year = sys_time.wYear - 1900;
|
newtime.tm_year = sys_time.wYear - 1900;
|
||||||
newtime.tm_mon = sys_time.wMonth - 1;
|
newtime.tm_mon = sys_time.wMonth - 1;
|
||||||
newtime.tm_mday = sys_time.wDay;
|
newtime.tm_mday = sys_time.wDay;
|
||||||
|
@ -62,9 +58,8 @@ static void get_rtc_timeval(struct timeval *tv)
|
||||||
tv->tv_usec = sys_time.wMilliseconds * 1000UL;
|
tv->tv_usec = sys_time.wMilliseconds * 1000UL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static rt_err_t soft_rtc_control(rt_device_t dev, int cmd, void *args)
|
static rt_err_t windows_rtc_control(rt_device_t dev, int cmd, void *args)
|
||||||
{
|
{
|
||||||
__time32_t *t;
|
|
||||||
struct tm newtime;
|
struct tm newtime;
|
||||||
|
|
||||||
RT_ASSERT(dev != RT_NULL);
|
RT_ASSERT(dev != RT_NULL);
|
||||||
|
@ -83,22 +78,24 @@ static rt_err_t soft_rtc_control(rt_device_t dev, int cmd, void *args)
|
||||||
get_rtc_timeval((struct timeval *) args);
|
get_rtc_timeval((struct timeval *) args);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
#ifdef BSP_USING_ALARM
|
||||||
case RT_DEVICE_CTRL_RTC_SET_TIME:
|
case RT_DEVICE_CTRL_RTC_SET_TIME:
|
||||||
{
|
{
|
||||||
#ifdef RT_USING_ALARM
|
|
||||||
soft_rtc_alarm_update(&wkalarm);
|
soft_rtc_alarm_update(&wkalarm);
|
||||||
#endif
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#ifdef RT_USING_ALARM
|
|
||||||
case RT_DEVICE_CTRL_RTC_GET_ALARM:
|
case RT_DEVICE_CTRL_RTC_GET_ALARM:
|
||||||
|
{
|
||||||
*((struct rt_rtc_wkalarm *)args) = wkalarm;
|
*((struct rt_rtc_wkalarm *)args) = wkalarm;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case RT_DEVICE_CTRL_RTC_SET_ALARM:
|
case RT_DEVICE_CTRL_RTC_SET_ALARM:
|
||||||
|
{
|
||||||
wkalarm = *((struct rt_rtc_wkalarm *)args);
|
wkalarm = *((struct rt_rtc_wkalarm *)args);
|
||||||
soft_rtc_alarm_update(&wkalarm);
|
soft_rtc_alarm_update(&wkalarm);
|
||||||
break;
|
break;
|
||||||
#endif
|
}
|
||||||
|
#endif /* BSP_USING_ALARM */
|
||||||
default:
|
default:
|
||||||
return -RT_ERROR;
|
return -RT_ERROR;
|
||||||
}
|
}
|
||||||
|
@ -114,22 +111,16 @@ const static struct rt_device_ops soft_rtc_ops =
|
||||||
RT_NULL,
|
RT_NULL,
|
||||||
RT_NULL,
|
RT_NULL,
|
||||||
RT_NULL,
|
RT_NULL,
|
||||||
soft_rtc_control
|
windows_rtc_control
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int rt_win_rtc_init(void)
|
int rt_windows_rtc_init(void)
|
||||||
{
|
{
|
||||||
static rt_bool_t init_ok = RT_FALSE;
|
|
||||||
|
|
||||||
if (init_ok)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
/* make sure only one 'rtc' device */
|
/* make sure only one 'rtc' device */
|
||||||
RT_ASSERT(!rt_device_find("rtc"));
|
RT_ASSERT(!rt_device_find("rtc"));
|
||||||
|
|
||||||
#ifdef RT_USING_ALARM
|
#ifdef BSP_USING_ALARM
|
||||||
rt_timer_init(&alarm_time,
|
rt_timer_init(&alarm_time,
|
||||||
"alarm",
|
"alarm",
|
||||||
alarm_timeout,
|
alarm_timeout,
|
||||||
|
@ -149,18 +140,11 @@ int rt_win_rtc_init(void)
|
||||||
rtc_dev.close = RT_NULL;
|
rtc_dev.close = RT_NULL;
|
||||||
rtc_dev.read = RT_NULL;
|
rtc_dev.read = RT_NULL;
|
||||||
rtc_dev.write = RT_NULL;
|
rtc_dev.write = RT_NULL;
|
||||||
rtc_dev.control = soft_rtc_control;
|
rtc_dev.control = windows_rtc_control;
|
||||||
#endif
|
#endif
|
||||||
|
rtc_dev.user_data = RT_NULL; /* no private */
|
||||||
/* no private */
|
|
||||||
rtc_dev.user_data = RT_NULL;
|
|
||||||
|
|
||||||
rt_device_register(&rtc_dev, "rtc", RT_DEVICE_FLAG_RDWR);
|
rt_device_register(&rtc_dev, "rtc", RT_DEVICE_FLAG_RDWR);
|
||||||
|
|
||||||
init_ok = RT_TRUE;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
INIT_BOARD_EXPORT(rt_win_rtc_init);
|
INIT_BOARD_EXPORT(rt_windows_rtc_init);
|
||||||
|
|
||||||
#endif /* RT_USING_RTC */
|
|
||||||
|
|
|
@ -98,6 +98,7 @@
|
||||||
#define RT_USING_SERIAL_V1
|
#define RT_USING_SERIAL_V1
|
||||||
#define RT_SERIAL_USING_DMA
|
#define RT_SERIAL_USING_DMA
|
||||||
#define RT_SERIAL_RB_BUFSZ 64
|
#define RT_SERIAL_RB_BUFSZ 64
|
||||||
|
#define RT_USING_RTC
|
||||||
|
|
||||||
/* Using USB */
|
/* Using USB */
|
||||||
|
|
||||||
|
@ -217,9 +218,10 @@
|
||||||
|
|
||||||
#define SOC_SIMULATOR
|
#define SOC_SIMULATOR
|
||||||
|
|
||||||
/* Onboard Peripheral Drivers */
|
/* Peripheral Drivers */
|
||||||
|
|
||||||
#define RT_USING_DFS_WINSHAREDIR
|
#define RT_USING_DFS_WINSHAREDIR
|
||||||
|
#define BSP_USING_RTC
|
||||||
#define BSP_USING_SOCKET
|
#define BSP_USING_SOCKET
|
||||||
#include "rtconfig_project.h"
|
#include "rtconfig_project.h"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue