oveRTOS C++ API
C++20 RAII wrappers for the oveRTOS C API
Loading...
Searching...
No Matches
watchdog.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2026 Kamil Lulko <kamil.lulko@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 *
6 * This file is part of oveRTOS.
7 */
8
14#pragma once
15
16#ifdef CONFIG_OVE_WATCHDOG
17
18#include <ove/watchdog.h>
19#include <ove/types.hpp>
20#include <ove/error.hpp>
21
22namespace ove
23{
24
36{
37 public:
54 explicit Watchdog(uint32_t timeout_ms)
55 {
56#ifdef CONFIG_OVE_ZERO_HEAP
57 int err = ove_watchdog_init(&handle_, &storage_, timeout_ms);
58#else
59 int err = ove_watchdog_create(&handle_, timeout_ms);
60#endif
61 if (err != OVE_OK) {
62 handle_ = nullptr;
63 }
64 }
65
69 ~Watchdog() noexcept
70 {
71 if (!handle_)
72 return;
73#ifdef CONFIG_OVE_ZERO_HEAP
74 ove_watchdog_deinit(handle_);
75#else
76 ove_watchdog_destroy(handle_);
77#endif
78 }
79
80 Watchdog(const Watchdog &) = delete;
81 Watchdog &operator=(const Watchdog &) = delete;
82
83#ifdef CONFIG_OVE_ZERO_HEAP
84 Watchdog(Watchdog &&) = delete;
85 Watchdog &operator=(Watchdog &&) = delete;
86#else
91 Watchdog(Watchdog &&other) noexcept : handle_(other.handle_)
92 {
93 other.handle_ = nullptr;
94 }
95
101 Watchdog &operator=(Watchdog &&other) noexcept
102 {
103 if (this != &other) {
104 if (handle_)
105 ove_watchdog_destroy(handle_);
106 handle_ = other.handle_;
107 other.handle_ = nullptr;
108 }
109 return *this;
110 }
111#endif
112
119 [[nodiscard]] Result<void> start() noexcept
120 {
121 return from_rc(ove_watchdog_start(handle_));
122 }
123
129 [[nodiscard]] Result<void> stop() noexcept
130 {
131 return from_rc(ove_watchdog_stop(handle_));
132 }
133
142 [[nodiscard]] Result<void> feed() noexcept
143 {
144 return from_rc(ove_watchdog_feed(handle_));
145 }
146
151 bool valid() const
152 {
153 return handle_ != nullptr;
154 }
155
160 ove_watchdog_t handle() const
161 {
162 return handle_;
163 }
164
165 private:
166 ove_watchdog_t handle_ = nullptr;
167#ifdef CONFIG_OVE_ZERO_HEAP
168 ove_watchdog_storage_t storage_ = {};
169#endif
170};
171
172} /* namespace ove */
173
174#endif /* CONFIG_OVE_WATCHDOG */
RAII wrapper around an oveRTOS hardware watchdog timer.
Definition watchdog.hpp:36
~Watchdog() noexcept
Destroys the watchdog, stopping it and releasing the kernel resource.
Definition watchdog.hpp:69
bool valid() const
Returns true if the underlying kernel handle is non-null.
Definition watchdog.hpp:151
Result< void > feed() noexcept
Resets the watchdog countdown, preventing a system reset.
Definition watchdog.hpp:142
Result< void > start() noexcept
Arms the watchdog and starts the countdown.
Definition watchdog.hpp:119
Watchdog & operator=(Watchdog &&other) noexcept
Move-assignment operator — transfers ownership of the kernel handle.
Definition watchdog.hpp:101
ove_watchdog_t handle() const
Returns the raw oveRTOS watchdog handle.
Definition watchdog.hpp:160
Watchdog(Watchdog &&other) noexcept
Move constructor — transfers ownership of the kernel handle.
Definition watchdog.hpp:91
Watchdog(uint32_t timeout_ms)
Constructs the watchdog and tries to initialise it with the given timeout.
Definition watchdog.hpp:54
Result< void > stop() noexcept
Disarms the watchdog, stopping the countdown.
Definition watchdog.hpp:129
Strong ove::Error type, Result<T> alias, and std::error_code interop for the oveRTOS C++ binding.
Top-level namespace for all oveRTOS C++ abstractions.
Definition app.hpp:20
Result< void > from_rc(int rc) noexcept
Lifts a substrate rc-code into a Result<void>.
Definition error.hpp:254
std::expected< T, Error > Result
std::expected-based result alias.
Definition error.hpp:139
Common type definitions and concepts for the C++ wrapper layer.