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

📄 cxmssen1.c

📁 CMEX source code RTOS for atmel atmega128
💻 C
字号:
/*********************************************************

Copyright (c) CMX Company. 1999. All rights reserved

*********************************************************/
/* version 5.30 */

#define CMXMODULE 1

#include <cxfuncs.h>	/* get cmx include header file */
#include <cxextern.h>	/* get cmx include header file */

#ifdef CMXTRACKER
#include <cmxtrack.h>	/* get cmx include header file */
#endif

/*******************************************************************
 General function for sending a message to a mailbox.
 
 wait = 0, do not wait after sending message

 wait = 1, wait after sending message, for receiver to wake us

*******************************************************************/
byte K_I_Mesg_Send_Common(byte mailbox,word16 timecnt,void *mesg,byte wait)
{
	MAILBOX *mail_ptr;
	MSG *link;	/* scratch pointer */

	K_I_Disable_Sched();
	/* see if mailbox within range and that there are
		message links available. */
	if ((mailbox >= MAX_MAILBOXES) || (!message_free))	
		{
		/* error */
#ifdef CMXTRACKER
		if (CMXTRACKER_ON)
			{
			cmxtracker_in3(CXMSSEND_K_ERROR,mailbox,wait);
			}
#endif
		K_I_Func_Return();	/* release task block */
		return(K_ERROR);	/* return good status to caller */
		}
	mail_ptr = &mail_box[mailbox];	/* CMX mailbox handler. */
	if (mail_ptr->waiter)	/* task waiting on this mailbox */
		{
		mail_ptr->waiter->tcbstate = RESUME;	/* allow task to run again */
		if (mail_ptr->waiter->priority < active_priority)
			PREEMPTED;	/* yes, so set the preempted scheduling flag */
		}

	link = message_ptr;	/* link now points to message header */
	message_ptr = link->env_link; /* update linked list */

	if (mail_ptr->first_lnk)	/* see if first link set */
		{
		mail_ptr->next_lnk->link = link;	/* yes, set next link. */
		}
	else
		{
		mail_ptr->first_lnk = link;	/* set first link. */
		/* because this is the first message into the mailbox
			see if mailbox is suppose to notify task that there
			are messages now residing in mailbox. */
		if (mail_ptr->task_num)	/* does task want to be notified? */
			/* yes, go set event. */
			{
#ifdef CMXTRACKER
			if (CMXTRACKER_ON)
				{
				if (locked_out == 2)
					{
					cmxtracker_in1(INT_ACTION);
					}
				}
#endif
			K_Event_Signal(0,mail_ptr->task_num,mail_ptr->event_num);
			}
		}
	mail_ptr->next_lnk = link;	/* set mailbox next link. */
	link->message = (byte *)mesg;	/* load address of message. */
	link->sender = NULL; /* set sender to NULL. This way interrupt will be covered */
	--message_free;	/* decrement message free */

	if (wait)	/* is this the send and wait call function */
		{
		link->sender = activetcb; /* load what task sent message. */
		/* this task will now be suspended. */
#ifdef CMXTRACKER
			if (CMXTRACKER_ON)
				{
				cmxtracker_in5(CXMSSENW_K_OK,mailbox,mesg);
				cmxtracker_in4(CXMSSEND_CALL,mailbox,timecnt);
				}
#endif
		if (K_I_Time_Common(timecnt,SEND_MESG))
			{
#ifdef CMXTRACKER
			if (CMXTRACKER_ON)
				{
				cmxtracker_in2(CXMSSEND_K_TIMEOUT,mailbox);
				}
#endif
			return(K_TIMEOUT);
			}
		else
			{
#ifdef CMXTRACKER
			if (CMXTRACKER_ON)
				{
				cmxtracker_in2(CXMSSEND_K_OK,mailbox);
				}
#endif
			return(K_OK);
			}
		}
	else
		{
		link->sender = NULL; /* set sender to NULL. */
#ifdef CMXTRACKER
			if (CMXTRACKER_ON)
				{
				cmxtracker_in5(CXMSSEND_K_OK1,mailbox,mesg);
				}
#endif
		K_I_Func_Return();	/* release task block */
		return(K_OK);	/* return good status to caller */
		}
}

⌨️ 快捷键说明

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