Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Xiaobo07
rt-thread
提交
991b6e78
R
rt-thread
项目概览
Xiaobo07
/
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,发现更多精彩内容 >>
提交
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
...
@@ -38,7 +38,7 @@ RT_WEAK void HAL_RTCEx_BKUPWrite(RTC_HandleTypeDef *hrtc, uint32_t BackupRegiste
return
;
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_TimeTypeDef
RTC_TimeStruct
=
{
0
};
RTC_DateTypeDef
RTC_DateStruct
=
{
0
};
RTC_DateTypeDef
RTC_DateStruct
=
{
0
};
...
@@ -59,6 +59,8 @@ static void get_rtc_timeval(struct timeval *tv)
...
@@ -59,6 +59,8 @@ static void get_rtc_timeval(struct timeval *tv)
#if defined(SOC_SERIES_STM32H7)
#if defined(SOC_SERIES_STM32H7)
tv
->
tv_usec
=
(
255
.
0
-
RTC_TimeStruct
.
SubSeconds
*
1
.
0
)
/
256
.
0
*
1000
.
0
*
1000
.
0
;
tv
->
tv_usec
=
(
255
.
0
-
RTC_TimeStruct
.
SubSeconds
*
1
.
0
)
/
256
.
0
*
1000
.
0
*
1000
.
0
;
#endif
#endif
return
RT_EOK
;
}
}
static
rt_err_t
set_rtc_time_stamp
(
time_t
time_stamp
)
static
rt_err_t
set_rtc_time_stamp
(
time_t
time_stamp
)
...
@@ -244,36 +246,30 @@ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI1;
...
@@ -244,36 +246,30 @@ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI1;
return
RT_EOK
;
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
;
struct
timeval
tv
;
get_rtc_timeval
(
&
tv
);
*
(
rt_uint32_t
*
)
args
=
tv
.
tv_sec
;
stm32_rtc_get_timeval
(
&
tv
);
LOG_D
(
"RTC: get rtc_time %x"
,
*
(
rt_uint32_t
*
)
args
);
*
(
time_t
*
)
sec
=
tv
.
tv_sec
;
LOG_D
(
"RTC: get rtc_time %d"
,
*
sec
);
return
RT_EOK
;
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
;
rt_err_t
result
=
RT_EOK
;
if
(
set_rtc_time_stamp
(
*
(
rt_uint32_t
*
)
args
))
if
(
set_rtc_time_stamp
(
*
sec
))
{
{
result
=
-
RT_ERROR
;
result
=
-
RT_ERROR
;
}
}
LOG_D
(
"RTC: set rtc_time %
x"
,
*
(
rt_uint32_t
*
)
args
);
LOG_D
(
"RTC: set rtc_time %
d"
,
*
sec
);
return
result
;
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
=
static
const
struct
rt_rtc_ops
stm32_rtc_ops
=
{
{
stm32_rtc_init
,
stm32_rtc_init
,
...
...
components/drivers/rtc/rtc.c
浏览文件 @
991b6e78
...
@@ -289,9 +289,9 @@ static void date(int argc, char **argv)
...
@@ -289,9 +289,9 @@ static void date(int argc, char **argv)
gettimeofday
(
&
tv
,
&
tz
);
gettimeofday
(
&
tv
,
&
tz
);
now
=
tv
.
tv_sec
;
now
=
tv
.
tv_sec
;
/* output current time */
/* output current time */
rt_kprintf
(
"local: %.*s"
,
25
,
ctime
(
&
now
));
rt_kprintf
(
"local
time
: %.*s"
,
25
,
ctime
(
&
now
));
rt_kprintf
(
"
stamp
: %ld
\n
"
,
(
long
)
tv
.
tv_sec
);
rt_kprintf
(
"
timestamps
: %ld
\n
"
,
(
long
)
tv
.
tv_sec
);
rt_kprintf
(
"t
z:
%c%d
\n
"
,
-
tz
.
tz_minuteswest
>
0
?
'+'
:
'-'
,
-
tz
.
tz_minuteswest
/
60
);
rt_kprintf
(
"t
imezone: UTC
%c%d
\n
"
,
-
tz
.
tz_minuteswest
>
0
?
'+'
:
'-'
,
-
tz
.
tz_minuteswest
/
60
);
}
}
else
if
(
argc
>=
7
)
else
if
(
argc
>=
7
)
{
{
...
@@ -301,17 +301,17 @@ static void date(int argc, char **argv)
...
@@ -301,17 +301,17 @@ static void date(int argc, char **argv)
rt_err_t
err
;
rt_err_t
err
;
tm_new
.
tm_year
=
atoi
(
argv
[
1
])
-
1900
;
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_mday
=
atoi
(
argv
[
3
]);
tm_new
.
tm_hour
=
atoi
(
argv
[
4
]);
tm_new
.
tm_hour
=
atoi
(
argv
[
4
]);
tm_new
.
tm_min
=
atoi
(
argv
[
5
]);
tm_new
.
tm_min
=
atoi
(
argv
[
5
]);
tm_new
.
tm_sec
=
atoi
(
argv
[
6
]);
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
;
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
"
);
rt_kprintf
(
"month is out of range [1-12]
\n
"
);
return
;
return
;
...
@@ -331,9 +331,9 @@ static void date(int argc, char **argv)
...
@@ -331,9 +331,9 @@ static void date(int argc, char **argv)
rt_kprintf
(
"minute is out of range [0-59]
\n
"
);
rt_kprintf
(
"minute is out of range [0-59]
\n
"
);
return
;
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
;
return
;
}
}
/* save old timestamp */
/* save old timestamp */
...
@@ -351,8 +351,7 @@ static void date(int argc, char **argv)
...
@@ -351,8 +351,7 @@ static void date(int argc, char **argv)
rt_kprintf
(
"set date failed. %d
\n
"
,
err
);
rt_kprintf
(
"set date failed. %d
\n
"
,
err
);
return
;
return
;
}
}
/* get new timestamp */
get_timestamp
(
&
now
);
/* get new timestamp */
get_timestamp
(
&
now
);
rt_kprintf
(
"old: %.*s"
,
25
,
ctime
(
&
old
));
rt_kprintf
(
"old: %.*s"
,
25
,
ctime
(
&
old
));
rt_kprintf
(
"now: %.*s"
,
25
,
ctime
(
&
now
));
rt_kprintf
(
"now: %.*s"
,
25
,
ctime
(
&
now
));
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录