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

📄 sendtoqueueunique.c

📁 zilog的实时操作系统RZK,可以移植到多种处理器上
💻 C
字号:
/*
* File			:	RZKSendToQueue.c
*
* Description	:	This file contains the RZKSendToQueue function 
*					which sends a message to the MQ.
* 
* 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 "ZInterrupt.h"
#include "ZMessageQ.h"
#include "ZScheduler.h"

#define pMessageQueue  ((RZK_MESSAGEQUEUE_t *) hMessageQueue)
#define pCurrentThread  ((RZK_TCB_t *) hCurrentThread)

/** extern functions */
//extern void RZKScheduler();
//extern void UpdateThreadStatus( RZK_TCB_t * hThread,UINT errNum);
extern void InitializeCircularBuffer(RZK_MESSAGEQUEUE_t * );
extern void RemoveFromResourceQueue(RZK_HANDLE_t hControlBlock, RZK_THREADHANDLE_t hThreadToRemove);
extern void WaitOnResourceQueue( RZK_HANDLE_t hControlBlock,UINT16 uBlockingReason,
							TICK_t tBlockTime);
//extern void* RZKMemcpy(void *, const void *, UINT); // IAR commented

/** extern variables */
extern RZK_THREADHANDLE_t hCurrentThread;


/*
* Function		:	RZKSendToQueue
*
* Description	:	This function does a timed blocking send to a queue specified by a
*					valid handle. Blocking of the thread happens when the queue can 
*					not store any more messages, since the maximum length specified
*					during queue creation has been reached. The message is appended
*					to the tail of queue.
* 
* Inputs		:	hMessageQueue  -  handle to the message queue 
*					pMessage - Pointer to the message to send to queue.
*					uSize - Size of the message.
*					tBlockTime - Time for which the thread will block in this queue, 
*																				if it can not send the message immediately.	
*
* Outputs		:	RZKERR_SUCCESS - If the message is successfully copied.
*					RZKERR_CB_BUSY- If the message control block is being exclusively used by another thread. RZKERR_INVALID_HANDLE - If the hMessageQueue parameter is invalid.
*					RZKERR_INVALID_ARGUMENTS - If pMessageQueue  parameters is invalid
*
* Dependencies	:	hCurrentThread
*/

RZK_STATUS_t RZKSendToQueueUnique 
					(
						RZK_MESSAGEQHANDLE_t  hMessageQueue,
						RZK_PTR_t  pMessage,
						COUNT_t uSize, 
						TICK_t tBlockTime
					)
{
	RZK_MESSAGE_PTR_t pTemp;
	RZK_STATE_t uState;
#ifdef RZK_DEBUG
	if((pMessageQueue==NULL) || (pMessageQueue->uState == 0 ) ||
		(pMessageQueue->magic_num != MAGIC_NUM_MESSAGEQ))
	{
		return RZKERR_INVALID_HANDLE;
	}
	if ((( pMessageQueue->uTotalMessageSize) <  uSize ) || ( pMessage == NULL))
		return RZKERR_INVALID_ARGUMENTS;

#endif

#ifndef RZK_PERFORMANCE
	if (!(pMessageQueue->uState & OBJECT_CREATED))
			return RZKERR_CB_BUSY;
#endif

	uState = RZKDisablePreemption();

	pTemp = pMessageQueue->pStart;

	while(pTemp != pMessageQueue->pWrite)
		if(
			(!memcmp(pTemp,&uSize,sizeof(COUNT_t))) &&
			(!memcmp((INT8 *)pTemp + sizeof(COUNT_t),pMessage,uSize) )
			)
		return (RZKERR_MSG_PRESENT);

	RZKSendToQueue(hMessageQueue,pMessage,uSize,tBlockTime);

	RZKRestorePreemption(uState);

	return RZKERR_SUCCESS;
} /* end of RZKSendToQueue */

⌨️ 快捷键说明

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