diff options
-rw-r--r-- | builtin/assert.h | 34 | ||||
-rw-r--r-- | include/util.h | 30 |
2 files changed, 34 insertions, 30 deletions
diff --git a/builtin/assert.h b/builtin/assert.h index 7e5f04b375..2db11115a7 100644 --- a/builtin/assert.h +++ b/builtin/assert.h @@ -6,7 +6,39 @@ #ifndef __CROS_EC_ASSERT_H__ #define __CROS_EC_ASSERT_H__ -#include "util.h" +/* Include CONFIG definitions for EC sources. */ +#ifndef THIRD_PARTY +#include "common.h" +#endif + +#ifdef CONFIG_DEBUG_ASSERT +#ifdef CONFIG_DEBUG_ASSERT_REBOOTS + +#ifdef CONFIG_DEBUG_ASSERT_BRIEF +extern void panic_assert_fail(const char *fname, int linenum); +#define ASSERT(cond) do { \ + if (!(cond)) \ + panic_assert_fail(__FILE__, __LINE__); \ + } while (0) +#else +extern void panic_assert_fail(const char *msg, const char *func, + const char *fname, int linenum); +#define ASSERT(cond) do { \ + if (!(cond)) \ + panic_assert_fail(#cond, __func__, __FILE__, \ + __LINE__); \ + } while (0) +#endif +#else +#define ASSERT(cond) do { \ + if (!(cond)) \ + __asm("bkpt"); \ + } while (0) +#endif +#else +#define ASSERT(cond) +#endif + #define assert(x...) ASSERT(x) #endif /* __CROS_EC_ASSERT_H__ */ diff --git a/include/util.h b/include/util.h index fd8f5d40c9..e031148e45 100644 --- a/include/util.h +++ b/include/util.h @@ -12,37 +12,9 @@ #include "compile_time_macros.h" #include "panic.h" +#include "builtin/assert.h" /* For ASSERT(). */ #include <stddef.h> -/** - * Trigger a debug exception if the condition - * is not verified at runtime. - */ -#ifdef CONFIG_DEBUG_ASSERT -#ifdef CONFIG_DEBUG_ASSERT_REBOOTS - -#ifdef CONFIG_DEBUG_ASSERT_BRIEF -#define ASSERT(cond) do { \ - if (!(cond)) \ - panic_assert_fail(__FILE__, __LINE__); \ - } while (0) -#else -#define ASSERT(cond) do { \ - if (!(cond)) \ - panic_assert_fail(#cond, __func__, __FILE__, \ - __LINE__); \ - } while (0) -#endif -#else -#define ASSERT(cond) do { \ - if (!(cond)) \ - __asm("bkpt"); \ - } while (0) -#endif -#else -#define ASSERT(cond) -#endif - /* Standard macros / definitions */ #ifndef MAX #define MAX(a, b) \ |