📄 sl811.h
字号:
/*******************************************************************************
** 文件创建人 :LTY
** 文件创建日期: 2006年11月19日
** 文件功能描述: CYPRESS的SL811HS USB主控制器芯片底层驱动函数
********************************************************************************/
#ifndef _SL811_
#define _SL811_
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE 1
#endif
#define SL811_ADDR (*((volatile U8 *)(0x0a000000)))
#define SL811_DATA (*((volatile U8 *)(0x0a000001)))
#define MAX_EP 0x06 // 定义最大端点数
#define TIMEOUT_RETRY 0x06 // USB传输超时次数
typedef struct
{
U8 ucDevInsert; //请求类型
U8 ucMasDev; //特定请求
} STDEVSIGN;
// SETUP包
typedef struct
{
U8 ucRequestType; //请求类型
U8 ucRequest; //特定请求
U16 usValue;
U16 usIndex;
U16 usLength;
} STSETUP, *PSTSETUP;
//发送接收数据结构
typedef struct
{
unsigned char ucUsbAddr; //终端地址
unsigned char ucEndPoint; //端点号
unsigned char ucPid; //标示码
unsigned char ucMaxPackLen; //每包数据最大长度(与端点接收最长数据有关)
unsigned char *pucDataBuf; //发送接收数据指针
unsigned short usRXLen; //发送接收数据长度
unsigned char ucDataTog; //每端点数据DATA0和DATA1 轮循位
//unsigned char ucResered;
STSETUP stSetup; //设置包
} STRTPACK, *PSTRTPACK;
//保存设备的信息
typedef struct
{
U8 ucNunEps; // 端点数
U8 ucClass; // 设备类型 ==8 MassDevice
U8 ucEPBulkIn; // mass 输入端点地址
U8 ucEPBulkOut; // mass 输出端点地址
U8 ucInMaxLen;
U8 ucOutMaxLen;
U8 ucInDataTog;
U8 ucOutDataTog;
U8 ucMaxLen0;
} STUSBDEV, *PSTUSBDEV;
//设备描述符
typedef struct
{ U8 bLength;
U8 bDescriptorType;
U16 bcdUSB;
U8 bDeviceClass;
U8 bDeviceSubClass;
U8 bDeviceProtocol;
U8 bMaxPacketSize0;
U16 idVendor;
U16 idProduct;
U16 bcdDevice;
U8 iManufacturer;
U8 iProduct;
U8 iSerialNumber;
U8 bNumConfigurations;
} STDEVDESC, *PSTDEVDESC;
//配置描述符
typedef struct
{
U8 bLength; // Size of descriptor in U8
U8 bType; // Configuration
U16 wLength; // Total length
U8 bNumIntf; // Number of interface
U8 bCV; // bConfigurationValue
U8 bIndex; // iConfiguration
U8 bAttr; // Configuration Characteristic
U8 bMaxPower; // Power config
} STCFGDESC, *PSTCFGDESC;
// 接口描述符
typedef struct
{ U8 bLength;
U8 bType;
U8 iNum;
U8 iAltString;
U8 bEndPoints;
U8 iClass;
U8 iSub;
U8 iProto;
U8 iIndex;
} STINTFDESC, *PSTINTFDESC;
//端点描述符
typedef struct
{ U8 bLength;
U8 bType;
U8 bEPAdd;
U8 bAttr;
U16 wPayLoad; // low-speed this must be 0x08
U8 bInterval;
} STEPDESC, *PSTEPDESC;
// 字符串描述符
typedef struct
{ U8 bLength;
U8 bType;
U16 wLang;
} STSTRDESC, *PSTSTRDESC;
//数据DATA指针
#define EP0_BUF 0x10
#define EP1_BUF 0x40
// 控制寄存器地址定义
#define REP0CTRL 0x00 //RW
#define REP0DATAADDR 0x01 //RW
#define REP0DATALEN 0x02 //RW
#define REP0STATUS 0x03 //R
#define REP0PIDEP 0x03 //W
#define REP0DEVADDR 0x04 //W
#define REP0REMAINCNT 0x04 //R
#define REP1CTRL 0x00 //RW
#define REP1DATAADDR 0x01 //RW
#define REP1DATALEN 0x02 //RW
#define REP1STATUS 0x03 //R
#define REP1PIDEP 0x03 //W
#define REP1DEVADDR 0x04 //W
#define REP1REMAINCNT 0x04 //R
#define RSLCTRL 0x05 //RW
#define RSLIRQENABLE 0x06 //RW
#define RSLIRQSTATUS 0x0d //RW
#define RSLREVSION 0x0e //R
#define RSLSOFLOW 0x0e //W
#define RSLSOFANDMS 0x0f //RW
//中断控制状态位定义
#define USB_A_DONE 0x01
#define USB_B_DONE 0x02
#define SOF_TIMER 0x10
#define INSERT_REMOVE 0x20
#define USB_DETECT 0x40
#define USB_DPBUS 0x80
#define INT_CLEAR 0xFF
//EP0 状态寄存器位定义
#define EP0_ACK 0x01
#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
//REP0CTRL和REP1CTRL控制寄存器命令定义
#define SLDATA_WR 0x27 // 0010 0111 ( Data0 + SOF + OUT + Enable + Arm)
#define SLDATA_RD 0x23 // 0010 0011 ( Data0 + SOF + IN + Enable + Arm)
//数据包标示
#define PID_SETUP 0xD0
#define PID_IN 0x90
#define PID_OUT 0x10
//9种请求类型
#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 0x01
#define CONFIGURATION 0x02
#define STRING 0x03
#define INTERFACE 0x04
#define ENDPOINT 0x05
void SL811_Init(void);
void USB_Check(void);
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -