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

下载本文档

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

文档简介

USBInterfacingLaneHauckPrerequesitesTogetthemostfromthiscourse,youshouldhaveanEZ-USBDevelopmentSystem.ThissystemincludesaDevelopmentBoardandtheKeilsoftwaredevelopmenttools.Mostchaptersincludeexamplecodeandsimpleprogrammingassignments.Tocompletetheassignments,youmustbeabletowrite8051firmwareusingtheClanguage.TodevelopcodeandruntheUSBdesigns,youmusthaveaccesstoaPCequippedwithaUSBport,andrunningWindows98MeorWindows2000.”AgendaUSBhistoryUSBDemoMouse,Speakers,CameraUSBBasics:10USBFacts8051PrimerEZ-USBArchitectureOnionintroductionUSBResourcesUSBFoundingCompaniesUSB1.0USB2.0CompaqCompaqIntelIntelMicrosoftMicrosoftNECNECIBMLucentDECHPNorthernTelecomPhilipsUSBDemoPluginsomeperipheralsMouseSpeakersCameraNoticethattheyare:“Hotplugged”PoweredbytheUSBcable Question:HowdidthePCknowwhatwaspluggedinandwhichdrivertoload?USBBasicsCablesFourwires:Vbus,GND,D+,D–Vbus:5Vnom,4.4Vminimum(nowallwarts!)Cablesare5metersMAXTwoconnectortypes,AandBPreventsillegaltopologiesUSBextensioncablesareILLEGALPChasa“roothub”with1or2portsEachportsupplies5“unitloads”or500maHubsexpandnumberofdevicesto1267-bitaddress=128–roothub–reservedaddr0Hubscanbebusorself-powered100/500maperdownstreamport10USBFactsFact1

USBisnotsimpleOutside,itissimpleThe“richuserexperience”requiressomeinnercomplexityEventhoughitreplacesserialandparallelports,it’snotadrop-inreplacementIt’selectricallysimple,butawholeprotocollayerisaddedFact2

TheHost(PC)initiatesalltransfersDevicesrespondtohostrequestsDirection:OUTishost-to-deviceDirection:INisdevice-to-hostUSBisNOTpeer-to-peerUSBTopology(a)DeviceDevicePCUSBUSBUSBTopology(b)PCUSBUSB“TieredStar”HubUSBUSBUSBUSBPCUSBUSBDeviceDeviceDeviceDeviceDeviceFact3

USBsupportsthreespeeds

Lowspeedis1.5Mb/sMiceKeyboardsFullspeedis12Mb/sModemsCamerasSpeakersPrintersHighspeedis480Mb/sUSB2.0iscomingFact4

AnEndpointIsanAddressableFIFO

USBSpec:“asourceorsinkofdata”CONTROLendpointisbi-directionalOthersareuni-directionalFouraddressbitsplusadirectionbitselectsbetween32buffers(FIFOs)DifferentUSBchipssupportVariousnumbersofendpointsVariousbuffersizesFact5

USBSupportsFourTransferTypesBulkGuaranteedaccuracy,butdeliverytimeisvariableBestfor“bursty”dataIsochronousGuaranteeddeliverytime,butaccuracyisnotguaranteedControlEnumerationanddevicecontrolInterruptPredictablepollingtimeFact6

USBTransfersOccurin1msFramesHostsends“SOF”(StartOfFrame)tokenevery1msHostschedulespacketsinsideframes.IsochronousdataFIFOS“ping-pong”everySOFAnatomyofaUSBFrame12MHz=1.5MB/sor1500bytes/msIsochronous/InterrupttraffichaveguaranteedbandwidthControltrafficis“best-effort”BulkuseswhatisleftActualschedulingorderdependsonhostcontrollerUHCI,OHCIVideoAudioMouseControlPrinterPrinter1msecframeSOF...IsochronousInterruptControlBulkSOFFact7

USBDataTravelsinPacketsIdentifiedby“PacketID”(PID)Tokenpackettellswhat’scomingDatapacketsdeliverbytesHandshakepacketsreportsuccessorotherwiseUSBPacketsSETUPADDRCRC5SYNCENDPDATA0CRC16SYNCDataACKSYNCTokenPacketDataPacketH/SPktSetupStageDataStageDataStage(cont'd)DataStage(cont'd)AControlWriteTransferDATA1CRC16SYNCDataDataPacketACKSYNCH/SPktOUTADDRCRC5SYNCENDPTokenPacketDATA0CRC16SYNCDataDataPacketACKSYNCH/SPktOUTADDRCRC5SYNCENDPTokenPacketDATA1CRC16SYNCDataACKSYNCH/SPktDataPacketOUTADDRCRC5SYNCENDPTokenPacketINADDRCRC5SYNCENDPDATA1CRC16SYNCACKSYNCDataPacketH/SPktTokenPacketStatusStageTheSIE

(SerialInterfaceEngine)SerialInterfaceEngine(SIE)D+BytesUSBTransceiverD+Fact8

Bulk/Ctl/IntTransfersHaveErrorRecoverySuccess=ACKtokenError=Noresponse(timeout)Busy=NAKtoken(tryagainlater)Fact9

ErroneousorMissingISODataIsLostNohandshakesorretriesIndividualapplicationmusthandleerrorsFact10

USBProjectsRequireaSignificant

CodeDevelopmentEffortDevicesideUSBhouskeepingfirmwareApplicationfirmwareHostsideDriver(maybe)ApplicationsoftwareTheEZ-USBDevelopmentkitsupplieshelpforbothsides,especiallythedevicesideFact11(OK,11facts)

ConformtoastandardUSBdeviceclass,andyouwon’tneedtowriteadriver.BIG

incentiveSpendeffortmakingfirmwareclass-compliantInWin98HID(HumanInterfaceDevice)SpeakersCommAdditionalWin2000andMillenniumdevicesMassstorageStillimagePrinter8051Primer8051Primer

Ass’ylangaccesstoInternalRegisters128GPRegisters00SFRegisters80FF7F128GPRegisters8052orEZ-USBFF80mov a,SBUF0mov TCON,#55hmyvar equ 40hmov a,r0mov myvar,aDirectAddressingIndirectAddressingmov r0,#90hmov a,@r0mov SP,#80h8051Primer

’C’accesstoInternalRegisters128GPRegisters00SFRegisters80FF7F128GPRegisters8052orEZ-USBFF80char(data)TCON;TCON=0x55;char(data)myvar1;myvar1=othervar;DirectAddressingIndirectAddressingcharidatamyvar2myvar2=0x558051Primer

Ass’ylangaccessto

8051ExternalMemory64KilobytesRAMFFFF000064KilobytesROMFFFF0000mov dptr,#8051hmovx a,@dptrmov MPAGE,#80hmov r0,#51hmovx a,@r0mov dptr,#8051hmovc a,@dptrRD#WR#PSEN#DataProgram8051Primer

’C’accessto

8051ExternalMemory64KilobytesRAMFFFF000064KilobytesROMFFFF0000charxdatadig[]=3,5,7;num=dig[2];RD#WR#PSEN#DataProgramcharcodedig[]=3,5,7;num=dig[2];8051Primer

EZ-USBInternalRAM8KilobytesRAMFFFF00008KilobytesRAMFFFF0000RD#WR#PSEN#7FFF7FFF8051Primer

EZ-USBCOMBINESinternal8KProgram&DataRAM8KilobytesRAM0000RD#WR#PSEN#7FFFcharxdatadig[]=3,5,7;num=dig[2];charcodedig[]=3,5,7;num=dig[2];isequivalenttoTherefore:8051Primer

EZ-USBControlRegistersandEndpointbuffers

Assemblylanguageaccess0000RD#WR#PSEN#7FFF7B40AllEZ-USBcontrolandstatusregistersandendpointbuffersarehere.Accessthemusingthedatapointerand‘movx’instruction.Example:mov dptr,#OUT2BCmov a,#35movx @dptr,a0000RD#WR#PSEN#7FFF7B40XdatacharOUT2BC_at_0x7FC9;….OUT2BC=45;8051Primer

EZ-USBControlRegistersandEndpointbuffers

CaccessEZ-USBArchitectureLearningUSB

TheConventionalWayUSBLearningContinuumPracticeTheoryStartFinishEnumerationcodetimeUSBLearningContinuumPracticeTheoryLearningUSB

UsingtheEZ-USBChipLearnhowtoservicedevicerequeststosetupUSBdevicesWriteCcodetoperformUSBtransfersusingpre-EnumeratedUSBdevice.(Lecture2:aBULK-INUSBtransfer.)timetimeStartFinishFinishDevelopmentKitContentsEZ-USBdevelopmentboardPrototypingboardEZ-USBdevelopmentsoftwareControlpanelKeiltoolsetAssemblerCcompilerLimited(4Kilobyte)codesizeEZ-USBTechnicalReferenceManualAndersonbookNecessarycablesDevelopmentFlowBulkINTransferxdatavolatilecharIN2BUF[64]_at_0x7E00;xdatavolatilecharIN2BC_at_0x7FB9;xdatavolatilecharIN2CS_at_0x7FB8;#define bBSY 0x02charj,count;main(){for(j=0;j<64;j++) //fillIN2bufferwithincrementingcount

IN2BUF[j]=j;IN2BC=64; //armthefirstIN2transfercount=0;while(1) //forever { while(IN2CS&bBSY); //loopwhileIN2busybitisHI

IN2BUF[0]=++count; //busybitwentLO--IN2BUFreadyformoredata

IN2BC=64; //armthenextIN2transferbyloadingbytecount } }BulkOUTTransfermain(){while(1) { while(OUT2CS&bBSY); //loopwhileEP2OUTbusybitisHI count=OUT2BC; //BusybitisLO--EP2OUTdatawassent for(j=0;j<count;j++) { display_hex(Digit[OUT2BUF[j]]);//usebyteinEP2OUTtolookupsegments delay(DISPLAYTIME); //delaysowecanseeit display_hex(0xFF); //blankdisplay(active-lowsegments;1=off) delay(DISPLAYTIME); }

OUT2BC =0; //armthenextOUT2transfer(BC=x) }}Assemblycode:AHandy8051MacroLDREG MACRO ad,val ;Loadregisterwithval mov a,val mov dptr,#ad movx @dptr,a ENDMBulkINTransfer(AssyCode)start: mov dptr,#IN2BUF mov r7,#64 ;fillEP2INbufferwith64bytesfill: mov a,r7 movx @dptr,a inc dptr djnz r7,fill ;loaddecrementingcounterstartingw.64 mov count,#0 ;counttheINtransfers

LDREG

IN2BC,#64 ;loadtheIN2ByteCountRegisterloop: JBL IN2CS,BSY,IN2 ;checkthebusybit sjmp loopIN2: inc count ;INpacketcounter

LDREG

IN2BUF,count ;put‘count’intofirstbufferbyte

LDREG

IN2BC,#64 ;thisarmstheINtra

温馨提示

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

评论

0/150

提交评论