收藏 分销(赏)

USB规范讲解及简单设计实例.pdf

上传人:曲**** 文档编号:226291 上传时间:2023-03-09 格式:PDF 页数:28 大小:807.53KB
下载 相关 举报
USB规范讲解及简单设计实例.pdf_第1页
第1页 / 共28页
USB规范讲解及简单设计实例.pdf_第2页
第2页 / 共28页
USB规范讲解及简单设计实例.pdf_第3页
第3页 / 共28页
USB规范讲解及简单设计实例.pdf_第4页
第4页 / 共28页
USB规范讲解及简单设计实例.pdf_第5页
第5页 / 共28页
点击查看更多>>
资源描述

1、USB规范讲解及简单设计实例要进行USB的硬件软件设计就先要了解 USB规范,今天简要介绍以下内容1.usb规范的版本发展2.使用USB设备的优缺点3.USB设计所要使用的软硬件资源和具体 流程,4.usb规范内容5.最后通过一个简单实例介绍一下usb设备 设计的概况l.Usb规范版本 Usb规范的前身是access上us规 范,access.busi范是由philips和数字设备 公司所制定而公开的标准,A ccess上us是 由 12c synchronies serial bus发展来的USB规范版本1.01.12.0发表日期 1996.1.15 1998.9.23 2000.4.272

2、.1USB的优点 容易使用:系统自动检测,不需重开机,容易连接,不需外加 电源 传输速度快:usb支持三种信道速度:低速L5Mb/s(鼠标,键 盘,游戏机),全速12Mb/s(电话,音频,麦克风),高速 480Mb/s(影像,储存设备)价位低 低能耗 稳定性 操作系统支持 外围设备支持 有弹性 usb实施者论坛支持 usb implementers forumJnc.,USB-IF www.usb.org2.2USB的缺点 缺乏对旧硬件的支持点对点的通信 速度的限制usb高速模式480Mb/s可与ieee-1394 400Mb/s 匹敌.但 ieee-1394b 速度达至 U3.2Gb/s距离

3、的限制电缆长度最长5M远如果要延伸必须通过 集线器最长可以达到30M需要6条5M长电缆需要5个 集线器 硬件的错误和故障 协议的复杂性 版权费3.USB开发准备 所需组件支持usb的主机主机上的设备驱动程序设备上的软硬件主机应用程序软件 开发工具一个汇编或C语言编译器(keil c51)一个监视程序,协议分析器帮助开发固件一个烧录设备和烧录程序(top851)一个主机上的程序语言和开发环境,来编写调试 主机软件(VC+)4.Usb协议概述4.1 一些概念包标识符PID:USB包的同步字段后都紧跟着包 标识符(PID)。如图8-1所示,包标识符由4 位的包类型字段和其后的4位的校验字段构 成。包

4、标识符指出了包的类型,并由此隐含地 指出了包的格式和包上所用错误检测的类型。(LSb)(MSb)P,D0 PID1 PID2 PID3 同。丽 丽2 瓯PID类型PID名MD|3:0检述标记(Token)输出(OUT)0001B在主机到功能部作的事务中有地址+端口号输入(IN)1001B在功能邻侔到主机的事务中有比址+说口号帧开始(SOF)0101B帧开始标记和帧号建立(SE TUP)1101B在主机到功能部伸转立一个控制管道的事务中有 地址+端口号数据(D A TA)抽悒。(D A TA 0)0011B1%鼓翻包PID赖据-nD A TA l)1011B奇抽悒包PID握手(Handshake

5、)确认(A C K)0010B隹收器收到无指数据包;不确认(NA K)1010B链收除富都不能隹收数据,或发送除缶不能发送教悒;停止(STA LL)1110B端口住起,或一个控制管道请求不独支恃.专用(Special)前同步(PRE)11C 0B主机发送的前网步字.打开到低速陵富的下行总 线通信.标记包:图8-5显示了标记包的字段格式。标记由PID,ADDR 和ENDP构成,其中PID指定了包是输入,输出还是建 立类型。对于输出和建立事务,地址和端口字段唯一 地确定了接下来将收到数据包的端口。对于输入事务 的,这些字段唯一地确定了哪个端口应该传送数据 包。只有主机能发出标记包。输入PID定义了

6、从功能部 件到主机的数据事务。输出和建立PID定义了从主机到 功能部件的数据事务。blD VDDK EMDb CHC2标记包包括了覆盖地址和端口字段的5位CRC。CRC并 不覆盖PID,因为它有自己的校验字段。传输:制造与携带一个通信要求的过程每一个传输包含 一笔或多笔事物,而每一笔事物包含一个,两个或是三个 信息包,每个信息包包含一个信息包标识符,CRC校验位,以及额外的信息.每一笔事物包含一个令牌信息包,并且 可能包含一个数据信息包或联络信息包.帧开始(SOF,Start-of-Frame)包主机以每1.00 ms 0.0005 ms一次的额定速率发出 帧开始(SOF)包。如图8-6中所示

7、,SOF包是由指 示包类型的PID和其后的H位的帧号字段构成。8 bits 11 bits 5 bitsPIDFrame NumberCRC5Y tSOF标记组成了仅有标记的(token-only)事务,它以 相对于每帧的开始精确计算的时间间隔发送SOF记 号(Marker)和伴随的帧数。包括集线器的所有全 速功能部件都可收至USOF包。SOF标记不会使得接 收功能部件产生返回包;因此,不能保证向任何给 定的功能部件发送的SOF都能被收到。数据包:数据包由PID,包括至少0个字节数据的数据区和CRC构成。有2种类型的数据包,根据不同的PID:DATAO和DATA1来识别。2种数据包PID是为了

8、*持数据切换同 步(Data Toggle Synchronization)而定义的。BIDCKCJeDVXV8O-JO53 pXieaJO P42数据必须以整数的字节数发出。数据CRC仅通过对包中 的数据字段计算而得到,而不包括PID,它有自己的校 验字段。4.2控制传输:Usb包括四种传输类型:控制传输,中断传输,批量传输,实 时传输,主机使用控制传输与设备交换配置的设置信息,同时设备也使用控制传输来传输任何类型的信息.每一 个控制传输都有一定的格式包括一个设置阶段,一个数据阶段,一个状态阶段421设置阶段:令牌信息包PID:setup数据信息包PID:dataO 联络信息包PID:ack

9、IdleIdlG|Host|FunctionControl SETUP F ran suctionTable 9-2.Format of Setup DataOffsetFieldSizeValueDesc ription0brnRoquostTypo1BitmapCharac teristic s of req uest:D7:Data transfer direc tion0=Host-to-dGvic 1=Devic e-to-hostD6.5:Type0=Standard1=Class2=Vendor3=RgsgcvgcID4.0:RedpiGnt 0=Devic e 1=Interf

10、ac e 2=Endpoint 3=Other 4.31=Rasorved1bRequest1ValueSpec ific req uest(refer to Table 9-3)2w Value2ValueWord-sized field that varies ac c ording to req uest4windex2Index or OffsetkVord-sized field that varies ac c ording to req uest:typic ally used to pass an index or offset6wLength2CountNumber of b

11、ytes to transfer if there is a Data stag e4.2.2.数据阶段:令牌信息包PID:out in数据信息包PID:datal/dataO联络信息包ACK,NAK,STALL4.2.3.状态阶段:Table 9-3.Standard Device RequestsbrnRq iiGstT ypbReq iiGStwValuGwlndexwLong thDataOlHJN.H IROOOOOOO1B 0000001OBCLEAR_FEATUREFeoturG Selec torZero Interfac e EndpointZeroNone10OOOOOOB

12、GET,CON FIGURATIONZeroZeroOnConfig uration Value1OOOOOOOBGET_DESCRIPTORDesc riptor Type and Desc riptor IndexZero or Lang uag e IDDesc riptor Leng thDesc riptor10000001BGET.INTERFACEZeroInterfac eOnAlternate Interfac e1OOOOOOOB1000000IB1000001OBGET_STATUSZeroZero Interfac e EndpointTwoDevic,Interfac

13、 e,or Endpoint StatusOOOOOOOOBSET.ADDRESSDevic e AddressZeroZeroNonOOOOOOOOBSET.CONFIGURATIONConfig uration ValueZeroZeroNonOOOOOOOOBSET DESCRIPTORDesc riptor Type and Desc riptor IndexZero or Lang uag eID、Desc riptor Leng thDesc riptorOOOOOOOOBOOOOOOO1B 0000001OBSET FEATUREFsaturSelec torZero Inter

14、fac e EndpointZeroNonOOOOOOOIBSET_INTERFACEAlternate SettingInterfac eZeroNon1000001OBSYNCH FRAMEZeroEndpointTwoFrame Number4.3描述符:4.3.1设备描 述符号Standard Device DescriptorOffsetFieldSizeValueDescription0bLength1NumberSize of this desc riptor in bytes1bDGScriptorTypo1ConstantDEVICE Desc riptor Type2bcd

15、USS2BCDUSB Spec ific ation Release Numtr in Binar/-CodGd Dec imal(i.e.2.10 is 21 OH).This field identifies the release of the USB Spec ific ation with 4hic h the devic e and its dGSc riptors are c ompliant.4bDeviceClass1ClassClass c ode(assig ned by th USB-IF).If this field is reset to zero,eac h in

16、terfac e v/ithin a c onfig uration spec ifies its ovn c lass information and th various interfac es operate independently.=Techmcal Help to Exporters 出商Efspec ific ations on different interfac es and th interfac GS may not operate independently.This value identifies the c lass definition used for th

17、s ag g reg ate interfac es.If this field is set to FFH.the devic e c lass is vendor-spec ific.5bDecoSubClass1SubClassSubc lass c od(assig ned by the USB-IF).These c odes are q ualified by the value of the bDeviceClass field.If ths bDeviceClass field is reset to zero,this field must also be reset to

18、zero.If th bDoviceCisss field is not set to FFH.all values are reserved for assig nment by th USB-IF.Standard Device Descriptor(Continiwd)OffsetFieldSizeValueDesc ription6bDevicG Protocol1Protoc olProtoc ol c ode(assig ned by the USB-IF).These c odes are q ualified by the value of the bDeviceQass an

19、d the bDevicGSubClass fields.If a devic e supports dass-spec ific protoc ols on a devic e basis as opposed to an interfac e basis,this c ode identifies the protoc ols that the devic e uses as defined by the spec ific ation of the devic e c lass.If this field is reset to zero,the devic e does not use

20、 c iass-spec ific protoc ols on a devic e basis.Hovver,it may use c lassspec ific protoc ols on an interfac e basis.If this field is set to FFH.the devic e uses a vendor-spec ific protoc ol on a devic e basis.7bMaxPacketSizeO1NumberMaximum pac ket size for endpoint zero(only 8,16,32,or 64 are valid)

21、8id Vendor2IDVendor ID(assig ned by th USB-IF)10idPtoduct2IDProduc t ID(assig ned by the manufac turer)12bcdDevicQ2BCDDevic release number in binary-c oded dec imal14Manufacturer1IndexIndex of siring desc riptor desc ribing manufac turer15iPiDdud1IndexIndex of siring desc riptor desc ribing produc t

22、16iSenalNumber1IndexIndex of siring desc riptor desc ribing the devic e s serial number17bNumCon figurations1NumberNumber of possible c onfig urations4.32配置描述符Standard(onfliration DescriptorOffsetFieldSizeValueDescription0bLength1NumberSize of this descriptor in bytes1bDescnptorType1ConstantCONFIGUR

23、ATION Descriptor Type2wTotalLength2NumberTotal length of data returned for this configuration.Includes the combined length of all descriptors(configuration,interface,endpoint,and class-or vendor-specific)returned for this configuration.4bNumlnterfaces1NumberNumber of interfaces supported by this con

24、figuration5bCofifigurationValue1NumberValue to use as an argument to the SetConfiguratioiii j request to select this configuration6/Configuration1IndexIndex of string descriptor describing this configurationStandard(oniluuration Desc riptor(Continued)OffsetFieldSizeValueDesc ription7bmAttributes1Bit

25、mapConfig uration c harac teristic sD7:Reserved(set to one)Do:Setf-poweredD5:Remote Wa keupD4.0:Reserved(reset to zero)D7 is reserved and must be set to ore fee historic al reasons.A devic e c onfig uration that uses pewer frem、bus and a loc al sourc e reports a nc n-zero value in bMaxPowec to indic

26、 ate the amc tjnt of bus pov、M req uired and sets 06.The ac tual pow*c&xjrc e at runtime may be deterrri r=d usiog Get Stat us(DEVICE)req uest(&=e Sec tion 9.4.5).If a devic e c onfig uration suppc c ts remote wakeup.D5 is set to one.8bMaxPower1mAFdaxinnum c onsumption of the USBdec e from the bus i

27、n this spec ificQ哈。QbMa炉ower也对勰:黑落兔黑案 没找到!18 mA).Note:A devic e c oafuration reports whether the c onfig uration is t(Js-powN=c ed or self-pow=fed.Devic e status reports whett=r 卜 devic e is c urrently self-pc r/ered.If a devic e is disc onnec ted from its external p“er sourc e,it updates devic e st

28、atus to indic ate that it is no long er self-po*ered.A devic e may not inc rease its power draw fr3m the bus,when it loses its external power sourc e,beyond the amount reported by its c onfig uration.If a devic e c an oendnue to operate when disc onnec ted from its external pwer sourc e,it c ontinue

29、s to do so.If the deoe-c anmt c ontinue to operate,it fails operations it c an no long er support.71石 USB System Software may determir the c ause of the failure by c tc ki rg status a rd noting the loss of the devic es po、sourc e.433.接口描述符bNUMEndpoints除端点零外支持的端点数目 blnterfaceclass 与bdeviceclass类似434.

30、端点描述符bendpointaddress Ibyte端点数目与方向Bmattributes Ibyte支持的传输类型控制实时批量中断Wmaxpacketsize 2byte端点能够传输的最大信息包大小Binterval Ibyte轮询中断端点的最大延迟或是轮询实时端点的时距或是高速批量输出或控制端点的最 大NAK速率.4.3.5.字符串描述符Wlangid或bstring Ibyte语言ID或产品名5.控制传输实例:bm Request TypebRequestwValuewlndexwLengthData10100000BGET DESCRIPTORDescriptor Type and

31、Descriptor IndexZeroDescriptor LengthDescriptor功能:主机要求返回一个指定的描述符数据来源:设备wValue:高字节是描述符类型,低字节是描述符数值wlndex:如果是字符串描述符表示语言的ID,其他描述符为 0.数据阶段的数据信息:要求的描述符.5.USB硬件软件设计实例本实例通过使用philips公司的usbl.l controller pdiusbdl2,下位机mcu使用89c738,驱动程序系统支持,上位机使用VC+编程.5.l usb开发需要知识和工具5.1.1 具体开发需要准备的工具和掌握的知识1.下位机程序设计C512.VC+程序设计

32、3.驱动程序一般了解4.收集资料的能力5.选择控制芯片的能力5.L2.必备资源L首先要搜集软件工具,上位机下位机编译器2.编程器3.能够买到要使用的芯片4.协议分析软件或硬件工具5.示例代码52PDIUSBD12芯片引脚图5.3.usb定义的类别码 bdeviceclass binterfaceclass例如HID0 x000 x03HUB 0 x09Mass storage 0 x0054下位机电路图0 x090 x085.5.下位机程序function block diagram2:-USB,;,、,总线事件等等MAINLOOP.C捽制LED即处守USB标准请求CHAP_9.C厂商请求PR

33、OTODMA.C中断服务程序ISR.CPD1USBDI2 P令接 IDI2C1.C硬件提取层E PPHA L.C以下是PDIUSBD12发送数据或命令的子程序Void outportb(unsigned int Addr,unsigned char Data)*(unsigned char xdata*)Addr)=Data;Addr是PDIUSBD12的地址,Data是输出的数据或和命令.当 Addr为奇数时表示输出的是命令,Addr为偶数时表示输 出的是数据下面的程序为从PDIUSBD12器件读取数据,addr为偶数Unsigned char inportb(unsigned int Ad

34、dr)return*(unsigned char xdata*)addr);#define D12.DATA 0 xff02 定义数据地址(偶数地址)#define D12_COMMAND 0 xff03 定义数据地址(偶数地 址)5.6.上位机程序设计:API函数。IRP*说明。以感域质IRP_MJ_CREATEp打开设备0IRP_MJ_READ从设备获取数据/IRP_MJ_WRITE向设备发送数据IRP_MJ_CLOSE关闭设备。砒以qC娘女以。IRP_MJ_DEVI CE_C ONTROI控制操作应川程序要和某个设备通信前要获得这个设备的 独特识别码GUID(128bit)码,通过A PI函数调川 获得接口信息,获取设备路径名然后就是打开这 个设备,获取设备句柄打开设备获取句柄通过 A PI 函数 C reateF ile 实现读写设备由ReadF ile WriteF ile函数完成关闭设备C loseHandle函数完成THE END

展开阅读全文
相似文档                                   自信AI助手自信AI助手
猜你喜欢                                   自信AI导航自信AI导航
搜索标签

当前位置:首页 > 行业资料 > 机械/制造/汽车

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        获赠5币

©2010-2024 宁波自信网络信息技术有限公司  版权所有

客服电话:4008-655-100  投诉/维权电话:4009-655-100

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :gzh.png    weibo.png    LOFTER.png 

客服