⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cntwus.c

📁 使用广泛的日本著名的开源嵌入式实时操作系统T-Kernel的源码
💻 C
字号:
/* *---------------------------------------------------------------------- *    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. * *---------------------------------------------------------------------- *//* *	cntwus.c (M32104) *	Loop Count Computation of micro Second Wait  */#include <basic.h>#include <sys/sysinfo.h>#include <tk/syslib.h>#include "tkdev_conf.h"/* * Mode register setting value *	TSEL =1	Output timer mode *	CCSEL=1	Use constant frequency clock (FCLK) *	CSSEL=2	32 dividing *	TCSEL=0	Unlimited terminal count number *	TCCR =0	Count down limit value 0 *	TOSEL=0	No timer output *	GTSEL=0	No gate/trigger input *	CMSEL=0	Count down */#define MFTMOD_INIT	( MFTMOD_TSEL | MFTMOD_CCSEL | MFTMOD_CSSEL(2) )/* * Wait loop */LOCAL void WaitLoop( UW count ){	Asm("	_loop:	addi	%0, #-1		\n"	"		bgtz	%0, _loop	"		: "=r"(count)		: "0"(count)	);}/* * WaitUsec()  Compute loop count of micro second wait *	Suppose that it is executed by interrupt disable. */EXPORT void CountWaitUsec( void ){	UH	cnt, sc, ec;	/* Stop timer */	out_w(MFTCR, MFTCR_DIS(0));	/* Set timer mode */	out_w(MFT0MOD, MFTMOD_INIT);	out_w(MFT0CUT, 0xffff);		/* Counter initial value */	/* Start timer count */	out_w(MFTCR, MFTCR_ENA(0));	/* Measure time for 110000 loops */	sc = in_w(MFT0CUT);	WaitLoop(110000);	ec = in_w(MFT0CUT);	cnt = sc - ec;	/* Measure time for 10000 loops */	sc = in_w(MFT0CUT);	WaitLoop(10000);	ec = in_w(MFT0CUT);	/* Delete time for operation except for loops and 	   compute the net time for 100000 loops */	cnt -= sc - ec;	/* Stop timer */	out_w(MFTCR, MFTCR_DIS(0));	/* Compute number of loops for 64 micro second	 *			100000 loops	 *	loop64us = ----------------------- * 64usec	 *		    cnt * (32 dividing / Fclk)	 *	Fclk = Constant frequency clock (MHz)	 */	SCInfo.loop64us = SCInfo.Fclk * 200000 / cnt;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -