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

📄 usbh_hcds_vhub.c

📁 epson usb2.0 控制芯片 S1R72V05 固件程序。
💻 C
📖 第 1 页 / 共 5 页
字号:
/*
 *	description	: USBH HCD Virtual Root Hub(static)
 *	Maker		: Hiromichi Kondo
 *	Copyright	: (C)2005,SEIKO EPSON Corp. All Rights Reserved.
 */



#include <string.h>				/* memset */
#include <SPRDEF.h>
#include <SPRSTS.h>
#include <usbh_hcd.h>
#include <usbh_hcds_common.h>
#include <usbh_hcds_vhub.h>
#include <usbh_hcds_port.h>
#include <usbh_hcds_72V05.h>



/*****************************************
 * Define definition
 *****************************************/
/* Virtual route hub setting*/
#define INT_EP_ADDRESS					(0x81)		/* Endpoint address of Interrupt IN Endpoint */
#define NUM_STRING_DESC					(3)			/* Number of String Descriptor is up to 3 */

/* USB State */
#define DEFAULT_STATE					(0x00)
#define ADDRESSED_STATE					(0x01)
#define CONFIGURED_STATE				(0x02)

/* bmRequest bit Mask */
#define BMREQ_DIR_MASK					(0x80)
#define BMREQ_TYPE_MASK					(0x60)
#define BMREQ_RECIPIENT_MASK			(0x1F)

/* Data transfer direction */
#define DIR_HOST_TO_DEVICE				(0x00)
#define DIR_DEVICE_TO_HOST				(0x80)

/* Recipient */
#define RECIPIENT_DEVICE				(0x00)
#define RECIPIENT_INTERFACE				(0x01)
#define RECIPIENT_ENDPOINT				(0x02)
#define RECIPIENT_OTHER					(0x03)

/* Type */
#define TYPE_STANDARD					(0x00)
#define TYPE_CLASS						(0x20)

/* Standard Request Codes */
#define SREQ_GET_STATUS					(0x00)
#define SREQ_CLEAR_FEATURE				(0x01)
#define SREQ_SET_FEATURE				(0x03)
#define	SREQ_SET_ADDRESS				(0x05)
#define SREQ_GET_DESCRIPTOR				(0x06)
#define SREQ_SET_DESCRIPTOR				(0x07)
#define SREQ_GET_CONFIGURATION			(0x08)
#define SREQ_SET_CONFIGURATION			(0x09)
#define SREQ_GET_INTERFACE				(0x0A)
#define SREQ_SET_INTERFACE				(0x0B)
#define SREQ_SYNCH_FRAME				(0x0C)

/* Class Request Codes */
#define CREQ_GET_STATUS					(0x00)
#define CREQ_CLEAR_FEATURE				(0x01)
#define CREQ_SET_FEATURE				(0x03)
#define CREQ_GET_DESCRIPTOR				(0x06)
#define CREQ_CLEAR_TT_BUFFER			(0x08)
#define CREQ_RESET_TT					(0x09)
#define CREQ_GET_TT_STATE				(0x0A)
#define CREQ_STOP_TT					(0x0B)

/* Request Data Length */
#define GET_STATUS_DATA_LENGTH			(0x02)
#define GET_CONFIG_DATA_LENGTH			(0x01)
#define GET_INTERFACE_DATA_LENGTH		(0x01)
#define CLASS_GET_STATUS_DATA_LENGTH	(0x04)
#define CLASS_GET_TT_STATE_DATA_LENGTH	(0x04)

/* Descriptor Types */
#define DTYPE_DEVICE					(0x01)
#define DTYPE_CONFIGURATION				(0x02)
#define DTYPE_STRING					(0x03)
#define DTYPE_INTERFACE					(0x04)
#define DTYPE_ENDPOINT					(0x05)
#define DTYPE_DEVICE_QUALIFIER			(0x06)
#define DTYPE_OTHER_SPEED_CONFIGURATION	(0x07)
#define DTYPE_INTERFACE_POWER			(0x08)
#define DTYPE_HUB						(0x29)

/* Standard Feature Selector */
#define SFEA_ENDPOINT_HALT				(0x00)
#define SFEA_DEVICE_REMOTE_WAKEUP		(0x01)
#define SFEA_TEST_MODE					(0x02)

/* Set Address Request */
#define MAX_USB_ADDRESS					(0x7F)

/* bmAttributes in Configuration Descriptor */
#define	ATTRIB_SELF_POWERED				(0x40)
#define ATTRIB_REMOTE_WAKEUP			(0x20)

/* bLength in Device Qualifier Descriptor */
#define DEVICE_QUALIFIER_BLENGTH		(0x0A)

/* wHubCharacteristics in HUB Descriptor */
#define HUB_CHAR_PORT_INDICATOOR		(0x0080)

/* Descriptor Offset */
#define OFFSET_BLENGTH					(0)
#define OFFSET_BDESCTYPE				(1)
#define OFFSET_WTOTALLENGTH				(2)
#define OFFSET_BMATTRIBUTES				(7)
#define OFFSET_BNUMCONFIGURATIONS		(17)
#define OFFSET_BNUMINTERFACES			(4)
#define OFFSET_WHUBCHARACTERISTICS		(3)
#define OFFSET_DQ_BNUMCONFIGURATIONS	(8)
#define OFFSET_DQ_RESERVED				(9)

/* Get Hub Status - Hub Status */
#define HUBSTS_HUB_LOCAL_POWER			(0x0001)
#define HUBSTS_HUB_OVER_CURRENT			(0x0002)

/* Get Hub Status - Change Hub Status */
#define HUBSTS_C_HUB_LOCAL_POWER		(0x0001)
#define HUBSTS_C_HUB_OVER_CURRENT		(0x0002)

/* Get Port Status - Port Status */
#define PORTSTS_PORT_CONNECTION			(0x0001)
#define PORTSTS_PORT_ENABLE				(0x0002)
#define PORTSTS_PORT_SUSPEND			(0x0004)
#define PORTSTS_PORT_OVER_CURRENT		(0x0008)
#define PORTSTS_PORT_RESET				(0x0010)
#define PORTSTS_PORT_POWER				(0x0100)
#define PORTSTS_PORT_LOW_SPEED			(0x0200)
#define PORTSTS_PORT_HIGH_SPEED			(0x0400)
#define PORTSTS_PORT_TEST				(0x0800)
#define PORTSTS_PORT_INDICATOR			(0x1000)

/* Get Port Status - Change Port Status */
#define PORTSTS_C_PORT_CONNECTION		(0x0001)
#define PORTSTS_C_PORT_ENABLE			(0x0002)
#define PORTSTS_C_PORT_SUSPEND			(0x0004)
#define PORTSTS_C_PORT_OVER_CURRENT		(0x0008)
#define PORTSTS_C_PORT_RESET			(0x0010)

/* Class Feature Selector */
#define CFEA_C_HUB_LOCAL_POWER			(0x00)
#define CFEA_C_HUB_OVER_CURRENT			(0x01)
#define CFEA_PORT_ENABLE				(0x01)
#define CFEA_PORT_SUSPEND				(0x02)
#define CFEA_PORT_RESET					(0x04)
#define CFEA_PORT_POWER					(0x08)
#define CFEA_PORT_TEST					(0x15)
#define CFEA_PORT_INDICATOR				(0x16)
#define CFEA_C_PORT_CONNECTION			(0x10)
#define CFEA_C_PORT_RESET				(0x14)
#define CFEA_C_PORT_ENABLE				(0x11)
#define CFEA_C_PORT_SUSPEND				(0x12)
#define CFEA_C_PORT_OVER_CURRENT		(0x13)

/* Set Feature Request */
#define TEST_J							USBH_HCDS_PORT_TEST_J
#define TEST_K							USBH_HCDS_PORT_TEST_K
#define TEST_SE0_NAK					USBH_HCDS_PORT_TEST_SE0_NAK
#define TEST_PACKET						USBH_HCDS_PORT_TEST_PACKET
#define TEST_FORCE_ENABLE				USBH_HCDS_PORT_TEST_FORCE_ENABLE


/*****************************************
 * Structure definition
 *****************************************/
typedef struct tagHUB_STATUS{
	unsigned short status;
	unsigned short changeStatus;
}HUB_STATUS;

typedef struct tagHUB_PORT_STATUS{
	unsigned short status;
	unsigned short changeStatus;
}HUB_PORT_STATUS;

typedef struct tagVHUB_MANAGER{
	USBH_HCD_URB *psUrb;
	CALLBACK_PROC pfnCallback;
	struct{
		unsigned short usbState:2;
		unsigned short remoteWakeup:1;
		unsigned short epHalt:1;
		unsigned short registerCBR:1;
		unsigned short reserved:11;
	}bmFlags;
	unsigned char usbAddress;
	unsigned char configValue;
	HUB_STATUS sHubStatus;
	HUB_PORT_STATUS sPortStatus;
}VHUB_MANAGER;

typedef struct tagDEVICE_REQUEST{
	unsigned char	bmRequestType;
	unsigned char	bRequest;
	unsigned char	wValueL;
	unsigned char	wValueH;
	unsigned char	wIndexL;
	unsigned char	wIndexH;
	unsigned char	wLengthL;
	unsigned char	wLengthH;
}DEVICE_REQUEST;

/*****************************************
 * Function prototype declaration
 *****************************************/
#ifdef DEBUG_C

long NotifyPortStateChanged( unsigned long portState, unsigned long param1, void *pParam );

#else /* #ifdef DEBUG_C */


static long NotifyPortStateChanged( unsigned long portState, unsigned long param1, void *pParam );

#endif /* #ifdef DEBUG_C */

Inline long StandardRequest( DEVICE_REQUEST *psDeviceRequest );
Inline long ClassRequest( DEVICE_REQUEST *psDeviceRequest );
Inline long GetStatus( DEVICE_REQUEST *psDeviceRequest );
Inline long ClearFeature( DEVICE_REQUEST *psDeviceRequest );
Inline long SetFeature( DEVICE_REQUEST *psDeviceRequest );
Inline long SetAddress( DEVICE_REQUEST *psDeviceRequest );
Inline long GetDescriptor( DEVICE_REQUEST *psDeviceRequest );
Inline long GetConfiguration( DEVICE_REQUEST *psDeviceRequest );
Inline long SetConfiguration( DEVICE_REQUEST *psDeviceRequest );
Inline long GetInterface( DEVICE_REQUEST *psDeviceRequest );
Inline long SetInterface( DEVICE_REQUEST *psDeviceRequest );
Inline long ClassGetStatus( DEVICE_REQUEST *psDeviceRequest );
Inline long ClassClearFeature( DEVICE_REQUEST *psDeviceRequest );
Inline long ClassSetFeature( DEVICE_REQUEST *psDeviceRequest );
Inline long ClassGetDescriptor( DEVICE_REQUEST *psDeviceRequest );
Inline long ClassClearTTBuffer( DEVICE_REQUEST *psDeviceRequest );
Inline long ClassResetTT( DEVICE_REQUEST *psDeviceRequest );
Inline long ClassGetTTState( DEVICE_REQUEST *psDeviceRequest );
Inline long ClassStopTT( DEVICE_REQUEST *psDeviceRequest );

 /*****************************************
 * Variable definition
 *****************************************/

/* Standard Descriptor: Device Descriptor */
const unsigned char StdDevDesc[] = {
			0x12,			/* blength = 18 Bytes							*/
			0x01,			/* bDescriptorType = Device Descriptor type		*/
			0x00, 0x02,		/* bcdUSB = Ver.2.00								*/
			0x09,			/* bDeviceClass = HUB CLASSCODE						*/
			0x00,			/* bDeviceSubClass = undefined					*/
			0x01,			/* BDeviceProtocol = single TT					*/
			0x40,			/* bMaxPacketSize0 = 64 Bytes 					*/
			0xB8, 0x04,		/* idVendor = "Seiko Epson Corp."					*/
			0x04, 0x09,		/* idProduct = used for virtual route hub		*/
			0x79, 0x00,		/* bcdDevice = Rev.0.79								*/
			0x01,			/* iManufacture= There is String 				*/
			0x02,			/* iProduct = There is String					*/
			0x00,			/* iSerialNumber= There is no String 			*/
			0x01			/* bNumConfigurations= Has 1 Configuration		*/
};

/* Standard Descriptor: Configuration + Interface + Endpoint Descriptor*/
const unsigned char StdConfigDesc[] = {
	/* Configuration Descriptor */
			0x09,			/* blength = 9 Bytes							*/
			0x02,			/* bDescriptorType = Configuration Descriptor type */
			0x19, 0x00,		/* wTotalLength	= 25Bytes(9+9+7) in all			*/
			0x01,			/* bNumInterfaces = Has 1 Interface				*/
			0x01,			/* bConfigurationValue = Value to show this Configuration */
			0x00,			/* iConfiguration = There is no String */
			0xE0,			/* bmAttributes = Attributes of this Configuration */
							/* bit7:Reserved(always be 1)					*/
							/* bit6:Self-Powerd(0 is Bus-Powerd) 			*/
							/* Bit5: Remote wake-up(0 is unsupported) 		*/
							/* bit4-0:Reserved(always be 0)					*/
			0x00,			/* bMasPower = doesn't consume it				*/
	/* Interafce Descriptor */
			0x09,			/* blength = 9 Bytes							*/
			0x04,			/* bDescriptorType = Interface Descriptor type	*/
			0x00,			/* bInterfaceNumber	= 0x00							*/
			0x00,			/* bAlternateSetting = 0x00							*/
			0x01,			/* bNumEndpoints = Has 1 Endpoint				*/
			0x09,			/* bInterfaceClass = HUB CLASSCODE					*/
			0x00,			/* bInterfaceSubClass = undefined 				*/
			0x00,			/* bInterfaceProtocol = single TT		 		*/
			0x00,			/* iInterface = There is no String				*/
	/* Endpoint Descriptor */
			0x07,			/* blength = 7 Bytes							*/
			0x05,			/* bDescriptorType = Endpoint Descriptor type	*/
			INT_EP_ADDRESS,	/* bEndpointAddress = INT_EP_ADDRESS				*/
			0x03,			/* bmAttributes = Attributes of this Endpoint	*/
							/* bit7-6:Reserved(always be 0) 				*/
							/* Bit5-4:Purpose type(for Isochronous)			*/
							/* bit3-2:Isochronous type(for Isochronous)		*/
							/* bit1-0:Transfer type 						*/
							/*		00 = Control								*/
							/*		01 = Isochronous							*/
							/*		10 = Bulk									*/
							/*		11 = Interrrupt								*/
			0x01,0x00,		/* wMaxPacketSize = 1 Byte 						*/
			0x01			/* bInterval = 0x01(FS is 1ms Interval, HS is 125 micro seconds Interval) */
							/* Here the virtual route hub is ignored		*/
};

/* Standard Descriptor: Device Qualifier Descriptor is generated from Device Descriptor */

/* Standard Descriptor: Other Speed Configuration Descriptor is generated from Configuration Descriptor */

/* Standard Descriptor: String Descriptor(Descriptor Index 0) */
const unsigned char StdString0Desc[] = {
			0x04,			/* blength = 4 Bytes						 		*/
			0x03,			/* bDescriptorType = String Descriptor type 		*/
			0x09, 0x04		/* Only wLANGID[0] =0x0409(English) is supported */
};

/* Standard Descriptor: String Descriptor(Descriptor Index 1) */
const unsigned char StdString1Desc[] = {
			0x0C,			/* blength = 12 Bytes						 	*/
			0x03,			/* bDescriptorType = String Descriptor type 	 */
			'E', 0x00,		/* wString = Writes with UNICODE					*/
			'P', 0x00,		/*													*/
			'S', 0x00,		/*													*/
			'O', 0x00,		/*													*/
			'N', 0x00		/*													*/
};

/* Standard Descriptor: String Descriptor(Descriptor Index 2)*/
const unsigned char StdString2Desc[] = {
			0x40,			/* blength = 64 Bytes 							*/
			0x03,			/* bDescriptorType = String Descriptor type 		*/
			'S', 0x00,		/* wString = Writes with UNICODE 				*/
			'1', 0x00,		/*													*/
			'R', 0x00,		/*													*/
			'7', 0x00,		/*													*/
			'2', 0x00,		/*													*/
			'V', 0x00,		/*													*/
			'0', 0x00,		/*													*/
			'5', 0x00,		/*													*/
			' ', 0x00,		/*													*/
			'H', 0x00,		/*													*/
			'o', 0x00,		/*													*/
			's', 0x00,		/*													*/
			't', 0x00,		/*													*/
			' ', 0x00,		/*													*/
			'C', 0x00,		/*													*/
			'o', 0x00,		/*													*/
			'n', 0x00,		/*													*/
			't', 0x00,		/*													*/
			'r', 0x00,		/*													*/
			'o', 0x00,		/*													*/
			'l', 0x00,		/*													*/
			'l', 0x00,		/*													*/
			'e', 0x00,		/*													*/
			'r', 0x00,		/*													*/
			' ', 0x00,		/*													*/
			'D', 0x00,		/*													*/
			'r', 0x00,		/*													*/
			'i', 0x00,		/*													*/
			'v', 0x00,		/*													*/
			'e', 0x00,		/*													*/
			'r', 0x00		/*													*/
};

/* Standard Descriptor: String Descriptor */
unsigned char* const StdStringDesc[] = {
	(unsigned char*)StdString0Desc,
	(unsigned char*)StdString1Desc,
	(unsigned char*)StdString2Desc
};

/* Class Definition Descriptor: Hub Descriptor */
const unsigned char ClassHubDesc[] = {
			0x09,			/* blength = 9 Bytes								*/
			0x29,			/* bDescriptorType = Hub Descriptor type 		*/
			0x01,			/* BNbrPorts = Has 1 port 						*/
			0x00, 0x00,		/* wHubCharacteristics = Characteristic of this hub */
							/* bit15-8:Reserved(always be 0) 				*/
							/* bit7:Port Indicators Supported(unsupported)	*/
							/*	 bit6-5:TT Think Time							*/
							/* 00:Max is 8 FS bit time		 				*/
							/* Max is 16 FS bit time	 						*/
							/* Max is 24 FS bit time		 					*/
							/* Max is 32 FS bit time				 			*/
							/*	 bit4-3:Over-current Protection Mode			*/
							/* Over-current Protection for all				*/
							/* Over-current Protection in each port 			*/
							/* Over-current Protection is not supported		*/
							/* Bit2: Compound device(1: Compound, 0: Single)*/
							/*	 bit1-0:Logical Power Switching Mode			*/
							/* Power Switching for all 						*/
							/* Power Switching in each port 					*/
							/*	   1X:Reserved									*/
			0x0A,			/* bPwrOn2PwrGood = Waiting time for power supply stability of port(20ms) */
			0x00,			/* bHubContrCurrent = Maximum current consumption(0mA) */
			0x00,			/* bDeviceRemovable = Status for device connection */
							/* bit7-2:Reserved(always be 0)		 			*/
							/* bit1:Port 1 (0:disconnect, 1:connected)		*/
							/* bit0:Reserved(always be 0)					*/
			0xFF,			/* bPortPwrCtrlMask = Mask for device unplug status */
							/* Used for USB1.0 compatibility					*/
};

#ifdef DEBUG_C

VHUB_MANAGER VHUBStatus;

#else /* #ifdef DEBUG_C */

static VHUB_MANAGER VHUBStatus;

#endif /* #ifdef DEBUG_C */


/*=============================================================================================
// Function_Name: USBH_HCDS_VHUBInit
//
// description	: Virtual route hub block initialization

⌨️ 快捷键说明

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