📄 rzkpendoneventgroup.c
字号:
/*
* File : RZKPendOnEventGroup
*
* 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"
#define pCurrentThread ((RZK_TCB_t *) hCurrentThread)
#define pEventGroup ((RZK_EVENTGROUP_t *) hEventGroup)
/** extern functions */
//extern void RZKScheduler();
extern void AddToResourceQueueBeg( RZK_HANDLE_t hInsertionPos,RZK_THREADHANDLE_t hThread);
extern void AddToResourceQueue( RZK_HANDLE_t hInsertionPos,RZK_THREADHANDLE_t hThread);
extern void WaitOnResourceQueue(RZK_HANDLE_t hControlBlock,UINT16 uBlockingReason,TICK_t tBlockTime);
/** extern variables */
extern RZK_THREADHANDLE_t hCurrentThread;
/* Function : RZKPendOnEventGroup
*
* Description : The calling thread will either retrieve a
* logic operation based upon sufficient
* combination of successful events from the
* event flag group or will do a timed
* blocking pend until the requested events
* are set.
*
* Inputs : hEventGroup - Specifies the handle to the EventGroup to pend on.
* TICK_t tBlockTime - Maximum time to wait for events.
* etOperation - Specifies if the event has to be OR or AND
* with the existing event value.
*
* Outputs : RZKERR_SUCCESS - The operation completed successfully.
* RZKERR_TIMEOUT - The timeout occurred before the event could be received.
* RZKERR_CB_BUSY - Specifies the object is for exclusive use.
*
* Dependencies : hCurrentThread
*/
RZK_STATUS_t RZKPendOnEventGroup
(
RZK_EVENTHANDLE_t hEventGroup,
RZK_EVENT_t eEvent,
TICK_t tBlockTime,
RZK_EVENT_OPERATION_et etOperation
)
{
/* Local Variables */
UINT8 uEventFlag ;
#ifdef RZK_DEBUG /* Check for INVALID_HANDLE */
if ((pEventGroup == NULL)||(pEventGroup -> uState == 0 )||
(pEventGroup -> magic_num != MAGIC_NUM_EVENT))
return RZKERR_INVALID_HANDLE;
#endif
#ifndef RZK_PERFORMANCE
if(!(pEventGroup->uState & OBJECT_CREATED))
return RZKERR_CB_BUSY;
#endif
/* set the uEventFlag to FALSE */
uEventFlag = RZK_FALSE;
/* check if etOperation is EVENT_OR */
if(etOperation & EVENT_OR)
{
/* check if eEventsReceived of hEventGroup control block contains all of the eEvents specified,then set uEventFlag to TRUE.*/
if(eEvent & pEventGroup -> eEventsReceived)
uEventFlag = RZK_TRUE;
}
else
{
/* check if eEventsReceived of hEventGroup control block contains any of the eEvents specified,then set uEventFlag to TRUE.*/
if(eEvent ==(eEvent & pEventGroup -> eEventsReceived))
uEventFlag = RZK_TRUE;
}
if(uEventFlag == RZK_FALSE)
{
RZK_STATE_t uState;
if(tBlockTime == 0)
{
pCurrentThread -> errNum = RZKERR_TIMEOUT;
return RZKERR_TIMEOUT;
}
uState = RZKDisablePreemption();
pCurrentThread->etEventOperation = etOperation;
pCurrentThread->eEventsRequested = eEvent;
(pEventGroup->pResNext == NULL)? AddToResourceQueueBeg(pEventGroup,hCurrentThread)
: AddToResourceQueue(pEventGroup->pLastPosition,hCurrentThread);
pEventGroup->pLastPosition = pCurrentThread;
WaitOnResourceQueue(pEventGroup ,BLOCK_PENDEVENTGROUP, tBlockTime);
/* Reset the running bit in the TCB */
pCurrentThread -> uState &= ~(THREAD_RUNNING);
/* Call Scheduler */
RZKRestorePreemption(uState);
}
else
pCurrentThread -> errNum = RZKERR_SUCCESS;
/*If the consume option is specified and the object is in created state
set the eEventsReceived bit to zero.*/
if ((etOperation & EVENT_CONSUME) && (pEventGroup -> uState & OBJECT_CREATED))
pEventGroup -> eEventsReceived = 0;
return pCurrentThread -> errNum;
} /* End of RZKPendOnEventGroup */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -