refractor hub

This commit is contained in:
hathach 2013-10-01 12:12:35 +07:00
parent 14ebd6c4d9
commit 4da3b03430
3 changed files with 72 additions and 49 deletions

View File

@ -158,7 +158,24 @@
<Name>-O975 -S0 -C0 -FO7 -FD10000000 -FC800 -FN2 -FF0LPC18xx43xx_512_BA -FS01A000000 -FL080000 -FF1LPC18xx43xx_512_BB -FS11B000000 -FL180000)</Name> <Name>-O975 -S0 -C0 -FO7 -FD10000000 -FC800 -FN2 -FF0LPC18xx43xx_512_BA -FS01A000000 -FL080000 -FF1LPC18xx43xx_512_BB -FS11B000000 -FL180000)</Name>
</SetRegEntry> </SetRegEntry>
</TargetDriverDllRegistry> </TargetDriverDllRegistry>
<Breakpoint/> <Breakpoint>
<Bp>
<Number>0</Number>
<Type>0</Type>
<LineNumber>375</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>0</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>0</BreakIfRCount>
<Filename>C:\Users\hathach\Dropbox\tinyusb\workspace\tinyusb\tinyusb\host\usbh.c</Filename>
<ExecCommand></ExecCommand>
<Expression></Expression>
</Bp>
</Breakpoint>
<WatchWindow1> <WatchWindow1>
<Ww> <Ww>
<count>0</count> <count>0</count>
@ -370,7 +387,24 @@
<Name>-O975 -S0 -C0 -FO7 -FD10000000 -FC800 -FN2 -FF0LPC18xx43xx_512_BA -FS01A000000 -FL080000 -FF1LPC18xx43xx_512_BB -FS11B000000 -FL180000)</Name> <Name>-O975 -S0 -C0 -FO7 -FD10000000 -FC800 -FN2 -FF0LPC18xx43xx_512_BA -FS01A000000 -FL080000 -FF1LPC18xx43xx_512_BB -FS11B000000 -FL180000)</Name>
</SetRegEntry> </SetRegEntry>
</TargetDriverDllRegistry> </TargetDriverDllRegistry>
<Breakpoint/> <Breakpoint>
<Bp>
<Number>0</Number>
<Type>0</Type>
<LineNumber>375</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>0</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>0</BreakIfRCount>
<Filename>C:\Users\hathach\Dropbox\tinyusb\workspace\tinyusb\tinyusb\host\usbh.c</Filename>
<ExecCommand></ExecCommand>
<Expression></Expression>
</Bp>
</Breakpoint>
<WatchWindow1> <WatchWindow1>
<Ww> <Ww>
<count>0</count> <count>0</count>
@ -440,10 +474,10 @@
<FileType>1</FileType> <FileType>1</FileType>
<tvExp>0</tvExp> <tvExp>0</tvExp>
<Focus>0</Focus> <Focus>0</Focus>
<ColumnNumber>0</ColumnNumber> <ColumnNumber>17</ColumnNumber>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
<TopLine>126</TopLine> <TopLine>126</TopLine>
<CurrentLine>149</CurrentLine> <CurrentLine>129</CurrentLine>
<bDave2>0</bDave2> <bDave2>0</bDave2>
<PathWithFileName>..\src\cdc_serial_app.c</PathWithFileName> <PathWithFileName>..\src\cdc_serial_app.c</PathWithFileName>
<FilenameWithoutPath>cdc_serial_app.c</FilenameWithoutPath> <FilenameWithoutPath>cdc_serial_app.c</FilenameWithoutPath>
@ -760,10 +794,10 @@
<FileType>1</FileType> <FileType>1</FileType>
<tvExp>0</tvExp> <tvExp>0</tvExp>
<Focus>0</Focus> <Focus>0</Focus>
<ColumnNumber>0</ColumnNumber> <ColumnNumber>24</ColumnNumber>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
<TopLine>1</TopLine> <TopLine>1</TopLine>
<CurrentLine>12</CurrentLine> <CurrentLine>11</CurrentLine>
<bDave2>0</bDave2> <bDave2>0</bDave2>
<PathWithFileName>..\..\..\tinyusb\host\hub.c</PathWithFileName> <PathWithFileName>..\..\..\tinyusb\host\hub.c</PathWithFileName>
<FilenameWithoutPath>hub.c</FilenameWithoutPath> <FilenameWithoutPath>hub.c</FilenameWithoutPath>
@ -792,10 +826,10 @@
<FileType>1</FileType> <FileType>1</FileType>
<tvExp>0</tvExp> <tvExp>0</tvExp>
<Focus>0</Focus> <Focus>0</Focus>
<ColumnNumber>0</ColumnNumber> <ColumnNumber>56</ColumnNumber>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
<TopLine>411</TopLine> <TopLine>562</TopLine>
<CurrentLine>419</CurrentLine> <CurrentLine>578</CurrentLine>
<bDave2>0</bDave2> <bDave2>0</bDave2>
<PathWithFileName>..\..\..\tinyusb\host\ehci\ehci.c</PathWithFileName> <PathWithFileName>..\..\..\tinyusb\host\ehci\ehci.c</PathWithFileName>
<FilenameWithoutPath>ehci.c</FilenameWithoutPath> <FilenameWithoutPath>ehci.c</FilenameWithoutPath>
@ -1080,10 +1114,10 @@
<FileType>2</FileType> <FileType>2</FileType>
<tvExp>0</tvExp> <tvExp>0</tvExp>
<Focus>0</Focus> <Focus>0</Focus>
<ColumnNumber>11</ColumnNumber> <ColumnNumber>0</ColumnNumber>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
<TopLine>145</TopLine> <TopLine>145</TopLine>
<CurrentLine>154</CurrentLine> <CurrentLine>151</CurrentLine>
<bDave2>0</bDave2> <bDave2>0</bDave2>
<PathWithFileName>..\..\bsp\lpc43xx\startup_keil\startup_LPC43xx.s</PathWithFileName> <PathWithFileName>..\..\bsp\lpc43xx\startup_keil\startup_LPC43xx.s</PathWithFileName>
<FilenameWithoutPath>startup_LPC43xx.s</FilenameWithoutPath> <FilenameWithoutPath>startup_LPC43xx.s</FilenameWithoutPath>

View File

@ -67,7 +67,7 @@ uint8_t hub_enum_buffer[sizeof(descriptor_hub_desc_t)] TUSB_CFG_ATTR_USBRAM;
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// HUB // HUB
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
tusb_error_t hub_port_clear_feature_subtask(uint8_t feature) tusb_error_t hub_port_clear_feature_subtask(uint8_t hub_addr, uint8_t hub_port, uint8_t feature)
{ {
tusb_error_t error; tusb_error_t error;
@ -78,8 +78,8 @@ tusb_error_t hub_port_clear_feature_subtask(uint8_t feature)
//------------- Clear Port Feature request -------------// //------------- Clear Port Feature request -------------//
OSAL_SUBTASK_INVOKED_AND_WAIT( 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), usbh_control_xfer_subtask( 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, HUB_REQUEST_CLEAR_FEATURE, feature, hub_port,
0, NULL ), 0, NULL ),
error error
); );
@ -87,8 +87,8 @@ tusb_error_t hub_port_clear_feature_subtask(uint8_t feature)
//------------- Get Port Status to check if feature is cleared -------------// //------------- Get Port Status to check if feature is cleared -------------//
OSAL_SUBTASK_INVOKED_AND_WAIT( 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), usbh_control_xfer_subtask( 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, HUB_REQUEST_GET_STATUS, 0, hub_port,
4, hub_enum_buffer ), 4, hub_enum_buffer ),
error error
); );
@ -101,7 +101,7 @@ tusb_error_t hub_port_clear_feature_subtask(uint8_t feature)
OSAL_SUBTASK_END OSAL_SUBTASK_END
} }
tusb_error_t hub_port_reset_subtask() tusb_error_t hub_port_reset_subtask(uint8_t hub_addr, uint8_t hub_port)
{ {
tusb_error_t error; tusb_error_t error;
@ -109,8 +109,8 @@ tusb_error_t hub_port_reset_subtask()
//------------- Set Port Reset -------------// //------------- Set Port Reset -------------//
OSAL_SUBTASK_INVOKED_AND_WAIT( 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), usbh_control_xfer_subtask( hub_addr, bm_request_type(TUSB_DIR_HOST_TO_DEV, TUSB_REQUEST_TYPE_CLASS, TUSB_REQUEST_RECIPIENT_OTHER),
HUB_REQUEST_SET_FEATURE, HUB_FEATURE_PORT_RESET, usbh_devices[0].hub_port, HUB_REQUEST_SET_FEATURE, HUB_FEATURE_PORT_RESET, hub_port,
0, NULL ), 0, NULL ),
error error
); );
@ -120,8 +120,8 @@ tusb_error_t hub_port_reset_subtask()
//------------- Get Port Status to check if port is enabled, powered and reset_change -------------// //------------- Get Port Status to check if port is enabled, powered and reset_change -------------//
OSAL_SUBTASK_INVOKED_AND_WAIT( 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), usbh_control_xfer_subtask( 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, HUB_REQUEST_GET_STATUS, 0, hub_port,
4, hub_enum_buffer ), 4, hub_enum_buffer ),
error error
); );
@ -134,27 +134,12 @@ tusb_error_t hub_port_reset_subtask()
OSAL_SUBTASK_END OSAL_SUBTASK_END
} }
tusb_error_t hub_enumerate_subtask(void) // can only get the speed RIGHT AFTER hub_port_reset_subtask call
tusb_speed_t hub_port_get_speed(void)
{ {
tusb_error_t error; hub_port_status_response_t * p_port_status = (hub_port_status_response_t *) hub_enum_buffer;
hub_port_status_response_t * p_port_status; return (p_port_status->status_current.high_speed_device_attached) ? TUSB_SPEED_HIGH :
(p_port_status->status_current.low_speed_device_attached ) ? TUSB_SPEED_LOW : TUSB_SPEED_FULL;
OSAL_SUBTASK_BEGIN
//------------- Port Reset & Get Port Speed -------------//
OSAL_SUBTASK_INVOKED_AND_WAIT ( hub_port_reset_subtask(), error );
SUBTASK_ASSERT_STATUS( error );
// TODO get port speed
p_port_status = (hub_port_status_response_t *) hub_enum_buffer;
usbh_devices[0].speed = (p_port_status->status_current.high_speed_device_attached) ? TUSB_SPEED_HIGH :
(p_port_status->status_current.low_speed_device_attached ) ? TUSB_SPEED_LOW : TUSB_SPEED_FULL;
// Acknowledge Port Reset Change
OSAL_SUBTASK_INVOKED_AND_WAIT( hub_port_clear_feature_subtask(HUB_FEATURE_PORT_RESET_CHANGE), error );
SUBTASK_ASSERT_STATUS( error );
OSAL_SUBTASK_END
} }
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+

View File

@ -370,11 +370,10 @@ tusb_error_t enumeration_body_subtask(void)
); );
SUBTASK_ASSERT_STATUS( error ); SUBTASK_ASSERT_STATUS( error );
if ( ! ((hub_port_status_response_t *) enum_data_buffer)->status_change.connect_status ) SUBTASK_EXIT(TUSB_ERROR_NONE); // only handle connection change
// Acknowledge Port Connection Change // Acknowledge Port Connection Change
OSAL_SUBTASK_INVOKED_AND_WAIT( hub_port_clear_feature_subtask(HUB_FEATURE_PORT_CONNECTION_CHANGE), error ); OSAL_SUBTASK_INVOKED_AND_WAIT( hub_port_clear_feature_subtask(usbh_devices[0].hub_addr, usbh_devices[0].hub_port, HUB_FEATURE_PORT_CONNECTION_CHANGE), error );
SUBTASK_ASSERT_STATUS( error );
if ( ! ((hub_port_status_response_t *) enum_data_buffer)->status_change.connect_status ) SUBTASK_EXIT(TUSB_ERROR_NONE); // only handle connection change
if ( ! ((hub_port_status_response_t *) enum_data_buffer)->status_current.connect_status ) if ( ! ((hub_port_status_response_t *) enum_data_buffer)->status_current.connect_status )
{ // Device is disconnected via Hub { // Device is disconnected via Hub
@ -388,8 +387,13 @@ tusb_error_t enumeration_body_subtask(void)
} }
else else
{ // Device is connected via Hub { // Device is connected via Hub
OSAL_SUBTASK_INVOKED_AND_WAIT( hub_enumerate_subtask(), error ); OSAL_SUBTASK_INVOKED_AND_WAIT ( hub_port_reset_subtask(usbh_devices[0].hub_addr, usbh_devices[0].hub_port), error );
SUBTASK_ASSERT_STATUS( error ); SUBTASK_ASSERT_STATUS( error );
usbh_devices[0].speed = hub_port_get_speed();
// Acknowledge Port Reset Change
OSAL_SUBTASK_INVOKED_AND_WAIT( hub_port_clear_feature_subtask(usbh_devices[0].hub_addr, usbh_devices[0].hub_port, HUB_FEATURE_PORT_RESET_CHANGE), error );
} }
} }
else else
@ -413,18 +417,18 @@ tusb_error_t enumeration_body_subtask(void)
); );
SUBTASK_ASSERT_STATUS(error); // TODO some slow device is observed to fail the very fist controller xfer, can try more times SUBTASK_ASSERT_STATUS(error); // TODO some slow device is observed to fail the very fist controller xfer, can try more times
//------------- Reset device again before Set Address -------------//
if (usbh_devices[0].hub_addr == 0) if (usbh_devices[0].hub_addr == 0)
{ // mount direct to root hub { // mount direct to root hub
hcd_port_reset( usbh_devices[0].core_id ); // reset port after 8 byte descriptor hcd_port_reset( usbh_devices[0].core_id ); // reset port after 8 byte descriptor
// osal_task_delay(50); // TODO reset is recommended to last 50 ms (NXP EHCI passes this) // osal_task_delay(50); // TODO reset is recommended to last 50 ms (NXP EHCI passes this)
}else }else
{ {
OSAL_SUBTASK_INVOKED_AND_WAIT ( hub_port_reset_subtask(), error ); OSAL_SUBTASK_INVOKED_AND_WAIT ( hub_port_reset_subtask(usbh_devices[0].hub_addr, usbh_devices[0].hub_port), error );
SUBTASK_ASSERT_STATUS( error ); SUBTASK_ASSERT_STATUS( error );
// Acknowledge Port Reset Change // Acknowledge Port Reset Change
OSAL_SUBTASK_INVOKED_AND_WAIT( hub_port_clear_feature_subtask(HUB_FEATURE_PORT_RESET_CHANGE), error ); OSAL_SUBTASK_INVOKED_AND_WAIT( hub_port_clear_feature_subtask(usbh_devices[0].hub_addr, usbh_devices[0].hub_port, HUB_FEATURE_PORT_RESET_CHANGE), error );
SUBTASK_ASSERT_STATUS( error );
(void) hub_status_pipe_queue( usbh_devices[0].hub_addr ); // done with hub, waiting for next data on status pipe (void) hub_status_pipe_queue( usbh_devices[0].hub_addr ); // done with hub, waiting for next data on status pipe
} }