|
|
|
|
@@ -61,9 +61,8 @@
|
|
|
|
|
// VERIFY Helper
|
|
|
|
|
//--------------------------------------------------------------------+
|
|
|
|
|
#if TUSB_CFG_DEBUG >= 1
|
|
|
|
|
// #define _VERIFY_MESS(format, ...) cprintf("[%08ld] %s: %d: verify failed\n", get_millis(), __func__, __LINE__)
|
|
|
|
|
#define _VERIFY_MESS(_status) printf("%s: %d: verify failed, error = %s\n", __PRETTY_FUNCTION__, __LINE__, tusb_strerr[_status]);
|
|
|
|
|
#define _ASSERT_MESS() printf("%s: %d: assert failed\n", __PRETTY_FUNCTION__, __LINE__);
|
|
|
|
|
#define _VERIFY_MESS(_status) printf("%s: %d: failed, error = %s\n", __PRETTY_FUNCTION__, __LINE__, tusb_strerr[_status])
|
|
|
|
|
#define _FAILED_MESS() printf("%s: %d: failed\n", __PRETTY_FUNCTION__, __LINE__)
|
|
|
|
|
#else
|
|
|
|
|
#define _VERIFY_MESS(_status)
|
|
|
|
|
#define _ASSERT_MESS()
|
|
|
|
|
@@ -94,19 +93,19 @@ static inline void verify_breakpoint(void)
|
|
|
|
|
#define GET_4TH_ARG(arg1, arg2, arg3, arg4, ...) arg4
|
|
|
|
|
|
|
|
|
|
/*------------- Generator for VERIFY and VERIFY_HDLR -------------*/
|
|
|
|
|
#define VERIFY_DEFINE(_cond, _handler, _error) do { if ( !(_cond) ) { _handler return _error; } } while(0)
|
|
|
|
|
#define VERIFY_DEFINE(_cond, _handler, _error) do { if ( !(_cond) ) { _handler; return _error; } } while(0)
|
|
|
|
|
|
|
|
|
|
/*------------- Generator for VERIFY_STATUS and VERIFY_STATUS_HDLR -------------*/
|
|
|
|
|
#define VERIFY_STS_DEF2(sts, _handler) \
|
|
|
|
|
do { \
|
|
|
|
|
uint32_t _status = (uint32_t)(sts); \
|
|
|
|
|
if ( 0 != _status ) { _VERIFY_MESS(_status) _handler return _status; }\
|
|
|
|
|
if ( 0 != _status ) { _VERIFY_MESS(_status); _handler; return _status; }\
|
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
|
|
#define VERIFY_STS_DEF3(sts, _handler, _error) \
|
|
|
|
|
do { \
|
|
|
|
|
uint32_t _status = (uint32_t)(sts); \
|
|
|
|
|
if ( 0 != _status ) { _VERIFY_MESS(_status) _handler return _error; }\
|
|
|
|
|
if ( 0 != _status ) { _VERIFY_MESS(_status); _handler; return _error; }\
|
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -128,8 +127,8 @@ static inline void verify_breakpoint(void)
|
|
|
|
|
* - VERIFY_HDLR_2ARGS : execute handler, return false if failed
|
|
|
|
|
* - VERIFY_HDLR_3ARGS : execute handler, return provided error if failed
|
|
|
|
|
*------------------------------------------------------------------*/
|
|
|
|
|
#define VERIFY_HDLR_2ARGS(cond, _handler) VERIFY_DEFINE(cond, _handler; , false)
|
|
|
|
|
#define VERIFY_HDLR_3ARGS(cond, _handler, _error) VERIFY_DEFINE(cond, _handler; , _error)
|
|
|
|
|
#define VERIFY_HDLR_2ARGS(cond, _handler) VERIFY_DEFINE(cond, _handler, false)
|
|
|
|
|
#define VERIFY_HDLR_3ARGS(cond, _handler, _error) VERIFY_DEFINE(cond, _handler, _error)
|
|
|
|
|
|
|
|
|
|
#define VERIFY_HDLR(...) GET_4TH_ARG(__VA_ARGS__, VERIFY_HDLR_3ARGS, VERIFY_HDLR_2ARGS)(__VA_ARGS__)
|
|
|
|
|
|
|
|
|
|
@@ -149,8 +148,8 @@ static inline void verify_breakpoint(void)
|
|
|
|
|
* - VERIFY_STS_HDLR_2ARGS : execute handler, return status if failed
|
|
|
|
|
* - VERIFY_STS_HDLR_3ARGS : execute handler, return provided error if failed
|
|
|
|
|
*------------------------------------------------------------------*/
|
|
|
|
|
#define VERIFY_STS_HDLR_2ARGS(sts, _handler) VERIFY_STS_DEF2(sts, _handler;)
|
|
|
|
|
#define VERIFY_STS_HDLR_3ARGS(sts, _handler, _error) VERIFY_STS_DEF3(sts, _handler; , _error)
|
|
|
|
|
#define VERIFY_STS_HDLR_2ARGS(sts, _handler) VERIFY_STS_DEF2(sts, _handler)
|
|
|
|
|
#define VERIFY_STS_HDLR_3ARGS(sts, _handler, _error) VERIFY_STS_DEF3(sts, _handler, _error)
|
|
|
|
|
|
|
|
|
|
#define VERIFY_STATUS_HDLR(...) GET_4TH_ARG(__VA_ARGS__, VERIFY_STS_HDLR_3ARGS, VERIFY_STS_HDLR_2ARGS)(__VA_ARGS__)
|
|
|
|
|
|
|
|
|
|
@@ -162,8 +161,8 @@ static inline void verify_breakpoint(void)
|
|
|
|
|
* - 1 arg : return false if failed
|
|
|
|
|
* - 2 arg : return error if failed
|
|
|
|
|
*------------------------------------------------------------------*/
|
|
|
|
|
#define ASSERT_1ARGS(cond) VERIFY_DEFINE(cond, verify_breakpoint(); , false)
|
|
|
|
|
#define ASSERT_2ARGS(cond, _error) VERIFY_DEFINE(cond, verify_breakpoint(); , _error)
|
|
|
|
|
#define ASSERT_1ARGS(cond) VERIFY_DEFINE(cond, _FAILED_MESS(); verify_breakpoint(), false)
|
|
|
|
|
#define ASSERT_2ARGS(cond, _error) VERIFY_DEFINE(cond, _FAILED_MESS(); verify_breakpoint(), _error)
|
|
|
|
|
|
|
|
|
|
#define TU_ASSERT(...) GET_3RD_ARG(__VA_ARGS__, ASSERT_2ARGS, ASSERT_1ARGS)(__VA_ARGS__)
|
|
|
|
|
|
|
|
|
|
@@ -171,8 +170,8 @@ static inline void verify_breakpoint(void)
|
|
|
|
|
/* ASSERT Error
|
|
|
|
|
* basically VERIFY Error with verify_breakpoint() as handler
|
|
|
|
|
*------------------------------------------------------------------*/
|
|
|
|
|
#define ASERT_ERR_1ARGS(_err) VERIFY_STS_DEF2(_err, verify_breakpoint();)
|
|
|
|
|
#define ASERT_ERR_2ARGS(_err, _ret) VERIFY_STS_DEF3(_err, verify_breakpoint();, _ret)
|
|
|
|
|
#define ASERT_ERR_1ARGS(_err) VERIFY_STS_DEF2(_err, verify_breakpoint())
|
|
|
|
|
#define ASERT_ERR_2ARGS(_err, _ret) VERIFY_STS_DEF3(_err, verify_breakpoint(), _ret)
|
|
|
|
|
|
|
|
|
|
#define ASSERT_ERR(...) GET_3RD_ARG(__VA_ARGS__, ASERT_ERR_2ARGS, ASERT_ERR_1ARGS)(__VA_ARGS__)
|
|
|
|
|
|
|
|
|
|
|