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

📄 usrinit.c

📁 RTOS -REWORKS 定时器的例子
💻 C
字号:
/*
 * usrInit.c
 * 
 */

#define CONFIGURE_INIT
#include "system.h"
#include "stdio.h"


extern int testOSClockSet();
extern int testOSClockGet();
extern int testOSClockTick();
extern int testOSTimerCreate();
extern int testOSTimerIdGet();
extern int testOSTimerDelete();
extern int testOSTimerFireAfter();
extern int testOSTimerFireWhen();
extern int testOSTimerReset();
extern int testOSTaskTimerFireAfter();
extern int testOSTaskTimerFireWhen();

static inline unsigned long long
rdtsc(void)
{
  /* Return the value of the on-chip cycle counter. */
  unsigned long long result;
  asm volatile(".byte 0x0F, 0x31" : "=A" (result));
  return result;
} /* rdtsc */
/*
 * 下面的函数是ReWorks图形工程所用,如果你写的是图形工程,
 * 请放开下面的函数注释,然后把gui_main()放到UserInit()中调用。
 * 注意:把定义make_window()所在的头文件包含进来
 */
 
/*
void gui_main()
{
  Fl_Window* w=make_window();
  w->show();
  Fl::run();
}
*/

void UserInit(void)
{
	/* Add your code here. */
	
	printf("the test of high precision timer:\n");
    double oldTime=0;
    double newTime=0;
    double the_time1;
    double the_time2;
    double the_time3;
    double the_time4;
    unsigned32 retTicks;

    OSClockGet(OS_TICKS_PER_SECOND_GET,&retTicks);
    
    oldTime = rdtsc();
    OSTaskDelay(retTicks);
    newTime = rdtsc();	
	the_time1 = rdtsc();
	the_time2 = rdtsc();
	the_time3 = rdtsc();
	the_time4 = rdtsc();
	printf("the current time is [%12.3f]\n",oldTime);
		printf("the current time is [%12.3f]\n",newTime);	
	printf("the current time is [%12.3f]\n",the_time1);

	printf("the current time is [%12.3f]\n",the_time2);

	printf("the current time is [%12.3f]\n",the_time3);

	printf("the current time is [%12.3f]\n",the_time4);
	
	getchar();
	testOSClockSet(); 
   getchar();
   testOSClockGet(); 
   getchar();
   testOSClockTick(); 
   getchar();
   testOSTimerCreate(); 
   getchar();
   testOSTimerIdGet(); 
   getchar();
   testOSTimerDelete(); 
   getchar();
   testOSTimerFireAfter(); 
   getchar();
   testOSTimerFireWhen(); 
   getchar();
   testOSTimerCancel(); 
   getchar();
   testOSTimerReset(); 
   getchar();
   testOSTaskTimerFireAfter(); 
   getchar();
   testOSTaskTimerFireWhen(); 
   getchar();
   
   printf("the timerTest is OK\n");
	return;	
}

⌨️ 快捷键说明

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