Zephyr C++ Toolkit
Loading...
Searching...
No Matches
zct::IWatchdog Class Referenceabstract

Interface for a hardware watchdog peripheral (not the software watchdog, this does not need to be mocked). More...

#include <IWatchdog.hpp>

Inheritance diagram for zct::IWatchdog:

Public Types

enum class  Option : uint8_t { None = 0 , PauseInSleep = 1 , PauseHaltedByDebug = 2 }
 Watchdog configuration options. More...
 
enum class  ResetFlag : uint8_t { None = 0 , ResetCpuCore = 1 , ResetSoc = 2 }
 Watchdog reset behavior flags. More...
 
using CallbackFn = std::function< void(int channelId, void *userData)>
 Watchdog callback function type.
 

Public Member Functions

 IWatchdog (const char *name)
 Constructor.
 
virtual ~IWatchdog ()=default
 Virtual destructor.
 
virtual int installTimeout (uint32_t timeoutMs, CallbackFn callback=nullptr, void *userData=nullptr, ResetFlag flags=ResetFlag::ResetSoc)=0
 Install a watchdog timeout configuration.
 
virtual int setup (Option options=Option::None)=0
 Setup the watchdog with global configuration.
 
virtual int feed (int channelId)=0
 Feed (service) a watchdog channel to prevent timeout.
 
virtual int disable ()=0
 Disable the watchdog instance.
 
const char * getName () const
 Get the name of this watchdog instance.
 
virtual const struct device * getRawDevice () const =0
 Get the raw watchdog device pointer. Only valid on real implementations, mock implementations will return nullptr.
 

Protected Attributes

const char * m_name
 Name of this watchdog instance.
 

Detailed Description

Interface for a hardware watchdog peripheral (not the software watchdog, this does not need to be mocked).

This class provides a C++ abstraction layer over Zephyr's watchdog API. It follows the same patterns as other ZephyrCppToolkit peripheral interfaces.

Member Typedef Documentation

◆ CallbackFn

using zct::IWatchdog::CallbackFn = std::function<void(int channelId, void* userData)>

Watchdog callback function type.

Parameters
channelIdThe channel ID that timed out
userDataUser data passed during configuration

Member Enumeration Documentation

◆ Option

enum class zct::IWatchdog::Option : uint8_t
strong

Watchdog configuration options.

Enumerator
None 
PauseInSleep 

Pause timer during CPU sleep.

PauseHaltedByDebug 

Pause timer when debugger halts CPU.

◆ ResetFlag

enum class zct::IWatchdog::ResetFlag : uint8_t
strong

Watchdog reset behavior flags.

Enumerator
None 
ResetCpuCore 

Reset CPU core on timeout.

ResetSoc 

Reset entire SoC on timeout.

Constructor & Destructor Documentation

◆ IWatchdog()

zct::IWatchdog::IWatchdog ( const char *  name)

Constructor.

Parameters
nameName of the watchdog instance for logging purposes

◆ ~IWatchdog()

virtual zct::IWatchdog::~IWatchdog ( )
virtualdefault

Virtual destructor.

Member Function Documentation

◆ disable()

virtual int zct::IWatchdog::disable ( )
pure virtual

Disable the watchdog instance.

Returns
0 on success, negative error code on failure

Implemented in zct::WatchdogMock, and zct::WatchdogReal.

◆ feed()

virtual int zct::IWatchdog::feed ( int  channelId)
pure virtual

Feed (service) a watchdog channel to prevent timeout.

Parameters
channelIdChannel ID to feed
Returns
0 on success, negative error code on failure

Implemented in zct::WatchdogMock, and zct::WatchdogReal.

◆ getName()

const char * zct::IWatchdog::getName ( ) const
inline

Get the name of this watchdog instance.

Returns
Name string

◆ getRawDevice()

virtual const struct device * zct::IWatchdog::getRawDevice ( ) const
pure virtual

Get the raw watchdog device pointer. Only valid on real implementations, mock implementations will return nullptr.

Returns
Raw watchdog device pointer. Returns nullptr on mock implementations.

Implemented in zct::WatchdogMock, and zct::WatchdogReal.

◆ installTimeout()

virtual int zct::IWatchdog::installTimeout ( uint32_t  timeoutMs,
CallbackFn  callback = nullptr,
void *  userData = nullptr,
ResetFlag  flags = ResetFlag::ResetSoc 
)
pure virtual

Install a watchdog timeout configuration.

Parameters
timeoutMsTimeout value in milliseconds
callbackCallback function to execute on timeout (optional)
userDataUser data to pass to callback (optional)
flagsReset behavior flags
Returns
Channel ID on success, negative error code on failure

Implemented in zct::WatchdogMock, and zct::WatchdogReal.

◆ setup()

virtual int zct::IWatchdog::setup ( Option  options = Option::None)
pure virtual

Setup the watchdog with global configuration.

Parameters
optionsGlobal watchdog options
Returns
0 on success, negative error code on failure

Implemented in zct::WatchdogMock, and zct::WatchdogReal.

Member Data Documentation

◆ m_name

const char* zct::IWatchdog::m_name
protected

Name of this watchdog instance.


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