⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xsusbhostapi.h

📁 优龙YLP270开发板 光盘自带的BIOS和实验例程源码 强烈推荐
💻 H
📖 第 1 页 / 共 3 页
字号:
  unsigned char bDeviceSubClass;
  unsigned char bDeviceProtocol;
  unsigned char bMaxPacketSize0;
  unsigned short idVendor;
  unsigned short idProduct;
  unsigned short bcdDevice;
  unsigned char iManfacturer;
  unsigned char iProduct;
  unsigned char iSerialNumber;
  unsigned char bNumConfigurations;
} USB_DeviceDescriptor_T;

typedef __packed struct USB_ConfigurationDescriptor_S {
  unsigned char bLength;
  unsigned char bDescriptorType;
  unsigned short wTotalLength;
  unsigned char bNumInterfaces;
  unsigned char bConfigurationValue;
  unsigned char iConfiguration;
  __packed union {
    __packed struct {
      unsigned Reserved : 5;
      unsigned RemoteWakeup : 1;
      unsigned SelfPowered : 1;
      unsigned One : 1;
    } s;
    unsigned char d;
  } bmBitmap;
  unsigned char bMaxPower;		/* in 2mA units */
}USB_ConfigurationDescriptor_T;

typedef __packed struct USB_InterfaceDescriptor_S {
  unsigned char bLength;
  unsigned char bDescriptorType;
  unsigned char bInterfaceNumber;
  unsigned char bAlternateSetting;
  unsigned char bNumEndpoints;
  unsigned char bInterfaceClass;
  unsigned char bInterfaceSubClass;
  unsigned char bInterfaceProtocol;
  unsigned char iInterface;
} USB_InterfaceDescriptor_T;

typedef enum USB_TransferType_E {
  UsbControl = 0,
  UsbIsochronous = 1,
  UsbBulk = 2,
  UsbInterrupt = 3
} USB_TransferType_T;

typedef __packed struct USB_EndpointDescriptorX_S {
  unsigned char bLength;
  unsigned char bDescriptorType;
  __packed union {
    __packed struct {
      unsigned EndpointNumber : 4;
      unsigned Reserved : 3;
      unsigned Direction : 1;
    } s;
    unsigned char d;
  } bEndpointAddress;
  __packed union {
    __packed struct {
      unsigned TransferType : 2;
      unsigned Reserved : 6;
    } s;
    unsigned char d;
  } bmAttributes;
  unsigned short wMaxPacketSize;
  unsigned char bInterval;
} USB_EndpointDescriptorX_T;

typedef __packed struct USB_GenericDescriptor_S {
  unsigned char bLength;
  unsigned char bDescriptorType;
} USB_GenericDescriptor_T;

// Feature selectors
typedef enum USB_FeatureSelectorType_E {
  UsbFeatureEndpointHalt = 0,
  UsbFeatureDeviceRemoteWakeup = 1
} USB_FeatureSelectorType_T;

// Driver specific structures
typedef enum USBD_DeviceState_E {
  UsbdStateFree = 0,
  UsbdStateUsed = 1,
  UsbdStateConnected = 2,
  UsbdStateEnumerated = 3,
  UsbdStateConfigured = 4,
  UsbdStateAllocated = 5
} USBD_DeviceState_T;

#define USBD_MAX_DEV_ED 16
#define USBD_BUFSIZ 256

typedef struct USBD_Device_S {
  USB_EndpointDescriptor_T * Endpoints[USBD_MAX_DEV_ED];
  unsigned char EndpointCount;
  unsigned char State;
  unsigned char DeviceAddress;
  unsigned char PortId;
  unsigned char ConfigSelect;
  unsigned char InterfaceSelect;
  unsigned char AlternateSetting;
  unsigned char BusSpeed;
  unsigned short VendorId;
  unsigned short DeviceId;
  char DeviceDesc[32];			/* Define larger for alignment */
  char ConfigBuffer[USBD_BUFSIZ];	/* All configurations */
} USBD_Device_T;

typedef void (*USBD_StatusCallback_T)(int state,
				      USBD_Device_T * devP);

typedef struct USBD_DeviceInfo_S {
  unsigned short VendorId;
  unsigned short DeviceId;
  USBD_StatusCallback_T Callback;
} USBD_DeviceInfo_T;

// Allocation sizes
#define USBD_MAX_ED 16 /* Max endpoints */
#define USBD_STATIC_ED 64 /* Static endpoints for periodic lists */
#define USBD_MAX_TD (USBD_MAX_ED + /* Max transfers (one marker per ED) */ \
		   (USBD_MAX_BUF * USBD_BUFSIZ / 8))
#define USBD_MAX_ITD 64
#define USBD_MAX_BUF 16
#define USBD_MAX_DEV 4

#define USBD_MAX_DEV_INFO 16

// Flag indicating whether viariable length data is OK
#define USBD_VarNotOK 0
#define USBD_VarOK 1

// Since we need to insure 256 byte alignment multiply the area size by two
#define USBD_INFO_SIZE 2 * sizeof(USB_HostControllerCommunicationArea_T) + \
		     USBD_STATIC_ED * sizeof(USB_EndpointDescriptor_T) + \
		     USBD_MAX_ED * sizeof(USB_EndpointDescriptor_T) + \
		     USBD_MAX_TD * sizeof(USB_TransferDescriptor_T) + \
		     USBD_MAX_ITD * sizeof(USB_IsoTransferDescriptor_T) + \
		     USBD_MAX_BUF * USBD_BUFSIZ

// Base index in the periodic list table for each polling rate
#define USBD_32MS_BASE ((1 << 5) - 1)
#define USBD_16MS_BASE ((1 << 4) - 1)
#define USBD_8MS_BASE  ((1 << 3) - 1)
#define USBD_4MS_BASE  ((1 << 2) - 1)
#define USBD_2MS_BASE  ((1 << 1) - 1)
#define USBD_1MS_BASE  ((1 << 0) - 1)

// Structure definition
typedef struct USBD_DescriptorDefinition_S {
  char * name;
  int offset;
  int size;
} USBD_DescriptorDefinition_T;

// Driver error codes
#define ERR_S_XSUSB_HWSETUP        	0x01 // XsUsbHostHWSetup
#define ERR_S_XSUSB_SHUT            0x02 // XsUsbHostHWShutdown 

#define ERR_S_XSUSB_INITHOST        0x03 // XsUsbHostInitialize
#define ERR_S_XSUSB_ADDDEVICE       0x04 // XsUsbHostAddDevice
#define ERR_S_XSUSB_ADDENDPOINT     0x05 // XsUsbHostAddEndpoint
#define ERR_S_XSUSB_GETDESCRIPTOR   0x06 // XsUsbHostGetDescriptor
#define ERR_S_XSUSB_DOCOMMAND       0x07 // XsUsbHostDoCommand
#define ERR_S_XSUSB_SELINTERFACE    0x08 // XsUsbHostSelectInterface
#define ERR_S_XSUSB_STARTBULK       0x09 // XsUsbHostStartBulkTransfer
#define ERR_S_XSUSB_STARTINT        0x0A // XsUsbHostStartIntTransfer
#define ERR_S_XSUSB_STARTISO        0x0B // XsUsbHostStartIsoTransfer

#define ERR_S_XSUSB_ENUMERATEDEV    0x0C // addDevice
#define ERR_S_XSUSB_GETCONFIG       0x0D // getConfiguration
#define ERR_S_XSUSB_SENDMESSAGE     0x0E // sendMessage
#define ERR_S_XSUSB_CLEARTD         0x0F // clearTD
#define ERR_S_XSUSB_SETADDRESS      0x10 // setAddress
#define ERR_S_XSUSB_SETCONFIG       0x11 // setConfiguration
#define ERR_S_XSUSB_GETDEVDESCR     0x12 // getDeviceDescriptor

#define ERR_S_XSUSB_NODESCRIPTOR    0x13 // Failure to register device
#define ERR_S_XSUSB_BADDEVICE       0x14 // No free device 
#define ERR_S_XSUSB_DISCONNECTED    0x15 // Access a disconnected port

// Tests Error codes
#define ERR_S_XSUSB_ENUMERATE       0x80 // USB Client Enumerate failed
#define ERR_S_XSUSB_LOOPBACK        0x81 // USB Host and USB Client data loopback failed

typedef enum USBD_ErrorCodes_E {
  UsbdNoError = ERR_T_NONE, /* No error */
  UsbdNoTransfer = -1,    /* No free transfer descriptors */
  UsbdBadTransfer = -2,   /* No free transfer descriptors */
  UsbdNoBuffer = -3,      /* No free buffers */
  UsbdBadBuffer = -4,     /* No free buffers */
  UsbdNoEndpoint = -5,    /* No free endpoints */
  UsbdBadEndpoint = -6,   /* No free endpoints */
  UsbdNoDevice = -7,      /* No free device structure */
  UsbdBadDevice = -8,     /* No free device structure */

  UsbdTimeout = -9,       /* Wait timeout */
  UsbdHalted = -10,       /* Endpoint halted */
  UsbdBadMaxPacket = -11, /* Bad max packet size returned */
  UsbdDisconnected = -12, /* Access a disconnected port */

  UsbdBadVersion = -14,   /* Unsupported host controller version */
  UsbdNoSuspend = -15,    /* Controller did not transition to suspend */
  UsbdBadConfig = -16,    /* Configuration not found */
  UsbdBadInterface = -17, /* Interface/alternate not found */
  UsbdBadIsoBuffer = -18, /* Invalid Iso buffer (size check) */
  UsbdBufferOverflow = -19,/* Internal buffer too small */
  UsbdFailure = -20,      /* General failure */
  UsbdMissingData = -21   /* Reply data is missing */
} USBD_ErrorCodes_T;

// Define loopback function
typedef UINT (*UsbClientLoopbackT) (void * ctxP, UINT mode);

/*
************************************************************************************
*                            FUNCTION PROTOTYPES 
************************************************************************************
*/

/* Start an isochronous transfer. The transfer is queued and the final status
 * is return via the callback.
 */
UINT XsUsbHostStartIsoTransfer(USB_EndpointDescriptor_T * edP,
			                char * bufP,
			                int length,
			                USBD_CompletionCallback_T completion,
			                USBD_CallbackParam_T param);

/* Start an interrupt transfer. The transfer is queued and the final status
 * is return via the callback.
 */
UINT XsUsbHostStartIntTransfer(USB_EndpointDescriptor_T * edP,
			                char * bufP,
			                int length,
			                USBD_CompletionCallback_T completion,
			                USBD_CallbackParam_T param);

/* Start a bulk transfer. The transfer is queued and the final status
 * is return via the callback.
 */
UINT XsUsbHostStartBulkTransfer(USB_EndpointDescriptor_T * edP,
			                    char * bufP,
			                    int length,
			                    int varOK,
			                    int errCount,
			                    USB_DirectionTD_T dir,
			                    USBD_CompletionCallback_T completion,
			                    USBD_CallbackParam_T param);

/* Select a device interface from the device configuration list. The interface
 * is made active at the device via SetInterface.
 */
UINT XsUsbHostSelectInterface(USBD_Device_T * devP,
			                int configNum,
			                int interfaceNum,
			                int altNum);

/* Check the USB host status. This is the main polling loop and must be called
 * regularly to keep the host controller moving. This will eventually be
 * replaced by an interrupt driven mechanism.
 */
void XsUsbHostCheckStatus(void);

/* Initialize the host controller and call XsUsbHostCheckStatus. The latter will
 * likely be removed as the caller needs to periodically poll anyway.
 */
UINT XsUsbHostInitialize (void * hostRegs, 
                          UsbClientLoopbackT func, 
                          UINT loopbackEnabled, 
                          PUINT udcTestStatus);

/* Register a callback for status change of a specific device. This is the
 * mechanism to attach device drivers to USB devices. The driver (or an agent)
 * registers the vendorID and deviceID and when that device is located the
 * speficied function is called with the device status.
 */
void XsUsbHostRegisterCallback(int vendorId,
			                int deviceId,
			                USBD_StatusCallback_T func);

/* Execute a control command. The command will not return until it completes
 * (either success or failure). This is unlike the USB_StartXxxTransfer
 * functions which are asynchronous.
 */
UINT XsUsbHostDoCommand(USB_EndpointDescriptor_T * edP,
		                int bmRequest,
		                int bRequest,
		                int wValue,
		                int wIndex,
		                int wLength,
		                void * bufP);

/* Display the internal structures. Debug only.
 */
void XsUsbHostDisplayStructures(void * arg, char * param);

/* Display the contents of a data/command buffer.
 */
void XsUsbHostDisplayBuffer(char * banner, char * p, int length);

/* Get a descriptor from the specified device.
 */
UINT XsUsbHostGetDescriptor(USBD_Device_T * devP,
		                    int recipient,
		                    int reqType,
		                    int descType,
		                    int index,
		                    void *bufP,
		                    int len);

/* Clear an endpoint after a failure.
 */
void XsUsbHostClearEndpoint(USB_EndpointDescriptor_T * ctrlEdP,
		                    USB_EndpointDescriptor_T * edP);

/* Manually add an endpoint to the device. Normally this is done automatically
 * by selecting the interface but for testing purposes it may be required to
 * add endpoints explicitly.
 */
void XsUsbHostAddEndpoint(USBD_Device_T * devP,
		                int endpointIndex,
		                int type,
		                int functionAddr,
		                int endpointNumber,
		                int dir,
		                int speed,
		                int format,
		                int maxPacketSize);

/* Manually add a device
 */
USBD_Device_T * XsUsbHostAddDevice(int portId, int speed);

#endif /* _XsUsbHostAPI_h */


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -