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

📄 os_msg.c

📁 引入事件驱动观念的抢占式多任务微型实时内核——MicroStar的设计与实现;提出基于事件的优先级这一新概念。
💻 C
字号:
/**************** os_msg.c*******************/
/*            MacroStar 1.0             	*/
/*          Zhengyuquan,2003.7          	*/
/*         All rights reserved          	*/                              
/********************************************/ 
#include "mStar.h"
extern TCB os_tcbs[];

/*
************************************************************
*
*
*
************************************************************
*/
void STDCALL _FAR os_PostMessage(uchar taskId,MSG msg)
{
	PTCB pTCB = os_tcbs + taskId;
    
	os_ASSERT( !(msg&0xE0),POST_INVALID_MSG);
	os_WARNING( !(os_tcbState&os_maskTable[taskId]),POST_MSG_TO_NULL);  

	LOCK_INT_EX( );
	if( msg&0xF0 )
	{
		pTCB->msg[1] |= os_maskTable[msg&0x0F];
		os_rdyState  |= os_maskTable[pTCB->priority];
	}
	else
	{
		pTCB->msg[0] |= os_maskTable[msg];
		os_rdyhState |= os_maskTable[pTCB->priority];
	}
	UNLOCK_INT_EX( );

    os_SetSwitchFlag( );
}

/*
************************************************************
*
*
*
************************************************************
*/
BOOL STDCALL _FAR os_SendMessage(uchar taskId,MSG msg)
{
	TCB*    pTCB  = os_tcbs+taskId;
	uint_16 msgMask = os_maskTable[ msg&0x0F ];
	uint_16 *pMsg = pTCB->msg;

	os_ASSERT( !(msg&0xE0),SEND_INVALID_MSG );
	os_WARNING( !(os_tcbState&os_maskTable[taskId]),SEND_MSG_TO_NULL);  

	if( msg &= 0xF0 )pMsg++;
	
	LOCK_INT( );
	if( !( msgMask&(*pMsg) ) )
	{
		*pMsg |= msgMask;
		if( msg )
			os_rdyState  |= os_maskTable[pTCB->priority];
		else
			os_rdyhState |= os_maskTable[pTCB->priority];
		os_SetSwitchFlag( );
		UNLOCK_INT();
		return os_true;
	}
	UNLOCK_INT();
    return os_false;
}

/*
************************************************************
*
*
*
************************************************************
*/
MSG STDCALL _FAR os_GetMessage( )
{
	uint_16   temp;
	MSG       msg;

	while(1)
	{
		LOCK_INT( );
		if( (temp = os_pCurTCB->msg[0] ) )
		{
			if( (msg = os_fastTable[ HIGHBYTE(temp) ]) == 0xFF)
				msg  = os_fastTable[ LOWBYTE(temp)  ] | 0x08;
			os_pCurTCB->msg[0] ^= os_maskTable[msg];
			UNLOCK_INT( );
			break;
		}
		if( (temp = os_pCurTCB->msg[1] ) )
		{
			if( (msg = os_fastTable[ HIGHBYTE(temp) ]) == 0xFF)
				msg = os_fastTable[ LOWBYTE(temp)  ] | 0x08;
			os_pCurTCB->msg[1] ^= os_maskTable[msg];		
			os_rdyState |= os_curPrioMask;/*robust code*/
			os_rdyhState &= ~os_curPrioMask;
			UNLOCK_INT( );
			if( os_rdyhState&os_slpState )
			    os_Schedule( );
			else
				os_SetSwitchFlag( );
			msg |= 0x10;
			break;
		}
		os_rdyhState &= ~os_curPrioMask;
		os_rdyState  &= ~os_curPrioMask;
		UNLOCK_INT( );
		os_Schedule( );
   }
   return msg;
}

/*
************************************************************
*
*
*
************************************************************
*/
MSG STDCALL _FAR os_PeekMessage( )
{
	uint_16   temp;
	MSG       msg=0xFF;

	LOCK_INT( );

	if( (temp = os_pCurTCB->msg[0] ) )
	{
		if( (msg = os_fastTable[ HIGHBYTE(temp) ]) == 0xFF)
			msg = os_fastTable[ LOWBYTE(temp)  ] | 0x08;
		os_pCurTCB->msg[0] ^= os_maskTable[msg];
	}
	else if( (temp = os_pCurTCB->msg[1] ) )
	{
		if( (msg = os_fastTable[ HIGHBYTE(temp) ]) == 0xFF)
			msg = os_fastTable[ LOWBYTE(temp)  ] | 0x08;
		os_pCurTCB->msg[1] ^= os_maskTable[msg];
		msg |= 0x10;
	}
	UNLOCK_INT( );
	return msg;
}

⌨️ 快捷键说明

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