libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
watchdog.hpp
1#pragma once
2
3#include "libxr.hpp"
4
5namespace LibXR
6{
7
14{
15 public:
27 {
28 uint32_t timeout_ms;
29 uint32_t feed_ms;
30 };
31
36
40 virtual ~Watchdog() {}
41
48 virtual ErrorCode SetConfig(const Configuration &config) = 0;
49
55 virtual ErrorCode Feed() = 0;
56
60 virtual ErrorCode Start() = 0;
61
65 virtual ErrorCode Stop() = 0;
66
78 static void ThreadFun(Watchdog *wdg)
79 {
80 while (true)
81 {
82 if (wdg->auto_feed_)
83 {
84 wdg->Feed();
85 }
87 }
88 }
89
101 static void TaskFun(Watchdog *wdg)
102 {
103 if (wdg->auto_feed_)
104 {
105 wdg->Feed();
106 }
107 }
108
109 uint32_t timeout_ms_ = 3000;
110 uint32_t feed_ms_ = 1000;
111 bool auto_feed_ = false;
112};
113
114} // namespace LibXR
static void Sleep(uint32_t milliseconds)
让线程进入休眠状态 Puts the thread to sleep
Definition thread.cpp:16
通用看门狗(Watchdog)抽象接口 General Watchdog interface for both thread and task style usage
Definition watchdog.hpp:14
virtual ErrorCode SetConfig(const Configuration &config)=0
初始化硬件并设置超时时间 Initialize hardware and set overflow time
uint32_t feed_ms_
自动喂狗间隔
Definition watchdog.hpp:110
virtual ~Watchdog()
虚析构函数 Virtual destructor
Definition watchdog.hpp:40
virtual ErrorCode Start()=0
启动看门狗 / Start the watchdog
static void ThreadFun(Watchdog *wdg)
Watchdog 自动喂狗线程函数 Watchdog thread function for auto-feeding.
Definition watchdog.hpp:78
virtual ErrorCode Feed()=0
立即手动喂狗 Feed the watchdog immediately
Watchdog()
构造函数 Constructor
Definition watchdog.hpp:35
static void TaskFun(Watchdog *wdg)
Watchdog 自动喂狗定时器任务函数 Watchdog timer task function for auto-feeding.
Definition watchdog.hpp:101
bool auto_feed_
是否自动喂狗
Definition watchdog.hpp:111
uint32_t timeout_ms_
溢出时间
Definition watchdog.hpp:109
virtual ErrorCode Stop()=0
停止看门狗 / Stop the watchdog
LibXR 命名空间
Definition ch32_gpio.hpp:9
看门狗配置结构体 Configuration for the watchdog
Definition watchdog.hpp:27
uint32_t feed_ms
自动喂狗周期 Auto feed interval (ms, < timeout_ms)
Definition watchdog.hpp:29
uint32_t timeout_ms
看门狗溢出时间 Watchdog overflow time (ms)
Definition watchdog.hpp:28