VxWorks_Timer
来源:互联网 发布:q版人物绘画软件 编辑:程序博客网 时间:2024/06/05 07:18
#include "VxWorks.h"
#include "time.h"
#include "timers.h"
#include "syslib.h"
#include "logLib.h"
#include "stdio.h"
#define COUNT 5
/*处理函数*/
void myHandler(timer_t tmId,int arg)
{
static int iCount=0;
int iRet;
iCount++;
printf("myHandler is called. the arg is %d,count is %d\n",arg,iCount);
/* When this funciton is called COUNT times, cancle the timer and
delete it.
*/
if(iCount>=COUNT)
{
iRet=timer_cancel(tmId);
if(iRet!=0)
{
printf("time_cancel error.\n");
return;
}
printf("Timer cancled\n");
timer_delete(tmId);
if(iRet!=0)
{
printf("time_delete error.\n");
return;
}
}
}
/*初始化、挂载Timer*/
void main()
{
int iRet;
struct timespec stTp0,stTp1;
struct itimerspec stValue;
timer_t tmId;
#if 0
iRet=clock_gettime(CLOCK_REALTIME, &stTp0);
printf("clock_gettime:%d, %d.\n", stTp0.tv_sec, stTp0.tv_nsec);
/* set current time to 0 second and o nsecond*/
stTp0.tv_sec=0;
stTp0.tv_nsec=0;
iRet=clock_settime(CLOCK_REALTIME, &stTp0);
if(iRet!=0)
{
printf("clock_settime error.\n");
return;
}
#endif
if(iRet!=0)
{
printf("timer_create error.\n");
}
else
{
/* connect tmId with myHandler*/
iRet=timer_connect(tmId,myHandler,10);
if(iRet!=0)
{
printf("timer_connect error.\n");
}
else
{
/* set interrupt time*/
stValue.it_interval.tv_sec=0;
stValue.it_interval.tv_nsec=500000000;
stValue.it_value.tv_sec=0;
if(iRet!=0)
{
printf("timer_settime error.\n");
}
else
{
/* Test here*/
stTp0.tv_sec=10;
stTp0.tv_nsec=0;
while(1)
{
/**/
//taskDelay(20);
#if 0
nanosleep(&stTp0,&stTp1);
#endif
//printf("**************tv_sec %ld tv_nsec %ld\n",stTp1.tv_sec,stTp1.tv_nsec);
}
}
}
}
}
#include "time.h"
#include "timers.h"
#include "syslib.h"
#include "logLib.h"
#include "stdio.h"
#define COUNT 5
/*处理函数*/
void myHandler(timer_t tmId,int arg)
{
static int iCount=0;
int iRet;
iCount++;
printf("myHandler is called. the arg is %d,count is %d\n",arg,iCount);
/* When this funciton is called COUNT times, cancle the timer and
delete it.
*/
if(iCount>=COUNT)
{
iRet=timer_cancel(tmId);
if(iRet!=0)
{
printf("time_cancel error.\n");
return;
}
printf("Timer cancled\n");
timer_delete(tmId);
if(iRet!=0)
{
printf("time_delete error.\n");
return;
}
}
}
/*初始化、挂载Timer*/
void main()
{
int iRet;
struct timespec stTp0,stTp1;
struct itimerspec stValue;
timer_t tmId;
#if 0
iRet=clock_gettime(CLOCK_REALTIME, &stTp0);
printf("clock_gettime:%d, %d.\n", stTp0.tv_sec, stTp0.tv_nsec);
/* set current time to 0 second and o nsecond*/
stTp0.tv_sec=0;
stTp0.tv_nsec=0;
iRet=clock_settime(CLOCK_REALTIME, &stTp0);
if(iRet!=0)
{
printf("clock_settime error.\n");
return;
}
#endif
/*timer_t*/
iRet = timer_create(CLOCK_REALTIME, NULL, &tmId);if(iRet!=0)
{
printf("timer_create error.\n");
}
else
{
/* connect tmId with myHandler*/
iRet=timer_connect(tmId,myHandler,10);
if(iRet!=0)
{
printf("timer_connect error.\n");
}
else
{
/* set interrupt time*/
stValue.it_interval.tv_sec=0;
stValue.it_interval.tv_nsec=500000000;
stValue.it_value.tv_sec=0;
stValue.it_value.tv_nsec=500000000;
if(iRet!=0)
{
printf("timer_settime error.\n");
}
else
{
/* Test here*/
stTp0.tv_sec=10;
stTp0.tv_nsec=0;
while(1)
{
/**/
//taskDelay(20);
#if 0
nanosleep(&stTp0,&stTp1);
#endif
//printf("**************tv_sec %ld tv_nsec %ld\n",stTp1.tv_sec,stTp1.tv_nsec);
}
}
}
}
}
0 0
- VxWorks_Timer
- AngularJS学习 之 过滤器实例
- Expected an int but was 0.01 at line 1 column 782 Gson工具使用出错的解决
- 基础总结篇之八:创建及调用自己的ContentProvider
- LINUX 挂载硬盘开机自启动
- 欢迎使用CSDN-markdown编辑器
- VxWorks_Timer
- Cocos2dx:java.lang.UnsatisfiedLinkError:findLibrary returned null 惊魂一个月
- Android通过Wifi来调试应用
- Android口袋天气系列四-->数据库封装类
- 理解Cookie和Session机制
- SQL Server之视图及自定义 函数
- TCP为什么需要3次握手与4次挥手
- MIT6.828 Lab2:第1部分 Physical Page Management
- jQuery同时操作多个属性