diff options
-rw-r--r-- | libmaple/exc.c | 12 | ||||
-rw-r--r-- | libmaple/libmaple.h | 6 | ||||
-rw-r--r-- | libmaple/util.h | 23 |
3 files changed, 31 insertions, 10 deletions
diff --git a/libmaple/exc.c b/libmaple/exc.c index dd02476..a5c67fa 100644 --- a/libmaple/exc.c +++ b/libmaple/exc.c @@ -24,7 +24,7 @@ * ****************************************************************************/
/**
- * @brief libmaple exception handlers. If MAPLE_DEBUG is set, then these
+ * @brief libmaple exception handlers. If DEBUG_LEVEL > DEBUG_FAULT, then these
* exceptions will ASSERT fail and call into the default _fail() light
* blinking.
*/
@@ -32,31 +32,31 @@ #include "util.h"
void NMIException(void) {
- ASSERT(0);
+ ASSERT_FAULT(0);
while(1)
;
}
void HardFaultException(void) {
- ASSERT(0);
+ ASSERT_FAULT(0);
while(1)
;
}
void MemManageException(void) {
- ASSERT(0);
+ ASSERT_FAULT(0);
while(1)
;
}
void BusFaultException(void) {
- ASSERT(0);
+ ASSERT_FAULT(0);
while(1)
;
}
void UsageFaultException(void) {
- ASSERT(0);
+ ASSERT_FAULT(0);
while(1)
;
}
diff --git a/libmaple/libmaple.h b/libmaple/libmaple.h index db05c96..c5763c8 100644 --- a/libmaple/libmaple.h +++ b/libmaple/libmaple.h @@ -34,7 +34,11 @@ #include "libmaple_types.h" // General configuration -#define MAPLE_DEBUG 1 +#ifndef DEBUG_LEVEL + //#define DEBUG_LEVEL DEBUG_ALL + #define DEBUG_LEVEL DEBUG_FAULT + //#define DEBUG_LEVEL DEBUG_NONE +#endif // MCU-specific configuration #ifdef MCU_STM32F103RB diff --git a/libmaple/util.h b/libmaple/util.h index 053731a..63e305d 100644 --- a/libmaple/util.h +++ b/libmaple/util.h @@ -32,6 +32,8 @@ #ifndef _UTIL_H_ #define _UTIL_H_ +#include "libmaple.h" + #define BIT(shift) (1 << (shift)) #define BIT_MASK_SHIFT(mask, shift) ((mask) << (shift)) @@ -70,9 +72,14 @@ void _fail(const char*, int, const char*); #endif -/* Assert for sanity checks, undefine MAPLE_DEBUG to compile - * out these checks */ -#if MAPLE_DEBUG +// Asserts for sanity checks, redefine DEBUG_LEVEL in libmaple.h to compile out +// these checks + +#define DEBUG_NONE 0 +#define DEBUG_FAULT 1 +#define DEBUG_ALL 2 + +#if DEBUG_LEVEL >= DEBUG_ALL #define ASSERT(exp) \ if (exp) \ {} \ @@ -82,5 +89,15 @@ void _fail(const char*, int, const char*); #define ASSERT(exp) (void)((0)) #endif +#if DEBUG_LEVEL >= DEBUG_FAULT +#define ASSERT_FAULT(exp) \ + if (exp) \ + {} \ + else \ + _fail(__FILE__, __LINE__, #exp) +#else +#define ASSERT_FAULT(exp) (void)((0)) +#endif + #endif |