Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2301_76519099
rt-thread
提交
fe556e63
R
rt-thread
项目概览
2301_76519099
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
3
Star
1
Fork
1
代码
文件
提交
分支
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,发现更多精彩内容 >>
未验证
提交
fe556e63
编写于
7月 12, 2019
作者:
B
Bernard Xiong
提交者:
GitHub
7月 12, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2847 from balanceTWK/master_wdt
[bsp][stm32] update drv_wdt.c
上级
34fa16cb
7cca8087
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
39 addition
and
25 deletion
+39
-25
bsp/stm32/libraries/HAL_Drivers/drv_wdt.c
bsp/stm32/libraries/HAL_Drivers/drv_wdt.c
+39
-25
未找到文件。
bsp/stm32/libraries/HAL_Drivers/drv_wdt.c
浏览文件 @
fe556e63
...
@@ -16,25 +16,17 @@
...
@@ -16,25 +16,17 @@
#define LOG_TAG "drv.wdt"
#define LOG_TAG "drv.wdt"
#include <drv_log.h>
#include <drv_log.h>
static
IWDG_HandleTypeDef
hiwdg
;
struct
stm32_wdt_obj
{
IWDG_HandleTypeDef
hiwdg
;
rt_uint16_t
is_start
;
};
static
struct
stm32_wdt_obj
stm32_wdt
;
static
struct
rt_watchdog_ops
ops
;
static
struct
rt_watchdog_ops
ops
;
static
rt_watchdog_t
watchdog
;
static
rt_watchdog_t
watchdog
;
static
rt_err_t
wdt_init
(
rt_watchdog_t
*
wdt
)
static
rt_err_t
wdt_init
(
rt_watchdog_t
*
wdt
)
{
{
hiwdg
.
Instance
=
IWDG
;
hiwdg
.
Init
.
Prescaler
=
IWDG_PRESCALER_256
;
hiwdg
.
Init
.
Reload
=
0x00000FFF
;
#if defined(SOC_SERIES_STM32F0) || defined(SOC_SERIES_STM32L4) || defined(SOC_SERIES_STM32F7)
hiwdg
.
Init
.
Window
=
0x00000FFF
;
#endif
if
(
HAL_IWDG_Init
(
&
hiwdg
)
!=
HAL_OK
)
{
LOG_E
(
"wdt init failed."
);
return
-
RT_ERROR
;
}
return
RT_EOK
;
return
RT_EOK
;
}
}
...
@@ -44,38 +36,44 @@ static rt_err_t wdt_control(rt_watchdog_t *wdt, int cmd, void *arg)
...
@@ -44,38 +36,44 @@ static rt_err_t wdt_control(rt_watchdog_t *wdt, int cmd, void *arg)
{
{
/* feed the watchdog */
/* feed the watchdog */
case
RT_DEVICE_CTRL_WDT_KEEPALIVE
:
case
RT_DEVICE_CTRL_WDT_KEEPALIVE
:
HAL_IWDG_Refresh
(
&
hiwdg
);
if
(
HAL_IWDG_Refresh
(
&
stm32_wdt
.
hiwdg
)
!=
HAL_OK
)
{
LOG_E
(
"watch dog keepalive fail."
);
}
break
;
break
;
/* set watchdog timeout */
/* set watchdog timeout */
case
RT_DEVICE_CTRL_WDT_SET_TIMEOUT
:
case
RT_DEVICE_CTRL_WDT_SET_TIMEOUT
:
#if defined(LSI_VALUE)
#if defined(LSI_VALUE)
if
(
LSI_VALUE
)
if
(
LSI_VALUE
)
{
{
hiwdg
.
Init
.
Reload
=
(
*
((
rt_uint32_t
*
)
arg
))
*
LSI_VALUE
/
256
;
stm32_wdt
.
hiwdg
.
Init
.
Reload
=
(
*
((
rt_uint32_t
*
)
arg
))
*
LSI_VALUE
/
256
;
}
}
else
else
{
{
LOG_E
(
"Please define the value of LSI_VALUE!"
);
LOG_E
(
"Please define the value of LSI_VALUE!"
);
}
}
#else
if
(
stm32_wdt
.
hiwdg
.
Init
.
Reload
>
0xFFF
)
#error "Please define the value of LSI_VALUE!"
#endif
if
(
hiwdg
.
Init
.
Reload
>
0xFFF
)
{
{
LOG_E
(
"wdg set timeout parameter too large
."
);
LOG_E
(
"wdg set timeout parameter too large
, please less than %ds"
,
0xFFF
*
256
/
LSI_VALUE
);
return
-
RT_EINVAL
;
return
-
RT_EINVAL
;
}
}
if
(
HAL_IWDG_Init
(
&
hiwdg
)
!=
HAL_OK
)
#else
#error "Please define the value of LSI_VALUE!"
#endif
if
(
stm32_wdt
.
is_start
)
{
{
LOG_E
(
"wdg set timeout failed."
);
if
(
HAL_IWDG_Init
(
&
stm32_wdt
.
hiwdg
)
!=
HAL_OK
)
return
-
RT_ERROR
;
{
LOG_E
(
"wdg set timeout failed."
);
return
-
RT_ERROR
;
}
}
}
break
;
break
;
case
RT_DEVICE_CTRL_WDT_GET_TIMEOUT
:
case
RT_DEVICE_CTRL_WDT_GET_TIMEOUT
:
#if defined(LSI_VALUE)
#if defined(LSI_VALUE)
if
(
LSI_VALUE
)
if
(
LSI_VALUE
)
{
{
(
*
((
rt_uint32_t
*
)
arg
))
=
hiwdg
.
Init
.
Reload
*
256
/
LSI_VALUE
;
(
*
((
rt_uint32_t
*
)
arg
))
=
stm32_wdt
.
hiwdg
.
Init
.
Reload
*
256
/
LSI_VALUE
;
}
}
else
else
{
{
...
@@ -85,6 +83,13 @@ static rt_err_t wdt_control(rt_watchdog_t *wdt, int cmd, void *arg)
...
@@ -85,6 +83,13 @@ static rt_err_t wdt_control(rt_watchdog_t *wdt, int cmd, void *arg)
#error "Please define the value of LSI_VALUE!"
#error "Please define the value of LSI_VALUE!"
#endif
#endif
break
;
break
;
case
RT_DEVICE_CTRL_WDT_START
:
if
(
HAL_IWDG_Init
(
&
stm32_wdt
.
hiwdg
)
!=
HAL_OK
)
{
LOG_E
(
"wdt start failed."
);
return
-
RT_ERROR
;
}
stm32_wdt
.
is_start
=
1
;
default:
default:
return
-
RT_ERROR
;
return
-
RT_ERROR
;
}
}
...
@@ -93,6 +98,15 @@ static rt_err_t wdt_control(rt_watchdog_t *wdt, int cmd, void *arg)
...
@@ -93,6 +98,15 @@ static rt_err_t wdt_control(rt_watchdog_t *wdt, int cmd, void *arg)
int
rt_wdt_init
(
void
)
int
rt_wdt_init
(
void
)
{
{
stm32_wdt
.
hiwdg
.
Instance
=
IWDG
;
stm32_wdt
.
hiwdg
.
Init
.
Prescaler
=
IWDG_PRESCALER_256
;
stm32_wdt
.
hiwdg
.
Init
.
Reload
=
0x00000FFF
;
#if defined(SOC_SERIES_STM32F0) || defined(SOC_SERIES_STM32L4) || defined(SOC_SERIES_STM32F7)
stm32_wdt
.
hiwdg
.
Init
.
Window
=
0x00000FFF
;
#endif
stm32_wdt
.
is_start
=
0
;
ops
.
init
=
&
wdt_init
;
ops
.
init
=
&
wdt_init
;
ops
.
control
=
&
wdt_control
;
ops
.
control
=
&
wdt_control
;
watchdog
.
ops
=
&
ops
;
watchdog
.
ops
=
&
ops
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录