/*FUNCTION*---------------------------------------------------------------- * * Function Name : usb_dev_list_detach_device * Returned Value : * Comments : * This function will be called when detach interrupt happens. * *END*--------------------------------------------------------------------*/ void usb_dev_list_detach_device ( _usb_host_handle handle, uint_8 hub_no, uint_8 port_no ) { /* Body */ USB_HOST_STATE_STRUCT_PTR usb_host_ptr = (USB_HOST_STATE_STRUCT_PTR)handle; DEV_INSTANCE_PTR dev_instance_ptr; DEV_INSTANCE_PTR _PTR_ device_root = (DEV_INSTANCE_PTR _PTR_)&usb_host_ptr->DEVICE_LIST_PTR; /* search device list for the one being detached */ USB_lock(); for (dev_instance_ptr = *device_root; dev_instance_ptr != NULL; dev_instance_ptr = dev_instance_ptr->next) { if (dev_instance_ptr->port_no != port_no) continue; if (dev_instance_ptr->hub_no != hub_no) continue; if (dev_instance_ptr->host != handle) continue; break; } /* EndFor */ USB_unlock(); if (dev_instance_ptr == NULL) { return; /* No match, abandon ship! */ } /* Endif */ /* SGarg 09/23/2003 . Sometimes a detach could come even before a attach is finished. This means that we should make sure that device memory is not NULL before we try to clean it up. For example this happens with OPT tester test 4.10.*/ if(dev_instance_ptr->memlist != NULL) { /* Notify the application of unavailable interfaces */ usb_hostdev_attach_detach(dev_instance_ptr, USB_DETACH_EVENT); } /* Unlink device from the instance list */ dev_instance_ptr->control_callback = NULL; /* no surprises */ /* Close control pipe */ usb_dev_list_close_pipe(handle, (PIPE_DESCRIPTOR_STRUCT_PTR)dev_instance_ptr->control_pipe); /* SGarg 09/24/2003 . Sometimes a detach could come even before a attach is finished. This means that we should make sure that device memory is not NULL before we try to clean it up. For example this happens with OPT tester test 4.10.*/ if(dev_instance_ptr->memlist != NULL) { usb_dev_list_free_memory((pointer)dev_instance_ptr); } USB_lock(); /* Find the address of the "pointer to the detached device" */ while (*device_root != dev_instance_ptr) { device_root = &(*device_root)->next; } /* Endwhile */ /* Remove the device */ *device_root = dev_instance_ptr->next; USB_mem_free(dev_instance_ptr); USB_unlock(); } /* EndBody */
/*FUNCTION*---------------------------------------------------------------- * * Function Name : usb_dev_list_detach_device * Returned Value : * Comments : * This function will be called when detach interrupt happens. * *END*--------------------------------------------------------------------*/ void usb_dev_list_detach_device ( _usb_host_handle handle, uint_8 hub_no, uint_8 port_no ) { /* Body */ USB_HOST_STATE_STRUCT_PTR usb_host_ptr = (USB_HOST_STATE_STRUCT_PTR)handle; DEV_INSTANCE_PTR dev_instance_ptr; // clean warning DEV_INSTANCE_PTR _PTR_ device_root = &(DEV_INSTANCE_PTR)usb_host_ptr->DEVICE_LIST_PTR; DEV_INSTANCE_PTR _PTR_ device_root; // clean warning uint_32 state; device_root = (DEV_INSTANCE_PTR _PTR_)(&usb_host_ptr->DEVICE_LIST_PTR); #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("usb_dev_list_detach_device"); DEBUGMSG(USB_DBG_LEVEL, ("usb_dev_list_detach_device\n")); #endif /* search device list for the one being detached */ USB_lock(); for (dev_instance_ptr = *device_root; dev_instance_ptr != NULL; dev_instance_ptr = dev_instance_ptr->next) { if (dev_instance_ptr->port_no != port_no) continue; if (dev_instance_ptr->hub_no != hub_no) continue; if (dev_instance_ptr->host != handle) continue; break; } /* EndFor */ USB_unlock(); if (dev_instance_ptr == NULL) { #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("usb_dev_list_detach_device NULL device pointer"); #endif return; /* No match, abandon ship! */ } /* Endif */ /* SGarg 09/23/2003 . Sometimes a detach could come even before a attach is finished. This means that we should make sure that device memory is not NULL before we try to clean it up. For example this happens with OPT tester test 4.10.*/ if(dev_instance_ptr->memlist != NULL) { /* Notify the application of unavailable interfaces */ usb_hostdev_attach_detach(dev_instance_ptr, USB_DETACH_EVENT); } /* Unlink device from the instance list */ dev_instance_ptr->control_callback = NULL; /* no surprises */ /* Close control pipe */ usb_dev_list_close_pipe(handle, dev_instance_ptr->control_pipe); /* SGarg 09/24/2003 . Sometimes a detach could come even before a attach is finished. This means that we should make sure that device memory is not NULL before we try to clean it up. For example this happens with OPT tester test 4.10.*/ if(dev_instance_ptr->memlist != NULL) { usb_dev_list_free_memory((pointer)dev_instance_ptr); } USB_lock(); /* Find the address of the "pointer to the detached device" */ while (*device_root != dev_instance_ptr) { device_root = &(*device_root)->next; } /* Endwhile */ /* Remove the device */ *device_root = dev_instance_ptr->next; USB_memfree(dev_instance_ptr); #ifdef __USB_OTG__ _usb_otg_get_status((pointer)usb_otg_state_struct_ptr, USB_OTG_STATE, &state); if (state < B_IDLE) { _usb_otg_get_status((pointer)usb_otg_state_struct_ptr, USB_OTG_B_CONN, &state); if (state) { _usb_otg_set_status((pointer)usb_otg_state_struct_ptr, USB_OTG_B_CONN, FALSE); } /* Endif */ } else { _usb_otg_get_status((pointer)usb_otg_state_struct_ptr, USB_OTG_A_CONN, &state); if (state) { _usb_otg_set_status((pointer)usb_otg_state_struct_ptr, USB_OTG_A_CONN, FALSE); } /* Endif */ } /* Endif */ #endif USB_unlock(); #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("usb_dev_list_detach_device SUCCESSFUL"); #endif } /* EndBody */