feat: add watchdog

This commit is contained in:
zys 2026-03-04 15:01:15 +08:00
parent 2c22d68494
commit 7b17066575
3 changed files with 17 additions and 10 deletions

View File

@ -2,25 +2,30 @@
#define __ZPP_WATCHDOG_HPP
#include <zephyr/drivers/watchdog.h>
#include <zpp/assert.hpp>
#include <zpp/timer.hpp>
namespace app {
class WatchDogConfig {
public:
#if 0
WatchDogConfig() {
if (!device_is_ready(m_wtd)) {
if (!device_is_ready(m_wdt)) {
__ASSERT_NO_MSG(0);
}
wdt_install_timeout(m_wtd, &wdt_timeout_cfg);
chan_id = wdt_install_timeout(m_wdt, &cfg);
if (auto err = wdt_setup(m_wtd, WDT_OPT_PAUSE_HALTED_BY_DBG); err < 0) {
if (auto err = wdt_setup(m_wdt, WDT_OPT_PAUSE_HALTED_BY_DBG); err < 0) {
__ASSERT_NO_MSG(0);
}
wdt_timeout_cfg cfg;
}
auto Feed() { wdt_feed(m_wdt, chan_id); }
private:
const device *m_wtd{DEVICE_DT_GET(DT_ALIAS(watchdog0))};
#endif
const device *m_wdt{DEVICE_DT_GET(DT_ALIAS(watchdog0))};
static constexpr wdt_timeout_cfg cfg{
.window{0, 1000},
.callback = nullptr,
.flags = WDT_FLAG_RESET_SOC,
};
int chan_id;
};
} // namespace app

View File

@ -10,4 +10,5 @@ CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_PMC_COM=y
CONFIG_HWINFO=y
CONFIG_REBOOT=y
CONFIG_REBOOT=y
CONFIG_WATCHDOG=y

View File

@ -14,9 +14,9 @@ enum Command { kTemp = 0x00, kGetId, kRunningState };
enum RunningState {};
constexpr auto kDeviceIdSize = 20;
enum StatusId : uint8_t { kRunning, kPause, kError, kStandby };
volatile bool flag{false};
} // namespace
volatile bool flag{false};
auto main(void) -> int {
pmc.SetRxCallback(kGetId, [](uart_com::DataType data) -> void {
uint8_t buffer[kDeviceIdSize];
@ -30,7 +30,7 @@ auto main(void) -> int {
zpp::println("Status Error: {}", zpp::error_str(code));
});
});
auto wdt = app::WatchDogConfig{};
sensor_trigger tri{.type = SENSOR_TRIG_DATA_READY,
.chan = SENSOR_CHAN_AMBIENT_TEMP};
if (auto r = sensor_trigger_set(
@ -52,6 +52,7 @@ auto main(void) -> int {
flag = false;
}
wdt.Feed();
}
return 0;
}