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

📄 createtimer.c

📁 zilog的实时操作系统RZK,可以移植到多种处理器上
💻 C
字号:
/*
* File			:	RZKCreateTimer.c
*
* Description	:	This file contains the RZKCreateTimer function which creates a 
*					software timer with 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 "ZTimer.h"
#include "externvar.h"

#define pCurrentThread ((RZK_TCB_t *) hCurrentThread)

/* Dependencies */
/** 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_HANDLE_t hCurrentThread;
extern RZK_TIMER_CB_t nTimer[];   

/*
* Function		:	RZKCreateTimer
*
* Description	:	This function creates a software timer with an 
*					initial delay and a period.
* 
* Inputs		:	szName - Name of the timer  
*					pTimerfuntion - Pointer to entry point function.
*					tInitialDelay - Initial delay for the timer in units of system ticks.
*					tPeriod - cyclic period (in ticks) for the timer, after initial delay.
*
* Outputs		:	Handle to timer or NULL on failure	
*
* Dependencies	:	None
*/

RZK_TIMERHANDLE_t RZKCreateTimer(
				RZK_NAME_t szName[8],	
				FNP_TIMER_FUNCTION pTimerFunction,	// IAR changed
				TICK_t tInitialDelay,
				TICK_t tPeriod
				)
{
	RZK_TIMER_t *hTimer;

	/* validate all parameters */
#ifdef RZK_DEBUG
	if((pTimerFunction == (FNP_TIMER_FUNCTION) NULL) || (tPeriod == 0))
	{
		pCurrentThread->errNum =  RZKERR_INVALID_ARGUMENTS;
		return NULL;
	}
#endif

	hTimer = (RZK_TIMER_t *)AcquireControlBlock((RZK_TCB_t *) &nTimer[0],   
									MAX_TIMERS, sizeof(RZK_TIMER_t));
	
#ifndef RZK_PERFORMANCE
	if(hTimer == NULL)
	{
		pCurrentThread->errNum = RZKERR_CB_UNAVAILABLE;
		return NULL;
	}
#endif
	/* Initialize all the parameters */
	#ifdef RZK_KERNEL_AWARE

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

	#endif /* KERNEL_AWARE */ 
	
	#ifdef RZK_DEBUG
		hTimer->magic_num = MAGIC_NUM_TIMER;
	#endif

	hTimer->pFuncPtr = pTimerFunction;
	hTimer->tInitialTime = tInitialDelay;
	hTimer->tPeriod = tPeriod;
	hTimer->hObject = hTimer;
	
	/* Some initializations when thread gets created. Old thread's values must not be retained here */
	hTimer->pNext = ( RZK_TCB_t * ) NULL;
	hTimer->pPrevious = ( RZK_TCB_t * ) NULL;
	hTimer->tWaitTime = 0;
#ifdef RZK_STATISTIC
	hTimer->tFirstTimeOfFuncEntry = 0;   /*  Specifies the first time function entry is called */ 
	hTimer->tPrevTimeOfFuncEntry = 0;	 /*  Specifies the previous time function entry was called */ 
	hTimer->tMinTimeOfFuncEntry = 0;	 /*  Specifies the minimum time between consecutive calls to function entry*/ 
	hTimer->tMaxTimeOfFuncEntry = 0;	 /*  Specifies the maximum time between consecutive calls to function entry*/ 
	hTimer->uFuncExecutionCount = 0;	 /* Specifies the number of times the function entry has called */
#endif
	/* Some initializations when thread gets created. Old thread's values must not be retained here */

	hTimer->uState = OBJECT_CREATED | OBJECT_BUSY | TIMER_DISABLE;

	pCurrentThread->errNum = RZKERR_SUCCESS;
	return hTimer;
}

⌨️ 快捷键说明

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