📄 usbdtask.c
字号:
/*----------------------------------------------------------------------*/
/* 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: NtfyUsbdResetCallback
// description : The callback which is called while in USB Reset
// argument :
// return :
// flag :
// global :
//=============================================================================
*/
LONG NtfyUsbdResetCallback(ULONG lParam0,ULONG lParam1,VOID *pParam)
{
LONG retTemp;
PMSGUSBD msg;
USBD_IF_USB_STATE usbState;
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_RESET; /* Notification of USB Reset */
msg->msgHead.msgLength = sizeof (PARAM_MSG_NTFY_USBD_RESET);
#ifdef DEBUG_C
USBResetCount++;
#endif
/* Get operation mode */
USBD_IFGetState(&usbState);
if (usbState.Speed == USBD_IF_SPEEDMODE_HS) {
#ifdef DEBUG_C
LED_Off(6);
LED_On(5);
#endif
((PARAM_MSG_NTFY_USBD_RESET *)msg->msgData)->speedStatus = USBD_HS_MODE;
} else if (usbState.Speed == USBD_IF_SPEEDMODE_FS) {
((PARAM_MSG_NTFY_USBD_RESET *)msg->msgData)->speedStatus = USBD_FS_MODE;
#ifdef DEBUG_C
LED_On(6);
LED_Off(5);
#endif
} else {
/* It doesn't come here */
}
UsbdTaskInfo.state = STATE_NOT_CONFIG;
if (UsbdStrgInfo.initStrg == 0) {
/* When Storage Class has not been initialized */
UsbdStrgInfo.initStrg = 1;
USBD_ProtStorageReset(); /* USBD Storage Class */
/* Callback of Storage event */
retTemp = USBD_ProtStorageRegisterCBRStorageEvent(StorageEventCallback);
if (retTemp != STATUS_SUCCESS) {
((PARAM_MSG_NTFY_USBD_PULLUP_CTRL *)msg->msgData)->result = USBD_REQ_NG;
}
retTemp = USBD_ProtStorageRegisterCBRStorageXferEvent(StorageXferEventCallback);
if (retTemp != STATUS_SUCCESS) {
((PARAM_MSG_NTFY_USBD_PULLUP_CTRL *)msg->msgData)->result = USBD_REQ_NG;
}
}
/* Stop Storage Class */
USBD_ProtStorageSetState(USBD_PROT_STORAGE_STOP_STATE);
/*----------------------------------------------------------------------*/
/* 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: NtfyUsbdResumeCallback
// description : The callback which is called when USB Resume has occurred
// argument :
// return :
// flag :
// global :
//=============================================================================
*/
LONG NtfyUsbdResumeCallback(ULONG lParam0,ULONG lParam1,VOID *pParam)
{
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_RESUME; /* Notification of USB Resume */
msg->msgHead.msgLength = 0;
#ifdef DISUSBDREQWAKEUP
/*
* Do following process only when USBD Task has not sent out request of ReqUsbdWakeup
*
*/
if (UsbdTaskInfo.state == STATE_NC_SUSPEND) {
UsbdTaskInfo.state = STATE_NOT_CONFIG;
} else if (UsbdTaskInfo.state == STATE_SC_SUSPEND) {
UsbdTaskInfo.state = STATE_STRG_CONFIG;
} else {
while (1)
;/* It doesn't come here */
}
#endif
/*----------------------------------------------------------------------*/
/* 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:
// description :
// argument :
// return :
// flag :
// global :
//=============================================================================
*/
static LONG ReqUsbdRequestNtfyParam(PMSGUSBD pMsg)
{
/* Not implemented */
return STATUS_SUCCESS;
}
/*
//=============================================================================
// Function_Name:
// description :
// argument :
// return :
// flag :
// global :
//=============================================================================
*/
static LONG ReqUsbdRequestXferStart(PMSGUSBD pMsg)
{
/* Not implemented */
return STATUS_SUCCESS;
}
/*
//=============================================================================
// Function_Name:
// description :
// argument :
// return :
// flag :
// global :
//=============================================================================
*/
static LONG ReqUsbdRequestEnd(PMSGUSBD pMsg)
{
/* Not implemented */
return STATUS_SUCCESS;
}
/*
//=============================================================================
// Function_Name: ReqUsbdStrgSetLUN
// description : Request of setting maxLUN
// argument :
// return :
// flag :
// global :
//=============================================================================
*/
static LONG ReqUsbdStrgSetLUN(PMSGUSBD pMsg)
{
LONG retValue,tempRet;
ULONG maxLUN;
USBD_PROT_STORAGE_PARAM_MAXLUN param;
PMSGUSBD msg;
retValue = USBD_REQ_OK;
maxLUN = ((PARAM_MSG_REQ_USBD_STRG_SET_LUN *)pMsg->msgData)->maxLUN;
param.bLength = 4;
param.bType = USBD_PROT_STORAGE_TYPE_MAXLUN;
param.bMaxLUN = maxLUN;
tempRet = USBD_ProtStorageSetParameter(¶m);
if (tempRet != STATUS_SUCCESS) {
retValue = USBD_PARAM_ERR;
} else {
UsbdStrgInfo.maxLUN = maxLUN;
if (UsbdStrgInfo.reqGetMaxLUN == 1) {
/* Do process for request, when there is a request of processing SetMaxLUN request */
UsbdStrgInfo.reqGetMaxLUN = 0;
USBD_ProtStorageRequestSuccess();
}
}
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_STRG_SET_LUN; /* Notification of completion for setting of number of connecting devices */
msg->msgHead.msgLength = sizeof (PARAM_MSG_NTFY_USBD_STRG_SET_LUN); /* Size of data */
((PARAM_MSG_NTFY_USBD_STRG_SET_LUN *)msg->msgData)->result = retValue;
/*----------------------------------------------------------------------*/
/* Transmission of message and notification of event when error occurred */
/*----------------------------------------------------------------------*/
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: StorageEventCallback
// description : Callback of Storage Class event
// argument :
// return :
// flag :
// global :
//=============================================================================
*/
LONG StorageEventCallback(ULONG lEvent,ULONG lParam1,VOID *pParam)
{
switch (lEvent) {
case USBD_PROT_STORAGE_ACTIVECHANGE_EVENT: /* Storage Class Enable/Disable */
/* Notify state of Enable/Disable of Storage Class */
NtfyUsbdStrgActiveChange(lParam1);
if (lParam1 == USBD_PROT_STORAGE_ACTIVE) {
/* Start operation of Storage Class, when it is enabled */
USBD_ProtStorageSetState(USBD_PROT_STORAGE_START_STATE);
UsbdTaskInfo.state = STATE_STRG_CONFIG;
UsbdStrgInfo.state = STATE_STRG_WAIT_CMD;
} else {
/* Stop operation of Storage Class, when it is disabled */
USBD_ProtStorageSetState(USBD_PROT_STORAGE_STOP_STATE);
UsbdTaskInfo.state = STATE_NOT_CONFIG;
UsbdStrgInfo.state = STATE_STRG_NONE;
}
break;
case USBD_PROT_STORAGE_BULKONLYRESET_EVENT: /* BulkOnlyReset */
ReqUsbdStrgReset();
break;
case USBD_PROT_STORAGE_GETMAXLUN_EVENT: /* GetMaxLUN */
if (UsbdStrgInfo.maxLUN == 0xFF) {
/* When MaxLUN has not been set */
UsbdStrgInfo.reqGetMaxLUN = 1;
} else {
/* Do process for request of GetMaxLUN, when MaxLUN has been set */
USBD_ProtStorageRequestSuccess();
}
break;
case USBD_PROT_STORAGE_COMMAND_RCVED_EVENT: /* Command Rcved */
NtfyUsbdStrgCmd();
break;
case USBD_PROT_STORAGE_COMMANDSTATUS_SENT_EVENT: /* Status Sent */
NtfyUsbdStrgCmdEnd();
UsbdStrgInfo.state = STATE_STRG_WAIT_CMD;
break;
default:
/* ??? */
break;
}
return STATUS_SUCCESS;
}
/*
//=============================================================================
// Function_Name: NtfyUsbdStrgActiveChange
// description : Called when state of Enable/Disable of Storage Class has been changed
// argument :
// return :
// flag :
// global :
//=============================================================================
*/
static LONG NtfyUsbdStrgActiveChange(ULONG lActiveFlag)
{
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_STRG_ACTIVE_CHANGE; /* Notification of Enable/Disable of Storage Class */
msg->msgHead.msgLength = sizeof (PARAM_MSG_NTFY_USBD_STRG_ACTIVE_CHANGE); /* Size of data */
if (lActiveFlag == USBD_PROT_STORAGE_ACTIVE) {
((PARAM_MSG_NTFY_USBD_STRG_ACTIVE_CHANGE *)msg->msgData)->activeStatus = USBD_STORAGE_ACTIVE;
} else {
((PARAM_MSG_NTFY_USBD_STRG_ACTIVE_CHANGE *)msg->msgData)->activeStatus = USBD_STORAGE_INACTIVE;
}
/*----------------------------------------------------------------------*/
/* 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: ReqUsbdStrgReset
// description : Send out request to other task while receiving BulkOnly Mass Storage Reset
// argument :
// return :
// flag :
// global :
//=============================================================================
*/
static LONG ReqUsbdStrgReset(void)
{
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_REQ_USBD_STRG_RESET; /* Request of Storage Reset */
msg->msgHead.msgLength = 0; /* Size of data */
/*----------------------------------------------------------------------*/
/* 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 */
UsbdStrgInfo.reqStrgReset = 1;
return STATUS_SUCCESS;
}
/*
//=============================================================================
// Function_Name: NtfyUsbdStrgReset
// description : Notify result of BulkOnly Mass Storage Reset
// argument :
// return :
// flag :
// global :
//=============================================================================
*/
static LONG NtfyUsbdStrgReset(PMSGUSBD pMsg)
{
LONG retValue;
ULONG result;
retValue = STATUS_UNSUCCESSFUL;
if (UsbdStrgInfo.reqStrgReset == 1) {
/* When request of Mass Storage Reset has been sent out from USBD Task */
UsbdStrgInfo.reqStrgReset = 0;
result = ((PARAM_MSG_NTFY_USBD_STRG_RESET *)pMsg->msgData)->result;
if (result == USBD_REQ_OK) {
retValue = USBD_ProtStorageSetState(USBD_PROT_STORAGE_RESET_STATE);
retValue = USBD_ProtStorageRequestSuccess();
} else {
retValue = USBD_ProtStorageRequestFail();
}
}
return retValue;
}
/*
//===============================================================
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -