check.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #pragma once
  2. #ifdef __cplusplus
  3. extern "C" {
  4. #define FURI_NORETURN [[noreturn]]
  5. #else
  6. #include <stdnoreturn.h>
  7. #define FURI_NORETURN noreturn
  8. #endif
  9. /** Pointer to pass message to __furi_crash and __furi_halt */
  10. extern const char* __furi_check_message;
  11. /** Crash system */
  12. FURI_NORETURN void __furi_crash();
  13. /** Halt system */
  14. FURI_NORETURN void __furi_halt();
  15. /** Crash system with message. Show message after reboot. */
  16. #define furi_crash(message) \
  17. do { \
  18. __furi_check_message = message; \
  19. __furi_crash(); \
  20. } while(0)
  21. /** Halt system with message. */
  22. #define furi_halt(message) \
  23. do { \
  24. __furi_check_message = message; \
  25. __furi_halt(); \
  26. } while(0)
  27. /** Check condition and crash if check failed */
  28. #define furi_check(__e) \
  29. do { \
  30. if ((__e) == 0) { \
  31. furi_crash("furi_check failed\r\n"); \
  32. } \
  33. } while(0)
  34. /** Only in debug build: Assert condition and crash if assert failed */
  35. #ifdef FURI_DEBUG
  36. #define furi_assert(__e) \
  37. do { \
  38. if ((__e) == 0) { \
  39. furi_crash("furi_assert failed\r\n"); \
  40. } \
  41. } while(0)
  42. #else
  43. #define furi_assert(__e) \
  44. do { \
  45. ((void)(__e)); \
  46. } while(0)
  47. #endif
  48. #ifdef __cplusplus
  49. }
  50. #endif