📄 cntwus.c
字号:
/* *---------------------------------------------------------------------- * 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. * *---------------------------------------------------------------------- *//* * cntwus.c (SH7727) * Loop Count Computation of micro Second Wait */#include <basic.h>#include <sys/sysinfo.h>#include <tk/syslib.h>#include "tkdev_conf.h"/* * Wait loop */LOCAL void WaitLoop( UW count ){ Asm(" _loop: tst %0, %0 \n" " bf/s _loop \n" " add #-1, %0 " : "=r"(count) : "0"(count) );}/* * WaitUsec() Compute loop count of micro second wait * Suppose that it is executed by interrupt disable. */EXPORT void CountWaitUsec( void ){ UW cnt, sc, ec; UB tstr; /* StopTMU0 */ tstr = in_b(TSTR) & ~TSTR_STR0; out_b(TSTR, tstr); /* Set TMU0 */ out_h(TCR0, TCR_TPSC_P64); /*Select clock/Disable interrupt */ out_w(TCOR0, 0xffffffff); /* Counter initial value */ out_w(TCNT0, 0xffffffff); /* Counter initial value */ /* Start TMU0 count */ out_b(TSTR, tstr | TSTR_STR0); /* Measure time for 110000 loops */ sc = in_w(TCNT0); WaitLoop(110000); ec = in_w(TCNT0); cnt = sc - ec; /* Measure time for 10000 loops */ sc = in_w(TCNT0); WaitLoop(10000); ec = in_w(TCNT0); /* Delete time for operation except for loops and compute the net time for 100000 loops */ cnt -= sc - ec; /* StopTMU0 */ out_b(TSTR, tstr); /* Compute number of loops for 64 micro seconds * 100000 loops * loop64us = ----------------------- * 64usec * cnt * (64 dividing / Pclk) * Pclk = Peripheral clock (MHz) */ SCInfo.loop64us = SCInfo.Pclk * 100000 / cnt;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -