add usbh_pipe_control_close (in conjunction with usbh pipe control open)

close control pipe when unplugged
This commit is contained in:
hathach
2013-03-13 11:20:02 +07:00
parent 97c9001d40
commit 97c436a16e
4 changed files with 30 additions and 9 deletions

View File

@@ -151,6 +151,7 @@ tusb_error_t usbh_control_xfer_subtask(uint8_t dev_addr, tusb_std_request_t cons
OSAL_SUBTASK_END
}
tusb_error_t usbh_pipe_control_open(uint8_t dev_addr, uint8_t max_packet_size) ATTR_ALWAYS_INLINE;
tusb_error_t usbh_pipe_control_open(uint8_t dev_addr, uint8_t max_packet_size)
{
osal_semaphore_reset( usbh_device_info_pool[dev_addr].sem_hdl );
@@ -160,6 +161,14 @@ tusb_error_t usbh_pipe_control_open(uint8_t dev_addr, uint8_t max_packet_size)
return TUSB_ERROR_NONE;
}
static inline tusb_error_t usbh_pipe_control_close(uint8_t dev_addr) ATTR_ALWAYS_INLINE;
static inline tusb_error_t usbh_pipe_control_close(uint8_t dev_addr)
{
ASSERT_STATUS( hcd_pipe_control_close(dev_addr) );
return TUSB_ERROR_NONE;
}
pipe_status_t usbh_pipe_status_get(pipe_handle_t pipe_hdl)
{
return PIPE_STATUS_BUSY;
@@ -192,6 +201,7 @@ void usbh_device_plugged_isr(uint8_t hostid, tusb_speed_t speed)
void usbh_device_unplugged_isr(uint8_t hostid)
{
//------------- find the device address that is unplugged -------------//
uint8_t dev_addr=1;
while ( dev_addr <= TUSB_CFG_HOST_DEVICE_MAX && ! (usbh_device_info_pool[dev_addr].core_id == hostid &&
usbh_device_info_pool[dev_addr].hub_addr == 0 &&
@@ -202,12 +212,17 @@ void usbh_device_unplugged_isr(uint8_t hostid)
ASSERT(dev_addr <= TUSB_CFG_HOST_DEVICE_MAX, (void) 0 );
// if device unplugged is not a hub TODO handle hub unplugged
for (uint8_t class_code = 1; class_code < TUSB_CLASS_MAX_CONSEC_NUMBER; class_code++)
{
if (usbh_class_drivers[class_code].close)
usbh_class_drivers[class_code].close(dev_addr);
}
usbh_pipe_control_close(dev_addr);
// set to REMOVING to prevent allocate to other new device
// need to set to UNPLUGGED by HCD after freeing all resources
usbh_device_info_pool[dev_addr].status = TUSB_DEVICE_STATUS_REMOVING;
}
@@ -276,7 +291,7 @@ OSAL_TASK_DECLARE(usbh_enumeration_task)
usbh_device_info_pool[new_addr].hub_port = usbh_device_info_pool[0].hub_port;
usbh_device_info_pool[new_addr].speed = usbh_device_info_pool[0].speed;
usbh_device_info_pool[new_addr].status = TUSB_DEVICE_STATUS_ADDRESSED;
hcd_pipe_control_close(0);
usbh_pipe_control_close(0);
// hcd_port_reset( usbh_device_info_pool[new_addr].core_id ); TODO verified