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

📄 rzkcreateregion.c

📁 zilog的实时操作系统RZK,可以移植到多种处理器上
💻 C
字号:
/*
* File			:	RZKCreateRegion.c
*
* Description	:	The file contains RZKCreateRegion function that 
*					creates a region with the given initial values
*
* 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 "ZRegion.h"
#include "externvar.h"
#include "ZInterrupt.h"

#define pCurrentThread ((RZK_TCB_t *) hCurrentThread)

/** extern functions */
extern RZK_HANDLE_t AcquireControlBlock (RZK_TCB_t *, UINT, UINT);
extern void* RZKMemcpy(void *, const void *, RZK_LENGTH_t); // IAR port, UINT changed to RZK_LENGTH_t

/** extern variables */
extern RZK_THREADHANDLE_t hCurrentThread;
extern RZK_REGION_CB_t nRegion[];  
extern RZK_SEGMENT_CB_t nRegion_Tab[]; 


/*
* Function		:	RZKCreateRegion
*
* Description	:	This function updates the thread statistics parameters of the given thread.
* 
* Inputs		:	szName - Specifies the name of the region to be  created.
*					RnAddr - Specifies the address of the memory for the region
*					uLength - Specifies the total size of the memory for the region
*					uUnit_Size - Specifies the minimum allocation size of memory from the region	
*					uRnDelete - Specifies whether the region should release the memory allocated, while it is getting deleted
*					etAttrib  This specifies the receiving attributes for the threads waiting on the region. It can be one of the two values 
*					RZK_RECV_ATTRIB_et enumerated data type - FIFO   
*					or PRIORITY
*
* Outputs		:	RZKERR_INVALID_ARGUMENTS - If any of the argument is Invalid
*					RZKERR_CB_UNAVAILABLE - If the control block is not Available.
*
* Dependencies	:	None
*/

RZK_REGIONHANDLE_t RZKCreateRegion
						( 
							RZK_NAME_t  szName[MAX_OBJECT_NAME_LEN],	
							UINT8 * RnAddr,
							RZK_LENGTH_t uLength,	// IAR port - changed from COUNT_t to RZK_LENGTH_t
							COUNT_t uUnit_Size,
							UINT8	uRnDelete,	// IAR Port -  changed from UINT to UINT8
							RZK_RECV_ATTRIB_et etAttrib		
						)

		
{
		/*Declare a handle to Region*/
	
		RZK_REGION_t *pHandleToRegion;
		UINT i;	// IAR port - changed from int to UINT
		RZK_STATE_t uState;

		#ifdef RZK_DEBUG
		/*If the length of the memory is zero or address to the memory is NULL, or if the minimum unit size of the memory allocation is less than
			16 bytes then return RZKERR_INVALID_ARGUMENTS*/
		if((uLength == 0) || (RnAddr == NULL) || (uUnit_Size < 16))
		{
			pCurrentThread -> errNum = RZKERR_INVALID_ARGUMENTS;
			return NULL;
		}
 		#endif

		/* Acquire Region Control Block */
		pHandleToRegion = (RZK_REGION_t *)AcquireControlBlock(((RZK_TCB_t*) &nRegion[0]),   
											MAX_REGIONS, sizeof(RZK_REGION_t));
#ifndef RZK_PERFORMANCE
		if(pHandleToRegion == NULL)
		{
			pCurrentThread -> errNum = RZKERR_CB_UNAVAILABLE;
			return NULL;
		}
#endif

		// IAR port added
#ifdef _IAR_CODE
		uLength &= 0xFFFFFF ;
#endif

		/* Acquire a region table entry for freelist of this region */
		for (i = 0; i < MAX_REGIONS_TAB && 
		(pHandleToRegion->Free_List = (pRZK_SEGMENT_t)&(nRegion_Tab[i]))->start != ( UINT8 * ) NULL; i++);
		if (i == MAX_REGIONS_TAB)
		{
			pCurrentThread -> errNum = RZKERR_CB_UNAVAILABLE;
			return NULL;
		}
			  
			/* Set the values in the control block */
		
#ifdef RZK_KERNEL_AWARE

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

#endif /* KERNEL_AWARE */ 

		/* Set the magic number */
		#ifdef RZK_DEBUG
			pHandleToRegion->magic_num = MAGIC_NUM_REGION;
		#endif


		/* Set the memory for region */
			pHandleToRegion -> Free_List->start = RnAddr; 
			pHandleToRegion -> Free_List->len = pHandleToRegion -> uLength = uLength;
			pHandleToRegion -> Reg_Mem_Addr = RnAddr;
			pHandleToRegion -> uUnit_Size = uUnit_Size;
			

		/* Initialize the pLastPosition and pResNext pointers to point to NULL */
		pHandleToRegion->pLastPosition = pHandleToRegion->pResNext = ( RZK_TCB_t* ) NULL;

		/* Initialize the allocated list and the freelist */
		pHandleToRegion->Alloc_List = ( pRZK_SEGMENT_t ) NULL;

		uState = RZKDisablePreemption();/*DISABLE Preemption*/

		/* Mark the state of Region as CREATED */
		pHandleToRegion->uState = OBJECT_CREATED | OBJECT_BUSY;
		

		if (etAttrib & RECV_ORDER_PRIORITY)
		{
			pHandleToRegion->uState |=OBJECT_RECV_PRIORITY;
		}

		if(uRnDelete == 0)
			pHandleToRegion->uRnDelete = RZK_FALSE;
		else
			pHandleToRegion->uRnDelete = RZK_TRUE;
	
	 	/* As soon as any region is created etWaitingQueue
		should be initialised to MESSAGE_NONE*/

		pHandleToRegion->etWaitingQueue = MESSAGE_NONE;

		RZKRestorePreemption(uState); /* Restore Preemption */
		pCurrentThread -> errNum = RZKERR_SUCCESS;
		return pHandleToRegion;
}  /* End of RZKCreateRegion */ 

⌨️ 快捷键说明

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