Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lfmiao0
rt-thread
提交
5c8f6cc8
R
rt-thread
项目概览
lfmiao0
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
1
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,发现更多精彩内容 >>
提交
5c8f6cc8
编写于
3月 08, 2021
作者:
I
iysheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[bsp][gd32103c-eval] Add watchdog driver
上级
15eb0b08
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
119 addition
and
1 deletion
+119
-1
bsp/gd32103c-eval/Kconfig
bsp/gd32103c-eval/Kconfig
+4
-1
bsp/gd32103c-eval/README.md
bsp/gd32103c-eval/README.md
+1
-0
bsp/gd32103c-eval/drivers/SConscript
bsp/gd32103c-eval/drivers/SConscript
+3
-0
bsp/gd32103c-eval/drivers/drv_iwdt.c
bsp/gd32103c-eval/drivers/drv_iwdt.c
+111
-0
未找到文件。
bsp/gd32103c-eval/Kconfig
浏览文件 @
5c8f6cc8
...
...
@@ -96,5 +96,8 @@ menu "On-chip Peripheral Drivers"
bool "using hwtimer7"
default n
endif
config BSP_USING_WDT
bool "Enable Watchdog Timer"
select RT_USING_WDT
default n
endmenu
bsp/gd32103c-eval/README.md
浏览文件 @
5c8f6cc8
...
...
@@ -48,6 +48,7 @@ msh />
| GPIO | 支持 | GPIOA~G |
| ADC | 支持 | ADC0~1 |
| HWTIMER | 支持 | TIMER0~7 |
| WDT | 支持 | Free watchdog timer |
| IIC | 未支持 | I2C0~1 |
| SPI | 未支持 | SPI0~2 |
| ETH | 未支持 | |
...
...
bsp/gd32103c-eval/drivers/SConscript
浏览文件 @
5c8f6cc8
...
...
@@ -24,6 +24,9 @@ if GetDepend('RT_USING_ADC'):
if
GetDepend
(
'RT_USING_HWTIMER'
):
src
+=
[
'drv_hwtimer.c'
]
if
GetDepend
(
'RT_USING_WDT'
):
src
+=
[
'drv_iwdt.c'
]
group
=
DefineGroup
(
'Drivers'
,
src
,
depend
=
[
''
],
CPPPATH
=
CPPPATH
)
Return
(
'group'
)
bsp/gd32103c-eval/drivers/drv_iwdt.c
0 → 100644
浏览文件 @
5c8f6cc8
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2021-03-03 iysheng first version
*/
#include <board.h>
#define DBG_TAG "drv.wdt"
#define DBG_LVL DBG_INFO
#include <rtdbg.h>
#ifdef RT_USING_WDT
typedef
struct
{
struct
rt_watchdog_device
wdt
;
rt_uint32_t
min_threshold_s
;
rt_uint32_t
max_threshold_s
;
rt_uint32_t
current_threshold_s
;
}
gd32_wdt_device_t
;
static
gd32_wdt_device_t
g_wdt_dev
;
static
rt_err_t
gd32_iwdt_init
(
rt_watchdog_t
*
wdt
)
{
rcu_osci_on
(
RCU_IRC40K
);
if
(
ERROR
==
rcu_osci_stab_wait
(
RCU_IRC40K
))
{
LOG_E
(
"failed init IRC40K clock for free watchdog."
);
return
-
EINVAL
;
}
g_wdt_dev
.
min_threshold_s
=
1
;
g_wdt_dev
.
max_threshold_s
=
(
0xfff
<<
8
)
/
40000
;
LOG_I
(
"threshold section [%u, %d]"
,
\
g_wdt_dev
.
min_threshold_s
,
g_wdt_dev
.
max_threshold_s
);
IWDG_Write_Enable
(
IWDG_WRITEACCESS_ENABLE
);
IWDG_SetPrescaler
(
IWDG_PRESCALER_256
);
IWDG_SetReloadValue
(
0xfff
);
IWDG_Write_Enable
(
IWDG_WRITEACCESS_DISABLE
);
return
0
;
}
static
rt_err_t
gd32_iwdt_control
(
rt_watchdog_t
*
wdt
,
int
cmd
,
void
*
arg
)
{
rt_uint32_t
param
;
switch
(
cmd
)
{
case
RT_DEVICE_CTRL_WDT_KEEPALIVE
:
IWDG_ReloadCounter
();
break
;
case
RT_DEVICE_CTRL_WDT_SET_TIMEOUT
:
param
=
*
(
rt_uint32_t
*
)
arg
;
if
((
param
>
g_wdt_dev
.
max_threshold_s
)
||
\
(
param
<
g_wdt_dev
.
min_threshold_s
))
{
LOG_E
(
"invalid param@%u."
,
param
);
return
-
E2BIG
;
}
else
{
g_wdt_dev
.
current_threshold_s
=
param
;
}
IWDG_Write_Enable
(
IWDG_WRITEACCESS_ENABLE
);
IWDG_SetReloadValue
(
param
*
40000
>>
8
);
IWDG_Write_Enable
(
IWDG_WRITEACCESS_DISABLE
);
break
;
case
RT_DEVICE_CTRL_WDT_GET_TIMEOUT
:
*
(
rt_uint32_t
*
)
arg
=
g_wdt_dev
.
current_threshold_s
;
break
;
case
RT_DEVICE_CTRL_WDT_START
:
IWDG_Enable
();
break
;
default:
LOG_W
(
"This command is not supported."
);
return
-
RT_ERROR
;
}
return
RT_EOK
;
}
static
struct
rt_watchdog_ops
g_wdt_ops
=
{
gd32_iwdt_init
,
gd32_iwdt_control
,
};
static
int
rt_hw_iwdt_init
(
void
)
{
rt_err_t
ret
;
g_wdt_dev
.
wdt
.
ops
=
&
g_wdt_ops
;
/* register watchdog device */
if
(
rt_hw_watchdog_register
(
&
g_wdt_dev
.
wdt
,
"iwdt"
,
\
RT_DEVICE_FLAG_DEACTIVATE
,
RT_NULL
)
!=
RT_EOK
)
{
LOG_E
(
"wdt device register failed."
);
return
-
RT_ERROR
;
}
LOG_D
(
"wdt device register success."
);
return
ret
;
}
INIT_BOARD_EXPORT
(
rt_hw_iwdt_init
);
#endif
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录