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

📄 testostimerfirewhen.c

📁 RTOS -REWORKS 定时器的例子
💻 C
字号:
#include "timerTest.h"

void t2_entry(unsigned32 id , void *data)
{
	printk("[%s]\n",data);
}
int testOSTimerFireWhen()
{
	OS_STATUS	status;
	unsigned32	t_id;
	os_tod		now_time; 
	os_tod		start_time;
  	
	printf("*** test of OSTimerFireWhen ***\n");
	printf("create a timer.\n");
 	status = OSTimerCreate  ("TIMER" , &t_id);
  	if (status != OS_OK)
    {
    	printf("OSTimerCreate error:[%s]\n",serrno(errno));
    	return -1;
    }  

	printf("fire the timer when after 3 second.\n");
	OSClockGet(OS_TOD_GET ,&now_time);
 	printf("the current time is %d.%d.%d,%d:%d:%d:%d\n",
  					now_time.year,
       				now_time.month,
           			now_time.day,
              		now_time.hour,
                	now_time.minute,
                 	now_time.second,
                 	now_time.ticks);
 	start_time.year 	= now_time.year;
  	start_time.month 	= now_time.month;  
  	start_time.day 		= now_time.day;      
  	start_time.hour 	= now_time.hour;    
  	start_time.minute 	= now_time.minute;
  	start_time.second 	= now_time.second + 3;
  	if(start_time.second > 59)
	{
    	start_time.second = 0;
     	start_time.minute = start_time.minute + 1; 
 	}
  	start_time.ticks 	= now_time.ticks;
  	printf("the start time is %d.%d.%d,%d:%d:%d:%d\n",
  					start_time.year,
       				start_time.month,
           			start_time.day,
              		start_time.hour,
                	start_time.minute,
                 	start_time.second,
                 	start_time.ticks);
	status = OSTimerFireWhen  (t_id , (os_tod*)&start_time , t2_entry , "OSTimerFireWhen:in timer");
    if (status != OS_OK)
    {
    	printf("OSTimerFireWhen error:[%s]\n",serrno(errno));
    	return -1;
    }    
    else
    	printf("OSTimerFireWhen OK\n");    	
	
 	OSTaskDelay(5000);

	OSTimerDelete (t_id); 
   	
	printf("*** OSTimerFireWhen test OK! ***\n");
	return 1;
}


⌨️ 快捷键说明

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