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

📄 rzkcreatepartition.c

📁 zilog的实时操作系统RZK,可以移植到多种处理器上
💻 C
字号:
/*
* File				:	RZKCreatePartition.c
*
* Description		:	This file defines an API called RZKCreatePartition
* 
* 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 "ZMemory.h"
#include "externvar.h"

#define pCurrentThread  ((RZK_TCB_t *) hCurrentThread)

/* Dependencies */
extern void* RZKMemcpy(void *, const void *, RZK_LENGTH_t); // IAR port, UINT changed to RZK_LENGTH_t
extern RZK_HANDLE_t AcquireControlBlock(RZK_TCB_t *,UINT,UINT);
extern void InitializeBufferPointers(RZK_PTR_t pMemory,RZK_PARTITIONHANDLE_t hPartition,UINT uBlockSize);

/** extern variables */
extern RZK_HANDLE_t hCurrentThread;
extern RZK_PARTITION_CB_t  nPartition[] ;   /* Changed on 08-05-03 */

/* Function			:	RZKCreatePartition
*
* Description		:	Creates a memory partition at the specified pointer.
*						The pointer to the memory blocks of the partition 
*						is maintained in a circular buffer.
* 
* Inputs			:	szName-Specifies the name of the memory partition 
*								 to be  created.
*						pMemory-Pointer to the memory area where the 
*								allocation has to start.
*						uMemoryBlocks-The maximum number of memory blocks
*										that the partition can have.
*							
* Outputs			:	Handle to the Memory Partition or NULL on failure.
*							
*
* Dependencies		:	hCurrentThread
*/
RZK_PARTITIONHANDLE_t  RZKCreatePartition
						(
							RZK_NAME_t  szName[MAX_OBJECT_NAME_LEN],			
							RZK_PTR_t pMemory,
							UINT uMemoryBlocks,
							UINT uBlockSize					
						)
{
				
RZK_PARTITION_t *pPartition;

#ifdef RZK_DEBUG
		if((pMemory == NULL) || 
			(uMemoryBlocks == 0) || (uBlockSize == 0))  // IAR port, fixed bug
		{
			pCurrentThread->errNum = RZKERR_INVALID_ARGUMENTS;
			return NULL;
		}
#endif

	pPartition = (RZK_PARTITION_t *)AcquireControlBlock((RZK_TCB_t*)&nPartition[0],
						MAX_PARTITIONS,sizeof(RZK_PARTITION_t ));       /* Changed on 08-05-03 */

#ifndef RZK_PERFORMANCE
	if(pPartition == NULL )
	{
		pCurrentThread->errNum = RZKERR_CB_UNAVAILABLE;
		return NULL;
	}
#endif

#ifdef RZK_KERNEL_AWARE

	RZKMemcpy(pPartition->szName,szName,MAX_OBJECT_NAME_LEN);

#endif  /* KERNEL_AWARE */ 

#ifdef RZK_DEBUG
	pPartition->magic_num = MAGIC_NUM_MEMORY;
#endif

	/*Initialize all the parameters */
	pPartition->uMemoryBlocks = pPartition->uMemoryBlocksLeft = uMemoryBlocks;
	pPartition->uBlockSize = uBlockSize;
	 
	/*Initialize all cirular buffer pointers*/
	pPartition->pStart = pPartition->pRead = pPartition->pWrite = ( RZK_PTR_t *) pMemory;
	pPartition->pEnd = (CADDR_t )pMemory + uMemoryBlocks * sizeof(RZK_PTR_t);

	/* Initialize the circular buffer with the pointers to the memory blocks.pWrite pointer specifies the pointer to the block that can be allocated.  */
	InitializeBufferPointers((RZK_PTR_t)pMemory, pPartition, uBlockSize);

	pPartition->pMemory = pMemory;

	/* Set the uState parameter */
	pPartition->uState = OBJECT_CREATED|OBJECT_BUSY;
	pCurrentThread->errNum = RZKERR_SUCCESS;
	return pPartition;
}

⌨️ 快捷键说明

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