📄 rzkpeekmessage.c
字号:
/*
* File : RZKPeekMessage.c
*
* Description : This file contains RZKPeekMessage function which peeks into
* the queue to read a message.
*
* 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 <string.h>
#include "ZSysgen.h"
#include "ZTypes.h"
#include "ZThread.h"
#include "ZQueue.h"
#include "ZMessageQ.h"
#define pMessageQueue ((RZK_MESSAGEQUEUE_t *) hMessageQueue)
extern void* RZKMemcpy(void *, const void *, RZK_LENGTH_t); // IAR port, UINT changed to RZK_LENGTH_t
/*
* Function : RZKPeekMessage
*
* Description : Peeks into the specified message queue and copies the message
* from the queue to the specified location and size.
* If the queue is empty it returns immediately.
*
* Inputs : hMessageQueue - handle to the message queue to peek into.
* pMessage - pointer to the memory area where message has to be copied.
* *uSize - size of the message to be copied and contains value of number of bytes
* received after API execution
*
* Outputs : RZKERR_SUCCESS - If the message is successfully copied.
* RZKERR_CB_BUSY- If the message control block is being used by another thread exclusively.
* RZKERR_INVALID_HANDLE - If the hMessageQueue is invalid.
* RZKERR_INVALID_ARGUMENTS - If the pMessage parameter is invalid.
* RZKERR_QUEUE_EMPTY - If the queue is empty.
*
* Dependencies : None
*/
RZK_STATUS_t RZKPeekMessageQueue
(
RZK_MESSAGEQHANDLE_t hMessageQueue,
RZK_PTR_t pMessage,
COUNT_t *uSize // IAR changed from UINT to COUNT_t
)
{
/* Local Variable */
// IAR port
COUNT_t uSizeActual ;
// COUNT_t uSizeActual[sizeof(COUNT_t)];
/* Check for the validity of the arguments */
#ifndef RZK_EFFICIENTQUEUE
#ifdef RZK_DEBUG
if ( (pMessageQueue==NULL) || ( pMessageQueue -> uState == 0 ) ||
( pMessageQueue -> magic_num != MAGIC_NUM_MESSAGEQ))
return RZKERR_INVALID_HANDLE;
if ( pMessage == NULL)
return RZKERR_INVALID_ARGUMENTS;
if ( uSize == NULL)
return RZKERR_INVALID_ARGUMENTS;
#endif
#ifndef RZK_PERFORMANCE
if ( ! ( pMessageQueue->uState & OBJECT_CREATED))
return RZKERR_CB_BUSY;
#endif
#endif
if ( pMessageQueue->uMessageSpaceLeft == pMessageQueue->uQueueLength)
return RZKERR_QUEUE_EMPTY;
// IAR change... and optimization opportunity here...
uSizeActual = (COUNT_t) *((COUNT_t *)(pMessageQueue ->pRead)) ;
// RZKMemcpy (uSizeActual, pMessageQueue ->pRead, sizeof(COUNT_t));
/* If the requested size of message is less than the actual size of message in the Queue
return uSize number of bytes else return the uSizeActual number oif bytes*/
// IAR optimization
if(*uSize > uSizeActual)
*uSize = uSizeActual ;
RZKMemcpy(pMessage,(CADDR_t)pMessageQueue ->pRead+sizeof(COUNT_t) ,*uSize);
/*
if(*uSize < *uSizeActual)
{
RZKMemcpy(pMessage,(CADDR_t)pMessageQueue ->pRead+sizeof(COUNT_t) ,*uSize);
}
else
{
RZKMemcpy(pMessage,(CADDR_t)pMessageQueue ->pRead+sizeof(COUNT_t) ,uSizeActual); // IAR changed
*uSize = *uSizeActual;
}
*/
return RZKERR_SUCCESS;
/* Note that the next receive will not guarantee the same message */
} /* end of RZKPeekMessage */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -