📄 host_811.h
字号:
////////////////////////////////////////////////////////////////////////////////
// File: host_811.h
//
// Copyright (c) 2002 Cypress Semiconductor. May not be reproduced without permission.
// See the license agreement for more details.
////////////////////////////////////////////////////////////////////////////////
typedef unsigned char BYTE;
typedef unsigned short int WORD;
typedef unsigned long LWORD;
//~~arm中无布尔类型,所以利用byte型变量代替它typedef bit BOOL;
#define NULL 0
#define TRUE 1
#define FALSE 0
#define ISO_BIT 0x10 // 00h/08h中iso位,“1”标识同步传输
#define MAX_DEV 0x2 //maximum number of devices (Address #0 + Slave + 4 Hub's device)//~5个还是2个?
#define MAX_EP 0x05 // maximum number of endpoints (Ep0 + max of 4 data endpoints)
//*****************************************************************************************
// Constant Defines
//*****************************************************************************************
#define TIMEOUT_RETRY 0x06 // Maximum no. of timeout retry during USB xfer
#pragma pack(push)
#pragma pack(1)
typedef struct
{
WORD wVID, wPID; // Vendor ID and Product ID
BYTE bClass; // 大容量存储类,0x08
BYTE bNumOfEPs; // actual number endpoint from slave
BYTE iMfg; // Manufacturer ID
BYTE iPdt; // Product ID
BYTE bId1;
BYTE bId2;
BYTE bEPAddr[MAX_EP]; // bit 7 = 1 = use PID_IN,端点号
BYTE bAttr[MAX_EP]; // ISO | Bulk | Interrupt | Control端点的传输特性,这里是bulk
WORD wPayLoad[MAX_EP]; // ISO range: 1-1023, Bulk: 1-64, etc//~~最大载荷
WORD bInterval[MAX_EP]; // polling interval (for LS)//~~主机查询断点的时间间隔,批量传输忽略此值
BYTE bData1[MAX_EP]; // DataToggle value
} pUSBDEV;
// USB specific request//usb设备请求命令结构
typedef struct
{
BYTE bmRequest;
BYTE bRequest;
WORD wValue;
WORD wIndex;
WORD wLength;
} SetupPKG, *pSetupPKG;
// Standard Device Descriptor设备描述符
typedef struct
{ BYTE bLength;
BYTE bDescriptorType;
WORD bcdUSB;
BYTE bDeviceClass;
BYTE bDeviceSubClass;
BYTE bDeviceProtocol;
BYTE bMaxPacketSize0;
WORD idVendor;
WORD idProduct;
WORD bcdDevice;
BYTE iManufacturer;
BYTE iProduct;
BYTE iSerialNumber;
BYTE bNumConfigurations;
} sDevDesc, *pDevDesc;
// Standard Configuration Descriptor 配置描述符
typedef struct
{
BYTE bLength; // Size of descriptor in Byte
BYTE bType; // Configuration
WORD wLength; // Total length
BYTE bNumIntf; // Number of interface
BYTE bCV; // bConfigurationValue
BYTE bIndex; // iConfiguration
BYTE bAttr; // Configuration Characteristic
BYTE bMaxPower; // Power config
} sCfgDesc, *pCfgDesc;
// Standard Interface Descriptor 接口描述符
typedef struct
{ BYTE bLength;
BYTE bType;
BYTE iNum;
BYTE iAltString;
BYTE bEndPoints;
BYTE iClass;
BYTE iSub;
BYTE iProto;
BYTE iIndex;
} sIntfDesc, *pIntfDesc;
// Standard EndPoint Descriptor 端点描述符
typedef struct
{ BYTE bLength;
BYTE bType;
BYTE bEPAdd;
BYTE bAttr;
WORD wPayLoad; // low-speed this must be 0x08
BYTE bInterval;
} sEPDesc, *pEPDesc;
// Standard String Descriptor 字符串描述符
typedef struct
{ BYTE bLength;
BYTE bType;
WORD wLang;
} sStrDesc, *pStrDesc;
typedef struct
{ BYTE name[8];
LWORD startadd;
LWORD length;
} ShapeFile, *pShapeFile;
#pragma pack(pop)
//------------------------------------------------------------------------
// EP0 use for configuration and Vendor Specific command interface
//------------------------------------------------------------------------
#define EP0_Buf 0x10 // define start of EP0 64-byte buffer//为什么是64byte?
#define EP1_Buf 0x40 // define start of EP1 64-byte buffer
/*-------------------------------------------------------------------------
* SL811H Register Control memory map
* --Note:
* --SL11H only has one control register set from 0x00-0x04
* --SL811H has two control register set from 0x00-0x04 and 0x08-0x0c
*------------------------------------------------------------------------*/
#define EP0Control 0x00
#define EP0Address 0x01
#define EP0XferLen 0x02
#define EP0Status 0x03
#define EP0Counter 0x04
#define EP1Control 0x08
#define EP1Address 0x09
#define EP1XferLen 0x0a
#define EP1Status 0x0b
#define EP1Counter 0x0c
#define CtrlReg 0x05
#define IntEna 0x06
// 0x07 is reserved
#define IntStatus 0x0d
#define cDATASet 0x0e
#define cSOFcnt 0x0f // when write:Master=1 Slave=0, D+/D-Pol Swap=1 0=not [0-5] SOF high Count
//Interrupt Status Mask/06H
#define USB_A_DONE 0x01
#define USB_B_DONE 0x02
#define BABBLE_DETECT 0x04
#define INT_RESERVE 0x08
#define SOF_TIMER 0x10
#define INSERT_REMOVE 0x20
#define USB_RESET 0x40
#define USB_DPLUS 0x80
#define INT_CLEAR 0xFF
//EP0 Status Mask
#define EP0_ACK 0x01 // EPxStatus bits mask during a read//03H/0BH
#define EP0_ERROR 0x02
#define EP0_TIMEOUT 0x04
#define EP0_SEQUENCE 0x08
#define EP0_SETUP 0x10
#define EP0_OVERFLOW 0x20
#define EP0_NAK 0x40
#define EP0_STALL 0x80
/*-------------------------------------------------------------------------
* Standard Chapter 9 definition
*-------------------------------------------------------------------------
*/
/*-------------------------------------------------------------------------
* Standard Chapter 9 definition
*-------------------------------------------------------------------------
*/
#define GET_STATUS 0x00
#define CLEAR_FEATURE 0x01
#define SET_FEATURE 0x03
#define SET_ADDRESS 0x05
#define GET_DESCRIPTOR 0x06
#define SET_DESCRIPTOR 0x07
#define GET_CONFIG 0x08
#define SET_CONFIG 0x09
#define GET_INTERFACE 0x0a
#define SET_INTERFACE 0x0b
#define SYNCH_FRAME 0x0c
#define DEVICE 0x0100
#define CONFIGURATION 0x0200
#define STRING 0x0300
#define INTERFACE 0x0400
#define ENDPOINT 0x0500
#define STDCLASS 0x00 //
#define HIDCLASS 0x03 //接口描述符bInterfaceClass字段的值
#define HUBCLASS 0x09 // bDeviceClass, bInterfaceClass
/*-------------------------------------------------------------------------
* SL11H/SL811H definition//~~usb-a/usb-b host control registers 00h/08h
*-------------------------------------------------------------------------
*/
// USB-A, USB-B Host Control Register [00H, 08H]
// Pre Reserved
// DatT Dir [1=Trans, 0=Recv]
// SOF Enable
// ISO Arm 7 6 5 2 1 0
#define DATA0_WR 0x07 // 0000 0111 ( Data0 + OUT + Enable + Arm)
#define sDATA0_WR 0x27 // 0010 0111 ( Data0 + SOF + OUT + Enable + Arm)27
#define pDATA0_WR 0x87 // 1000 0111 (Pre + Data0 + OUT + Enable + Arm)
#define psDATA0_WR 0xA7 // 1010 0111 (Pre + Data0 + SOF + OUT + Enable + Arm)
#define DATA0_RD 0x03 // 0000 0011 ( Data0 + IN + Enable + Arm)
#define sDATA0_RD 0x23 // 0010 0011 ( Data0 + SOF + IN + Enable + Arm)23
#define pDATA0_RD 0x83 // 1000 0011 (Pre + Data0 + IN + Enable + Arm)
#define psDATA0_RD 0xA3 // 1010 0011 (Pre + Data0 + SOF + IN + Enable + Arm)
#define PID_SETUP 0xD0 //~~包标识域,03h/0bh的高4位
#define PID_IN 0x90
#define PID_OUT 0x10
/*-------------------------------------------------------------------------
* Function Protocol
*-------------------------------------------------------------------------
*/
// 1) usbXfer() : handles usd data transfer, SETUP,IN, OUT
// 2) ep0Xfer() : handles endpoint zero control pipe
// 3) DataRW() : handles data endpoint transfer pipe
// 4) EnumUsbDev() : device enum(HID/HUB), excl. multi-interface
// 6) speed_detect(): SL811H slave device attach/speed detect
// 7) slave_detect(): Main loop control between SL811H & EZUSB & GUI
void sl811h_init(void); //SL811 初始化
int slave_detect(void); // slave_detect(): Main loop control between SL811H & EZUSB & GUI
int speed_detect(void); // speed_detect(): SL811H slave device attach/speed detect
BYTE SL811Read(BYTE a);//基础函数
void SL811Write(BYTE a, BYTE d);
void SL811BufRead(BYTE addr, BYTE *s, BYTE c);
void SL811BufWrite(BYTE addr, BYTE *s, BYTE c);
void USBReset();
int usbXfer(BYTE usbaddr, BYTE endpoint, BYTE pid, BYTE iso, WORD wPayload, WORD wLen, BYTE *buffer);
int ep0Xfer(BYTE usbaddr, WORD payload, pSetupPKG setup, BYTE *pData);
int VendorCmd(BYTE usbaddr,BYTE bReq, BYTE bCmd, WORD wValue, WORD wIndex,WORD wLen,BYTE* pData);
int GetDesc(BYTE usbaddr, WORD wValue, WORD wIndex, WORD wLen, BYTE *desc);//功能函数
int GetStatus(BYTE usbaddr, BYTE *desc);
int SetAddress(WORD addr);
int Set_Configuration(BYTE usbaddr,WORD wVal);
int EnumUsbDev(BYTE DevAddr); //device enum(HID/HUB), excl. multi-interface
//WORD WordSwap(WORD input);
//int GetPortStatus(BYTE usbaddr, BYTE cPort, BYTE *desc);
//int Slave_Detach(void);
/*-------------------------------------------------------------------------
* Structure for Mass Storage( CBW and CSW )//并没有CSW的定义啊
*------------------------------------------------------------------------*/
// CBW
#pragma pack(push)
#pragma pack(1)
typedef struct
{
LWORD dCBWSignature;
LWORD dCBWTag;
BYTE dCBWDataTransferLength[4];
BYTE bmCBWFlags;
BYTE bCBWLUN;
BYTE bCBWCBLength;
BYTE CBWCB[16];
} CBW,*pCBW;
#pragma pack(pop)
//~~ufi子类命令
BYTE Get_LUN(void);
BYTE Reset_U(void);
BYTE UFLInquiry(void);
BYTE UFLRequestSense(void);//主机请求判别参数
BYTE UFLReadCapacity(void);
BYTE UFLReadSector(LWORD LBA);
BYTE UFLWriteSector(LWORD LBA);
//~~WORD CheckFreeCapacity(WORD TotalWriteSize,WORD *FreeList,WORD ErrorCapacity);//查询U盘空闲容量,得到空闲簇的地址列表
void USB_Delay(WORD time);//time 单位为 ms
//~~WORD CheckFileName();
extern int Program(int addr_base, char* pData, int data_size);
extern int erase_flash(int base_addr);
extern BYTE SLAVE_ENUMERATED; //原来的xdata被删掉,以下同,到文件末尾
extern BYTE ErrorCode;
extern BYTE EPOut,EPIn,MaxLUN;
extern WORD OutPayLoad,InPayLoad;
extern LWORD USBCapacity;
extern BYTE MassStorageDataBuf[0x200];
extern WORD DBRAddr,FATAddr,RootDirAddr,FileDataAddr;
extern WORD RootDirNum,SectorSize,FATLength;//FreeCapacity,
extern BYTE ClusterSize,RootDirSize;
extern pUSBDEV uDev[MAX_DEV]; // Multiple USB devices attributes, Max 5 devices
extern WORD TotalWriteSize,ErrorCapacity;
extern LWORD ValidCapacity;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -