📄 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 (MC9328) * 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: subs %0, %0, #1 \n" " bhi _loop " : "=r"(count) : "0"(count + 1) );}/* * WaitUsec() Compute loop count of micro second wait * Suppose that it is executed by interrupt disable. */EXPORT void CountWaitUsec( void ){ UH cnt, sc, ec; if ( (in_w(TCTL) & TCT_TEN) != 0 ) { /* Reset */ out_w(TCTL, in_w(TCTL) | TCT_SWR); while ( (in_w(TCTL) & TCT_SWR) != 0 ); out_w(TCTL, 0); } /* No divides */ out_w(TPRER, 0); /* Start timer count */ out_w(TCTL, TCT_FRR|TCT_CLK_PERCLK1|TCT_TEN); /* Measure time for 110000 loops */ sc = in_w(TCN); WaitLoop(110000); ec = in_w(TCN); cnt = ec - sc; /* Measure time for 10000 loops */ sc = in_w(TCN); WaitLoop(10000); ec = in_w(TCN); /* Delete time for operation except for loops and compute the net time for 100000 loops */ cnt -= ec - sc; /* Stop timer */ out_w(TCTL, in_w(TCTL) | TCT_SWR); while ( (in_w(TCTL) & TCT_SWR) != 0 ); out_w(TCTL, 0); /* Compute number of loops for 64 micro second * 100000 loops * loop64us = ----------------------- * 64usec * cnt * (100 / PERCLK1) * PERCLK1 = Timer input clock (1/100 MHz) */ SCInfo.loop64us = SCInfo.perclk1 * 64000 / cnt;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -