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

📄 idetask.c

📁 epson usb2.0 控制芯片 S1R72V05 固件程序。
💻 C
📖 第 1 页 / 共 5 页
字号:
LONG HardReset( void )
{
PARAM_MSG_NTFY_IDE_HRST	data;
LONG		result;
UCHAR	i;

#ifdef DEBUG_C
	IDEResetCount++;
#endif

	StatusChange( IDE_MSTS_RESET );		/* Reset state 					*/

	for( ;; ){
		/*------------------------------------------------------------------*/
		/* Hard reset													*/
		/*------------------------------------------------------------------*/
		result = IDE_FuncReset();
		if( result != STATUS_SUCCESS ){
			break;						/* Completed abnormally			*/
		}
		/* It confirms that the maximum time interval is 30 seconds until the device becomes to idle.*/
		result = StatusWait();
		if( result != STATUS_SUCCESS ){
			break;						/* Completed abnormally			*/
		}
		/*------------------------------------------------------------------*/
		/* Get device list												*/
		/*------------------------------------------------------------------*/
		result = IDE_FuncGetDeviceList( DeviceID, &DeviceList );
		if( result != STATUS_SUCCESS ){
			break;						/* Completed abnormally			*/
		}

		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;
			}
		}

		break;
	}

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

	/*----------------------------------------------------------------------*/
	/* Generate the message and send the message						*/
	/*----------------------------------------------------------------------*/
										/* generate data section		*/
	if( result == STATUS_SUCCESS ){		/* Processing result			*/
		data.result = IDE_REQ_OK;
		StatusChange( IDE_MSTS_IDLE );	/* Idle state					*/
	}
	else{
		data.result = IDE_REQ_NG;
		StatusChange( IDE_MSTS_INIT );	/* Initial state 				*/
	}
										/* Set the number of connected devices */
	data.deviceCnt = DeviceList.deviceCount;
	switch( DeviceList.deviceCount )
	{									/* Set Device type 				*/
		case 1:							/* When one device is connected */
			data.deviceType[0] = GetDeviceType( 0 );/* Logical unit 0 	*/
			data.deviceType[1] = IDE_DEV_NOT;/* Logical unit 1	 		*/
			break;

		case 2:							/* When 2 devices are connected	*/
			data.deviceType[0] = GetDeviceType( 0 );/* Logical unit 0 	*/
			data.deviceType[1] = GetDeviceType( 1 );/* Logical unit 1	*/
			break;

		case 0:							/* When 0 device is connected	*/
		default:						/* Error						*/
			data.deviceType[0] = IDE_DEV_NOT;/* Logical unit 0	 		*/
			data.deviceType[1] = IDE_DEV_NOT;/* Logical unit 1	 		*/
			break;
	}
	UnitFlag[0].aten = 1;				/* Unit attention state 		*/
	UnitFlag[1].aten = 1;
										/* Send message 				*/
	if( RegRead( REG08_HostDeviceSel ) & BIT_HOSTxDEVICE_HOST ){
		SendMessage( MBXID_USBH_SAMPLE, MSG_NTFY_IDE_HRST,
									sizeof(PARAM_MSG_NTFY_IDE_HRST), &data );
	} else {
		SendMessage( MBXID_DEVICE, MSG_NTFY_IDE_HRST,
									sizeof(PARAM_MSG_NTFY_IDE_HRST), &data );
	}
	/*----------------------------------------------------------------------*/
	return STATUS_SUCCESS;
}

/*
//=============================================================================
// Function_Name: SoftReset
// description	:
// argument		:
// return		:
// flag			:
// global		:
//=============================================================================
*/
LONG SoftReset( void )
{
PARAM_MSG_NTFY_IDE_SRST	data;
LONG		result;

#ifdef DEBUG_C
	IDEResetCount++;
#endif

	StatusChange( IDE_MSTS_RESET );		/* Reset state 					*/

	for( ;; ){
		/*------------------------------------------------------------------*/
		/* Soft reset													*/
		/*------------------------------------------------------------------*/
		result = IDE_FuncDeviceReset( DeviceID, DeviceNo );
		if( result != STATUS_SUCCESS ){
			break;						/* Completed abnormally			*/
		}
		/* It confirms that the maximum time interval is 30 seconds until the device becomes to idle.*/
		result = StatusWait();
		if( result != STATUS_SUCCESS ){
			break;						/* Completed abnormally			*/
		}

		/*------------------------------------------------------------------*/
		/* Set transfer mode 											*/
		/*------------------------------------------------------------------*/
		result = IDE_FuncXferRateSet( DeviceID, DeviceNo );
		if( result != STATUS_SUCCESS ){
			break;						/* Completed abnormally			*/
		}

		break;
	}

	/*----------------------------------------------------------------------*/
	/* Generate the message and send the message						*/
	/*----------------------------------------------------------------------*/
										/* Make data region.			*/
	if( result == STATUS_SUCCESS ){		/* Processing result			*/
		data.result = IDE_REQ_OK;
		StatusChange( IDE_MSTS_IDLE );	/* Idle state					*/
	}
	else{
		data.result = IDE_REQ_NG;
		StatusChange( IDE_MSTS_INIT );	/* Initial state 				*/
	}
	UnitFlag[0].aten = 1;				/* Unit attention status	*/
	UnitFlag[1].aten = 1;
										/* Send message 				*/
	if( RegRead( REG08_HostDeviceSel ) & BIT_HOSTxDEVICE_HOST ){
		SendMessage( MBXID_USBH_SAMPLE, MSG_NTFY_IDE_SRST,
									sizeof(PARAM_MSG_NTFY_IDE_SRST), &data );
	} else {
		SendMessage( MBXID_DEVICE, MSG_NTFY_IDE_SRST,
									sizeof(PARAM_MSG_NTFY_IDE_SRST), &data );
	}
	/*----------------------------------------------------------------------*/
	return STATUS_SUCCESS;
}

/*
//=============================================================================
// Function_Name: GetDeviceList
// description	: process to return the device list
// argument		:
// return		:
// flag			:
// global		:
//=============================================================================
*/
LONG GetDeviceList( PMSGIDE pMsg )
{
PARAM_MSG_NTFY_IDE_DEV_LIST	data;
STR_DEV_LIST	*buf;					/* For device list				*/


	StatusChange( IDE_MSTS_CMDEXEC );	/* Executing device state		*/
	/*----------------------------------------------------------------------*/
	/* Generate the message and send the message						*/
	/*----------------------------------------------------------------------*/
										/* Get out the data transfer memory pointer from the received message */
	buf = (STR_DEV_LIST *)((PARAM_MSG_REQ_IDE_DEV_LIST *)pMsg->msgData)->bufferPtr;

										/* number of connected devives	*/
	buf->deviceCnt = DeviceList.deviceCount;
										/* Logical unit device type 	*/
	switch( DeviceList.deviceCount )
	{									/* Set Device type 				*/
		case 1:							/* When one device is connected */
			buf->deviceType[0] = GetDeviceType( 0 );/* Logical unit 0 	*/
			buf->deviceType[1] = IDE_DEV_NOT;/* Logical unit 1	 		*/
			break;

		case 2:							/* When 2 devices are connected	*/
			buf->deviceType[0] = GetDeviceType( 0 );/* Logical unit 0 	*/
			buf->deviceType[1] = GetDeviceType( 1 );/* Logical unit 1	*/
			break;

		case 0:							/* When 0 device is connected	*/
		default:						/* Error						*/
			buf->deviceType[0] = IDE_DEV_NOT;/* Logical unit 0	 		*/
			buf->deviceType[1] = IDE_DEV_NOT;/* Logical unit 1	 		*/
			LED_Off(1);						/* (Toya ARM CPU BOARD LED 1)		*/
			break;
	}
										/* Data section 				*/
	data.result = IDE_REQ_OK;			/* Processing result			*/

	if( RegRead( REG08_HostDeviceSel ) & BIT_HOSTxDEVICE_HOST ){
		SendMessage( MBXID_USBH_SAMPLE, MSG_NTFY_IDE_DEV_LIST,
								sizeof(PARAM_MSG_NTFY_IDE_DEV_LIST), &data );
	} else {
		SendMessage( MBXID_DEVICE, MSG_NTFY_IDE_DEV_LIST,
								sizeof(PARAM_MSG_NTFY_IDE_DEV_LIST), &data );
	}
	/*----------------------------------------------------------------------*/
	StatusChange( IDE_MSTS_IDLE );		/* Idle state					*/

	return STATUS_SUCCESS;
}

/*
//=============================================================================
// Function_Name: SetXferRate
// description	:
// argument		:
// return		:
// flag			:
// global		:
//=============================================================================
*/
LONG SetXferRate( PMSGIDE pMsg )
{
PARAM_MSG_REQ_IDE_SET_XFERRATE	*msg;
LONG		result;
PARAM_MSG_NTFY_IDE_SET_XFERRATE	data;


	StatusChange( IDE_MSTS_CMDEXEC );	/* Executing command state 		*/

	for( ;; ){
		/*------------------------------------------------------------------*/
		/* Check parameter of received message							*/
		/*------------------------------------------------------------------*/
										/* Data area for received data. */
		msg = (PARAM_MSG_REQ_IDE_SET_XFERRATE *)pMsg->msgData;

		result = SetXferRate_ParaCheck( msg );
		if( result != STATUS_SUCCESS ){
			break;						/* Completed abnormally			*/
		}
		DeviceNo = msg->LUN;

		IdeXferPara.PIOMode = msg->PIOMode;
		IdeXferPara.multiDMAMode = msg->multiDMAMode;
		IdeXferPara.ultraDMAMode = msg->ultraDMAMode;

		/*------------------------------------------------------------------*/
		/* change transfer mode											*/
		/*------------------------------------------------------------------*/
		IDE_FuncXferRateChange( DeviceNo, &IdeXferPara );
		/*------------------------------------------------------------------*/
		/* Sent transfer mode 											*/
		/*------------------------------------------------------------------*/
		result = IDE_FuncXferRateSet( DeviceID, DeviceNo );
		if( result != STATUS_SUCCESS ){
			break;						/* Completed abnormally			*/
		}

		break;
	}
	/*----------------------------------------------------------------------*/
	/* Generate the message and send the message						*/
	/*----------------------------------------------------------------------*/
										/* Generate data section 		*/
	if( result == STATUS_SUCCESS ){		/* Processing result			*/
		data.result = IDE_REQ_OK;
	}
	else{
		data.result = IDE_REQ_NG;
	}

	if( RegRead( REG08_HostDeviceSel ) & BIT_HOSTxDEVICE_HOST ){
		SendMessage( MBXID_USBH_SAMPLE, MSG_NTFY_IDE_SET_XFERRATE,
								sizeof(PARAM_MSG_NTFY_IDE_SET_XFERRATE), &data );
	} else {
		SendMessage( MBXID_DEVICE, MSG_NTFY_IDE_SET_XFERRATE,
								sizeof(PARAM_MSG_NTFY_IDE_SET_XFERRATE), &data );
	}
	/*----------------------------------------------------------------------*/
	StatusChange( IDE_MSTS_IDLE );		/* Idle state					*/

	return STATUS_SUCCESS;
}

/*
//=============================================================================
// Function_Name: SetXferRate_ParaCheck
// description	:
// argument		:
// return		:
// flag			:
// global		:
//=============================================================================
*/
static LONG SetXferRate_ParaCheck( PARAM_MSG_REQ_IDE_SET_XFERRATE *msg )
{
	if( msg->LUN >= MAX_DEVICE ){		/* Check LUN 					*/
		return STATUS_INVALID_PARAMETER;/* Parameter error 				*/
	}
	if( msg->PIOMode > IDE_FUNC_PIO_MODE4 ){/* Asset PIO transfer mode 		*/
		return STATUS_INVALID_PARAMETER;/* Parameter error 				*/
	}
	if( msg->multiDMAMode > IDE_FUNC_MULTI_MODE2 ){/* Assert multiDMA transfer mode */
		return STATUS_INVALID_PARAMETER;/* Parameter error 				*/
	}
	if( msg->ultraDMAMode > IDE_FUNC_ULTRA_MODE6 ){/* Check ultraDMA transfer mode */
		return STATUS_INVALID_PARAMETER;/* Parameter error 				*/
	}
	return STATUS_SUCCESS;
}

/*
//=============================================================================
// Function_Name: IDE_CmdIdle_Proc
// description	:
// argument		:
// return		:
// flag			:
// global		:
//=============================================================================
*/
static LONG IDE_CmdIdle_Proc( PMSGIDE pMsg )
{
LONG	result;
volatile REG_rxH_CHxWindow *prxH_CHxWindow;
volatile unsigned short *prsH_CHxWindow;
UCHAR		i, joinFlag;
UCHAR errInfo;  // Add for USBCV MSC Test

	/*----------------------------------------------------------------------*/
	/* Check the parameter of the received message						*/
	/*----------------------------------------------------------------------*/
	result = IDECmd_ParaCheck( (PARAM_MSG_REQ_IDE_CMD *)pMsg->msgData );
	if( result != STATUS_SUCCESS ){
		/* Execute the callback that registered at DirectCopy */
		if( ((PARAM_MSG_REQ_IDE_CMD *)pMsg->msgData)->xferMode == IDE_XFER_DIRECT) {
			IdeTsk_CmdPara.pfnCallback(DeviceNo, 0x00, 0x00);
			LED_Off(1);							/* (Toya ARM CPU BOARD LED 1)		*/
		} else {
			SendMessageNTFY_IDE_CMD( IDE_REQ_NG, 0 );/* Parameter error 	*/
		}
		return STATUS_SUCCESS;
	}

	/*----------------------------------------------------------------------*/
	/* The field that receives message									*/
	/*----------------------------------------------------------------------*/
	IDECmd_ParaSave( (PARAM_MSG_REQ_IDE_CMD *)pMsg->msgData );
	/*----------------------------------------------------------------------*/
	/* Determine the device type and device No.from LUN					*/
	/*----------------------------------------------------------------------*/
	DeviceType = GetDeviceType( IdeTsk_CmdPara.LUN );
	DeviceNo = IdeTsk_CmdPara.LUN;

	IdeTsk_CmdPara.dataSize = 0;		/* Initialize 					*/

	/* When the host operates, the device type is converted according to the command.  */
	if( RegRead( REG08_HostDeviceSel ) & BIT_HOSTxDEVICE_HOST ){
		if( DeviceType == IDE_FUNC_HDD ){

⌨️ 快捷键说明

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