📄 rzkcreatequeue.c
字号:
/*
* File : RZKCreateQueue.c
*
* Description : This file contains RZKCreateQueue function which creates
* a message queue with the given parameters
*
* 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 <stdio.h>
#include <string.h>
#include "ZSysgen.h"
#include "ZTypes.h"
#include "ZThread.h"
#include "ZQueue.h"
#include "ZMessageQ.h"
#include "externvar.h"
#define pCurrentThread ((RZK_TCB_t *) hCurrentThread)
/** extern functions */
extern RZK_HANDLE_t AcquireControlBlock(RZK_TCB_t *,UINT,UINT);
extern void InitializeCircularBuffer(RZK_MESSAGEQUEUE_t * pMessageQueue);
extern void* RZKMemcpy(void *, const void *, RZK_LENGTH_t); // IAR port, UINT changed to RZK_LENGTH_t
/** extern variables */
extern RZK_MQ_CB_t nMessageQueue[];
extern RZK_HANDLE_t hCurrentThread;
/*
* Function : RZKCreateQueue
*
* Description : This function creates a message queue with the given parameters
*
* Inputs : szName - name of message queue.
* uQueueLength - no. of max. messages in queue.
* pMessage - pointer to message queue area.
* uMaxSizeOfMessage - max. size of each message.
* etAttrib - receiving attributes.
*
* Outputs : Handle to message queue or NULL on failure.
*
* Dependencies : hCurrentThread
*/
RZK_MESSAGEQHANDLE_t RZKCreateQueue
(
RZK_NAME_t szName[MAX_OBJECT_NAME_LEN],
COUNT_t uQueueLength,
RZK_PTR_t pMessage,
COUNT_t uMaxSizeOfMessage,
RZK_RECV_ATTRIB_et etAttrib
)
{
RZK_MESSAGEQUEUE_t * pMessageQueue;
#ifdef RZK_DEBUG
if ( pMessage == NULL ) {
pCurrentThread -> errNum = RZKERR_INVALID_ARGUMENTS;
return NULL;
}
#endif
/* Acquire message queue control block*/
pMessageQueue=(RZK_MESSAGEQUEUE_t *)(AcquireControlBlock
( ( RZK_TCB_t *) &nMessageQueue[0],
MAX_MESSAGEQS,
sizeof(RZK_MESSAGEQUEUE_t )
));
#ifndef RZK_PERFORMANCE
if ( pMessageQueue == NULL)
{
pCurrentThread -> errNum = RZKERR_CB_UNAVAILABLE;
return NULL;
}
#endif
/* Set the values in the control block */
#ifdef RZK_KERNEL_AWARE
RZKMemcpy(pMessageQueue -> szName, szName, MAX_OBJECT_NAME_LEN);
#endif /* KERNEL_AWARE */
#ifdef RZK_DEBUG
pMessageQueue->magic_num = MAGIC_NUM_MESSAGEQ;
/* Initialize the start and end pointers of the queue to beginning of the queue*/
#endif
pMessageQueue ->uTotalMessageSize = uMaxSizeOfMessage;
pMessageQueue ->pStart = pMessage;
// pMessageQueue ->pEnd = (CADDR_t)pMessageQueue ->pStart + (uQueueLength * pMessageQueue ->uTotalMessageSize) + (uQueueLength * sizeof(RZK_PTR_t));
pMessageQueue ->pEnd = (CADDR_t)pMessageQueue ->pStart + (uQueueLength * uMaxSizeOfMessage) + (uQueueLength * sizeof(COUNT_t)); //IAR port
InitializeCircularBuffer(pMessageQueue);
/* Initialize the message queue parameters */
pMessageQueue -> uQueueLength = pMessageQueue -> uMessageSpaceLeft= uQueueLength;
pMessageQueue ->etReceiveType = etAttrib;
/* Some initializations when thread gets created. Old thread's values must not be retained here */
pMessageQueue ->pResNext = pMessageQueue ->pLastPosition = ( RZK_TCB_t * ) NULL;
pMessageQueue ->uMaxMessageSize = 0;
/* Some initializations when thread gets created. Old thread's values must not be retained here */
pMessageQueue -> uState = (etAttrib == RECV_ORDER_FIFO)?OBJECT_CREATED | OBJECT_BUSY:OBJECT_CREATED | OBJECT_BUSY | OBJECT_RECV_PRIORITY;
pCurrentThread -> errNum = RZKERR_SUCCESS;
return pMessageQueue;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -