//////////////////////////////////////////////////////////////////////////////// // //> Name: UsbMscProjectInitDevice0 // // Type: Function // // Description: Project-specific USB MSC device init for device 0 // // Inputs: none // // Outputs: RETCODE // // Notes: none //< //////////////////////////////////////////////////////////////////////////////// RETCODE UsbMscProjectInitDevice0(void) { WORD sectorBufferSizeInWords; USBMSC_DEVICE * pDev; WORD i; // Device 1 setup pDev = &(UsbMscDevice[USBMSC_DEVICE_0]); // Run the reset routine UsbMscProjectResetDevice0(); #if defined(DEVICE_3410) || defined(DEVICE_3310) usb_device_init_endpoint(pDev->wBulkInEndpointNum ,64,USB_IN,USB_BULK_ENDPOINT,FALSE); usb_device_init_endpoint(pDev->wBulkOutEndpointNum,64,USB_OUT,USB_BULK_ENDPOINT,FALSE); #else // Do nothing. // The endpoints will be initialized in the UsbMscCbwProcessor() #endif usb_device_register_service(pDev->wBulkInEndpointNum,UsbMscBulkInService); usb_device_register_service(pDev->wBulkOutEndpointNum,UsbMscBulkOutService); usb_device_register_service(0,USBMSCRequestHandler); usb_device_register_service(USB_SERVICE_BUS_RESET,UsbMscResetService); #ifdef DEVICE_3500 usb_device_register_service(USB_SERVICE_SUSPEND,UsbMscSuspendService); usb_device_register_service(USB_SERVICE_RESUME,UsbMscResumeService); #endif for(i=0;i<SCSI_DEVICE_NUM_LUNS_DEV_0;i++) { ScsiLunSetupDefaultSenseData(&(pDev->Lun[i])); pDev->Lun[i].wCompletionStatus = USBMSC_CSW_COMMAND_PASSED; pDev->Lun[i].dwNumBytesXferred = 0; } // Lun 0 stuff pDev->Lun[0].wInquiryVendorData[0] = (g_SCSIVendorID[0]<<16); pDev->Lun[0].wInquiryVendorData[1] = g_SCSIVendorID[1] | (g_SCSIVendorID[2]<<8) | (g_SCSIVendorID[3]<<16); pDev->Lun[0].wInquiryVendorData[2] = g_SCSIVendorID[4] | (g_SCSIVendorID[5]<<8) | (g_SCSIVendorID[6]<<16); pDev->Lun[0].wInquiryVendorData[3] = g_SCSIVendorID[7] | (g_SCSIProductID[0]<<8) | (g_SCSIProductID[1]<<16); pDev->Lun[0].wInquiryVendorData[4] = g_SCSIProductID[2] | (g_SCSIProductID[3]<<8) | (g_SCSIProductID[4]<<16); pDev->Lun[0].wInquiryVendorData[5] = g_SCSIProductID[5] | (g_SCSIProductID[6]<<8) | (g_SCSIProductID[7]<<16); pDev->Lun[0].wInquiryVendorData[6] = g_SCSIProductID[8] | (g_SCSIProductID[9]<<8) | (g_SCSIProductID[10]<<16); pDev->Lun[0].wInquiryVendorData[7] = g_SCSIProductID[11] | (g_SCSIProductID[12]<<8) | (g_SCSIProductID[13]<<16); pDev->Lun[0].wInquiryVendorData[8] = g_SCSIProductID[14] | (g_SCSIProductID[15]<<8) | ('0'<<16); pDev->Lun[0].wInquiryVendorData[9] = '1' | ('0'<<8) | ('0'<<16); pDev->Lun[0].wInquiryVendorSpecific[0] = (0<<20) | (pDev->wDeviceNumber<<16) | // Lun 0, Device num (SCSI_INQUIRY_VENDOR_SPECIFIC_STRUCT_MDS<<8) | 1; // MDS, 1 struct pDev->Lun[0].wInquiryVendorSpecific[1] = (SCSI_MDS_MEDIA_TYPE_NAND<<8) | // Nand SCSI_MDS_FLAGS_SYSTEM_MEDIA_FLAG_SYSTEM; // System media pDev->Lun[0].wInquiryVendorSpecific[2] = 0; pDev->Lun[0].wInquiryVendorSpecific[3] = 0; pDev->Lun[0].wInquiryVendorSpecific[4] = 0; pDev->Lun[0].wInquiryVendorSpecific[5] = 0; pDev->Lun[0].wInquiryVendorSpecific[6] = 0; pDev->Lun[0].FlagMediaChange = ScsiDummyFlagMediaChange; #if (MULTI_LUN_BUILD==1) // Lun 1 stuff pDev->Lun[1].wInquiryVendorData[0] = (g_SCSIVendorID[0]<<16); pDev->Lun[1].wInquiryVendorData[1] = g_SCSIVendorID[1] | (g_SCSIVendorID[2]<<8) | (g_SCSIVendorID[3]<<16); pDev->Lun[1].wInquiryVendorData[2] = g_SCSIVendorID[4] | (g_SCSIVendorID[5]<<8) | (g_SCSIVendorID[6]<<16); pDev->Lun[1].wInquiryVendorData[3] = g_SCSIVendorID[7] | (g_SCSIProductID[0]<<8) | (g_SCSIProductID[1]<<16); pDev->Lun[1].wInquiryVendorData[4] = g_SCSIProductID[2] | (g_SCSIProductID[3]<<8) | (g_SCSIProductID[4]<<16); pDev->Lun[1].wInquiryVendorData[5] = g_SCSIProductID[5] | (g_SCSIProductID[6]<<8) | (g_SCSIProductID[7]<<16); pDev->Lun[1].wInquiryVendorData[6] = g_SCSIProductID[8] | (g_SCSIProductID[9]<<8) | (g_SCSIProductID[10]<<16); pDev->Lun[1].wInquiryVendorData[7] = g_SCSIProductID[11] | (g_SCSIProductID[12]<<8) | (g_SCSIProductID[13]<<16); pDev->Lun[1].wInquiryVendorData[8] = g_SCSIProductID[14] | (g_SCSIProductID[15]<<8) | ('0'<<16); pDev->Lun[1].wInquiryVendorData[9] = '1' | ('0'<<8) | ('0'<<16); pDev->Lun[1].wInquiryVendorSpecific[0] = (0<<20) | (pDev->wDeviceNumber<<16) | // Lun 0, Device num (SCSI_INQUIRY_VENDOR_SPECIFIC_STRUCT_MDS<<8) | 1; // MDS, 1 struct pDev->Lun[1].wInquiryVendorSpecific[1] = #ifdef MMC (SCSI_MDS_MEDIA_TYPE_MMC_UNKNOWN_VERSION<<8) | // MMC #else (SCSI_MDS_MEDIA_TYPE_SMARTMEDIA<<8) | // SmartMedia #endif SCSI_MDS_FLAGS_SYSTEM_MEDIA_FLAG_NON_SYSTEM; // Non-system media pDev->Lun[1].wInquiryVendorSpecific[2] = 0; pDev->Lun[1].wInquiryVendorSpecific[3] = 0; pDev->Lun[1].wInquiryVendorSpecific[4] = 0; pDev->Lun[1].wInquiryVendorSpecific[5] = 0; pDev->Lun[1].wInquiryVendorSpecific[6] = 0; #ifdef MMC pDev->Lun[1].FlagMediaChange = MmcFlagMediaChange; #else pDev->Lun[1].FlagMediaChange = ScsiDummyFlagMediaChange; #endif #endif //MultiLUN build. // Add one to the length of the sector buffer to account for the USB DMA defect sectorBufferSizeInWords = g_NandAuxData.SectorTotalSizeInWords + 1; // Pad the start address of the buffer array to avoid the USB DMA defect SectorArrayInitialize(&pDev->SectorArray,USBMSC_TOTAL_BUFFER_SIZE/sectorBufferSizeInWords,sectorBufferSizeInWords, Target0SectorArray,(Target0BufferArray+1)); // Device1CommandInBuffer is shared with Mtp pDev->CommandInBuffer = Device1CommandInBuffer; pDev->CommandOutBuffer = Device1CommandOutBuffer; return SUCCESS; }
/**************************************************************************//*! * * @name USB_Class_PHDC_Event * * @brief Initializes non control endpoints * * @param handle * @param event : event notified by the layer below * @param value : additional parameter used by the event * * @return : None ****************************************************************************** * Initializes non control endpoints when Enumeration complete event is * received. *****************************************************************************/ void USB_Class_PHDC_Event ( uint8_t event, void* val, void* arg ) { uint8_t count_rx = 0; uint8_t count_tx = 0; uint8_t index; usb_ep_struct_t* ep_struct_ptr; phdc_device_struct_t* devicePtr; uint8_t * phdc_qos; #if USBCFG_DEV_COMPOSITE usb_composite_info_struct_t* usb_composite_info; uint32_t interface_index = 0xFF; #else usb_class_struct_t* usbclass = NULL; #endif devicePtr = (phdc_device_struct_t *)arg; /* if enum is complete initialize non-control endpoints */ if (event == USB_DEV_EVENT_CONFIG_CHANGED) { uint8_t count = 0; #if USBCFG_DEV_COMPOSITE uint8_t type_sel; devicePtr->desc_callback.get_desc_entity((uint32_t)devicePtr->handle, USB_COMPOSITE_INFO, (uint32_t *)&usb_composite_info); devicePtr->desc_callback.get_desc_entity((uint32_t)devicePtr->handle, USB_PHDC_QOS_INFO, (uint32_t *)&phdc_qos); devicePtr->desc_callback.get_desc_entity((uint32_t)devicePtr, USB_CLASS_INTERFACE_INDEX_INFO, (uint32_t *)&interface_index); if(interface_index == 0xFF) { #if _DEBUG USB_PRINTF("not find interface index\n"); #endif return; } for (type_sel = 0;type_sel < usb_composite_info->count;type_sel++) { if ((usb_composite_info->class_handle[type_sel].type == USB_CLASS_PHDC) && (type_sel == interface_index)) { break; } } if(type_sel >= usb_composite_info->count) { #if _DEBUG USB_PRINTF("not find phdc interface\n"); #endif return; } devicePtr->ep_desc_data = (usb_endpoints_t *) &usb_composite_info->class_handle[type_sel].interfaces.interface->endpoints; devicePtr->phdc_endpoint_data.count_rx = 0; /* init the count_rx */ devicePtr->phdc_endpoint_data.count_tx = 0; /* init the count_tx */ /* calculate the rx and tx endpoint counts */ for (index = 0; index < usb_composite_info->class_handle[type_sel].interfaces.interface->endpoints.count; index++) { if ((usb_composite_info->class_handle[type_sel].interfaces.interface->endpoints.ep[index].direction == USB_RECV) & (devicePtr->phdc_endpoint_data.count_rx < PHDC_RX_ENDPOINTS)) { devicePtr->phdc_endpoint_data.count_rx++; } else if ((usb_composite_info->class_handle[type_sel].interfaces.interface->endpoints.ep[index].direction == USB_SEND) & (devicePtr->phdc_endpoint_data.count_tx < PHDC_TX_ENDPOINTS)) { devicePtr->phdc_endpoint_data.count_tx++; } } /* initialize endpoint data structure for all endpoints */ for (index = 0; index <usb_composite_info->class_handle[type_sel].interfaces.interface->endpoints.count; index++) { if ((usb_composite_info->class_handle[type_sel].interfaces.interface->endpoints.ep[index].direction == USB_RECV) & (count_rx < PHDC_RX_ENDPOINTS)) { /* initialize endpoint data structure for recv endpoint */ devicePtr->phdc_endpoint_data.ep_rx[count_rx].endpoint = usb_composite_info->class_handle[type_sel].interfaces.interface->endpoints.ep[index].ep_num; devicePtr->phdc_endpoint_data.ep_rx[count_rx].type = usb_composite_info->class_handle[type_sel].interfaces.interface->endpoints.ep[index].type; devicePtr->phdc_endpoint_data.ep_rx[count_rx].size = usb_composite_info->class_handle[type_sel].interfaces.interface->endpoints.ep[index].size; devicePtr->phdc_endpoint_data.ep_rx[count_rx].qos = phdc_qos[index]; devicePtr->phdc_endpoint_data.ep_rx[count_rx].current_qos = INVALID_VAL; devicePtr->phdc_endpoint_data.ep_rx[count_rx].buff_ptr = NULL; devicePtr->phdc_endpoint_data.ep_rx[count_rx].buffer_size = 0; /* increment count_rx by 1 */ count_rx++; } else if ((usb_composite_info->class_handle[type_sel].interfaces.interface->endpoints.ep[index].direction == USB_SEND) & (count_tx < PHDC_TX_ENDPOINTS)) { /* initialize endpoint data structure for send endpoint */ devicePtr->phdc_endpoint_data.ep_tx[count_tx].endpoint = usb_composite_info->class_handle[type_sel].interfaces.interface->endpoints.ep[index].ep_num; devicePtr->phdc_endpoint_data.ep_tx[count_tx].type = usb_composite_info->class_handle[type_sel].interfaces.interface->endpoints.ep[index].type; devicePtr->phdc_endpoint_data.ep_tx[count_tx].size = usb_composite_info->class_handle[type_sel].interfaces.interface->endpoints.ep[index].size; devicePtr->phdc_endpoint_data.ep_tx[count_tx].qos = phdc_qos[index]; devicePtr->phdc_endpoint_data.ep_tx[count_tx].current_qos = INVALID_VAL; devicePtr->phdc_endpoint_data.ep_tx[count_tx].bin_consumer = 0x00; devicePtr->phdc_endpoint_data.ep_tx[count_tx].bin_producer = 0x00; /* increment count_tx by 1 */ count_tx++; } } #else devicePtr->desc_callback.get_desc_entity((uint32_t)devicePtr->handle, USB_CLASS_INFO, (uint32_t *)&usbclass); devicePtr->desc_callback.get_desc_entity((uint32_t)devicePtr->handle, USB_PHDC_QOS_INFO, (uint32_t *)&phdc_qos); devicePtr->ep_desc_data = (usb_endpoints_t *) &usbclass->interfaces.interface->endpoints; devicePtr->phdc_endpoint_data.count_rx = 0; /* init the count_rx */ devicePtr->phdc_endpoint_data.count_tx = 0; /* init the count_tx */ /* calculate the rx and tx endpoint counts */ for (index = 0; index < usbclass->interfaces.interface->endpoints.count; index++) { if ((usbclass->interfaces.interface->endpoints.ep[index].direction == USB_RECV) & (devicePtr->phdc_endpoint_data.count_rx < PHDC_RX_ENDPOINTS)) { devicePtr->phdc_endpoint_data.count_rx++; } else if ((usbclass->interfaces.interface->endpoints.ep[index].direction == USB_SEND) & (devicePtr->phdc_endpoint_data.count_tx < PHDC_TX_ENDPOINTS)) { devicePtr->phdc_endpoint_data.count_tx++; } } /* initialize endpoint data structure for all endpoints */ for (index = 0; index < usbclass->interfaces.interface->endpoints.count; index++) { if ((usbclass->interfaces.interface->endpoints.ep[index].direction == USB_RECV) & (count_rx < PHDC_RX_ENDPOINTS)) { /* initialize endpoint data structure for recv endpoint */ devicePtr->phdc_endpoint_data.ep_rx[count_rx].endpoint = usbclass->interfaces.interface->endpoints.ep[index].ep_num; devicePtr->phdc_endpoint_data.ep_rx[count_rx].type = usbclass->interfaces.interface->endpoints.ep[index].type; devicePtr->phdc_endpoint_data.ep_rx[count_rx].size = usbclass->interfaces.interface->endpoints.ep[index].size; devicePtr->phdc_endpoint_data.ep_rx[count_rx].qos = phdc_qos[index]; devicePtr->phdc_endpoint_data.ep_rx[count_rx].current_qos = INVALID_VAL; devicePtr->phdc_endpoint_data.ep_rx[count_rx].buff_ptr = NULL; devicePtr->phdc_endpoint_data.ep_rx[count_rx].buffer_size = 0; /* increment count_rx by 1 */ count_rx++; } else if ((usbclass->interfaces.interface->endpoints.ep[index].direction == USB_SEND) & (count_tx < PHDC_TX_ENDPOINTS)) { /* initialize endpoint data structure for send endpoint */ devicePtr->phdc_endpoint_data.ep_tx[count_tx].endpoint = usbclass->interfaces.interface->endpoints.ep[index].ep_num; devicePtr->phdc_endpoint_data.ep_tx[count_tx].type = usbclass->interfaces.interface->endpoints.ep[index].type; devicePtr->phdc_endpoint_data.ep_tx[count_tx].size = usbclass->interfaces.interface->endpoints.ep[index].size; devicePtr->phdc_endpoint_data.ep_tx[count_tx].qos = phdc_qos[index]; devicePtr->phdc_endpoint_data.ep_tx[count_tx].current_qos = INVALID_VAL; devicePtr->phdc_endpoint_data.ep_tx[count_tx].bin_consumer = 0x00; devicePtr->phdc_endpoint_data.ep_tx[count_tx].bin_producer = 0x00; /* increment count_tx by 1 */ count_tx++; } } #endif usb_endpoints_t *ep_desc_data = devicePtr->ep_desc_data; /* initialize all non control endpoints */ count = 0; while (count < ep_desc_data->count) { ep_struct_ptr= (usb_ep_struct_t*) &ep_desc_data->ep[count]; (void)usb_device_init_endpoint(devicePtr->handle, ep_struct_ptr, TRUE); /* register callback service for endpoint 1 */ (void)usb_device_register_service(devicePtr->handle, (uint8_t)((uint8_t)(USB_SERVICE_EP0+ep_struct_ptr->ep_num) | ((uint8_t)(ep_struct_ptr->direction << 7))), USB_PHDC_Endpoint_Service, arg); count++; } } else if (event == USB_DEV_EVENT_ENUM_COMPLETE) { } else if (event == USB_DEV_EVENT_BUS_RESET) { } if (devicePtr->phdc_application_callback.callback != NULL) { devicePtr->phdc_application_callback.callback(event,val,devicePtr->phdc_application_callback.arg); } }
/**************************************************************************//*! * * @name USB_Class_CDC_Event * * @brief The function initializes CDC endpoints * * @param handle handle to Identify the controller * @param event pointer to event structure * @param val gives the configuration value * * @return None * *****************************************************************************/ void USB_Class_CDC_Event(uint8_t event, void* val, void* arg) { usb_interfaces_struct_t usb_interfaces = {0, NULL}; cdc_device_struct_t * cdc_obj_ptr = NULL; cdc_obj_ptr = (cdc_device_struct_t *)arg; uint8_t index; if (event == USB_DEV_EVENT_CONFIG_CHANGED) { #if CDC_RNDIS_SUPPORT uint32_t max_if_count; #endif usb_ep_struct_t* ep_struct_ptr = NULL; /* Get class info */ if(USB_UNINITIALIZED_VAL_32 != USB_Class_Get_Class_Handle(cdc_obj_ptr->controller_id)) { usb_composite_info_struct_t* usbcompinfoPtr; uint32_t interface_index = 0xFF; cdc_obj_ptr->desc_callback.get_desc_entity((uint32_t)cdc_obj_ptr, USB_COMPOSITE_INFO, (uint32_t*)&usbcompinfoPtr); cdc_obj_ptr->desc_callback.get_desc_entity((uint32_t)cdc_obj_ptr, USB_CLASS_INTERFACE_INDEX_INFO, (uint32_t *)&interface_index); if ((interface_index < usbcompinfoPtr->count) && (usbcompinfoPtr->class_handle[interface_index].type == USB_CLASS_COMMUNICATION)) { usb_interfaces = usbcompinfoPtr->class_handle[interface_index].interfaces; } else { return; } } else { usb_class_struct_t* usbclassPtr; cdc_obj_ptr->desc_callback.get_desc_entity((uint32_t)cdc_obj_ptr, USB_CLASS_INFO, (uint32_t*)&usbclassPtr); usb_interfaces = usbclassPtr->interfaces; } #if CDC_RNDIS_SUPPORT /* Get count of interfaces for a specific configuration */ USB_Cdc_Get_Desc_Info(cdc_obj_ptr, USB_CDC_INTERFACE_COUNT, &max_if_count); cdc_obj_ptr->max_supported_interfaces = max_if_count; #endif if (NULL != cdc_obj_ptr->ep) { index = 0; for (int inter_index =0; inter_index < usb_interfaces.count; inter_index++) { for (int ep_index = 0; ep_index < usb_interfaces.interface[inter_index].endpoints.count; ep_index++) { ep_struct_ptr = &usb_interfaces.interface[inter_index].endpoints.ep[ep_index]; cdc_obj_ptr->ep[index].endpoint = ep_struct_ptr->ep_num; cdc_obj_ptr->ep[index].type = ep_struct_ptr->type; cdc_obj_ptr->ep[index].direction = ep_struct_ptr->direction; #if CDC_IMPLEMENT_QUEUING cdc_obj_ptr->ep[index].bin_consumer = 0x00; cdc_obj_ptr->ep[index].bin_producer = 0x00; #endif index++; } } } /* Initialize all non control endpoints */ for (int inter_index =0; inter_index < usb_interfaces.count; inter_index++) { for (int ep_index = 0; ep_index < usb_interfaces.interface[inter_index].endpoints.count; ep_index++) { ep_struct_ptr = &usb_interfaces.interface[inter_index].endpoints.ep[ep_index]; (void)usb_device_init_endpoint(cdc_obj_ptr->controller_handle,ep_struct_ptr, TRUE); /* register callback service for Non Control EndPoints */ switch(ep_struct_ptr->type) { case USB_INTERRUPT_PIPE: (void)usb_device_register_service(cdc_obj_ptr->controller_handle, (uint8_t)((uint8_t)(USB_SERVICE_EP0 + ep_struct_ptr->ep_num) | ((uint8_t)(ep_struct_ptr->direction << 7))), USB_Service_Cdc_Notif, (void *)cdc_obj_ptr); cdc_obj_ptr->cic_recv_endpoint = USB_CONTROL_ENDPOINT; cdc_obj_ptr->cic_send_endpoint = ep_struct_ptr->ep_num; cdc_obj_ptr->cic_send_pkt_size = ep_struct_ptr->size; break; case USB_BULK_PIPE: if (ep_struct_ptr->direction == USB_RECV) { (void)usb_device_register_service(cdc_obj_ptr->controller_handle, (uint8_t)((uint8_t)(USB_SERVICE_EP0 + ep_struct_ptr->ep_num) | ((uint8_t)(ep_struct_ptr->direction << 7))), USB_Service_Dic_Bulk_Out, (void *)cdc_obj_ptr); cdc_obj_ptr->dic_recv_endpoint = ep_struct_ptr->ep_num; cdc_obj_ptr->dic_recv_pkt_size = ep_struct_ptr->size; } else { (void)usb_device_register_service(cdc_obj_ptr->controller_handle, (uint8_t)((uint8_t)(USB_SERVICE_EP0 + ep_struct_ptr->ep_num) | ((uint8_t)(ep_struct_ptr->direction << 7))), USB_Service_Dic_Bulk_In, (void *)cdc_obj_ptr); cdc_obj_ptr->dic_send_endpoint = ep_struct_ptr->ep_num; cdc_obj_ptr->dic_send_pkt_size = ep_struct_ptr->size; } break; default: break; } } } } else if (event == USB_DEV_EVENT_ENUM_COMPLETE) { /* To Do */ } else if(event == USB_DEV_EVENT_TYPE_CLR_EP_HALT) { uint8_t value; value = *((uint8_t *)val); if (cdc_obj_ptr->ep != NULL) { for (index = 0; index < MAX_CDC_EP_NUM; index++) { if((value & 0x0F) == (cdc_obj_ptr->ep[index].endpoint &0x0F)) { usb_device_unstall_endpoint(cdc_obj_ptr->controller_handle,(value & 0x0F), ((uint8_t)(value & 0x80)) >> 7); } } }