


版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、Usb初始化intusb_init(void)2intusb_lowlevel_init(void)3voidusb_scan_devices(void)6intusb_new_device(structusb_device*dev)7STEP1主機(jī)自動(dòng)設(shè)別USB®備的插入5rio+FuH-speedUSBTransceiver1<IRpuD+Low-speedUSBTransceiverSlowSlewRateBuffersiD-Low-spee<lFunctionD-HubUpstreamPortorFull-speedFunctionUSE®過(guò)D-,D+信
2、號(hào)的狀態(tài)判斷設(shè)備的插入,如上圖所示,D+S上拉電阻為高速設(shè)備,D-接下拉為低速設(shè)備。很多嵌入示系統(tǒng)利用這一點(diǎn),來(lái)控制USES備,使其復(fù)位(D+,D_,均為0大丁2.5us)。STEP2識(shí)別到USBt,主機(jī)初始化設(shè)備所有的US卵有endpoint0.如此類似還有別的endpoint如1,2,3,4等等,endpoint0,是初始化的默認(rèn)通道,一旦設(shè)備初始化完成后無(wú)任何意義。初始化主要完成以下事情。Reset設(shè)備讀出設(shè)備描敘符讀出設(shè)備配置符讀出接口信息讀出Endpoint信息讀出STRING言息配置設(shè)備描敘符STEP3主機(jī)初始化OK即可正常通訊對(duì)于數(shù)據(jù)量大的數(shù)據(jù)可以采用DMA!信,小數(shù)據(jù)量采用中斷
3、通信,這兩個(gè)比較簡(jiǎn)單,把握好基本流程即可以實(shí)現(xiàn)。/*InitUSBDevice*/intusb_init(void)intresult;/s_SetIRQHandler(INT_USBH,hc_interrupt_irq);running=0;dev_index=0;asynch_allowed=1;usb_hub_reset();/usb_hub_index=0;/*initlow_levelUSB*/s_UartPrint("USB:");result=usb_lowlevel_init();/*iflowlevelinitisOK,scanthebusfordevic
4、esi.e.searchHUBsandconfigurethem*/if(result=0)running=1;usb_scan_devices();return0;elses_UartPrint("Error,couldn'tinitLowlevelpartn");return-1;intusb_lowlevel_init(void)unsignedlongupllvalue;S3C24X0_CLOCK_POWER*constclk_powerS3C24X0_GetBase_CLOCK_POWER();S3C24X0_GPIO*constgpio=S3C24X0_
5、GetBase_GPIO();/*Setthe48MHzUPLLclocking.Valuesaretakenfrom*"PLLvalueselectionguide",6-23,s3c2410_UM.pdf.*/clk_power->CLKSLOW|=UCLK_ON;clk_power->UPLLCON=0x78023;/(0x78<<12)+(2<<4)+3);upllvalue=0x78023;/(0x78<<12)|(0x02<<4)|(0x03);while(upllvalue!=clk_power-&g
6、t;UPLLCON)clk_power->UPLLCON=0x78023;/(0x78<<12)+(2<<4)+3);wait_ms(1);/gpio->MISCCR|=MISCCR_USBPAD;/1=usepadsrelatedUSBforUSBhost/gpio->MISCCR&=MISCCR_USBPAD;/DP0DN0=HOSTDP1DN1=DEVICEgpio->MISCCR&=(MISCCR_USB0_SUSPEND|MISCCR_USB1_SUSPEND);/1=usepadsrelatedUSBforUSBhos
7、t/clk_power->CLKSLOW&=(UCLK_ON|MPLL_OFF|SLOW_BIT);/clk_power->CLKSLOW&=UCLK_ON;/EnableUSBhostclock.clk_power->CLKCON|=CLKCON_USBH;/changebywqhmemset(&gohci,0,sizeof(ohci_t);memset(&urb_priv,0,sizeof(urb_priv_t);/*alignthestorage*/s_UartPrint("Hccaaddr=%04x”,(U32)&gh
8、cca0);if(U32)&ghcca0&0xff)err("HCCAnotaligned!");return-1;phcca=&ghcca0;info("alignedghcca%p",phcca);memset(&ohci_dev,0,sizeof(structohci_device);if(U32)&ohci_dev.ed0&0x7)err("EDsnotaligned!");return-1;memset(gtd,0,sizeof(td_t)*(NUM_TD+1);if(U32)
9、gtd&0x7)(err("TDsnotaligned!");return-1;ptd=gtd;gohci.hcca=phcca;memset(phcca,0,sizeof(structohci_hcca);gohci.disabled=1;gohci.sleeping=0;gohci.irq=-1;gohci.regs=(structohci_regs*)S3C24X0_USB_HOST_BASE;gohci.flags=0;gohci.slot_name="s3c2410"if(hc_reset(&gohci)<0)(hc_re
10、lease_ohci(&gohci);/*Initializationfailed*/clk_power->CLKCON&=CLKCON_USBH;err("init_step2n");return-1;/*FIXMEthisisasecondHCreset;why?*/writel(gohci.hc_control=OHCI_USB_RESET,&gohci.regs->control);wait_ms(10);if(hc_start(&gohci)<0)(err("can'tstartusb-%s&qu
11、ot;,gohci.slot_name);hc_release_ohci(&gohci);/*Initializationfailed*/clk_power->CLKCON&=CLKCON_USBH;return-1;#ifdefDEBUGohci_dump(&gohci,1);#elsewait_ms(1);#endifohci_inited=1;urb_finished=1;return0;/*builddeviceTree*/voidusb_scan_devices(void)inti;structusb_device*dev;/*firstmakealld
12、evicesunknown*/for(i=0;i<USB_MAX_DEVICE;i+)memset(&usb_devi,0,sizeof(structusb_device);usb_devi.devnum=-1;dev_index=0;/*device0isalwayspresent(roothub,soletitanalyze)*/s_UartPrint("scan_step1n");dev=usb_alloc_new_device();s_UartPrint("scan_step2n");s_UartPrint("dev=%d
13、”,dev);usb_new_device(dev);/s_UartPrint("scan_step3n");/s_UartPrint("%dUSBDevice(s)foundn",dev_index);/*insert"driver"ifpossible*/* Bythetimewegethere,thedevicehasgottenanewdeviceID* andisinthedefaultstate.Weneedtoidentifythethingand* gettheballrolling.* Returns0forsucc
14、ess,!=0forerror.*/intusb_new_device(structusb_device*dev)intaddr,err;inttmp;unsignedchartmpbufUSB_BUFSIZ;dev->descriptor.bMaxPacketSize0=8;/*Startoffat8bytes*/dev->maxpacketsize=0;/*Defaultto8bytemaxpacketsize*/dev->epmaxpacketin0=8;dev->epmaxpacketout0=8;/*Westillhaven'tsettheAddres
15、syet*/addr=dev->devnum;dev->devnum=0;#undefNEW_INIT_SEQ#ifdefNEW_INIT_SEQ/*thisisaWindowsschemeofinitializationsequence,withdouble*resetofthedevice.Someequipmentissaidtoworkonlywithsuch*initsequence;thispatchisbasedontheworkbyAlanStern:intj;structusb_device_descriptor*desc;intport=-1;structusb
16、_device*parent=dev->parent;unsignedshortportstatus;* /*send64-byteGET-DEVICE-DESCRIPTORrequest.Sincethedescriptorisonly18byteslong,thiswillterminatewithashortpacket.Butifthemaxpacketsizeis8or16thedevicemaybewaitingtotransmitsomemore.*/desc=(structusb_device_descriptor*)tmpbuf;desc->bMaxPacketS
17、ize0=0;for(j=0;j<3;+j)err=usb_get_descriptor(dev,USB_DT_DEVICE,0,desc,64);if(err<0)USB_PRINTF("usb_new_device:64bytedescrn");break;dev->descriptor.bMaxPacketSize0=desc->bMaxPacketSize0;/*findtheportnumberwe'reat*/if(parent)for(j=0;j<parent->maxchild;j+)if(parent->c
18、hildrenj=dev)port=j;break;if(port<0)s_UartPrint("usb_new_device:cannotlocatedevice'sport.n");return1;/*resettheportforthesecondtime*/err=hub_port_reset(dev->parent,port,&portstatus);if(err<0)s_UartPrint("nCouldn'tresetport%in",port);return1;#else/*andthisisth
19、eoldandknownwayofinitializingdevices*/s_UartPrint("NEW_step1n");err=usb_get_descriptor(dev,USB_DT_DEVICE,0,&dev->descriptor,8);if(err<8)s_UartPrint("nUSBdevicenotresponding,givingup(status=%lX)n”,dev->status);return1;/s_UartPrint("NEW_step3err=%dn",err);#endifde
20、v->epmaxpacketin0=dev->descriptor.bMaxPacketSize0;dev->epmaxpacketout0=dev->descriptor.bMaxPacketSize0;switch(dev->descriptor.bMaxPacketSize0)case8:dev->maxpacketsize=0;break;case16:dev->maxpacketsize=1;break;case32:dev->maxpacketsize=2;break;case64:dev->maxpacketsize=3;br
21、eak;dev->devnum=addr;/s_UartPrint("NEW_step4n");err=usb_set_address(dev);/*setaddress*/s_UartPrint("NEW_step5n");if(err<0)s_UartPrint("nUSBdevicenotacceptingnewaddress(error=%lX)n”,dev->status);s_UartPrint("NEW_step6n");return1;wait_ms(10);/*LettheSET_ADDR
22、ESSsettle*/tmp=sizeof(dev->descriptor);/tmp=8;/s_UartPrint("NEW_step7n");err=usb_get_descriptor(dev,USB_DT_DEVICE,0,&dev->descriptor,sizeof(dev->descriptor);if(err<tmp)(if(err<0)s_UartPrint("unabletogetdevicedescriptor(error=%d)n",err);elses_UartPrint("USB
23、devicedescriptorshortread(expected%i,got%i)n",tmp,err);s_UartPrint("NEW_step8n");return1;/dev->epmaxpacketin0=dev->descriptor.bMaxPacketSize0;/dev->epmaxpacketout0=dev->descriptor.bMaxPacketSize0;/*correctlevalues*/dev->descriptor.bcdUSB=swap_16(dev->descriptor.bcdUS
24、B);dev->descriptor.idVendor=swap_16(dev->descriptor.idVendor);dev->descriptor.idProduct=swap_16(dev->descriptor.idProduct);dev->descriptor.bcdDevice=swap_16(dev->descriptor.bcdDevice);/s_UartPrint("NEW_step9size=%dn",sizeof(dev->descriptor);USB_PRINTF("bLength%xn”
25、,dev->descriptor.bLength);USB_PRINTF("bDescriptorTypeUSB_PRINTF("bcdUSBUSB_PRINTF("bDeviceClassUSB_PRINTF("bDeviceSubClassUSB_PRINTF("bDeviceProtocolUSB_PRINTF("bMaxPacketSize0USB_PRINTF("idVendorUSB_PRINTF("idProductUSB_PRINTF("bcdDevice%xn",dev-
26、>descriptor.bDescriptorType);%xn",dev->descriptor.bcdUSB);%xn",dev->descriptor.bDeviceClass);%xn",dev->descriptor.bDeviceSubClass);%xn",dev->descriptor.bDeviceProtocol);%xn”,dev->descriptor.bMaxPacketSize0);%xn",dev->descriptor.idVendor);%xn",dev-&g
27、t;descriptor.idProduct);%xn",dev->descriptor.bcdDevice);USB_PRINTF("iManufacturer%xn”,dev->descriptor.iManufacturer);USB_PRINTF("iProduct%xn",dev->descriptor.iProduct);USB_PRINTF("iSerialNumber%xn”,dev->descriptor.iSerialNumber);USB_PRINTF("bNumConfiguration
28、s%xn",dev->descriptor.bNumConfigurations);/*onlysupportforoneconfigfornow*/usb_get_configuration_no(dev,&tmpbuf0,0);/s_UartPrint("NEW_step10n");usb_parse_config(dev,&tmpbuf0,0);/s_UartPrint("NEW_step11n");usb_set_maxpacket(dev);/s_UartPrint("NEW_step12n");/*wesetthedefaultconfigurationhere*/if(usb_set_configuration(dev,dev->config.bConfigurationValue)s_UartPrint("
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 25年公司安全管理人員安全培訓(xùn)考試試題【培優(yōu)】
- 2024-2025企業(yè)員工安全培訓(xùn)考試試題(一套)
- 2024-2025公司安全培訓(xùn)考試試題答案4A
- 2025家居裝修合同示范文本
- 2025家具采購(gòu)合同范本
- 2025員工違反保密合同泄露商業(yè)機(jī)密詐騙賠償金法律途徑維權(quán)被判刑
- 2025心理咨詢師合同協(xié)議書(shū)范本
- 2025年燒結(jié)釹鐵硼永磁材料合作協(xié)議書(shū)
- 2025技術(shù)合作開(kāi)發(fā)合同模板樣本
- 2025企業(yè)貸款合同簡(jiǎn)化版
- 血透延續(xù)護(hù)理服務(wù)
- 公路路面灌縫施工方案
- 《西游記知識(shí)競(jìng)賽》題庫(kù)及答案(單選題100道、多選題100道)
- 《建筑工程施工現(xiàn)場(chǎng)安全管理的問(wèn)題與完善對(duì)策研究》9200字(論文)
- 2024廣西能匯投資集團(tuán)有限公司面向社會(huì)公開(kāi)招聘79人筆試核心備考題庫(kù)及答案解析
- 軀體形式障礙心理治療
- DB11T 494.7-2013 人力資源服務(wù)規(guī)范 第7部分:素質(zhì)測(cè)評(píng)服務(wù)
- 物管物業(yè)交接驗(yàn)收明細(xì)表格(全)模板
- 職業(yè)病防護(hù)設(shè)施與個(gè)體防護(hù)用品的使用和維護(hù)
- 不寧腿綜合征病例分析
- AECOPD合并呼吸衰竭護(hù)理查房
評(píng)論
0/150
提交評(píng)論