libxr  1.0
Want to be the best embedded framework
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]

Data Structures

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.
 

Data Fields

uint32_t timeout_ms_ = 3000
 溢出时间
 
uint32_t feed_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 35 of file watchdog.hpp.

35{}

◆ ~Watchdog()

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

虚析构函数 Virtual destructor

Definition at line 40 of file watchdog.hpp.

40{}

Member Function Documentation

◆ Feed()

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

立即手动喂狗 Feed the watchdog immediately

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

Implemented in 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::STM32Watchdog.

◆ Start()

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

启动看门狗 / Start the watchdog

Implemented in LibXR::STM32Watchdog.

◆ Stop()

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

停止看门狗 / Stop the watchdog

Implemented in 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 101 of file watchdog.hpp.

102 {
103 if (wdg->auto_feed_)
104 {
105 wdg->Feed();
106 }
107 }

◆ 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 78 of file watchdog.hpp.

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

Field Documentation

◆ auto_feed_

bool LibXR::Watchdog::auto_feed_ = false

是否自动喂狗

Definition at line 111 of file watchdog.hpp.

◆ feed_ms_

uint32_t LibXR::Watchdog::feed_ms_ = 1000

自动喂狗间隔

Definition at line 110 of file watchdog.hpp.

◆ timeout_ms_

uint32_t LibXR::Watchdog::timeout_ms_ = 3000

溢出时间

Definition at line 109 of file watchdog.hpp.


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