⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wtdogdemo.c

📁 2410/vxworks/tornado下的基本实验包括 serial,ramdrv,interrupt,multi-tasking,FTP,TCP,UDP
💻 C
字号:
/*WdDemo.c - 利用看门狗的例子*/
  
 /* includes */ #include "vxWorks.h"
 #include "wdLib.h"
 #include "stdio.h"
  /* defines */#define TIMEOUT			10
#define DEADLINE_TIME 1


 LOCAL WDOG_ID   wdId;		/*看门狗定时器ID*/

/*
	wdHandler - 看门狗定时器处理函数,
						处理结束后再次启动定时器
						循环处理

	RETURN : OK or ERROR					
*/

STATUS wdHandler()
{
	static int count = 0;
	if(count < TIMEOUT )
		{
			count++;
			printf("call wdHandler %d times!\n",count);
			/*再次启动wdId*/
		    if ((wdStart (wdId, sysClkRateGet ()* DEADLINE_TIME, 
		               (FUNCPTR) wdHandler, 0)) == ERROR)
		        {
		        perror ("Error in starting watchdog timer");
		        return (ERROR);
		        }
			
		}
	return (OK);
}

/*
	wdDemo	 - 看门狗定时器主函数,
						创建并发起一个看门狗定时器
	RETURN : OK or ERROR					
*/

STATUS wdDemo()
{
     /* 创建一个看门狗定时器 */
     if ((wdId = wdCreate ()) == NULL)         {         perror ("cannot create watchdog");         return (ERROR);         }    /*启动看门狗定时器,并绑定一个处理函数*/
    if ((wdStart (wdId, sysClkRateGet ()* DEADLINE_TIME, 
               (FUNCPTR) wdHandler, 0)) == ERROR)
        {
        perror ("Error in starting watchdog timer");
        return (ERROR);
        }
		
		return (OK);

}

⌨️ 快捷键说明

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