libxr
Embedded C++ framework for bare-metal, RTOS and Linux
Loading...
Searching...
No Matches
LibXR::Watchdog Class Referenceabstract

通用看门狗(Watchdog)抽象接口 General Watchdog interface for both thread and task style usage More...

#include <watchdog.hpp>

Inheritance diagram for LibXR::Watchdog:
[legend]

Classes

struct  Configuration
 看门狗配置结构体 Configuration for the watchdog More...
 

Public Member Functions

 Watchdog ()
 构造函数 / Constructor
 
virtual ~Watchdog ()
 虚析构函数 / Virtual destructor
 
virtual ErrorCode SetConfig (const Configuration &config)=0
 初始化硬件并设置超时时间 Initialize hardware and set overflow time
 
virtual ErrorCode Feed ()=0
 立即手动喂狗 Feed the watchdog immediately
 
virtual ErrorCode Start ()=0
 启动看门狗 / Start the watchdog
 
virtual ErrorCode Stop ()=0
 停止看门狗 / Stop the watchdog
 

Static Public Member Functions

static void ThreadFun (Watchdog *wdg)
 Watchdog 自动喂狗线程函数 Watchdog thread function for auto-feeding.
 
static void TaskFun (Watchdog *wdg)
 Watchdog 自动喂狗定时器任务函数 Watchdog timer task function for auto-feeding.
 

Public Attributes

uint32_t timeout_ms_ = 3000
 溢出时间
 
uint32_t auto_feed_interval_ms = 1000
 自动喂狗间隔
 
bool auto_feed_ = false
 是否自动喂狗
 

Detailed Description

通用看门狗(Watchdog)抽象接口 General Watchdog interface for both thread and task style usage

Definition at line 13 of file watchdog.hpp.

Constructor & Destructor Documentation

◆ Watchdog()

LibXR::Watchdog::Watchdog ( )
inline

构造函数 / Constructor

Definition at line 36 of file watchdog.hpp.

36{}

◆ ~Watchdog()

virtual LibXR::Watchdog::~Watchdog ( )
inlinevirtual

虚析构函数 / Virtual destructor

Definition at line 41 of file watchdog.hpp.

41{}

Member Function Documentation

◆ Feed()

virtual ErrorCode LibXR::Watchdog::Feed ( )
pure virtual

立即手动喂狗 Feed the watchdog immediately

Returns
操作结果的错误码 / Error code of the operation

Implemented in LibXR::ESP32Watchdog, and LibXR::STM32Watchdog.

◆ SetConfig()

virtual ErrorCode LibXR::Watchdog::SetConfig ( const Configuration & config)
pure virtual

初始化硬件并设置超时时间 Initialize hardware and set overflow time

Parameters
config配置参数 / Configuration
Returns
操作结果的错误码 / Error code of the operation

Implemented in LibXR::ESP32Watchdog, and LibXR::STM32Watchdog.

◆ Start()

virtual ErrorCode LibXR::Watchdog::Start ( )
pure virtual

启动看门狗 / Start the watchdog

Implemented in LibXR::ESP32Watchdog, and LibXR::STM32Watchdog.

◆ Stop()

virtual ErrorCode LibXR::Watchdog::Stop ( )
pure virtual

停止看门狗 / Stop the watchdog

Implemented in LibXR::ESP32Watchdog, and LibXR::STM32Watchdog.

◆ TaskFun()

static void LibXR::Watchdog::TaskFun ( Watchdog * wdg)
inlinestatic

Watchdog 自动喂狗定时器任务函数 Watchdog timer task function for auto-feeding.

适合轮询/定时任务调度环境。可直接作为Timer/Task回调,每次被调度时喂狗一次。 Suitable for cooperative/periodic polling system. Called by timer, feeds the watchdog once per call.

Parameters
wdg指向 Watchdog 实例的指针 / Pointer to the Watchdog instance

Definition at line 103 of file watchdog.hpp.

104 {
105 if (wdg->auto_feed_)
106 {
107 wdg->Feed();
108 }
109 }

◆ ThreadFun()

static void LibXR::Watchdog::ThreadFun ( Watchdog * wdg)
inlinestatic

Watchdog 自动喂狗线程函数 Watchdog thread function for auto-feeding.

适合 RTOS/多线程环境。可直接传递给线程创建API作为入口,循环调用 Feed(),每隔 feed_ms 毫秒自动喂狗。 Suitable for RTOS or multi-threading. Call by thread system, periodically feeds the watchdog.

Parameters
wdg指向 Watchdog 实例的指针 / Pointer to the Watchdog instance

Definition at line 80 of file watchdog.hpp.

81 {
82 while (true)
83 {
84 if (wdg->auto_feed_)
85 {
86 wdg->Feed();
87 }
88 LibXR::Thread::Sleep(wdg->auto_feed_interval_ms);
89 }
90 }
static void Sleep(uint32_t milliseconds)
让线程进入休眠状态 Puts the thread to sleep
Definition thread.cpp:15

Member Data Documentation

◆ auto_feed_

bool LibXR::Watchdog::auto_feed_ = false

是否自动喂狗

Definition at line 113 of file watchdog.hpp.

◆ auto_feed_interval_ms

uint32_t LibXR::Watchdog::auto_feed_interval_ms = 1000

自动喂狗间隔

Definition at line 112 of file watchdog.hpp.

◆ timeout_ms_

uint32_t LibXR::Watchdog::timeout_ms_ = 3000

溢出时间

Definition at line 111 of file watchdog.hpp.


The documentation for this class was generated from the following file: