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

📄 devicetaskapi.c

📁 epson usb2.0 控制芯片 S1R72V05 固件程序。
💻 C
📖 第 1 页 / 共 3 页
字号:
	DEVICEInfo.playInfo.lun			  = LUN;
	DEVICEInfo.playInfo.cmdType		  = cmdType;
	DEVICEInfo.playInfo.xferInfo.dir	  = pXferInfo->dir;
	DEVICEInfo.playInfo.xferInfo.buffer  = pXferInfo->pAddress;
	DEVICEInfo.playInfo.xferInfo.mode	  = pXferInfo->mode;
	DEVICEInfo.playInfo.xferInfo.reqSize = pXferInfo->size;
	DEVICEInfo.playInfo.xferInfo.dmaCh	 = pXferInfo->dmaChannel;
	memcpy( &DEVICEInfo.playInfo.ideCmd, pIdeCmd, sizeof(DEVICEInfo.playInfo.ideCmd) );	// Copy the command.

	DEVICEInfo.state = DEVICE_TASK_STATE_PLAY_CMD_EXEC;	// DEVICE is changed to command running state

	OS_SetFlg( FLGID_DEVICE, (FLG_EVENT_EXECMD_DEVICE) );

	// Execution mode's judgment
	if( DEVICEInfo.playInfo.execMode == DEVICE_TASK_PLAY_CMD_SYNC_MODE )
	{
		OS_WaiSem( SEMID_DEVICE );

		if( DEVICEInfo.playInfo.cmdStatus != DEVICE_TASK_CMD_STATUS_PASSED )
		{
			// Command failed
			return DEVICE_TASK_STATUS_UNSUCCESSFUL;
		}
	}

	return DEVICE_TASK_STATUS_SUCCESS;
}

/*
//=============================================================================
// Function_Name: DEVICE_TASK_StartUSBPIO
// description	: PIO transfer requirement for USB host
// argument		: unsigned char dir
//				: unsigned long size
//				: unsigned char* pAddress
// return		: long
//=============================================================================
*/
long DEVICE_TASK_StartUSBPIO ( unsigned char dir, unsigned long size, unsigned char* pAddress )
{
	//========================================================================
	// Check state
	//========================================================================
	if( DEVICEInfo.state != DEVICE_TASK_STATE_MODULE_ACC )
	{
		// Error when it is called besides other module access
		return DEVICE_TASK_STATUS_STATE_ERROR;
	}

	//========================================================================
	// Check parameter
	//========================================================================
	if( size == 0x00 || pAddress == NULL )
	{
		return DEVICE_TASK_STATUS_INVALID_PARAMETER;
	}

	//========================================================================
	// Data transfer notification to DEVICE task
	//========================================================================
	UserCmdInfo.xferInfo.mode = DEVICE_TASK_XFER_MODE_PIO;
	UserCmdInfo.xferInfo.dir = dir;
	UserCmdInfo.xferInfo.size = size;
	UserCmdInfo.xferInfo.pBuffer = pAddress;
	UserCmdInfo.xferInfo.dmaCh = 0x00;

	OS_SetFlg( FLGID_DEVICE, (FLG_EVENT_USB_XFER_DEVICE) );
	return DEVICE_TASK_STATUS_SUCCESS;
}

/*
//=============================================================================
// Function_Name: DEVICE_TASK_StartUSBDMA
// description	: Start DMA between CPU andUSB host
// argument		: unsigned char dir		Direction of data transfer
//				: unsgined long size	Number of data transfer
//				: unsigned char dmaChannel DMA channel to use
// return		: long
//=============================================================================
*/
long DEVICE_TASK_StartUSBDMA ( unsigned char dir, unsigned long size, unsigned char dmaChannel )
{
	//========================================================================
	// Check state
	//========================================================================
	if( DEVICEInfo.state != DEVICE_TASK_STATE_MODULE_ACC )
	{
		// Error when it is called besides other module access
		return DEVICE_TASK_STATUS_STATE_ERROR;
	}

	//========================================================================
	// Check parameter
	//========================================================================
	if( size == 0x00 )
	{
		return DEVICE_TASK_STATUS_INVALID_PARAMETER;
	}

	//========================================================================
	// Data transfer notification of DEVICE task
	//========================================================================
	UserCmdInfo.xferInfo.mode = DEVICE_TASK_XFER_MODE_DMA;
	UserCmdInfo.xferInfo.dir = dir;
	UserCmdInfo.xferInfo.size = size;
	UserCmdInfo.xferInfo.pBuffer = NULL;
	UserCmdInfo.xferInfo.dmaCh = dmaChannel;

	OS_SetFlg( FLGID_DEVICE, (FLG_EVENT_USB_XFER_DEVICE) );
	return DEVICE_TASK_STATUS_SUCCESS;
}

/*
//=============================================================================
// Function_Name: DEVICE_TASK_StartDma
// description	: Start DMA transfer
// argument		: none
// return		: long
//=============================================================================
*/
long DEVICE_TASK_StartDma ( void )
{
	//========================================================================
	// Check state
	//========================================================================
	if( DEVICEInfo.state != DEVICE_TASK_STATE_PLAY_DMA_READY )
	{
		// Error when it is called besides other module access
		return DEVICE_TASK_STATUS_STATE_ERROR;
	}

	DEVICEInfo.state = DEVICE_TASK_STATE_PLAY_DMA_XFER;		// Change to DMA start state

	OS_SetFlg( FLGID_DEVICE, (FLG_EVENT_DMA_START_DEVICE) );

	return DEVICE_TASK_STATUS_SUCCESS;

}

/*
//=============================================================================
// Function_Name: DEVICE_TASK_AbortDma
// description	: Stop DMA transfer
// argument		: none
// return		: long
//=============================================================================
*/
long DEVICE_TASK_AbortDma ( void )
{
	//========================================================================
	// Check state
	//========================================================================
	if( DEVICEInfo.state != DEVICE_TASK_STATE_PLAY_DMA_XFER )
	{
		// Error when it is called besides other module access
		return DEVICE_TASK_STATUS_STATE_ERROR;
	}


	DEVICEInfo.state = DEVICE_TASK_STATE_PLAY_DMA_ABORT;		// Change to DMA abort state

	OS_SetFlg( FLGID_DEVICE, (FLG_EVENT_DMA_ABORT_DEVICE) );
	return DEVICE_TASK_STATUS_SUCCESS;
}

/*
//=============================================================================
// Function_Name: DEVICE_TASK_IDE_HRST
// description	: HRST start requirement
// argument		: none
// return		: long
//=============================================================================
*/
long DEVICE_TASK_IDE_HRST ( void )
{
	//========================================================================
	// Check state
	//========================================================================
	if( DEVICEInfo.state != DEVICE_TASK_STATE_WAIT_EVENT )
	{
		// It doesn't accept except the event waiting state
		return DEVICE_TASK_STATUS_STATE_ERROR;
	}

	//========================================================================
	// HRST requirement for DEVICE task
	//========================================================================
	OS_SetFlg( FLGID_DEVICE, FLG_EVENT_IDEHRST_DEVICE );

	return DEVICE_TASK_STATUS_SUCCESS;
}

/*
//=============================================================================
// Function_Name: DEVICE_TASK_PullupControl
// description	: Control Pull-up of USB
// argument		: none
// return		: long
//=============================================================================
*/
long DEVICE_TASK_PullupControl ( unsigned char control )
{
	//========================================================================
	// Check state
	//========================================================================
	switch( DEVICEInfo.state )
	{
		case DEVICE_TASK_STATE_USB_NON_CONNECT:
		case DEVICE_TASK_STATE_USB_STORAGE:
		case DEVICE_TASK_STATE_USB_SUSPEND:
		case DEVICE_TASK_STATE_MODULE_ACC:
			// It is a valid state when in state of event waiting/upper module access
			break;
		default:
			// Error state for other states
			return DEVICE_TASK_STATUS_STATE_ERROR;
	}

	//========================================================================
	// Check parameter
	//========================================================================
	switch( control )
	{
		case DEVICE_TASK_USB_PULLUP_ON:
		case DEVICE_TASK_USB_PULLUP_OFF:
			break;
		default:
			return DEVICE_TASK_STATUS_INVALID_PARAMETER;
	}

	//========================================================================
	// Confirm whether manual Attach is specified with StartUSB
	//========================================================================
	if( DEVICEInfo.usbInfo.bManAttach != TRUE )
	{
		return DEVICE_TASK_STATUS_STATE_ERROR;
	}

	if( control == DEVICE_TASK_USB_PULLUP_ON )
	{
		// Attach requirement
		OS_SetFlg( FLGID_DEVICE, FLG_EVENT_ATTACH_USB_DEVICE );
	}
	else
	{
		// Detach requirement
		OS_SetFlg( FLGID_DEVICE, FLG_EVENT_DETACH_USB_DEVICE );
	}

	return DEVICE_TASK_STATUS_SUCCESS;
}

/*
//=============================================================================
// Function_Name: InitVariable
// description	: Initialize variables used by this module
// argument		: none
// return		: none
//=============================================================================
*/
void InitVariable( void )
{
	// Variable's initialization
	DEVICEInfo.pfnMsgProc = NULL;
	DEVICEInfo.playInfo.execMode = DEVICE_TASK_PLAY_CMD_SYNC_MODE;
	DEVICEInfo.state = DEVICE_TASK_STATE_NON_EXISTENT;
}

/*
//=============================================================================
// Function_Name: ChangePMMode
// description	: Change the PM mode
// argument		: none
// return		: none
//=============================================================================
*/
void ChangePMMode( unsigned char suspendLevel )
{
	unsigned char pmState;
	unsigned char nowPMState;


	pmState = 0;		// Countermeasure against warning of optimizing

	switch( DEVICEInfo.usbInfo.suspenLV )
	{
		case DEVICE_TASK_SUSPEND_LV0:
			if( DEVICEInfo.state == DEVICE_TASK_STATE_USB_SUSPEND ){
				pmState = PM_IF_PMSTATE_ACT_DEVICE;
			}else{
				pmState = PM_IF_PMSTATE_ACT_60;
			}
			break;
		case DEVICE_TASK_SUSPEND_LV1:	pmState = PM_IF_PMSTATE_SNOOZE;		break;
		case DEVICE_TASK_SUSPEND_LV2:	pmState = PM_IF_PMSTATE_SLEEP;		break;
		default:
			// It doesn't come here
			break;
	}

	// Confirm present PM
	PM_IFGetPMState( &nowPMState );
	if( nowPMState == pmState )
	{
		// Escape if it is same
		return;
	}

	PM_IFSetPMState( pmState );

}

⌨️ 快捷键说明

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