vxworks的看门狗疑问.

abzhang2 2011-11-02 08:38:56
今天用看门狗, 遇到一个问题, 请大侠们指点下.

WDOG_ID wd_test = NULL;

.....

void OnFunction(int times)
{
int i;

wdStart(wd_test, 1秒钟, (FUNCPTR)OnFunction, 0); // 比如说1秒钟后启动看门狗。

i = 0; .... // 功能处理。比如说功能处理需要10秒钟时间。
}

///////////////////
那上面这种情况会出现什么样子,请问一秒钟后会执行OnFunction? 还是等功能处理完了才会执行函数OnFunction。 对于这个地方不是很明白。
...全文
424 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
abzhang2 2011-11-04
  • 打赏
  • 举报
回复
谢谢楼上的回答, 先去测试下看看。
井中月_QCJ 2011-11-03
  • 打赏
  • 举报
回复
对了系统tick设置为1ms!
井中月_QCJ 2011-11-03
  • 打赏
  • 举报
回复
1. 看门狗定时器是系统中断级的, 如果用logMsg打印输出语句时,会输出 interrupt : 1 tickGet()=
所以对定时回调函数的编写是有限制的,限制规则与中断程序一样,比如:不可以输出printf,不可以获取信号量, 不能分配内存,不能执行过多IO操作等。
2. 通过下面的例子测试时,如果定时10ms, TimerTest()中循环 4000000,则系统会重启系统。
3. 测试结果显示,如果TimerTest中循环次数大于4000000时,即浪费的时间大于1个tick时,系统会重启。
小于1个tick,则系统正常运行。

故:如果1秒的定时器,做10秒的工作,系统会重新启动。
如果有疑问可以自己试一下,共同交流学习!




#include "RS422.h"
#include "inetLib.h"
#include "vxWorks.h"
#include "stdio.h"
#include "iolib.h"
#include "time.h"
#include "selectLib.h"
#include "msgQLib.h"
#include "semLib.h"
#include "wdLib.h"


//系统Tick=1ms
WDOG_ID g_wd2sHandle = NULL; /*2S定时器的句柄, 用于模拟量的计量*/



void TimerTest(int nInterval)
{
int i = 0;
int j = 0;


/* Start watchdog */
wdStart(g_wd2sHandle, nInterval, (FUNCPTR)TimerTest, nInterval);
logMsg("1. tickGet() = %ld \n", tickGet());
for(i = 0; i < 1000000; i++)
{
j = j+1;
}
logMsg("2. tickGet() = %ld \n", tickGet());

}

/************************************************************************/
/* Function : 启动向上位机发AI数据定时器函数
/* Input : nInterval, 定时时间ms
/* RetValue : 无
/* Date :
/************************************************************************/
void StartTimer(int nInterval)
{
/*If Timer of 2s is started, delete it */
if(NULL != g_wd2sHandle)
wdDelete(g_wd2sHandle);

/*Create watchdog handle*/
g_wd2sHandle = wdCreate();
if(NULL == g_wd2sHandle)
return ;

/*Start watchdog */
wdStart(g_wd2sHandle, nInterval, (FUNCPTR)TimerTest, nInterval);


}




/**************************************************************************
* 函数功能 : 测试程序的主函数,在usrAppInit.c文件中调用
* 输入参数 : 无
* 输出参数 : 无
* 返 回 值 : 无
* 创建信息 :
**************************************************************************/
void ProjMain()
{

int i = 0;
for(i = 0; i++; i < 10)
{
printf("AAAAAAAAAAAAAAAAAAAAAAAAAAAA \n");
}
printf("sysClkRateGet() = %d \n", sysClkRateGet() );

taskDelay(1000);
StartTimer(100);

//COMTest();
}
abzhang2 2011-11-03
  • 打赏
  • 举报
回复
怎么没人呢。 。

2,179

社区成员

发帖
与我相关
我的任务
社区描述
xworks是美国 Wind River System 公司( 以下简称风河公司 ,即 WRS 公司)推出的一个实时操作系统。
社区管理员
  • VxWorks开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧