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

📄 exdevice.c

📁 M-System DOC(Disk on a Chip) Flash芯片映像读写工具, 可以进行二片Flash芯片的内容互相拷贝, 提高烧录程序的效率.
💻 C
📖 第 1 页 / 共 2 页
字号:
#include "exdevice.h"
#include "exos.h"
/*---------------------------------------------------------------------------------*/
static ExStatus exstat;

/*---------------------------------------------------------------------------------*/
#ifdef EX_USE_CLOSE_ALL_DEVICES

static ExDevice*pCloseAllList[MAX_DEVICES];
ExStatus ExAddToCloseAllList( ExDevice* dev, ExDeviceType type );
ExStatus ExRemoveFromCloseAllList( ExDevice* dev );

#else /* EX_USE_CLOSE_ALL_DEVICES */

#define ExAddToCloseAllList( dev, type )          EX_OK
#define ExRemoveFromCloseAllList( dev, type )	  EX_OK

#endif /* EX_USE_CLOSE_ALL_DEVICES */


/*---------------------------------------------------------------------------------*/
#ifdef EX_USE_CLOSE_ALL_DEVICES

/*---------------------------------------------------------------------------------*/
/***********************************************************************
 * Name : ExAddToCloseAllList
 *   Add a device to a List of devices that will be closed when
 *   the function ExCloseAllDevices will be called.
 *
 * Parameters:
 *   dev   - pointer to device
 *	 type  - type of device
 *
 * Outputs:
 *   ExStatus -  EX_OK : device added to close list
 *				 EX_MALLOC_ERROR : device was not added to close list
 ***********************************************************************/
ExStatus ExAddToCloseAllList(ExDevice*dev,ExDeviceType type)
{
	static EXBOOL fInit=EXFALSE;
	EXWORD w;

	if(!fInit)
	{
		for(w=0;w<MAX_DEVICES;w++)
			pCloseAllList[w]=EXNULL;
		fInit=EXTRUE;
	}

	dev->type=type;
	for(w=0;w<MAX_DEVICES;w++)
		if(pCloseAllList[w]==EXNULL)
		{
			pCloseAllList[w]=dev;
			dev->wCloseAllEntry=w;
			return EX_OK;
		}
	return EX_MALLOC_ERROR;
}

/***********************************************************************
 * Name : ExRemoveFromCloseAllList
 *   remove a device from a List of devices that will be closed when
 *   the function ExCloseAllDevices will be called.
 *
 * Parameters:
 *   dev   - pointer to device
 *
 * Outputs:
 *   ExStatus -  EX_OK : device removed from close list
 *
 ***********************************************************************/
ExStatus ExRemoveFromCloseAllList(ExDevice*dev)
{
	pCloseAllList[dev->wCloseAllEntry]=EXNULL;
	return EX_OK;
}
/***********************************************************************
 * Name : ExCloseAllDevices
 *   Close all the devices that are in the list of devices to be closed
 *
 *
 * Parameters:
 *   none
 *
 * Outputs:
 *   ExStatus -  EX_OK
 *
 ***********************************************************************/

/*---------------------------------------------------------------------------------*/
ExStatus EXAPI ExCloseAllDevices(void)
{
	EXWORD w;
	for(w=0;w<MAX_DEVICES;w++)
		if(pCloseAllList[w]!=EXNULL)
		{
			switch(pCloseAllList[w]->type)
			{
#ifdef EX_USE_COMMAND_LINE_DEVICE
			case EX_COMMAND_LINE_DEVICE:
				CloseCmdLineDevice(pCloseAllList[w]);
				break;
#endif /* EX_USE_COMMAND_LINE_DEVICE */
#ifdef EX_USE_MSG_DEVICE
			case EX_MSG_DEVICE:
				CloseMsgDevice(pCloseAllList[w]);
				break;
#endif /* EX_USE_MSG_DEVICE */
#ifdef EX_USE_ERROR_MSG_DEVICE
			case EX_ERROR_MSG_DEVICE:
				CloseErrorMsgDevice(pCloseAllList[w]);
				break;
#endif	/* EX_USE_ERROR_MSG_DEVICE */
#ifdef EX_USE_SERIAL_DEVICE
			case EX_SERIAL_READ_DEVICE:
				CloseReadSerialFileDevice(pCloseAllList[w]);
				break;
			case EX_SERIAL_WRITE_DEVICE:
				CloseWriteSerialFileDevice(pCloseAllList[w]);
				break;
#endif	/* EX_USE_SERIAL_DEVICE */
#ifdef EX_USE_PROGRESS_BAR_DEVICE
			case EX_PROGRESS_BAR_DEVICE:
				ClosePrgBarDevice(pCloseAllList[w]);
				break;
#endif	/* EX_USE_PROGRESS_BAR_DEVICE */
#ifdef EX_USE_USER_INPUT
			case EX_USER_INPUT_DEVICE:
				CloseUserInputDevice(pCloseAllList[w]);
				break;
#endif
			}
		}
	return EX_OK;
}
#endif /* EX_USE_CLOSE_ALL_DEVICES */


/*---------------------------------------------------------------------------------*/
/* Command line device functions */
#ifdef EX_USE_COMMAND_LINE_DEVICE
/***********************************************************************
 * Name : OpenCmdLineDevice
 *   open command line device
 *
 *
 * Parameters:
 *   pDevice  - pointer to a device
 *
 * Outputs:
 *   ExStatus -  status of the operation
 *
 ***********************************************************************/

ExStatus EXAPI OpenCmdLineDevice( ExDevice* pDevice )
{
	if( ( exstat = ExOsOpenCmdLineDevice( &pDevice->data ) ) != EX_OK )
		return exstat;
	return ExAddToCloseAllList( pDevice, EX_COMMAND_LINE_DEVICE );
}
/***********************************************************************
 * Name : CloseCmdLineDevice
 *   close command line device
 *
 *
 * Parameters:
 *   pDevice  - pointer to a device
 *
 * Outputs:
 *   ExStatus -  status of the operation
 *
 ***********************************************************************/

ExStatus EXAPI CloseCmdLineDevice( ExDevice* pDevice )
{
	ExRemoveFromCloseAllList( pDevice );
	return ExOsCloseCmdLineDevice( pDevice->data );
}
/***********************************************************************
 * Name : ReadCmdLineDevice
 *   Read command line device
 *
 *
 * Parameters:
 *   pDevice  - pointer to a device
 *
 * Outputs:
 *   ExStatus -  status of the operation
 *
 ***********************************************************************/

ExStatus EXAPI ReadCmdLineDevice( ExDevice* pDevice, EXWORD argc, void** retCommand )
{
	return ExOsReadCmdLineDevice( pDevice->data, argc, retCommand );
}

#endif	/* EX_USE_COMMAND_LINE_DEVICE */

/*---------------------------------------------------------------------------------*/
/* Message device functions */

#ifdef EX_USE_MSG_DEVICE

/***********************************************************************
 * Name : OpenMsgDevice
 *   Open message device
 *
 *
 * Parameters:
 *   pDevice  - pointer to a device
 *
 * Outputs:
 *   ExStatus -  status of the operation
 *
 ***********************************************************************/
ExStatus EXAPI OpenMsgDevice( ExDevice* pDevice )
{
	if( ( exstat = ExOsOpenMsgDevice( &pDevice->data ) ) != EX_OK )
		return exstat;
	return ExAddToCloseAllList( pDevice, EX_MSG_DEVICE );
}
/***********************************************************************
 * Name : CloseMsgDevice
 *   Close message device
 *
 *
 * Parameters:
 *   pDevice  - pointer to a device
 *
 * Outputs:
 *   ExStatus -  status of the operation
 *
 ***********************************************************************/

ExStatus EXAPI CloseMsgDevice( ExDevice* pDevice )
{
	ExRemoveFromCloseAllList( pDevice );
	return ExOsCloseMsgDevice( pDevice->data );
}

/***********************************************************************
 * Name : WriteMsgDevice
 *   Write to message device
 *
 *
 * Parameters:
 *   pDevice  - pointer to a device
 *	 pStr	  - pointer to string that will be send to message device
 * Outputs:
 *   ExStatus -  status of the operation
 *
 ***********************************************************************/
ExStatus EXAPI WriteMsgDevice( ExDevice* pDevice, void* pStr )
{
	return ExOsWriteMsgDevice( pDevice->data, (EXCHAR*)pStr );
}

#endif /* EX_USE_MSG_DEVICE */

/*---------------------------------------------------------------------------------*/
/* Error massage device functions */

#ifdef EX_USE_ERROR_MSG_DEVICE

/***********************************************************************
 * Name : OpenErrorMsgDevice
 *   Open Error Message Device
 *     (It can be leds or 7-segments in a certain board)
 *
 * Parameters:
 *   pDevice  - pointer to a device
 *
 * Outputs:
 *   ExStatus -  status of the operation
 *
 ***********************************************************************/
ExStatus EXAPI OpenErrorMsgDevice( ExDevice* pDevice )
{
	if( ( exstat = ExOsOpenErrorMsgDevice( &pDevice->data ) ) != EX_OK )
		return exstat;
	return ExAddToCloseAllList( pDevice, EX_ERROR_MSG_DEVICE );
}
/***********************************************************************
 * Name : CloseErrorMsgDevice
 *   Close Error Message Device
 *
 *
 * Parameters:
 *   pDevice  - pointer to a device
 *
 * Outputs:
 *   ExStatus -  status of the operation
 *

⌨️ 快捷键说明

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