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

📄 timers.c

📁 opentcp_mcf5282原代码
💻 C
字号:
/******************************************************************************
File:			timers.c

Date:			22.1.2004

Version:		0.1

Author:			Jari Lahti (jari.lahti@violasystems.com)

Description:	Implements simple timer pool. No timer chaining

Version Info:	22.1.2004 - First version (JaL)
*******************************************************************************/

#include "opentcp.h"

struct timers TimerPool[NUMTIMERS];

/******************************************************************************
Function:		init_timerpool

Parameters:		none

Return val:		void

Date:			18.7.2001

Desc:			Initialize timer pool
*******************************************************************************/

void init_timerpool (void)
{
	UINT8 i;

	for( i=0; i < NUMTIMERS; i++)
	{
		TimerPool[i].TimerField = 0;
		TimerPool[i].Free = TRUE;

	}

}

/******************************************************************************
Function:		get_timer

Parameters:		none

Return val:		Return handle of free timer

Date:			18.7.2001

Desc:			Gets free timer from the timer pool
*******************************************************************************/

UINT8 get_timer (void)
{

	UINT8 i;
	UINT8 FirstMatch;


	for( i=0; i < NUMTIMERS; i++)
	{
		if( TimerPool[i].Free == TRUE )
		{
			/* We found a free timer! */
			/* Mark is reserved		  */

			TimerPool[i].Free = FALSE;
			FirstMatch = i;
			return FirstMatch;		/* Return Handle	*/
		}

	}

	/* Error Check	*/

	DEBUGOUT("No Timers, Resetting..\n\r");
	RESET_SYSTEM();
	return(0);


}

/******************************************************************************
Function:		free_timer

Parameters:		none

Return val:		UINT8 nbr - number

Date:			18.7.2001

Desc:			puts the given timer back to the timer pool
*******************************************************************************/

void free_timer (UINT8 nbr)
{
	/* Make a simple check */

	if( nbr > (NUMTIMERS-1) )
		return;

	TimerPool[nbr].Free = TRUE;

}


/******************************************************************************
Function:		init_timer

Parameters:		UINT8 nbr - number
				UINT32 tout -  time out

Return val:		none

Date:			18.7.2001

Desc:			Initializes given timer to given time-out
*******************************************************************************/

void init_timer ( UINT8 nbr, UINT32 tout )
{
	/* Make a simple check */

	UINT32 val;
	int old_ipl;

	if( nbr > (NUMTIMERS-1) )
		return;

	if( TimerPool[nbr].Free == TRUE )
		return;

	/* All OK				*/

	val = tout;

	//DISABLE_TIMER_IRQ();
	old_ipl = asm_set_ipl(6);

	/* Normalize seconds to timer tics	*/

	TimerPool[nbr].TimerField = val;

	//ENABLE_TIMER_IRQ();
	asm_set_ipl(old_ipl);

}


/******************************************************************************
Function:		check_timer

Parameters:		UINT8 nbr - number

Return val:		return the value of given timer

Date:			18.7.2001

Desc:			return the value of given timer
*******************************************************************************/

UINT32 check_timer (UINT8 nbr)
{
	/* This should be quite fast function! 				*/
	/* Interrupts are not disabled when fetching the	*/
	/* value, therefore returned value possible has 	*/
	/* an error component +/- TIMERTIC.					*/
	/* Just live with it!								*/


	return TimerPool[nbr].TimerField;

}


/******************************************************************************
Function:		irqhandler_timer

Parameters:		void

Return val:		void

Date:			18.7.2001

Desc:			Call this function on timer interrupt
*******************************************************************************/

void irqhandler_timer (void)
{
	UINT16 i;

	for( i=0; i<NUMTIMERS; i++ )
	{
		if( TimerPool[i].Free == FALSE &&
			TimerPool[i].TimerField != 0	)

			TimerPool[i].TimerField --;

	}


}


/* EOF	*/

⌨️ 快捷键说明

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