CypressUSB教程第5讲课件_第1页
CypressUSB教程第5讲课件_第2页
CypressUSB教程第5讲课件_第3页
CypressUSB教程第5讲课件_第4页
CypressUSB教程第5讲课件_第5页
已阅读5页,还剩35页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

Lecture5AgendaSuspend/ResumeHowitworksHowtocodeitAGotchaKeilDebugtip—theWatchwindowHIDIntroductionEnumerationcodeStartsafelyUsecontrolpaneltotest:Get_Descriptor:DeviceGet_Descriptor:InterfaceGet_Descriptor:StringSuspend/ResumeSuspend-ResumeMechanism(TRMCh.11)staticvoidSuspend_ISR(void)interrupt038051receives‘suspend’interrupt‘Suspend’8051doespower-savinghousekeeping,thensetsPCON.0toturnoffoscillator.‘Suspend’CodestaticvoidSuspend_ISR(void)interrupt03 //'03'isSUSPENDinterruptnumber{EZUSB_IRQ_CLEAR(); //AlwaysclearINT2flagfirstUSBIRQ=bmSUSP; //...thenclearSUSPENDIRQbywriting"1"toIRQbitdisplay_hex(0x7F); //decimalpointonlyPCON|=1; //setbitzeroonly:zzzzzzzzzzzzzzzzz}(Initializationin‘main()’:USBIEN=bmSOF|bmSUSP; //EnableSOF&SuspendinterruptsEICON|=0x20; //***EnableResumeInterrupt‘Resume’8051Interrupt6(vector0x33)Oscillatorrestarts,and8051receivesinterrupt6,fromoneoftwosources:USBbusactivityorWAKEUPpingoingLOW.‘Resume’Code//wuisr.csbitWAKEUP=0xD8^4; //declaretheSFRbitaddressforWakeup(EICON.4)staticvoidwakeup(void)interrupt6//vectoraddr33h=51=(6*8)+3{ WAKEUP=0; //justcleartheinterruptrequestbit}Note:thiscodeMUSTbeplacedinadifferentmodulethan‘suspend.c’code,because‘suspend.c’overridesthenormal8051interruptvectorswithit’sdirective: #pragmaintvector(0x17FD)‘Resume’CodeCompleteexamplein‘suspend.c’sofint.cwithenhancements:UpdatesdigitcountratefromEP2OUTAddssuspend/resumecodeThreecodemodulessuspend.cint2jmp.a51wuisr.cSuspend/ResumeIssueThereisaproblemwithsuspend.cAfter‘resume’,thenextIN-2requesthangsDemonstrationDiagnosetheproblemAddanISRforUSBResetDemonstration(suspend2.c)staticvoidURES_ISR(void)interrupt04//'04'isUSBbusresetinterruptnumber{EZUSB_IRQ_CLEAR(); //AlwaysclearINT2flagfirstUSBIRQ=bmURES; //...thenclearSUSPENDIRQbywriting"1"toIRQbitdisplay_hex(0xB6); //3horizsegmentsonly}What’sHappeningUSBbusresetun-armsallINendpointsTRM6,Section10.5:“AfteraUSBbusreset,theEZ-USBcore‘unarms’allBulkINendpoints.Dataloadedbythe8051intoanINendpointbufferremainsthere,andthe8051firmwarecaneitherre-senditbyloadingtheendpointbytecountregistertore-armthetransfer,orsendnewdatabyre-loadingtheINbufferbeforere-armingtheendpoint.”AsolutionRe-armIN2wheneverthere’saUSBresetThispreservesthedataalreadyloadedintotheINendpointbufferDemonstrationstaticvoidURES_ISR(void)interrupt04//'04'isUSBbusresetinterruptnumber{EZUSB_IRQ_CLEAR(); //AlwaysclearINT2flagfirstUSBIRQ=bmURES; //...thenclearSUSPENDIRQbywriting"1"toIRQbitdisplay_hex(0xB6); //3horizsegmentsonlyIN2BC=1; //re-armourINendpoint}FinalSuspend/ResumeNoteNoapparentconsistencyfromPCtoPCinhandlingsuspendMostvariationseeninlaptopsHow(andif)theysuspendHow(andif)theyresumeKILLER:SometurnoffVbusduringsuspendVERYhardtoexecute‘resume’codeifwearebus-poweredandthepowergoesaway…KeilDebugTipKeilDebuggingTipUsingtheWatchWindowDisplayallsymbolsThistableisbuiltfromcompileofyourcode(w.includes)SetWatchPointsWatchwindowupdateswhencodeexecutionstopsWheretofindtoolshelpC:\Cypress\USB\uV2_4k\keil\C51\HLPA51.pdfisAssemblerReferenceManualC51.pdfisCCompilerReferenceManualC:\Cypress\USB\Doc\KeilDocEZ-USBControlPanelHelp/ContentsandTutorial,andHelp/ControlPanelUserGuideHIDPart1HIDClassBuiltintoWindows98(orlater) Noneedtowriteadriver!Mostlyusedbymice,keyboardsCommunicateswithdevicesusingreportsSetReport,GetReportFullSpecatYouneedthespec,andtheHIDUsageTablesHIDTheHIDdescriptorisintheInterfacedescriptor,nottheDevicedescriptorAllowsdifferentinterfacestouseHIDdifferently(e.g.fordifferentcontrols)Classcode(ininterfacedescriptor)bInterfaceClass=3forHIDReportDescriptorsUsagetellswhatacontrolisactuallymeasuringAlsowhatshouldbedonewiththedataExample:x,y,zinputReportdescribesthedataformatExample:three8-bitfieldsInput,Output,FeaturereportsReportDescriptors“BylookingataReportdescriptoralone,anapplicationknowshowtohandleincomingdata,aswellaswhatthedatacouldbeusedfor”.(HIDv1.1Spec,page24).Areportuses‘tags’InputOutputFeature(i/onotintendedfortheenduser)CollectionAmeaningfulgroupingofInput,OutputandFeatureitemse.g.mouse,keyboard,joystickEndCollectionAn“Application”usageappliesanametoatoplevelcollectionwhichtheOSusestoidentifyadeviceandpossiblyre-maptoalegacyAPIBestexamples:kbandmouseReport_Dscr: db 05h,01h ;Usagepage(genericdesktop) db 09h,06h ;Usage(keyboard) db 0A1h,01h ;Collection(application) db 05h,07h ; UsagePage(HIDPage7forkeycodes) db 95h,01h ; Reportcount(1) db 75h,08h ; Reportsize(8) db 15h,00h ; Logicalminimum(0) db 25h,101 ; Logicalmaximum(101d) db 19h,00h ; Usageminimum(0) db 29h,101 ; Usagemaximum(101) db 81h,00h ; Input(Data,Array)--keycode db 05h,08h ; UsagePage(Page8forLEDS) db 95h,03h ; Reportcount(3) db 75h,01h ; Reportsize(1) db 19h,01h ; Usageminimum(1) db 29h,03h ; Usagemaximum(3) db 91h,02h ; Output(Data,Variable,Absolute)--LEDreport db 95h,01h ; Reportcount(1) db 75h,05h ; Reportsize(5) db 91h,01h ; Output(constant)padLEDreportto8bitsReport_end: db 0C0h ;EndCollectionAReportDescriptorAone-buttonremoteNUMLOCKkey/light1byte3bits5bitsHIDToolsHIDDescriptorToolFreeutilityonHelpscreatereportdescriptorsChecksforerrorsHIDViewPartofUSBCheckAlsoonTestsforUSBcomplianceEnumerationCodeEnumeration-LiteStartwritingourownEnumerationcodeProjectssofarhaveusedthepre-enumeratedchipAlldescriptorsforthepre-enumeratedchiparehard-wiredintheSIE,anddocumentedintheTRMEZ-USBhasa‘RENUM’bitUSBCS(0x7FD6)bit1RENUM=0whenthechipcomesoutofresetIntelligentSIEhandlesallhost“Chapter9”requests8051codehandlesdatatransfersWeusedthisfeatureinBULKINandBULKOUTassignmentsThe8051cansetRENUM=1

tohandleCONTROLrequestsincode.HostrequeststhencomethroughtheEP0SUDAVinterrupt,insteadofbeinghandledbytheSIE.BenefitofthisapproachTheRENUMfeatureallowsustowriteenumerationcodealittleatatime,andtestitwithoutthedangerofcrashingtheWindowshostForexample:Get_Descriptor:DeviceControlpanelcancommandthisrequestanytimeAfterchipenumeration,thedataisnotactuallyusedbythehost;it’sonlyreportedbytheapplication(controlpanel)ThereforeanyincorrectvaluescanbeinspectedwithoutdangerofasystemcrashorhangBenefit(cont’d)Oncewe’vewrittenanddebugged8051responsestohostrequestsusingthismethod,wecanputitalltogetherandcomeoninitiallyasthecustomdeviceWeneedthiscapabilitytofunctionwithstandarddriverssuchastheserialUSBorHIDdriverAlsototestfeaturessuchasremotewakeup,whichisnotsupportedintheSIE-GenericEnumeration.enumlite.c(1)

Thisshouldlookfamiliar.DefineVID/PID/DID.#pragmaintvector(0x17FD) //startinterruptsat1800h#pragmainterval(4) //fourbytesperjumpinstr:1800,1804,1808...#defineALLOCATE_EXTERN //ezregs.hneedsthisforstand-aloneprograms#include"ezusb.h" //NOTE:SetenvironmentpathforINCfiles..#include"ezregs.h" //..toc:\Cypress\USB\Target\Inc\#defineVID0x0547#definePID0x2131#defineDID0xabcdenumlite.c(2)

Functionprototypesandglobalvariables//functionprototypesvoidprocess_std_request(void);voidprocess_descriptor(void);voidprocess_class_request(void);voidprocess_vendor_request(void);//globalvariableschar bmRequestType,bRequest,wValueH,wValueL; enumlite.c(3)

DeviceDescriptor.

codeBYTEDevice_Descriptor[]={18, //descriptorlength=18d1, //type=Device(1)0x00,0x01, //USBspecrev(BCD)0xFF,0xFF,0xFF, //Deviceclass,subclass,protocol(vendorspecific)64, //maxpacketsizeforEP0LSB(VID),MSB(VID), //VIDLSB(PID),MSB(PID), //PIDLSB(DID),MSB(DID), //DID1,2,0, //manuf,prod,serialnumstringindices1}; //numberofconfigsinthisinterfaceenumlite.c(4)

USBCS.1istheRENUMbit.main(){USBCS|=bmRENUM; //settingtheRENUMbitputsthe8051inchargeUSBBAV=bmAVEN; //EnableautovectorEUSB=1; //EnableUSB(INT2)interruptUSBIEN=bmSUDAV; //EnableSUDAV(SetupDataAvailable)interruptEA=1; //Enable8051interruptswhile(1); //loopforever,waitingforaninterrupt}enumlite.c(5)

TheSUDAVinterruptmeansaCONTROLpackethasarrived,andthe8SetupbytesaresittinginSETUPDAT[0..7]staticvoidSUDAV_ISR(void)interrupt0x00 //vector00isSUDAV{bmRequestType =SETUPDAT[0];bRequest =SETUPDAT[1];wValueL =SETUPDAT[2];wValueH =SETUPDAT[3];EZUSB_IRQ_CLEAR(); //ClearUSBinterrupt(INT2)USBIRQ=bmSUDAV; //ClearSUDAVIRQ(cont’d)bmRequestTypeStandardClassVendorbRequestCustomProgramming00GET_STATUS0CSTALLCLR_FEATURESET_FEATURESET_ADDRESSGET_DESCRIPT0RSET_DESCRIPT0RGET_C0NFIGSET_CONFIGGET_INTERFACESET_INTERFACESYNC_FRAME010305060708090A0BSTALLotherbRequestd01XXXXXd00XXXXXd11XXXXXd10XXXXX03DEVICECONFIGURATIONSTRING0102STALLotherwValueHenumlite.c(6)

SwitchonfourbmRequestTypevalues.switch(bmRequestType&0x60) //00-std,20-class,40-vendor,60-reserved { caseSETUP_STANDARD_REQUEST:

process_std_request(); break; caseSETUP_CLASS_REQUEST: process_class_request(); break; caseSETUP_VENDOR_REQUEST: process_vendor_request(); break; default: EZUSB_STALL_EP0(); break; }EP0CS|=0x02; //CleartheHSNAKbittoACKtheSTATUSstage}//endSUDAV_ISRenumlite.c(7)

SwitchoneightbRequestvalues.voidprocess_std_request(void){switch(bRequest) { caseSC_GET_DESCRIPTOR: //putmostcommonfirst

process_descriptor(); break; caseSC_SET_FEATURE: break; caseSC_CLEAR_FEATURE: break; caseSC_GET_STATUS: break; caseSC_SET_INTERFACE: break; caseSC_GET_INTERFACE: break; caseSC_SET_CONFIGURATION: break; caseSC_GET_CONFIGURATION: break; default: EZUSB_STALL_EP0(); break; } }enumlite.c(8)

SwitchonfiveDescriptortypes.voidprocess_descriptor(void){switch(wValueH) { caseGD_DEVICE:

SUDPTRH=MSB(Device_Descriptor);

SUDPTRL=LSB(Device_Descriptor); break; caseGD_CONFIGURATION: break; caseGD_STRING: break; caseGD_HID: break; caseGD_REPORT: break; default: EZUSB_STALL_EP0(); break; } }enumlite.c(9)

Stubstofillinlatervoidprocess_class_request(void){ EZUSB_STALL_EP0();}voidprocess_vendor_request(void){ EZUSB_STALL_EP0();}SetupDataPointerReviewLoaddescriptortableinSUDPTRHthenSUDPTRLTheloadordermatters—activatesonSUDPTRLloadEZ-USBcoredoestherestRespondstotheCONTROLtransferDATAstagesPacketizesthedataChecksforerrorsandre-sendsifnecessaryImportant:SUDPTRcanonlyaccesson-chipXDATAmemoryWedesignatedit‘code’,butbecausetheEZ-USB‘VonNeumanizes’the8051Harvardarchitecture,codeanddata(XDAT

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论