📄 devicetask.c
字号:
{
DEVICEInfo.pfnMsgProc( msg, param0, pParam1 );
}
}
/*
//=============================================================================
// Function_Name: CreDataBus
// description : Create MPF in specified size
// argument : USHORT size Size of data to create
// : void* buf Address of the data created
// return : OS_ID The MPFID abtained.
//=============================================================================
*/
Inline OS_ID CreDataBus ( USHORT size, void** pBuf )
{
OS_ID mpfID = 0;
if( size <= MPF_DATA64_SIZE ){ mpfID = MPFID_DEVICE_DATA64; }
else if( size <= MPF_DATA128_SIZE ){ mpfID = MPFID_DEVICE_DATA128; }
else if( size <= MPF_DATA256_SIZE ){ mpfID = MPFID_DEVICE_DATA256; }
else if( size <= MPF_DATA512_SIZE ){ mpfID = MPFID_DEVICE_DATA512; }
else { Panic(); } /* Specify the size that was not able to be acquired. */
OS_GetMpf( mpfID, pBuf );
return mpfID;
}
/*
//=============================================================================
// Function_Name: DEVICETask
// description : DEVICE control task
// argument : none
// return : none
//=============================================================================
*/
void DEVICETask( void )
{
OS_FLGPTN flgPtn;
DEVICE_MSG* pDEVICEMsg;
OS_ER errCode;
// Task initialization
TaskInit();
//========================================================================
// Confirm whether starting the reset of HDD for the IDE task.
// Request to do HDD initialization, when FLG_EVENT_FORCE_DEVICE bit is not 1.
//========================================================================
errCode = OS_PolFlg( FLGID_DEVICE, FLG_EVENT_FORCE_DEVICE, OS_TWF_ORW, &flgPtn );
if( errCode == OS_E_TMOUT )
{
// Start the lower task
ResetLowRankTsk();
}
//========================================================================
// DEVICE Task's main loop
//========================================================================
while( 1 )
{
OS_WaiFlg( FLGID_DEVICE, FLG_WAIT_PTN_DEVICE, OS_TWF_ORW, &flgPtn ); // Waiting for event information
//------------------------------------------------------------------------
// Check the event flag and process according to each flag
//------------------------------------------------------------------------
if ( flgPtn & FLG_EVENT_FORCE_DEVICE )
{
// Force process event
// Clear the synchronous mechanism of task that used in this task.
//========================================================================
ForceCancelEvent(); // Cancel the event
}
else if ( flgPtn & FLG_EVENT_INT_DEVICE )
{
// Interrup process event
//========================================================================
DEVICE_IntEvent(); // Process the interrupt event
OS_ClrFlg( FLGID_DEVICE, ~(FLG_EVENT_INT_DEVICE) );
}
else if ( flgPtn & FLG_EVENT_MSG_DEVICE )
{
// Message process event
//========================================================================
// Receive the message form mailbox
errCode = OS_PRcvMbx( MBXID_DEVICE, ( T_MSG** )&pDEVICEMsg ); // Receive the message form mailbox
if ( errCode == E_OK )
{
// There are messages
MsgEvent( pDEVICEMsg ); // Process the message event
}
else if ( errCode == E_TMOUT )
{
// None message
OS_ClrFlg( FLGID_DEVICE, ~(FLG_EVENT_MSG_DEVICE)); // clear the flag
}
else
{
// Error in receiving message
Panic();
}
}
else if ( flgPtn & FLG_EVENT_START_USB_DEVICE )
{
// Request to start USB operation
//========================================================================
OS_ClrFlg( FLGID_DEVICE, ~(FLG_EVENT_START_USB_DEVICE) );
UsbStrgProc();
}
else if( flgPtn & FLG_EVENT_EXECMD_DEVICE )
{
// Request to start PLAY operation
//========================================================================
OS_ClrFlg( FLGID_DEVICE, ~(FLG_EVENT_EXECMD_DEVICE) );
PlayExecProc();
}
else if ( flgPtn & FLG_EVENT_IDEHRST_DEVICE )
{
// IDE HRST request
//========================================================================
IdeResetRequest();
OS_ClrFlg( FLGID_DEVICE, ~(FLG_EVENT_IDEHRST_DEVICE) );
}
else
{
// Clear the flag when an unsupported event has been received
//========================================================================
OS_ClrFlg( FLGID_DEVICE, ~(FLG_WAIT_PTN_DEVICE) );
}
}
}
/*
//=============================================================================
// Function_Name: TaskInit
// description : Initialization process of DEVICE control task
// argument :
// return :
// flag :
// global :
//=============================================================================
*/
void TaskInit( void )
{
PM_IF_CPU_CONFIG cpuConfig;
// TaskInfo
TaskInfo.forceEvntInfo.bIdeInit = FALSE;
TaskInfo.forceEvntInfo.bUsbInit = FALSE;
TaskInfo.ideTaskInfo.bHddRstCmp = FALSE;
TaskInfo.ideTaskInfo.bSuspend = FALSE;
TaskInfo.ideTaskInfo.deviceCnt = 0;
//=======================================================================*/
/* In the ARM7 CPU38000 made by EPSON, the IRQ is not output to an external terminal(there is FIQ) */
/* In NORTiOS, because the handler from FIQ interrupt is beyond the support, */
/* the xINT from DEVICE is inputed to GPIO and the GPIO interrupt of CPU38000 is chosen as DEVICEINT. */
//=======================================================================*/
OS_LocCpu();
// def_inh( DEVICE_CHIP_INT, &dinh_handler1 );
rlMX21_PTA_DDIR &= ~0x00800000; /* PTA23 is Input Port */
rlMX21_PTA_ICONFA2 &= ~0x0000C000;
rlMX21_PTA_ICONFB2 &= ~0x0000C000;
rlMX21_PTA_GUIS |= 0x00800000; /* PTA23 is Use in GPIO */
rlMX21_PTA_ICR2 |= 0x0000C000; /* PTA23 Interrupt is Low Level */
rlMX21_PTA_ISR |= 0x00800000; /* PTA23 Interrupt Clear */
rlMX21_PTA_IMR |= 0x00800000; /* PTA23 Mask Off! */
ena_int( DEVICE_CHIP_INT );
OS_UnlCpu();
//========================================================================
// Setting of PM reset and DEVICECPU bus
//========================================================================
cpuConfig.clkSel = PM_IF_CLK24; // CLK is 24MHz
cpuConfig.IntLevel = PM_IF_LOW_ACT; // xINT Active low
cpuConfig.IntMode = PM_IF_1_0_MODE; // 1/0 Mode
cpuConfig.DREQ_Level = PM_IF_LOW_ACT; // DREQ Active low
cpuConfig.DACK_Level = PM_IF_LOW_ACT; // DACK Active low
// cpuConfig.CS_Mode = PM_IF_DACK_MODE; // DACK mode
cpuConfig.CS_Mode = 1; // DACK mode
// For Big Endian
#ifdef LITTLE_ENDIAN_C
cpuConfig.CPU_Swap = PM_IF_CPU_SWAP_ON; // Swap on
#else
cpuConfig.CPU_Swap = PM_IF_CPU_SWAP_OFF; // Swap off
#endif
cpuConfig.BusMode = PM_IF_XBE_MODE; // XBE Mode
cpuConfig.Bus8x16 = PM_IF_BUS16; // Bus 8x16
PM_IFReset( &cpuConfig );
// Change the power mode
PM_IFSetWakeupTim( WAKEUP_TIME );
// When starting, operate with ACTIVE 60.
// Operate with ACTIVE HOST
PM_IFSetPMState( PM_IF_PMSTATE_ACT_DEVICE ); // When starting, operate with ACTIVE DEVICE.
RegSet(REG08_H_XcvrControl,BIT_RemoveRPD);
// Reset FIFO
FIFO_IFReset();
// Reset CPU DMA
CPUDMA_IFReset();
//========================================================================
// Register Call Back
//========================================================================
// CPU
CPUDMA_IFRegisterCBRDMA0_Cmp( DMA0CmpEvent ); // DMA0 completion notification
CPUDMA_IFRegisterCBRDMA1_Cmp( DMA1CmpEvent ); // DMA1completion notification
// FIFO
FIFO_IFRegisterCBRFifoIDECmp( FIFOIdeCmpEvent ); // FIFO IDE Cmp
FIFO_IFRegisterCBRFifo1Cmp( FIFO1CmpEvent ); // FIFO0 Cmp
FIFO_IFRegisterCBRFifo0Cmp( FIFO0CmpEvent ); // FIFO1 Cmp
FIFO_IFRegisterCBRFifoEmpty( FIFOEmptyEvent ); // FIFO Empty
FIFO_IFRegisterCBRFifoFull( FIFOFullEvent ); // FIFO Full
// Media FIFO
FIFO_IFRegisterCBRMediaIDECmp( MediaIdeCmpEvent ); // FIFO IDE Cmp
FIFO_IFRegisterCBRMediaEmpty( MediaEmptyEvent ); // FIFO Empty
FIFO_IFRegisterCBRMediaFull( MediaFullEvent ); // FIFO Full
//========================================================================
// Start the lower task.
//========================================================================
OS_ActTsk( TSKID_USBD ); // Start the USBD Task
OS_ActTsk( TSKID_IDE ); // Start IDE Task
#ifdef DEBUG_C
IDEResetCount = 0; // The number of IDE device resetted
USBResetCount = 0; // Number of times that USB Reset is generated
EP0InErrorCount = 0; // Number of times that packet error occured in EP0 IN
EP0OutErrorCount = 0; // Number of times that packet error occured in EP0 OUT
BulkInErrorCount = 0; // Number of times that packet error occured in Bulk IN
BulkOutErrorCount = 0; // Number of times that packet error occured in Bulk OUT
CBWErrorCount = 0; // Number of times that packet error occured when receive CBW
CSWErrorCount = 0; // Number of times that packet error occured when receive CSW
DBG_WatchSetData("IDEResetCount",4,(UCHAR *)&IDEResetCount);
DBG_WatchSetData("USBResetCount",4,(UCHAR *)&USBResetCount);
DBG_WatchSetData("EP0InErrorCount",4,(UCHAR *)&EP0InErrorCount);
DBG_WatchSetData("EP0OutErrorCount",4,(UCHAR *)&EP0OutErrorCount);
DBG_WatchSetData("BulkInErrorCount",4,(UCHAR *)&BulkInErrorCount);
DBG_WatchSetData("BulkOutErrorCount",4,(UCHAR *)&BulkOutErrorCount);
DBG_WatchSetData("CBWErrorCount",4,(UCHAR *)&CBWErrorCount);
DBG_WatchSetData("CSWErrorCount",4,(UCHAR *)&CSWErrorCount);
#endif
return;
}
/*
//=============================================================================
// Function_Name: ForceCancelEvent
// description : Process for Event Cancel
// argument : void
// return : void
// flag :
// global :
//=============================================================================
*/
void ForceCancelEvent ( void )
{
// Clear all the event of the device
DEVICEMailDataCancel(); // Destruct the message data
OS_ClrFlg( FLGID_DEVICE, ~(FLG_EVENT_FORCE_DEVICE)); // Clear the flag
// Set the request to clear the events in the USBD/IDE task
OS_SetFlg( FLGID_IDE, FLG_EVENT_FORCE_DEVICE ); // IDE Task
OS_SetFlg( FLGID_USBD, FLG_EVENT_FORCE_DEVICE ); // USB Task's force process request
return;
}
/*
//=============================================================================
// Function_Name: DEVICE_IntEvent
// description : Process the interrupt event
// argument : none
// return : none
//=============================================================================
*/
void DEVICE_IntEvent( void )
{
//========================================================================
// Check the device status
//========================================================================
switch( DEVICEInfo.state )
{
case DEVICE_TASK_STATE_NON_EXISTENT:
/* It does not run to here */
break;
case DEVICE_TASK_STATE_STOP:
/* Do not break */
case DEVICE_TASK_STATE_MODULE_INIT:
/* Do not break */
case DEVICE_TASK_STATE_DEV_INIT:
/* Do not break */
case DEVICE_TASK_STATE_WAIT_EVENT:
/* Do not break */
case DEVICE_TASK_STATE_SLEEP_A:
/* Do not break */
case DEVICE_TASK_STATE_PLAY_CMD_EXEC:
/* Do not break */
case DEVICE_TASK_STATE_PLAY_DMA_XFER:
/* Do not break */
case DEVICE_TASK_STATE_PLAY_DMA_ABORT:
/* Do not break */
case DEVICE_TASK_STATE_USB_NON_CONNECT:
/* Do not break */
case DEVICE_TASK_STATE_USB_STORAGE:
/* Do not break */
case DEVICE_TASK_STATE_USB_SUSPEND:
/* Do not break */
case DEVICE_TASK_STATE_MODULE_ACC:
/* Do not break */
case DEVICE_TASK_STATE_USB_WAIT_STOP:
/* Do not break */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -