From 5fb22e3f34db0d9e91df8ca306cc97518bb99792 Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 30 Sep 2013 16:13:08 +0700 Subject: [PATCH] refractor hub --- .../boards/embedded_artists/board_ea4357.h | 4 +- demos/host/host_os_none/host_os_none.uvopt | 12 ++-- tinyusb/host/hub.c | 56 ++++++++++++------- tinyusb/host/hub.h | 46 ++++++++------- 4 files changed, 71 insertions(+), 47 deletions(-) diff --git a/demos/bsp/boards/embedded_artists/board_ea4357.h b/demos/bsp/boards/embedded_artists/board_ea4357.h index cb9a7136a..5858b0496 100644 --- a/demos/bsp/boards/embedded_artists/board_ea4357.h +++ b/demos/bsp/boards/embedded_artists/board_ea4357.h @@ -67,8 +67,8 @@ #include "oem_base_board/pca9532.h" // LEDs -#define CFG_PRINTF_TARGET PRINTF_TARGET_SWO -//#define CFG_PRINTF_TARGET PRINTF_TARGET_UART // FIXME keil's cmsis rtx does not work with UART (work with SWO) +//#define CFG_PRINTF_TARGET PRINTF_TARGET_SWO +#define CFG_PRINTF_TARGET PRINTF_TARGET_UART // FIXME keil's cmsis rtx does not work with UART (work with SWO) /*========================================================================= HARDWARE MAC ADDRESS diff --git a/demos/host/host_os_none/host_os_none.uvopt b/demos/host/host_os_none/host_os_none.uvopt index 4aada8217..0eae74b13 100644 --- a/demos/host/host_os_none/host_os_none.uvopt +++ b/demos/host/host_os_none/host_os_none.uvopt @@ -762,8 +762,8 @@ 0 0 0 - 1 - 1 + 74 + 93 0 ..\..\..\tinyusb\host\hub.c hub.c @@ -778,8 +778,8 @@ 0 0 0 - 1 - 1 + 328 + 334 0 ..\..\..\tinyusb\host\usbh.c usbh.c @@ -1080,10 +1080,10 @@ 2 0 0 - 18 + 5 0 145 - 147 + 152 0 ..\..\bsp\lpc43xx\startup_keil\startup_LPC43xx.s startup_LPC43xx.s diff --git a/tinyusb/host/hub.c b/tinyusb/host/hub.c index ec033b868..672ac4c10 100644 --- a/tinyusb/host/hub.c +++ b/tinyusb/host/hub.c @@ -64,6 +64,40 @@ uint8_t hub_enum_buffer[sizeof(descriptor_hub_desc_t)] TUSB_CFG_ATTR_USBRAM; //--------------------------------------------------------------------+ // HUB //--------------------------------------------------------------------+ +tusb_error_t hub_port_clear_feature_subtask(uint8_t feature) +{ + tusb_error_t error; + + OSAL_SUBTASK_BEGIN + + SUBTASK_ASSERT(HUB_FEATURE_PORT_CONNECTION_CHANGE <= feature && + feature <= HUB_FEATURE_PORT_RESET_CHANGE); + + //------------- Clear Port Feature request -------------// + OSAL_SUBTASK_INVOKED_AND_WAIT( + usbh_control_xfer_subtask( usbh_devices[0].hub_addr, bm_request_type(TUSB_DIR_HOST_TO_DEV, TUSB_REQUEST_TYPE_CLASS, TUSB_REQUEST_RECIPIENT_OTHER), + HUB_REQUEST_CLEAR_FEATURE, feature, usbh_devices[0].hub_port, + 0, NULL ), + error + ); + SUBTASK_ASSERT_STATUS( error ); + + //------------- Get Port Status to check if feature is cleared -------------// + OSAL_SUBTASK_INVOKED_AND_WAIT( + usbh_control_xfer_subtask( usbh_devices[0].hub_addr, bm_request_type(TUSB_DIR_DEV_TO_HOST, TUSB_REQUEST_TYPE_CLASS, TUSB_REQUEST_RECIPIENT_OTHER), + HUB_REQUEST_GET_STATUS, 0, usbh_devices[0].hub_port, + 4, hub_enum_buffer ), + error + ); + SUBTASK_ASSERT_STATUS( error ); + + //------------- Check if feature is cleared -------------// + hub_port_status_response_t * p_port_status = (hub_port_status_response_t *) hub_enum_buffer; + SUBTASK_ASSERT( !BIT_TEST_(p_port_status->status_change.value, feature-16) ); + + OSAL_SUBTASK_END +} + tusb_error_t hub_enumerate_subtask(void) { tusb_error_t error; @@ -90,28 +124,10 @@ tusb_error_t hub_enumerate_subtask(void) SUBTASK_EXIT(TUSB_ERROR_NONE); } - // Hub connection - //------------- Clear Hub Port Connect Status Change -------------// - OSAL_SUBTASK_INVOKED_AND_WAIT( - usbh_control_xfer_subtask( usbh_devices[0].hub_addr, bm_request_type(TUSB_DIR_HOST_TO_DEV, TUSB_REQUEST_TYPE_CLASS, TUSB_REQUEST_RECIPIENT_OTHER), - HUB_REQUEST_CLEAR_FEATURE, HUB_FEATURE_PORT_CONNECTION_CHANGE, usbh_devices[0].hub_port, - 0, NULL ), - error - ); + // Acknowledge Port Connection Change + OSAL_SUBTASK_INVOKED_AND_WAIT( hub_port_clear_feature_subtask(HUB_FEATURE_PORT_CONNECTION_CHANGE), error ); SUBTASK_ASSERT_STATUS( error ); - //------------- Get Port Status again to make sure Connect Change is cleared -------------// - OSAL_SUBTASK_INVOKED_AND_WAIT( - usbh_control_xfer_subtask( usbh_devices[0].hub_addr, bm_request_type(TUSB_DIR_DEV_TO_HOST, TUSB_REQUEST_TYPE_CLASS, TUSB_REQUEST_RECIPIENT_OTHER), - HUB_REQUEST_GET_STATUS, 0, usbh_devices[0].hub_port, - 4, hub_enum_buffer ), - error - ); - SUBTASK_ASSERT_STATUS( error ); - - p_port_status = (hub_port_status_response_t *) hub_enum_buffer; - SUBTASK_ASSERT( !p_port_status->status_change.connect_status); // this has to be cleared - //--------------------------------------------------------------------+ // PORT RESET & WAIT FOR STATUS ENDPOINT & GET STATUS & CLEAR RESET CHANGE //--------------------------------------------------------------------+ diff --git a/tinyusb/host/hub.h b/tinyusb/host/hub.h index cc36ef0a6..445b4e2a3 100644 --- a/tinyusb/host/hub.h +++ b/tinyusb/host/hub.h @@ -144,32 +144,40 @@ enum{ // data in response of HUB_REQUEST_GET_STATUS, wIndex = 0 (hub) typedef struct { - ATTR_PACKED_STRUCT(struct) { - uint16_t local_power_source : 1; - uint16_t over_current : 1; - uint16_t : 14; - }status, status_change; + union{ + ATTR_PACKED_STRUCT(struct) { + uint16_t local_power_source : 1; + uint16_t over_current : 1; + uint16_t : 14; + }; + + uint16_t value; + } status, status_change; } hub_status_response_t; STATIC_ASSERT( sizeof(hub_status_response_t) == 4, "size is not correct"); // data in response of HUB_REQUEST_GET_STATUS, wIndex = Port num typedef struct { - ATTR_PACKED_STRUCT(struct) { - uint16_t connect_status : 1; - uint16_t port_enable : 1; - uint16_t suspend : 1; - uint16_t over_current : 1; - uint16_t reset : 1; + union { + ATTR_PACKED_STRUCT(struct) { + uint16_t connect_status : 1; + uint16_t port_enable : 1; + uint16_t suspend : 1; + uint16_t over_current : 1; + uint16_t reset : 1; - uint16_t : 3; - uint16_t port_power : 1; - uint16_t low_speed_device_attached : 1; - uint16_t high_speed_device_attached : 1; - uint16_t port_test_mode : 1; - uint16_t port_indicator_control : 1; - uint16_t : 0; - }status_current, status_change; + uint16_t : 3; + uint16_t port_power : 1; + uint16_t low_speed_device_attached : 1; + uint16_t high_speed_device_attached : 1; + uint16_t port_test_mode : 1; + uint16_t port_indicator_control : 1; + uint16_t : 0; + }; + + uint16_t value; + } status_current, status_change; } hub_port_status_response_t; STATIC_ASSERT( sizeof(hub_port_status_response_t) == 4, "size is not correct");