VxWorks_Timer
2016-05-19 19:01
281 查看
#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
/*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;
iRet=timer_settime(tmId,0,&stValue,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;
iRet=timer_settime(tmId,0,&stValue,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);
}
}
}
}
}
相关文章推荐
- 牛顿法解方程
- java JVM 加载类的顺序
- Android项目重构之路:实现篇
- 2016/05/19 thinkphp 3.2.2 文件上传
- 你真的会写单例模式吗——Java实现
- MIT6.828 Lab2:第1部分 Physical Page Management
- jQuery同时操作多个属性
- TCP为什么需要3次握手与4次挥手
- 理解Cookie和Session机制
- centos linux 服务器时间少8个小时的问题
- 5.19[bzoj树网的核]
- CoreException: Could not calculate build plan: Plugin org.apache.maven.plugins:maven-compiler-plugin:3.1 or one of its dependencies could not be resolved
- Cocos2dx:java.lang.UnsatisfiedLinkError:findLibrary returned null 惊魂一个月
- ajaxfileupload
- 欢迎使用CSDN-markdown编辑器
- 基础总结篇之八:创建及调用自己的ContentProvider
- LINUX 挂载硬盘开机自启动
- Linux中常用的查找文件的命令
- 作业
- IDEA中搭建Scala + Play+Slick环境