Zephyr C++ Toolkit
Loading...
Searching...
No Matches
WatchdogReal.hpp
Go to the documentation of this file.
1/**************************************************************************************
2 * @file WatchdogReal.hpp
3 *
4 * Real hardware implementation of the watchdog interface using Zephyr's watchdog API.
5 *
6 **************************************************************************************
7 *
8 * Copyright 2025 Electronic Timers Ltd.
9 *
10 **************************************************************************************/
11
12#pragma once
13
14// 3rd party includes
15#include <zephyr/drivers/watchdog.h>
16
17// Local includes
18#include "IWatchdog.hpp"
19
20namespace zct {
21
27class WatchdogReal : public IWatchdog {
28public:
35 WatchdogReal(const char* name, const struct device* device);
36
41
52 int installTimeout(uint32_t timeoutMs,
53 CallbackFn callback = nullptr,
54 void* userData = nullptr,
55 ResetFlag flags = ResetFlag::ResetSoc) override;
56
63 int setup(Option options = Option::None) override;
64
71 int feed(int channelId) override;
72
78 int disable() override;
79
85 const struct device* getRawDevice() const override;
86
87private:
94 static uint8_t convertOptions(Option options);
95
102 static uint8_t convertResetFlags(ResetFlag flags);
103
110 static void staticCallback(const struct device* dev, int channelId);
111
112 const struct device* m_device;
116};
117
118} // namespace zct
Interface for a hardware watchdog peripheral (not the software watchdog, this does not need to be moc...
Definition IWatchdog.hpp:26
Option
Watchdog configuration options.
Definition IWatchdog.hpp:31
std::function< void(int channelId, void *userData)> CallbackFn
Watchdog callback function type.
Definition IWatchdog.hpp:52
ResetFlag
Watchdog reset behavior flags.
Definition IWatchdog.hpp:40
@ ResetSoc
Reset entire SoC on timeout.
Real hardware implementation of the watchdog interface.
Definition WatchdogReal.hpp:27
const struct device * getRawDevice() const override
Get the raw watchdog device pointer.
Definition WatchdogReal.cpp:169
CallbackFn m_callback
User callback function.
Definition WatchdogReal.hpp:114
int installTimeout(uint32_t timeoutMs, CallbackFn callback=nullptr, void *userData=nullptr, ResetFlag flags=ResetFlag::ResetSoc) override
Install a watchdog timeout configuration.
Definition WatchdogReal.cpp:49
bool m_isSetup
Track if setup() has been called.
Definition WatchdogReal.hpp:113
void * m_userData
User data for callback.
Definition WatchdogReal.hpp:115
static uint8_t convertOptions(Option options)
Convert IWatchdog::Option to Zephyr wdt options.
Definition WatchdogReal.cpp:127
int feed(int channelId) override
Feed (service) a watchdog channel to prevent timeout.
Definition WatchdogReal.cpp:98
const struct device * m_device
Zephyr watchdog device.
Definition WatchdogReal.hpp:112
int disable() override
Disable the watchdog instance.
Definition WatchdogReal.cpp:111
~WatchdogReal()
Destructor.
Definition WatchdogReal.cpp:43
static void staticCallback(const struct device *dev, int channelId)
Static callback function for Zephyr WDT API.
Definition WatchdogReal.cpp:161
int setup(Option options=Option::None) override
Setup the watchdog with global configuration.
Definition WatchdogReal.cpp:81
static uint8_t convertResetFlags(ResetFlag flags)
Convert IWatchdog::ResetFlag to Zephyr wdt flags.
Definition WatchdogReal.cpp:142
Definition Mutex.hpp:6