Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
天中雨水
rt-thread
提交
c4f4710b
R
rt-thread
项目概览
天中雨水
/
rt-thread
该项目与 Fork 源项目分叉
Fork自
RT-Thread / rt-thread
通知
2
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rt-thread
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c4f4710b
编写于
2月 16, 2018
作者:
armink_ztl
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[DeviceDriver][RTC] Add software simulation RTC device.
上级
a692cc15
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
111 addition
and
0 deletion
+111
-0
components/drivers/rtc/SConscript
components/drivers/rtc/SConscript
+4
-0
components/drivers/rtc/soft_rtc.c
components/drivers/rtc/soft_rtc.c
+107
-0
未找到文件。
components/drivers/rtc/SConscript
浏览文件 @
c4f4710b
...
...
@@ -7,6 +7,8 @@ rtc = ['rtc.c']
rtc_alarm
=
[
'alarm.c'
]
soft_rtc
=
[
'soft_rtc.c'
]
CPPPATH
=
[
cwd
+
'/../include'
]
group
=
[]
...
...
@@ -14,6 +16,8 @@ if GetDepend(['RT_USING_RTC']):
src
=
src
+
rtc
if
GetDepend
([
'RT_USING_ALARM'
]):
src
=
src
+
rtc_alarm
if
GetDepend
([
'RT_USING_SOFT_RTC'
]):
src
=
src
+
soft_rtc
group
=
DefineGroup
(
'DeviceDrivers'
,
src
,
depend
=
[
'RT_USING_RTC'
],
CPPPATH
=
CPPPATH
)
...
...
components/drivers/rtc/soft_rtc.c
0 → 100644
浏览文件 @
c4f4710b
/*
* File : soft_rtc.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team
*
* 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; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2018-01-30 armink the first version
*/
#include <time.h>
#include <string.h>
#include <rtthread.h>
#include <drivers/rtc.h>
#ifdef RT_USING_SOFT_RTC
/* 2018-01-30 14:44:50 = RTC_TIME_INIT(2018, 1, 30, 14, 44, 50) */
#define RTC_TIME_INIT(year, month, day, hour, minute, second) \
{.tm_year = year - 1900, .tm_mon = month - 1, .tm_mday = day, .tm_hour = hour, .tm_min = minute, .tm_sec = second}
#ifndef SOFT_RTC_TIME_DEFAULT
#define SOFT_RTC_TIME_DEFAULT RTC_TIME_INIT(2018, 1, 1, 0, 0 ,0)
#endif
static
struct
rt_device
soft_rtc_dev
;
static
rt_tick_t
init_tick
;
static
time_t
init_time
;
static
rt_err_t
soft_rtc_control
(
rt_device_t
dev
,
int
cmd
,
void
*
args
)
{
time_t
*
time
;
struct
tm
time_temp
;
RT_ASSERT
(
dev
!=
RT_NULL
);
memset
(
&
time_temp
,
0
,
sizeof
(
struct
tm
));
switch
(
cmd
)
{
case
RT_DEVICE_CTRL_RTC_GET_TIME
:
time
=
(
time_t
*
)
args
;
*
time
=
init_time
+
(
rt_tick_get
()
-
init_tick
)
/
RT_TICK_PER_SECOND
;
break
;
case
RT_DEVICE_CTRL_RTC_SET_TIME
:
{
time
=
(
time_t
*
)
args
;
init_time
=
*
time
-
(
rt_tick_get
()
-
init_tick
)
/
RT_TICK_PER_SECOND
;
break
;
}
}
return
RT_EOK
;
}
int
rt_soft_rtc_init
(
void
)
{
static
rt_bool_t
init_ok
=
RT_FALSE
;
struct
tm
time_new
=
SOFT_RTC_TIME_DEFAULT
;
if
(
init_ok
)
{
return
0
;
}
/* make sure only one 'rtc' device */
RT_ASSERT
(
!
rt_device_find
(
"rtc"
));
init_tick
=
rt_tick_get
();
init_time
=
mktime
(
&
time_new
);
soft_rtc_dev
.
type
=
RT_Device_Class_RTC
;
/* register rtc device */
soft_rtc_dev
.
init
=
RT_NULL
;
soft_rtc_dev
.
open
=
RT_NULL
;
soft_rtc_dev
.
close
=
RT_NULL
;
soft_rtc_dev
.
read
=
RT_NULL
;
soft_rtc_dev
.
write
=
RT_NULL
;
soft_rtc_dev
.
control
=
soft_rtc_control
;
/* no private */
soft_rtc_dev
.
user_data
=
RT_NULL
;
rt_device_register
(
&
soft_rtc_dev
,
"rtc"
,
RT_DEVICE_FLAG_RDWR
);
init_ok
=
RT_TRUE
;
return
0
;
}
INIT_DEVICE_EXPORT
(
rt_soft_rtc_init
);
#endif
/* RT_USING_SOFT_RTC */
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录