libxr
Embedded C++ framework for bare-metal, RTOS and Linux
Loading...
Searching...
No Matches
LibXR::ESP32Watchdog Class Reference
Inheritance diagram for LibXR::ESP32Watchdog:
[legend]
Collaboration diagram for LibXR::ESP32Watchdog:
[legend]

Public Member Functions

 ESP32Watchdog (uint32_t timeout_ms=1000, uint32_t feed_ms=250)
 
ErrorCode SetConfig (const Configuration &config) override
 初始化硬件并设置超时时间 Initialize hardware and set overflow time
 
ErrorCode Feed () override
 立即手动喂狗 Feed the watchdog immediately
 
ErrorCode Start () override
 启动看门狗 / Start the watchdog
 
ErrorCode Stop () override
 停止看门狗 / Stop the watchdog
 
- Public Member Functions inherited from LibXR::Watchdog
 Watchdog ()
 构造函数 / Constructor
 
virtual ~Watchdog ()
 虚析构函数 / Virtual destructor
 

Additional Inherited Members

- Static Public Member Functions inherited from LibXR::Watchdog
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 inherited from LibXR::Watchdog
uint32_t timeout_ms_ = 3000
 溢出时间
 
uint32_t auto_feed_interval_ms = 1000
 自动喂狗间隔
 
bool auto_feed_ = false
 是否自动喂狗
 

Detailed Description

Definition at line 44 of file esp_watchdog.hpp.

Constructor & Destructor Documentation

◆ ESP32Watchdog()

LibXR::ESP32Watchdog::ESP32Watchdog ( uint32_t timeout_ms = 1000,
uint32_t feed_ms = 250 )
explicit

Definition at line 41 of file esp_watchdog.cpp.

42{
43 (void)SetConfig({timeout_ms, feed_ms});
44 (void)Start();
45}
ErrorCode Start() override
启动看门狗 / Start the watchdog
ErrorCode SetConfig(const Configuration &config) override
初始化硬件并设置超时时间 Initialize hardware and set overflow time

Member Function Documentation

◆ Feed()

ErrorCode LibXR::ESP32Watchdog::Feed ( )
overridevirtual

立即手动喂狗 Feed the watchdog immediately

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

Implements LibXR::Watchdog.

Definition at line 159 of file esp_watchdog.cpp.

160{
161 if (!initialized_ || !started_)
162 {
163 return ErrorCode::INIT_ERR;
164 }
165
166 wdt_hal_write_protect_disable(&hal_);
167 wdt_hal_feed(&hal_);
168 wdt_hal_write_protect_enable(&hal_);
169 return ErrorCode::OK;
170}
@ INIT_ERR
初始化错误 / Initialization error
@ OK
操作成功 / Operation successful

◆ SetConfig()

ErrorCode LibXR::ESP32Watchdog::SetConfig ( const Configuration & config)
overridevirtual

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

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

Implements LibXR::Watchdog.

Definition at line 139 of file esp_watchdog.cpp.

140{
141 if ((config.timeout_ms == 0) || (config.feed_ms == 0) ||
142 (config.feed_ms > config.timeout_ms))
143 {
144 return ErrorCode::ARG_ERR;
145 }
146
147 timeout_ms_ = config.timeout_ms;
148 auto_feed_interval_ms = config.feed_ms;
149
150 ErrorCode ret = InitializeHardware();
151 if (ret != ErrorCode::OK)
152 {
153 return ret;
154 }
155
156 return ApplyConfiguration();
157}
uint32_t auto_feed_interval_ms
自动喂狗间隔
Definition watchdog.hpp:112
uint32_t timeout_ms_
溢出时间
Definition watchdog.hpp:111
ErrorCode
定义错误码枚举 / Defines an enumeration for error codes
@ ARG_ERR
参数错误 / Argument error

◆ Start()

ErrorCode LibXR::ESP32Watchdog::Start ( )
overridevirtual

启动看门狗 / Start the watchdog

Implements LibXR::Watchdog.

Definition at line 172 of file esp_watchdog.cpp.

173{
174 ErrorCode ret = InitializeHardware();
175 if (ret != ErrorCode::OK)
176 {
177 return ret;
178 }
179
180 ret = ApplyConfiguration();
181 if (ret != ErrorCode::OK)
182 {
183 return ret;
184 }
185
186 wdt_hal_write_protect_disable(&hal_);
187 wdt_hal_enable(&hal_);
188 wdt_hal_feed(&hal_);
189 wdt_hal_write_protect_enable(&hal_);
190
191 auto_feed_ = true;
192 started_ = true;
193 return ErrorCode::OK;
194}
bool auto_feed_
是否自动喂狗
Definition watchdog.hpp:113

◆ Stop()

ErrorCode LibXR::ESP32Watchdog::Stop ( )
overridevirtual

停止看门狗 / Stop the watchdog

Implements LibXR::Watchdog.

Definition at line 196 of file esp_watchdog.cpp.

197{
198 if (!initialized_)
199 {
200 return ErrorCode::INIT_ERR;
201 }
202
203 wdt_hal_write_protect_disable(&hal_);
204 wdt_hal_disable(&hal_);
205 wdt_hal_write_protect_enable(&hal_);
206
207 auto_feed_ = false;
208 started_ = false;
209 return ErrorCode::OK;
210}

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