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

📄 idetask.c

📁 epson usb2.0 控制芯片 S1R72V05 固件程序。
💻 C
📖 第 1 页 / 共 5 页
字号:
//=============================================================================
*/
LONG IDETaskInit( void )
{

	/*----------------------------------------------------------------------*/
	/* Initial setting of S1R72V0X LSI									*/
	/*----------------------------------------------------------------------*/
	IDE_FuncOpen();

	/*----------------------------------------------------------------------*/
	/* Initialize internal information of task							*/
	/*----------------------------------------------------------------------*/
	IdeTsk_Inf.mState = IDE_MSTS_INIT;	/* IDE TASK main state			*/
	IdeTsk_Inf.sState = IDE_SSTS_IDLE;	/* IDE TASK sub state			*/
	memset( &IdeTsk_CmdPara, 0, sizeof(IdeTsk_CmdPara) );
	memset( IdeTsk_CmdError, 0, sizeof(IdeTsk_CmdError) );

	memset( &IdeXferPara, 0, sizeof(IdeXferPara) );

	DIRECT_B(IDEIntStatus) = 0;

	memset( &IdeCmdPara, 0, sizeof(IdeCmdPara) );

	DeviceList.deviceCount = 0;			/* Reset the number of connected devices */
	memset( &DeviceList.deviceType, 0xff, sizeof(DeviceList.deviceType) );
	memset( &DeviceList.identify, 0, sizeof(DeviceList.identify) );

	memset( &IdeTranPara, 0, sizeof(IdeTranPara) );

	DeviceID = 0;						/* IDE Func Access Id (fixed to 0)	*/
	DeviceNo = 0;						/* IDE Device No 					*/
	IDEStatus = 0;
	DeviceType = 0;
	transferSize = 0;
	memset( senseData, 0, sizeof(senseData) );

	UnitFlag[0].aten = 1;				/* Unit attention state			*/
	UnitFlag[1].aten = 1;

	return STATUS_SUCCESS;
}

/*
//=============================================================================
// Function_Name: IDEMailDataCancel
// description	: Destruct the data in IDE mail box
// argument		:
// return		:
// flag			:
// global		:
//=============================================================================
*/
LONG IDEMailDataCancel( void )
{
VP		pk_msg;
int		mpfid,ercd;

	do {
										/* Receive message from mail box */
		ercd = OS_PRcvMbx( MBXID_IDE, ( T_MSG** )&pk_msg );
		if ( ercd == E_OK )
		{
										/* Destrut the data if there is message */
			mpfid = ( (PMSGIDE)pk_msg )->msgHead.useMpfId;
			OS_RelMpf( mpfid, pk_msg );	/* Free message buffer 		*/
		}
	} while( ercd == E_OK );

	return STATUS_SUCCESS;
}

/*
//=============================================================================
// Function_Name: IDE_ForceEvent
// description	: Process the Force Event
// argument		:
// return		:
// flag			:
// global		:
//=============================================================================
*/
static LONG IDE_ForceEvent( void )
{
UCHAR	i;

	switch( IdeTsk_Inf.mState )
	{
		case IDE_MSTS_INIT:				/* Initial state 				*/
		case IDE_MSTS_RESET:			/* Reset state 					*/
		case IDE_MSTS_IDLE:				/* Idle state					*/
			break;

		case IDE_MSTS_CMDEXEC:			/* Executing Command state 		*/
			/* Fix for a problem that command is not accepted if plug in and out while copying data. */

			/* Modify to fix the bug that if plugged out when copying data, can not receive command after that */
			/* If it is in command executing state,do hard reset  */
			IDE_FuncReset();
			/* It confirms that the maximum time interval is 30 seconds until the device becomes to idle.*/
			StatusWait();
			/* Get Device List											*/
			IDE_FuncGetDeviceList( DeviceID, &DeviceList );

			for( i = 0; i < DeviceList.deviceCount; i++ ){
				/* Check if the connected device is HDD  */
				if( DeviceList.deviceType[i] == IDE_FUNC_HDD ){
					ReadSectorSize[i] = 0x200;
					WriteSectorSize[i] = 0x200;
				}
				else{
				/* Check if the connected device is CD or MO */
					ReadSectorSize[i] = 0x0;
					WriteSectorSize[i] = 0x0;
				}
			}

			if( DeviceList.deviceCount == 0 ){
				ATA_IFIdeTerm( ATA_IF_TERM_OFF );
			}
			else{
				ATA_IFIdeTerm( ATA_IF_TERM_ON );
			}

			StatusChange( IDE_MSTS_IDLE );	/* Idle state 					*/
			break;
		default:
										/* There is no processing currently */
			break;
	}

	/*----------------------------------------------------------------------*/
	/* Generate the message and send the message						*/
	/*----------------------------------------------------------------------*/
										/* Send message					*/

	if( RegRead( REG08_HostDeviceSel ) & BIT_HOSTxDEVICE_HOST ){
		SendMessage( MBXID_USBH_SAMPLE, MSG_NTFY_IDE_FORCE_CMP, 0, NULL );
	} else {
		SendMessage( MBXID_DEVICE, MSG_NTFY_IDE_FORCE_CMP, 0, NULL );
	}
	/*----------------------------------------------------------------------*/

	return STATUS_SUCCESS;
}

/*
//=============================================================================
// Function_Name: IDE_IntEvent
// description	: Process interrupt event
// argument		:
// return		:
// flag			:
// global		:
//=============================================================================
*/
static LONG IDE_IntEvent( void )
{

	switch( IdeTsk_Inf.mState )
	{
		case IDE_MSTS_INIT:				/* Initial state 				*/
		case IDE_MSTS_RESET:			/* Reset state 					*/
		case IDE_MSTS_IDLE:				/* Idle state					*/
			break;

		case IDE_MSTS_CMDEXEC:			/* Executing Command state		*/
			IDE_CmdExecSts_IntProc();
			break;

		default:						/* It cannot run here because it is an internal state.	*/
			break;
	}

	return STATUS_SUCCESS;
}

/*
//=============================================================================
// Function_Name: IDE_CmdExecSts_IntProc
// description	:
// argument		:
// return		:
// flag			:
// global		:
//=============================================================================
*/
static LONG IDE_CmdExecSts_IntProc( void )
{
UCHAR	intStatus;


	intStatus = 0;

	OS_LocCpu();						/* Diable the interrupt			*/
										/* Get the interrupt factor		*/
	IDE_FuncGetInterrupt( DIRECT_B(main_int_enb_ide), (UCHAR *)&intStatus );

	DIRECT_B(main_int_enb_ide) = 0x00;	/* Clear						*/

	OS_UnlCpu();						/* Unlock the interrupt			*/

										/* Check the interrupt factor	*/

	if( intStatus & IDE_FUNC_INT_CMPINTRQ ){
		IDEIntStatus.CompleteINTRQ = 1;
	}

	if( intStatus & IDE_FUNC_INT_IDECMP ){
		IDE_FuncNotifyDmaComp( DeviceID, 0, NULL );
		IDEDMA_IFGetTransferStatus( DeviceID, &IDEStatus );
		IDEIntStatus.IDE_Cmp = 1;
	}

	if( intStatus & IDE_FUNC_INT_DETECTINTRQ ){
		IDE_FuncNotifyIntrq( DeviceID, 0, NULL );
		IDEIntStatus.DetectINTRQ = 1;
	}

	if( DeviceType == IDE_DEV_ATA ){	/* Check the connected device	*/
		ATACmd_Main( IDE_TASK_EVT_INT );/* Process ATA command			*/
	}else if( DeviceType == IDE_DEV_ATAPI ){
		ATAPICmd_Main( IDE_TASK_EVT_INT );/* Process ATAPI command		*/
	}

	return STATUS_SUCCESS;
}

/*
//=============================================================================
// Function_Name: IDE_MsgEvent
// description	: Process message event
// argument		:
// return		:
// flag			:
// global		:
//=============================================================================
*/
static LONG IDE_MsgEvent( PMSGIDE pMsg )
{

	switch( IdeTsk_Inf.mState )			/* Judgement on task state		*/
	{
		case IDE_MSTS_INIT:				/* Initial state 				*/
			IDE_InitSts_MsgProc( pMsg );
			break;

		case IDE_MSTS_RESET:			/* Reset state 					*/
			break;						/* Do not process the event of this state */

		case IDE_MSTS_IDLE:				/* Idle state					*/
			IDE_IdleSts_MsgProc( pMsg );
			break;

		case IDE_MSTS_CMDEXEC:			/* Executing command state		*/
			IDE_CmdExecSts_MsgProc( pMsg );
			break;

		default:						/* It cannot run here because it is an internal state.	*/
			break;
	}

	return STATUS_SUCCESS;
}

/*
//=============================================================================
// Function_Name: IDE_InitSts_MsgProc
// description	: Process initial statemessage
// argument		:
// return		:
// flag			:
// global		:
//=============================================================================
*/
static LONG IDE_InitSts_MsgProc( PMSGIDE pMsg )
{

	switch ( pMsg->msgHead.msgNo )		/* Judgement on the received message number  */
	{
		case MSG_REQ_IDE_HRST:			/* IDE hard reset request 		*/
			HardReset();				/* Process IDE hard reset 		*/
			break;

		default:
			StatusError( pMsg );		/* Send error  					*/
			break;
	}

	return STATUS_SUCCESS;
}

/*
//=============================================================================
// Function_Name: IDE_IdleSts_MsgProc
// description	: Process idle state message
// argument		:
// return		:
// flag			:
// global		:
//=============================================================================
*/
static LONG IDE_IdleSts_MsgProc( PMSGIDE pMsg )
{

	LED_On(1);						/* (Toya ARM CPU BOARD LED 1)		*/

										/* Start the procession of the command */

	switch ( pMsg->msgHead.msgNo )		/* Judgement on received message number */
	{
		case MSG_REQ_IDE_HRST:			/* Hard reset IDE request 		*/
			HardReset();				/* Process hard reset			*/
			break;

		case MSG_REQ_IDE_SRST:			/* Soft reset IDE request		*/
			SoftReset();				/* Process soft reset 			*/
			break;

		case MSG_REQ_IDE_DEV_LIST:		/* Get IDE device list request 	*/
			GetDeviceList( pMsg );		/* Process Get device list 		*/
			break;

		case MSG_REQ_IDE_SET_XFERRATE:	/* Set IDE Datarate request		*/
			SetXferRate( pMsg );		/* Process Set Data rate 		*/
			break;

		case MSG_REQ_IDE_CMD:			/* IDE command processing request(ATA/ATAPI) */
			IDE_CmdIdle_Proc( pMsg );
			break;

		default:
			StatusError( pMsg );		/* Send error */
			break;
	}

	return STATUS_SUCCESS;
}

/*
//=============================================================================
// Function_Name: IDE_CmdExecSts_MsgProc
// description	: Process executing command state message
// argument		:
// return		:
// flag			:
// global		:
//=============================================================================
*/
static LONG IDE_CmdExecSts_MsgProc( PMSGIDE pMsg )
{

	switch ( pMsg->msgHead.msgNo )		/* Judgement on the receive message number */
	{
		case MSG_REQ_IDE_HRST:			/* Hard reset IDE request 		*/
			HardReset();				/* Process IDE hard reset */
			break;

		case MSG_REQ_IDE_SRST:			/* Soft reset IDE request 		*/
			SoftReset();				/* Process soft reset of IDE 	*/
			break;

		case MSG_REQ_IDE_XFER_START:	/* IDE data trandfer request	*/
			IDE_CmdExec_Proc( pMsg );
			break;

		default:
			StatusError( pMsg );		/* Send error */
			break;
	}

	return STATUS_SUCCESS;
}

/*
//=============================================================================
/ Function_Name: HardReset
// description	: Process IDE hard reset
// argument		:
// return		:
// flag			:
// global		:
//=============================================================================
*/

⌨️ 快捷键说明

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