📄 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 (MC9328) * 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 50IMPORT UW TimerClkDiv; /* Dividing rate of timer clock *//* * Set timer */Inline void init_hw_timer( void ){ UW n, imask; /* Determine dividing rate (less than 100MHz) */ TimerClkDiv = SCInfo.perclk1 / 10000 + 1; DI(imask); n = in_w(TCTL); if ( (n & TCT_TEN) != 0 ) { /* Reset */ out_w(TCTL, n | TCT_SWR); while ( (in_w(TCTL) & TCT_SWR) != 0 ) { ; } out_w(TCTL, 0); } /* Set dividing rate */ out_w(TPRER, TimerClkDiv - 1); /* Set counter */ n = (UW)TIMER_PERIOD * (SCInfo.perclk1 * 10) / TimerClkDiv - 1; out_w(TCMP, n); /* Start timer count */ out_w(TCTL, TCT_IRQEN|TCT_CLK_PERCLK1|TCT_TEN); 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_TM1, timer_handler_startup); /* Timer interrupt enable */ EnableInt(VECNO_TM1, 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 */ if ( in_w(TSTATUS) != 0 ) { out_w(TSTATUS, 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_TM1);}/* * 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(TCMP) + 1; do { unf = in_w(TSTATUS) & TST_COMP; ofs = in_w(TCN); } while ( unf != (in_w(TSTATUS) & TST_COMP) ); if ( unf != 0 ) { ofs += max; } EI(imask); return ofs * (100000 * TimerClkDiv / SCInfo.perclk1);}#endif /* _TKDEV_TIMER_ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -