diff options
| author | hathach <[email protected]> | 2019-10-24 13:17:01 +0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2019-10-24 13:17:01 +0700 |
| commit | 5d975d93139e0ce346372dc07ca34ef9df7b0287 (patch) | |
| tree | 8661248bd0392312a212dd02e07b06f6fa248da8 /src/common | |
| parent | e413c9efa303d70de019a91aa415384fe80ca78f (diff) | |
| parent | 6f952a8e84acfbc962cf3d37ed72bddefebaf58b (diff) | |
Merge pull request #203 from hathach/develop
add log support using uart with CFG_TUSB_DEBUG >= 2, close #200
Diffstat (limited to 'src/common')
| -rw-r--r-- | src/common/tusb_common.h | 44 | ||||
| -rw-r--r-- | src/common/tusb_compiler.h | 7 | ||||
| -rw-r--r-- | src/common/tusb_verify.h | 51 |
3 files changed, 60 insertions, 42 deletions
diff --git a/src/common/tusb_common.h b/src/common/tusb_common.h index 57c6e2fcf..59e1fe7fd 100644 --- a/src/common/tusb_common.h +++ b/src/common/tusb_common.h @@ -35,7 +35,7 @@ extern "C" {
#endif
- //--------------------------------------------------------------------+
+//--------------------------------------------------------------------+
// Macros Helper
//--------------------------------------------------------------------+
#define TU_ARRAY_SIZE(_arr) ( sizeof(_arr) / sizeof(_arr[0]) )
@@ -58,7 +58,7 @@ #define TU_BIT(n) (1U << (n))
//--------------------------------------------------------------------+
-// INCLUDES
+// Includes
//--------------------------------------------------------------------+
// Standard Headers
@@ -77,7 +77,7 @@ #include "tusb_types.h"
//--------------------------------------------------------------------+
-// INLINE FUNCTION
+// Inline Functions
//--------------------------------------------------------------------+
#define tu_memclr(buffer, size) memset((buffer), 0, (size))
#define tu_varclr(_var) tu_memclr(_var, sizeof(*(_var)))
@@ -203,6 +203,44 @@ static inline bool tu_bit_test (uint32_t value, uint8_t n) { return (value & + TU_BIN8(dlsb))
#endif
+//--------------------------------------------------------------------+
+// Debug Function
+//--------------------------------------------------------------------+
+
+// CFG_TUSB_DEBUG for debugging
+// 0 : no debug
+// 1 : print when there is error
+// 2 : print out log
+#if CFG_TUSB_DEBUG
+
+void tu_print_mem(void const *buf, uint8_t size, uint16_t count);
+
+#ifndef tu_printf
+ #define tu_printf printf
+#endif
+
+// Log with debug level 1
+#define TU_LOG1 tu_printf
+#define TU_LOG1_MEM tu_print_mem
+
+// Log with debug level 2
+#if CFG_TUSB_DEBUG > 1
+ #define TU_LOG2 TU_LOG1
+ #define TU_LOG2_MEM TU_LOG1_MEM
+#endif
+
+#endif // CFG_TUSB_DEBUG
+
+#ifndef TU_LOG1
+ #define TU_LOG1(...)
+ #define TU_LOG1_MEM(...)
+#endif
+
+#ifndef TU_LOG2
+ #define TU_LOG2(...)
+ #define TU_LOG2_MEM(...)
+#endif
+
#ifdef __cplusplus
}
#endif
diff --git a/src/common/tusb_compiler.h b/src/common/tusb_compiler.h index 58732b871..0bac3eae7 100644 --- a/src/common/tusb_compiler.h +++ b/src/common/tusb_compiler.h @@ -67,6 +67,7 @@ #define TU_ATTR_WEAK __attribute__ ((weak))
#define TU_ATTR_DEPRECATED(mess) __attribute__ ((deprecated(mess))) // warn if function with this attribute is used
#define TU_ATTR_UNUSED __attribute__ ((unused)) // Function/Variable is meant to be possibly unused
+ #define TU_ATTR_USED __attribute__ ((used)) // Function/Variable is meant to be used
// Endian conversion use well-known host to network (big endian) naming
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
@@ -75,8 +76,8 @@ #define TU_BYTE_ORDER TU_BIG_ENDIAN
#endif
-#define TU_BSWAP16(u16) (__builtin_bswap16(u16))
-#define TU_BSWAP32(u32) (__builtin_bswap32(u32))
+ #define TU_BSWAP16(u16) (__builtin_bswap16(u16))
+ #define TU_BSWAP32(u32) (__builtin_bswap32(u32))
#elif defined(__TI_COMPILER_VERSION__)
#define TU_ATTR_ALIGNED(Bytes) __attribute__ ((aligned(Bytes)))
@@ -86,6 +87,7 @@ #define TU_ATTR_WEAK __attribute__ ((weak))
#define TU_ATTR_DEPRECATED(mess) __attribute__ ((deprecated(mess))) // warn if function with this attribute is used
#define TU_ATTR_UNUSED __attribute__ ((unused)) // Function/Variable is meant to be possibly unused
+ #define TU_ATTR_USED __attribute__ ((used))
// __BYTE_ORDER is defined in the TI ARM compiler, but not MSP430 (which is little endian)
#if ((__BYTE_ORDER__) == (__ORDER_LITTLE_ENDIAN__)) || defined(__MSP430__)
@@ -123,7 +125,6 @@ #define tu_htonl(u32) (u32)
#define tu_ntohl(u32) (u32)
-
#define tu_htole16(u16) (tu_bswap16(u16))
#define tu_le16toh(u16) (tu_bswap16(u16))
diff --git a/src/common/tusb_verify.h b/src/common/tusb_verify.h index fae0c88ae..e59481352 100644 --- a/src/common/tusb_verify.h +++ b/src/common/tusb_verify.h @@ -107,20 +107,6 @@ if ( !(_cond) ) { _handler; return _ret; } \ } while(0) -/*------------- Generator for TU_VERIFY_ERR and TU_VERIFY_ERR_HDLR -------------*/ -#define TU_VERIFY_ERR_DEF2(_error, _handler) do \ -{ \ - uint32_t _err = (uint32_t)(_error); \ - if ( 0 != _err ) { _MESS_ERR(_err); _handler; return _err; } \ -} while(0) - -#define TU_VERIFY_ERR_DEF3(_error, _handler, _ret) do \ -{ \ - uint32_t _err = (uint32_t)(_error); \ - if ( 0 != _err ) { _MESS_ERR(_err); _handler; return _ret; } \ -} while(0) - - /*------------------------------------------------------------------*/ /* TU_VERIFY * - TU_VERIFY_1ARGS : return false if failed @@ -142,28 +128,6 @@ #define TU_VERIFY_HDLR(...) GET_4TH_ARG(__VA_ARGS__, TU_VERIFY_HDLR_3ARGS, TU_VERIFY_HDLR_2ARGS,UNUSED)(__VA_ARGS__) - -/*------------------------------------------------------------------*/ -/* TU_VERIFY STATUS - * - TU_VERIFY_ERR_1ARGS : return status of condition if failed - * - TU_VERIFY_ERR_2ARGS : return provided status code if failed - *------------------------------------------------------------------*/ -#define TU_VERIFY_ERR_1ARGS(_error) TU_VERIFY_ERR_DEF2(_error, ) -#define TU_VERIFY_ERR_2ARGS(_error, _ret) TU_VERIFY_ERR_DEF3(_error, ,_ret) - -#define TU_VERIFY_ERR(...) GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_ERR_2ARGS, TU_VERIFY_ERR_1ARGS,UNUSED)(__VA_ARGS__) - -/*------------------------------------------------------------------*/ -/* TU_VERIFY STATUS WITH HANDLER - * - TU_VERIFY_ERR_HDLR_2ARGS : execute handler, return status if failed - * - TU_VERIFY_ERR_HDLR_3ARGS : execute handler, return provided error if failed - *------------------------------------------------------------------*/ -#define TU_VERIFY_ERR_HDLR_2ARGS(_error, _handler) TU_VERIFY_ERR_DEF2(_error, _handler) -#define TU_VERIFY_ERR_HDLR_3ARGS(_error, _handler, _ret) TU_VERIFY_ERR_DEF3(_error, _handler, _ret) - -#define TU_VERIFY_ERR_HDLR(...) GET_4TH_ARG(__VA_ARGS__, TU_VERIFY_ERR_HDLR_3ARGS, TU_VERIFY_ERR_HDLR_2ARGS,UNUSED)(__VA_ARGS__) - - /*------------------------------------------------------------------*/ /* ASSERT * basically TU_VERIFY with TU_BREAKPOINT() as handler @@ -175,6 +139,21 @@ #define TU_ASSERT(...) GET_3RD_ARG(__VA_ARGS__, ASSERT_2ARGS, ASSERT_1ARGS,UNUSED)(__VA_ARGS__) +// TODO remove TU_ASSERT_ERR() later + +/*------------- Generator for TU_VERIFY_ERR and TU_VERIFY_ERR_HDLR -------------*/ +#define TU_VERIFY_ERR_DEF2(_error, _handler) do \ +{ \ + uint32_t _err = (uint32_t)(_error); \ + if ( 0 != _err ) { _MESS_ERR(_err); _handler; return _err; } \ +} while(0) + +#define TU_VERIFY_ERR_DEF3(_error, _handler, _ret) do \ +{ \ + uint32_t _err = (uint32_t)(_error); \ + if ( 0 != _err ) { _MESS_ERR(_err); _handler; return _ret; } \ +} while(0) + /*------------------------------------------------------------------*/ /* ASSERT Error * basically TU_VERIFY Error with TU_BREAKPOINT() as handler |
