diff options
| author | hathach <[email protected]> | 2018-03-28 15:23:33 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2018-03-28 15:24:55 +0700 |
| commit | ccf6f03817daf860173a41d72454ae23b2eab974 (patch) | |
| tree | 1aa8d830966e87c7450a6f0ad6fd1201a112db90 /tinyusb/common | |
| parent | 03a4f02b89ccd4bddbfa0b117771ca1905d9f4a6 (diff) | |
add verify_breakpoint hw independence
Diffstat (limited to 'tinyusb/common')
| -rw-r--r-- | tinyusb/common/assertion.h | 4 | ||||
| -rw-r--r-- | tinyusb/common/verify.h | 28 |
2 files changed, 24 insertions, 8 deletions
diff --git a/tinyusb/common/assertion.h b/tinyusb/common/assertion.h index 31ae04d30..c16e7d1a3 100644 --- a/tinyusb/common/assertion.h +++ b/tinyusb/common/assertion.h @@ -54,8 +54,6 @@ extern "C" #include "tusb_option.h"
#include "tusb_compiler.h"
-#include "tusb_hal.h" // TODO find a way to break hal dependency
-
#define VOID_RETURN
//#if ( defined CFG_PRINTF_UART || defined CFG_PRINTF_USBCDC || defined CFG_PRINTF_DEBUG )
@@ -74,7 +72,7 @@ extern "C" do{\
setup_statement;\
if (!(condition)) {\
- tusb_hal_dbg_breakpoint();\
+ verify_breakpoint();\
_ASSERT_MESSAGE(format, __VA_ARGS__);\
return error; /* Throw X for Test */\
}\
diff --git a/tinyusb/common/verify.h b/tinyusb/common/verify.h index 9fe52ad83..07ff71793 100644 --- a/tinyusb/common/verify.h +++ b/tinyusb/common/verify.h @@ -63,6 +63,24 @@ #define _ASSERT_MESS() #endif +// Halt CPU (breakpoint) when hitting error, only apply for Cortex M3, M4, M7 +#if defined(__ARM_ARCH_7M__) || defined (__ARM_ARCH_7EM__) + +// Cortex M CoreDebug->DHCSR +#define ARM_CM_DHCSR (*((volatile uint32_t*) 0xE000EDF0UL)) + +static inline void verify_breakpoint(void) +{ + // Only halt mcu if debugger is attached + if ( ARM_CM_DHCSR & 1UL ) __asm("BKPT #0\n"); +} + +#else + +#define verify_breakpoint() + +#endif + /*------------------------------------------------------------------*/ /* VERIFY STATUS * - VERIFY_STS_1ARGS : return status of condition if failed @@ -95,13 +113,13 @@ #define VERIFY_STS_HDLR_2ARGS(sts, _handler) \ do { \ uint32_t _status = (uint32_t)(sts); \ - if ( 0 != _status ) { tusb_hal_dbg_breakpoint(); _VERIFY_MESS(_status) _handler; return _status; }\ + if ( 0 != _status ) { verify_breakpoint(); _VERIFY_MESS(_status) _handler; return _status; }\ } while(0) #define VERIFY_STS_HDLR_3ARGS(sts, _handler, _error) \ do { \ uint32_t _status = (uint32_t)(sts); \ - if ( 0 != _status ) { tusb_hal_dbg_breakpoint(); _VERIFY_MESS(_status) _handler; return _error; }\ + if ( 0 != _status ) { verify_breakpoint(); _VERIFY_MESS(_status) _handler; return _error; }\ } while(0) #define VERIFY_STATUS_HDLR(...) GET_4TH_ARG(__VA_ARGS__, VERIFY_STS_HDLR_3ARGS, VERIFY_STS_HDLR_2ARGS)(__VA_ARGS__) @@ -137,12 +155,12 @@ /*------------------------------------------------------------------*/ /* ASSERT - * basically VERIFY with tusb_hal_dbg_breakpoint as handler + * basically VERIFY with verify_breakpoint as handler * - 1 arg : return false if failed * - 2 arg : return error if failed *------------------------------------------------------------------*/ -#define ASSERT_1ARGS(cond) do { if (!(cond)) { tusb_hal_dbg_breakpoint(); _ASSERT_MESS() return false; } } while(0) -#define ASSERT_2ARGS(cond, _error) do { if (!(cond)) { tusb_hal_dbg_breakpoint(); _ASSERT_MESS() return _error;} } while(0) +#define ASSERT_1ARGS(cond) do { if (!(cond)) { verify_breakpoint(); _ASSERT_MESS() return false; } } while(0) +#define ASSERT_2ARGS(cond, _error) do { if (!(cond)) { verify_breakpoint(); _ASSERT_MESS() return _error;} } while(0) #define TU_ASSERT(...) GET_3RD_ARG(__VA_ARGS__, ASSERT_2ARGS, ASSERT_1ARGS)(__VA_ARGS__) |
