📄 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 (SH7751R) * 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/* * Timer control register setting value * Interrupt enable, 16 dividing */#define TCR4_INIT ( TCR_UNIE | TCR_TPSC_P16 )/* * Set timer */Inline void init_hw_timer( void ){ UB tstr; UW cnt; /* Stop timer */ tstr = in_b(TSTR2) & ~TSTR_STR4; out_b(TSTR2, tstr); /* Set timer mode */ out_h(TCR4, TCR4_INIT); /* Set counter */ cnt = TIMER_PERIOD * (UW)SCInfo.Pclk * 1000 / 16 - 1; out_w(TCOR4, cnt); out_w(TCNT4, cnt); /* Start timer count */ out_b(TSTR2, tstr | TSTR_STR4);}/* * Timer start processing * Initialize the timer and start the periodical timer interrupt. */Inline void start_hw_timer( void ){IMPORT void timer_handler_startup( void ); UW ipri; /* Set timer */ init_hw_timer(); /* Interrupt handler definition */ define_inthdr(VECNO_TMU4, timer_handler_startup); /* Timer interrupt enable */ ipri = in_w(INTPRI00); ipri = (ipri & 0xffff0fff) | (TIMER_INTLEVEL << 12); out_w(INTPRI00, ipri); out_w(INTMSKCLR00, 1 << 9);}/* * 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 depending on hardware. */Inline void clear_hw_timer_interrupt( void ){ /* Clear underflow flag */ out_h(TCR4, TCR4_INIT);}Inline void end_of_hw_timer_interrupt( void ){ /* Nothing required to do at this point */}/* * Timer stop processing * Stop the timer operation. * Called when system stops. */Inline void terminate_hw_timer( void ){ UW ipri; /* Timer interrupt disable */ ipri = in_w(INTPRI00); ipri = ipri & 0xffff0fff; out_w(INTPRI00, ipri); out_w(INTMSK00, 1 << 9);}/* * 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; UH unf; max = in_w(TCOR4) + 1; do { unf = in_h(TCR4) & TCR_UNF; ofs = max - in_w(TCNT4); } while ( unf != (in_h(TCR4) & TCR_UNF) ); if ( unf != 0 ) ofs += max; return ofs * 1000 / SCInfo.Pclk * 16;}#endif /* _TKDEV_TIMER_ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -