diff options
| author | hathach <[email protected]> | 2013-01-22 17:41:06 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2013-01-22 17:41:06 +0700 |
| commit | 38ce3f7534ec9e3e0b10b8923d7d17e437463e86 (patch) | |
| tree | 4eb3c2e065610c6b1dadc14a9c98e421041c5546 /tinyusb/common | |
| parent | cfe7a3d23b4639c3578b166fc865450bc439d82c (diff) | |
start to support
- usbd host
- osal
some global define
#define TUSB_CFG_HOST_CONTROLLER_NUM
#define TUSB_CFG_HOST_DEVICE_MAX
#define TUSB_CFG_CONFIGURATION_MAX
rename & refractor HID type structure & enum
use CException to test asssertion library
add test for hid_host_keyboard with usbd configure get & osal queue get stubs
update test for assertion library
refractor ASSERT_STATUS in assertion library
update tusb_error_t values
rename usb basic type & enum in tusb_types.h and std_descriptors.h
Diffstat (limited to 'tinyusb/common')
| -rw-r--r-- | tinyusb/common/assertion.h | 45 | ||||
| -rw-r--r-- | tinyusb/common/common.h | 11 | ||||
| -rw-r--r-- | tinyusb/common/errors.h | 7 |
3 files changed, 44 insertions, 19 deletions
diff --git a/tinyusb/common/assertion.h b/tinyusb/common/assertion.h index 1891e83f2..f2812cd08 100644 --- a/tinyusb/common/assertion.h +++ b/tinyusb/common/assertion.h @@ -71,28 +71,32 @@ extern "C" #define ASSERT_FILENAME __BASE_FILE__ #define ASSERT_FUNCTION __PRETTY_FUNCTION__ #define ASSERT_STATEMENT _PRINTF("assert at %s: %s :%d :\n", ASSERT_FILENAME, ASSERT_FUNCTION, __LINE__) + +#ifndef _TEST_ASSERT_ + #define ASSERT_ERROR_HANDLE(x) return (x) +#else + #define ASSERT_ERROR_HANDLE(x) Throw(x) +#endif + #define ASSERT_DEFINE(setup_statement, condition, error, format, ...) \ do{\ setup_statement;\ if (!(condition)) {\ _PRINTF("Assert at %s: %s:%d: " format "\n", ASSERT_FILENAME, ASSERT_FUNCTION, __LINE__, __VA_ARGS__);\ - return error;\ + ASSERT_ERROR_HANDLE(error);\ }\ }while(0) //--------------------------------------------------------------------+ -// tusb_error_t Status Assert +// tusb_error_t Status Assert TODO use ASSERT_DEFINE //--------------------------------------------------------------------+ #define ASSERT_STATUS_MESSAGE(sts, message) \ - do{\ - tusb_error_t status = (tusb_error_t)(sts);\ - if (TUSB_ERROR_NONE != status) {\ - _PRINTF("Assert at %s line %d: %s %s\n", ASSERT_FILENAME, ASSERT_FUNCTION, __LINE__, TUSB_ErrorStr[status], message); \ - return status;\ - }\ - }while(0) + ASSERT_DEFINE(tusb_error_t status = (tusb_error_t)(sts),\ + TUSB_ERROR_NONE == status, status, "%s: %s", TUSB_ErrorStr[status], message) -#define ASSERT_STATUS(sts) ASSERT_STATUS_MESSAGE(sts, NULL) +#define ASSERT_STATUS(sts) \ + ASSERT_DEFINE(tusb_error_t status = (tusb_error_t)(sts),\ + TUSB_ERROR_NONE == status, status, "%s", TUSB_ErrorStr[status]) //--------------------------------------------------------------------+ // Logical Assert @@ -102,7 +106,14 @@ extern "C" #define ASSERT_FALSE(condition , error) ASSERT_DEFINE( ,!(condition), error, "%s", "evaluated to true") //--------------------------------------------------------------------+ -// Integer Assert +// 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(\ @@ -118,6 +129,9 @@ extern "C" error,\ "expected within " type_format " - " type_format ", actual " type_format, low, up, act) +//--------------------------------------------------------------------+ +// Integer Assert +//--------------------------------------------------------------------+ #define ASSERT_INT(...) ASSERT_INT_EQUAL(__VA_ARGS__) #define ASSERT_INT_EQUAL(...) ASSERT_XXX_EQUAL("%d", __VA_ARGS__) #define ASSERT_INT_WITHIN(...) ASSERT_XXX_WITHIN("%d", __VA_ARGS__) @@ -130,11 +144,12 @@ extern "C" #define ASSERT_HEX_WITHIN(...) ASSERT_XXX_WITHIN("0x%x", __VA_ARGS__) //--------------------------------------------------------------------+ -// Pointer Assert +// TODO Bin Assert +//--------------------------------------------------------------------+ + +//--------------------------------------------------------------------+ +// TODO Bit Assert //--------------------------------------------------------------------+ -#define ASSSERT_PTR(...) ASSERT_PTR_NOT_NULL(__VA_ARGS__) -#define ASSERT_PTR_NOT_NULL(pointer, error) ASSERT_DEFINE( , NULL != (pointer), error, "%s", "pointer is NULL") -#define ASSSERT_PTR_NULL(pointer, error) ASSERT_DEFINE( , NULL == (pointer), error, "%s", "pointer is NULL") #ifdef __cplusplus diff --git a/tinyusb/common/common.h b/tinyusb/common/common.h index 51ba07f97..769cd7139 100644 --- a/tinyusb/common/common.h +++ b/tinyusb/common/common.h @@ -74,15 +74,22 @@ #include "osal/osal.h" +/// form an uint32_t from 4 x uint8_t +static inline uint32_t u32_from_u8(uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4) ATTR_ALWAYS_INLINE ATTR_CONST; +static inline uint32_t u32_from_u8(uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4) +{ + return (b1 << 24) + (b2 << 16) + (b3 << 8) + b4; +} + /// min value -static inline uint32_t min_of(uint32_t x, uint32_t y) ATTR_ALWAYS_INLINE; +static inline uint32_t min_of(uint32_t x, uint32_t y) ATTR_ALWAYS_INLINE ATTR_CONST; static inline uint32_t min_of(uint32_t x, uint32_t y) { return (x < y) ? x : y; } /// max value -static inline uint32_t max_of(uint32_t x, uint32_t y) ATTR_ALWAYS_INLINE; +static inline uint32_t max_of(uint32_t x, uint32_t y) ATTR_ALWAYS_INLINE ATTR_CONST; static inline uint32_t max_of(uint32_t x, uint32_t y) { return (x > y) ? x : y; diff --git a/tinyusb/common/errors.h b/tinyusb/common/errors.h index aa373e357..e771794c1 100644 --- a/tinyusb/common/errors.h +++ b/tinyusb/common/errors.h @@ -60,7 +60,10 @@ #define ERROR_TABLE(ENTRY) \ ENTRY(TUSB_ERROR_NONE)\ - ENTRY(tERROR_FAILED)\ + ENTRY(TUSB_ERROR_INVALID_PARA)\ + ENTRY(TUSB_ERROR_CLASS_DEVICE_DONT_SUPPORT)\ + ENTRY(TUSB_ERROR_OSAL_TIMEOUT)\ + ENTRY(TUSB_ERROR_FAILED)\ /** \enum tusb_error_t @@ -68,7 +71,7 @@ */ typedef enum { ERROR_TABLE(ERROR_ENUM) - ERROR_COUNT + TUSB_ERROR_COUNT }tusb_error_t; #if TUSB_CFG_DEBUG == 3 |
