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

📄 msg.c

📁 基于东南大学开发的SEP3203的ARM7中的所有驱动
💻 C
字号:
/*************************************************************************
 *
 *  Copyright (C) Asic Center. 2001
 *  All Rights Reserved
 *
 *  Filename : systask.c
 *  Function : Message Transfer and Manage Message Cache
 *  Revision :
 *          2001/09/21  Pessia      Create this file
 *			2001/10/16	Pessia		Add Malloc Module
 *			2002/4/4	Pessia		Use NULL to replace zero pointer
 ************************************************************************/
#include <stdlib.h>

#include "ros33.h"
#include "sysusr.h"
#include "sysmsg.h"
#include "syserr.h"
#include "systsk.h"
#include "lmalloc.h"

/*************************************************************************
 *	Function Name: 	InitMsgCache()
 *	Param In	:	SysTcb	*psystcb
 *  Result code	:	void
 *	Description	:	Init MsgCache in structure SYSTCB
 *					note: reserved now!
 *************************************************************************/
 void	InitMsgCache(SYSTCB	*psystcb)
 {
 	/* 	to be added */
 }

 /************************************************************************
 *	Function Name: 	GetMsgBlock()
 *	Param In	:	ID id 
 *  Result code	:	T_MSG * 						
 						fail,		return NULL
 *	Description	:	note: reserved now!
 *************************************************************************/	
 static	T_MSG *GetMsgBlock(ID id)
 {
 	/* 	to be added */
 }
 
 /************************************************************************
 *	Function Name: 	RelMsgBlock()
 *	Param In	:	T_MSG *pmsg
 *  Result code	:	void						
 *	Description	:	note: reserved now!
 *************************************************************************/	
 static void RelMsgBlock(T_MSG *pmsg)
 {
 	/* 	to be added */
 }

 
 /************************************************************************
 *	Function Name: 	SendMessage()
 *	Param In	:	ID taskid		: Destination
 *					PMSG pmsg 		: Message
 *  Result code	:	ER
 *						no free message block	,return E_NOMEM
 *						snn_msg error			,return E_SYS
 *						success					,return E_OK
 *	Description	:	system task receive and handle event infinite
 *************************************************************************/	
 STATUS	SysSendMessage(ID taskid, PMSG pmsg)
 {
 	T_MSG	*newpmb;
 	PMSG	newpmsg;
 	
 	/* Get one message block from task whose ID is taskid */
 	newpmb = (T_MSG *)SysLmalloc(sizeof(T_MSG));
//// 	newpmb = (T_MSG *)malloc(sizeof(T_MSG));		////malloc is replaced by sysLmalloc
 	if(newpmb == NULL)
 		return E_NOMEM;
 	
 	/* we should set this item to be zero!!! */
 	newpmb->pNxt = NULL;
 	
 	/* copy message content from pmsg to newpmsg */
 	newpmsg = (PMSG)&newpmb->msgcont;
 	newpmsg->message = pmsg->message;
 	newpmsg->lparam = pmsg->lparam;
 	newpmsg->data = pmsg->data;
 	newpmsg->wparam = pmsg->wparam;
 	
 	/* Send message */
 	/* id of mbx is task's id */
 	if(snd_msg(taskid, newpmb) == E_OK)
 	{
 		/* if destination of message is System Task, we should set SYS_EVENT */ 		
		if(taskid == SYSTASK_ID)
 			set_flg(SYS_EVENT, TASKMSG_FLG);
 		
 		return SYS_OK;
 	}
 	
//	SysLfree( newpmb );
	free( newpmb );

 	return SYS_ERR;
 }
 
 
 /************************************************************************
 *	Function Name: 	RecvMessage()
 *	Param In	:	PMSG pmsg 
 *					TMO timeout
 *  Result code	:	ER
 *						success			,return E_OK
 *						timeout			,return E_TMOUT
 *						trcv_msg fail	,return E_SYS
 *	Description	:	system task receive and handle event infinite
 *************************************************************************/	
 STATUS	SysRecvMessage(PMSG pmsg, int timeout)
 {
 	T_MSG	*pgetmb;
 	PMSG	pgetmsg;
 	ID		id;
 	STATUS	error;
 	
 	get_tid(&id);	/* current task's ID */
 	
 	/* id of mbx is task's id */
 	error = trcv_msg(&pgetmb, id, timeout);
 	if(error == E_OK)
 	{
 		pgetmsg = (PMSG)&pgetmb->msgcont;
  		pmsg->message = pgetmsg->message;
	 	pmsg->lparam = pgetmsg->lparam;
	 	pmsg->data = pgetmsg->data;
	 	pmsg->wparam = pgetmsg->wparam;
	 	
//	 	SysLfree(pgetmb);
	 	free(pgetmb);
 		return SYS_OK;
 	}else
 		pmsg = NULL;
 	
 	if(error == E_TMOUT)
 		return SYS_TMOUT;
 	
 	return SYS_ERR; 	
 }
 
 
 /************************************************************************
 *	Function Name: 	SendMessageTo()
 *	Param In	:	ID mbxid		: Destination
 *					PMSG pmsg 		: Message
 *  Result code	:	ER
 *						no free message block	,return E_NOMEM
 *						snn_msg error			,return E_SYS
 *						success					,return E_OK
 *	Description	:	system task receive and handle event infinite
 *************************************************************************/	
 STATUS	SysSendMessageTo(ID mbxid, PMSG pmsg)
 {
 	T_MSG	*newpmb;
 	PMSG	newpmsg;
 	
 	/* Get one message block from task whose ID is taskid */
 	newpmb = (T_MSG *)SysLmalloc(sizeof(T_MSG));
//// 	newpmb = (T_MSG *)malloc(sizeof(T_MSG));			////malloc is replaced by sysLmalloc
 	if(newpmb == NULL)
 		return E_NOMEM;
 		
 	/* we should set this item to be zero!!! */
 	newpmb->pNxt = NULL;
 	
 	/* copy message content from pmsg to newpmsg */
 	newpmsg = (PMSG)&newpmb->msgcont;
 	newpmsg->message = pmsg->message;
 	newpmsg->lparam = pmsg->lparam;
 	newpmsg->data = pmsg->data;
 	newpmsg->wparam = pmsg->wparam;
 	
 	if(snd_msg(mbxid, newpmb) == E_OK)
 	{
 		/* here we think that system task will not use user-defined mailbox */
 		/* we don't set_flg SYS_EVENT */
 		return SYS_OK;
 	}
 		
 	return SYS_ERR;
 }
 
 /************************************************************************
 *	Function Name: 	RecvMessageFrom()
 *	Param In	:	ID mbxid
 *					PMSG pmsg 
 *					TMO timeout
 *  Result code	:	ER
 *						success			,return E_OK
 *						timeout			,return E_TMOUT
 *						trcv_msg fail	,return E_SYS
 *	Description	:	system task receive and handle event infinite
 *************************************************************************/	
 STATUS	SysRecvMessageFrom(ID mbxid, PMSG pmsg, int timeout)
 {
 	T_MSG	*pgetmb;
 	PMSG	pgetmsg;
 	//ID		id;
 	STATUS	error;
 	
 	/* id of mbx is task's id */
 	error = trcv_msg(&pgetmb, mbxid, timeout);
 	if(error == E_OK)
 	{
 		pgetmsg = (PMSG)&pgetmb->msgcont;
 		pmsg->message = pgetmsg->message;
	 	pmsg->lparam = pgetmsg->lparam;
	 	pmsg->data = pgetmsg->data;
	 	pmsg->wparam = pgetmsg->wparam;
	 	
//	 	SysLfree(pgetmb);
	 	free(pgetmb);
 		return SYS_OK;
 	}else
 		pmsg = NULL;
 	
 	if(error == E_TMOUT)
 		return SYS_TMOUT;
 	
 	return SYS_ERR; 	
 }
 

⌨️ 快捷键说明

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