📄 devicetask.c
字号:
// Descriptor setting completed
TaskInfo.usbTaskInfo.bSetDesc = TRUE;
// Send the request of enabling USB VBUS detection
vbus.detectFlag = USBD_VBUS_ENABLE;
SendMessage( MBXID_USBD, MSG_REQ_USBD_DETECT_VBUS, sizeof(vbus), &vbus );
}
else
{
// Mistake in the format of descriptor!
Panic();
}
break;
default:
// Ignore it
break;
}
}
else if( pMsg->msgHead.msgSndTskId == TSKID_IDE )
{
//------------------------------------------------------------------------
// Message process for IDE Task
//------------------------------------------------------------------------
switch( pMsg->msgHead.msgNo )
{
case MSG_NTFY_IDE_HRST: // Completion notification of hardware reset of connected device
MsgIdeHRSTCmp( pMsg ); // Completion process of HRST
DEVICEInfo.state = DEVICE_TASK_STATE_WAIT_EVENT; // Change to the event waiting state
break;
default:
// Ignore it
break;
}
}
return;
}
/*
//=============================================================================
// Function_Name: StateWaitEventMsgProc
// description : Message processing for event waiting state
// argument : DEVICE_MSG* pMsg Message receiving
// return : none
//=============================================================================
*/
void StateWaitEventMsgProc ( DEVICE_MSG* pMsg )
{
//========================================================================
// Judge the transfer destination of mailbox, process each mail
//========================================================================
if( pMsg->msgHead.msgSndTskId == TSKID_USBD )
{
PARAM_MSG_REQ_USBD_DETECT_VBUS vbus;
//------------------------------------------------------------------------
// Process message from USBD Task
//------------------------------------------------------------------------
switch( pMsg->msgHead.msgNo )
{
case MSG_NTFY_USBD_DETECT_VBUS: // Completion notification of MSG_REQ_USBD_DETECT_VBUS requirement
// Status judgment
//==================================
if( ((PARAM_MSG_NTFY_USBD_DETECT_VBUS *)pMsg->msgData)->result != USBD_REQ_OK )
{
// The VBUS detection requirement is sent again
vbus.detectFlag = USBD_VBUS_ENABLE;
SendMessage( MBXID_USBD, MSG_REQ_USBD_DETECT_VBUS, sizeof(vbus), &vbus );
}
break;
case MSG_NTFY_USBD_VBUS_STATUS: // Change notification for state of VBUS
// VBUS state judgment
//==================================
MsgUsbVBusChanged( pMsg );
if( DEVICEInfo.usbInfo.vbus == DEVICE_TASK_USB_VBUS_HIGH && DEVICEInfo.usbInfo.bEnable == TRUE && DEVICEInfo.usbInfo.bManAttach == FALSE )
{
// Request of USB connect
DEVICEInfo.state = DEVICE_TASK_STATE_USB_NON_CONNECT; // Change to USB unconnect state
OS_SetFlg( FLGID_DEVICE, FLG_EVENT_START_USB_DEVICE ); // Set flag for the task
}
break;
case MSG_NTFY_USBD_SET_DESC_CMP: // Completion notification of Descriptor setting
// A result of Descriptor setting is confirmed
//==================================
if( ((PARAM_MSG_NTFY_USBD_SET_DESC_CMP *)pMsg->msgData)->result == USBD_REQ_OK )
{
PARAM_MSG_REQ_USBD_DETECT_VBUS vbus;
// The VBUS detection requirement is issued
TaskInfo.usbTaskInfo.bSetDesc = TRUE; // Descriptor setting completed
vbus.detectFlag = USBD_VBUS_ENABLE; // Change of VBUS state
SendMessage( MBXID_USBD, MSG_REQ_USBD_DETECT_VBUS, sizeof(vbus), &vbus ); // Send the request of enabling USB VBUS detection
}
else
{
// Mistake in the format of descriptor!
Panic();
}
break;
default:
// Ignore it
break;
}
}
return;
}
/*
//=============================================================================
// Function_Name: StateSleepAMsgProc
// description : Message processing for SLEEP_A state
// argument : DEVICE_MSG* pMsg Message receiving
// return : none
//=============================================================================
*/
void StateSleepAMsgProc ( DEVICE_MSG* pMsg )
{
//========================================================================
//
//In the command running state, there is no message to process
//Return error if message has come
//========================================================================
ErrMessageProc( pMsg );
}
/*
//=============================================================================
// Function_Name: StatePlayCmdExecMsgProc
// description : Message processing for command running state
// argument : DEVICE_MSG* pMsg Message receiving
// return : none
//=============================================================================
*/
void StatePlayCmdExecMsgProc ( DEVICE_MSG* pMsg )
{
//========================================================================
//
//In the command running state, it doesn't come to this function
//Return error if coming
//========================================================================
ErrMessageProc( pMsg );
}
/*
//=============================================================================
/ Function_Name: StatePlayDmaXferMsgProc
// description : Message processing for DMA transfer state
// argument : DEVICE_MSG* pMsg Message receiving
// return : none
//=============================================================================
*/
void StatePlayDmaXferMsgProc ( DEVICE_MSG* pMsg )
{
//========================================================================
//
//In the state of the DMA transfer, it doesn't come to this function
//Return error if coming
//========================================================================
ErrMessageProc( pMsg );
}
/*
//=============================================================================
// Function_Name: StateUsbNonConnectMsgProc
// description : Message processing for USB disconnection state
// argument : DEVICE_MSG* pMsg Message receiving
// return : none
//=============================================================================
*/
void StateUsbNonConnectMsgProc ( DEVICE_MSG* pMsg )
{
//========================================================================
//
//In the state of USB disconnection, it doesn't come to this function
//Return error if coming
//========================================================================
ErrMessageProc( pMsg );
}
/*
//=============================================================================
// Function_Name: StateUsbStorageMsgProc
// description : Message processing for Storage state
// argument : DEVICE_MSG* pMsg Message receiving
// return : none
//=============================================================================
*/
void StateUsbStorageMsgProc( DEVICE_MSG* pMsg )
{
//========================================================================
//
//In the state of storage, it doesn't come to this function.
//Return error if coming
//========================================================================
ErrMessageProc( pMsg );
}
/*
//=============================================================================
// Function_Name: StateUsbSleepBMsgProc
// description : Message processing for Storage suspend state
// argument : DEVICE_MSG* pMsg Message receiving
// return : none
//=============================================================================
*/
void StateUsbSleepBMsgProc ( DEVICE_MSG* pMsg )
{
//========================================================================
//
//In the state of the storage sleep, it doesn't come to this function
//Return error if coming
//========================================================================
ErrMessageProc( pMsg );
}
/*
//=============================================================================
// Function_Name: StateModuleAccMsgProc
// description : Message processing for other module access state
// argument : DEVICE_MSG* pMsg Message receiving
// return : none
//=============================================================================
*/
void StateModuleAccMsgProc ( DEVICE_MSG* pMsg )
{
//========================================================================
//
//In the state of other module access, it doesn't come to this function
//Return error if coming
//========================================================================
ErrMessageProc( pMsg );
}
/*
//=============================================================================
// Function_Name: PlayExecProc
// description : Main processing of Play operation
// argument : none
// return : none
//=============================================================================
*/
void PlayExecProc( void )
{
UCHAR epMediaJoinFifo;
UCHAR intEvent;
//========================================================================
// Shelter state of FIFO
//========================================================================
FIFO_IFGetIntEventMedia( &intEvent ); // Get event which has been set
FIFO_IFSetIntEvent( intEvent, FIFO_IF_EVENTOFF ); // Stop event which has been set
FIFO_IFGetFIFO_Join( FIFO_IF_NUM_FIFO_MEDIA, &epMediaJoinFifo ); // Shelter MediaJoin state
//========================================================================
// Start Play operation
//========================================================================
PlayModeInit(); // Initialization is done, to operate Play Mode
PlaySendCmd(); // Transfer command to IDE task
PlayCmdResultWait(); // Wait for result of command
//========================================================================
// FIFO is returned to the state before the specification
//========================================================================
FIFO_IFSetIntEvent( intEvent, FIFO_IF_EVENTON ); // Return the set event
FIFO_IFSetFIFO_Join( FIFO_IF_NUM_FIFO_MEDIA, epMediaJoinFifo, FIFO_IF_EVENTON ); // Return EPaJoin state
// 2005/4/6 Nagashima Modify for state transition when other module is accessed
// DEVICEInfo.state = DEVICE_TASK_STATE_WAIT_EVENT;
if( StrgInfo.target == EXEC_USER ){
DEVICEInfo.state = DEVICE_TASK_STATE_MODULE_ACC;
}
else{
DEVICEInfo.state = DEVICE_TASK_STATE_WAIT_EVENT;
}
//========================================================================
// If the PLAY operation mode is synchronous mode, free the semaphore
//========================================================================
if( DEVICEInfo.playInfo.execMode == DEVICE_TASK_PLAY_CMD_SYNC_MODE )
{
//========================================================================
// DEVICE is returned to the event waiting state
//========================================================================
OS_SigSem( SEMID_DEVICE ); // Release the semaphore resource
}
else
{
//=============================================================
// CallBack Completion notification for IDE command
//-------------------------------------------------------------
// Message : DEVICE_TASK_MSG_PLAY_IDE_CMD_CMP
// Param0 : Command status
// pParam : NULL
//=============================================================
SendCallback( DEVICE_TASK_MSG_PLAY_IDE_CMD_CMP, DEVICEInfo.playInfo.cmdStatus, NULL );
}
return;
}
/*
//=============================================================================
// Function_Name: PlayModeInit
// description : Initialization of Play mode operation
// argument : none
// return : none
//=============================================================================
*/
void PlayModeInit ( void )
{
PLAY_INFO *pPlayInfo;
pPlayInfo = &DEVICEInfo.playInfo;
// Initialization of variable
pPlayInfo->xferInfo.fifoRWSize = 0x00; // Times written in FIFO
pPlayInfo->bCpuXferCmp = FALSE; // Flag for CPU transfer completion
pPlayInfo->bIdeCmdCmp = FALSE; // Flag for IDE transfer completion
CpuDmaIntEnb = 0x00;
// Disable the FIFO interrupt
FIFO_IFSetIntEvent( FIFO_IF_MEDIA_IDE_CMP, FIFO_IF_EVENTOFF ); // FIFO IDE Comp
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -