mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2024-12-18 19:01:47 +03:00
41 lines
1.7 KiB
Markdown
41 lines
1.7 KiB
Markdown
|
# Run time checks and forced system crash
|
||
|
|
||
|
The best way to protect system integrity is to reduce amount cases that we must handle and crash the system as early as possible.
|
||
|
For that purpose we have bunch of helpers located in Furi Core check.h.
|
||
|
|
||
|
## Couple notes before start
|
||
|
|
||
|
- Definition of Crash - log event, save crash information in RTC and reboot the system.
|
||
|
- Definition of Halt - log event, stall the system.
|
||
|
- Debug and production builds behaves differently: debug build will never reset system in order to preserve state for debugging.
|
||
|
- If you have debugger connected we will stop before reboot automatically.
|
||
|
- All helpers accept optional MESSAGE_CSTR: it can be in RAM or Flash memory, but only messages from Flash will be shown after system reboot.
|
||
|
- MESSAGE_CSTR can be NULL, but macros magic already doing it for you, so just don't.
|
||
|
|
||
|
## `furi_assert(CONDITION)` or `furi_assert(CONDITION, MESSAGE_CSTR)`
|
||
|
|
||
|
Assert condition in development environment and crash the system if CONDITION is false.
|
||
|
|
||
|
- Should be used at development stage in apps and services
|
||
|
- Keep in mind that release never contains this check
|
||
|
- Keep in mind that libraries never contains this check by default, use `LIB_DEBUG=1` if you need it
|
||
|
- Avoid putting function calls into CONDITION, since it may be omitted in some builds
|
||
|
|
||
|
## `furi_check(CONDITION)` or `furi_check(CONDITION, MESSAGE_CSTR)`
|
||
|
|
||
|
Always assert condition and crash the system if CONDITION is false.
|
||
|
|
||
|
- Use it if you always need to check conditions
|
||
|
|
||
|
## `furi_crash()` or `furi_crash(MESSAGE_CSTR)`
|
||
|
|
||
|
Crash the system.
|
||
|
|
||
|
- Use it to crash the system. For example: if abnormal condition detected.
|
||
|
|
||
|
## `furi_halt()` or `furi_halt(MESSAGE_CSTR)`
|
||
|
|
||
|
Halt the system.
|
||
|
|
||
|
- We use it internally to shutdown flipper if poweroff is not possible.
|