looptime.c

来自「UC/OS 在SparcLite 上的移植范例」· C语言 代码 · 共 77 行

C
77
字号
/*
; ---------------------------------------------------------------------------
; File:	looptimer.c
;
; uC/OS Real-time multitasking kernel for the SparcLite processor.
;
; main program: sets up timer 2 for 20/second, times a loop
;
; Created by Brad Denniston, Viewpoint Engineering  (bradd@vpeng.com).;
; ---------------------------------------------------------------------------
*/

#include "ucos.h"
#include "cpu.h"

OS_TCB	*OSTCBCur;
OS_TCB	*OSTCBHighRdy;

static uint OSTime = 0;
static uint	OSIntNesting = 0;

struct hist
{
	uint 	time;
	uint	count;
} history[32];

/*
; ---------------------------------------------------------------------
; main
; ---------------------------------------------------------------------
*/
main()
{
	int		lastTime = 0;
	uint	count = 0;
	int		points = 0;
	uint	time;

	CPUInit();
	printf( "Loop Timer\n" );
	while( count++ < 500000 && points < 20 )
	{
		if( (time = OSTimeGet() ) != lastTime )
		{
			history[points].count = count;
			history[points].time = time;
			points++;
			lastTime = time;
			count = 0;
		}
	}

	printf( "Count is %d, points is %d\n", count, points );
	for( points = 0; points < 20; points++ )	/* run for 5 minutes max */
	{
		printf( "%d: %ld  %d\n", points, history[points].count, 
				history[points].time );
	}
}

void OSTimeTick()
{
	OSTime++;
}

OSIntExit()
{
	OSIntNesting--;
	return( FALSE );
}

uint OSTimeGet()
{
	return( OSTime );
}

⌨️ 快捷键说明

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