Skip to content

Commit

Permalink
core/assert: halt running thread instead of panic
Browse files Browse the repository at this point in the history
  • Loading branch information
benpicco committed Apr 26, 2024
1 parent 3359f26 commit 08b6435
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions core/lib/assert.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ __NORETURN static inline void _assert_common(void)
#ifdef DEBUG_ASSERT_BREAKPOINT
DEBUG_BREAKPOINT(1);
#endif
if (DEBUG_ASSERT_NO_PANIC && !irq_is_in()) {
puts("FAILED ASSERTION.");
while (1) {
thread_sleep();
}
}
core_panic(PANIC_ASSERT_FAIL, "FAILED ASSERTION.");
}

Expand Down
9 changes: 9 additions & 0 deletions core/lib/include/assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,15 @@ __NORETURN void _assert_panic(void);
#endif
#endif

/**
* @brief Don't panic on a failed assertion, just halt the running thread.
*
* If the assertion failed in an interrupt, the system will still panic.
*/
#ifndef DEBUG_ASSERT_NO_PANIC
#define DEBUG_ASSERT_NO_PANIC (1)
#endif

#ifdef __cplusplus
}
#endif
Expand Down

0 comments on commit 08b6435

Please sign in to comment.