time.c

来自「Intel PXA270的bootloader程序,在linux环境下运行的.」· C语言 代码 · 共 52 行

C
52
字号
#include <hardware.h>#include <time.h>static unsigned long msecond_boundary;static int udelay_init(void);bool time_init(void){	udelay_init();	RCNR = 0;	OSCR = 0;	return true;}time_t time(time_t *t){	*t = RCNR;		// 1 Hz	return *t;}clock_t clock(void){	return OSCR;	// 3.6864 MHz}/* * 100000 : a / 3686400 s = x : 1 / 1000 s * x = 3686400 * 100000 / (1000 * a) * x = 368640000 / a */static int udelay_init(void){	unsigned long i, diff;	OSCR = 0;	for (i=0; i < 100000; i++);	diff = OSCR;	msecond_boundary = 368640000 / diff;	//printf("udelay : msecond_boundary : %d [0x%08lx]\n", msecond_boundary, msecond_boundary);	return 0;}void udelay(unsigned long usecs){	unsigned long i;	for (i=0; i < msecond_boundary * usecs / 1000; i++);	return;}void mdelay(unsigned long msecs){	while (msecs-- > 0)		udelay(1000);	return;}

⌨️ 快捷键说明

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