From aa040c4c984039ba9b5820aa15fd0264582bc207 Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 4 Feb 2013 21:52:50 +0700 Subject: [PATCH] rename device_info_pool to usbh_device_info_pool update enum task to post set address --- tests/test/host/test_usbh.c | 34 +++++++++++++++------- tinyusb/host/usbh.c | 58 +++++++++++++++++++++++++------------ tinyusb/host/usbh.h | 8 +++-- tinyusb/host/usbh_hcd.h | 1 + 4 files changed, 69 insertions(+), 32 deletions(-) diff --git a/tests/test/host/test_usbh.c b/tests/test/host/test_usbh.c index 02177122e..432efc0d8 100644 --- a/tests/test/host/test_usbh.c +++ b/tests/test/host/test_usbh.c @@ -42,12 +42,12 @@ #include "mock_hcd.h" #include "mock_usbh_hcd.h" -extern usbh_device_info_t device_info_pool[TUSB_CFG_HOST_DEVICE_MAX]; +extern usbh_device_info_t usbh_device_info_pool[TUSB_CFG_HOST_DEVICE_MAX]; tusb_handle_device_t dev_hdl; void setUp(void) { dev_hdl = 0; - memset(device_info_pool, 0, TUSB_CFG_HOST_DEVICE_MAX*sizeof(usbh_device_info_t)); + memset(usbh_device_info_pool, 0, TUSB_CFG_HOST_DEVICE_MAX*sizeof(usbh_device_info_t)); } void tearDown(void) @@ -98,12 +98,12 @@ void test_usbh_init_ok(void) TEST_ASSERT_EQUAL(TUSB_ERROR_NONE, usbh_init()); - TEST_ASSERT_EQUAL_MEMORY(device_info_zero, device_info_pool, sizeof(usbh_device_info_t)*TUSB_CFG_HOST_DEVICE_MAX); + TEST_ASSERT_EQUAL_MEMORY(device_info_zero, usbh_device_info_pool, sizeof(usbh_device_info_t)*TUSB_CFG_HOST_DEVICE_MAX); } void test_usbh_status_get_fail(void) { - device_info_pool[dev_hdl].status = 0; + usbh_device_info_pool[dev_hdl].status = 0; TEST_ASSERT_EQUAL( 0, tusbh_device_status_get(TUSB_CFG_HOST_DEVICE_MAX) ); TEST_ASSERT_EQUAL( TUSB_DEVICE_STATUS_UNPLUG, tusbh_device_status_get(dev_hdl) ); @@ -111,7 +111,7 @@ void test_usbh_status_get_fail(void) void test_usbh_status_get_succeed(void) { - device_info_pool[dev_hdl].status = TUSB_DEVICE_STATUS_READY; + usbh_device_info_pool[dev_hdl].status = TUSB_DEVICE_STATUS_READY; TEST_ASSERT_EQUAL( TUSB_DEVICE_STATUS_READY, tusbh_device_status_get(dev_hdl) ); } @@ -194,15 +194,29 @@ void test_enum_task_connect(void) osal_queue_receive_StubWithCallback(queue_recv_stub); hcd_port_connect_status_ExpectAndReturn(enum_connect.core_id, true); hcd_port_speed_ExpectAndReturn(enum_connect.core_id, TUSB_SPEED_FULL); - hcd_addr0_open_IgnoreAndReturn(TUSB_ERROR_NONE); - hcd_pipe_control_xfer_StubWithCallback(pipe_control_stub); - osal_semaphore_wait_StubWithCallback(semaphore_wait_stub); + { + hcd_addr0_open_IgnoreAndReturn(TUSB_ERROR_NONE); + + // get 8-byte of device descriptor + hcd_pipe_control_xfer_StubWithCallback(pipe_control_stub); + osal_semaphore_wait_StubWithCallback(semaphore_wait_stub); + // set device address + hcd_pipe_control_xfer_StubWithCallback(pipe_control_stub); + osal_semaphore_wait_StubWithCallback(semaphore_wait_stub); + + hcd_addr0_close_IgnoreAndReturn(TUSB_ERROR_NONE); + } - hcd_pipe_control_xfer_StubWithCallback(pipe_control_stub); - osal_semaphore_wait_StubWithCallback(semaphore_wait_stub); usbh_enumeration_task(); + + TEST_ASSERT_EQUAL(TUSB_DEVICE_STATUS_ADDRESSED, usbh_device_info_pool[0].status); + TEST_ASSERT_EQUAL(TUSB_SPEED_FULL, usbh_device_info_pool[0].speed); + TEST_ASSERT_EQUAL(enum_connect.core_id, usbh_device_info_pool[0].core_id); + TEST_ASSERT_EQUAL(enum_connect.hub_addr, usbh_device_info_pool[0].hub_addr); + TEST_ASSERT_EQUAL(enum_connect.hub_port, usbh_device_info_pool[0].hub_port); + } void test_enum_task_disconnect(void) diff --git a/tinyusb/host/usbh.c b/tinyusb/host/usbh.c index f60299a06..ffdb2769f 100644 --- a/tinyusb/host/usbh.c +++ b/tinyusb/host/usbh.c @@ -56,8 +56,9 @@ //--------------------------------------------------------------------+ // INTERNAL OBJECT & FUNCTION DECLARATION //--------------------------------------------------------------------+ +static inline uint8_t get_new_address(void) ATTR_ALWAYS_INLINE; -STATIC_ usbh_device_info_t device_info_pool[TUSB_CFG_HOST_DEVICE_MAX]; +STATIC_ usbh_device_info_t usbh_device_info_pool[TUSB_CFG_HOST_DEVICE_MAX]; //--------------------------------------------------------------------+ // PUBLIC API (Parameter Verification is required) @@ -65,7 +66,7 @@ STATIC_ usbh_device_info_t device_info_pool[TUSB_CFG_HOST_DEVICE_MAX]; tusbh_device_status_t tusbh_device_status_get (tusb_handle_device_t const device_hdl) { ASSERT(device_hdl < TUSB_CFG_HOST_DEVICE_MAX, 0); - return device_info_pool[device_hdl].status; + return usbh_device_info_pool[device_hdl].status; } //--------------------------------------------------------------------+ @@ -76,11 +77,15 @@ OSAL_TASK_DEF(enum_task, usbh_enumeration_task, 128, OSAL_PRIO_HIGH); #define ENUM_QUEUE_DEPTH 5 OSAL_QUEUE_DEF(enum_queue, ENUM_QUEUE_DEPTH, uin32_t); osal_queue_handle_t enum_queue_hdl; + usbh_device_addr0_t device_addr0 TUSB_CFG_ATTR_USBRAM; uint8_t enum_data_buffer[TUSB_CFG_HOST_ENUM_BUFFER_SIZE] TUSB_CFG_ATTR_USBRAM; + + void usbh_enumeration_task(void) { tusb_error_t error; + static uint8_t new_addr; OSAL_TASK_LOOP_BEGIN @@ -95,9 +100,8 @@ void usbh_enumeration_task(void) error = hcd_addr0_open(&device_addr0); TASK_ASSERT_STATUS(error); - { - tusb_std_request_t request_device_desc = - { + { // Get first 8 bytes of device descriptor to get Control Endpoint Size + tusb_std_request_t request_device_desc = { .bmRequestType = { .direction = TUSB_DIR_DEV_TO_HOST, .type = TUSB_REQUEST_TYPE_STANDARD, .recipient = TUSB_REQUEST_RECIPIENT_DEVICE }, .bRequest = TUSB_REQUEST_GET_DESCRIPTOR, .wValue = (TUSB_DESC_DEVICE << 8), @@ -109,22 +113,14 @@ void usbh_enumeration_task(void) TASK_ASSERT_STATUS(error); } - { - uint8_t new_addr = 0; - for (new_addr=0; new_addr