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

📄 usbh_hcd_api.c

📁 epson usb2.0 控制芯片 S1R72V05 固件程序。
💻 C
📖 第 1 页 / 共 2 页
字号:
===============================================================================================*/
long USBH_HCD_EndpointDisable( USBH_HCD_USBDEV *psDev, unsigned char epAddress )
{
	if( psDev == NULL ){
		/* The pointer of the USB device information structure is NULL */

		return USBH_HCD_STATUS_INVALID_PARAMETER;
	}

	if( HCDStatus.bmFlags.hcSuspend == 1 ){
		/* Host Controller is suspending */

		return USBH_HCD_STATUS_UNSUCCESSFUL;
	}

	/*=========================================================/
	/ Cancel all the URB that relates to Endpoint of corresponding USB device /
	/=========================================================*/
	USBH_HCDS_URBEndpointAllCancel(psDev, HCDStatus.psRootDev, epAddress);

	return USBH_HCD_STATUS_SUCCESS;
}

/*=============================================================================================
// Function_Name: USBH_HCD_Suspend
//
// description	: Host Controller is suspended
//
//				  After suspending the route hub, also suspend the Host Controller in specified suspend level
//
// argument 	: suspendLevel						(in)Suspend level
//														USBH_HCD_SUSPEND_LV0
//															 Oscillator and PLL all operated
//														USBH_HCD_SUSPEND_LV1
//															Stop PLL only
//														USBH_HCD_SUSPEND_LV2
//															Stop all oscillator and PLL
//
//				  pfnCallback						(in)Pointer of callback function that is called when completed
//
// return		: USBH_HCD_STATUS_SUCCESS			Processing is completed successfully
//				  USBH_HCD_STATUS_UNSUCCESSFUL		Host Controller is suspending

===============================================================================================*/
long USBH_HCD_Suspend( USBH_HCD_ENUMSUSPENDLV suspendLevel, USBH_HCD_CALLBACK pfnCallback )
{
	long retValue;


	if( HCDStatus.bmFlags.hcSuspend == 1 ){
		/* Host Controller has already suspended */

		return USBH_HCD_STATUS_UNSUCCESSFUL;
	}

	HCDStatus.pfnSuspendCallback = pfnCallback;
	HCDStatus.bmFlags.hcSuspend = 1;
	HCDStatus.suspendLevel = (unsigned char)suspendLevel;

	/*=======================================/
	/ Change after target of port state change notification is saved /
	/=======================================*/
	HCDStatus.pfnSavedPortCallback = USBH_HCDS_PortGetCBR();

	USBH_HCDS_PortRegisterCBR(HCDS_PortStatusChangedCallback);

	/*======================/
	/ Begin the USB suspend /
	/======================*/
	retValue = USBH_HCDS_PortControl(USBH_HCDS_PORT_ST_SUSPENDING);
	if( retValue != STATUS_SUCCESS ){
		/* we can consider that the USB suspend is compelted  when in the state that translation can not be done */

		HCDS_PortStatusChangedCallback(USBH_HCDS_PORT_ST_SUSPENDED, USBH_HCDS_PORT_SPEED_MODE_UNKNOWN, NULL);
	}

	return USBH_HCD_STATUS_SUCCESS;
}

/*=============================================================================================
// Function_Name: USBH_HCD_Resume
//
// description	: Host Controller resume
//
//				  After resuming the Host Controller, also resume the route hub.
//
// argument 	: pfnCallback						(in)Pointer of callback function that is called when completed
//
// return		: USBH_HCD_STATUS_SUCCESS			Processing is completed successfully
//				  USBH_HCD_STATUS_UNSUCCESSFUL		Host Controller is not suspended

===============================================================================================*/
long USBH_HCD_Resume( USBH_HCD_CALLBACK pfnCallback )
{
	unsigned char suspendLevel;


	if( HCDStatus.bmFlags.hcSuspend == 0 ){
		/* Except while Host Controller is suspending */

		return USBH_HCD_STATUS_UNSUCCESSFUL;
	}

	HCDStatus.pfnResumeCallback = pfnCallback;

	suspendLevel = HCDStatus.suspendLevel;
	if( suspendLevel == USBH_HCD_SUSPEND_LV0 ){
		/* Return while oscillator and PLL in operation */

		// Can not do GoActHost when it is in 1 port operation
		if( (RegRead(REG08_ClkSelect) & MASK_Port1x2 ) == BIT_Port1x2_1Port ) {
			HCDS_HCResumeCmpCallback(USBH_HCDS_HC_PM_STATE_ACTDEVICE, 0, NULL);
		} else {
			HCDS_HCResumeCmpCallback(USBH_HCDS_HC_PM_STATE_ACTHOST, 0, NULL);
		}

	} else if( suspendLevel == USBH_HCD_SUSPEND_LV1 ){
		/* Only PLL return from the stop */

		// Can not do GoActHost when it is in 1 port operation
		if( (RegRead(REG08_ClkSelect) & MASK_Port1x2 ) == BIT_Port1x2_1Port ) {
			USBH_HCDS_HCPMControl(USBH_HCDS_HC_PM_STATE_ACTDEVICE, HCDS_HCResumeCmpCallback);
		} else {
			USBH_HCDS_HCPMControl(USBH_HCDS_HC_PM_STATE_ACTHOST, HCDS_HCResumeCmpCallback);
		}

	} else if( suspendLevel == USBH_HCD_SUSPEND_LV2 ){
		/* Resume oscillator and PLL from the stop */

		// Can not do GoActHost when it is in 1 port operation
		if( (RegRead(REG08_ClkSelect) & MASK_Port1x2 ) == BIT_Port1x2_1Port ) {
			USBH_HCDS_HCPMControl(USBH_HCDS_HC_PM_STATE_ACTDEVICE, HCDS_HCResumeCmpCallback);
		} else {
			USBH_HCDS_HCPMControl(USBH_HCDS_HC_PM_STATE_ACTHOST, HCDS_HCResumeCmpCallback);
		}
	}

	return USBH_HCD_STATUS_SUCCESS;
}

/*=============================================================================================
// Function_Name: USBH_HCD_DetectDevConnect
//
// description	: Detect whether device is connected with connector on the Device side
//
//				  Detect whether device is connected with B connector on the Device side
//
// argument 	: pfnCallback						(in)Pointer of callback function that is called when detecting it
//
// return		: USBH_HCD_STATUS_SUCCESS			Processing is completed successfully
===============================================================================================*/
long USBH_HCD_DetectDevConnect( USBH_HCD_CALLBACK pfnCallback )
{
	HCDStatus.pfnDetDevConnectCallback = pfnCallback;

	USBH_HCDS_HCRegisterDetDevConnect(HCDS_DetDevConnectCallback);

	return USBH_HCD_STATUS_SUCCESS;
}

/*=============================================================================================
// Function_Name: USBH_HCD_GetDevVBUSStatus
//
// description	: Return the connector's current VBUS state on the Device side
//
//				  Return the connector's current VBUS state on the Device side
//
// argument 	: pVBUSStatus;
//
// return		: USBH_HCD_STATUS_SUCCESS			Processing is completed successfully
//				  USBH_HCD_STATUS_INVALID_PARAMETER	Error in passed parameters
===============================================================================================*/
long USBH_HCD_GetDevVBUSStatus( unsigned char *pVBUSStatus )
{
	if( pVBUSStatus == NULL ){
		return USBH_HCD_STATUS_INVALID_PARAMETER;
	}

	*pVBUSStatus = USBH_HCDS_HCGetVBUSStatus();

	return USBH_HCD_STATUS_SUCCESS;
}

/*=============================================================================================
// Function_Name: USBH_HCD_Interrupt
//
// description	: Process the interrupt of this module
//
//				  Process the interrupt of this module
//
// argument 	: None
//
// return		: USBH_HCD_STATUS_SUCCESS			Processing is completed successfully
===============================================================================================*/
long USBH_HCD_Interrupt( void )
{
	USBH_HCDS_HCInterruptProc();

	return USBH_HCD_STATUS_SUCCESS;
}

/*=============================================================================================
// Function_Name: HCD_InitCallback
//
// description	: Callback processing of USBH_HCD_Init() completeness
//
//				  When initialization is completed, the host function is made active.
//
// argument 	: None
//
// return		: USBH_HCD_STATUS_SUCCESS			Processing is completed successfully

===============================================================================================*/
static long HCDS_InitCallback( unsigned long event, unsigned long param1, void *pParam )
{

	USBH_HCDS_HCHostActive();

	HCDS_ExecCallback(HCDStatus.pfnInitCallback, USBH_HCD_MSG_INIT_CMP, 0, NULL);

	return USBH_HCD_STATUS_SUCCESS;
}

/*=============================================================================================
// Function_Name: HCDS_PortStatusChangedCallback
//
// description	: Callback processing of port status change notification
//
// argument 	: portState							(in)Port state to set
//				  portSpeed							(in)Transfer speed of port
//				  *pParam							(in)Unused
//
// return		: STATUS_SUCCESS					Processing is completed successfully

===============================================================================================*/
static long HCDS_PortStatusChangedCallback(unsigned long portState, unsigned long portSpeed, void *pParam)
{
	unsigned char suspendLevel;


	switch( portState ){
		case USBH_HCDS_PORT_ST_ENABLED:
			/* Resume completion from suspend */

			HCDStatus.bmFlags.hcSuspend = 0;		/* Release when Host Controller is being suspended */

			USBH_HCDS_PortRegisterCBR(HCDStatus.pfnSavedPortCallback);

			HCDS_ExecCallback(HCDStatus.pfnResumeCallback, USBH_HCD_MSG_RESUME_CMP, 0, NULL);
			break;
		case USBH_HCDS_PORT_ST_SUSPENDED:
			/* Suspend transition complete */

			suspendLevel = HCDStatus.suspendLevel;
			if( suspendLevel == USBH_HCD_SUSPEND_LV0 ){
				/* Because oscillator and PLL remains working, nothing is done */

				;
			} else if( suspendLevel == USBH_HCD_SUSPEND_LV1 ){
				/* Stop PLL only */

				USBH_HCDS_HCPMControl(USBH_HCDS_HC_PM_STATE_SNOOZE, NULL);

			} else if( suspendLevel == USBH_HCD_SUSPEND_LV2 ){
				/* Stop Oscillator and PLL */

				USBH_HCDS_HCPMControl(USBH_HCDS_HC_PM_STATE_SLEEP, NULL);
			}

			HCDS_ExecCallback(HCDStatus.pfnSuspendCallback, USBH_HCD_MSG_SUSPEND_CMP, 0, NULL);
			break;
		case USBH_HCDS_PORT_ST_DISCONNECTED:
			HCDStatus.bmFlags.hcSuspend = 0;		/* Release when Host Controller is suspended */
			USBH_HCDS_ExecCallback(HCDStatus.pfnSavedPortCallback, portState, portSpeed, pParam);
			break;
		default:
			USBH_HCDS_ExecCallback(HCDStatus.pfnSavedPortCallback, portState, portSpeed, pParam);
	}

	return STATUS_SUCCESS;
}

/*=============================================================================================
// Function_Name: HCDS_HCResumeCmpCallback
//
// description	: Callback processing of Host Controller resume completion
//
// argument 	: param0							(in)Unused
//				  param1							(in)Unused
//				  *pParam							(in)Unused
//
// return		: STATUS_SUCCESS					Processing is completed successfully

===============================================================================================*/
static long HCDS_HCResumeCmpCallback(unsigned long param0, unsigned long param1, void *pParam)
{
	long retValue;


	/*==================/
	/ USBResume begin execution /
	/==================*/
	retValue = USBH_HCDS_PortControl(USBH_HCDS_PORT_ST_RESUMING);
	if( retValue != STATUS_SUCCESS ){
		/* we can consider that the return from the USB suspend is completed when in the status that translation can not be done */

		HCDS_PortStatusChangedCallback(USBH_HCDS_PORT_ST_ENABLED, USBH_HCDS_PORT_SPEED_MODE_UNKNOWN, NULL);
	}

	return STATUS_SUCCESS;
}

/*=============================================================================================
// Function_Name: HCDS_DetDevConnectCallback
//
// description	: Callback processing of Device connection detection
//
// argument 	: param0							(in)Unused
//				  param1							(in)Unused
//				  *pParam							(in)Unused
//
// return		: STATUS_SUCCESS					Processing is completed successfully

===============================================================================================*/
static long HCDS_DetDevConnectCallback(unsigned long param0, unsigned long param1, void *pParam)
{
	HCDS_ExecCallback(HCDStatus.pfnDetDevConnectCallback, USBH_HCD_MSG_DETECT_DEV_CONNECT, 0, NULL);

	return STATUS_SUCCESS;
}

/*=============================================================================================
// Function_Name: HCDS_ExecCallback
//
// description	: Execut part of API callback function
//
// argument 	: pfnFunc							Pointer of callback function
//				  param0							Argument 1 passed to callback function
//				  param1							Argument 2 passed to callback function
//				  *pParam							Argument 3 passed to callback function
//
// return		: USBH_HCD_STATUS_SUCCESS			Processing is completed successfully
//				  USBH_HCD_STATUS_XXX				Depend on the callback function
===============================================================================================*/
void HCDS_ExecCallback(USBH_HCD_CALLBACK pfnFunc, unsigned long param0, unsigned long param1, void *pParam)
{
	if( pfnFunc != NULL ){
		/* The callback function is registered */

		/* Call the callback function */
		(pfnFunc)(param0, param1, pParam);
	}
}

⌨️ 快捷键说明

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