summaryrefslogtreecommitdiff
path: root/tinyusb/common
diff options
context:
space:
mode:
authorhathach <[email protected]>2018-03-28 14:49:00 +0700
committerhathach <[email protected]>2018-03-28 14:49:00 +0700
commit03a4f02b89ccd4bddbfa0b117771ca1905d9f4a6 (patch)
tree8801b27fa93787d75cc558b9e9407215b8ce2b40 /tinyusb/common
parent0d3e66fa0a274d2482d6bbb6dea80508dcd614de (diff)
rename ASSERT to TU_ASSERT to avoid name conflict
Diffstat (limited to 'tinyusb/common')
-rw-r--r--tinyusb/common/assertion.h45
-rw-r--r--tinyusb/common/verify.h2
2 files changed, 12 insertions, 35 deletions
diff --git a/tinyusb/common/assertion.h b/tinyusb/common/assertion.h
index a3218b5f1..31ae04d30 100644
--- a/tinyusb/common/assertion.h
+++ b/tinyusb/common/assertion.h
@@ -68,30 +68,18 @@ extern "C"
//--------------------------------------------------------------------+
// Assert Helper
//--------------------------------------------------------------------+
-#ifndef _TEST_
- #define _ASSERT_MESSAGE(format, ...) _PRINTF("Assert at %s: %s: %d: " format "\n", __BASE_FILE__, __func__ , __LINE__, __VA_ARGS__)
-#else // TODO remove this
- #define _ASSERT_MESSAGE(format, ...) _PRINTF("%d:note: Assert " format "\n", __LINE__, __VA_ARGS__)
-#endif
-
-#ifndef _TEST_ASSERT_
- #define ASSERT_ERROR_HANDLER(x, para) return x
-#else
- #define ASSERT_ERROR_HANDLER(x, para) Throw(x)
-#endif
+#define _ASSERT_MESSAGE(format, ...) _PRINTF("Assert at %s: %s: %d: " format "\n", __BASE_FILE__, __func__ , __LINE__, __VA_ARGS__)
-#define ASSERT_DEFINE_WITH_HANDLER(error_handler, handler_para, setup_statement, condition, error, format, ...) \
+#define ASSERT_DEFINE(setup_statement, condition, error, format, ...) \
do{\
setup_statement;\
if (!(condition)) {\
tusb_hal_dbg_breakpoint();\
_ASSERT_MESSAGE(format, __VA_ARGS__);\
- error_handler(error, handler_para);\
+ return error; /* Throw X for Test */\
}\
}while(0)
-#define ASSERT_DEFINE(...) ASSERT_DEFINE_WITH_HANDLER(ASSERT_ERROR_HANDLER, NULL, __VA_ARGS__)
-
//--------------------------------------------------------------------+
// tusb_error_t Status Assert TODO use ASSERT_DEFINE
//--------------------------------------------------------------------+
@@ -106,33 +94,22 @@ extern "C"
//--------------------------------------------------------------------+
// Logical Assert
//--------------------------------------------------------------------+
-#define ASSERT(...) ASSERT_TRUE(__VA_ARGS__)
-#define ASSERT_TRUE(condition , error) ASSERT_DEFINE( , (condition), error, "%s", "evaluated to false")
#define ASSERT_FAILED(error) ASSERT_DEFINE( , false, error, "%s", "FAILED")
//--------------------------------------------------------------------+
-// Pointer Assert
-//--------------------------------------------------------------------+
-#define ASSERT_PTR(...) ASSERT_PTR_NOT_NULL(__VA_ARGS__)
-#define ASSERT_PTR_NOT_NULL(pointer, error) ASSERT_DEFINE( , NULL != (pointer), error, "%s", "pointer is NULL")
-#define ASSERT_PTR_NULL(pointer, error) ASSERT_DEFINE( , NULL == (pointer), error, "%s", "pointer is not NULL")
-
-//--------------------------------------------------------------------+
// Integral Assert
//--------------------------------------------------------------------+
#define ASSERT_XXX_EQUAL(type_format, expected, actual, error) \
- ASSERT_DEFINE(\
- uint32_t exp = (expected); uint32_t act = (actual),\
- exp==act,\
- error,\
- "expected " type_format ", actual " type_format, exp, act)
+ ASSERT_DEFINE( uint32_t exp = (expected); uint32_t act = (actual),\
+ exp==act,\
+ error,\
+ "expected " type_format ", actual " type_format, exp, act)
#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)
+ 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
diff --git a/tinyusb/common/verify.h b/tinyusb/common/verify.h
index a5eeb5ae8..9fe52ad83 100644
--- a/tinyusb/common/verify.h
+++ b/tinyusb/common/verify.h
@@ -57,7 +57,7 @@
#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 _ASSERT_MESS() printf("%s: %d: assert failed\n", __PRETTY_FUNCTION__, __LINE__);
#else
#define _VERIFY_MESS(_status)
#define _ASSERT_MESS()