📄 usb20.h
字号:
/********************************************************************************
*********************************************************************************
COPYRIGHT (c) 2004 BY ROCK-CHIP FUZHOU
-- ALL RIGHTS RESERVED --
File Name: USB.H
Author: XUESHAN LIN
Created: 29th SEP 2004
Modified:
Revision: 1.00
********************************************************************************
********************************************************************************/
#ifndef _USB20_H
#define _USB20_H
//1可配置参数
#if MAX_LUN>1
#define iManufactuer 1 /*厂商描述符字符串索引*/
#define iProduct 2 /*产品描述符字符串索引*/
#define iSerialNumber 3 /*设备序列号字符串索引*/
#define iConfiguration 0// 4 /*配置描述符字符串索引*/
#define iInterface 0// 5 /*接口描述符字符串索引*/
#else
#define iManufactuer 0 /*厂商描述符字符串索引*/
#define iProduct 0 /*产品描述符字符串索引*/
#define iSerialNumber 0 /*设备序列号字符串索引*/
#define iConfiguration 0// 3 /*配置描述符字符串索引*/
#define iInterface 0// 4 /*接口描述符字符串索引*/
#endif
//1结构定义
//设备描述符结构
typedef struct _USB_DEVICE_DESCRIPTOR
{
uint8 bLength;
uint8 bDescriptorType;
#ifdef __C51__
uint16 bcdUSB;
#endif
#ifdef __ZSP__
uint8 bcdUSB;
uint8 reserve1;
#endif
uint8 bDeviceClass;
uint8 bDeviceSubClass;
uint8 bDeviceProtocol;
uint8 bMaxPacketSize0;
#ifdef __C51__
uint16 idVendor;
uint16 idProduct;
uint16 bcdDevice;
#endif
#ifdef __ZSP__
uint8 idVendor;
uint8 reserve2;
uint8 idProduct;
uint8 reserve3;
uint8 bcdDevice;
uint8 reserve4;
#endif
uint8 iiManufacturer;
uint8 iiProduct;
uint8 iiSerialNumber;
uint8 bNumConfigurations;
} USB_DEVICE_DESCRIPTOR, *PUSB_DEVICE_DESCRIPTOR;
//端点描述符结构
typedef struct _USB_ENDPOINT_DESCRIPTOR
{
uint8 bLength;
uint8 bDescriptorType;
uint8 bEndpointAddress;
uint8 bmAttributes;
#ifdef __C51__
uint16 wMaxPacketSize;
#endif
#ifdef __ZSP__
uint8 wMaxPacketSize;
uint8 reserve1;
#endif
uint8 bInterval;
} USB_ENDPOINT_DESCRIPTOR, *PUSB_ENDPOINT_DESCRIPTOR;
//配置描述符结构
typedef struct _USB_CONFIGURATION_DESCRIPTOR
{
uint8 bLength;
uint8 bDescriptorType;
#ifdef __C51__
uint16 wTotalLength;
#endif
#ifdef __ZSP__
uint8 wTotalLength;
uint8 reserve1;
#endif
uint8 bNumInterfaces;
uint8 bConfigurationValue;
uint8 iiConfiguration;
uint8 bmAttributes;
uint8 MaxPower;
} USB_CONFIGURATION_DESCRIPTOR, *PUSB_CONFIGURATION_DESCRIPTOR;
//高速设备的其它速度配置描述符
typedef struct _OTHER_SPEED_CONFIG_DESCRIPTOR
{
uint8 bLength;
uint8 bDescriptorType;
#ifdef __C51__
uint16 wTotalLength;
#endif
#ifdef __ZSP__
uint8 wTotalLength;
uint8 reserve1;
#endif
uint8 bNumInterfaces;
uint8 bConfigurationValue;
uint8 iiConfiguration;
uint8 bmAttributes;
uint8 MaxPower;
}OTHER_SPEED_CONFIG_DESCRIPTOR;
//接口描述符结构
typedef struct _USB_INTERFACE_DESCRIPTOR
{
uint8 bLength;
uint8 bDescriptorType;
uint8 bInterfaceNumber;
uint8 bAlternateSetting;
uint8 bNumEndpoints;
uint8 bInterfaceClass;
uint8 bInterfaceSubClass;
uint8 bInterfaceProtocol;
uint8 iiInterface;
} USB_INTERFACE_DESCRIPTOR, *PUSB_INTERFACE_DESCRIPTOR;
//字符串描述符结构
typedef struct _USB_STRING_DESCRIPTOR
{
uint8 bLength;
uint8 bDescriptorType;
uint8 bString[1];
} USB_STRING_DESCRIPTOR, *PUSB_STRING_DESCRIPTOR;
//高速设备限制描述符
typedef struct _HS_DEVICE_QUALIFIER
{
uint8 bLength; //length of HS Device Descriptor
uint8 bQualifier; //HS Device Qualifier Type
#ifdef __C51__
uint16 wVersion; // USB 2.0 version
#endif
#ifdef __ZSP__
uint8 wVersion; // USB 2.0 version
uint8 reserve1;
#endif
uint8 bDeviceClass; //Device class
uint8 bDeviceSubClasss; //Device SubClass
uint8 bProtocol; //Device Protocol Code
uint8 MaxPktSize; //Maximum Packet SIze for other speed
uint8 bOther_Config; //Number of Other speed configurations
uint8 Reserved; //Reserved
}HS_DEVICE_QUALIFIER;
//电源描述符结构
typedef struct _USB_POWER_DESCRIPTOR
{
uint8 bLength;
uint8 bDescriptorType;
uint8 bCapabilitiesFlags;
uint16 EventNotification;
uint16 D1LatencyTime;
uint16 D2LatencyTime;
uint16 D3LatencyTime;
uint8 PowerUnit;
uint16 D0PowerConsumption;
uint16 D1PowerConsumption;
uint16 D2PowerConsumption;
} USB_POWER_DESCRIPTOR, *PUSB_POWER_DESCRIPTOR;
//通用描述符结构
typedef struct _USB_COMMON_DESCRIPTOR
{
uint8 bLength;
uint8 bDescriptorType;
} USB_COMMON_DESCRIPTOR, *PUSB_COMMON_DESCRIPTOR;
//标准HUB描述符结构
typedef struct _USB_HUB_DESCRIPTOR
{
uint8 bDescriptorLength; // Length of this descriptor
uint8 bDescriptorType; // Hub configuration type
uint8 bNumberOfPorts; // number of ports on this hub
uint16 wHubCharacteristics; // Hub Charateristics
uint8 bPowerOnToPowerGood; // port power on till power good in 2ms
uint8 bHubControlCurrent; // max current in mA
// room for 255 ports power control and removable bitmask
uint8 bRemoveAndPowerMask[64];
} USB_HUB_DESCRIPTOR, *PUSB_HUB_DESCRIPTOR;
#define FULL_SPEED 0
#define HIGH_SPEED 1
//事件组标志结构
typedef union _epp_flags
{
struct _flags
{
uint8 HS_FS_State :1;
uint8 bus_reset :1;
uint8 suspend :1;
uint8 setup_packet :1;
uint8 remote_wakeup :1;
uint8 Alter_Interface :1;
uint8 control_state :2;
uint8 configuration :1;
uint8 WdtUsbEn :1;
uint8 ep1_rxdone :1;
uint8 setup_dma :2; // V2.3
uint8 dma_state :2;
uint8 power_down :1; // Smart Board
} bits;
uint16 value;
} EPPFLAGS;
//设备请求结构
typedef struct _device_request
{
uint8 bmRequestType;
uint8 bRequest;
#ifdef __C51__
uint16 wValue;
uint16 wIndex;
uint16 wLength;
#endif
#ifdef __ZSP__
uint8 wValue;
uint8 reserved1;
uint8 wIndex;
uint8 reserved2;
uint8 wLength;
uint8 reserved3;
#endif
} DEVICE_REQUEST;
//I/O请求结构(用于DMA)
typedef struct _IO_REQUEST
{
uint16 uAddressL;
uint8 bAddressH;
uint16 uSize;
uint8 bCommand;
} IO_REQUEST, *PIO_REQUEST;
#define MAX_CONTROLDATA_SIZE 8 //控制管道最大包长
//带数据的设备请求结构
typedef struct _control_xfer
{
DEVICE_REQUEST DeviceRequest;
#ifdef __C51__
uint16 wLength;
uint16 wCount;
#endif
#ifdef __ZSP__
uint8 wLength;
uint8 reserved1;
uint8 wCount;
uint8 reserved2;
#endif
uint8 *pData;
uint8 dataBuffer[MAX_CONTROLDATA_SIZE];
} CONTROL_XFER;
typedef struct _TWAIN_FILEINFO
{
uint8 bPage; // bPage bit 7 - 5 map to uSize bit 18 - 16
uint8 uSizeH; // uSize bit 15 - 8
uint8 uSizeL; // uSize bit 7 - 0
} TWAIN_FILEINFO, *PTWAIN_FILEINFO;
//1常量定义
#define MSB(x) (((x) >> 8) & 0xFF)
#define LSB(x) ((x) & 0xFF)
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE (!FALSE)
#endif
#define NUM_ENDPOINTS 2 //端点数除0外
#define CONFIG_DESCRIPTOR_LENGTH sizeof(USB_CONFIGURATION_DESCRIPTOR) \
+ sizeof(USB_INTERFACE_DESCRIPTOR) \
+ (NUM_ENDPOINTS * sizeof(USB_ENDPOINT_DESCRIPTOR))
//Rock2
#define USB_ADDR (USB_BASE+0x00/2)
#define USB_INT_SRC_IN (USB_BASE+0x02/2)
#define USB_INT_SRC_OUT (USB_BASE+0x04/2)
#define USB_INT_EN_IN (USB_BASE+0x06/2)
#define USB_INT_EN_OUT (USB_BASE+0x08/2)
#define USB_INT_SRC_USB (USB_BASE+0x0a/2)
#define USB_FRAME (USB_BASE+0x0c/2)
#define USB_INDEX (USB_BASE+0x0e/2)
#define USB_MAX_PACK_IN (USB_BASE+0x10/2)
#define USB_CSR0 (USB_BASE+0x12/2)
#define USB_CSR_IN (USB_BASE+0x12/2)
#define USB_MAX_PACK_OUT (USB_BASE+0x14/2)
#define USB_CSR_OUT (USB_BASE+0x16/2)
#define USB_COUNT0 (USB_BASE+0x18/2)
#define USB_COUNT_OUT (USB_BASE+0x18/2)
//0x1A~0x1F RESERVE
#define USB_FIFO_BASE (USB_BASE+0x20/2)
//USB_INT_EN_IN
#define USB_INT_ENDP0 0x0001
#define USB_INT_ENDP1IN 0x0002
#define USB_INT_ENDP1OUT 0x0002
#define USB_INT_SUSPEND 0x0001
#define USB_INT_RESUME 0x0002
#define USB_INT_RESET 0x0004
#define USB_INT_SOF 0x0008
//USB_POWER
#define USB_SOFTCONNECT (0x0040 << 8)
#define USB_HS_ENABLE (0x0020 << 8)
#define USB_INT_HS_STAT (0x0010 << 8)
#define USB_RESUME (0x0004 << 8)
#define USB_SUSPEND_EN (0x0001 << 8)
//csr0
#define CSR0_OUT_RDY 0x0001
#define CSR0_IN_RDY 0x0002
#define CSR0_SENT_STALL 0x0004
#define CSR0_DATA_END 0x0008
#define CSR0_SETUP_END 0x0010
#define CSR0_SEND_STALL 0x0020
#define CSR0_OUT_SEVD 0x0040
#define CSR0_SETUP_SEVD 0x0080
//INCSR
#define CSR_IN_ISO 0x4000
#define CSR_IN_MODE 0x2000
#define CSR_IN_FDT 0x0800
#define CSR_IN_CDT 0x0040
#define CSR_IN_SENT_STALL 0x0020
#define CSR_IN_SEND_STALL 0x0010
#define CSR_IN_FLUSH_FIFO 0x0008
#define CSR_IN_FIFO_NotEmpty 0x0002
#define CSR_IN_PKT_RDY 0x0001
//OUTCSR
#define CSR_OUT_ISO 0x4000
#define CSR_OUT_DisNyet 0x1000
#define CSR_OUT_CDT 0x0080
#define CSR_OUT_SENT_STALL 0x0040
#define CSR_OUT_SEND_STALL 0x0020
#define CSR_OUT_FLUSH_FIFO 0x0010
#define CSR_OUT_PKT_RDY 0x0001
//IntUSB
#define INT_USB_SOF 0x0008
#define INT_USB_RESET 0x0004
#define INT_USB_RESUME 0x0002
#define INT_USB_SUSPEND 0x0001
//TestMode
#define TEST_FS (0x20 << 8)
#define TEST_HS (0x10 << 8)
#define TEST_PACKET (0x08 << 8)
#define TEST_K (0x04 << 8)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -