mirror of
https://github.com/hathach/tinyusb.git
synced 2025-01-31 05:52:55 +08:00
hack ehci advance async to handle disconnect via hub
This commit is contained in:
parent
5eebec61f1
commit
93821c55ce
@ -762,8 +762,8 @@
|
||||
<Focus>0</Focus>
|
||||
<ColumnNumber>0</ColumnNumber>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<TopLine>74</TopLine>
|
||||
<CurrentLine>93</CurrentLine>
|
||||
<TopLine>1</TopLine>
|
||||
<CurrentLine>12</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>328</TopLine>
|
||||
<CurrentLine>334</CurrentLine>
|
||||
<TopLine>1</TopLine>
|
||||
<CurrentLine>1</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>5</ColumnNumber>
|
||||
<ColumnNumber>11</ColumnNumber>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<TopLine>145</TopLine>
|
||||
<CurrentLine>152</CurrentLine>
|
||||
<CurrentLine>154</CurrentLine>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\..\bsp\lpc43xx\startup_keil\startup_LPC43xx.s</PathWithFileName>
|
||||
<FilenameWithoutPath>startup_LPC43xx.s</FilenameWithoutPath>
|
||||
|
@ -572,6 +572,13 @@ static void port_connect_status_change_isr(uint8_t hostid)
|
||||
}
|
||||
}
|
||||
|
||||
// TODO refractor abtract later
|
||||
void hcd_hub_advance_asyn(uint8_t hostid)
|
||||
{
|
||||
ehci_registers_t* const regs = get_operational_register(hostid);
|
||||
regs->usb_cmd_bit.advacne_async = 1; // Async doorbell check EHCI 4.8.2 for operational details
|
||||
}
|
||||
|
||||
static void qhd_xfer_complete_isr(ehci_qhd_t * p_qhd)
|
||||
{
|
||||
uint8_t max_loop = 0;
|
||||
|
@ -61,6 +61,9 @@ typedef struct {
|
||||
usbh_hub_t hub_data[TUSB_CFG_HOST_DEVICE_MAX] TUSB_CFG_ATTR_USBRAM;
|
||||
uint8_t hub_enum_buffer[sizeof(descriptor_hub_desc_t)] TUSB_CFG_ATTR_USBRAM;
|
||||
|
||||
//OSAL_SEM_DEF(hub_enum_semaphore);
|
||||
//static osal_semaphore_handle_t hub_enum_sem_hdl;
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// HUB
|
||||
//--------------------------------------------------------------------+
|
||||
@ -113,7 +116,7 @@ tusb_error_t hub_port_reset_subtask()
|
||||
);
|
||||
SUBTASK_ASSERT_STATUS( error );
|
||||
|
||||
osal_task_delay(200); // TODO Hub wait for Status Endpoint on Reset Change
|
||||
osal_task_delay(50); // TODO Hub wait for Status Endpoint on Reset Change
|
||||
|
||||
//------------- Get Port Status to check if port is enabled, powered and reset_change -------------//
|
||||
OSAL_SUBTASK_INVOKED_AND_WAIT(
|
||||
@ -134,32 +137,9 @@ tusb_error_t hub_port_reset_subtask()
|
||||
tusb_error_t hub_enumerate_subtask(void)
|
||||
{
|
||||
tusb_error_t error;
|
||||
|
||||
OSAL_SUBTASK_BEGIN
|
||||
|
||||
hub_port_status_response_t * p_port_status;
|
||||
|
||||
//------------- Get Port Status -------------//
|
||||
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;
|
||||
if ( !p_port_status->status_change.connect_status ) SUBTASK_EXIT(TUSB_ERROR_NONE); // only handle connection change
|
||||
|
||||
if ( !p_port_status->status_current.connect_status )
|
||||
{ // TODO HUB Disconnection
|
||||
|
||||
SUBTASK_EXIT(TUSB_ERROR_NONE);
|
||||
}
|
||||
|
||||
// Acknowledge Port Connection Change
|
||||
OSAL_SUBTASK_INVOKED_AND_WAIT( hub_port_clear_feature_subtask(HUB_FEATURE_PORT_CONNECTION_CHANGE), error );
|
||||
SUBTASK_ASSERT_STATUS( error );
|
||||
OSAL_SUBTASK_BEGIN
|
||||
|
||||
//------------- Port Reset & Get Port Speed -------------//
|
||||
OSAL_SUBTASK_INVOKED_AND_WAIT ( hub_port_reset_subtask(), error );
|
||||
@ -183,6 +163,7 @@ tusb_error_t hub_enumerate_subtask(void)
|
||||
void hub_init(void)
|
||||
{
|
||||
memclr_(hub_data, TUSB_CFG_HOST_DEVICE_MAX*sizeof(usbh_hub_t));
|
||||
// hub_enum_sem_hdl = osal_semaphore_create( OSAL_SEM_REF(hub_enum_semaphore) );
|
||||
}
|
||||
|
||||
tusb_error_t hub_open_subtask(uint8_t dev_addr, tusb_descriptor_interface_t const *p_interface_desc, uint16_t *p_length)
|
||||
@ -248,15 +229,21 @@ void hub_isr(pipe_handle_t pipe_hdl, tusb_event_t event, uint32_t xferred_bytes)
|
||||
}
|
||||
}
|
||||
|
||||
// TODO queue next transfer
|
||||
// NOTE: next status transfer is queued by usbh.c after handling this request
|
||||
}
|
||||
|
||||
void hub_close(uint8_t dev_addr)
|
||||
{
|
||||
(void) hcd_pipe_close(hub_data[dev_addr-1].pipe_status);
|
||||
memclr_(&hub_data[dev_addr-1], sizeof(usbh_hub_t));
|
||||
|
||||
// osal_semaphore_reset(hub_enum_sem_hdl);
|
||||
}
|
||||
|
||||
tusb_error_t hub_status_pipe_queue(uint8_t dev_addr)
|
||||
{
|
||||
return hcd_pipe_xfer(hub_data[dev_addr-1].pipe_status, &hub_data[dev_addr-1].status_change, 1, true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -192,6 +192,7 @@ tusb_error_t hub_open_subtask(uint8_t dev_addr, tusb_descriptor_interface_t cons
|
||||
void hub_isr(pipe_handle_t pipe_hdl, tusb_event_t event, uint32_t xferred_bytes);
|
||||
void hub_close(uint8_t dev_addr);
|
||||
|
||||
tusb_error_t hub_status_pipe_queue(uint8_t dev_addr);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -354,8 +354,64 @@ tusb_error_t enumeration_body_subtask(void)
|
||||
|
||||
if ( usbh_devices[0].hub_addr != 0) // connected/disconnected via hub
|
||||
{
|
||||
OSAL_SUBTASK_INVOKED_AND_WAIT( hub_enumerate_subtask(), error );
|
||||
//------------- Get Port Status -------------//
|
||||
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, enum_data_buffer ),
|
||||
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
|
||||
OSAL_SUBTASK_INVOKED_AND_WAIT( hub_port_clear_feature_subtask(HUB_FEATURE_PORT_CONNECTION_CHANGE), error );
|
||||
SUBTASK_ASSERT_STATUS( error );
|
||||
|
||||
if ( ! ((hub_port_status_response_t *) enum_data_buffer)->status_current.connect_status )
|
||||
{ // Device is disconnected via Hub
|
||||
uint8_t dev_addr = 1;
|
||||
while ( dev_addr <= TUSB_CFG_HOST_DEVICE_MAX &&
|
||||
!(usbh_devices[dev_addr].core_id == usbh_devices[0].core_id &&
|
||||
usbh_devices[dev_addr].hub_addr == usbh_devices[0].hub_addr &&
|
||||
usbh_devices[dev_addr].hub_port == usbh_devices[0].hub_port &&
|
||||
usbh_devices[dev_addr].state != TUSB_DEVICE_STATE_UNPLUG ) )
|
||||
{
|
||||
dev_addr++;
|
||||
}
|
||||
|
||||
if (dev_addr > TUSB_CFG_HOST_DEVICE_MAX) // unplug unmounted device
|
||||
{
|
||||
SUBTASK_EXIT(TUSB_ERROR_NONE);
|
||||
}
|
||||
|
||||
// if device unplugged is not a hub TODO handle hub unplugged
|
||||
for (uint8_t class_index = 1; class_index < TUSB_CLASS_MAPPED_INDEX_END; class_index++)
|
||||
{
|
||||
if ((usbh_devices[dev_addr].flag_supported_class & BIT_(class_index)) &&
|
||||
usbh_class_drivers[class_index].close)
|
||||
{
|
||||
usbh_class_drivers[class_index].close(dev_addr);
|
||||
}
|
||||
}
|
||||
usbh_pipe_control_close(dev_addr);
|
||||
|
||||
// set to REMOVING to allow HCD to clean up its cached data for this device
|
||||
// HCD must set this device's state to TUSB_DEVICE_STATE_UNPLUG when done
|
||||
usbh_devices[dev_addr].state = TUSB_DEVICE_STATE_REMOVING;
|
||||
usbh_devices[dev_addr].flag_supported_class = 0;
|
||||
|
||||
hcd_hub_advance_asyn(usbh_devices[0].core_id); // TODO hack
|
||||
|
||||
(void) hub_status_pipe_queue( usbh_devices[0].hub_addr ); // done with hub, waiting for next data on status pipe
|
||||
SUBTASK_EXIT(TUSB_ERROR_NONE); // restart task
|
||||
}
|
||||
else
|
||||
{ // Device is connected via Hub
|
||||
OSAL_SUBTASK_INVOKED_AND_WAIT( hub_enumerate_subtask(), error );
|
||||
SUBTASK_ASSERT_STATUS( error );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -390,6 +446,8 @@ tusb_error_t enumeration_body_subtask(void)
|
||||
// Acknowledge Port Reset Change
|
||||
OSAL_SUBTASK_INVOKED_AND_WAIT( hub_port_clear_feature_subtask(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
|
||||
}
|
||||
|
||||
//------------- Set new address -------------//
|
||||
|
Loading…
x
Reference in New Issue
Block a user