[FL-2892] Gui: update statusbar attention icon and better crash handling (#1908)

* Gui: update statusbar attention icon
* Furi: snapshot registers on crash and restore in halt
* Furi: document check routines
This commit is contained in:
あく
2022-10-23 00:21:10 +09:00
committed by GitHub
parent c1bb10a694
commit f8af0c1509
6 changed files with 78 additions and 29 deletions

View File

@@ -11,6 +11,9 @@
#include <stdio.h>
#include <stdlib.h>
PLACE_IN_SECTION("MB_MEM2") const char* __furi_check_message = NULL;
PLACE_IN_SECTION("MB_MEM2") uint32_t __furi_check_registers[12] = {0};
extern size_t xPortGetTotalHeapSize(void);
extern size_t xPortGetFreeHeapSize(void);
extern size_t xPortGetMinimumEverFreeHeapSize(void);
@@ -52,8 +55,10 @@ static void __furi_print_name(bool isr) {
}
}
static FURI_NORETURN void __furi_halt() {
static FURI_NORETURN void __furi_halt_mcu() {
register const void* r12 asm ("r12") = (void*)__furi_check_registers;
asm volatile(
"ldm r12, {r0-r11} \n"
#ifdef FURI_DEBUG
"bkpt 0x00 \n"
#endif
@@ -61,22 +66,29 @@ static FURI_NORETURN void __furi_halt() {
"wfi \n"
"b loop%= \n"
:
:
: "r" (r12)
: "memory");
__builtin_unreachable();
}
FURI_NORETURN void furi_crash(const char* message) {
FURI_NORETURN void __furi_crash() {
register const void* r12 asm ("r12") = (void*)__furi_check_registers;
asm volatile(
"stm r12, {r0-r11} \n"
:
: "r" (r12)
: "memory");
bool isr = FURI_IS_ISR();
__disable_irq();
if(message == NULL) {
message = "Fatal Error";
if(__furi_check_message == NULL) {
__furi_check_message = "Fatal Error";
}
furi_hal_console_puts("\r\n\033[0;31m[CRASH]");
__furi_print_name(isr);
furi_hal_console_puts(message);
furi_hal_console_puts(__furi_check_message);
if(!isr) {
__furi_print_stack_info();
@@ -86,9 +98,9 @@ FURI_NORETURN void furi_crash(const char* message) {
#ifdef FURI_DEBUG
furi_hal_console_puts("\r\nSystem halted. Connect debugger for more info\r\n");
furi_hal_console_puts("\033[0m\r\n");
__furi_halt();
__furi_halt_mcu();
#else
furi_hal_rtc_set_fault_data((uint32_t)message);
furi_hal_rtc_set_fault_data((uint32_t)__furi_check_message);
furi_hal_console_puts("\r\nRebooting system.\r\n");
furi_hal_console_puts("\033[0m\r\n");
furi_hal_power_reset();
@@ -96,18 +108,25 @@ FURI_NORETURN void furi_crash(const char* message) {
__builtin_unreachable();
}
FURI_NORETURN void furi_halt(const char* message) {
FURI_NORETURN void __furi_halt() {
register const void* r12 asm ("r12") = (void*)__furi_check_registers;
asm volatile(
"stm r12, {r0-r11} \n"
:
: "r" (r12)
: "memory");
bool isr = FURI_IS_ISR();
__disable_irq();
if(message == NULL) {
message = "System halt requested.";
if(__furi_check_message == NULL) {
__furi_check_message = "System halt requested.";
}
furi_hal_console_puts("\r\n\033[0;31m[HALT]");
__furi_print_name(isr);
furi_hal_console_puts(message);
furi_hal_console_puts(__furi_check_message);
furi_hal_console_puts("\r\nSystem halted. Bye-bye!\r\n");
furi_hal_console_puts("\033[0m\r\n");
__furi_halt();
__furi_halt_mcu();
}

View File

@@ -8,25 +8,52 @@ extern "C" {
#define FURI_NORETURN noreturn
#endif
/** Pointer to pass message to __furi_crash and __furi_halt */
extern const char* __furi_check_message;
/** Crash system */
FURI_NORETURN void __furi_crash();
/** Halt system */
FURI_NORETURN void __furi_halt();
/** Crash system with message. Show message after reboot. */
#define furi_crash(message) \
do { \
__furi_check_message = message; \
__furi_crash(); \
} while(0)
/** Halt system with message. */
#define furi_halt(message) \
do { \
__furi_check_message = message; \
__furi_halt(); \
} while(0)
/** Check condition and crash if check failed */
#define furi_check(__e) ((__e) ? (void)0 : furi_crash("furi_check failed\r\n"))
#define furi_check(__e) \
do { \
if ((__e) == 0) { \
furi_crash("furi_check failed\r\n"); \
} \
} while(0)
/** Only in debug build: Assert condition and crash if assert failed */
#ifdef FURI_DEBUG
#define furi_assert(__e) ((__e) ? (void)0 : furi_crash("furi_assert failed\r\n"))
#define furi_assert(__e) \
do { \
if ((__e) == 0) { \
furi_crash("furi_assert failed\r\n"); \
} \
} while(0)
#else
#define furi_assert(__e) \
do { \
((void)(__e)); \
#define furi_assert(__e) \
do { \
((void)(__e)); \
} while(0)
#endif
/** Crash system */
FURI_NORETURN void furi_crash(const char* message);
/** Halt system */
FURI_NORETURN void furi_halt(const char* message);
#ifdef __cplusplus
}
#endif