垡头做网站的公司网站制作怎样做背景
news/
2025/10/7 23:33:07/
文章来源:
垡头做网站的公司,网站制作怎样做背景,上海市建设工程咨询奖,数据中心网站模板[摘要] Timer是实时操作系统的一个重要组成部分。本文结合近阶段的学习和实验情况#xff0c;对VxWorks中的时间函数和定时器作了一些探讨。主要介绍了Timer的机制#xff0c;相关的函数#xff0c;并给出了一些具体的例子。 一. Tick
Tick是指每秒中定时器中断的次数。POS…[摘要] Timer是实时操作系统的一个重要组成部分。本文结合近阶段的学习和实验情况对VxWorks中的时间函数和定时器作了一些探讨。主要介绍了Timer的机制相关的函数并给出了一些具体的例子。 一. Tick
Tick是指每秒中定时器中断的次数。POSIX标准中tick等于50即每20ms定时器中断一次。VxWorks中tick的缺省设置为60。因为实时操作系统中任务的调度和定时器密切相关tick设置是否合理对整个系统性能的影响是很明显的。如果tick太小则系统实时响应能力较差反之如果tick太大则会使得系统的绝大多数资源浪费在不断的任务管理和调度中。
Tick的次数在userconfig.c文件中设置其语句为sysClkRateSet (60)。用户可以更改这个文件然后重新编译BSP库也可以在应用程序中更改。
和tick相关的函数主要有 sysClkRateGet 得到每秒系统的tick数 sysClkRateSet 设置系统的tick数 二. 看门狗时钟Watchdog Timer
Watchdog Timer 提供了这样一种机制它使一个C函数和一个时间延迟联系起来。当该时间延迟到达以后系统会调用该C函数。Watchdog Timer采用了中断服务进程ISR的机理当C函数被激活时它是作为ISR运行的。
和Watchdog Timer相关的函数如下 wdCreate 创建Watchdog Timer wdDelete 删除Watchdog Timer wdStart 启动一个Watchdog Timer wdCancel 取消一个正在记数的Watchdog Timer Watchdog使用过程如下首先调用wdCreate创建一个Watchdog Timer, 然后通过wdStart启动该Timer。当tick累计到设定的数字时和它相联系的C函数被激活作为ISR运行。下面是一个例子该例子在延迟3秒后输出一句话“Watchdog timer just expired”。
例
#include VxWorks.h
#include logLib.h
#include wdLib.h
#include taskLib.h /* defines */
#define SECONDS (3) WDOG_ID myWatchDogId;
myTask (void)
{ /* Create watchdog */ if ((myWatchDogId wdCreate()) NULL) return (ERROR); /* Set timer to go off in SECONDS - printing a message to stdout */ if (wdStart (myWatchDogId, sysClkRateGet() * SECONDS, logMsg, Watchdog timer just expired\n) ERROR) taskDelay(200); return (ERROR);
} 三.POSIX Timer
VxWorks提供了和POSIX1003.1b兼容的时间机制。和POSIX Timer相关的主要函数如下 clock_gettime 取得当前时间 clock_settime 设置当前时间 timer_create 创建定时器 timer_connect 将定时器和某个C 函数相连接 timer_cancel 取消某个定时器 timer_delete 删除定时器 timer_settime 设置Timer的中断周期 下面是POSIX Timer的例子。该例子中myTimer()用来初始化Timer将myHandler()和tmID Timer相关联。每隔1秒myHandler()被调用一次。当myHandler()被调用10次后它取消并删除定时器tmID。
POSIX Timer中定义了两个重要的结构它们都在time.h文件中定义。其定义如下
struct timespec
{ /* interval tv_sec*10**9 tv_nsec */ time_t tv_sec; /* seconds */ long tv_nsec; /* nanoseconds (0 - 1,000,000,000) */
};
struct itimerspec { struct timespec it_interval; /* timer period (reload value) */ struct timespec it_value; /* timer expiration*/ }; 例子见附录。 四.小结
VxWorks目前并没有向我们提供系统的文档及开发资料所有的资料只有连机帮助。帮助中对各个系统函数也只作了一个简单的介绍对函数中的输入、输出、返回值以及函数中用到的各种结构、宏定义都没有说明。本文中提供的例子及对函数的理解都是通过实验得出的可能会有曲解或错误的地方欢迎大家批评指正。
为了测试系统函数编制了一些小程序如有兴趣者可和我联系。
VxWorks中并没有系统地讲述其时间机制而是分散在帮助文件的各个地方有兴趣者可参见以下章节
² Tornado 1.0.1 online Manuals - VxWorks Programmer’s Guide - Basic Os - Watchdog Timers
² Tornado 1.0.1 online Manuals - VxWorks Programmer’s Guide- Basic Os - POSIX Clock and Timers
² Tornado 1.0.1 online Manuals - VxWorks Reference - Libraries and Drivers - ClockLib
² Tornado 1.0.1 online Manuals - VxWorks Reference - Libraries and Drivers - sysLib
² Tornado 1.0.1 online Manuals - VxWorks Reference - Libraries and Drivers - tickLib
² Tornado 1.0.1 online Manuals - VxWorks Reference - Libraries and Drivers - timerLib 五.附录 vxtimer.c /****************************************************************************** 标题: vxtimer.c 功能: VxWorks timer test programm. 说明: This is a test program for VxWorks. In function myTimer, the timer handler--myHandler is connect to the timer tmId. Once the timer reaches the set time, myHandler will be called. It will display some infomration on the screen. To run this program, just compile it and do as follows: ldvxtimer.o sp myTimer 作者: An Yunbo 日期: 1999/7/14
******************************************************************************/ #include VxWorks.h
#include time.h
#include timers.h
#include syslib.h
#include logLib.h
#include stdio.h #define COUNT 10 /****************************************************************************** 标题: myhandler 功能: the timer handler. it will be called once the set time is reachted. 格式void myHandler(timer_t tmId, int arg). 输入 timer_t tmId: the Id of the set timer. int arg. A user parameter. 输出 返回值
******************************************************************************/
void myHandler(timer_t tmId,int arg)
{ static int iCount0; 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(iCountCOUNT) { iRettimer_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; } }
} /************************************************************************* 标题myTimer 功能init timId and connect it with function myHandler. 格式void myTimer(). 输入 输出 返回值
*************************************************************************/
void myTimer()
{ int iRet; struct timespec stTp0,stTp1; struct itimerspec stValue; timer_t tmId; /* set current time to 0 second and o nsecond*/ stTp0.tv_sec0; stTp0.tv_nsec0; iRetclock_settime(CLOCK_REALTIME, stTp0); if(iRet!0) { printf(clock_settime error.\n); return; } iRettimer_create(CLOCK_REALTIME,NULL,tmId); iRettimer_create(0,NULL,tmId); if(iRet!0) { printf(timer_create error.\n); return; } /* connect tmId with myHandler*/ iRettimer_connect(tmId,myHandler,10); if(iRet!0) { printf(timer_connect error.\n); return; } /* set interrupt time: 1 second and the first interrup time will be 2 second later */ stValue.it_interval.tv_sec1; stValue.it_interval.tv_nsec0; stValue.it_value.tv_sec2; stValue.it_value.tv_nsec0; iRettimer_settime(tmId,0,stValue,0); if(iRet!0) { printf(timer_settime error.\n); return; } /* sleep 10 second and print the remind time when the time interrupt come*/ stTp0.tv_sec10; stTp0.tv_nsec0; while(1) { nanosleep(stTp0,stTp1); printf(tv_sec %ld tv_nsec %ld\n,stTp1.tv_sec,stTp1.tv_nsec); }
}
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/930969.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!