2019-03-18 08:32:42 -03:00
|
|
|
#include "AP_InternalError.h"
|
|
|
|
|
2019-07-03 21:06:02 -03:00
|
|
|
#include <AP_BoardConfig/AP_BoardConfig.h>
|
|
|
|
|
2019-05-09 08:15:00 -03:00
|
|
|
extern const AP_HAL::HAL &hal;
|
|
|
|
|
2019-03-18 08:32:42 -03:00
|
|
|
// actually create the instance:
|
|
|
|
static AP_InternalError instance;
|
|
|
|
|
|
|
|
void AP_InternalError::error(const AP_InternalError::error_t e) {
|
|
|
|
#if CONFIG_HAL_BOARD == HAL_BOARD_SITL
|
2019-05-09 08:15:00 -03:00
|
|
|
switch (e) {
|
|
|
|
case AP_InternalError::error_t::watchdog_reset:
|
|
|
|
case AP_InternalError::error_t::main_loop_stuck:
|
|
|
|
// don't panic on these to facilitate watchdog testing
|
|
|
|
break;
|
|
|
|
default:
|
2019-05-09 05:48:50 -03:00
|
|
|
AP_HAL::panic("internal error %u", unsigned(e));
|
|
|
|
}
|
2019-03-18 08:32:42 -03:00
|
|
|
#endif
|
|
|
|
internal_errors |= uint32_t(e);
|
2019-06-03 00:20:53 -03:00
|
|
|
total_error_count++;
|
|
|
|
|
2019-05-09 08:15:00 -03:00
|
|
|
hal.util->persistent_data.internal_errors = internal_errors;
|
2019-06-03 00:20:53 -03:00
|
|
|
hal.util->persistent_data.internal_error_count = total_error_count;
|
2019-03-18 08:32:42 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace AP {
|
|
|
|
|
|
|
|
AP_InternalError &internalerror()
|
|
|
|
{
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
2020-04-28 03:35:38 -03:00
|
|
|
|
|
|
|
// stack overflow hook for low level RTOS code, C binding
|
|
|
|
void AP_stack_overflow(const char *thread_name)
|
|
|
|
{
|
|
|
|
static bool done_stack_overflow;
|
|
|
|
AP::internalerror().error(AP_InternalError::error_t::stack_overflow);
|
|
|
|
if (!done_stack_overflow) {
|
|
|
|
// we don't want to record the thread name more than once, as
|
|
|
|
// first overflow can trigger a 2nd
|
|
|
|
strncpy(hal.util->persistent_data.thread_name4, thread_name, 4);
|
|
|
|
done_stack_overflow = true;
|
|
|
|
}
|
|
|
|
hal.util->persistent_data.fault_type = 42; // magic value
|
|
|
|
if (!hal.util->get_soft_armed()) {
|
|
|
|
AP_HAL::panic("stack overflow %s\n", thread_name);
|
|
|
|
}
|
|
|
|
}
|