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

📄 devicetaskapi.c

📁 epson usb2.0 控制芯片 S1R72V05 固件程序。
💻 C
📖 第 1 页 / 共 3 页
字号:
/*
 * description: DEVICE Module Application programming interface
 * Maker	  : Kagaya.Michiru
 * Copyright  : (C)2003,SEIKO EPSON Corp. All Rights Reserved.
 */

//=============================================================================
// Include file
//=============================================================================
#include <string.h>
#include "SPRDEF.h"
#include "OSCall.h"
#include "DeviceTaskAPI.h"		// DeviceAPI
#include "DeviceTask.h"		// Device Task
#include "IDETask.h"	// IDE Task
#include "USBDTask.h"	// USB Device Task
#include "PM_IF.h"

//=============================================================================
// Define declaration
//=============================================================================

//=============================================================================
// Structure declaration
//=============================================================================

//=============================================================================
// Variables declaration
//=============================================================================
extern USER_CMD_INFO UserCmdInfo;
DEVICE_MODULE_INFO DEVICEInfo;

//=============================================================================
// Static functions
//=============================================================================
static void InitVariable( void );
static void ChangePMMode( unsigned char suspendLevel );


/*
//=============================================================================
// Function_Name: DEVICE_TASK_Create
// description	: Create this module
//				: Do nothing if it is things except a standard profile
//				: Reply of DEVICE_TASK_STATUS_SUCCESS
// argument		: none
// return		: long
//=============================================================================
*/
long DEVICE_TASK_Create ( void )
{
	DEVICEInfo.state  = DEVICE_TASK_STATE_NON_EXISTENT;	// Initialize the state of DEVICE Only


	// The variables used by this module is initialized
	InitVariable();

	// Change to stop state
	DEVICEInfo.state = DEVICE_TASK_STATE_STOP;


	return DEVICE_TASK_STATUS_SUCCESS;
}

/*
//=============================================================================
// Function_Name: DEVICE_TASK_Delete
// description	: Create this module
// argument		: none
// return		: long status error is specified
//				:	   : DEVICE_TASK_STATUS_SUCCESS : terminated successfully
//				:	   : DEVICE_TASK_STATUS_STATE_ERROR : state error
//=============================================================================
*/
long DEVICE_TASK_Delete ( void )
{
	// Confirm the state
	if( DEVICEInfo.state == DEVICE_TASK_STATE_NON_EXISTENT )
	{
		// Error for unregistered state
		return DEVICE_TASK_STATUS_STATE_ERROR;
	}

	return DEVICE_TASK_STATUS_SUCCESS;
}

/*
//=============================================================================
// Function_Name: DEVICE_TASK_Active
// description	: Create this moudle
// argument		: DEVICE_TASK_PFN_CALLBACK_PROC pfnCallbackProc
//				:	Function address which receive message from this module
//				: unsigned char cmdMode
//				:	 Execution Operation of Play Mode command is specified
//				:
// return		: long status
//				:	Operation result of this API
//=============================================================================
*/
long DEVICE_TASK_Active ( DEVICE_TASK_PFN_CALLBACK_PROC pfnCallbackProc, unsigned char cmdMode )
{
	OS_BOOL	dspState;		// State of dispatch

	//========================================================================
	// Parameter's judgment
	//========================================================================
	if( pfnCallbackProc == NULL )
	{
		// Parameter error
		return DEVICE_TASK_STATUS_INVALID_PARAMETER;
	}
	if( cmdMode != DEVICE_TASK_PLAY_CMD_ASYNC_MODE && cmdMode != DEVICE_TASK_PLAY_CMD_SYNC_MODE )
	{
		// Unsupported mode is specified
		return DEVICE_TASK_STATUS_INVALID_PARAMETER;
	}

	//========================================================================
	// Check state
	//========================================================================
	if( DEVICEInfo.state != DEVICE_TASK_STATE_STOP )
	{
		return DEVICE_TASK_STATUS_STATE_ERROR;
	}

	//========================================================================
	// DEVICE Task is started
	//========================================================================
	dspState = OS_SnsDsp();		// Refer to the dispatch state
	if( dspState != OS_TRUE )
	{
		// When dispatch is valid, invalidate it
		OS_DisDsp();
	}

	//========================================================================
	// Initialize each variable
	//========================================================================
	DEVICEInfo.state = DEVICE_TASK_STATE_MODULE_INIT;
	DEVICEInfo.playInfo.execMode = cmdMode;		// Execution mode's setting
	DEVICEInfo.pfnMsgProc = pfnCallbackProc;		// Callback function's registration
	OS_ActTsk( TSKID_DEVICE  );					// Start DEVICE Task

	if( dspState != OS_TRUE )
	{
		// When dispatch is invalidated, return it to valid
		OS_EnaDsp();
	}

	return DEVICE_TASK_STATUS_SUCCESS;
}

/*
//=============================================================================
// Function_Name: DEVICE_TASK_Inactive
// description	: Stop this module
// argument		: none
// return		: long
//=============================================================================
*/
long DEVICE_TASK_Inactive ( void )
{
	//========================================================================
	// Check state
	//========================================================================
	if( DEVICEInfo.state == DEVICE_TASK_STATE_NON_EXISTENT || DEVICEInfo.state == DEVICE_TASK_STATE_STOP )
	{
		// Error for an unregistered state, and stop state
		return DEVICE_TASK_STATUS_STATE_ERROR;
	}

	//========================================================================
	//
	//Because synchronization and communication mechanism can't be dynamically deleted
	//for a standard profile, remained mailboxes cannot be deleted.
	//Therefore, set "" bit to delete it when reset
	//========================================================================
	OS_ClrFlg( FLGID_DEVICE, ~FLG_WAIT_PTN_DEVICE );
	OS_SetFlg( FLGID_DEVICE, FLG_EVENT_FORCE_DEVICE );
	DEVICEInfo.state = DEVICE_TASK_STATE_STOP;

	// This module ends the task of starting
	OS_TerTsk( TSKID_USBD );
	OS_TerTsk( TSKID_IDE );
	OS_TerTsk( TSKID_DEVICE );

	// 2005/4/7 Nagashima: Modified bug of USB operation which occured after stopping the device module
	memset(&DEVICEInfo.usbInfo,0,sizeof(USB_INFO));	// Initialize information of USB operation mode

	DEVICEInfo.state = DEVICE_TASK_STATE_STOP;

	return DEVICE_TASK_STATUS_SUCCESS;
}

/*
//=============================================================================
// Function_Name: DEVICE_TASK_StartUSB
// description	: Beginning of USB operation mode
// argument		: none
// return		: long
//=============================================================================
*/
long DEVICE_TASK_StartUSB ( unsigned long mode )
{

	//========================================================================
	// Check state
	//========================================================================
	switch( DEVICEInfo.state )
	{
		case DEVICE_TASK_STATE_NON_EXISTENT:
		case DEVICE_TASK_STATE_STOP:
		case DEVICE_TASK_STATE_MODULE_INIT:
		case DEVICE_TASK_STATE_SLEEP_A:
		case DEVICE_TASK_STATE_PLAY_CMD_EXEC:
		case DEVICE_TASK_STATE_PLAY_DMA_XFER:
			//------------------------------------------------------------------------
			// Return error for USB can't be started
			//------------------------------------------------------------------------
			return DEVICE_TASK_STATUS_STATE_ERROR;
//			break;

		case DEVICE_TASK_STATE_USB_NON_CONNECT:
		case DEVICE_TASK_STATE_USB_STORAGE:
		case DEVICE_TASK_STATE_MODULE_ACC:
		case DEVICE_TASK_STATE_USB_SUSPEND:
			//------------------------------------------------------------------------
			// Fot it is already a USB state, terminate it normally
			//------------------------------------------------------------------------
			return DEVICE_TASK_STATUS_SUCCESS;
//			break;

		case DEVICE_TASK_STATE_DEV_INIT:
		case DEVICE_TASK_STATE_WAIT_EVENT:
			break;

		default:
			//------------------------------------------------------------------------
			// Return error for states outside assumption
			//------------------------------------------------------------------------
			return DEVICE_TASK_STATUS_STATE_ERROR;
//			break;
	}

	//========================================================================
	// Check parameter
	//========================================================================
	if( mode & DEVICE_TASK_MODE_USB_MANUAL_ATTACH )
	{
		// Specify the manual attach mode
		DEVICEInfo.usbInfo.bManAttach = TRUE;
	}
	else
	{
		// Auto attach mode is specified.
		DEVICEInfo.usbInfo.bManAttach = FALSE;
	}

	if( mode & DEVICE_TASK_MODE_USB_MANUAL_PWR_CTL )
	{
		// Check whether the AUTO mode is specified at the same time
		if( mode & (DEVICE_TASK_MODE_USB_AUTO_PWR_LV0 | DEVICE_TASK_MODE_USB_AUTO_PWR_LV1 | DEVICE_TASK_MODE_USB_AUTO_PWR_LV2 ) )
		{
			return DEVICE_TASK_STATUS_INVALID_PARAMETER;
		}
		// Specify the control mode of manual power saving
		DEVICEInfo.usbInfo.bManPwrCtrl = TRUE;
	}
	else
	{
		// Specify the automatic suspend mode
		DEVICEInfo.usbInfo.bManPwrCtrl = FALSE;

		//------------------------------------------------------------------------
		// Confirm the control mode of current consumption when receiving in USB suspend
		//------------------------------------------------------------------------
		if( mode & DEVICE_TASK_MODE_USB_AUTO_PWR_LV0 )
		{
			DEVICEInfo.usbInfo.suspenLV = DEVICE_TASK_SUSPEND_LV0;
		}
		else if( mode & DEVICE_TASK_MODE_USB_AUTO_PWR_LV1 )
		{
			DEVICEInfo.usbInfo.suspenLV = DEVICE_TASK_SUSPEND_LV1;
		}
		else if( mode & DEVICE_TASK_MODE_USB_AUTO_PWR_LV2 )
		{
			DEVICEInfo.usbInfo.suspenLV = DEVICE_TASK_SUSPEND_LV2;
		}
		else
		{
			/* When nothing is specified, DEVICE_TASK_MODE_USB_AUTO_PWR_LV2 is valid*/
			DEVICEInfo.usbInfo.suspenLV = DEVICE_TASK_SUSPEND_LV2;
		}
	}

	//========================================================================
	// Request to start the USB storage operation
	//========================================================================
	DEVICEInfo.usbInfo.bEnable = TRUE;
	DEVICEInfo.state = DEVICE_TASK_STATE_USB_NON_CONNECT;		// Change to USB disconnect state
	OS_SetFlg( FLGID_DEVICE, FLG_EVENT_START_USB_DEVICE );

	return DEVICE_TASK_STATUS_SUCCESS;
}

/*
//=============================================================================
// Function_Name: DEVICE_TASK_StopUSB
// description	: Stop USB operation mode
//				: MSG_USB_STOPPED is notified when the USB storage's termination process completed successfully
// argument		: none
// return		: long
//=============================================================================

⌨️ 快捷键说明

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