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

📄 usbh_hcds_port.c

📁 epson usb2.0 控制芯片 S1R72V05 固件程序。
💻 C
字号:
/*
 *	description	: USBH HCD Port Control(static)
 *	Maker		: Hiromichi Kondo
 *	Copyright	: (C)2005,SEIKO EPSON Corp. All Rights Reserved.
 */


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



/*****************************************
 * Define definition
 *****************************************/

/*****************************************
 * Structure definition
 *****************************************/
typedef struct tagPORT_MANAGER{
	CALLBACK_PROC pfnCallback;
	unsigned char CurPortState;
	unsigned char CurRmtWkupControl;
	struct{
		unsigned short enableTestMode:1;
		unsigned short afterReset:1;
		unsigned short reserved:15;
	}bmFlags;
}PORT_MANAGER;

/*****************************************
 * Function prototype declaration
 *****************************************/
#ifdef DEBUG_C
long PortInterrupt( unsigned long param0, unsigned long param1, void *pParam );
#else /* #ifdef DEBUG_C */
static long PortInterrupt( unsigned long param0, unsigned long param1, void *pParam );
#endif /* #ifdef DEBUG_C */

/*****************************************
 * Macro declaration
 *****************************************/

/*****************************************
 * Variable definition
 *****************************************/
#ifdef DEBUG_C

PORT_MANAGER PortStatus;

#else /* #ifdef DEBUG_C */

static PORT_MANAGER PortStatus;

#endif /* #ifdef DEBUG_C */

/*=============================================================================================
// Function_Name: USBH_HCDS_PortInit
//
// description	: Port control block initialization
//
//				  Initialize the port control part
//
// argument 	: None
//
// return		: None
===============================================================================================*/
void USBH_HCDS_PortInit( void )
{
	memset(&PortStatus, 0, sizeof(PortStatus));
	PortStatus.CurPortState = USBH_HCDS_PORT_ST_UNKNOWN;
	PortStatus.CurRmtWkupControl = USBH_HCDS_PORT_RMTWKUP_DISABLE;
	PortStatus.pfnCallback = NULL;
	PortStatus.bmFlags.afterReset = 1;
}

/*=============================================================================================
// Function_Name: USBH_HCDS_PortRegisterCBR
//
// description	: Register the notification target of port state change
//
//				  Register the callback function notified when the state of the downstream port changed
//
//
// argument 	: pfnCallback						(in)Pointer of callback function
//
// return		: None
===============================================================================================*/
void USBH_HCDS_PortRegisterCBR( CALLBACK_PROC pfnCallback)
{
	PortStatus.pfnCallback = pfnCallback;
}

/*=============================================================================================
// Function_Name: USBH_HCDS_PortGetCBR
//
// description	: Get notification target of port state change
//
//				  Return the callback function notified when the state of the downstream port changed
//
//
// argument 	: None
//
// return		: pfnCallback						Pointer of callback function

===============================================================================================*/
CALLBACK_PROC USBH_HCDS_PortGetCBR( void )
{
	return PortStatus.pfnCallback;
}

/*=============================================================================================
// Function_Name: USBH_HCDS_PortControl
//
// description	: Set port state
//
//				  Set the state of the downstream port
//
// argument 	: portState							(in)State of port to set
//
// return		: STATUS_SUCCESS					Processing completed successfully
//				  STATUS_NOT_READY					Transfer not ready
//				  STATUS_INVALID_PARAMETER			Parameter error
//				  STATUS_UNSUCCESSFUL				Change unsuccessful

===============================================================================================*/
long USBH_HCDS_PortControl( unsigned char portState )
{
	unsigned char remoteWakeupControl;


	if( PortStatus.bmFlags.afterReset == 1 ){
		/* Register PortInterrupt after reset */

		USBH_HCDS_HCRegisterPortInterrupt(PortInterrupt);

		PortStatus.bmFlags.afterReset = 0;
	}


	if( PortStatus.bmFlags.enableTestMode == 1 ){
		/* When executed in test mode, the state cannot be controlled */

		return STATUS_NOT_READY;
	}

	switch( portState ){
		case USBH_HCDS_PORT_ST_POWERED_OFF:
			/* State of VBUS OFF */

			USBH_HCDS_HCPortGoIdle();
			break;
		case USBH_HCDS_PORT_ST_DISCONNECTED:
			/* State of connect waiting of the USB device though VBUS is ON */

			USBH_HCDS_HCPortGoWaitConnect();
			break;
		case USBH_HCDS_PORT_ST_DISABLED:
			/* State of USB reset be not done though the USB device connected */

			if( PortStatus.CurPortState != USBH_HCDS_PORT_ST_DISCONNECTED ){
				USBH_HCDS_HCPortGoDisabled();
			}
			break;
		case USBH_HCDS_PORT_ST_RESETTING:
			/* State of USB reset */

			USBH_HCDS_HCPortGoResetToOP();
			break;
		case USBH_HCDS_PORT_ST_ENABLED:
			/* State of enable to process request with USB device */

			break;
		case USBH_HCDS_PORT_ST_SUSPENDING:
			/* State of be changing to USB suspend */

			if( PortStatus.CurPortState <= USBH_HCDS_PORT_ST_DISCONNECTED ){
				/* Return error when in state that cannot change to USB suspend */

				return STATUS_UNSUCCESSFUL;
			}

			if( PortStatus.CurRmtWkupControl == USBH_HCDS_PORT_RMTWKUP_ENABLE ){
				remoteWakeupControl = USBH_HCDS_HC_REMOTE_WAKEUP_ENABLE;
			} else {
				remoteWakeupControl = USBH_HCDS_HC_REMOTE_WAKEUP_DISABLE;
			}
			USBH_HCDS_HCPortGoSuspend(remoteWakeupControl);
			break;
		case USBH_HCDS_PORT_ST_SUSPENDED:
			/* State of USB suspend */

			break;
		case USBH_HCDS_PORT_ST_RESUMING:
			/* State of be resuming from USB suspend */

			if( PortStatus.CurPortState != USBH_HCDS_PORT_ST_SUSPENDED ){
				/* Return error when not in USB suspend state */

				return STATUS_UNSUCCESSFUL;
			}
			USBH_HCDS_HCPortGoResume();
			break;
		case USBH_HCDS_PORT_ST_VBUS_OVER_CURRENT:
			/* State of VBUS overcurrent occurred */

			/* Set to Idle immediately and stop the VBUS supply  */
			USBH_HCDS_HCPortGoIdle();
		case USBH_HCDS_PORT_ST_VBUS_OVER_CURRENT_CLR:
			/* State of be recovered from VBUS overcurrent */

			break;
		default:
			return STATUS_INVALID_PARAMETER;
	}

	PortStatus.CurPortState = portState;

	return STATUS_SUCCESS;
}

/*=============================================================================================
// Function_Name: USBH_HCDS_PortRemoteWakeupControl
//
// description	: Remote wake-up control function
//
//				  Controll the remote wake-up function of the downstream port
//
// argument 	: control							(in)Enable/Disable
//													USBH_HCDS_PORT_RMTWKUP_ENABLE
//													USBH_HCDS_PORT_RMTWKUP_DISABLE
//
// return		: None
===============================================================================================*/
void USBH_HCDS_PortRemoteWakeupControl( unsigned char control )
{
	if( control == USBH_HCDS_PORT_RMTWKUP_ENABLE ){
		/* Enable remote wake-up */

		PortStatus.CurRmtWkupControl = USBH_HCDS_PORT_RMTWKUP_ENABLE;
	} else {
		/* Disable Remote wake-up */

		PortStatus.CurRmtWkupControl = USBH_HCDS_PORT_RMTWKUP_DISABLE;
	}
}

/*=============================================================================================
// Function_Name: USBH_HCDS_PortTestMode
//
// description	: Control for test mode of port
//
//				  Control the test mode of the downstream port
//
// argument 	: testMode							(in)Test mode to set
//				  control							(in)Enable/Disable for test mode
//														USBH_HCDS_PORT_TEST_ENABLE
//														USBH_HCDS_PORT_TEST_DISABLE
//
// return		: STATUS_SUCCESS					Processing completed successfully
//				  STATUS_INVALID_PARAMETER			Parameter error

===============================================================================================*/
long USBH_HCDS_PortTestMode( unsigned char testMode, unsigned char control )
{
#ifdef HCD_PARAMCHK_C
	long retValue;
#endif

	if( control == USBH_HCDS_PORT_TEST_ENABLE ){
		/* /Start test mode */

		PortStatus.bmFlags.enableTestMode = 1;

#ifdef HCD_PARAMCHK_C
		retValue = USBH_HCDS_HCStartTestMode(testMode);
		if( retValue != STATUS_SUCCESS ){
			return retValue;
		}
#else
		USBH_HCDS_HCStartTestMode(testMode);
#endif

	} else {
		/* Stop test mode */

		USBH_HCDS_HCStopTestMode();

		PortStatus.bmFlags.enableTestMode = 0;
	}

	return STATUS_SUCCESS;
}

/*=============================================================================================
// Function_Name: PortInterrupt
//
// description	: Port interrupt process
//
//				  Processing that is called from interrupt when state of downstream port changed
//
// argument 	: param0							(in)State of port to set
//				  param1							(in)Transfer speed of port
//				  *pParam							(in)Not used
//
// return		: STATUS_SUCCESS					Processing completed successfully
//				  STATUS_INVALID_PARAMETER			Parameter error
===============================================================================================*/
long PortInterrupt( unsigned long param0, unsigned long param1, void *pParam )
{
	unsigned char portState, portSpeed;
	unsigned long retValue;


	portState = (unsigned char)param0;
	portSpeed = (unsigned char)param1;

	/*===============/
	Set port state/
	/===============*/
	retValue = USBH_HCDS_PortControl( portState );
	if( retValue != STATUS_SUCCESS ){
		return retValue;
	}

	/*=====================================/
	Callback processing for asynchronous event notification/
	/=====================================*/
	USBH_HCDS_ExecCallback(PortStatus.pfnCallback, portState, portSpeed, NULL);

	return STATUS_SUCCESS;
}


⌨️ 快捷键说明

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