Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_46254178
rt-thread
提交
6ea9a4b3
R
rt-thread
项目概览
weixin_46254178
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rt-thread
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
6ea9a4b3
编写于
8月 25, 2021
作者:
Dozingfiretruck
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
implement RTC framework V2.0
上级
00373d5e
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
50 addition
and
71 deletion
+50
-71
bsp/at32/Libraries/rt_drivers/drv_rtc.c
bsp/at32/Libraries/rt_drivers/drv_rtc.c
+50
-71
未找到文件。
bsp/at32/Libraries/rt_drivers/drv_rtc.c
浏览文件 @
6ea9a4b3
...
...
@@ -4,12 +4,14 @@
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2020-05-19 shelton first version
* Date Author Notes
* 2020-05-19 shelton first version
* 2021-08-125 Dozingfiretruck implement RTC framework V2.0
*/
#include "board.h"
#include <rtthread.h>
#include <rtdevice.h>
#include <sys/time.h>
#ifdef BSP_USING_RTC
...
...
@@ -24,8 +26,6 @@
#define BKUP_REG_DATA 0xA5A5
static
struct
rt_device
rtc
;
static
time_t
get_rtc_timestamp
(
void
)
{
#ifdef SOC_SERIES_AT32F415
...
...
@@ -93,25 +93,7 @@ static rt_err_t set_rtc_time_stamp(time_t time_stamp)
return
RT_EOK
;
}
static
void
rt_rtc_init
(
void
)
{
#if defined (SOC_SERIES_AT32F415)
RCC_APB1PeriphClockCmd
(
RCC_APB1PERIPH_PWR
,
ENABLE
);
#else
RCC_APB1PeriphClockCmd
(
RCC_APB1PERIPH_PWR
|
RCC_APB1PERIPH_BKP
,
ENABLE
);
#endif
#ifdef BSP_RTC_USING_LSI
RCC_LSICmd
(
ENABLE
);
while
(
RCC_GetFlagStatus
(
RCC_FLAG_LSISTBL
)
==
RESET
);
#else
PWR_BackupAccessCtrl
(
ENABLE
);
RCC_LSEConfig
(
RCC_LSE_ENABLE
);
while
(
RCC_GetFlagStatus
(
RCC_FLAG_LSESTBL
)
==
RESET
);
#endif
/* BSP_RTC_USING_LSI */
}
static
rt_err_t
rt_rtc_config
(
struct
rt_device
*
dev
)
static
rt_err_t
rt_rtc_config
(
void
)
{
#if defined (SOC_SERIES_AT32F415)
ERTC_InitType
ERTC_InitStructure
;
...
...
@@ -166,73 +148,70 @@ static rt_err_t rt_rtc_config(struct rt_device *dev)
return
RT_EOK
;
}
static
rt_err_t
rt_rtc_control
(
rt_device_t
dev
,
int
cmd
,
void
*
args
)
static
rt_err_t
at32_rtc_init
(
void
)
{
#if defined (SOC_SERIES_AT32F415)
RCC_APB1PeriphClockCmd
(
RCC_APB1PERIPH_PWR
,
ENABLE
);
#else
RCC_APB1PeriphClockCmd
(
RCC_APB1PERIPH_PWR
|
RCC_APB1PERIPH_BKP
,
ENABLE
);
#endif
#ifdef BSP_RTC_USING_LSI
RCC_LSICmd
(
ENABLE
);
while
(
RCC_GetFlagStatus
(
RCC_FLAG_LSISTBL
)
==
RESET
);
#else
PWR_BackupAccessCtrl
(
ENABLE
);
RCC_LSEConfig
(
RCC_LSE_ENABLE
);
while
(
RCC_GetFlagStatus
(
RCC_FLAG_LSESTBL
)
==
RESET
);
#endif
/* BSP_RTC_USING_LSI */
if
(
rt_rtc_config
()
!=
RT_EOK
)
{
LOG_E
(
"rtc init failed."
);
return
-
RT_ERROR
;
}
return
RT_EOK
;
}
static
rt_err_t
at32_rtc_get_secs
(
void
*
args
)
{
*
(
rt_uint32_t
*
)
args
=
get_rtc_timestamp
();
LOG_D
(
"RTC: get rtc_time %x
\n
"
,
*
(
rt_uint32_t
*
)
args
);
return
RT_EOK
;
}
static
rt_err_t
at32_rtc_set_secs
(
void
*
args
)
{
rt_err_t
result
=
RT_EOK
;
RT_ASSERT
(
dev
!=
RT_NULL
);
switch
(
cmd
)
if
(
set_rtc_time_stamp
(
*
(
rt_uint32_t
*
)
args
)
)
{
case
RT_DEVICE_CTRL_RTC_GET_TIME
:
*
(
rt_uint32_t
*
)
args
=
get_rtc_timestamp
();
LOG_D
(
"RTC: get rtc_time %x
\n
"
,
*
(
rt_uint32_t
*
)
args
);
break
;
case
RT_DEVICE_CTRL_RTC_SET_TIME
:
if
(
set_rtc_time_stamp
(
*
(
rt_uint32_t
*
)
args
))
{
result
=
-
RT_ERROR
;
}
LOG_D
(
"RTC: set rtc_time %x
\n
"
,
*
(
rt_uint32_t
*
)
args
);
break
;
result
=
-
RT_ERROR
;
}
LOG_D
(
"RTC: set rtc_time %x
\n
"
,
*
(
rt_uint32_t
*
)
args
);
return
result
;
}
#ifdef RT_USING_DEVICE_OPS
const
static
struct
rt_device_ops
rtc_ops
=
static
const
struct
rt_rtc_ops
at32_rtc_ops
=
{
at32_rtc_init
,
at32_rtc_get_secs
,
at32_rtc_set_secs
,
RT_NULL
,
RT_NULL
,
RT_NULL
,
RT_NULL
,
RT_NULL
,
rt_rtc_control
};
#endif
static
rt_err_t
rt_hw_rtc_register
(
rt_device_t
device
,
const
char
*
name
,
rt_uint32_t
flag
)
{
RT_ASSERT
(
device
!=
RT_NULL
);
rt_rtc_init
();
if
(
rt_rtc_config
(
device
)
!=
RT_EOK
)
{
return
-
RT_ERROR
;
}
#ifdef RT_USING_DEVICE_OPS
device
->
ops
=
&
rtc_ops
;
#else
device
->
init
=
RT_NULL
;
device
->
open
=
RT_NULL
;
device
->
close
=
RT_NULL
;
device
->
read
=
RT_NULL
;
device
->
write
=
RT_NULL
;
device
->
control
=
rt_rtc_control
;
#endif
device
->
type
=
RT_Device_Class_RTC
;
device
->
rx_indicate
=
RT_NULL
;
device
->
tx_complete
=
RT_NULL
;
device
->
user_data
=
RT_NULL
;
/* register a character device */
return
rt_device_register
(
device
,
name
,
flag
);
}
static
rt_rtc_dev_t
at32_rtc_dev
;
int
rt_hw_rtc_init
(
void
)
{
rt_err_t
result
;
result
=
rt_hw_rtc_register
(
&
rtc
,
"rtc"
,
RT_DEVICE_FLAG_RDWR
);
at32_rtc_dev
.
ops
=
&
at32_rtc_ops
;
result
=
rt_hw_rtc_register
(
&
at32_rtc_dev
,
"rtc"
,
RT_DEVICE_FLAG_RDWR
,
RT_NULL
);
if
(
result
!=
RT_EOK
)
{
LOG_E
(
"rtc register err code: %d"
,
result
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录