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

📄 usbd_protenum.c

📁 epson usb2.0 控制芯片 S1R72V05 固件程序。
💻 C
📖 第 1 页 / 共 5 页
字号:
/*
 * description: USBD Protocol Enumeration
 * Maker	  :
 * Copyright  : (C)2003,SEIKO EPSON Corp. All Rights Reserved.
 *----------------------------------------------------------------------------
 * $Revision: 1.6 $ $Date: 2006/12/22 05:35:27 $
 */


//#include <stdlib.h>	/* malloc, free */
#include <string.h> /* memset */
#include "SPRDEF.h"
#include "SPRSTS.h"
//#include <SysInterrupt.h>
#include "USBD_ProtEnum.h"
#include "usbd_func.h"
#include "OSCall.h"

 /*****************************************
 * Constants Definition
 *****************************************/
#define NUM_INTERFACE					(8)	/* The number of Interface supported. */
#define	BUFFER_SIZE					(2)	/* Size of buffer for data stage of standard request */

#define TMOUT_AUTO_REMOTEWAKEUP		(500)	/* Time of waiting for Auto Remote Wakeup */

/* Module Control relatives */
#define EVENT_STS_DETECT_DISCONNECT		(0x0001)
#define EVENT_STS_DETECT_CONNECT			(0x0002)
#define EVENT_STS_DETECT_RESET			(0x0004)
#define EVENT_STS_DETECT_SUSPEND			(0x0008)
#define EVENT_STS_DETECT_RESUME			(0x0010)
#define EVENT_STS_CONFIGURED				(0x0020)
#define EVENT_STS_DECONFIGURED			(0x0040)
#define EVENT_STS_ALTERNATE_CHANGED		(0x0080)

#define API_STS_WAKEUP_A				(0x0001)

#define NUM_REGISTER_CBR				(10)
#define CBR_CONNECT_EVENT				(0)
#define CBR_DISCONNECT_EVENT			(1)
#define CBR_RESET_EVENT				(2)
#define CBR_SUSPEND_EVENT				(3)
#define CBR_RESUME_EVENT				(4)
#define CBR_CONFIGURED_EVENT			(5)
#define CBR_DECONFIGURED_EVENT			(6)
#define CBR_WAKEUP_END					(7)
#define CBR_ALTERNATE_CHANGED_EVENT		(8)
#define CBR_CLR_ENDPOINTHALT_REQ_EVENT	(9)

#define DUMMY_XFER_SIZE					(0xFFFF)

/* USB relatives */

/* 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)

/* 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)

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

/* Descriptor Types */
#define DTYPE_DEVICE					(USBD_PROT_ENUM_DTYPE_DEVICE)
#define DTYPE_CONFIGURATION				(USBD_PROT_ENUM_DTYPE_CONFIG)
#define DTYPE_STRING					(USBD_PROT_ENUM_DTYPE_STRING)
#define DTYPE_INTERFACE					(0x04)
#define DTYPE_ENDPOINT					(0x05)
#define DTYPE_DEVICE_QUALIFIER			(USBD_PROT_ENUM_DTYPE_QUALIFIER)
#define DTYPE_OTHER_SPEED_CONFIGURATION	(USBD_PROT_ENUM_DTYPE_OTHER_SPEED_CONFIG)
#define DTYPE_INTERFACE_POWER			(0x08)

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

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

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

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

/* Set Feature Request */
#define TEST_J_MODE						(0x01)
#define TEST_K_MODE						(0x02)
#define TEST_SE0_NAK_MODE				(0x03)
#define TEST_PACKET_MODE				(0x04)

/* Set Address Request */
#define MAX_USB_ADDRESS					(127)

/* Get Status Request */
#define ENDPOINT_NOT_STALL				(0x00)
#define ENDPOINT_STALL					(0x01)

/* Get Interface Request */
#define DEFAULT_ALTERNATE_SETTING		(0x00)

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

/* Endpoint Number */
#define EP0_IN							(0x80)
#define EP0_OUT							(0x00)

/* 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)

/* Transfer Type */
#define TRANTYPE_CONTROL				(0x00)
#define TRANTYPE_ISOCHRONOUS			(0x01)
#define TRANTYPE_BULK					(0x02)
#define TRANTYPE_INTERRUPT				(0x03)

/* Synchronaization Type */
#define SYNCTYPE_NOSYNC					(0x00)
#define SYNCTYPE_ASYNC					(0x01)
#define SYNCTYPE_ADAPTIVE				(0x02)
#define SYNCTYPE_SYNC					(0x03)

 /*****************************************
 * Structure Definition
 *****************************************/
typedef const struct{
	UCHAR	bmRequestType;
	UCHAR	bRequest;
	UCHAR	wValueL;
	UCHAR	wValueH;
	UCHAR	wIndexL;
	UCHAR	wIndexH;
	UCHAR	wLengthL;
	UCHAR	wLengthH;
}DEVICE_REQUEST;

typedef	union{
		USHORT	wData;
		struct{
			USHORT	wCBRAttachEvent:1;
			USHORT	wCBRDetachEvent:1;
			USHORT	wCBRResetEvent:1;
			USHORT	wCBRSuspendEvent:1;
			USHORT	wCBRResumeEvent:1;
			USHORT	wCBRRcvRequest:1;
			USHORT	wCBRDataStageEnd:1;
			USHORT	wConfigured:1;
			USHORT	wDeconfigured:1;
			USHORT	wSendRemoteWakeupA:1;
			USHORT	wGoReplyDescriptorA:1;
			USHORT	wEPxPIOSimpleTransferA:1;
			USHORT	wSetInterface:1;
			USHORT	wAltenateSettingChanged:1;
			USHORT	Reserved:2;
		}bit;
}APIFLG;

typedef	union{
		USHORT	wData;
		struct{
			USHORT	wEnableAutoWakeup:1;
			USHORT	wEnableAutoNegotiation:1;
			USHORT	wEnableReplyDescriptor:1;
			USHORT	wEnableAutoSetAddress:1;
			USHORT	wReserved:12;
		}bit;
}CTRLFLG;

typedef struct{
	UCHAR	pbAlternateSetting[NUM_INTERFACE];
	DEVICE_REQUEST	sDeviceRequest;
	UCHAR	bUSBState;
	UCHAR	bUSBAddress;
	UCHAR	bConfigurationValue;
	UCHAR	bHSMode;
	UCHAR	bEnableRemoteWakeup;
}USB_STATUS;

typedef struct{
	APIFLG			sAPIFlag;
	CTRLFLG			sControlFlag;
	USHORT			wAllocatedID;
	USHORT			wOPStatus;
	USHORT			wEventStatus;
	CALLBACK_PROC	pfnCallbackTable[NUM_REGISTER_CBR];
	USB_STATUS		sUSBStatus;
	UCHAR			pDataBuf[BUFFER_SIZE];
}MODULE_STATUS;

/*****************************************
 * Function Prototype Declaration
 *****************************************/
static LONG ModuleManager( void );
static LONG GetPowerSaveMode( void *pParamData );
static LONG GetHWFeatureMode( void *pParamData );
static LONG SetHWFeatureMode( const void *pParamData );
static LONG StandardRequest( void );
static LONG GetStatus( DEVICE_REQUEST *psDeviceRequest );
static LONG ClearFeature( DEVICE_REQUEST *psDeviceRequest );
static LONG SetFeature( DEVICE_REQUEST *psDeviceRequest );
static LONG SetAddress( DEVICE_REQUEST *psDeviceRequest );
static LONG GetDescriptor( DEVICE_REQUEST *psDeviceRequest );
static LONG GetConfiguration( DEVICE_REQUEST *psDeviceRequest );
static LONG SetConfiguration( DEVICE_REQUEST *psDeviceRequest );
static LONG GetInterface( DEVICE_REQUEST *psDeviceRequest );
static LONG SetInterface( DEVICE_REQUEST *psDeviceRequest );
static LONG RequestError( DEVICE_REQUEST *psDeviceRequest );
static LONG CheckInterfaceNumber( UCHAR bIFNum );
static LONG XferRequestData( UCHAR *pbDataBuf, USHORT wXferSize, UCHAR bEPNum );
static LONG XferDescriptorData( USHORT wReqTranCnt, USHORT wDescType, UCHAR bDescSpeed );
static LONG RequestSuccess( void );

/*****************************************
 * MACRO Definition
 *****************************************/
#ifdef USBD_PROT_ENUM_DEBUG
static void Panic( char *pFilename, int nFileline );
#define PANIC()	Panic(__FILE__, __LINE__);
#else	/* ifdef USBD_PROT_ENUM_DEBUG */
#define PANIC()
#endif	/* USBD_PROT_ENUM_DEBUG */


/*****************************************
 * Variable Definition
 *****************************************/

static MODULE_STATUS	ModuleStatus;
static LONG ( * const RegisterCBRTable[])(CALLBACK_PROC) = {
					USBD_FuncRegisterCBRSendRemoteWakeup,
					USBD_FuncRegisterCBRReset,
					USBD_FuncRegisterCBRSuspend,
					USBD_FuncRegisterCBRResume,
					USBD_FuncRegisterCBRChangeUSBAddress,
					USBD_FuncRegisterCBRRequestDecode	};
static LONG ( * const CBRTable[])(ULONG, ULONG, void *) = {
					USBD_ProtEnumRemoteWakeupEnd,
					USBD_ProtEnumResetEvent,
					USBD_ProtEnumSuspendEvent,
					USBD_ProtEnumResumeEvent,
					USBD_ProtEnumChangeUSBAddress,
					USBD_ProtEnumRcvRequest	};

static LONG ( * const StandardRequestTable[])( DEVICE_REQUEST *psDeviceRequest) = {
	GetStatus,				/* 00h Request of Get Status */
	ClearFeature,			/* 01h Request of Clear Feature */
	RequestError,			/* 02h Reserved for future use */
	SetFeature,				/* 03h Request of Set Feature */
	RequestError,			/* 04h Reserved for future use */
	SetAddress,				/* 05h Request of Set Address */
	GetDescriptor,			/* 06h Request of Get Descriptor */
	RequestError,			/* 07h Request of Set Descriptor is unsupported */
	GetConfiguration,		/* 08h Request of Get Configuration */
	SetConfiguration,		/* 09h Request of Set Configuration */
	GetInterface,			/* 0Ah Request of Get Interface */
	SetInterface,			/* 0Bh Request of Set Interface */
	RequestError};			/* 0Ch Request of Synch Frame */

/*======================================================================
// Function_Name: USBD_ProtEnumReset
//
// description	: Reset this module
//
// Reset the module to state of not opened, without concerning the state of module
//
// argument 	: None
//
// return		: STATUS_SUCCESS			Success
========================================================================*/
LONG USBD_ProtEnumReset( void )
{
	UCHAR	i;


	memset(&ModuleStatus, 0, sizeof(ModuleStatus));
	ModuleStatus.wOPStatus = USBD_PROT_ENUM_OP_STOP;

	for( i=0; i< NUM_REGISTER_CBR; i++ ){
		ModuleStatus.pfnCallbackTable[i] = NULL;
	}

	ModuleStatus.sUSBStatus.bUSBState = DEFAULT_STATE;
	USBD_FuncReset();

	/* Though Open is not used, call it here */
	USBD_ProtEnumOpen();

	return STATUS_SUCCESS;
}
/*======================================================================
// Function_Name: USBD_ProtEnumOpen
//
// description	: Open this module
//
//				  Enable to use API of the module
//
// argument 	: None
//
// return		: STATUS_SUCCESS			Success
//				  STATUS_UNSUCCESSFUL		Error
========================================================================*/
LONG USBD_ProtEnumOpen( void )
{
	ULONG	dwAPIStatus;
	UCHAR	i;

		/* Not used */
	/************************/
	/* Get ID from lower module */
	/************************/
	dwAPIStatus = USBD_FuncAllocID(&ModuleStatus.wAllocatedID);
	if( dwAPIStatus != STATUS_SUCCESS ){
		/* Failed to get */

		return STATUS_UNSUCCESSFUL;
	}

	/**************************************/
	/* Register set of callback function to lower module */
	/**************************************/
	for( i = 0; i < (sizeof(RegisterCBRTable) / sizeof(RegisterCBRTable[0])); i++ ){
		dwAPIStatus = RegisterCBRTable[i]((CALLBACK_PROC)CBRTable[i]);
	}

	dwAPIStatus = USBD_FuncRegisterCBREPxPIOSimpleTransferComplete(ModuleStatus.wAllocatedID, EP0_IN, USBD_ProtEnumDataStageEnd);

	dwAPIStatus = USBD_FuncRegisterCBRReplyDescriptor(USBD_ProtEnumDataStageEnd);
	dwAPIStatus = USBD_FuncRegisterCBREP0StatusStageComplete(ModuleStatus.wAllocatedID, USBD_ProtEnumStatusStageEnd);

	/********************/
	/* Process of completion for Open */
	/********************/
	memset(&ModuleStatus, 0, sizeof(ModuleStatus));
	ModuleStatus.wOPStatus = USBD_PROT_ENUM_OP_STOP;

	for( i=0; i< NUM_REGISTER_CBR; i++ ){
		ModuleStatus.pfnCallbackTable[i] = NULL;
	}

	ModuleStatus.sUSBStatus.bUSBState = DEFAULT_STATE;
	return STATUS_SUCCESS;
}

/*======================================================================
// Function_Name: USBD_ProtEnumClose
//
// description	: Close this module
//
//				  Disable to use API of the module
//
// argument 	: None
//
// return		: STATUS_SUCCESS			Success
//				  STATUS_NOT_OPENED 		Not opened
//				  STATUS_UNSUCCESSFUL		Error
========================================================================*/
LONG USBD_ProtEnumClose( void )
{
	return STATUS_UNSUCCESSFUL;
}


/*======================================================================
// Function_Name: USBD_ProtEnumGetParameter
//
// description	: Return parameter of this module
//
//				  Return parameter of specified type
//
// argument 	: wParamType	 			 Type of parameter
//						USBD_PROT_ENUM_POWERSAVE_MODE	Power saving mode
//						USBD_PROT_ENUM_REMOTEWAKEUP_MODE	Remote Wakeup mode
//						USBD_PROT_ENUM_FIFOAREA_SET_MODE	FIFO area setting mode
//				  *pParamData	  			 Pointer of parameter data
//

⌨️ 快捷键说明

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