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

📄 usbdtask.c

📁 epson usb2.0 控制芯片 S1R72V05 固件程序。
💻 C
📖 第 1 页 / 共 5 页
字号:
//=============================================================================
*/
LONG USBDMsgEvent( PMSGUSBD pMsg )
{
	/* Do process which is related to message number */
	switch (UsbdTaskInfo.state) {
		case STATE_IDLE:			/* Idle */
			UsbdStrgInfo.state = STATE_STRG_NONE;
			StateIdleMsgProc(pMsg);
			break;
		case STATE_WAIT_CONNECT:	/* Waiting Connect */
			UsbdStrgInfo.state = STATE_STRG_NONE;
			StateWaitConnectMsgProc(pMsg);
			break;
		case STATE_WAIT_ATTACH:		/* Waiting Attach */
			UsbdStrgInfo.state = STATE_STRG_NONE;
			StateWaitAttachMsgProc(pMsg);
			break;
		case STATE_WAIT_DETACH:		/* Waiting Detach */
			UsbdStrgInfo.state = STATE_STRG_NONE;
			StateWaitDetachMsgProc(pMsg);
			break;
		case STATE_NOT_CONFIG:		/* Not Configured */
			UsbdStrgInfo.state = STATE_STRG_NONE;
			StateNotConfigMsgProc(pMsg);
			break;
		case STATE_STRG_CONFIG:		/* Storage Configured */
			StateStrgConfigMsgProc(pMsg);
			break;
		case STATE_NC_SUSPEND:		/* Suspend(Not Config) */
			StateNC_SuspendMsgProc(pMsg);
			break;
		case STATE_SC_SUSPEND:		/* Suspend(Storage Config) */
			StateSC_SuspendMsgProc(pMsg);
			break;
		default:
			/* ??? */
			break;
	}

	return STATUS_SUCCESS;
}
/*
//=============================================================================
// Function_Name: USBDMailDataCancel
// description	: Discard data of USBD Mailbox
// argument		:
// return		:
// flag			:
// global		:
//=============================================================================
*/
LONG USBDMailDataCancel( void )
{
	VP	pk_msg;
	int	mpfid,ercd;

	do {
		/* Receive message from mailbox */
		ercd = OS_PRcvMbx( MBXID_USBD, ( T_MSG** )&pk_msg );
		if ( ercd == E_OK )
		{
			/* Discard data when there are messages */
			mpfid = (( PMSGHEADUSBD )pk_msg )->useMpfId;
			OS_RelMpf( mpfid, pk_msg );				/* Release message buffer */
		}
	} while( ercd == E_OK );

	return STATUS_SUCCESS;
}

/*
//=============================================================================
// Function_Name: StateIdleMsgProc
// description	: Process of message while in STATE_IDLE
// argument		:
// return		:
// flag			:
// global		:
//=============================================================================
*/
static LONG StateIdleMsgProc(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_SET_DESC:					/* Request of setting Descriptor of USB */
			ReqUsbdSetDesc(pMsg);
			break;
		case MSG_REQ_USBD_REQUEST_NTFY_PARAM:		/* Request of setting notification for request receiving */
			ReqUsbdRequestNtfyParam(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: StateWaitConnectMsgProc
// description	: Process of message while in STATE_WAIT_CONNECT
// argument		:
// return		:
// flag			:
// global		:
//=============================================================================
*/
static LONG StateWaitConnectMsgProc(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_SET_DESC:					/* Request of setting Descriptor of USB */
			ReqUsbdSetDesc(pMsg);
			break;
		case MSG_REQ_USBD_REQUEST_NTFY_PARAM:		/* Request of setting notification for request receiving */
			ReqUsbdRequestNtfyParam(pMsg);
			break;
		case MSG_NTFY_USBD_WAKEUP:					/* Request of Wakeup */
			NtfyUsbdWakeup(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: StateWaitAttachMsgProc
// description	: Process of message while in state of Attach waiting
// argument		:
// return		:
// flag			:
// global		:
//=============================================================================
*/
static LONG StateWaitAttachMsgProc(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_SET_DESC:					/* Request of setting Descriptor of USB */
			ReqUsbdSetDesc(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;
		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: StateWaitDetachMsgProc
// description	: Process of message while in state of Detach waiting
// argument		:
// return		:
// flag			:
// global		:
//=============================================================================
*/
static LONG StateWaitDetachMsgProc(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_NTFY_USBD_WAKEUP:					/* Notification of completion for process of Wakeup */
			NtfyUsbdWakeup(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;
		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: StateNotConfigMsgProc
// description	: Process of message while in invalid state of Storage Class
// argument		:
// return		:
// flag			:
// global		:
//=============================================================================
*/
static LONG StateNotConfigMsgProc(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;
		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: StateStrgConfigMsgProc
// description	: Process of message while in valid state of Storage Class
// argument		:
// return		:
// flag			:
// global		:
//=============================================================================
*/
static LONG StateStrgConfigMsgProc(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_REQ_USBD_REQUEST_XFER_START:		/* Request of transferring request data */
			ReqUsbdRequestXferStart(pMsg);
			break;
		case MSG_REQ_USBD_REQUEST_END:				/* Request of completing process of request */
			ReqUsbdRequestEnd(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: StateStrgMainMsgProc
// description	: Main of valid state of Storage Class
// argument		:
// return		:
// flag			:
// global		:
//=============================================================================
*/
static LONG StateStrgMainMsgProc(PMSGUSBD pMsg)
{

	LONG retValue,tempRet;
	ULONG dwStorEvent;

	retValue = STATUS_SUCCESS;

	if (!(UsbdTaskInfo.state == STATE_NC_SUSPEND || UsbdTaskInfo.state == STATE_SC_SUSPEND || UsbdTaskInfo.state == STATE_WAIT_DETACH)) {
		/* When it is not a state of USB Suspend */

		switch (UsbdStrgInfo.state) {
			case STATE_STRG_NONE:								/* No action */
				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_WAIT_CMD:					/* Waiting command */
				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_WAIT_REQ:					/* Waiting request */
				if (pMsg->msgHead.msgNo == MSG_REQ_USBD_STRG_XFER_START) {
					/* Request of transferring Storage data */
					tempRet = ReqUsbdStrgXferStart(pMsg);
					if (tempRet == STATUS_SUCCESS) {
						UsbdStrgInfo.state = STATE_STRG_DATAXFER;
					}
				} 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_CMD_END) {

⌨️ 快捷键说明

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