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

📄 timeq1.c

📁 zilog的实时操作系统RZK,可以移植到多种处理器上
💻 C
字号:
/*
* File				:	TimeQ1.c
*
* Description		:	This file contains functions Related to Time Q1.
*
* 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 "ZSysgen.h"
#include "ZTypes.h"
#include "ZThread.h"
#include "ZQueue.h"

extern RZK_TIMEQ_t TimeQueue[TMAX_QUEUE];

/** extern functions */
//extern void QueueAppend(RZK_TCB_t *pInsertionPosition ,RZK_TCB_t *pObjectToAppend);
//extern void QueueNodeRemove(RZK_TCB_t *pObjectToRemove );

/* Function			:	AddToTimeQ1
*
* Description		:	This function adds the object to the Time Q1, by calling a function 
*						that finds the position of insertion. It also updates the tWaitTime 
*						member of the succeeding object.
* 
* Inputs			:	RZK_TCB_t *pObjectToAdd.
*							
* Outputs			:	None.
*							
*
* Dependencies		:	None.
*/
void AddToTimeQ1 ( RZK_TCB_t * pObjectToAdd )
{
	
	RZK_TCB_t *pInsertionPos;      

	/* This function specifies the insertion position for the object to be inserted in the time queue 1 and it also 
	updates the tWaitTime  */

	pInsertionPos = FindTQ1InsertionPosition ( pObjectToAdd );

	/* Now insert pObjectToAdd in the time queue1 at the after pInsertionPos*/ 

	QueueAppend ( pInsertionPos, pObjectToAdd );
	 
	if ( ( void *) pObjectToAdd -> pNext != ( void *) &TimeQueue[TIME_Q1] )
	{
		pObjectToAdd -> pNext -> tWaitTime -= pObjectToAdd ->tWaitTime;
	}
}

/*
* Function			:	FindTQ1InsertionPosition
*
* Description		:	This function searches the Time Queue1 for the position at
*					    which  a new object is to be inserted	depending on it's wait 
*					    time. It also  initializes the wait time of the	object being 
*						inserted. It returns  a pointer to the preceding object.
* 
* Inputs			:	pThreadToAdd - Pointer to object
*							
* Outputs			:	Pointer to previous object
*							
* Dependencies		:	None.
*/
RZK_TCB_t * FindTQ1InsertionPosition (RZK_TCB_t * pThreadToAdd)
{
	RZK_TCB_t * pTemp;
	TICK_t tTotalTime = 0;

	/* Go to the first valid node. Since the first node is the reference node, the pNext pointer of that node will point to the first valid node of the queue.*/

	pTemp = TimeQueue[TIME_Q1].pNext; 

	while( ( void * ) pTemp != ( void * ) &TimeQueue[TIME_Q1])
	{
			/* Update time ticks for the current thread based on other threads in queue*/
			tTotalTime += pTemp->tWaitTime ;
			if ( tTotalTime > pThreadToAdd->tWaitTime )
			{
					tTotalTime -= pTemp->tWaitTime;
					break;
			}
			else
			{
					pTemp = pTemp->pNext;
			}
	}/* End while*/
	
	pThreadToAdd->tWaitTime -= tTotalTime;
	return pTemp->pPrevious;
}
	

/* Function			:	UpdateTQ1OnRemove
*
* Description		:	This function updates the wait time of the object succeeding the
*						object being removed from TQ1.
* 
* Inputs			:	RZK_TCB_t *hObjectToRemove.
*							
* Outputs			:	None.
*							
*
* Dependencies		:	None.
*/					
void UpdateTQ1OnRemove(RZK_TCB_t *pObjectToRemove )	
{

	if( ( void * ) pObjectToRemove->pNext != ( void * ) &TimeQueue[TIME_Q1])
	{
		pObjectToRemove->pNext->tWaitTime = pObjectToRemove->pNext->tWaitTime  + 
							pObjectToRemove->tWaitTime;
	}	
	QueueNodeRemove(pObjectToRemove);
}

⌨️ 快捷键说明

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