Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Mozi
rt-thread
提交
991b6e78
R
rt-thread
项目概览
Mozi
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
0
Star
0
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,发现更多精彩内容 >>
提交
991b6e78
编写于
4月 16, 2022
作者:
mysterywolf
提交者:
guo
4月 19, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[bug] 修正rtc对时间参数范围的处理 | fix a bug of rtc
上级
5e9f525c
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
21 addition
and
26 deletion
+21
-26
bsp/stm32/libraries/HAL_Drivers/drv_rtc.c
bsp/stm32/libraries/HAL_Drivers/drv_rtc.c
+11
-15
components/drivers/rtc/rtc.c
components/drivers/rtc/rtc.c
+10
-11
未找到文件。
bsp/stm32/libraries/HAL_Drivers/drv_rtc.c
浏览文件 @
991b6e78
...
...
@@ -38,7 +38,7 @@ RT_WEAK void HAL_RTCEx_BKUPWrite(RTC_HandleTypeDef *hrtc, uint32_t BackupRegiste
return
;
}
static
void
get_rtc
_timeval
(
struct
timeval
*
tv
)
static
rt_err_t
stm32_rtc_get
_timeval
(
struct
timeval
*
tv
)
{
RTC_TimeTypeDef
RTC_TimeStruct
=
{
0
};
RTC_DateTypeDef
RTC_DateStruct
=
{
0
};
...
...
@@ -59,6 +59,8 @@ static void get_rtc_timeval(struct timeval *tv)
#if defined(SOC_SERIES_STM32H7)
tv
->
tv_usec
=
(
255
.
0
-
RTC_TimeStruct
.
SubSeconds
*
1
.
0
)
/
256
.
0
*
1000
.
0
*
1000
.
0
;
#endif
return
RT_EOK
;
}
static
rt_err_t
set_rtc_time_stamp
(
time_t
time_stamp
)
...
...
@@ -244,36 +246,30 @@ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI1;
return
RT_EOK
;
}
static
rt_err_t
stm32_rtc_get_secs
(
void
*
args
)
static
rt_err_t
stm32_rtc_get_secs
(
time_t
*
sec
)
{
struct
timeval
tv
;
get_rtc_timeval
(
&
tv
);
*
(
rt_uint32_t
*
)
args
=
tv
.
tv_sec
;
LOG_D
(
"RTC: get rtc_time %x"
,
*
(
rt_uint32_t
*
)
args
);
stm32_rtc_get_timeval
(
&
tv
);
*
(
time_t
*
)
sec
=
tv
.
tv_sec
;
LOG_D
(
"RTC: get rtc_time %d"
,
*
sec
);
return
RT_EOK
;
}
static
rt_err_t
stm32_rtc_set_secs
(
void
*
args
)
static
rt_err_t
stm32_rtc_set_secs
(
time_t
*
sec
)
{
rt_err_t
result
=
RT_EOK
;
if
(
set_rtc_time_stamp
(
*
(
rt_uint32_t
*
)
args
))
if
(
set_rtc_time_stamp
(
*
sec
))
{
result
=
-
RT_ERROR
;
}
LOG_D
(
"RTC: set rtc_time %
x"
,
*
(
rt_uint32_t
*
)
args
);
LOG_D
(
"RTC: set rtc_time %
d"
,
*
sec
);
return
result
;
}
static
rt_err_t
stm32_rtc_get_timeval
(
void
*
args
)
{
get_rtc_timeval
((
struct
timeval
*
)
args
);
return
RT_EOK
;
}
static
const
struct
rt_rtc_ops
stm32_rtc_ops
=
{
stm32_rtc_init
,
...
...
components/drivers/rtc/rtc.c
浏览文件 @
991b6e78
...
...
@@ -289,9 +289,9 @@ static void date(int argc, char **argv)
gettimeofday
(
&
tv
,
&
tz
);
now
=
tv
.
tv_sec
;
/* output current time */
rt_kprintf
(
"local: %.*s"
,
25
,
ctime
(
&
now
));
rt_kprintf
(
"
stamp
: %ld
\n
"
,
(
long
)
tv
.
tv_sec
);
rt_kprintf
(
"t
z:
%c%d
\n
"
,
-
tz
.
tz_minuteswest
>
0
?
'+'
:
'-'
,
-
tz
.
tz_minuteswest
/
60
);
rt_kprintf
(
"local
time
: %.*s"
,
25
,
ctime
(
&
now
));
rt_kprintf
(
"
timestamps
: %ld
\n
"
,
(
long
)
tv
.
tv_sec
);
rt_kprintf
(
"t
imezone: UTC
%c%d
\n
"
,
-
tz
.
tz_minuteswest
>
0
?
'+'
:
'-'
,
-
tz
.
tz_minuteswest
/
60
);
}
else
if
(
argc
>=
7
)
{
...
...
@@ -301,17 +301,17 @@ static void date(int argc, char **argv)
rt_err_t
err
;
tm_new
.
tm_year
=
atoi
(
argv
[
1
])
-
1900
;
tm_new
.
tm_mon
=
atoi
(
argv
[
2
])
;
tm_new
.
tm_mon
=
atoi
(
argv
[
2
])
-
1
;
/* .tm_min's range is [0-11] */
tm_new
.
tm_mday
=
atoi
(
argv
[
3
]);
tm_new
.
tm_hour
=
atoi
(
argv
[
4
]);
tm_new
.
tm_min
=
atoi
(
argv
[
5
]);
tm_new
.
tm_sec
=
atoi
(
argv
[
6
]);
if
(
tm_new
.
tm_year
>
199
||
tm_new
.
tm_year
<
10
0
)
if
(
tm_new
.
tm_year
<=
0
)
{
rt_kprintf
(
"year is out of range [
2000-2099
]
\n
"
);
rt_kprintf
(
"year is out of range [
1900-
]
\n
"
);
return
;
}
if
(
tm_new
.
tm_mon
==
0
||
tm_new
.
tm_mon
>
12
)
if
(
tm_new
.
tm_mon
>
11
)
/* .tm_min's range is [0-11] */
{
rt_kprintf
(
"month is out of range [1-12]
\n
"
);
return
;
...
...
@@ -331,9 +331,9 @@ static void date(int argc, char **argv)
rt_kprintf
(
"minute is out of range [0-59]
\n
"
);
return
;
}
if
(
tm_new
.
tm_sec
>
59
)
if
(
tm_new
.
tm_sec
>
60
)
{
rt_kprintf
(
"second is out of range [0-
59
]
\n
"
);
rt_kprintf
(
"second is out of range [0-
60
]
\n
"
);
return
;
}
/* save old timestamp */
...
...
@@ -351,8 +351,7 @@ static void date(int argc, char **argv)
rt_kprintf
(
"set date failed. %d
\n
"
,
err
);
return
;
}
/* get new timestamp */
get_timestamp
(
&
now
);
get_timestamp
(
&
now
);
/* get new timestamp */
rt_kprintf
(
"old: %.*s"
,
25
,
ctime
(
&
old
));
rt_kprintf
(
"now: %.*s"
,
25
,
ctime
(
&
now
));
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录