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

📄 deadlinewd.c

📁 软件简介 1.vxworks下看门狗计时器的应用程序 2.本软件基于c语言开发 3.开发平台为windriver公司的tornada开发平台 4.经过交叉调试后测试成功
💻 C
字号:
#include "vxWorks.h"
#include "taskLib.h"
#include "msgQLib.h"
#include "wdLib.h"
#include "usrLib.h"
#include "sysLib.h"
#include "stdio.h"
#include "logLib.h"

#define FIVE_SEC	5
#define TWENTY_SEC	20
#define DEADLINE_TIME	20
#define NUM_MSGS	10
#define TASK_STACK_SIZE	20000
#define PRIORITY	101

/* globals */
LOCAL int countNum;
LOCAL int valueGot;
LOCAL BOOL working;
LOCAL BOOL notDone;
LOCAL WDOG_ID wdId;
LOCAL MSG_Q_ID msgQId;

/* function prototypes*/
LOCAL STATUS deadlineHandler();		/* deadline handler - watchdog handler routine */
LOCAL STATUS coordinatorTask();		/* sends data to organizer */
LOCAL STATUS organizerTask();		/* receives data from the coordinator and 
					 * resets the coordinator while deadline time elapses */
LOCAL STATUS getDataFromDevice();	/* simulation data collection */


STATUS deadlineWd()
{
/* initialize the globals */
notDone = TRUE;
working = TRUE;
countNum = 0;
valueGot = 0;

/* Create msgQ */
if ((msgQId = msgQCreate(NUM_MSGS,sizeof(int),MSG_Q_FIFO)) == NULL)
    {
    perror ("cannot create msgQ");
    return (ERROR);
    }

/* Create watchDog timer */
if ((wdId = wdCreate()) == NULL)
    {
    perror ("cannot create watchdog");
    return (ERROR);
    }

/* Spawn the organizerTask */
if ((taskSpawn("tOrgTask",PRIORITY,0,TASK_STACK_SIZE,
		(FUNCPTR)organizerTask,0,0,0,0,0,0,0,0,0,0)) == ERROR)
    {
    perror ("deadlineWd: Error in spawning organizerTask");
    return (ERROR);
    }

/* Spawn the coordinatorTask */
if ((taskSpawn("tCordTask",PRIORITY,0,TASK_STACK_SIZE,
		(FUNCPTR)coordinatorTask,0,0,0,0,0,0,0,0,0,0)) == ERROR)
    {
    perror ("deadlineWd: Error in spawning coordinatorTask");
    return (ERROR);
    }

/* stop the demo after 20 seconds */
taskDelay (sysClkRateGet() * TWENTY_SEC);
printf ("\n\nStopping deadlineWd...\n");
notDone = FALSE;
if (msgQDelete (msgQId) == ERROR )
    {
    perror ("Error in deleting msgQ");
    return (ERROR);
    }
if (wdCancel (wdId) == ERROR )
    {
    perror ("Error in canceling watchdog timer");
    return (ERROR);
    }
if (wdDelete (wdId) == ERROR )
    {
    perror ("Error in deleting watchdog timer");
    return (ERROR);
    }

return (OK);
}


STATUS coordinatorTask()
{
FOREVER
    {
    countNum++;
    if ((msgQSend(msgQId,(char *)&countNum,sizeof(int),NO_WAIT,MSG_PRI_NORMAL)) == ERROR)
		{
		perror ("Error in sending the msg");
		return (ERROR);
		}
	printf ("\n\ncoordinatorTask: Send item = %d\n", countNum);
	printf ("coordinatorTask: idle for %d seconds\n", countNum);
	getDataFromDevice();

	if (notDone == FALSE)
		break;
    }

return (OK);
}

STATUS organizerTask()
{
	while (notDone)
	{
		if ((wdStart(wdId, sysClkRateGet()*DEADLINE_TIME, (FUNCPTR)deadlineHandler, 0)) == ERROR)
		{
			perror ("Error in starting watchdog timer");
			return (ERROR);
		}
		if ((msgQReceive(msgQId, (char *)&valueGot, sizeof(int), WAIT_FOREVER)) == ERROR)
		{
			perror ("Error in receiving the message");
			return (OK);
		}
		else
			printf ("organizerTask: Received item = %d\n", valueGot);
	}

	return (OK);
}

STATUS deadlineHandler ()
{
	logMsg ("\n\nReseting the coordinator on elapse of the deadline time\n",0,0,0,0,0,0);
	countNum = 0;
	return (OK);
}

STATUS getDataFromDevice ()
{
	taskDelay (sysClkRateGet()*countNum);
	return (OK);
}

⌨️ 快捷键说明

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