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

📄 pipef.c

📁 samsung 9908DVD源代码,
💻 C
字号:
/**********************************************************************************
 * pipeF.c
 * coded by hspark@ce.cnu.ac.kr
 * date : 2001/06/23
 * modified by hjahn@ce.cnu.ac.kr
 * date : 2003/03/03
 **********************************************************************************/

#include "kernel\\mk_sys.h"
#include "kernel\\mk_pipeF.h"

#if (defined(_MK_PIPE) && defined(_MK_DDI))

static INT MK_OpenFixedPipeFunction(VOID *pFd);
static INT MK_CloseFixedPipeFunction(VOID *pFd);
static INT MK_ReadFixedPipeFunction(VOID *pFd, VOID *pAddr, INT Length);
static INT MK_WriteFixedPipeFunction(VOID *pFd, VOID *pAddr, INT Length);
static INT MK_IOControlFixedPipeFunction(VOID *pFd, INT Function, INT Arg);

VOID
MK_FixedPipeInitialize(VOID)
{
}

STATUS
MK_CreateFixedPipe(MK_FIXED_PIPE *pPipe, CHAR *pName, VOID *pAddr, INT Count, 
				   UINT Size)
{
	//CHAR pTemp[MK_NAME_MAX + 8];
	STATUS Status;


	if(pPipe->fp_Magic == MK_PIPEF_MAGIC)
	{
#if MK_DEBUG_PRINT
		MK_Panic("MK_CreateFixedPipe() - Magic error!\n");
#endif
		return MK_ERROR;
	}
	
	//MK_BlockCopy(pTemp, pName, MK_NAME_MAX);
	//MK_Strcat(pTemp, "_F");
	//Status = MK_CreateDDI((MK_DDI *)pPipe, pTemp, MK_OpenFixedPipeFunction, 
	Status = MK_CreateDDI((MK_DDI *)pPipe, MK_NULL, MK_OpenFixedPipeFunction, 
		MK_CloseFixedPipeFunction, MK_ReadFixedPipeFunction, 
		MK_WriteFixedPipeFunction, MK_IOControlFixedPipeFunction);
	if( Status < 0)
	{
#if MK_DEBUG_PRINT
		MK_InfoPrintf(MK_TASK_WARNING, "MK_CreateFixedPipe() - DDI is not created! Task(%s)\n", MK_GetCurrentTask()->t_pName);
#endif
		return Status;
	}
	Status = MK_CreateFixedMsgQueue(&pPipe->fp_MsgQF, MK_NULL, pAddr, Count, Size, 
		MK_SERVICE_FIFO);
	//Status = MK_CreateFixedMsgQueue(&pPipe->fp_MsgQF, pTemp, pAddr, Count, Size, 
	//	MK_SERVICE_FIFO);
	if( Status < 0)
	{
		MK_DeleteDDI(&pPipe->fp_DDI);

#if MK_DEBUG_PRINT		
		MK_InfoPrintf(MK_TASK_WARNING, "MK_CreatFixedPipe() - FixedMsgQueue is not created! Task(%s)\n", MK_GetCurrentTask()->t_pName);
#endif
		return Status;
	}

	pPipe->fp_Magic = MK_PIPEF_MAGIC;

	return MK_NO_ERROR;
}

STATUS
MK_DeleteFixedPipe(MK_FIXED_PIPE *pPipe)
{
	if(pPipe->fp_Magic != MK_PIPEF_MAGIC)
	{
#if MK_DEBUG_PRINT
		MK_Panic("MK_DeleteFixedPipe() - Magic error! Task(%s)\n", MK_GetCurrentTask()->t_pName);
#endif
		return MK_RESOURCE_ERROR;
	}

	pPipe->fp_Magic = 0;

	MK_DeleteDDI(&pPipe->fp_DDI);
	MK_DeleteFixedMsgQueue(&pPipe->fp_MsgQF);

	return MK_NO_ERROR;
}

BOOLEAN
MK_IsFixedPipeOpened(MK_FIXED_PIPE *pPipe)
{
	if(pPipe->fp_Magic == MK_PIPEF_MAGIC)
		return TRUE;
	return FALSE;
}

static INT
MK_OpenFixedPipeFunction(VOID *pFd)
{
	MK_FIXED_PIPE *pPipe;

	pPipe = (MK_FIXED_PIPE *)pFd;
	pPipe->fp_Magic = MK_PIPEF_MAGIC;
	return MK_Open(&pPipe->fp_DDI);
}

static INT
MK_CloseFixedPipeFunction(VOID *pFd)
{
	MK_FIXED_PIPE *pPipe;

	pPipe = (MK_FIXED_PIPE *)pFd;

	if(pPipe->fp_Magic != MK_PIPEF_MAGIC)
	{
#if MK_DEBUG_PRINT
		MK_Panic("MK_CloseFixedPipeFunction() - Magic error! Task(%s)\n", MK_GetCurrentTask()->t_pName);
#endif
		return MK_RESOURCE_ERROR;
	}

	pPipe->fp_Magic = 0;

	return MK_Close(&pPipe->fp_DDI);
}

static INT
MK_ReadFixedPipeFunction(VOID *pFd, VOID *pBuf, INT BufSize)
{
	MK_FIXED_PIPE *pPipe;
	UINT	Length;
	STATUS Status;

	pPipe = (MK_FIXED_PIPE *)pFd;
	if(pPipe->fp_Magic != MK_PIPEF_MAGIC)
	{
#if MK_DEBUG_PRINT
		MK_Panic("MK_ReadFixedPipeFunction() - Magic error! Task(%s)\n", MK_GetCurrentTask()->t_pName);
#endif
		return MK_RESOURCE_ERROR;
	}
	Status = MK_FixedMsgQueuePend(&pPipe->fp_MsgQF, pBuf, BufSize, 
		&Length, MK_WAIT_FOREVER);
	if( Status < 0)
	{
#if MK_DEBUG_PRINT
		MK_InfoPrintf(MK_TASK_ERROR, "MK_ReadFixedPipeFunction() - FixedMsgQueuePend is magic error or timeout! Task(%s)\n", MK_GetCurrentTask()->t_pName);
#endif
		 return Status;
	}
	return Length;
}

static INT
MK_WriteFixedPipeFunction(VOID *pFd, VOID *pAddr, INT Length)
{
	MK_FIXED_PIPE *pPipe;
	STATUS Status;

	pPipe = (MK_FIXED_PIPE *)pFd;
	if(pPipe->fp_Magic != MK_PIPEF_MAGIC)
	{
#if MK_DEBUG_PRINT
		MK_Panic("MK_WriteFixedPipeFunction() - Magic error! Task(%s)\n", MK_GetCurrentTask()->t_pName);
#endif
		return MK_RESOURCE_ERROR;
	}
	Status = MK_FixedMsgQueuePost(&pPipe->fp_MsgQF, pAddr, Length,
		MK_WAIT_FOREVER);
	if( Status < 0)
	{
#if MK_DEBUG_PRINT
		MK_Panic("MK_WriteFixedPipeFunction() - FixedMsgQueuePost is magic error or timeout! Task(%s)\n", MK_GetCurrentTask()->t_pName);
#endif
		return Status;
	}
	return Length;
}

static INT
MK_IOControlFixedPipeFunction(VOID *pFd, INT Function, INT Arg)
{
	MK_FIXED_PIPE *pPipe;

	pPipe = (MK_FIXED_PIPE *)pFd;
	if(pPipe->fp_Magic != MK_PIPEF_MAGIC)
	{
#if MK_DEBUG_PRINT
		MK_Panic("MK_IOControlFixedPipeFunction() - Magic error! Task(%s)\n", MK_GetCurrentTask()->t_pName);
#endif
		return MK_RESOURCE_ERROR;
	}

	return MK_NO_ERROR;
}

#endif /* #if (defined(_MK_PIPE) && defined(_MK_DDI)) */

⌨️ 快捷键说明

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