|
|
- 大家来看个关于看门狗程序
作者:tony001 时间:2008-9-9 21:58:52
大家来看个关于看门狗程序
#include "wdLib.h"
#include "stdio.h"
#include "taskLib.h"
#include "logLib.h"
#include "sysLib.h"
void main (void)
{
int taskid,taskid2,taskone,tasktwo;
taskid=taskSpawn("t1",120,0,200,(FUNCPTR) taskone,0,0,0,0,0,0,0,0,0,0);
taskid=taskSpawn("t2",120,0,200,(FUNCPTR) tasktwo,0,0,0,0,0,0,0,0,0,0);
}
void taskone(void)
{
int tasktwo;
WDOG_ID wdId;
wdStart(wdId,1000,(FUNCPTR)tasktwo,0);
int i;
for(i=0; ;i++)
logMsg("this is ........n",0,0,0,0,0,0);
}
void tasktwo(void)
{
int i;
for(i=0;i<100;i++)
logMsg("*****"n,0,0,0,0,0,0);
}
这个程序原意是使this is ........输出1000ticks后转去执行tasktwo输出*****,但是程序一直输出this is...........,过了一段时间后就自动目标机丢失连接了,请问哪里出错了? 这样用看门狗可以吗?
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
作者:maomaotr 时间:2008-9-10 22:31:01
/* countingSemDemo.c - Demonstrates task synchronization using counting
* semaphores.
*/
/* Copyright 1984-1997 Wind River Systems, Inc. */
/*
modification history
--------------------
01c,06nov97,mm added copyright.
01b,16sep97,ram included files stdio.h, taskLib.h, usrLib.h, sysLib.h
Used the semShow() function to display info about
the semaphore inplace of the show() function.
01a,27mar94,ms cleaned up for VxDemo
*/
/*
* DESCRIPTION
* Counting semaphore example. Using binary semaphores for task
* synchronization may, if the events can occur rapidly enough, cause
* a loss of data, i.e. an event can be missed if the events can occur
* faster then a task can process them. Using counting semaphores may
* solve this problem. This program demonstrates task synchronization using
* counting semaphores. User can also select to use a binary semaphore instead
* of a counting semaphore in this demonstration, for comparision between the
* two semaphores.
*
* RETURNS: OK or ERROR
*
* EXAMPLE
*
* -> sp countingSemDemo, typeOfSemaphore
*
* where typeOfSemaphore is the value of the type of semaphore to be used
* for task synchronization in this demonstration. For using counting
* semaphores use a value 'c' or 'C' for typeOfSemaphore parameter and for
* using binary semaphores use a value 'b' or 'B' for typeOfSemaphore
* parameter.
*
* example:
* -> sp countingSemDemo, 'c'
* -> sp countingSemDemo, 'b'
*
*/
/* include files */
#include "vxWorks.h"
#include "wdLib.h"
#include "stdio.h"
#include "semLib.h"
#include "taskLib.h"
#include "usrLib.h"
#include "sysLib.h"
/* defines */
#define TASK_PRIORITY 101
#define TASK_STACK_SIZE 5000
#define TIME_BETWEEN_INTERRUPTS 1 /* 1 tick */
#define TASK_WORK_TIME 2 /* 2 ticks */
#define NUM_OF_GIVES 3
/* globals */
LOCAL SEM_ID semId = NULL; /* counting or binary semaphore ID */
LOCAL WDOG_ID wdId = NULL; /* watchdog ID */
LOCAL int syncTaskTid = 0; /* tid of syncTask */
LOCAL int numToGive = NUM_OF_GIVES; /* Number of times semGive is called */
/* forward declaratiuon */
void syncISR(int); /* ISR to unblock syncTask */
void cleanUp (); /* cleanup routine */
void syncTask (); /* task that needs to be synchronized
* with external events */
/*****************************************************************************
* countingSemDemo - demonstrates task synchronization using counting
* semaphores. User can also select to use binary semaphore instead of
* counting semaphore in this demonstration, for comparision between the two
* semaphores.
*
* RETURNS: OK or ERROR
*
*/
STATUS countingSemDemo
(
char semType /* counting semaphore type 'c' or binary semaphore
* type 'b'
*/
)
{
switch (semType)
{
case 'c':
case 'C':
if ((semId = semCCreate (SEM_Q_PRIORITY, 0)) == NULL)
{
perror ("semCCreate");
return (ERROR);
}
break;
case 'b':
case 'B':
if ((semId = semBCreate(SEM_Q_PRIORITY, SEM_EMPTY)) == NULL)
{
perror ("semBCreate");
return (ERROR);
}
break;
default:
printf ("Unknown semType -- must be 'c' or 'b'\n");
return (ERROR);
}
if ((wdId = wdCreate()) == NULL)
{
perror ("wdCreate");
cleanUp ();
return (ERROR);
}
if ((syncTaskTid = taskSpawn ("tsyncTask", TASK_PRIORITY, 0,TASK_STACK_SIZE,(FUNCPTR) syncTask, 0,0,0,0,0,0,0,0,0,0)) == ERROR)
{
perror ("taskSpawn");
cleanUp();
return (ERROR);
}
/* watchdog simulates hardware interrupts */
if (wdStart (wdId, TIME_BETWEEN_INTERRUPTS, (FUNCPTR) syncISR, numToGive)
== ERROR)
{
perror ("wdStart");
cleanUp ();
return (ERROR);
}
/* arbitrary delay to allow program to complete before clean up */
taskDelay (sysClkRateGet() + ((TASK_WORK_TIME + 2) * numToGive));
cleanUp();
return (OK);
}
/*****************************************************************************
* syncTask - synchronizes with interrupts using counting or binary
* semaphores.
*/
void syncTask (void)
{
int eventCount = 0;
FOREVER
{
if (semTake (semId, WAIT_FOREVER) == ERROR)
{
perror ("syncTask semTake");
return;
}
/* Do "work" */
taskDelay (TASK_WORK_TIME);
semShow (semId,1);
eventCount++;
printf ("semaphore taken %d times\n", eventCount);
}
}
/*****************************************************************************
* syncISR - simulates a hardware device which generates interrupts very
* quickly and synchronizes with syncTask using semaphores.
*/
void syncISR
(
int times
)
{
semGive (semId);
times--;
if (times > 0)
wdStart (wdId, TIME_BETWEEN_INTERRUPTS, (FUNCPTR) syncISR, times);
}
/*****************************************************************************
* cleanUP - deletes the syncTask, deletes the semaphore and the watchdog timer
* previously created by countingSemDemo.
*/
void cleanUp ()
{
if (syncTaskTid)
taskDelete (syncTaskTid);
if (semId)
semDelete (semId);
if (wdId)
wdDelete (wdId);
}
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
作者:maomaotr 时间:2008-9-10 22:16:25
从网上找的:
WatchDog
VxWorks提供了一个看门狗定时器(watchdog timer)机制,利用提供的函数,任何任务都可以创建一个看门狗定时器,经过指定的延时后,实现在系统时钟ISR的上下文中运行指定的程序。在VxWorks中,看门狗定时器作为系统时钟中断服务程序的一部分来维护。因此,与看门狗定时器相联系的函数运行在系统时钟中断级。在使用看门狗定时器实现定时/延时时,经过指定的时间,应用程序中断在系统时钟中断优先级上面,然而,如果内核不能立即执行这个中断服务程序,这个任务就被排队到tExcTask 工作队列中去,处在 tExcTask工作队列中的任务的优先级为 tExcTask (通常是 0)。对于使用看门狗定时器的中断服务程序,仍然必须遵守一般的ISR所要遵守的规则。通过wdCreate( )可以创建一个看门狗定时器。调用wdStart()启动定时器,延时参数以tick为单位,同时还要指定定时完成后要调用的程序。如果你的应用程序需要多个看门狗函数,使用wdCreate( )为每个需求产生独立的看门狗ID。因为对于给定的看门狗ID,只有最近的wdStart()有效。在指定的tick计数到达之前,要取消一个看门狗计时器,可以调用wdCancel()实现。每调用一次wdStart(),看门狗定时器只执行一次。对于一些要求周期性执行的应用程序。要获得该效果,定时器函数本身必须通过递归调用wdStart()来重新启动定时器。利用看门狗定时器,调用的任务不会被阻塞:因为wdStart()调用是立即返回的。使用该方法实现延时,关联函数所受限制太大,好多系统调用不可用,郁闷也…
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
作者:iceofwater 时间:2008-9-10 0:33:03
你的看门狗没有创建啊,拜托,怎么在中国电子开发网上也提问了~~~..
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
作者:much 时间:2008-9-9 23:23:44
任务的优先级的问题
这个问题,你可以发到vxworks的板块,那里会有比较多的同学。
本想帮你移动过去,无奈,不知道咋移动的!
[em53][em51]-------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|