mirror of
https://github.com/hathach/tinyusb.git
synced 2025-02-19 06:40:45 +00:00
more verify and assert clean up
This commit is contained in:
parent
1d33d4e072
commit
d63d5d6160
@ -85,26 +85,6 @@ extern "C"
|
||||
ASSERT_DEFINE(tusb_error_t status = (tusb_error_t)(sts),\
|
||||
TUSB_ERROR_NONE == status, status, "%s", tusb_strerr[status])
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Integral Assert
|
||||
//--------------------------------------------------------------------+
|
||||
#define ASSERT_XXX_WITHIN(type_format, lower, upper, actual, error) \
|
||||
ASSERT_DEFINE( uint32_t low = (lower); uint32_t up = (upper); uint32_t act = (actual),\
|
||||
(low <= act) && (act <= up),\
|
||||
error,\
|
||||
"expected within " type_format " - " type_format ", actual " type_format, low, up, act)
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Integer Assert
|
||||
//--------------------------------------------------------------------+
|
||||
#define ASSERT_INT_WITHIN(...) ASSERT_XXX_WITHIN("%d", __VA_ARGS__)
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Hex Assert
|
||||
//--------------------------------------------------------------------+
|
||||
#define ASSERT_HEX_WITHIN(...) ASSERT_XXX_WITHIN("0x%x", __VA_ARGS__)
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -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__)
|
||||
|
||||
|
@ -958,7 +958,7 @@ static void qhd_init(ehci_qhd_t *p_qhd, uint8_t dev_addr, uint16_t max_packet_si
|
||||
{
|
||||
if (TUSB_SPEED_HIGH == p_qhd->endpoint_speed)
|
||||
{
|
||||
ASSERT_INT_WITHIN(1, 16, interval, VOID_RETURN);
|
||||
TU_ASSERT( interval <= 16, VOID_RETURN);
|
||||
if ( interval < 4) // sub milisecond interval
|
||||
{
|
||||
p_qhd->interval_ms = 0;
|
||||
|
@ -128,7 +128,7 @@ static inline uint8_t get_configure_number_for_device(tusb_desc_device_t* dev_de
|
||||
//--------------------------------------------------------------------+
|
||||
tusb_device_state_t tuh_device_get_state (uint8_t const dev_addr)
|
||||
{
|
||||
ASSERT_INT_WITHIN(1, TUSB_CFG_HOST_DEVICE_MAX, dev_addr, TUSB_DEVICE_STATE_INVALID_PARAMETER);
|
||||
TU_ASSERT( dev_addr <= TUSB_CFG_HOST_DEVICE_MAX, TUSB_DEVICE_STATE_INVALID_PARAMETER);
|
||||
return (tusb_device_state_t) usbh_devices[dev_addr].state;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user