/*FUNCTION*---------------------------------------------------------------- * * Function Name : usb_test_mode_init * Returned Value : None * Comments : * This function is called by common class to initialize the class driver. It * is called in response to a select interface call by application * *END*--------------------------------------------------------------------*/ usb_status_t USB_HostTestModeInit(usb_device_handle deviceHandle) { #if (((defined USB_HOST_CONFIG_EHCI) && (USB_HOST_CONFIG_EHCI)) || \ ((defined USB_HOST_CONFIG_IP3516HS) && (USB_HOST_CONFIG_IP3516HS))) usb_host_device_instance_t *deviceInstance = (usb_host_device_instance_t *)deviceHandle; usb_host_instance_t *hostInstance = (usb_host_instance_t *)deviceInstance->hostHandle; #endif uint32_t productId; uint32_t vendorId; usb_echo("usb host test init\r\n"); USB_HostHelperGetPeripheralInformation(deviceHandle, kUSB_HostGetDevicePID, &productId); USB_HostHelperGetPeripheralInformation(deviceHandle, kUSB_HostGetDeviceVID, &vendorId); usb_echo(" vendor id :0x%x product id:0x%x \r\n", vendorId, productId); if ((productId != 0x0200U) && (productId != 0x0101) && (productId != 0x0102) && (productId != 0x0103) && (productId != 0x0104) && (productId != 0x0105) && (productId != 0x0106) && (productId != 0x0107) && (productId != 0x0108)) { usb_echo("Unsupported Device\r\n"); } if (productId == 0x0200U) { usb_echo("PET test device attached\r\n"); } else { #if ((defined USB_HOST_CONFIG_EHCI) && (USB_HOST_CONFIG_EHCI)) if (hostInstance->controllerTable == &s_EhciInterface) { USB_HostEhciTestModeInit(deviceHandle); } #elif((defined USB_HOST_CONFIG_IP3516HS) && (USB_HOST_CONFIG_IP3516HS)) if (hostInstance->controllerTable == &s_Ip3516HsInterface) { USB_HostIp3516HsTestModeInit(deviceHandle); } #endif } return kStatus_USB_Success; }
/*! * @brief initialize the cdc instance. * * This function allocate the resource for cdc instance. * * @param deviceHandle the device handle. * @param classHandle return class handle. * * @retval kStatus_USB_Success The device is initialized successfully. * @retval kStatus_USB_AllocFail Allocate memory fail. */ usb_status_t USB_HostCdcInit(usb_device_handle deviceHandle, usb_host_class_handle *classHandle) { usb_host_cdc_instance_struct_t *control_ptr = (usb_host_cdc_instance_struct_t *)USB_OsaMemoryAllocate(sizeof(usb_host_cdc_instance_struct_t)); uint32_t info_value; if (control_ptr == NULL) { return kStatus_USB_AllocFail; } control_ptr->deviceHandle = deviceHandle; USB_HostHelperGetPeripheralInformation(deviceHandle, kUSB_HostGetHostHandle, &info_value); control_ptr->hostHandle = (usb_host_handle)info_value; USB_HostHelperGetPeripheralInformation(deviceHandle, kUSB_HostGetDeviceControlPipe, &info_value); control_ptr->controlPipe = (usb_host_pipe_handle)info_value; *classHandle = control_ptr; return kStatus_USB_Success; }
usb_status_t USB_HostMsdEvent(usb_device_handle deviceHandle, usb_host_configuration_handle configurationHandle, uint32_t eventCode) { usb_status_t status = kStatus_USB_Success; uint8_t id; usb_host_configuration_t *configuration; uint8_t interfaceIndex; usb_host_interface_t *interface; uint32_t infoValue; switch (eventCode) { case kUSB_HostEventAttach: /* judge whether is configurationHandle supported */ configuration = (usb_host_configuration_t *)configurationHandle; for (interfaceIndex = 0; interfaceIndex < configuration->interfaceCount; ++interfaceIndex) { interface = &configuration->interfaceList[interfaceIndex]; id = interface->interfaceDesc->bInterfaceClass; if (id != USB_HOST_MSD_CLASS_CODE) { continue; } id = interface->interfaceDesc->bInterfaceSubClass; if ((id != USB_HOST_MSD_SUBCLASS_CODE_UFI) && (id != USB_HOST_MSD_SUBCLASS_CODE_SCSI)) { continue; } id = interface->interfaceDesc->bInterfaceProtocol; if (id != USB_HOST_MSD_PROTOCOL_BULK) { continue; } else { if (g_MsdCommandInstance.deviceState == kStatus_DEV_Idle) { /* the interface is supported by the application */ g_MsdCommandInstance.deviceHandle = deviceHandle; g_MsdCommandInstance.interfaceHandle = interface; g_MsdCommandInstance.configHandle = configurationHandle; return kStatus_USB_Success; } else { continue; } } } status = kStatus_USB_NotSupported; break; case kUSB_HostEventNotSupported: break; case kUSB_HostEventEnumerationDone: if (g_MsdCommandInstance.configHandle == configurationHandle) { if ((g_MsdCommandInstance.deviceHandle != NULL) && (g_MsdCommandInstance.interfaceHandle != NULL)) { /* the device enumeration is done */ if (g_MsdCommandInstance.deviceState == kStatus_DEV_Idle) { g_MsdCommandInstance.deviceState = kStatus_DEV_Attached; USB_HostHelperGetPeripheralInformation(deviceHandle, kUSB_HostGetDevicePID, &infoValue); usb_echo("mass storage device attached:pid=0x%x", infoValue); USB_HostHelperGetPeripheralInformation(deviceHandle, kUSB_HostGetDeviceVID, &infoValue); usb_echo("vid=0x%x ", infoValue); USB_HostHelperGetPeripheralInformation(deviceHandle, kUSB_HostGetDeviceAddress, &infoValue); usb_echo("address=%d\r\n", infoValue); } else { usb_echo("not idle msd instance\r\n"); status = kStatus_USB_Error; } } } break; case kUSB_HostEventDetach: if (g_MsdCommandInstance.configHandle == configurationHandle) { /* the device is detached */ g_MsdCommandInstance.configHandle = NULL; if (g_MsdCommandInstance.deviceState != kStatus_DEV_Idle) { g_MsdCommandInstance.deviceState = kStatus_DEV_Detached; } } break; default: break; } return status; }