mirror of
https://github.com/hathach/tinyusb.git
synced 2025-01-17 05:32:55 +08:00
refractor hub
This commit is contained in:
parent
821f85cb20
commit
5fb22e3f34
@ -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
|
||||
|
@ -762,8 +762,8 @@
|
||||
<Focus>0</Focus>
|
||||
<ColumnNumber>0</ColumnNumber>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<TopLine>1</TopLine>
|
||||
<CurrentLine>1</CurrentLine>
|
||||
<TopLine>74</TopLine>
|
||||
<CurrentLine>93</CurrentLine>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\..\..\tinyusb\host\hub.c</PathWithFileName>
|
||||
<FilenameWithoutPath>hub.c</FilenameWithoutPath>
|
||||
@ -778,8 +778,8 @@
|
||||
<Focus>0</Focus>
|
||||
<ColumnNumber>0</ColumnNumber>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<TopLine>1</TopLine>
|
||||
<CurrentLine>1</CurrentLine>
|
||||
<TopLine>328</TopLine>
|
||||
<CurrentLine>334</CurrentLine>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\..\..\tinyusb\host\usbh.c</PathWithFileName>
|
||||
<FilenameWithoutPath>usbh.c</FilenameWithoutPath>
|
||||
@ -1080,10 +1080,10 @@
|
||||
<FileType>2</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
<ColumnNumber>18</ColumnNumber>
|
||||
<ColumnNumber>5</ColumnNumber>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<TopLine>145</TopLine>
|
||||
<CurrentLine>147</CurrentLine>
|
||||
<CurrentLine>152</CurrentLine>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\..\bsp\lpc43xx\startup_keil\startup_LPC43xx.s</PathWithFileName>
|
||||
<FilenameWithoutPath>startup_LPC43xx.s</FilenameWithoutPath>
|
||||
|
@ -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
|
||||
//--------------------------------------------------------------------+
|
||||
|
@ -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");
|
||||
|
Loading…
x
Reference in New Issue
Block a user