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

📄 rzkposteventgroup.c

📁 zilog的实时操作系统RZK,可以移植到多种处理器上
💻 C
字号:
/*
* File				:	RZKPostEventGroup.c
*
* Description		:	This file contains definition of RZKPendOnEventGroup API
* 
* Copyright 2004 ZiLOG Inc.  ALL RIGHTS RESERVED.
*
* This file contains unpublished confidential and proprietary information
* of ZiLOG, Inc.
* NO PART OF THIS WORK MAY BE DUPLICATED, STORED, PUBLISHED OR DISCLOSED 
* IN ANY FORM WITHOUT THE PRIOR WRITTEN CONSENT OF ZiLOG, INC.
* This is not a license and no use of any kind of this work is authorized
* in the absence of a written license granted by ZiLOG, Inc. in ZiLOG's 
* sole discretion 
*/
#include "ZSysgen.h"
#include "ZTypes.h"
#include "ZThread.h"
#include "ZQueue.h"
#include "ZEventgroup.h"
#include "externvar.h"
#include "ZScheduler.h"
#include "ZInterrupt.h"

#ifdef  RZK_DEBUG
	#define EventOperation(pEventsReceived, etOperation, eEvent)					\
		switch (etOperation)														\
			{																		\
				case EVENT_AND:														\
					pEventsReceived &= eEvent;										\
						break;														\
				case EVENT_OR :														\
					pEventsReceived |= eEvent;										\
						break;														\
				case EVENT_XOR :													\
					pEventsReceived ^= eEvent;										\
						break;														\
				default	:															\
					RZKRestorePreemption(uState);							\
					return RZKERR_INVALID_OPERATION;								\
			}
#else
	#define EventOperation(pEventsReceived, etOperation, eEvent)					\
		switch (etOperation)														\
			{																		\
				case EVENT_AND:														\
					pEventsReceived &= eEvent;										\
						break;														\
				case EVENT_OR :														\
					pEventsReceived |= eEvent;										\
						break;														\
				case EVENT_XOR :													\
					pEventsReceived ^= eEvent;										\
						break;														\
			}
#endif /* RZK_DEBUG */

#define pEventGroup  ((RZK_EVENTGROUP_t *) hEventGroup)

/** extern functions */
//extern void RZKScheduler();
extern void RemoveFromResourceQueue(RZK_HANDLE_t hControlBlock, RZK_THREADHANDLE_t hThreadToRemove);

/* Function			:	RZKPostToEventGroup
*
* Description		:	This function sends the specified events to Event Group. 
*						It also performs the operation (AND, OR, XOR) specified
*						with current events to sent one.
* 
* Inputs			:	hEventgroup - handle to Event Group
*						eEvent - event to set
*						etOperation - specifies operation to be performed
*						on event value
*							
* Outputs			:	RZKERR_SUCCESS - on successful posting.
*						RZKERR_INVALID_HANDLE - if handle is invalid.
*						RZKERR_INVALID_OPERATION -if operation is invalid.
*						RZKERR_CB_BUSY - the control block is for exclusive use 
*
* Dependencies		:	hCurrentThread
*/
RZK_STATUS_t RZKPostToEventGroup
			(
				RZK_EVENTHANDLE_t hEventGroup,
				RZK_EVENT_t eEvent,
				RZK_EVENT_OPERATION_et etOperation
			)
{
	/* Local Variables */
	RZK_TCB_t *pTemp;
	RZK_EVENT_t l_eEventsRequested;
	UINT8 cUpdateThread = 0;
	RZK_STATE_t uState;

	/* Validate the handle passed */
#ifdef RZK_DEBUG
		if((pEventGroup == NULL)||(pEventGroup -> uState == 0) || 
			(pEventGroup -> magic_num != MAGIC_NUM_EVENT))
				return RZKERR_INVALID_HANDLE;
#endif /* RZK_DEBUG */

#ifndef RZK_PERFORMANCE
		if(!(pEventGroup -> uState & OBJECT_CREATED))
			return RZKERR_CB_BUSY;
#endif
		/* Perform an AND with the user specified eEvent to the Event Groups uMask */
		eEvent &= pEventGroup -> uMask;
		uState = RZKDisablePreemption();
		/* Perform AND/OR/ XOR operation on the
		eEventsReceived parameter of the Event Group with the above events to be posted. */

		EventOperation(pEventGroup->eEventsReceived, etOperation, eEvent)

		/* check the threads which are pending on the Event Group. */
		pTemp = pEventGroup -> pResNext;

		/* Do not call the scheduler, Restore Preemption and return if there were no threads pending on the evengroup */
		while(pTemp != NULL)
		{
			/* Check if all of the events requested are posted from its TCB Event Requested */
			l_eEventsRequested = pTemp->eEventsRequested;
			if (pTemp->etEventOperation & EVENT_OR)
			{ 
				/* If the Result of the below AND is non-zero implies at least 
				one event is set */
				if((l_eEventsRequested & pEventGroup->eEventsReceived) != 0)	
					cUpdateThread = 1;
			}
			else
			{
				/* If the Result of the below AND is equal to the requested event
				implies all events are set */
				if(l_eEventsRequested == (l_eEventsRequested & pEventGroup->eEventsReceived))
					cUpdateThread = 1;
			}

			if(cUpdateThread)
			{
				UpdateThreadStatus(pTemp,RZKERR_SUCCESS);
				RemoveFromResourceQueue(pEventGroup,pTemp);
				cUpdateThread = 0;
			}

			pTemp = pTemp -> pResNext;
		} /* end of while loop */

		RZKRestorePreemption(uState);
		return RZKERR_SUCCESS;
}/* End of RZKPostEventGroup */

⌨️ 快捷键说明

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