登录发现更多内容
首页
分类
发帖
账号
自动登录
找回密码
密码
登录
立即注册
立即登录
立即注册
其他登录
QQ
微信
首页
Portal
求助问答
Xiuno资源
Xiuno教程
Xiuno插件
Xiuno主题
休闲茶馆
定制主题
产品教程
BBS
求助问答
Xiuno资源
Xiuno教程
Xiuno插件
Xiuno主题
休闲茶馆
定制主题
开发资料
求助问答
Xiuno资源
Xiuno教程
Xiuno插件
Xiuno主题
休闲茶馆
定制主题
样品购买
求助问答
Xiuno资源
Xiuno教程
Xiuno插件
Xiuno主题
休闲茶馆
定制主题
IoT云平台
求助问答
Xiuno资源
Xiuno教程
Xiuno插件
Xiuno主题
休闲茶馆
定制主题
GitHub
求助问答
Xiuno资源
Xiuno教程
Xiuno插件
Xiuno主题
休闲茶馆
定制主题
技术博客
求助问答
Xiuno资源
Xiuno教程
Xiuno插件
Xiuno主题
休闲茶馆
定制主题
搜索
搜索
热搜:
LoRa
ESP8266
安信可
本版
帖子
用户
请
登录
后使用快捷导航
没有账号?
立即注册
每日签到
任务
广播
导读
排行榜
设置
我的收藏
退出
4
0
0
首页
小安派&M61基本系统教程
›
【Ai-M61入门篇】看门狗使用
返回列表
【Ai-M61入门篇】看门狗使用
[ 复制链接 ]
发布帖子
lazy
论坛元老
39
主题
992
回帖
1万
积分
论坛元老
论坛元老, 积分 11549, 距离下一级还需 9988450 积分
论坛元老, 积分 11549, 距离下一级还需 9988450 积分
积分
11549
私信
4人留言
楼主
小安派&M61基本系统教程
1017
4
2024-11-19 17:53:05
## 一、了解Ai-M61 的 看门狗 ### **时钟源定义** Ai-M61看门狗的时钟来源有以下五种选择: • BCLK--总线时钟 • 32K--32K 时钟 • 1K--1K 时钟(32K 的分频) • XTAL--外部晶振 • GPIO--外部 GPIO ``` #define WDG_CLKSRC_BCLK 0 #define WDG_CLKSRC_32K 1 #define WDG_CLKSRC_1K 2 #define WDG_CLKSRC_XTAL 3 #define WDG_CLKSRC_GPIO 4 ``` 这些宏定义了看门狗定时器的时钟源选项,不同的时钟源可以提供不同的定时精度和稳定性。 ### **看门狗模式定义** 可以选择在超时后触发中断或复位系统 ``` #define WDG_MODE_INTERRUPT 0 #define WDG_MODE_RESET 1 ``` ## 二、结构体与函数接口 ### **struct bflb_wdg_config_s** 说明:这个结构体用于配置看门狗定时器的参数。包括时钟源、时钟分频值、比较值和工作模式 ``` /** * @brief WDG configuration structure * * @param clock_source Wdg clock source, use BFLB_SYSTEM_* definition * @param clock_div Wdg clock divison value, from 0 to 255 * @param comp_val Wdg compare value * @param mode Wdg reset/interrupt mode */ struct bflb_wdg_config_s { uint8_t clock_source; uint8_t clock_div; uint16_t comp_val; uint8_t mode; }; ``` | parameter | description | | ------------- | ----------- | | clock\_source | 时钟源选择 | | clock\_div | 分频值 | | comp_val | 比较值 | | mode | 工作模式 | ### **bflb_wdg_init** 说明:初始化看门狗定时器 ``` /** * @brief Initialize watchdog. * * @param [in] dev device handle * @param [in] config pointer to save watchdog config */ void bflb_wdg_init(struct bflb_device_s *dev, const struct bflb_wdg_config_s *config); ``` | parameter | description | | --------- | ----------- | | dev | 设备句柄 | | config | 配置项 | ### bflb_wdg_start 说明:启动看门狗定时器 ``` /** * @brief Start watchdog. * * @param [in] dev device handle */ void bflb_wdg_start(struct bflb_device_s *dev); ``` | parameter | description | | --------- | ----------- | | dev | 设备句柄 | ### bflb_wdg_stop 说明:停止看门狗定时器 ``` /** * @brief Stop watchdog. * * @param [in] dev device handle */ void bflb_wdg_stop(struct bflb_device_s *dev); ``` | parameter | description | | --------- | ----------- | | dev | 设备句柄 | ### bflb_wdg_set_countervalue 说明: 设置看门狗计数器值。 ``` /** * @brief Set watchdog counter value. * * @param [in] dev device handle * @param [in] counter value */ void bflb_wdg_set_countervalue(struct bflb_device_s *dev, uint16_t value); ``` | parameter | description | | --------- | ----------- | | dev | 设备句柄 | | value | 计数器值 | ### bflb_wdg_get_countervalue 说明: 获取看门狗计数器值。 ``` /** * @brief Get watchdog counter value. * * @param [in] dev device handle * @return counter value */ uint16_t bflb_wdg_get_countervalue(struct bflb_device_s *dev); ``` | parameter | description | | --------- | ----------- | | dev | 设备句柄 | | return | 计数值 | ### bflb_wdg_reset_countervalue 说明:重置计数值 ``` /** * @brief Reset watchdog counter value. * * @param [in] dev device handle */ void bflb_wdg_reset_countervalue(struct bflb_device_s *dev); ``` | parameter | description | | --------- | ----------- | | dev | 设备句柄 | ### bflb_wdg_compint_clear 说明:清除比较中断状态 ``` /** * @brief Clear watchdog compare interrupt status. * * @param [in] dev device handle */ void bflb_wdg_compint_clear(struct bflb_device_s *dev); ``` | parameter | description | | --------- | ----------- | | dev | 设备句柄 | ## 三、看门狗的两种工作方式 ### 一、看门狗定时器时钟源的选择以及分频 以选择 WDG_CLKSRC_32K 这个外部晶振的时钟源来举例,频率为 32MHz,而分频系数,也就是结构体中的 clock\_div,这里系数可选 0\~255,选择 31,时钟计数=时钟频率/(分频系数 +1)。也就是 32Mhz/(31+1),也就是 1Mhz,而周期与频率互为倒数,也就是 1us 一个计数。这样分频的话就是一微秒计数 +1。 ### 二、中断 在看门狗定时器的计数器计数过程中,一旦计数器的值与三个比较器中的某比较值一致,该比较器的比较标志就会置位,并可以产生相应的比较中断。 ## 四、简单示例 ``` #include "bflb_wdg.h" #include "bflb_mtimer.h" #include "board.h" #include "bflb_gpio.h" struct bflb_device_s *wdg; static volatile uint8_t wdg_int_arrived = 0; void wdg_isr(int irq, void *arg) { bflb_wdg_compint_clear(wdg); wdg_int_arrived = 1; printf("Error! wdg_isr. \r\n"); } void wdg_task(void *arg) { struct bflb_wdg_config_s wdg_cfg; wdg_cfg.clock_source = WDG_CLKSRC_32K; wdg_cfg.clock_div = 31; wdg_cfg.comp_val = 2000; wdg_cfg.mode = WDG_MODE_INTERRUPT; // 中断模式 wdg = bflb_device_get_by_name("watchdog"); bflb_wdg_init(wdg, &wdg_cfg); bflb_irq_attach(wdg->irq_num, wdg_isr, wdg); bflb_irq_enable(wdg->irq_num); wdg_int_arrived = 0; bflb_wdg_start(wdg); int i = 0; while (1) { bflb_wdg_reset_countervalue(wdg); bflb_mtimer_delay_ms(10); uint16_t value = bflb_wdg_get_countervalue(wdg); printf("重置狗. %d\r\n", value); if(i>15){ i = 0; bflb_mtimer_delay_ms(2500); // LOG_E("超时狗 \r\n"); }else{ bflb_mtimer_delay_ms(1000); // LOG_E("不超时 \r\n"); } i++; value = bflb_wdg_get_countervalue(wdg); printf("延迟. %d\r\n", value); } } int main(void) { board_init(); xTaskCreate(wdg_task, "wdg_task", 1024, NULL, 2, NULL); vTaskStartScheduler(); } ``` ## 效果  这里园长写的Ai-WB2看门狗使用 > 【Ai-WB2入门篇】看门狗使用 > [https://bbs.ai-thinker.com/forum.php?mod=viewthread&tid=45189&fromuid=16612](https://bbs.ai-thinker.com/forum.php?mod=viewthread&tid=45189&fromuid=16612) > (出处: 物联网开发者社区-安信可论坛) [干簧管]([https://bbs.ai-thinker.com/home.php?mod=space&uid=14022](https://bbs.ai-thinker.com/home.php?mod=space&uid=14022)) > 看门狗的分类及其作用 > [https://bbs.ai-thinker.com/forum.php?mod=viewthread&tid=43663&fromuid=16612](https://bbs.ai-thinker.com/forum.php?mod=viewthread&tid=43663&fromuid=16612) > (出处: 物联网开发者社区-安信可论坛)
点赞
0
收藏
0
淘帖
0
────
0
人觉得很赞
────
回复
使用道具
举报
4 回复
电梯直达
正序浏览
倒序浏览
正序浏览
沙发
大猫的鱼
回复
使用道具
举报
2024-11-19 22:55:19
赞
回复
评论
使用道具
举报
板凳
爱笑
回复
使用道具
举报
2024-11-20 08:37:54
太棒了!
回复
评论
使用道具
举报
用心做好保姆工作
地板
WT_0213
回复
使用道具
举报
2024-11-20 09:01:32
赞
回复
评论
使用道具
举报
5
#
XiongNeng
回复
使用道具
举报
2025-9-19 16:24:03
打卡👍
回复
评论
使用道具
举报
B
Color
Image
Link
Quote
Code
Smilies
您需要登录后才可以回帖
立即登录
手机登录
点评
高级模式
本版积分规则
回帖并转播
回帖后跳转到最后一页
返回
今日推荐
基于Ai-WB2的HomeAssistant实现RGB彩灯控制功能
BU04 原理图
基于 Ai-WV01-32S+STM32移植 emMCP 实现 AI 语音控制点灯
AiPi-PalChatV1_“湾湾小何”提示音测试固件V2.9_UART-MCP
[WB2] 实现自动发现局域网下的设备
热帖排行
论坛应该出一个发帖时间排序
基于Ai-WB2的HomeAssistant实现RGB彩灯控制功能
BU04 原理图
小安派-Eyes-S1 - UART
小安派-Eyes-S1 - PWM
小安派-Eyes-S1 - TIMER
VC-02 Custom Audio Replacement - pcm.bin Generated but Not I
基于 Ai-WV01-32S+STM32移植 emMCP 实现 AI 语音控制点灯
统计信息
会员数: 30511 个
话题数: 44682 篇
首页
分类
我的