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

📄 watchdog.c

📁 vxworks的实时性
💻 C
字号:
#include "vxworks.h"
#include "wdLib.h"
#include "stdio.h"
#include "taskLib.h"
#include "logLib.h"
#include "sysLib.h"

void taskTwo(void)
{
	int i;
	for(i = 0; i <  10; i++)
	{
		taskDelay(10);
		logMsg("taskTwo: this is %d............\r\n", i, 0, 0, 0, 0, 0);
	}
}

void taskThree(void)
{
	int i;
	for(i = 0; i <  10; i++)
	{
		taskDelay(10);
		logMsg("taskThree: this is %d............\r\n", i, 0, 0, 0, 0, 0);
	}
}

void taskFour(void)
{
	int i;
	for(i = 0; i <  10; i++)
	{
		taskDelay(10);
		logMsg("taskFour: this is %d............\r\n", i, 0, 0, 0, 0, 0);
	}
}

void taskOne(void)
{
	int task2;
	int i;
	WDOG_ID wdId;
	
	printf("\r\n");
	
#if 1
	wdId = wdCreate();
	if(NULL == wdId)
	{
		printf("\r\ncreate watchdog error.");
		return;
	}
	
	printf("\r\nfirst show: watchdog created!");
	if(ERROR == wdShow(wdId))
	{
		printf("\r\nshow watchdog error.");
	}
	
	if(ERROR == wdStart(wdId, 200, (FUNCPTR)taskTwo, 0))
	{
		printf("\r\nstart watchdog error.");
	}
	
	printf("\r\nsecond show: watchdog started.");
	if(ERROR == wdShow(wdId))
	{
		printf("\r\nshow watchdog error.");
	}
	
	for(i = 0; i < 10; i++)
	{
		taskDelay(10);
		logMsg("taskOne: this is %d ...........\r\n", i, 0, 0, 0, 0, 0);
	}
		
	if(ERROR == wdCancel(wdId))
	{
		printf("\r\ncancel watchdog error.");
	}
	
	printf("\r\nthird show: watchdog canceled.");
	if(ERROR == wdShow(wdId))
	{
		printf("\r\nshow watchdog error.");
	}
		
	if(ERROR == wdStart(wdId, 200, (FUNCPTR)taskThree, 0))
	{
		printf("\r\nstart watchdog error.");
	}
	printf("\r\nforth show: watchdog started the second time.");
	if(ERROR == wdShow(wdId))
	{
		printf("\r\nshow watchdog error.");
	}
	
	taskDelay(201);
	printf("\r\nfifth show: watchdog expired.");
	if(ERROR == wdShow(wdId))
	{
		printf("\r\nshow watchdog error.");
	}
	if(ERROR == wdDelete(wdId))
	{
		printf("\r\ndelete watchdog error.");
	}
	printf("\r\nsixth show: watchdog deleted.");
	if(ERROR == wdShow(wdId))
	{
		printf("\r\nshow watchdog error.");
	}
	
	if(ERROR == wdStart(wdId, 200, (FUNCPTR)taskFour, 0))
	{
		printf("\r\nstart watchdog error.");
	}
	
#endif
}


void watchdog(void)
{
	int taskId1, taskId2;
	
	taskId1 = taskSpawn("t1", 120, 0, 200, (FUNCPTR)taskOne, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
#if 0
	taskId2 = taskSpawn("t2", 120, 0, 200, (FUNCPTR)taskTwo, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
#endif
}

⌨️ 快捷键说明

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