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

📄 tkdev_timer.h

📁 使用广泛的日本著名的开源嵌入式实时操作系统T-Kernel的源码
💻 H
字号:
/* *---------------------------------------------------------------------- *    T-Kernel * *    Copyright (C) 2004-2006 by Ken Sakamura. All rights reserved. *    T-Kernel is distributed under the T-License. *---------------------------------------------------------------------- * *    Version:   1.02.02 *    Released by T-Engine Forum(http://www.t-engine.org) at 2006/8/9. * *---------------------------------------------------------------------- *//* *	tkdev_timer.h (VR4131) *	Hardware-Dependent Timer Processing */#ifndef _TKDEV_TIMER_#define _TKDEV_TIMER_#include <tk/syslib.h>#include <sys/sysinfo.h>#include <tk/sysdef.h>#include "tkdev_conf.h"/* * Settable interval range (millisecond) */#define MIN_TIMER_PERIOD	1#define MAX_TIMER_PERIOD	50/* * Set timer */Inline void init_hw_timer( void ){	UW	n, imask;	DI(imask);	/* Stop timer */	out_h(TCLKLREG, 0);	out_h(TCLKHREG, 0);	/* Counter setting value */	n = (UW)TIMER_PERIOD * SCInfo.TClock * 10 - 1;	/* Start timer count */	out_h(TCLKLREG, n & 0xffff);	out_h(TCLKHREG, n >> 16);	EI(imask);}/* * Timer start processing *	Initialize the timer and start the periodical timer interrupt. */Inline void start_hw_timer( void ){IMPORT	void	timer_handler_startup( void );	/* Set timer */	init_hw_timer();	/* Interrupt handler definition */	define_inthdr(VECNO_TCLK, timer_handler_startup);	/* Timer interrupt enable */	out_h(RTCINTREG, RTC_TCLK); /* Interrupt clear */	EnableInt(VECNO_TCLK);}/* * Clear timer interrupt *	Clear the timer interrupt request. Depending on the type of *	hardware, there are two timings for clearing: at the beginning *	and the end of the interrupt handler. *	'clear_hw_timer_interrupt()' is called at the beginning of the *	timer interrupt handler. *	'end_of_hw_timer_interrupt()' is called at the end of the timer  *	interrupt handler. *	Use either or both according to hardware. */Inline void clear_hw_timer_interrupt( void ){	/* Clear timer interrupt */	out_h(RTCINTREG, RTC_TCLK);}Inline void end_of_hw_timer_interrupt( void ){	/* Nothing special */}/* * Timer stop processing *	Stop the timer operation. *	Called when system stops. */Inline void terminate_hw_timer( void ){	/* Timer interrupt disable */	DisableInt(VECNO_TCLK);}/* * Get processing time from the previous timer interrupt to the * current (nanosecond) *	Consider the possibility that the timer interrupt occurred *	during the nterrupt disable and calculate the processing time  *	within the following  *	range:	0 <= Processing time < TIMER_PERIOD * 2 */Inline UINT get_hw_timer_nsec( void ){	UW	hi, lo, ofs, max, unf, imask;	DI(imask);	max = (((UW)in_h(TCLKHREG) << 16) | in_h(TCLKLREG)) + 1;	do {		unf = in_h(RTCINTREG) & RTC_TCLK;		do {			hi = in_h(TCLKCNTHREG);			lo = in_h(TCLKCNTLREG);		} while ( hi != in_h(TCLKCNTHREG) );		ofs = max - ((hi << 16) | lo);	} while ( unf != (in_h(RTCINTREG) & RTC_TCLK) );	if ( unf != 0 ) {		ofs += max;	}	EI(imask);	return ofs * 100 / SCInfo.TClock * 1000;}#endif /* _TKDEV_TIMER_ */

⌨️ 快捷键说明

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