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
21namespace ove {
22
33class Watchdog {
34public:
41 explicit Watchdog(uint32_t timeout_ms) {
42#ifdef CONFIG_OVE_ZERO_HEAP
43 int err = ove_watchdog_init(&handle_, &storage_,
44 timeout_ms);
45#else
46 int err = ove_watchdog_create(&handle_, timeout_ms);
47#endif
48 OVE_STATIC_INIT_ASSERT(err == OVE_OK);
49 }
50
55 if (!handle_) return;
56#ifdef CONFIG_OVE_ZERO_HEAP
57 ove_watchdog_deinit(handle_);
58#else
59 ove_watchdog_destroy(handle_);
60#endif
61 }
62
63 Watchdog(const Watchdog &) = delete;
64 Watchdog &operator=(const Watchdog &) = delete;
65
66#ifdef CONFIG_OVE_ZERO_HEAP
67 Watchdog(Watchdog &&) = delete;
68 Watchdog &operator=(Watchdog &&) = delete;
69#else
74 Watchdog(Watchdog &&other) noexcept : handle_(other.handle_) {
75 other.handle_ = nullptr;
76 }
77
83 Watchdog &operator=(Watchdog &&other) noexcept {
84 if (this != &other) {
85 if (handle_) ove_watchdog_destroy(handle_);
86 handle_ = other.handle_;
87 other.handle_ = nullptr;
88 }
89 return *this;
90 }
91#endif
92
97 [[nodiscard]] int start() {
98 return ove_watchdog_start(handle_);
99 }
100
105 [[nodiscard]] int stop() {
106 return ove_watchdog_stop(handle_);
107 }
108
116 [[nodiscard]] int feed() {
117 return ove_watchdog_feed(handle_);
118 }
119
124 bool valid() const { return handle_ != nullptr; }
125
130 ove_watchdog_t handle() const { return handle_; }
131
132private:
133 ove_watchdog_t handle_ = nullptr;
134#ifdef CONFIG_OVE_ZERO_HEAP
135 ove_watchdog_storage_t storage_ = {};
136#endif
137};
138
139} /* namespace ove */
140
141#endif /* CONFIG_OVE_WATCHDOG */
RAII wrapper around an oveRTOS hardware watchdog timer.
Definition watchdog.hpp:33
bool valid() const
Returns true if the underlying kernel handle is non-null.
Definition watchdog.hpp:124
int feed()
Resets the watchdog countdown, preventing a system reset.
Definition watchdog.hpp:116
~Watchdog()
Destroys the watchdog, stopping it and releasing the kernel resource.
Definition watchdog.hpp:54
Watchdog & operator=(Watchdog &&other) noexcept
Move-assignment operator — transfers ownership of the kernel handle.
Definition watchdog.hpp:83
ove_watchdog_t handle() const
Returns the raw oveRTOS watchdog handle.
Definition watchdog.hpp:130
Watchdog(Watchdog &&other) noexcept
Move constructor — transfers ownership of the kernel handle.
Definition watchdog.hpp:74
int start()
Arms the watchdog and starts the countdown.
Definition watchdog.hpp:97
Watchdog(uint32_t timeout_ms)
Constructs and initialises the watchdog with the given timeout.
Definition watchdog.hpp:41
int stop()
Disarms the watchdog, stopping the countdown.
Definition watchdog.hpp:105
Top-level namespace for all oveRTOS C++ abstractions.
Definition app.hpp:19
Common type definitions and concepts for the C++ wrapper layer.