📄 tkdev_timer.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 (MB87Q1100) * Hardware-Dependent Timer Processing */#ifndef _TKDEV_TIMER_#define _TKDEV_TIMER_#include <tk/syslib.h>#include <sys/sysinfo.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 imask; DI(imask); /* Stop timer count */ out_w(TMRCTL, TC_MODE); out_w(TMRIC, 0); /* Set counter */ out_w(TMRLD, TIMER_PERIOD * SCInfo.PAclk * 10 - 1); /* Start timer count */ out_w(TMRCTL, TC_TEN|TC_INTEN|TC_MODE); 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_TM, timer_handler_startup); /* Timer interrupt enable */ EnableInt(VECNO_TM, 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(TMRIC, 0);}Inline void end_of_hw_timer_interrupt( void ){}/* * Timer stop processing * Stop the timer operation. * Called when system stops. */Inline void terminate_hw_timer( void ){ /* Interrupt disable */ DisableInt(VECNO_TM);}/* * 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(TMRLD) + 1; do { unf = in_w(TMRRIS) & 1; ofs = max - in_w(TMRVAL); } while ( unf != (in_w(TMRRIS) & 1) ); if ( unf != 0 ) { ofs += max; } EI(imask); /* ofs x (1 / TimerClock) x 10^9 = [ns] */ return ofs * 100 / (SCInfo.PAclk / 100) * 10;}#endif /* _TKDEV_TIMER_ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -