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

📄 usbd_func.c

📁 epson usb2.0 控制芯片 S1R72V05 固件程序。
💻 C
📖 第 1 页 / 共 5 页
字号:
// return		: STATUS_SUCCESS			Finished normally
// return		: STATUS_UNSUCCESSFUL		Finished abnormally
// return		: STATUS_NOT_OPENED			Not be opened yet
// return		: STATUS_INVALID_PARAMETER	Parameter error
// =============================================================================
*/
LONG USBD_FuncSetParameter(void *ptr)
{
	LONG retValue,retIFValue;
	UCHAR *pTemp;
	USBD_FUNC_HWFEATURE *pHwFeature;
	USBD_IF_FEATURE_MODE FeatureMode;
	USHORT	wEPxFifo[USBD_IF_MAX_ENDPOINT];
	USBD_FUNC_BULKONLY *pBulkOnly;
	UCHAR	epxCBW,epxCSW,epNum;
	USHORT i;
	USHORT size;

	retValue = STATUS_SUCCESS;
	while (1) {
		pTemp = ptr;
		/* Check the minimum length which is necessary for parameter */
		if (pTemp[0] < 2) {
			retValue = STATUS_INVALID_PARAMETER;
			break;
		}
		pTemp = ptr;

		switch (pTemp[1]) {
			case USBD_FUNC_HWFEATURE_PARAM:
				/* Unable to set after USBD_FuncStart() has been started */
				if (IS_START() == TRUE) {
					retValue = STATUS_UNSUCCESSFUL;
					break;
				}

				/* Save parameter of hardware function's setting */
				memcpy(&PrvHwFeatureParam,ptr,sizeof (USBD_FUNC_HWFEATURE));
				pHwFeature = (USBD_FUNC_HWFEATURE *)pTemp;

				/* Do function setting owned by hardware to USB I/F */
				FeatureMode.AutoNego		= pHwFeature->bHwAutoNego;		/* Set the AutoNego H/W function */
				FeatureMode.HWSetAddress	= pHwFeature->bHwSetAddress;		/* Set the HW SetAddress H/W support function */
				FeatureMode.ReplyDescriptor = pHwFeature->bHwReplyDescriptor;	/* Set the Reply Descriptor H/W support function */
				retIFValue = USBD_IFSetFeatureMode(&FeatureMode);
				retValue = IFRET_TO_FUNCRET(retIFValue);
				if (retValue != STATUS_SUCCESS) {
					break;
				}
				if (FeatureMode.ReplyDescriptor == 1) {
					/* Set data in Reply Descriptor area */
					PrvSetupReplyDescriptor();
				}
				break;
			case USBD_FUNC_SWFEATURE_PARAM:
				/* Unable to set after USBD_FuncStart() has been started */
				if (IS_START() == TRUE) {
					retValue = STATUS_UNSUCCESSFUL;
					break;
				}

				/* Save parameter of software function's setting */
				memcpy(&PrvSwFeatureParam,ptr,sizeof (USBD_FUNC_SWFEATURE));

				break;
			case USBD_FUNC_FIFOAREA_PARAM:
				/* Unable to set after USBD_FuncStart() has been started */
				if (IS_START() == TRUE) {
					retValue = STATUS_UNSUCCESSFUL;
					break;
				}

				/* Save parameter of FIFO area */
				memcpy(&PrvFifoAreaParam,ptr,pTemp[0]);

				/* Set the Reply Descriptor area */
				size = PrvFifoAreaParam.wReplyArea;
				retIFValue = USBD_IFSetReplyDataSize(size);
				retValue = IFRET_TO_FUNCRET(retIFValue);
				if (retValue != STATUS_SUCCESS) {
					break;
				}
				epNum = (PrvFifoAreaParam.bLength - 4) / 4;
				/* Set the FIFO area */
				for (i = 0;i < USBD_IF_MAX_ENDPOINT;i++) {
					if (i < epNum) {
						wEPxFifo[i] = (USHORT)PrvFifoAreaParam.dwEpxFifoArea[i];
					} else {
						wEPxFifo[i] = 0x0000;	/* Unused */
					}
				}
				retIFValue = USBD_IFSetEPxDataSize(wEPxFifo,USBD_IF_MAX_ENDPOINT);
				retValue = IFRET_TO_FUNCRET(retIFValue);
				if (retValue != STATUS_SUCCESS) {
					/* Unable to set */
					break;
				}
				break;
			case USBD_FUNC_BULKONLY_PARAM:
				pBulkOnly = (USBD_FUNC_BULKONLY *)pTemp;
				epxCBW = PrvEPAdrToEPx(pBulkOnly->bCBWEPNum);
				epxCSW = PrvEPAdrToEPx(pBulkOnly->bCSWEPNum);
				retIFValue = USBD_IFSetBulkOnlyEndpoint(epxCBW,epxCSW);
				if (retIFValue != STATUS_SUCCESS) {
					retValue = STATUS_INVALID_PARAMETER;
					break;
				}
				USBD_IFSetBulkOnlyNakMode(USBD_IF_CBW_ENBAUTONAK);
				/* Save parameter of BulkOnly */
				memcpy(&PrvBulkOnlyParam,ptr,sizeof (USBD_FUNC_BULKONLY));
				break;
			default:
				retValue = STATUS_INVALID_PARAMETER;
		}
	break;};

	return retValue;
}
/* =============================================================================
// Function_Name: USBD_FuncSendRemoteWakeupA
// description	: Send the remote wake-up signal when suspend
// argument		: None
// return		: STATUS_SUCCESS			Finished normally
// return		: STATUS_UNSUCCESSFUL		Finished abnormally
// return		: STATUS_NOT_OPENED			Not be opened yet
// =============================================================================
*/
LONG USBD_FuncSendRemoteWakeupA(void)
{
	LONG retValue;
	USBD_IF_USB_STATE	usbState;

	retValue = STATUS_SUCCESS;
	while (1) {
		/* Confirm if on Suspending */
		if (IS_BIT(PrvStatusInfo.dwBusStatus,USBD_FUNC_BS_SUSPEND) == FALSE) {
			/* Assume it as error when it is not on Suspending */
			retValue = STATUS_UNSUCCESSFUL;
			break;
		}

		/* Confirm if it is on Remote Wakeup */
		if (IS_BIT(PrvStatusInfo.dwBusStatus,USBD_FUNC_BS_REMOTEWAKEUP) == TRUE) {
			/* Assume it as error when it is on Remote Wakeup */
			retValue = STATUS_UNSUCCESSFUL;
			break;
		}

		/* Wait for 10ms, because remote wakeup has been forbidden within 5ms from the start of USB suspend */
		OS_DlyTsk(TMOUT_REMOTEWAKEUPDIS);


		/* Send out the K state, send out the request of remote wakeup */
		USBD_IFRemoteWakeup(USBD_IF_SIGNAL_K);

		/* Wait while it is in remote wakeup */
		OS_DlyTsk(TMOUT_REMOTEWAKEUP);
		USBD_IFRemoteWakeup(USBD_IF_SIGNAL_STOP_K);
		/* Get the state of LineState */
		USBD_IFGetState(&usbState);
		if (usbState.VBUS == USBD_IF_VBUS_HIGH && usbState.LineState == USBD_IF_TESTMODE_K) {
			/* When the request of remote wakeup was accepted */
			retValue = STATUS_SUCCESS;
		} else {
			/* When the request of remote wakeup was failed */
			retValue = STATUS_UNSUCCESSFUL;
		}
	break;};

	return retValue;
}
/* =============================================================================
// Function_Name: USBD_FuncRegisterCBRSendRemoteWakeup
// description	: Register the callback function for notifying result of remote wakeup
// argument		: pfnCallback			[in]	Address of callback function
// return		: STATUS_SUCCESS				Finished normally
// return		: STATUS_NOT_OPENED			Not be opened yet
// return		: STATUS_UNABLE_TO_REGISTER	Unable to register the callback function
// =============================================================================
*/
LONG USBD_FuncRegisterCBRSendRemoteWakeup(CALLBACK_PROC pfnCallback)
{
	LONG retValue;
	retValue = STATUS_SUCCESS;
	while (1) {
		/* Register the callback function */
		retValue = PrvAddCallbackInf(PRV_CBINF_REMWAKE,PRV_ID_NONE,PRV_PORT_NONE,pfnCallback);
	break;};

	return retValue;

}
/* =============================================================================
// Function_Name: USBD_FuncUnregisterCBRSendRemoteWakeup
// description	: Delete the callback function for notifying result of remote wakeup
// argument		: pfnCallback			[in]	Address of callback function
// return		: STATUS_SUCCESS				Finished normally
// return		: STATUS_NOT_OPENED			Not be opened yet
// return		: STATUS_UNREGISTERED			Unable to delete the callback function
// =============================================================================
*/
LONG USBD_FuncUnregisterCBRSendRemoteWakeup(CALLBACK_PROC pfnCallback)
{
	LONG retValue;

	retValue = STATUS_SUCCESS;
	while (1) {
		/* Delete the callback function */
		retValue = PrvDelCallbackInf(PRV_CBINF_REMWAKE,PRV_ID_NONE,PRV_PORT_NONE,pfnCallback);

	break;};

	return retValue;

}
/* =============================================================================
// Function_Name: USBD_FuncGetStatus
// description	: Get status of USB Function layer
// argument		: id			[in]			ID
// argument		: type		[in]			Type of status
// argument		: *pstatus	[out]			Address to return status
// return		: STATUS_SUCCESS			Finished normally
// return		: STATUS_NOT_OPENED			Not be opened yet
// return		: STATUS_INVALID_PARAMETER	Parameter error
// =============================================================================
*/
LONG USBD_FuncGetStatus(USHORT id,UCHAR type,ULONG *pstatus)
{
	LONG retValue;

	retValue = STATUS_SUCCESS;

	while (1) {
		switch (type) {
			case USBD_FUNC_BUS_EVENT:
				*pstatus = PrvStatusInfo.dwBusEvent;
				PrvStatusInfo.dwBusEvent = 0;
				break;
			case USBD_FUNC_PACKET_EVENT:
				*pstatus = PrvStatusInfo.dwPktEvent;
				PrvStatusInfo.dwPktEvent = 0;
				break;
			case USBD_FUNC_BUS_STATUS:
				*pstatus = PrvStatusInfo.dwBusStatus;
				break;
			case USBD_FUNC_EXEC_STATUS:
				*pstatus = PrvStatusInfo.dwCommonExecStatus;
				*pstatus |= PrvStatusInfo.dwExecStatus[id];
				break;
			default:
				retValue = STATUS_INVALID_PARAMETER;
		}

		/* Unused */
	break;};

	return retValue;

}
/* =============================================================================
// Function_Name: USBD_FuncGetSETUPPacket
// description	: Get the value of request which was received
// argument		: *pRequest			[out]	Address for saving request
// return		: STATUS_SUCCESS			Finished normally
// return		: STATUS_NOT_OPENED			Not be opened yet
// =============================================================================
*/
LONG USBD_FuncGetSETUPPacket(USBD_FUNC_REQUEST *pRequest)
{
	LONG retValue;
	USBD_IF_REQUEST_PACKET req;

	retValue = STATUS_SUCCESS;
	while (1) {
		USBD_IFGetSetupPacket(&req);
		/* Copy the data */
		pRequest->bmRequestType = req.bmRequestType;
		pRequest->bRequest		= req.bRequest;
		pRequest->wValue[0] 	= LOBYTE(req.wValue);
		pRequest->wValue[1] 	= HIBYTE(req.wValue);
		pRequest->wIndex[0] 	= LOBYTE(req.wIndex);
		pRequest->wIndex[1] 	= HIBYTE(req.wIndex);
		pRequest->wLength[0]	= LOBYTE(req.wLength);
		pRequest->wLength[1]	= HIBYTE(req.wLength);

#ifdef DEBUG_C
#ifdef SETUPLOG
	PrvSetupLog[PrvSetupLogCount][0] = pRequest->bmRequestType;
	PrvSetupLog[PrvSetupLogCount][1] = pRequest->bRequest;
	PrvSetupLog[PrvSetupLogCount][2] = pRequest->wValue[0];
	PrvSetupLog[PrvSetupLogCount][3] = pRequest->wValue[1];
	PrvSetupLog[PrvSetupLogCount][4] = pRequest->wIndex[0];
	PrvSetupLog[PrvSetupLogCount][5] = pRequest->wIndex[1];
	PrvSetupLog[PrvSetupLogCount][6] = pRequest->wLength[0];
	PrvSetupLog[PrvSetupLogCount][7] = pRequest->wLength[1];
	PrvSetupLogCount++;
	if (PrvSetupLogCount == 32) {
		PrvSetupLogCount = 0;
	}
#endif
#endif

	break;};

	return retValue;
}
/* =============================================================================
// Function_Name: USBD_FuncGetUSBAddress
// description	: Get the Vallue of USB Address
// argument		: *pusbaddress		[out]	Address to return USB Address
// return		: STATUS_SUCCESS			Finished normally
// return		: STATUS_NOT_OPENED			Not be opened yet
// =============================================================================
*/
LONG USBD_FuncGetUSBAddress(UCHAR *pusbaddress)
{
	LONG retValue;
	UCHAR adr;

	retValue = STATUS_SUCCESS;
	while (1) {
		/* Get USB Address */
		USBD_IFGetAddress(&adr);
		/* Copy the data */
		*pusbaddress = adr;
	break;};

	return retValue;
}
/* =============================================================================
// Function_Name: USBD_FuncSetAddress
// description	: Set USB Address
// argument		: usbaddress			[in]	USB Address for setting
// return		: STATUS_SUCCESS				Finished normally
// return		: STATUS_UNSUCCESSFUL			Finished abnormally
// return		: STATUS_NOT_OPENED			Not be opened yet
// =============================================================================
*/
LONG USBD_FuncSetAddress(UCHAR usbaddress)
{
	LONG retValue,retIFValue;
	USBD_IF_FEATURE_MODE feature;
#ifdef AUTO_SET_ADDRESS_DIS	/* Countermeasure against AutoSetAddress */
	UCHAR autoSetAddress;
#endif /* AUTO_SET_ADDRESS_DIS */

	retValue = STATUS_SUCCESS;
	while (1) {
		/* Check if ReserveControlTransfer() has been called */
		if (IS_BIT(PrvStatusInfo.dwInternalStatus,PRV_IS_EP0TRNDIS) == TRUE) {
			/* Assume it as error when ReserveControlTransfer() has not been done */
			retValue = STATUS_UNSUCCESSFUL;
			break;
		}

		/* Set the flag of USB Address's setting */
		SET_BIT(PrvStatusInfo.dwInternalStatus,PRV_IS_SETADRREQ);
		PrvUsbAddress = usbaddress;

		/* Check if USB Address H/W sopport function is enabled */

⌨️ 快捷键说明

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