Zephyr C++ Toolkit
Loading...
Searching...
No Matches
IWatchdog.hpp
Go to the documentation of this file.
1/**************************************************************************************
2 * @file IWatchdog.hpp
3 *
4 * Interface for watchdog peripherals in the ZephyrCppToolkit library.
5 *
6 **************************************************************************************
7 *
8 * Copyright 2025 Electronic Timers Ltd.
9 *
10 **************************************************************************************/
11
12#pragma once
13
14// System includes
15#include <functional>
16#include <cstdint>
17
18namespace zct {
19
26class IWatchdog {
27public:
31 enum class Option : uint8_t {
32 None = 0,
33 PauseInSleep = 1,
35 };
36
40 enum class ResetFlag : uint8_t {
41 None = 0,
42 ResetCpuCore = 1,
43 ResetSoc = 2
44 };
45
52 using CallbackFn = std::function<void(int channelId, void* userData)>;
53
59 IWatchdog(const char* name);
60
64 virtual ~IWatchdog() = default;
65
75 virtual int installTimeout(uint32_t timeoutMs,
76 CallbackFn callback = nullptr,
77 void* userData = nullptr,
78 ResetFlag flags = ResetFlag::ResetSoc) = 0;
79
86 virtual int setup(Option options = Option::None) = 0;
87
94 virtual int feed(int channelId) = 0;
95
101 virtual int disable() = 0;
102
108 const char* getName() const { return m_name; }
109
115 virtual const struct device* getRawDevice() const = 0;
116
117protected:
118 const char* m_name;
119};
120
125 return static_cast<IWatchdog::Option>(static_cast<uint8_t>(lhs) | static_cast<uint8_t>(rhs));
126}
127
132 return static_cast<IWatchdog::Option>(static_cast<uint8_t>(lhs) & static_cast<uint8_t>(rhs));
133}
134
135} // namespace zct
Interface for a hardware watchdog peripheral (not the software watchdog, this does not need to be moc...
Definition IWatchdog.hpp:26
const char * getName() const
Get the name of this watchdog instance.
Definition IWatchdog.hpp:108
Option
Watchdog configuration options.
Definition IWatchdog.hpp:31
@ PauseInSleep
Pause timer during CPU sleep.
@ PauseHaltedByDebug
Pause timer when debugger halts CPU.
virtual int installTimeout(uint32_t timeoutMs, CallbackFn callback=nullptr, void *userData=nullptr, ResetFlag flags=ResetFlag::ResetSoc)=0
Install a watchdog timeout configuration.
virtual const struct device * getRawDevice() const =0
Get the raw watchdog device pointer. Only valid on real implementations, mock implementations will re...
virtual ~IWatchdog()=default
Virtual destructor.
const char * m_name
Name of this watchdog instance.
Definition IWatchdog.hpp:118
virtual int setup(Option options=Option::None)=0
Setup the watchdog with global configuration.
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
@ ResetCpuCore
Reset CPU core on timeout.
@ ResetSoc
Reset entire SoC on timeout.
virtual int feed(int channelId)=0
Feed (service) a watchdog channel to prevent timeout.
virtual int disable()=0
Disable the watchdog instance.
Definition Mutex.hpp:6
constexpr IWatchdog::Option operator|(IWatchdog::Option lhs, IWatchdog::Option rhs)
Bitwise OR operator for watchdog options.
Definition IWatchdog.hpp:124
constexpr IWatchdog::Option operator&(IWatchdog::Option lhs, IWatchdog::Option rhs)
Bitwise AND operator for watchdog options.
Definition IWatchdog.hpp:131