summaryrefslogtreecommitdiff
path: root/tinyusb
diff options
context:
space:
mode:
authorhathach <[email protected]>2013-02-06 12:03:01 +0700
committerhathach <[email protected]>2013-02-06 12:03:01 +0700
commite20025b54d16deccbd6e86433f31d80f5a976fd4 (patch)
treeb94fc6905de315cc5ce3778d297cc711cc195f0f /tinyusb
parentaeccdfde3f4462fae5e3b9cbb4eae76526bdb204 (diff)
refractor move test enum to its own file
add assert with handler add task assert with error catcher
Diffstat (limited to 'tinyusb')
-rw-r--r--tinyusb/class/hid_host.c2
-rw-r--r--tinyusb/common/assertion.h14
-rw-r--r--tinyusb/common/common.h3
-rw-r--r--tinyusb/common/errors.h1
-rw-r--r--tinyusb/host/hcd.h6
-rw-r--r--tinyusb/host/usbh.c10
-rw-r--r--tinyusb/host/usbh.h10
-rw-r--r--tinyusb/osal/osal.h7
-rw-r--r--tinyusb/osal/osal_none.h16
9 files changed, 42 insertions, 27 deletions
diff --git a/tinyusb/class/hid_host.c b/tinyusb/class/hid_host.c
index eeed7cb0b..07abb7e6a 100644
--- a/tinyusb/class/hid_host.c
+++ b/tinyusb/class/hid_host.c
@@ -91,7 +91,7 @@ uint8_t tusbh_hid_keyboard_no_instances(tusb_handle_device_t const device_hdl)
//--------------------------------------------------------------------+
void class_hid_keyboard_init(void)
{
- memset(&keyboard_info_pool, 0, sizeof(class_hid_keyboard_info_t)*TUSB_CFG_HOST_DEVICE_MAX);
+ memclr_(&keyboard_info_pool, sizeof(class_hid_keyboard_info_t)*TUSB_CFG_HOST_DEVICE_MAX);
}
tusb_error_t class_hid_keyboard_install(uint8_t const dev_addr, uint8_t const *descriptor)
diff --git a/tinyusb/common/assertion.h b/tinyusb/common/assertion.h
index f6aff004e..e8ce24c0a 100644
--- a/tinyusb/common/assertion.h
+++ b/tinyusb/common/assertion.h
@@ -69,25 +69,25 @@ extern "C"
// Assert Helper
//--------------------------------------------------------------------+
#define ASSERT_MESSAGE(format, ...)\
- _PRINTF("Assert at %s: %s:%d: " format "\n", __FILE__, __PRETTY_FUNCTION__, __LINE__, __VA_ARGS__)
+ _PRINTF("Assert at %s %s %d: " format "\n", __BASE_FILE__, __PRETTY_FUNCTION__, __LINE__, __VA_ARGS__)
#ifndef _TEST_ASSERT_
- #define ASSERT_ERROR_HANDLER(x) return (x)
+ #define ASSERT_ERROR_HANDLER(x, para) return (x)
#else
- #define ASSERT_ERROR_HANDLER(x) Throw(x)
+ #define ASSERT_ERROR_HANDLER(x, para) Throw(x)
#endif
-#define ASSERT_DEFINE(...) ASSERT_DEFINE_WITH_HANDLER(ASSERT_ERROR_HANDLER, __VA_ARGS__)
-
-#define ASSERT_DEFINE_WITH_HANDLER(error_handler, setup_statement, condition, error, format, ...) \
+#define ASSERT_DEFINE_WITH_HANDLER(error_handler, handler_para, setup_statement, condition, error, format, ...) \
do{\
setup_statement;\
if (!(condition)) {\
ASSERT_MESSAGE(format, __VA_ARGS__);\
- error_handler(error);\
+ error_handler(error, handler_para);\
}\
}while(0)
+#define ASSERT_DEFINE(...) ASSERT_DEFINE_WITH_HANDLER(ASSERT_ERROR_HANDLER, NULL, __VA_ARGS__)
+
//--------------------------------------------------------------------+
// tusb_error_t Status Assert TODO use ASSERT_DEFINE
//--------------------------------------------------------------------+
diff --git a/tinyusb/common/common.h b/tinyusb/common/common.h
index 403ca5d6c..a3c8cfef5 100644
--- a/tinyusb/common/common.h
+++ b/tinyusb/common/common.h
@@ -98,6 +98,9 @@
#define U32_TO_U8S_BE(u32) U32_B1_U8(u32), U32_B2_U8(u32), U32_B3_U8(u32), U32_B4_U8(u32)
#define U32_TO_U8S_LE(u32) U32_B4_U8(u32), U32_B3_U8(u32), U32_B2_U8(u32), U32_B1_U8(u32)
+
+#define memclr_(buffer, size) memset(buffer, 0, size)
+
/// 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)
diff --git a/tinyusb/common/errors.h b/tinyusb/common/errors.h
index 2d8a80e22..42a7a3975 100644
--- a/tinyusb/common/errors.h
+++ b/tinyusb/common/errors.h
@@ -66,6 +66,7 @@
ENTRY(TUSB_ERROR_CLASS_DEVICE_DONT_SUPPORT)\
ENTRY(TUSB_ERROR_CLASS_DATA_NOT_AVAILABLE)\
ENTRY(TUSB_ERROR_HCD_FAILED)\
+ ENTRY(TUSB_ERROR_USBH_MOUNT_FAILED)\
ENTRY(TUSB_ERROR_OSAL_TIMEOUT)\
ENTRY(TUSB_ERROR_OSAL_TASK_FAILED)\
ENTRY(TUSB_ERROR_OSAL_QUEUE_FAILED)\
diff --git a/tinyusb/host/hcd.h b/tinyusb/host/hcd.h
index db16ce869..079a0c4f3 100644
--- a/tinyusb/host/hcd.h
+++ b/tinyusb/host/hcd.h
@@ -71,9 +71,9 @@ tusb_error_t hcd_init(uint8_t hostid) ATTR_WARN_UNUSED_RESULT;
//--------------------------------------------------------------------+
// PIPE API
//--------------------------------------------------------------------+
-pipe_handle_t hcd_pipe_control_open(uint8_t dev_addr, uint8_t max_packet_size);
-tusb_error_t hcd_pipe_control_xfer(pipe_handle_t pipe_hdl, tusb_std_request_t const * p_request, uint8_t data[]);
-pipe_handle_t hcd_pipe_open(uint8_t dev_addr, tusb_descriptor_endpoint_t const * endpoint_desc);
+pipe_handle_t hcd_pipe_control_open(uint8_t dev_addr, uint8_t max_packet_size) ATTR_WARN_UNUSED_RESULT;
+tusb_error_t hcd_pipe_control_xfer(pipe_handle_t pipe_hdl, tusb_std_request_t const * p_request, uint8_t data[]) ATTR_WARN_UNUSED_RESULT;
+pipe_handle_t hcd_pipe_open(uint8_t dev_addr, tusb_descriptor_endpoint_t const * endpoint_desc) ATTR_WARN_UNUSED_RESULT;
#if 0
//tusb_error_t hcd_pipe_open(
diff --git a/tinyusb/host/usbh.c b/tinyusb/host/usbh.c
index ffdb2769f..371514748 100644
--- a/tinyusb/host/usbh.c
+++ b/tinyusb/host/usbh.c
@@ -89,16 +89,14 @@ void usbh_enumeration_task(void)
OSAL_TASK_LOOP_BEGIN
- osal_queue_receive(enum_queue_hdl, (uint32_t*)(&device_addr0.enum_entry), OSAL_TIMEOUT_NORMAL, &error);
- TASK_ASSERT_STATUS(error);
+ osal_queue_receive(enum_queue_hdl, (uint32_t*)(&device_addr0.enum_entry), OSAL_TIMEOUT_WAIT_FOREVER, &error);
if (device_addr0.enum_entry.hub_addr == 0) // direct connection
{
TASK_ASSERT(device_addr0.enum_entry.connect_status == hcd_port_connect_status(device_addr0.enum_entry.core_id)); // there chances the event is out-dated
device_addr0.speed = hcd_port_speed(device_addr0.enum_entry.core_id);
- error = hcd_addr0_open(&device_addr0);
- TASK_ASSERT_STATUS(error);
+ TASK_ASSERT_STATUS( hcd_addr0_open(&device_addr0) );
{ // Get first 8 bytes of device descriptor to get Control Endpoint Size
tusb_std_request_t request_device_desc = {
@@ -110,7 +108,7 @@ void usbh_enumeration_task(void)
hcd_pipe_control_xfer(device_addr0.pipe_hdl, &request_device_desc, enum_data_buffer);
osal_semaphore_wait(device_addr0.sem_hdl, OSAL_TIMEOUT_NORMAL, &error); // careful of local variable without static
- TASK_ASSERT_STATUS(error);
+ TASK_ASSERT_STATUS_HANDLER(error, tusbh_device_mount_failed_cb(TUSB_ERROR_USBH_MOUNT_FAILED, NULL));
}
new_addr = get_new_address();
@@ -158,7 +156,7 @@ tusb_error_t usbh_init(void)
{
uint32_t i;
- memset(usbh_device_info_pool, 0, sizeof(usbh_device_info_t)*TUSB_CFG_HOST_DEVICE_MAX);
+ memclr_(usbh_device_info_pool, sizeof(usbh_device_info_t)*TUSB_CFG_HOST_DEVICE_MAX);
for(i=0; i<TUSB_CFG_HOST_CONTROLLER_NUM; i++)
{
diff --git a/tinyusb/host/usbh.h b/tinyusb/host/usbh.h
index 03d6cbbc2..2d9c44a85 100644
--- a/tinyusb/host/usbh.h
+++ b/tinyusb/host/usbh.h
@@ -127,9 +127,11 @@ typedef uint8_t tusbh_device_status_t;
//--------------------------------------------------------------------+
// APPLICATION API
//--------------------------------------------------------------------+
-void tusbh_device_mounting_cb (tusb_error_t const error, tusb_handle_device_t const device_hdl);
-void tusbh_device_mounted_cb (tusb_error_t const error, tusb_handle_device_t const device_hdl);
-tusb_error_t tusbh_configuration_set (tusb_handle_device_t const device_hdl, uint8_t const configure_number) ATTR_WARN_UNUSED_RESULT;
+uint8_t tusbh_device_attached_cb (tusb_descriptor_device_t const *p_desc_device) ATTR_WEAK ATTR_WARN_UNUSED_RESULT;
+void tusbh_device_mounted_cb (tusb_handle_device_t device_hdl) ATTR_WEAK;
+void tusbh_device_mount_failed_cb(tusb_error_t error, tusb_descriptor_device_t const *p_desc_device) ATTR_WEAK;
+
+tusb_error_t tusbh_configuration_set (tusb_handle_device_t device_hdl, uint8_t configure_number) ATTR_WARN_UNUSED_RESULT;
tusbh_device_status_t tusbh_device_status_get (tusb_handle_device_t const device_hdl) ATTR_WARN_UNUSED_RESULT;
#if TUSB_CFG_OS == TUSB_OS_NONE // TODO move later
@@ -147,7 +149,7 @@ static inline void tusb_tick_tock(void)
tusb_error_t usbh_init(void);
pipe_status_t usbh_pipe_status_get(pipe_handle_t pipe_hdl) ATTR_WARN_UNUSED_RESULT;
-void usbh_enum_task(void);
+void usbh_enumeration_task(void);
#endif
diff --git a/tinyusb/osal/osal.h b/tinyusb/osal/osal.h
index 055f28d1a..2482695fa 100644
--- a/tinyusb/osal/osal.h
+++ b/tinyusb/osal/osal.h
@@ -85,10 +85,17 @@ typedef uint32_t osal_task_t;
#define OSAL_TASK_LOOP_BEGIN
#define OSAL_TASK_LOOP_END
+#define TASK_ASSERT_ERROR_HANDLER(error, func_call)\
+ func_call; return error
+
+#define TASK_ASSERT_STATUS_HANDLER(sts, func_call) \
+ ASSERT_DEFINE_WITH_HANDLER(TASK_ASSERT_ERROR_HANDLER, func_call, tusb_error_t status = (tusb_error_t)(sts),\
+ TUSB_ERROR_NONE == status, status, "%s", TUSB_ErrorStr[status])
#define TASK_ASSERT_STATUS(sts) \
ASSERT_DEFINE(tusb_error_t status = (tusb_error_t)(sts),\
TUSB_ERROR_NONE == status, (void) 0, "%s", TUSB_ErrorStr[status])
+
#define TASK_ASSERT(condition) ASSERT(condition, (void) 0)
tusb_error_t osal_task_create(osal_task_t *task);
diff --git a/tinyusb/osal/osal_none.h b/tinyusb/osal/osal_none.h
index 93f77d593..e424d4143 100644
--- a/tinyusb/osal/osal_none.h
+++ b/tinyusb/osal/osal_none.h
@@ -90,12 +90,16 @@ uint32_t osal_tick_get(void);
state = 0;\
}
-#define TASK_ASSERT_ERROR_HANDLER \
- state = 0; break;
+#define TASK_ASSERT_ERROR_HANDLER(error, func_call) \
+ func_call; state = 0; break
-#define TASK_ASSERT(condition) ASSERT_DEFINE_WITH_HANDLER(TASK_ASSERT_ERROR_HANDLER, , (condition), (void) 0, "%s", "evaluated to false")
+#define TASK_ASSERT_STATUS_HANDLER(sts, func_call) \
+ ASSERT_DEFINE_WITH_HANDLER(TASK_ASSERT_ERROR_HANDLER, func_call, tusb_error_t status = (tusb_error_t)(sts),\
+ TUSB_ERROR_NONE == status, status, "%s", TUSB_ErrorStr[status])
+
+#define TASK_ASSERT(condition) ASSERT_DEFINE_WITH_HANDLER(TASK_ASSERT_ERROR_HANDLER, , , (condition), (void) 0, "%s", "evaluated to false")
#define TASK_ASSERT_STATUS(sts) \
- ASSERT_DEFINE_WITH_HANDLER(TASK_ASSERT_ERROR_HANDLER, tusb_error_t status = (tusb_error_t)(sts),\
+ ASSERT_DEFINE_WITH_HANDLER(TASK_ASSERT_ERROR_HANDLER, , tusb_error_t status = (tusb_error_t)(sts),\
TUSB_ERROR_NONE == status, status, "%s", TUSB_ErrorStr[status])
//--------------------------------------------------------------------+
// Semaphore API
@@ -129,7 +133,7 @@ static inline tusb_error_t osal_semaphore_post(osal_semaphore_handle_t const se
timeout = osal_tick_get();\
state = __LINE__; case __LINE__:\
if( *(sem_hdl) == 0 ) {\
- if ( timeout + osal_tick_from_msec(msec) < osal_tick_get() ) /* time out */ \
+ if ( (msec != OSAL_TIMEOUT_WAIT_FOREVER) && (timeout + osal_tick_from_msec(msec) < osal_tick_get()) ) /* time out */ \
*(p_error) = TUSB_ERROR_OSAL_TIMEOUT;\
else\
return;\
@@ -194,7 +198,7 @@ static inline tusb_error_t osal_queue_send(osal_queue_handle_t const queue_hdl,
timeout = osal_tick_get();\
state = __LINE__; case __LINE__:\
if( queue_hdl-> count == 0 ) {\
- if ( timeout + osal_tick_from_msec(msec) < osal_tick_get() ) /* time out */ \
+ if ( (msec != OSAL_TIMEOUT_WAIT_FOREVER) && ( timeout + osal_tick_from_msec(msec) < osal_tick_get() )) /* time out */ \
*(p_error) = TUSB_ERROR_OSAL_TIMEOUT;\
else\
return;\