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

📄 usbdtask.c

📁 epson usb2.0 控制芯片 S1R72V05 固件程序。
💻 C
📖 第 1 页 / 共 5 页
字号:
					/* Request of completing the process of Storage command */
					tempRet = ReqUsbdStrgCmdEnd(pMsg);
					if (tempRet == STATUS_SUCCESS) {
						UsbdStrgInfo.state = STATE_STRG_STATUSXFER;
					}
				} else if (pMsg->msgHead.msgNo == MSG_NTFY_USBD_STRG_RESET) {
					/* Notification of completion for Storage Reset */
					tempRet = NtfyUsbdStrgReset(pMsg);
					if (tempRet == STATUS_SUCCESS) {
						UsbdStrgInfo.state = STATE_STRG_WAIT_CMD;
					}
				} else if (pMsg->msgHead.msgNo == MSG_REQ_USBD_STRG_SET_LUN) {
					/* Request of setting number of connecting devices */
					ReqUsbdStrgSetLUN(pMsg);
				} else {
					retValue = STATUS_UNSUCCESSFUL;
				}
				break;
			case STATE_STRG_DATAXFER:					/* Data transfer */
				if (pMsg->msgHead.msgNo == MSG_REQ_USBD_STRG_XFER_START) {
					/* Request of transferring Storage data */
					ReqUsbdStrgXferStart(pMsg);
				} else if (pMsg->msgHead.msgNo == MSG_REQ_USBD_STRG_CMD_END) {
					/* Request of completing the process of Storage command */
					ReqUsbdStrgCmdEnd(pMsg);
				} else if (pMsg->msgHead.msgNo == MSG_REQ_USBD_STRG_XFER_ABORT) {
					/* Request of aborting the transfer of Storage data */
					ReqUsbdStrgXferAbort(pMsg);
				} else if (pMsg->msgHead.msgNo == MSG_REQ_USBD_STRG_XFER_FLUSH) {
					/* Request of flushing the transfer of Storage data */
					ReqUsbdStrgXferFlush(pMsg);
				} else if (pMsg->msgHead.msgNo == MSG_REQ_USBD_STRG_SET_LUN) {
					/* Request of setting number of connecting devices */
					ReqUsbdStrgSetLUN(pMsg);
				} else if (pMsg->msgHead.msgNo == MSG_NTFY_USBD_STRG_RESET) {
					/* Notification of completion for Storage Reset */
					tempRet = NtfyUsbdStrgReset(pMsg);
					if (tempRet == STATUS_SUCCESS) {
						UsbdStrgInfo.state = STATE_STRG_WAIT_CMD;
					}
				} else {
					retValue = STATUS_UNSUCCESSFUL;
				}
				break;
			case STATE_STRG_STATUSXFER:					/* Status's transmission */
				if (pMsg->msgHead.msgNo == MSG_NTFY_USBD_STRG_RESET) {
					/* Notification of completion for Storage Reset */
					tempRet = NtfyUsbdStrgReset(pMsg);
					if (tempRet == STATUS_SUCCESS) {
						UsbdStrgInfo.state = STATE_STRG_WAIT_CMD;
					}
				} else if (pMsg->msgHead.msgNo == MSG_REQ_USBD_STRG_SET_LUN) {
					/* Request of setting number of connecting devices */
					ReqUsbdStrgSetLUN(pMsg);
				} else {
					retValue = STATUS_UNSUCCESSFUL;
				}
				break;
			default:
				retValue = STATUS_UNSUCCESSFUL;
				break;
		}
		/* Call it for executing the polling process of USBD_ProtStorage */
		USBD_ProtStorageGetStatus(USBD_PROT_STORAGE_EVENTSTATUS,&dwStorEvent);
	} else {
		if (UsbdTaskInfo.state != STATE_WAIT_DETACH) {
			/* When it is state of USB Suspend */
			if (pMsg->msgHead.msgNo == MSG_REQ_USBD_STRG_SET_LUN) {
				/* Request of setting number of connecting devices */
				ReqUsbdStrgSetLUN(pMsg);
			} else {
				retValue = STATUS_UNSUCCESSFUL;
			}
		}
	}

	return retValue;
}
/*
//=============================================================================
// Function_Name: StateNC_SuspendMsgProc
// description	: Process of message while in Suspend state(Not Config)
// argument		:
// return		:
// flag			:
// global		:
//=============================================================================
*/
static LONG StateNC_SuspendMsgProc(PMSGUSBD pMsg)
{
	LONG tempRet;

	/* Judge message number */
	switch ( pMsg->msgHead.msgNo) {
		case MSG_REQ_USBD_DETECT_VBUS:				/* Request of setting detection of VBUS */
			ReqUsbdDetectVbus(pMsg);
			break;
		case MSG_REQ_USBD_VBUS_STATUS:				/* Request of notifying state of VBUS */
			ReqUsbdVbusStatus(pMsg);
			break;
		case MSG_REQ_USBD_PULLUP_CTRL:				/* Request of USB Attach/Detach */
			ReqUsbdPullupCtrl(pMsg);
			break;
		case MSG_REQ_USBD_REQUEST_NTFY_PARAM:		/* Request of setting notification for request receiving */
			ReqUsbdRequestNtfyParam(pMsg);
			break;
		case MSG_NTFY_USBD_WAKEUP:					/* Notification of completion for process of Wakeup */
			NtfyUsbdWakeup(pMsg);
			break;
		case MSG_REQ_USBD_REMOTEWAKEUP:				/* Request of USB Remote Wakeup */
			ReqUsbdRemoteWakeup(pMsg);
			break;
		default:									/* Main process for Storage Class */
			tempRet = StateStrgMainMsgProc(pMsg);
			if (tempRet != STATUS_SUCCESS) {
				/* Assume it as error, while unable to execute it in this state */
				USBDStatusError(pMsg);
			}
			break;
	}

	return STATUS_SUCCESS;
}
/*
//=============================================================================
// Function_Name: StateSC_SuspendMsgProc
// description	: Process of message while in Suspend(Storage Config)
// argument		:
// return		:
// flag			:
// global		:
//=============================================================================
*/
static LONG StateSC_SuspendMsgProc(PMSGUSBD pMsg)
{
	LONG tempRet;

	/* Judge message number */
	switch ( pMsg->msgHead.msgNo) {
		case MSG_REQ_USBD_DETECT_VBUS:				/* Request of setting detection of VBUS */
			ReqUsbdDetectVbus(pMsg);
			break;
		case MSG_REQ_USBD_VBUS_STATUS:				/* Request of notifying state of VBUS */
			ReqUsbdVbusStatus(pMsg);
			break;
		case MSG_REQ_USBD_PULLUP_CTRL:				/* Request of USB Attach/Detach */
			ReqUsbdPullupCtrl(pMsg);
			break;
		case MSG_REQ_USBD_REQUEST_NTFY_PARAM:		/* Request of setting notification for request receiving */
			ReqUsbdRequestNtfyParam(pMsg);
			break;
		case MSG_NTFY_USBD_WAKEUP:					/* Notification of completion for process of Wakeup */
			NtfyUsbdWakeup(pMsg);
			break;
		case MSG_REQ_USBD_REMOTEWAKEUP:				/* Request of USB Remote Wakeup */
			ReqUsbdRemoteWakeup(pMsg);
			break;
		default:									/* Main process for Storage Class */
			tempRet = StateStrgMainMsgProc(pMsg);
			if (tempRet != STATUS_SUCCESS) {
				/* Assume it as error, while unable to execute it in this state */
				USBDStatusError(pMsg);
			}
			break;
	}

	return STATUS_SUCCESS;
}
/*
//=============================================================================
// Function_Name: StateNotIdleIntProc
// description	: Process of event handler
// argument		:
// return		:
// flag			:
// global		:
//=============================================================================
*/
static LONG StateNotIdleIntProc(void)
{
	USHORT wEnumEvent;
	ULONG dwStorEvent;

	USBD_IFInterruptProc(&device_int_enb_usb,&sie_int_enb_usb,&cpu_int_enb_device_task,&fifo_int_enb_usb);

	/* Call it for executing the polling process of USBD_ProtEnum */
	USBD_ProtEnumGetStatus(&wEnumEvent,USBD_PROT_ENUM_EVENT_STATUS);

	/* Call it for executing the polling process of USBD_ProtStorage */
	USBD_ProtStorageGetStatus(USBD_PROT_STORAGE_EVENTSTATUS,&dwStorEvent);

	return STATUS_SUCCESS;
}
/*
//=============================================================================
// Function_Name: ReqUsbdSetDesc
// description	: Setting of Descriptor
// argument		:
// return		:
// flag			:
// global		:
//=============================================================================
*/
static LONG ReqUsbdSetDesc(PMSGUSBD pMsg)
{
	USB_DESCINFO *pDescInfo;
	USBD_FUNC_HWFEATURE	hwFeatureParam;
	USBD_FUNC_FIFOAREA	fifoAreaParam;
	USHORT wRemainDataLength,wDataLength;
	UCHAR	*ptr;
	USHORT	wDescType;
	UCHAR	bDescSpeed;
	UCHAR	pbSpeedTable[]={USBD_FUNC_SPEEDCOMMON,0xFF,USBD_FUNC_SPEEDFS,USBD_FUNC_SPEEDHS};
	LONG	retValue;
	PMSGUSBD msg;

	OS_GetMpf( MPFID_USBD_MSG, (VP)&msg );						/* Fixed length memory pool for message transmission */
	msg->msgHead.msgSndTskId = TSKID_USBD;						/* ID of USBD Task */
	msg->msgHead.useMpfId = MPFID_USBD_MSG;						/* ID of memory pool to be used */
	msg->msgHead.msgNo = MSG_NTFY_USBD_SET_DESC_CMP;			/* Notification of completion for setting of USB Descriptor */
	msg->msgHead.msgLength = 1;
	((PARAM_MSG_NTFY_USBD_SET_DESC_CMP *)msg->msgData)->result = USBD_PARAM_ERR;

	ptr = (UCHAR *)((PARAM_MSG_REQ_USBD_SET_DESC *)pMsg->msgData)->bufferPtr;
	wRemainDataLength = ((PARAM_MSG_REQ_USBD_SET_DESC *)pMsg->msgData)->descSize;
	while (wRemainDataLength >= sizeof (USB_DESCINFO)) {
		pDescInfo = (USB_DESCINFO *)ptr;
		wDataLength = MAKEWORD(pDescInfo->wDescInfoSizeL,pDescInfo->wDescInfoSizeH);
		if (wRemainDataLength < wDataLength) {
			/* Data is not enough */
			break;
		}

		wDescType = MAKEWORD(pDescInfo->bIndex,pDescInfo->bType);
		if (pDescInfo->bSpeedType > USB_DESCINFO_SPEED_HS) {
			/* Parameter is besides defined value */
			break;
		}
		bDescSpeed = pbSpeedTable[pDescInfo->bSpeedType];
		retValue = USBD_FuncSetDescriptorInfoAddress(bDescSpeed,wDescType,pDescInfo->bDescData);
		if (retValue != STATUS_SUCCESS) {
			/* Unable ot set */
			break;
		}

		wRemainDataLength -= wDataLength;
		ptr += wDataLength;
		if (wRemainDataLength == 0) {
			/* When setting of all Endpoints has completed */

			fifoAreaParam.bLength	 = sizeof (USBD_FUNC_FIFOAREA);
			fifoAreaParam.bType 	 = USBD_FUNC_FIFOAREA_PARAM;
			fifoAreaParam.wReplyArea = 336;	// Reply Descriptor area

			/* Bit15-0:Number of bytes for FIFO area, Bit23-16:Endpoint Address,Bit31-24 unused */
			fifoAreaParam.dwEpxFifoArea[0] = FIFOAREA0;	/* FIFO area in EP0 */
			fifoAreaParam.dwEpxFifoArea[1] = FIFOAREA1;	/* FIFO area in EPa(Unused) */
			fifoAreaParam.dwEpxFifoArea[2] = FIFOAREA2;	/* FIFO area in EPb(Bulk In) */
			fifoAreaParam.dwEpxFifoArea[3] = FIFOAREA3;	/* FIFO area in EPc(Bulk Out) */

			retValue = USBD_FuncSetParameter(&fifoAreaParam);
			if (retValue != STATUS_SUCCESS) {
				/* Unable ot set */
				break;
			}

			USBD_FuncGetParameter(USBD_FUNC_HWFEATURE_PARAM,&hwFeatureParam,sizeof (USBD_FUNC_HWFEATURE));
			hwFeatureParam.bHwReplyDescriptor = 1;
			retValue = USBD_FuncSetParameter(&hwFeatureParam);
			if (retValue == STATUS_SUCCESS) {
				((PARAM_MSG_NTFY_USBD_SET_DESC_CMP *)msg->msgData)->result = USBD_REQ_OK;
				UsbdTaskInfo.initDescriptor = 1;
			}
		}
	}

	/*----------------------------------------------------------------------*/
	/* Transmission of message and notification of event				*/
	/*----------------------------------------------------------------------*/
	OS_SndMbx( MBXID_DEVICE, (T_MSG *)msg );						/* Send message */
	OS_SetFlg( FLGID_DEVICE, FLG_EVENT_MSG_DEVICE );					/* Notify event to DEVICE Task */


	return STATUS_SUCCESS;
}
/*
//=============================================================================
// Function_Name: ReqUsbdDetectVbus
// description	: Set the Enable/Disable for detection of VBUS
// argument		:
// return		:
// flag			:
// global		:
//=============================================================================
*/
static LONG ReqUsbdDetectVbus(PMSGUSBD pMsg)
{
	LONG	retValue;
	UCHAR	detectFlag;
	USBD_IF_USB_STATE usbState;
	PMSGUSBD msg;
	UCHAR ntfyVBUSStatus = FALSE;

	OS_GetMpf( MPFID_USBD_MSG, (VP)&msg );						/* Fixed length memory pool for message transmission */
	msg->msgHead.msgSndTskId = TSKID_USBD;						/* ID of USBD Task */
	msg->msgHead.useMpfId = MPFID_USBD_MSG;						/* ID of memory pool to be used */
	msg->msgHead.msgNo = MSG_NTFY_USBD_DETECT_VBUS;				/* Notification of completion for detection of VBUS */
	msg->msgHead.msgLength = sizeof (PARAM_MSG_NTFY_USBD_DETECT_VBUS);
	((PARAM_MSG_NTFY_USBD_DETECT_VBUS *)msg->msgData)->result = USBD_PARAM_ERR;

	detectFlag = ((PARAM_MSG_REQ_USBD_DETECT_VBUS *)pMsg->msgData)->detectFlag;
	if (detectFlag == USBD_VBUS_ENABLE) {
		retValue = USBD_FuncRegisterCBRVBusChange(VBusChangeCallback);
		if (retValue == STATUS_SUCCESS) {
			/* Finished normally */
			USBD_IFGetState(&usbState);
			if (usbState.VBUS == USBD_IF_VBUS_HIGH) {
				/*
				 * If VBUS was High, because it is unable the detct the fact of being High,
				 * set flag to notify the VBUS Status
				 */
				ntfyVBUSStatus = TRUE;
			}
			UsbdTaskInfo.state = STATE_WAIT_CONNECT;
			((PARAM_MSG_NTFY_USBD_DETECT_VBUS *)msg->msgData)->result = USBD_REQ_OK;
		}
	} else if (detectFlag == USBD_VBUS_DISABLE) {
		retValue = USBD_FuncUnregisterCBRVBusChange(VBusChangeCallback);
		if (retValue == STATUS_SUCCESS || STATUS_UNREGISTERED) {
			/* Finished normally or originally it has not been registered */
			((PARAM_MSG_NTFY_USBD_DETECT_VBUS *)msg->msgData)->result = USBD_REQ_OK;
		}
		/* Stop the operation of USB */
		USBD_FuncStop();
		UsbdTaskInfo.state = STATE_IDLE;
	}

	/*----------------------------------------------------------------------*/
	/* Transmission of message and notification of event				*/
	/*----------------------------------------------------------------------*/
	OS_SndMbx( MBXID_DEVICE, (T_MSG *)msg );						/* Send message */
	OS_SetFlg( FLGID_DEVICE, FLG_EVENT_MSG_DEVICE );					/* Notify event to DEVICE Task */

	if (ntfyVBUSStatus == TRUE) {
		/*
		 * When this request has been called, or VBUS was High, because it is unable to notify the fact of VBUS being High
		 * to other task, call the callback of changing VBUS
		 */
		VBusChangeCallback(0L,0L,NULL);
	}
	return STATUS_SUCCESS;
}
/*
//=============================================================================
// Function_Name: ReqUsbdVbusStatus
// description	: Get current status of VBUS
// argument		:
// return		:
// flag			:
// global		:
//=============================================================================
*/
static LONG ReqUsbdVbusStatus(PMSGUSBD pMsg)
{
	ULONG lParam0 = 0L,lParam1 = 0L;
	VOID *pParam = NULL;
	/* Call the callback here which is called by USBD_Func when status of VBUS has been changed */
	VBusChangeCallback(lParam0,lParam1,pParam);

	return STATUS_SUCCESS;
}
/*
//=============================================================================
// Function_Name: VBusChangeCallback
// description	: The callback which is called when status of VBUS has been changed
// argument		:
// return		:
// flag			:

⌨️ 快捷键说明

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