usb设备固件结构分析
由于要用fpga给电脑传输视频信息,所以决定用cypress公司的cy7c68013A来作为usb、设备的主控芯片,看了好2周的usb的书,基本上算是把大概的协议搞清楚了,今天开始着手开发固件,这些示例都是以官方示例的基础上更改过来的。
dscr.a51。usb的描述符文件。
包括设备描述 ,接口描述符,端点描述符,字符串描述符等。用于描述设备的总体信息。包括pid,vid,设备类和设备子类等。一个usb设备只能有一个设备描述符。配置描述符一般描述usb设备的配置信息。可以有一个或者多个配置,每个配置必须有一个配置描述符。字符串描述符用来保存一些供应商的名称,设备序列号,供应商名称等的文本信息。接口描述符用来表述usb接口中各个接口的特性。,包括接口号,端点个数,所属的设备和子类等等。
端点描述符表述usb设备端点的特性,包括所支持的传输类型、传输方向、最大的数据包长度、和访问间隔等信息。
;;-----------------------------------------------------------------------------
;; File: dscr.a51
;; Contents: This file contains descriptor data tables. 此文件包含描述符表
;;
;; $Archive: /USB/Examples/Fx2lp/bulkloop/dscr.a51 $
;; $Date: 9/01/03 8:51p $
;; $Revision: 3 $
;;
;;
;;-----------------------------------------------------------------------------
;; Copyright 2003, Cypress Semiconductor Corporation
;;-----------------------------------------------------------------------------;;-----------------------------------------------------------------------------
DSCR_DEVICE equ 1 ;; Descriptor type: Device 描述类型:设备
DSCR_CONFIG equ 2 ;; Descriptor type: Configuration 描述类型:配置
DSCR_STRING equ 3 ;; Descriptor type: String 描述类型:字符串
DSCR_INTRFC equ 4 ;; Descriptor type: Interface 描述类型:接口
DSCR_ENDPNT equ 5 ;; Descriptor type: Endpoint 描述类型:端点
DSCR_DEVQUAL equ 6 ;; Descriptor type: Device Qualifier 描述类型:设备速度类型,告诉或全速设备所独有
DSCR_DEVICE_LEN equ 18
DSCR_CONFIG_LEN equ 9
DSCR_INTRFC_LEN equ 9
DSCR_ENDPNT_LEN equ 7
DSCR_DEVQUAL_LEN equ 10
ET_CONTROL equ 0 ;; Endpoint type: Control 端点类型,控制传输
ET_ISO equ 1 ;; Endpoint type: Isochronous 端点类型,等时传输
ET_BULK equ 2 ;; Endpoint type: Bulk 端点类型,块传输
ET_INT equ 3 ;; Endpoint type: Interrupt 端点类型,中断
public DeviceDscr, DeviceQualDscr, HighSpeedConfigDscr, FullSpeedConfigDscr, StringDscr, UserDscr
DSCR SEGMENT CODE PAGE
;;-----------------------------------------------------------------------------
;; Global Variables
;;-----------------------------------------------------------------------------
rseg DSCR ;; locate the descriptor table in on-part memory.
DeviceDscr:
db DSCR_DEVICE_LEN ;; Descriptor length 设备描述符的长度,18字节。
db DSCR_DEVICE ;; Decriptor type 描述类型
dw 0002H ;; Specification Version (BCD) 符合usb2.0规范
db 00H ;; Device class 设备类代码
db 00H ;; Device sub-class 设备子类代码
db 00H ;; Device sub-sub-class 设备协议代码
db 64 ;; Maximum packet size 端点0的最大包大小
dw 3412H ;; Vendor ID 厂商id vid
dw 7856H ;; Product ID (Sample Device) 产品id pid
dw 0000H ;; Product version ID 设备版本
db 1 ;; Manufacturer string index 厂商的字符串描述索引
db 2 ;; Product string index 产品的描述符索引
db 0 ;; Serial number string index 设备序列号的字符串描述符索引
db 1 ;; Number of configurations 可能的配置数目
DeviceQualDscr:
db DSCR_DEVQUAL_LEN ;; Descriptor length 高速设备独有的描述符,支持全速和高速的设备,必须有一个这个描述符
db DSCR_DEVQUAL ;; Decriptor type
dw 0002H ;; Specification Version (BCD)
db 00H ;; Device class
db 00H ;; Device sub-class
db 00H ;; Device sub-sub-class
db 64 ;; Maximum packet size
db 1 ;; Number of configurations
db 0 ;; Reserved
HighSpeedConfigDscr:
db DSCR_CONFIG_LEN ;; Descriptor length 配置描述符,高速设备描述符
db DSCR_CONFIG ;; Descriptor type 描述类型 =0x02
db (HighSpeedConfigDscrEnd-HighSpeedConfigDscr) mod 256 ;; Total Length (LSB) 描述符总长度,低字节
db (HighSpeedConfigDscrEnd-HighSpeedConfigDscr) / 256 ;; Total Length (MSB) 高字节
db 1 ;; Number of interfaces 接口数目
db 1 ;; Configuration number 配置值
db 0 ;; Configuration string 配置的字符串描述符索引
db 10000000b ;; Attributes (b7 - buspwr, b6 - selfpwr, b5 - rwu) 配置的属性
db 50 ;; Power requirement (div 2 ma) 最大电流
;; Interface Descriptor 接口描述符
db DSCR_INTRFC_LEN ;; Descriptor length
db DSCR_INTRFC ;; Descriptor type 04h
db 0 ;; Zero-based index of this interface 接口号
db 0 ;; Alternate setting 替换设置号数
db 2 ;; Number of end points 除了端点0外,支持的端点数目是2
db 0ffH ;; Interface class 接口类代码,制定为厂商定义类
db 00H ;; Interface sub class 接口有子类代码
db 00H ;; Interface sub sub class 接口协议代码
db 0 ;; Interface descriptor string index 此接口的字符串描述符索引
;; Endpoint Descriptor 端点描述符
db DSCR_ENDPNT_LEN ;; Descriptor length
db DSCR_ENDPNT ;; Descriptor type
db 82H ;; Endpoint number, and direction 端点号,和方向
db ET_BULK ;; Endpoint type 端点传输类型
db 00H ;; Maximun packet size (LSB) 数据包大小低位
db 04H ;; Max packect size (MSB)
db 00H ;; Polling interval 轮巡间隔
;; Endpoint Descriptor
db DSCR_ENDPNT_LEN ;; Descriptor length
db DSCR_ENDPNT ;; Descriptor type
db 08H ;; Endpoint number, and direction
db ET_BULK ;; Endpoint type
db 00H ;; Maximun packet size (LSB)
db 02H ;; Max packect size (MSB)
db 00H ;; Polling interval
HighSpeedConfigDscrEnd:
FullSpeedConfigDscr:
db DSCR_CONFIG_LEN ;; Descriptor length
db DSCR_CONFIG ;; Descriptor type
db (FullSpeedConfigDscrEnd-FullSpeedConfigDscr) mod 256 ;; Total Length (LSB)
db (FullSpeedConfigDscrEnd-FullSpeedConfigDscr) / 256 ;; Total Length (MSB)
db 1 ;; Number of interfaces
db 1 ;; Configuration number
db 0 ;; Configuration string
db 10000000b ;; Attributes (b7 - buspwr, b6 - selfpwr, b5 - rwu)
db 50 ;; Power requirement (div 2 ma)
;; Interface Descriptor
db DSCR_INTRFC_LEN ;; Descriptor length
db DSCR_INTRFC ;; Descriptor type
db 0 ;; Zero-based index of this interface
db 0 ;; Alternate setting
db 4 ;; Number of end points
db 0ffH ;; Interface class
db 00H ;; Interface sub class
db 00H ;; Interface sub sub class
db 0 ;; Interface descriptor string index
;; Endpoint Descriptor
db DSCR_ENDPNT_LEN ;; Descriptor length
db DSCR_ENDPNT ;; Descriptor type
db 02H ;; Endpoint number, and direction
db ET_BULK ;; Endpoint type
db 40H ;; Maximun packet size (LSB)
db 00H ;; Max packect size (MSB)
db 00H ;; Polling interval
;; Endpoint Descriptor
db DSCR_ENDPNT_LEN ;; Descriptor length
db DSCR_ENDPNT ;; Descriptor type
db 04H ;; Endpoint number, and direction
db ET_BULK ;; Endpoint type
db 40H ;; Maximun packet size (LSB)
db 00H ;; Max packect size (MSB)
db 00H ;; Polling interval
;; Endpoint Descriptor
db DSCR_ENDPNT_LEN ;; Descriptor length
db DSCR_ENDPNT ;; Descriptor type
db 86H ;; Endpoint number, and direction
db ET_BULK ;; Endpoint type
db 40H ;; Maximun packet size (LSB)
db 00H ;; Max packect size (MSB)
db 00H ;; Polling interval
;; Endpoint Descriptor
db DSCR_ENDPNT_LEN ;; Descriptor length
db DSCR_ENDPNT ;; Descriptor type
db 88H ;; Endpoint number, and direction
db ET_BULK ;; Endpoint type
db 40H ;; Maximun packet size (LSB)
db 00H ;; Max packect size (MSB)
db 00H ;; Polling interval
FullSpeedConfigDscrEnd:
StringDscr: //字符串描述符
StringDscr0: //字符串0
db StringDscr0End-StringDscr0 ;; String descriptor length 描述长度
db DSCR_STRING // 描述类型
db 09H,04H //设备所支持的语言代码,表示是英语
StringDscr0End:
StringDscr1:
db StringDscr1End-StringDscr1 ;; String descriptor length 制造商的字符串描述符
db DSCR_STRING
db 'C',00
db 'y',00
db 'p',00
db 'r',00
db 'e',00
db 's',00
db 's',00
StringDscr1End:
StringDscr2:
db StringDscr2End-StringDscr2 ;; Descriptor length 产品的字符串描述符
db DSCR_STRING
db 'E',00
db 'Z',00
db '-',00
db 'U',00
db 'S',00
db 'B',00
StringDscr2End:
UserDscr: //空描述符,表述描述符表的结束
dw 0000H
end