SatNOGS-COMMS  4.1.0
A COMMS subsystem for CubeSats
Loading...
Searching...
No Matches
error_handler.cpp
Go to the documentation of this file.
1#include "error_handler.hpp"
2#include <zephyr/drivers/hwinfo.h>
3#include <zephyr/sys/reboot.h>
4
5namespace scl = satnogs::comms::lib;
6
7namespace satnogs::comms
8{
14void
19
29void
31{
32 ETL_ASSERT(condition, e);
33}
34
40uint32_t
42{
43 return m_hw_reset_cause;
44}
45
61void
62error_handler::get_reset_cause()
63{
64 uint32_t cause;
65 hwinfo_get_reset_cause(&cause);
66 hwinfo_clear_reset_cause();
67 m_hw_reset_cause = cause;
68 return;
69}
70
78void
80{
81 /* Wait a bit for any log buffers to be flushed */
82 k_sleep(K_SECONDS(2));
83 sys_reboot(SYS_REBOOT_COLD);
84
85 /* If this routine fails, we rely on the WDT to do its job */
86 volatile uint32_t x = 0;
87 while (1) {
88 x++;
89 }
90}
91
107void
109{
110 log(e);
111 switch (e.get_severity()) {
115 break;
117 if (m_last_errno == e.get_errno()) {
118 m_errno_cnt++;
119 } else {
120 m_last_errno = e.get_errno();
121 }
122 if (m_errno_cnt > CONFIG_MAX_MAJOR_ERRORS) {
124 }
125 break;
126 default:
127 break;
128 }
129}
130
139void
140error_handler::handle(const etl::exception &e)
141{
142 log(e);
143}
144
154void
155error_handler::handle(const std::exception &e)
156{
157 log(e);
159}
160
174 : m_hw_reset_cause(0), m_last_errno(0), m_errno_cnt(0)
175{
176 get_reset_cause();
177}
178
179} // namespace satnogs::comms
uint32_t hwinfo_reset_cause() const
Retrieves the hardware reset cause from the MCU.
error_handler()
Constructs an error_handler instance.
void system_reboot() const
Instructs a system reboot.
void handle(const lib::exception &e)
Handles a lib::exception based on its severity.
void log(const T &e) const
void assert_error(const lib::exception &e)
Logs error details and throws an exception with ETL_ASSERT().
Exception base class.
Definition exception.hpp:63
@ MAJOR
Failure causing minor mission degradation.
Definition exception.hpp:74
@ CATASTROPHIC
Failure causing loss of mission.
Definition exception.hpp:72
@ CRITICAL
Failure causing mission degradation or significant damage.
Definition exception.hpp:73
severity get_severity() const
Get error severity level as defined in FDIR.