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

📄 cxmswat.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

/**********************************************************
 The following is the generalize message wait function

 is_get = 0, means to wait for message, with possible timeout

 is_get = 1, means don't wait for message, if none. 

**********************************************************/
void * K_I_Mesg_Wait_Common(byte mailbox,word16 timecnt,byte is_get)
{
	MAILBOX *mail_ptr;
	byte *copy_ptr;
	MSG *link;

	if (mailbox >= MAX_MAILBOXES)	/* see if mailbox number OK. */
		{
#ifdef CMXTRACKER
		if (CMXTRACKER_ON)
			{
			cmxtracker_in3(CXMSWATM_K_ERROR,mailbox,is_get);
			}
#endif
		return(NULL);	/* no, return null idicating error. */
		}
	K_I_Disable_Sched();	/* set task block. */
	mail_ptr = &mail_box[mailbox];	/* address of the CMX mailbox handler. */
	if (mail_ptr->waiter)	/* see if another task already "owns" this mailbox. */
		{
#ifdef CMXTRACKER
		if (CMXTRACKER_ON)
			{
			cmxtracker_in3(CXMSWATM_MAILBOX_K_ERROR,mailbox,is_get);
			}
#endif
		K_I_Func_Return();	/* release task block. */
		return(NULL);	/* return error, for only one task may wait on mailbox. */
		}
	if (!mail_ptr->first_lnk) 	/* any messages present in mailbox, null = no */
		{
		if (is_get)	/* K_Mesg_Get function used, do not wait */
			{
#ifdef CMXTRACKER
		if (CMXTRACKER_ON)
			{
			cmxtracker_in2(CXMSGET_NOMESG_K_ERROR,mailbox);
			}
#endif
			K_I_Func_Return();	/* release task block. */
			return(NULL);	/* return error. */
			}
		mail_ptr->waiter = activetcb;	/* identify who "owns" mailbox. */
#ifdef CMXTRACKER
		if (CMXTRACKER_ON)
			{
			cmxtracker_in4(CXMSWATM_CALL,mailbox,timecnt);
			}
#endif
		K_I_Time_Common(timecnt,WAIT_MESG);	/* go suspend task. */

		/* task will be return to here by the K_I_Time_Common function. */
		mail_ptr->waiter = NULL;	/* now task will NOT own mailbox. */
		/* test to see if time expired or task forcefully woken, prior
			to a message being set to this mailbox. */
		if (activetcb->tcbstate & TIME_EXPIRED)
			{
#ifdef CMXTRACKER
		if (CMXTRACKER_ON)
			{
			cmxtracker_in2(CXMSWATM_NOMESG_K_ERROR,mailbox);
			}
#endif
			return(NULL);	/* yes, pass back null, indicating no message. */
			}
		else
			{
			K_I_Disable_Sched();	/* set task lock */
			}
		}

	link = mail_ptr->first_lnk;	/* get first link. */
	link->env_link = message_ptr->env_link; /* re-arrange linked list. */
	message_ptr->env_link = link;
	message_free++;	/* increment message free counter. */

	copy_ptr = link->message;		/* address of message */
	activetcb->mesg_sender = link->sender;	/* what task sent this message. */

	/* update link to point to next message link, also test if more messages
		present. */
	if ((mail_ptr->first_lnk = link->link)) 
		{
		if (mail_ptr->task_num)	/* see if mailbox is suppose to signal event,
											that it has messages. */
			/* yes, then go set proper event bit. */
			K_Event_Signal(0,mail_ptr->task_num,mail_ptr->event_num);
		}
	link->link = NULL;	/* set message link to NULL. */
#ifdef CMXTRACKER
		if (CMXTRACKER_ON)
			{
			if (is_get)
				cmxtracker_in5(CXMSGET_K_OK,mailbox,copy_ptr);
			else
				cmxtracker_in5(CXMSWATM_K_OK,mailbox,copy_ptr);
			}
#endif
	K_I_Func_Return();	/* release task block */
	return((void *)copy_ptr);	/* return good status to caller */
}

⌨️ 快捷键说明

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