您好,欢迎访问三七文档
当前位置:首页 > 行业资料 > 生活/日用品 > Cypress USB教程第5讲
5-1Lecture5AgendaSuspend/ResumeHowitworksHowtocodeitAGotchaKeilDebugtip—theWatchwindowHIDIntroductionEnumerationcodeStartsafelyUsecontrolpaneltotest:Get_Descriptor:DeviceGet_Descriptor:InterfaceGet_Descriptor:String5-2Suspend/Resume5-3Suspend-ResumeMechanism(TRMCh.11)PLLOscillatordivby2805148MHzCLK2412MHzSTARTUSBRESUMEWAKEUPpinPCON.0STOPUSBSUSPENDInterruptNoUSBactivityfor3msec.RESUMEINTSignalResume(USBCS.0)RestartDelaystaticvoidSuspend_ISR(void)interrupt038051receives‘suspend’interrupt5-4‘Suspend’PLLOscillatordivby2805148MHzCLK2412MHzSTARTUSBRESUMEWAKEUPpinPCON.0STOPUSBSUSPENDInterruptNoUSBactivityfor3msec.RESUMEINTSignalResume(USBCS.0)RestartDelay8051doespower-savinghousekeeping,thensetsPCON.0toturnoffoscillator.5-5‘Suspend’CodestaticvoidSuspend_ISR(void)interrupt03//'03'isSUSPENDinterruptnumber{EZUSB_IRQ_CLEAR();//AlwaysclearINT2flagfirstUSBIRQ=bmSUSP;//...thenclearSUSPENDIRQbywriting1toIRQbitdisplay_hex(0x7F);//decimalpointonlyPCON|=1;//setbitzeroonly:zzzzzzzzzzzzzzzzz}(Initializationin‘main()’:USBIEN=bmSOF|bmSUSP;//EnableSOF&---SuspendinterruptsEICON|=0x20;//***EnableResumeInterrupt5-6‘Resume’PLLOscillatordivby2805148MHzCLK2412MHzSTARTUSBRESUMEWAKEUPpinPCON.0STOPUSBSUSPENDInterruptNoUSBactivityfor3msec.RESUMEINTSignalResume(USBCS.0)RestartDelay8051Interrupt6(vector0x33)Oscillatorrestarts,and8051receivesinterrupt6,fromoneoftwosources:USBbusactivityorWAKEUPpingoingLOW.5-7‘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)5-8‘Resume’CodeCompleteexamplein‘suspend.c’sofint.cwithenhancements:UpdatesdigitcountratefromEP2OUTAddssuspend/resumecodeThreecodemodulessuspend.cint2jmp.a51wuisr.c5-9Suspend/ResumeIssueThereisaproblemwithsuspend.cAfter‘resume’,thenextIN-2requesthangsDemonstrationDiagnosetheproblemAddanISRforUSBResetDemonstration(suspend2.c)staticvoidURES_ISR(void)interrupt04//'04'isUSBbusresetinterruptnumber{EZUSB_IRQ_CLEAR();//AlwaysclearINT2flagfirstUSBIRQ=bmURES;//...thenclearSUSPENDIRQbywriting1toIRQbitdisplay_hex(0xB6);//3horizsegmentsonly}5-10What’sHappeningUSBbusresetun-armsallINendpointsTRMpage10-6,Section10.5:“AfteraUSBbusreset,theEZ-USBcore‘unarms’allBulkINendpoints.Dataloadedbythe8051intoanINendpointbufferremainsthere,andthe8051firmwarecaneitherre-senditbyloadingtheendpointbytecountregistertore-armthetransfer,orsendnewdatabyre-loadingtheINbufferbeforere-armingtheendpoint.”5-11AsolutionRe-armIN2wheneverthere’saUSBresetThispreservesthedataalreadyloadedintotheINendpointbufferDemonstrationstaticvoidURES_ISR(void)interrupt04//'04'isUSBbusresetinterruptnumber{EZUSB_IRQ_CLEAR();//AlwaysclearINT2flagfirstUSBIRQ=bmURES;//...thenclearSUSPENDIRQbywriting1toIRQbitdisplay_hex(0xB6);//3horizsegmentsonlyIN2BC=1;//re-armourINendpoint}5-12FinalSuspend/ResumeNoteNoapparentconsistencyfromPCtoPCinhandlingsuspendMostvariationseeninlaptopsHow(andif)theysuspendHow(andif)theyresumeKILLER:SometurnoffVbusduringsuspendVERYhardtoexecute‘resume’codeifwearebus-poweredandthepowergoesaway…5-13KeilDebugTip5-14KeilDebuggingTipUsingtheWatchWindowDisplayallsymbolsThistableisbuiltfromcompileofyourcode(w.includes)SetWatchPoints5-15Watchwindowupdateswhencodeexecutionstops5-16WheretofindtoolshelpC:\Cypress\USB\uV2_4k\keil\C51\HLPA51.pdfisAssemblerReferenceManualC51.pdfisCCompilerReferenceManualC:\Cypress\USB\Doc\KeilDocEZ-USBControlPanelHelp/ContentsandTutorial,andHelp/ControlPanelUserGuide5-17HIDPart15-18HIDClassBuiltintoWindows98(orlater)Noneedtowriteadriver!Mostlyusedbymice,keyboardsCommunicateswithdevicesusingreportsSetReport,GetReportFullSpecatYouneedthespec,andtheHIDUsageTables5-19HIDTheHIDdescriptorisintheInterfacedescriptor,nottheDevicedescriptorAllowsdifferentinterfacestouseHIDdifferently(e.g.fordifferentcontrols)Classcode(ininterfacedescriptor)bInterfaceClass=3forHIDReportDescriptorsUsagetellswhatacontrolisactuallymeasuringAlsowhatshouldbedonewiththedataExample:x,y,zinputReportdescribesthedataformatExample:three8-bitfieldsInput,Output,Featurereports5-20ReportDescriptors“BylookingataReportdescriptoralone,anapplicationknowshowtohandleincomingdata,aswellaswhatthedatacouldbeusedfor”.(HIDv1.1Spec,page24).Areportuses‘tags’InputOutputFeature(i/onotintendedfortheenduser)CollectionAmeaningfulgroupingofInput,OutputandFeatureitemse.g.mouse,keyboard,joystickEndCollectionAn“Application”usageappliesanametoatoplevelcollectionwhichtheOSusestoidentifyadeviceandpossiblyre-maptoalegacyAPIBestexamples:kbandmouse5-21Report_Dscr:db05h,01h;Usagepage(genericdesktop)db09h,06h;Usage(keyboard)db0A1h,01h;Collection(application)db05h,07h;UsagePage(HIDPage7forkeycodes)db95h,01h;Reportcount(1)db75h,08h;Reportsize(8)db15h,00h;Logicalminimum(0)db25h,101;Logicalmaximum(101d)db19h,0
本文标题:Cypress USB教程第5讲
链接地址:https://www.777doc.com/doc-4060736 .html