SatNOGS-COMMS
4.1.0
A COMMS subsystem for CubeSats
Toggle main menu visibility
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
5
namespace
scl
=
satnogs::comms::lib
;
6
7
namespace
satnogs::comms
8
{
14
void
15
error_handler::assert_error
(
const
scl::exception
&e)
16
{
17
assert_error
(0, e);
18
}
19
29
void
30
error_handler::assert_error
(
bool
condition,
const
scl::exception
&e)
31
{
32
ETL_ASSERT(condition, e);
33
}
34
40
uint32_t
41
error_handler::hwinfo_reset_cause
()
const
42
{
43
return
m_hw_reset_cause;
44
}
45
61
void
62
error_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
78
void
79
error_handler::system_reboot
()
const
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
107
void
108
error_handler::handle
(
const
lib::exception
&e)
109
{
110
log
(e);
111
switch
(e.
get_severity
()) {
112
case
scl::exception::severity::CATASTROPHIC
:
113
case
scl::exception::severity::CRITICAL
:
114
system_reboot
();
115
break
;
116
case
scl::exception::severity::MAJOR
:
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) {
123
system_reboot
();
124
}
125
break
;
126
default
:
127
break
;
128
}
129
}
130
139
void
140
error_handler::handle
(
const
etl::exception &e)
141
{
142
log
(e);
143
}
144
154
void
155
error_handler::handle
(
const
std::exception &e)
156
{
157
log
(e);
158
system_reboot
();
159
}
160
173
error_handler::error_handler
()
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
satnogs::comms::error_handler::hwinfo_reset_cause
uint32_t hwinfo_reset_cause() const
Retrieves the hardware reset cause from the MCU.
Definition
error_handler.cpp:41
satnogs::comms::error_handler::error_handler
error_handler()
Constructs an error_handler instance.
Definition
error_handler.cpp:173
satnogs::comms::error_handler::system_reboot
void system_reboot() const
Instructs a system reboot.
Definition
error_handler.cpp:79
satnogs::comms::error_handler::handle
void handle(const lib::exception &e)
Handles a lib::exception based on its severity.
Definition
error_handler.cpp:108
satnogs::comms::error_handler::log
void log(const T &e) const
Definition
error_handler.hpp:136
satnogs::comms::error_handler::assert_error
void assert_error(const lib::exception &e)
Logs error details and throws an exception with ETL_ASSERT().
Definition
error_handler.cpp:15
satnogs::comms::lib::exception
Exception base class.
Definition
exception.hpp:63
satnogs::comms::lib::exception::severity::MAJOR
@ MAJOR
Failure causing minor mission degradation.
Definition
exception.hpp:74
satnogs::comms::lib::exception::severity::CATASTROPHIC
@ CATASTROPHIC
Failure causing loss of mission.
Definition
exception.hpp:72
satnogs::comms::lib::exception::severity::CRITICAL
@ CRITICAL
Failure causing mission degradation or significant damage.
Definition
exception.hpp:73
satnogs::comms::lib::exception::get_severity
severity get_severity() const
Get error severity level as defined in FDIR.
Definition
exception.hpp:165
satnogs::comms::lib::exception::get_errno
int32_t get_errno() const
Definition
exception.hpp:152
error_handler.hpp
satnogs::comms::lib
Definition
ad8318.hpp:30
satnogs::comms
Definition
bsp.cpp:28
src
error_handler.cpp
Generated by
1.17.0