/* ************************************************************************************************************ * * function * * 函数名称: * * 参数列表: * * 返回值 : * * 说明 : * * ************************************************************************************************************ */ __u32 usb_detect_enter(void) { awxx_usb[0].index = 0; awxx_usb[0].reg_base = 0x01c13000; awxx_usb[0].irq_no = GIC_SRC_USB0; awxx_usb[0].drq_no = 0x04; __inf("usb start detect\n"); if(!usb_working) { __inf("usb enter detect\n"); usb_working = 1; usb_clock_init(); tmr_hd = wBoot_timer_request((void *)timer_test_usbdc, 0); if(!tmr_hd) { __inf("timer request fail\n"); } else { wBoot_timer_start(tmr_hd, 400, 0); } wBoot_InsINT_Func(awxx_usb[0].irq_no, (int *)usb_detect_irq_handler, 0); wBoot_EnableInt(awxx_usb[0].irq_no); usb_init(&awxx_usb[0]); usb_soft_connect(&awxx_usb[0]); } return 0; }
/* ************************************************************************************************************ * * function * * 函数名称: * * 参数列表: * * 返回值 : * * 说明 : * * ************************************************************************************************************ */ void usb_params_init(void) { __u32 i; usb_clock_init(); awxx_usb[0].index = 0; awxx_usb[0].reg_base = 0x01c19000; awxx_usb[0].irq_no = 103; awxx_usb[0].drq_no = 0x04; awxx_usb[0].role = USB0_ROLE; //USB_ROLE_HST; //USB_ROLE_UNK awxx_usb[0].speed = USB0_SPEED; if(awxx_usb[0].speed==USB_SPEED_HS) { awxx_usb[0].device.dev_desc = USB_HS_BULK_DevDesc; awxx_usb[0].device.config_desc= USB_HS_BULK_ConfigDesc; } else { awxx_usb[0].device.dev_desc = USB_FS_BULK_DevDesc; awxx_usb[0].device.config_desc= USB_FS_BULK_ConfigDesc; } for(i=0; i<4; i++) { awxx_usb[0].device.str_desc[i] = USB_StrDec0[i]; } awxx_usb[0].device.intf_desc = USB_HS_BULK_ConfigDesc; awxx_usb[0].device.endp_desc = USB_HS_BULK_ConfigDesc; awxx_usb[0].device.dev_qual = USB_DevQual; awxx_usb[0].device.otg_desc = USB_OTGDesc; //awxx_usb[0].device.MaxLUN = USB_MAX_LUN; //awxx_usb[0].device.MaxLUN = wBoot_part_count() - 1; awxx_usb[0].device.MaxLUN = wBoot_part_count(1) - 1; __inf("part count = %d\n", awxx_usb[0].device.MaxLUN + 1); //awxx_usb[0].device.bo_memory_base = USB_BO_DEV0_MEM_BASE; // USB_BO_DEV0_MEM_BASE; //awxx_usb[0].device.bo_capacity = USB_DEV0_TOTAL_CAP; //MB //awxx_usb[0].device.bo_seccnt = usb_get_capacity(); //USB_DEV0_SEC_CNT; //awxx_usb[0].device.bo_bufbase = USB_BO_DEV0_BUF_BASE; //?? awxx_usb[0].device.bo_memory_base = (__u32)wBoot_malloc(128 * 1024); //use to storage user data awxx_usb[0].device.bo_bufbase = (__u32)wBoot_malloc(64 * 1024); //use to usb ping-pang buffer awxx_usb[0].ep0_flag = 0; awxx_usb[0].ep0_xfer_state = USB_EP0_SETUP; //dma awxx_usb[0].dma = wBoot_dma_request(1); if(!awxx_usb[0].dma) { __inf("usb error: request dma fail\n"); } }
void usb_init() { usb_isr_init(); usb_clock_init(); usb_cablepin_init(); usb_cable_config(USB_CABLE_CONNECT); usb_power_on(); /* ADD your init code here */ usb_app_init(); }
int MSCenable(void){ USBD_API_INIT_PARAM_T usb_param; USB_CORE_DESCS_T desc; ErrorCode_t ret = LPC_OK; USB_CORE_CTRL_T *pCtrl; flashInit(); usb_clock_init(); usb_phy_enable(); /* Init USB API structure */ g_pUsbApi = (const USBD_API_T *) LPC_ROM_API->usbdApiBase; /* initialize call back structures */ memset((void *) &usb_param, 0, sizeof(USBD_API_INIT_PARAM_T)); usb_param.usb_reg_base = LPC_USB_BASE; usb_param.mem_base = USB_STACK_MEM_BASE; usb_param.mem_size = USB_STACK_MEM_SIZE; usb_param.max_num_ep = 2; /* Set the USB descriptors */ desc.device_desc = (uint8_t *) USB_msc_DeviceDescriptor; desc.string_desc = (uint8_t *) USB_msc_StringDescriptor; desc.high_speed_desc = USB_msc_HsConfigDescriptor; desc.full_speed_desc = USB_msc_FsConfigDescriptor; desc.device_qualifier = (uint8_t *) USB_msc_DeviceQualifier; /* USB Initialization */ ret = USBD_API->hw->Init(&g_hUsb, &desc, &usb_param); if (ret == LPC_OK) { /* WORKAROUND for artf45032 ROM driver BUG: Due to a race condition there is the chance that a second NAK event will occur before the default endpoint0 handler has completed its preparation of the DMA engine for the first NAK event. This can cause certain fields in the DMA descriptors to be in an invalid state when the USB controller reads them, thereby causing a hang. */ pCtrl = (USB_CORE_CTRL_T *) g_hUsb; /* convert the handle to control structure */ g_Ep0BaseHdlr = pCtrl->ep_event_hdlr[0];/* retrieve the default EP0_OUT handler */ pCtrl->ep_event_hdlr[0] = EP0_patch;/* set our patch routine as EP0_OUT handler */ ret = mscDisk_init(g_hUsb, &desc, &usb_param); if (ret == LPC_OK) { /* enable USB interrrupts */ nvic_enable_irq(NVIC_USB0_IRQ); /* now connect */ USBD_API->hw->Connect(g_hUsb, 1); return 0; } } return 1; }
void hsusb_clock_init(void) { /* USB local clock control not enabled; use proc comm */ usb_clock_init(); }