📄 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 (VR4131) * Loop Count Computation of micro Second Wait */#include <basic.h>#include <sys/sysinfo.h>#include <tk/syslib.h>#include <tk/sysdef.h>#include "tkdev_conf.h"/* * Wait loop */LOCAL void WaitLoop( UW count ){ Asm(" .set push \n" " .set noreorder \n" " _loop: bnez %0, _loop \n" " subu %0, %0, 1 \n" " .set pop " : "=r"(count) : "0"(count) );}/* * Read timer count value */LOCAL UW getcnt( void ){ UW hi, lo; do { hi = in_h(TCLKCNTHREG); lo = in_h(TCLKCNTLREG); } while ( hi != in_h(TCLKCNTHREG) ); return (hi << 16) | lo;}/* * WaitUsec() Compute loop count of micro second wait * Suppose that it is executed by interrupt disable. */EXPORT void CountWaitUsec( void ){const UW MAXCNT = 0x01ffffff; UW cnt, sc, ec; /* Stop timer */ out_h(TCLKLREG, 0); out_h(TCLKHREG, 0); /* Start timer count */ out_h(TCLKLREG, MAXCNT & 0xffff); out_h(TCLKHREG, MAXCNT >> 16); /* Measure time for 110000 loops */ sc = getcnt(); WaitLoop(110000); ec = getcnt(); cnt = (sc - ec) & MAXCNT; /* Measure time for 10000 loops */ sc = getcnt(); WaitLoop(10000); ec = getcnt(); /* Delete time for operation except for loops and compute the net time for 100000 loops */ cnt -= (sc - ec) & MAXCNT; /* Stop timer */ out_h(TCLKLREG, 0); out_h(TCLKHREG, 0); /* Compute number of loops for 64 micro second * 100000 loops * loop64us = ------------------------- * 64usec * cnt * (100 / GPTCLK) * TClock = Timer input clock (1/100 MHz) */ SCInfo.loop64us = SCInfo.TClock * 64000 / cnt;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -