libxr
Embedded C++ framework for bare-metal, RTOS and Linux
Loading...
Searching...
No Matches
watchdog.hpp
1#pragma once
2
3#include "libxr.hpp"
4
5namespace LibXR
6{
7
14{
15 public:
28 {
29 uint32_t timeout_ms;
30 uint32_t feed_ms;
31 };
32
37
41 virtual ~Watchdog() {}
42
49 virtual ErrorCode SetConfig(const Configuration& config) = 0;
50
56 virtual ErrorCode Feed() = 0;
57
61 virtual ErrorCode Start() = 0;
62
66 virtual ErrorCode Stop() = 0;
67
80 static void ThreadFun(Watchdog* wdg)
81 {
82 while (true)
83 {
84 if (wdg->auto_feed_)
85 {
86 wdg->Feed();
87 }
89 }
90 }
91
103 static void TaskFun(Watchdog* wdg)
104 {
105 if (wdg->auto_feed_)
106 {
107 wdg->Feed();
108 }
109 }
110
111 uint32_t timeout_ms_ = 3000;
112 uint32_t auto_feed_interval_ms = 1000;
113 bool auto_feed_ = false;
114};
115
116} // namespace LibXR
static void Sleep(uint32_t milliseconds)
让线程进入休眠状态 Puts the thread to sleep
Definition thread.cpp:15
通用看门狗(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 auto_feed_interval_ms
自动喂狗间隔
Definition watchdog.hpp:112
virtual ~Watchdog()
虚析构函数 / Virtual destructor
Definition watchdog.hpp:41
virtual ErrorCode Start()=0
启动看门狗 / Start the watchdog
static void ThreadFun(Watchdog *wdg)
Watchdog 自动喂狗线程函数 Watchdog thread function for auto-feeding.
Definition watchdog.hpp:80
virtual ErrorCode Feed()=0
立即手动喂狗 Feed the watchdog immediately
Watchdog()
构造函数 / Constructor
Definition watchdog.hpp:36
static void TaskFun(Watchdog *wdg)
Watchdog 自动喂狗定时器任务函数 Watchdog timer task function for auto-feeding.
Definition watchdog.hpp:103
bool auto_feed_
是否自动喂狗
Definition watchdog.hpp:113
uint32_t timeout_ms_
溢出时间
Definition watchdog.hpp:111
virtual ErrorCode Stop()=0
停止看门狗 / Stop the watchdog
LibXR 命名空间 / LibXR namespace.
Definition ch32_can.hpp:14
ErrorCode
定义错误码枚举 / Defines an enumeration for error codes
看门狗配置结构体 Configuration for the watchdog
Definition watchdog.hpp:28
uint32_t feed_ms
自动喂狗周期 / Auto feed interval (ms, < timeout_ms)
Definition watchdog.hpp:30
uint32_t timeout_ms
看门狗溢出时间 / Watchdog overflow time (ms)
Definition watchdog.hpp:29