📄 tkdev_timer.h
字号:
/* *---------------------------------------------------------------------- * T-Kernel * * Copyright (C) 2004 by Ken Sakamura. All rights reserved. * T-Kernel is distributed under the T-License. *---------------------------------------------------------------------- * * Version: 1.01.00 * Released by T-Engine Forum(http://www.t-engine.org) at 2004/6/28. * *---------------------------------------------------------------------- *//* * tkdev_timer.h (VR5500) * 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); /* Set timer mode (no pre-scale)/Stop timer */ out_w(GPT0CTRL, 0); /* Set counter */ n = (UW)TIMER_PERIOD * GPTCLK / 1000 - 1; out_w(GPT0VAL, n); /* Start timer count */ out_w(GPT0CTRL, GPTC_EN); 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_GPT0, timer_handler_startup); /* Timer interrupt enable */ ClearInt(VECNO_GPT0); EnableInt(VECNO_GPT0, TIMER_INTLEVEL);}/* * 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_w(INTCLR32, 1 << GPT0_IRQ);}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 */ out_w(GPT0CTRL, 0); DisableInt(VECNO_GPT0);}/* * Get processing time from the previous timer interrupt to the * current (nanosecond) * Consider the possibility that the timer interrupt occurred * during the interrupt disable and calculate the processing * time within the following * range: 0 <= Processing time < TIMER_PERIOD * 2 */Inline UINT get_hw_timer_nsec( void ){ UW ofs, max, unf, imask; DI(imask); max = in_w(GPT0VAL) + 1; do { unf = in_w(INTSTAT(TIMER_INTLEVEL)) & (1 << GPT0_IRQ); ofs = max - in_w(GPT0CNTR); } while ( unf != (in_w(INTSTAT(TIMER_INTLEVEL)) & (1 << GPT0_IRQ)) ); if ( unf != 0 ) ofs += max; EI(imask); return ofs * 10000 / (GPTCLK/100) * 1000;}#endif /* _TKDEV_TIMER_ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -