testostasktimerfirewhen.c

来自「RTOS -REWORKS 定时器的例子」· C语言 代码 · 共 80 行

C
80
字号
#include "timerTest.h"

void tt1_entry(unsigned32 id , void *data)
{
	printk("[%s]\n",data);
}
int testOSTaskTimerFireWhen()
{
	OS_STATUS	status;
	char*		t_name; 
	unsigned32	t_id;
  	os_tod		now_time; 
	os_tod		start_time;
	
	printf("*** test of OSTaskTimerFireWhen ***\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("start the timer server task.\n");
 	status = OSTaskTimerInit(1 , 2048 , OS_DEFAULT);
  	if (status != OS_OK)
    {
    	printf("OSTaskTimerInit error:[%s]\n",serrno(errno));
    	return -1;
    }
 */	
	printf("fire the task timer 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 = OSTaskTimerFireWhen (t_id , (os_tod*)&start_time , tt1_entry , "OSTaskTimerFireWhen:in timer");
    if (status != OS_OK)
    {
    	printf("OSTaskTimerFireWhen error:[%s]\n",serrno(errno));
    	return -1;
    }   
    else
    	printf("OSTaskTimerFireWhen OK\n");    	

	OSTaskDelay(5000);

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


⌨️ 快捷键说明

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